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> |
Juan Quintela | 71e72a1 | 2009-07-27 16:12:56 +0200 | [diff] [blame] | 50 | #ifdef CONFIG_BSD |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 51 | #include <sys/stat.h> |
Aurelien Jarno | a167ba5 | 2009-11-29 18:00:41 +0100 | [diff] [blame] | 52 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 53 | #include <libutil.h> |
Juergen Lock | 92c0e65 | 2010-03-25 22:07:12 +0100 | [diff] [blame] | 54 | #include <sys/sysctl.h> |
blueswir1 | 24646c7 | 2008-11-07 16:55:48 +0000 | [diff] [blame] | 55 | #else |
| 56 | #include <util.h> |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 57 | #endif |
Aurelien Jarno | bbe813a | 2009-11-30 15:42:59 +0100 | [diff] [blame] | 58 | #else |
blueswir1 | 223f0d7 | 2008-09-30 18:12:18 +0000 | [diff] [blame] | 59 | #ifdef __linux__ |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 60 | #include <pty.h> |
| 61 | #include <malloc.h> |
ths | bd494f4 | 2007-09-16 20:03:23 +0000 | [diff] [blame] | 62 | |
bellard | e57a8c0 | 2005-11-10 23:58:52 +0000 | [diff] [blame] | 63 | #include <linux/ppdev.h> |
ths | 5867c88 | 2007-02-17 23:44:43 +0000 | [diff] [blame] | 64 | #include <linux/parport.h> |
blueswir1 | 223f0d7 | 2008-09-30 18:12:18 +0000 | [diff] [blame] | 65 | #endif |
| 66 | #ifdef __sun__ |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 67 | #include <sys/stat.h> |
| 68 | #include <sys/ethernet.h> |
| 69 | #include <sys/sockio.h> |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 70 | #include <netinet/arp.h> |
ths | d5d10bc | 2007-02-17 22:54:49 +0000 | [diff] [blame] | 71 | #include <netinet/in_systm.h> |
| 72 | #include <netinet/ip.h> |
| 73 | #include <netinet/ip_icmp.h> // must come after ip.h |
| 74 | #include <netinet/udp.h> |
| 75 | #include <netinet/tcp.h> |
| 76 | #include <net/if.h> |
| 77 | #include <syslog.h> |
| 78 | #include <stropts.h> |
Blue Swirl | 8d32cf0 | 2009-10-02 19:32:12 +0000 | [diff] [blame] | 79 | /* See MySQL bug #7156 (http://bugs.mysql.com/bug.php?id=7156) for |
| 80 | discussion about Solaris header problems */ |
| 81 | extern int madvise(caddr_t, size_t, int); |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 82 | #endif |
bellard | 7d3505c | 2004-05-12 19:32:15 +0000 | [diff] [blame] | 83 | #endif |
bellard | ec530c8 | 2006-04-25 22:36:06 +0000 | [diff] [blame] | 84 | #endif |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 85 | |
blueswir1 | 9892fbf | 2008-08-24 10:34:20 +0000 | [diff] [blame] | 86 | #if defined(__OpenBSD__) |
| 87 | #include <util.h> |
| 88 | #endif |
| 89 | |
ths | 8a16d27 | 2008-07-19 09:56:24 +0000 | [diff] [blame] | 90 | #if defined(CONFIG_VDE) |
| 91 | #include <libvdeplug.h> |
| 92 | #endif |
| 93 | |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 94 | #ifdef _WIN32 |
aliguori | 49dc768 | 2009-03-08 16:26:59 +0000 | [diff] [blame] | 95 | #include <windows.h> |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 96 | #endif |
| 97 | |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 98 | #ifdef CONFIG_SDL |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 99 | #if defined(__APPLE__) || defined(main) |
Stefan Weil | 6693665 | 2009-06-13 13:19:11 +0200 | [diff] [blame] | 100 | #include <SDL.h> |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 101 | int qemu_main(int argc, char **argv, char **envp); |
| 102 | int main(int argc, char **argv) |
| 103 | { |
Stefan Weil | 59a36a2 | 2009-06-18 20:11:03 +0200 | [diff] [blame] | 104 | return qemu_main(argc, argv, NULL); |
malc | 880fec5 | 2009-02-15 20:18:41 +0000 | [diff] [blame] | 105 | } |
| 106 | #undef main |
| 107 | #define main qemu_main |
bellard | 96bcd4f | 2004-07-10 16:26:15 +0000 | [diff] [blame] | 108 | #endif |
bellard | 73332e5 | 2004-04-04 20:22:28 +0000 | [diff] [blame] | 109 | #endif /* CONFIG_SDL */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 110 | |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 111 | #ifdef CONFIG_COCOA |
| 112 | #undef main |
| 113 | #define main qemu_main |
| 114 | #endif /* CONFIG_COCOA */ |
| 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" |
Kevin Wolf | d3f2436 | 2009-05-18 16:42:09 +0200 | [diff] [blame] | 146 | #include "qemu-option.h" |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 147 | #include "qemu-config.h" |
Luiz Capitulino | e78c48e | 2009-12-10 17:16:04 -0200 | [diff] [blame] | 148 | #include "qemu-objects.h" |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 149 | #include "qemu-options.h" |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 150 | #ifdef CONFIG_VIRTFS |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 151 | #include "fsdev/qemu-fsdev.h" |
| 152 | #endif |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 153 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 154 | #include "disas.h" |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 155 | |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 156 | #include "qemu_socket.h" |
| 157 | |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 158 | #include "slirp/libslirp.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 159 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 160 | #include "qemu-queue.h" |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 161 | #include "cpus.h" |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 162 | #include "arch_init.h" |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 163 | |
blueswir1 | 9dc63a1 | 2008-10-04 07:25:46 +0000 | [diff] [blame] | 164 | //#define DEBUG_NET |
| 165 | //#define DEBUG_SLIRP |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 166 | |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 167 | #define DEFAULT_RAM_SIZE 128 |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 168 | |
Amit Shah | 98b1925 | 2010-01-20 00:36:52 +0530 | [diff] [blame] | 169 | #define MAX_VIRTIO_CONSOLES 1 |
| 170 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 171 | static const char *data_dir; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 172 | const char *bios_name = NULL; |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 173 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 174 | DisplayType display_type = DT_DEFAULT; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 175 | const char* keyboard_layout = NULL; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 176 | ram_addr_t ram_size; |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 177 | const char *mem_path = NULL; |
| 178 | #ifdef MAP_POPULATE |
| 179 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
| 180 | #endif |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 181 | int nb_nics; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 182 | NICInfo nd_table[MAX_NICS]; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 183 | int vm_running; |
Paolo Bonzini | d399f67 | 2009-07-27 23:17:51 +0200 | [diff] [blame] | 184 | int autostart; |
Amit Shah | 8e84865 | 2010-07-27 15:49:19 +0530 | [diff] [blame] | 185 | int incoming_expected; /* Started with -incoming and waiting for incoming */ |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 186 | static int rtc_utc = 1; |
| 187 | static int rtc_date_offset = -1; /* -1 means no change */ |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 188 | QEMUClock *rtc_clock; |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 189 | int vga_interface_type = VGA_NONE; |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 190 | static int full_screen = 0; |
blueswir1 | 634a21f | 2008-11-16 11:34:07 +0000 | [diff] [blame] | 191 | #ifdef CONFIG_SDL |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 192 | static int no_frame = 0; |
blueswir1 | 634a21f | 2008-11-16 11:34:07 +0000 | [diff] [blame] | 193 | #endif |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 194 | int no_quit = 0; |
bellard | 8d11df9 | 2004-08-24 21:13:40 +0000 | [diff] [blame] | 195 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 196 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
aliguori | 9ede2fd | 2009-01-15 20:05:25 +0000 | [diff] [blame] | 197 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 198 | int win2k_install_hack = 0; |
aliguori | 73822ec | 2009-01-15 20:11:34 +0000 | [diff] [blame] | 199 | int rtc_td_hack = 0; |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 200 | int usb_enabled = 0; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 201 | int singlestep = 0; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 202 | int smp_cpus = 1; |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 203 | int max_cpus = 0; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 204 | int smp_cores = 1; |
| 205 | int smp_threads = 1; |
ths | 73fc974 | 2006-12-22 02:09:07 +0000 | [diff] [blame] | 206 | const char *vnc_display; |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 207 | int acpi_enabled = 1; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 208 | int no_hpet = 0; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 209 | int fd_bootchk = 1; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 210 | int no_reboot = 0; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 211 | int no_shutdown = 0; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 212 | int cursor_hide = 1; |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 213 | int graphic_rotate = 0; |
Jes Sorensen | 6b35e7b | 2009-08-06 16:25:50 +0200 | [diff] [blame] | 214 | uint8_t irq0override = 1; |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 215 | const char *watchdog; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 216 | const char *option_rom[MAX_OPTION_ROMS]; |
| 217 | int nb_option_roms; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 218 | int semihosting_enabled = 0; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 219 | int old_param = 0; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 220 | const char *qemu_name; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 221 | int alt_grab = 0; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 222 | int ctrl_grab = 0; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 223 | unsigned int nb_prom_envs = 0; |
| 224 | const char *prom_envs[MAX_PROM_ENVS]; |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 225 | int boot_menu; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 226 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 227 | int nb_numa_nodes; |
| 228 | uint64_t node_mem[MAX_NODES]; |
| 229 | uint64_t node_cpumask[MAX_NODES]; |
| 230 | |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 231 | static QEMUTimer *nographic_timer; |
balrog | ee5605e | 2007-12-03 03:01:40 +0000 | [diff] [blame] | 232 | |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 233 | uint8_t qemu_uuid[16]; |
| 234 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 235 | static QEMUBootSetHandler *boot_set_handler; |
| 236 | static void *boot_set_opaque; |
| 237 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 238 | static NotifierList exit_notifiers = |
| 239 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); |
| 240 | |
Blue Swirl | d745bef | 2010-03-29 19:23:49 +0000 | [diff] [blame] | 241 | int kvm_allowed = 0; |
| 242 | uint32_t xen_domid; |
| 243 | enum xen_mode xen_mode = XEN_EMULATE; |
| 244 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 245 | static int default_serial = 1; |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 246 | static int default_parallel = 1; |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 247 | static int default_virtcon = 1; |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 248 | static int default_monitor = 1; |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 249 | static int default_vga = 1; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 250 | static int default_floppy = 1; |
| 251 | static int default_cdrom = 1; |
| 252 | static int default_sdcard = 1; |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 253 | |
| 254 | static struct { |
| 255 | const char *driver; |
| 256 | int *flag; |
| 257 | } default_list[] = { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 258 | { .driver = "isa-serial", .flag = &default_serial }, |
| 259 | { .driver = "isa-parallel", .flag = &default_parallel }, |
Gerd Hoffmann | d8bcbab | 2009-12-16 14:25:40 +0100 | [diff] [blame] | 260 | { .driver = "isa-fdc", .flag = &default_floppy }, |
| 261 | { .driver = "ide-drive", .flag = &default_cdrom }, |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 262 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
| 263 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, |
| 264 | { .driver = "virtio-serial", .flag = &default_virtcon }, |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 265 | { .driver = "VGA", .flag = &default_vga }, |
Gerd Hoffmann | 69fd02e | 2009-12-16 13:35:19 +0100 | [diff] [blame] | 266 | { .driver = "cirrus-vga", .flag = &default_vga }, |
| 267 | { .driver = "vmware-svga", .flag = &default_vga }, |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | static int default_driver_check(QemuOpts *opts, void *opaque) |
| 271 | { |
| 272 | const char *driver = qemu_opt_get(opts, "driver"); |
| 273 | int i; |
| 274 | |
| 275 | if (!driver) |
| 276 | return 0; |
| 277 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { |
| 278 | if (strcmp(default_list[i].driver, driver) != 0) |
| 279 | continue; |
| 280 | *(default_list[i].flag) = 0; |
| 281 | } |
| 282 | return 0; |
| 283 | } |
| 284 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 285 | /***********************************************************/ |
Paolo Bonzini | 8f0056b | 2010-01-13 14:05:34 +0100 | [diff] [blame] | 286 | /* real time host monotonic timer */ |
bellard | 09b26c5 | 2006-04-12 21:09:08 +0000 | [diff] [blame] | 287 | |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 288 | /* compute with 96 bit intermediate result: (a*b)/c */ |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 289 | uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 290 | { |
| 291 | union { |
| 292 | uint64_t ll; |
| 293 | struct { |
Juan Quintela | e2542fe | 2009-07-27 16:13:06 +0200 | [diff] [blame] | 294 | #ifdef HOST_WORDS_BIGENDIAN |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 295 | uint32_t high, low; |
| 296 | #else |
| 297 | uint32_t low, high; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 298 | #endif |
bellard | 87858c8 | 2003-06-27 12:01:39 +0000 | [diff] [blame] | 299 | } l; |
| 300 | } u, res; |
| 301 | uint64_t rl, rh; |
| 302 | |
| 303 | u.ll = a; |
| 304 | rl = (uint64_t)u.l.low * (uint64_t)b; |
| 305 | rh = (uint64_t)u.l.high * (uint64_t)b; |
| 306 | rh += (rl >> 32); |
| 307 | res.l.high = rh / c; |
| 308 | res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; |
| 309 | return res.ll; |
| 310 | } |
| 311 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 312 | /***********************************************************/ |
balrog | f650305 | 2008-02-17 11:42:19 +0000 | [diff] [blame] | 313 | /* host time/date access */ |
| 314 | void qemu_get_timedate(struct tm *tm, int offset) |
| 315 | { |
| 316 | time_t ti; |
| 317 | struct tm *ret; |
| 318 | |
| 319 | time(&ti); |
| 320 | ti += offset; |
| 321 | if (rtc_date_offset == -1) { |
| 322 | if (rtc_utc) |
| 323 | ret = gmtime(&ti); |
| 324 | else |
| 325 | ret = localtime(&ti); |
| 326 | } else { |
| 327 | ti -= rtc_date_offset; |
| 328 | ret = gmtime(&ti); |
| 329 | } |
| 330 | |
| 331 | memcpy(tm, ret, sizeof(struct tm)); |
| 332 | } |
| 333 | |
| 334 | int qemu_timedate_diff(struct tm *tm) |
| 335 | { |
| 336 | time_t seconds; |
| 337 | |
| 338 | if (rtc_date_offset == -1) |
| 339 | if (rtc_utc) |
| 340 | seconds = mktimegm(tm); |
| 341 | else |
| 342 | seconds = mktime(tm); |
| 343 | else |
| 344 | seconds = mktimegm(tm) + rtc_date_offset; |
| 345 | |
| 346 | return seconds - time(NULL); |
| 347 | } |
| 348 | |
Luiz Capitulino | 80cd347 | 2010-02-25 12:11:44 -0300 | [diff] [blame] | 349 | void rtc_change_mon_event(struct tm *tm) |
| 350 | { |
| 351 | QObject *data; |
| 352 | |
| 353 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); |
| 354 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); |
| 355 | qobject_decref(data); |
| 356 | } |
| 357 | |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 358 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
| 359 | { |
| 360 | time_t rtc_start_date; |
| 361 | struct tm tm; |
| 362 | |
| 363 | if (!strcmp(startdate, "now") && legacy) { |
| 364 | rtc_date_offset = -1; |
| 365 | } else { |
| 366 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", |
| 367 | &tm.tm_year, |
| 368 | &tm.tm_mon, |
| 369 | &tm.tm_mday, |
| 370 | &tm.tm_hour, |
| 371 | &tm.tm_min, |
| 372 | &tm.tm_sec) == 6) { |
| 373 | /* OK */ |
| 374 | } else if (sscanf(startdate, "%d-%d-%d", |
| 375 | &tm.tm_year, |
| 376 | &tm.tm_mon, |
| 377 | &tm.tm_mday) == 3) { |
| 378 | tm.tm_hour = 0; |
| 379 | tm.tm_min = 0; |
| 380 | tm.tm_sec = 0; |
| 381 | } else { |
| 382 | goto date_fail; |
| 383 | } |
| 384 | tm.tm_year -= 1900; |
| 385 | tm.tm_mon--; |
| 386 | rtc_start_date = mktimegm(&tm); |
| 387 | if (rtc_start_date == -1) { |
| 388 | date_fail: |
| 389 | fprintf(stderr, "Invalid date format. Valid formats are:\n" |
| 390 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); |
| 391 | exit(1); |
| 392 | } |
| 393 | rtc_date_offset = time(NULL) - rtc_start_date; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | static void configure_rtc(QemuOpts *opts) |
| 398 | { |
| 399 | const char *value; |
| 400 | |
| 401 | value = qemu_opt_get(opts, "base"); |
| 402 | if (value) { |
| 403 | if (!strcmp(value, "utc")) { |
| 404 | rtc_utc = 1; |
| 405 | } else if (!strcmp(value, "localtime")) { |
| 406 | rtc_utc = 0; |
| 407 | } else { |
| 408 | configure_rtc_date_offset(value, 0); |
| 409 | } |
| 410 | } |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 411 | value = qemu_opt_get(opts, "clock"); |
| 412 | if (value) { |
| 413 | if (!strcmp(value, "host")) { |
| 414 | rtc_clock = host_clock; |
| 415 | } else if (!strcmp(value, "vm")) { |
| 416 | rtc_clock = vm_clock; |
| 417 | } else { |
| 418 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 419 | exit(1); |
| 420 | } |
| 421 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 422 | value = qemu_opt_get(opts, "driftfix"); |
| 423 | if (value) { |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 424 | if (!strcmp(value, "slew")) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 425 | rtc_td_hack = 1; |
Blue Swirl | 7e4c033 | 2010-03-27 21:33:46 +0000 | [diff] [blame] | 426 | } else if (!strcmp(value, "none")) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 427 | rtc_td_hack = 0; |
| 428 | } else { |
| 429 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); |
| 430 | exit(1); |
| 431 | } |
| 432 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 433 | } |
| 434 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 435 | /***********************************************************/ |
| 436 | /* Bluetooth support */ |
| 437 | static int nb_hcis; |
| 438 | static int cur_hci; |
| 439 | static struct HCIInfo *hci_table[MAX_NICS]; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 440 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 441 | static struct bt_vlan_s { |
| 442 | struct bt_scatternet_s net; |
| 443 | int id; |
| 444 | struct bt_vlan_s *next; |
| 445 | } *first_bt_vlan; |
| 446 | |
| 447 | /* find or alloc a new bluetooth "VLAN" */ |
blueswir1 | 674bb26 | 2008-09-30 18:18:27 +0000 | [diff] [blame] | 448 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 449 | { |
| 450 | struct bt_vlan_s **pvlan, *vlan; |
| 451 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { |
| 452 | if (vlan->id == id) |
| 453 | return &vlan->net; |
| 454 | } |
| 455 | vlan = qemu_mallocz(sizeof(struct bt_vlan_s)); |
| 456 | vlan->id = id; |
| 457 | pvlan = &first_bt_vlan; |
| 458 | while (*pvlan != NULL) |
| 459 | pvlan = &(*pvlan)->next; |
| 460 | *pvlan = vlan; |
| 461 | return &vlan->net; |
| 462 | } |
| 463 | |
| 464 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) |
| 465 | { |
| 466 | } |
| 467 | |
| 468 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) |
| 469 | { |
| 470 | return -ENOTSUP; |
| 471 | } |
| 472 | |
| 473 | static struct HCIInfo null_hci = { |
| 474 | .cmd_send = null_hci_send, |
| 475 | .sco_send = null_hci_send, |
| 476 | .acl_send = null_hci_send, |
| 477 | .bdaddr_set = null_hci_addr_set, |
| 478 | }; |
| 479 | |
| 480 | struct HCIInfo *qemu_next_hci(void) |
| 481 | { |
| 482 | if (cur_hci == nb_hcis) |
| 483 | return &null_hci; |
| 484 | |
| 485 | return hci_table[cur_hci++]; |
| 486 | } |
| 487 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 488 | static struct HCIInfo *hci_init(const char *str) |
| 489 | { |
| 490 | char *endp; |
| 491 | struct bt_scatternet_s *vlan = 0; |
| 492 | |
| 493 | if (!strcmp(str, "null")) |
| 494 | /* null */ |
| 495 | return &null_hci; |
| 496 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) |
| 497 | /* host[:hciN] */ |
| 498 | return bt_host_hci(str[4] ? str + 5 : "hci0"); |
| 499 | else if (!strncmp(str, "hci", 3)) { |
| 500 | /* hci[,vlan=n] */ |
| 501 | if (str[3]) { |
| 502 | if (!strncmp(str + 3, ",vlan=", 6)) { |
| 503 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); |
| 504 | if (*endp) |
| 505 | vlan = 0; |
| 506 | } |
| 507 | } else |
| 508 | vlan = qemu_find_bt_vlan(0); |
| 509 | if (vlan) |
| 510 | return bt_new_hci(vlan); |
| 511 | } |
| 512 | |
| 513 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int bt_hci_parse(const char *str) |
| 519 | { |
| 520 | struct HCIInfo *hci; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 521 | bdaddr_t bdaddr; |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 522 | |
| 523 | if (nb_hcis >= MAX_NICS) { |
| 524 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); |
| 525 | return -1; |
| 526 | } |
| 527 | |
| 528 | hci = hci_init(str); |
| 529 | if (!hci) |
| 530 | return -1; |
| 531 | |
| 532 | bdaddr.b[0] = 0x52; |
| 533 | bdaddr.b[1] = 0x54; |
| 534 | bdaddr.b[2] = 0x00; |
| 535 | bdaddr.b[3] = 0x12; |
| 536 | bdaddr.b[4] = 0x34; |
| 537 | bdaddr.b[5] = 0x56 + nb_hcis; |
| 538 | hci->bdaddr_set(hci, bdaddr.b); |
| 539 | |
| 540 | hci_table[nb_hcis++] = hci; |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static void bt_vhci_add(int vlan_id) |
| 546 | { |
| 547 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); |
| 548 | |
| 549 | if (!vlan->slave) |
| 550 | fprintf(stderr, "qemu: warning: adding a VHCI to " |
| 551 | "an empty scatternet %i\n", vlan_id); |
| 552 | |
| 553 | bt_vhci_init(bt_new_hci(vlan)); |
| 554 | } |
| 555 | |
| 556 | static struct bt_device_s *bt_device_add(const char *opt) |
| 557 | { |
| 558 | struct bt_scatternet_s *vlan; |
| 559 | int vlan_id = 0; |
| 560 | char *endp = strstr(opt, ",vlan="); |
| 561 | int len = (endp ? endp - opt : strlen(opt)) + 1; |
| 562 | char devname[10]; |
| 563 | |
| 564 | pstrcpy(devname, MIN(sizeof(devname), len), opt); |
| 565 | |
| 566 | if (endp) { |
| 567 | vlan_id = strtol(endp + 6, &endp, 0); |
| 568 | if (*endp) { |
| 569 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); |
| 570 | return 0; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | vlan = qemu_find_bt_vlan(vlan_id); |
| 575 | |
| 576 | if (!vlan->slave) |
| 577 | fprintf(stderr, "qemu: warning: adding a slave device to " |
| 578 | "an empty scatternet %i\n", vlan_id); |
| 579 | |
| 580 | if (!strcmp(devname, "keyboard")) |
| 581 | return bt_keyboard_init(vlan); |
| 582 | |
| 583 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | static int bt_parse(const char *opt) |
| 588 | { |
| 589 | const char *endp, *p; |
| 590 | int vlan; |
| 591 | |
| 592 | if (strstart(opt, "hci", &endp)) { |
| 593 | if (!*endp || *endp == ',') { |
| 594 | if (*endp) |
| 595 | if (!strstart(endp, ",vlan=", 0)) |
| 596 | opt = endp + 1; |
| 597 | |
| 598 | return bt_hci_parse(opt); |
| 599 | } |
| 600 | } else if (strstart(opt, "vhci", &endp)) { |
| 601 | if (!*endp || *endp == ',') { |
| 602 | if (*endp) { |
| 603 | if (strstart(endp, ",vlan=", &p)) { |
| 604 | vlan = strtol(p, (char **) &endp, 0); |
| 605 | if (*endp) { |
| 606 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); |
| 607 | return 1; |
| 608 | } |
| 609 | } else { |
| 610 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
| 611 | return 1; |
| 612 | } |
| 613 | } else |
| 614 | vlan = 0; |
| 615 | |
| 616 | bt_vhci_add(vlan); |
| 617 | return 0; |
| 618 | } |
| 619 | } else if (strstart(opt, "device:", &endp)) |
| 620 | return !bt_device_add(endp); |
| 621 | |
| 622 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); |
| 623 | return 1; |
| 624 | } |
| 625 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 626 | /***********************************************************/ |
| 627 | /* QEMU Block devices */ |
| 628 | |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 629 | #define HD_ALIAS "index=%d,media=disk" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 630 | #define CDROM_ALIAS "index=2,media=cdrom" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 631 | #define FD_ALIAS "index=%d,if=floppy" |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 632 | #define PFLASH_ALIAS "if=pflash" |
| 633 | #define MTD_ALIAS "if=mtd" |
balrog | 9d413d1 | 2007-12-04 00:10:34 +0000 | [diff] [blame] | 634 | #define SD_ALIAS "index=0,if=sd" |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 635 | |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 636 | static int drive_init_func(QemuOpts *opts, void *opaque) |
| 637 | { |
Markus Armbruster | a803cb8 | 2010-06-02 13:31:55 +0200 | [diff] [blame] | 638 | int *use_scsi = opaque; |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 639 | int fatal_error = 0; |
| 640 | |
Markus Armbruster | a803cb8 | 2010-06-02 13:31:55 +0200 | [diff] [blame] | 641 | if (drive_init(opts, *use_scsi, &fatal_error) == NULL) { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 642 | if (fatal_error) |
| 643 | return 1; |
| 644 | } |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
| 649 | { |
| 650 | if (NULL == qemu_opt_get(opts, "snapshot")) { |
| 651 | qemu_opt_set(opts, "snapshot", "on"); |
| 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
Jan Kiszka | 76e30d0 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 656 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
| 657 | { |
| 658 | boot_set_handler = func; |
| 659 | boot_set_opaque = opaque; |
| 660 | } |
| 661 | |
| 662 | int qemu_boot_set(const char *boot_devices) |
| 663 | { |
| 664 | if (!boot_set_handler) { |
| 665 | return -EINVAL; |
| 666 | } |
| 667 | return boot_set_handler(boot_set_opaque, boot_devices); |
| 668 | } |
| 669 | |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 670 | static void validate_bootdevices(char *devices) |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 671 | { |
| 672 | /* We just do some generic consistency checks */ |
| 673 | const char *p; |
| 674 | int bitmap = 0; |
| 675 | |
| 676 | for (p = devices; *p != '\0'; p++) { |
| 677 | /* Allowed boot devices are: |
| 678 | * a-b: floppy disk drives |
| 679 | * c-f: IDE disk drives |
| 680 | * g-m: machine implementation dependant drives |
| 681 | * n-p: network devices |
| 682 | * It's up to each machine implementation to check if the given boot |
| 683 | * devices match the actual hardware implementation and firmware |
| 684 | * features. |
| 685 | */ |
| 686 | if (*p < 'a' || *p > 'p') { |
| 687 | fprintf(stderr, "Invalid boot device '%c'\n", *p); |
| 688 | exit(1); |
| 689 | } |
| 690 | if (bitmap & (1 << (*p - 'a'))) { |
| 691 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); |
| 692 | exit(1); |
| 693 | } |
| 694 | bitmap |= 1 << (*p - 'a'); |
| 695 | } |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 698 | static void restore_boot_devices(void *opaque) |
| 699 | { |
| 700 | char *standard_boot_devices = opaque; |
Alex Williamson | 37905d6 | 2010-04-30 15:21:11 -0600 | [diff] [blame] | 701 | static int first = 1; |
| 702 | |
| 703 | /* Restore boot order and remove ourselves after the first boot */ |
| 704 | if (first) { |
| 705 | first = 0; |
| 706 | return; |
| 707 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 708 | |
| 709 | qemu_boot_set(standard_boot_devices); |
| 710 | |
| 711 | qemu_unregister_reset(restore_boot_devices, standard_boot_devices); |
| 712 | qemu_free(standard_boot_devices); |
| 713 | } |
| 714 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 715 | static void numa_add(const char *optarg) |
| 716 | { |
| 717 | char option[128]; |
| 718 | char *endptr; |
| 719 | unsigned long long value, endvalue; |
| 720 | int nodenr; |
| 721 | |
| 722 | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
| 723 | if (!strcmp(option, "node")) { |
| 724 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
| 725 | nodenr = nb_numa_nodes; |
| 726 | } else { |
| 727 | nodenr = strtoull(option, NULL, 10); |
| 728 | } |
| 729 | |
| 730 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
| 731 | node_mem[nodenr] = 0; |
| 732 | } else { |
| 733 | value = strtoull(option, &endptr, 0); |
| 734 | switch (*endptr) { |
| 735 | case 0: case 'M': case 'm': |
| 736 | value <<= 20; |
| 737 | break; |
| 738 | case 'G': case 'g': |
| 739 | value <<= 30; |
| 740 | break; |
| 741 | } |
| 742 | node_mem[nodenr] = value; |
| 743 | } |
| 744 | if (get_param_value(option, 128, "cpus", optarg) == 0) { |
| 745 | node_cpumask[nodenr] = 0; |
| 746 | } else { |
| 747 | value = strtoull(option, &endptr, 10); |
| 748 | if (value >= 64) { |
| 749 | value = 63; |
| 750 | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n"); |
| 751 | } else { |
| 752 | if (*endptr == '-') { |
| 753 | endvalue = strtoull(endptr+1, &endptr, 10); |
| 754 | if (endvalue >= 63) { |
| 755 | endvalue = 62; |
| 756 | fprintf(stderr, |
| 757 | "only 63 CPUs in NUMA mode supported.\n"); |
| 758 | } |
Paolo Bonzini | 0dfbd51 | 2010-02-04 14:31:50 +0100 | [diff] [blame] | 759 | value = (2ULL << endvalue) - (1ULL << value); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 760 | } else { |
Paolo Bonzini | 0dfbd51 | 2010-02-04 14:31:50 +0100 | [diff] [blame] | 761 | value = 1ULL << value; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | node_cpumask[nodenr] = value; |
| 765 | } |
| 766 | nb_numa_nodes++; |
| 767 | } |
| 768 | return; |
| 769 | } |
| 770 | |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 771 | static void smp_parse(const char *optarg) |
| 772 | { |
| 773 | int smp, sockets = 0, threads = 0, cores = 0; |
| 774 | char *endptr; |
| 775 | char option[128]; |
| 776 | |
| 777 | smp = strtoul(optarg, &endptr, 10); |
| 778 | if (endptr != optarg) { |
| 779 | if (*endptr == ',') { |
| 780 | endptr++; |
| 781 | } |
| 782 | } |
| 783 | if (get_param_value(option, 128, "sockets", endptr) != 0) |
| 784 | sockets = strtoull(option, NULL, 10); |
| 785 | if (get_param_value(option, 128, "cores", endptr) != 0) |
| 786 | cores = strtoull(option, NULL, 10); |
| 787 | if (get_param_value(option, 128, "threads", endptr) != 0) |
| 788 | threads = strtoull(option, NULL, 10); |
| 789 | if (get_param_value(option, 128, "maxcpus", endptr) != 0) |
| 790 | max_cpus = strtoull(option, NULL, 10); |
| 791 | |
| 792 | /* compute missing values, prefer sockets over cores over threads */ |
| 793 | if (smp == 0 || sockets == 0) { |
| 794 | sockets = sockets > 0 ? sockets : 1; |
| 795 | cores = cores > 0 ? cores : 1; |
| 796 | threads = threads > 0 ? threads : 1; |
| 797 | if (smp == 0) { |
| 798 | smp = cores * threads * sockets; |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 799 | } |
| 800 | } else { |
| 801 | if (cores == 0) { |
| 802 | threads = threads > 0 ? threads : 1; |
| 803 | cores = smp / (sockets * threads); |
| 804 | } else { |
Joel Schopp | dca9816 | 2010-07-21 15:05:17 -0500 | [diff] [blame] | 805 | threads = smp / (cores * sockets); |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | smp_cpus = smp; |
| 809 | smp_cores = cores > 0 ? cores : 1; |
| 810 | smp_threads = threads > 0 ? threads : 1; |
| 811 | if (max_cpus == 0) |
| 812 | max_cpus = smp_cpus; |
| 813 | } |
| 814 | |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 815 | /***********************************************************/ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 816 | /* USB devices */ |
| 817 | |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 818 | static int usb_device_add(const char *devname) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 819 | { |
| 820 | const char *p; |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 821 | USBDevice *dev = NULL; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 822 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 823 | if (!usb_enabled) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 824 | return -1; |
| 825 | |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 826 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
| 827 | dev = usbdevice_create(devname); |
| 828 | if (dev) |
| 829 | goto done; |
| 830 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 831 | /* the other ones */ |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 832 | if (strstart(devname, "host:", &p)) { |
| 833 | dev = usb_host_device_open(p); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 834 | } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { |
| 835 | dev = usb_bt_init(devname[2] ? hci_init(p) : |
| 836 | bt_new_hci(qemu_find_bt_vlan(0))); |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 837 | } else { |
| 838 | return -1; |
| 839 | } |
pbrook | 0d92ed3 | 2006-05-21 16:30:15 +0000 | [diff] [blame] | 840 | if (!dev) |
| 841 | return -1; |
| 842 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 843 | done: |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 844 | return 0; |
| 845 | } |
| 846 | |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 847 | static int usb_device_del(const char *devname) |
| 848 | { |
| 849 | int bus_num, addr; |
| 850 | const char *p; |
| 851 | |
aliguori | 5d0c575 | 2008-09-14 01:07:41 +0000 | [diff] [blame] | 852 | if (strstart(devname, "host:", &p)) |
| 853 | return usb_host_device_close(p); |
| 854 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 855 | if (!usb_enabled) |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 856 | return -1; |
| 857 | |
| 858 | p = strchr(devname, '.'); |
| 859 | if (!p) |
| 860 | return -1; |
| 861 | bus_num = strtoul(devname, NULL, 0); |
| 862 | addr = strtoul(p + 1, NULL, 0); |
| 863 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 864 | return usb_device_delete_addr(bus_num, addr); |
aliguori | 1f3870a | 2008-08-21 19:27:48 +0000 | [diff] [blame] | 865 | } |
| 866 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 867 | static int usb_parse(const char *cmdline) |
| 868 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 869 | int r; |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 870 | r = usb_device_add(cmdline); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 871 | if (r < 0) { |
| 872 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); |
| 873 | } |
| 874 | return r; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 877 | void do_usb_add(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 878 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 879 | const char *devname = qdict_get_str(qdict, "devname"); |
Markus Armbruster | fb08000 | 2010-05-28 15:38:44 +0200 | [diff] [blame] | 880 | if (usb_device_add(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 881 | error_report("could not add USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 882 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Luiz Capitulino | d54908a | 2009-08-28 15:27:13 -0300 | [diff] [blame] | 885 | void do_usb_del(Monitor *mon, const QDict *qdict) |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 886 | { |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 887 | const char *devname = qdict_get_str(qdict, "devname"); |
| 888 | if (usb_device_del(devname) < 0) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 889 | error_report("could not delete USB device '%s'", devname); |
Scott Tsai | 59d1c1c | 2009-12-23 04:30:18 +0800 | [diff] [blame] | 890 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 891 | } |
| 892 | |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 893 | /***********************************************************/ |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 894 | /* PCMCIA/Cardbus */ |
| 895 | |
| 896 | static struct pcmcia_socket_entry_s { |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 897 | PCMCIASocket *socket; |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 898 | struct pcmcia_socket_entry_s *next; |
| 899 | } *pcmcia_sockets = 0; |
| 900 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 901 | void pcmcia_socket_register(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 902 | { |
| 903 | struct pcmcia_socket_entry_s *entry; |
| 904 | |
| 905 | entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s)); |
| 906 | entry->socket = socket; |
| 907 | entry->next = pcmcia_sockets; |
| 908 | pcmcia_sockets = entry; |
| 909 | } |
| 910 | |
Paul Brook | bc24a22 | 2009-05-10 01:44:56 +0100 | [diff] [blame] | 911 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 912 | { |
| 913 | struct pcmcia_socket_entry_s *entry, **ptr; |
| 914 | |
| 915 | ptr = &pcmcia_sockets; |
| 916 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) |
| 917 | if (entry->socket == socket) { |
| 918 | *ptr = entry->next; |
| 919 | qemu_free(entry); |
| 920 | } |
| 921 | } |
| 922 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 923 | void pcmcia_info(Monitor *mon) |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 924 | { |
| 925 | struct pcmcia_socket_entry_s *iter; |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 926 | |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 927 | if (!pcmcia_sockets) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 928 | monitor_printf(mon, "No PCMCIA sockets\n"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 929 | |
| 930 | for (iter = pcmcia_sockets; iter; iter = iter->next) |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 931 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
| 932 | iter->socket->attached ? iter->socket->card_string : |
| 933 | "Empty"); |
balrog | 201a51f | 2007-04-30 00:51:09 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | /***********************************************************/ |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 937 | /* I/O handling */ |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 938 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 939 | typedef struct IOHandlerRecord { |
| 940 | int fd; |
Juan Quintela | 7b27a76 | 2010-03-11 17:55:39 +0100 | [diff] [blame] | 941 | IOCanReadHandler *fd_read_poll; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 942 | IOHandler *fd_read; |
| 943 | IOHandler *fd_write; |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 944 | int deleted; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 945 | void *opaque; |
| 946 | /* temporary data */ |
| 947 | struct pollfd *ufd; |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 948 | QLIST_ENTRY(IOHandlerRecord) next; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 949 | } IOHandlerRecord; |
| 950 | |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 951 | static QLIST_HEAD(, IOHandlerRecord) io_handlers = |
| 952 | QLIST_HEAD_INITIALIZER(io_handlers); |
| 953 | |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 954 | |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 955 | /* XXX: fd_read_poll should be suppressed, but an API change is |
| 956 | necessary in the character devices to suppress fd_can_read(). */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 957 | int qemu_set_fd_handler2(int fd, |
Juan Quintela | 7b27a76 | 2010-03-11 17:55:39 +0100 | [diff] [blame] | 958 | IOCanReadHandler *fd_read_poll, |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 959 | IOHandler *fd_read, |
| 960 | IOHandler *fd_write, |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 961 | void *opaque) |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 962 | { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 963 | IOHandlerRecord *ioh; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 964 | |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 965 | if (!fd_read && !fd_write) { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 966 | QLIST_FOREACH(ioh, &io_handlers, next) { |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 967 | if (ioh->fd == fd) { |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 968 | ioh->deleted = 1; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 969 | break; |
| 970 | } |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 971 | } |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 972 | } else { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 973 | QLIST_FOREACH(ioh, &io_handlers, next) { |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 974 | if (ioh->fd == fd) |
| 975 | goto found; |
| 976 | } |
| 977 | ioh = qemu_mallocz(sizeof(IOHandlerRecord)); |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 978 | QLIST_INSERT_HEAD(&io_handlers, ioh, next); |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 979 | found: |
| 980 | ioh->fd = fd; |
| 981 | ioh->fd_read_poll = fd_read_poll; |
| 982 | ioh->fd_read = fd_read; |
| 983 | ioh->fd_write = fd_write; |
| 984 | ioh->opaque = opaque; |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 985 | ioh->deleted = 0; |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 986 | } |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 987 | return 0; |
| 988 | } |
| 989 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 990 | int qemu_set_fd_handler(int fd, |
| 991 | IOHandler *fd_read, |
| 992 | IOHandler *fd_write, |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 993 | void *opaque) |
| 994 | { |
| 995 | return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque); |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 996 | } |
| 997 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 998 | /***********************************************************/ |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 999 | /* machine registration */ |
| 1000 | |
blueswir1 | bdaf78e | 2008-10-04 07:24:27 +0000 | [diff] [blame] | 1001 | static QEMUMachine *first_machine = NULL; |
aliguori | 6f338c3 | 2009-02-11 15:21:54 +0000 | [diff] [blame] | 1002 | QEMUMachine *current_machine = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1003 | |
| 1004 | int qemu_register_machine(QEMUMachine *m) |
| 1005 | { |
| 1006 | QEMUMachine **pm; |
| 1007 | pm = &first_machine; |
| 1008 | while (*pm != NULL) |
| 1009 | pm = &(*pm)->next; |
| 1010 | m->next = NULL; |
| 1011 | *pm = m; |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 1015 | static QEMUMachine *find_machine(const char *name) |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1016 | { |
| 1017 | QEMUMachine *m; |
| 1018 | |
| 1019 | for(m = first_machine; m != NULL; m = m->next) { |
| 1020 | if (!strcmp(m->name, name)) |
| 1021 | return m; |
Mark McLoughlin | 3f6599e | 2009-07-22 10:02:50 +0100 | [diff] [blame] | 1022 | if (m->alias && !strcmp(m->alias, name)) |
| 1023 | return m; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1024 | } |
| 1025 | return NULL; |
| 1026 | } |
| 1027 | |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1028 | static QEMUMachine *find_default_machine(void) |
| 1029 | { |
| 1030 | QEMUMachine *m; |
| 1031 | |
| 1032 | for(m = first_machine; m != NULL; m = m->next) { |
| 1033 | if (m->is_default) { |
| 1034 | return m; |
| 1035 | } |
| 1036 | } |
| 1037 | return NULL; |
| 1038 | } |
| 1039 | |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1040 | /***********************************************************/ |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1041 | /* main execution loop */ |
| 1042 | |
pbrook | 9596ebb | 2007-11-18 01:44:38 +0000 | [diff] [blame] | 1043 | static void gui_update(void *opaque) |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1044 | { |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1045 | uint64_t interval = GUI_REFRESH_INTERVAL; |
ths | 740733b | 2007-06-08 01:57:56 +0000 | [diff] [blame] | 1046 | DisplayState *ds = opaque; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1047 | DisplayChangeListener *dcl = ds->listeners; |
| 1048 | |
Sheng Yang | 62a2744 | 2010-01-26 19:21:16 +0800 | [diff] [blame] | 1049 | qemu_flush_coalesced_mmio_buffer(); |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1050 | dpy_refresh(ds); |
| 1051 | |
| 1052 | while (dcl != NULL) { |
| 1053 | if (dcl->gui_timer_interval && |
| 1054 | dcl->gui_timer_interval < interval) |
| 1055 | interval = dcl->gui_timer_interval; |
| 1056 | dcl = dcl->next; |
| 1057 | } |
| 1058 | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock)); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 1061 | static void nographic_update(void *opaque) |
| 1062 | { |
| 1063 | uint64_t interval = GUI_REFRESH_INTERVAL; |
| 1064 | |
Sheng Yang | 62a2744 | 2010-01-26 19:21:16 +0800 | [diff] [blame] | 1065 | qemu_flush_coalesced_mmio_buffer(); |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 1066 | qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock)); |
| 1067 | } |
| 1068 | |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1069 | struct vm_change_state_entry { |
| 1070 | VMChangeStateHandler *cb; |
| 1071 | void *opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1072 | QLIST_ENTRY (vm_change_state_entry) entries; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1073 | }; |
| 1074 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1075 | 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] | 1076 | |
| 1077 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
| 1078 | void *opaque) |
| 1079 | { |
| 1080 | VMChangeStateEntry *e; |
| 1081 | |
| 1082 | e = qemu_mallocz(sizeof (*e)); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1083 | |
| 1084 | e->cb = cb; |
| 1085 | e->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1086 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1087 | return e; |
| 1088 | } |
| 1089 | |
| 1090 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
| 1091 | { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1092 | QLIST_REMOVE (e, entries); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1093 | qemu_free (e); |
| 1094 | } |
| 1095 | |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1096 | void vm_state_notify(int running, int reason) |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1097 | { |
| 1098 | VMChangeStateEntry *e; |
| 1099 | |
| 1100 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
aliguori | 9781e04 | 2009-01-22 17:15:29 +0000 | [diff] [blame] | 1101 | e->cb(e->opaque, running, reason); |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1105 | void vm_start(void) |
| 1106 | { |
| 1107 | if (!vm_running) { |
| 1108 | cpu_enable_ticks(); |
| 1109 | vm_running = 1; |
aliguori | 9781e04 | 2009-01-22 17:15:29 +0000 | [diff] [blame] | 1110 | vm_state_notify(1, 0); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1111 | resume_all_vcpus(); |
Luiz Capitulino | 6ed2c48 | 2010-04-27 20:35:59 -0300 | [diff] [blame] | 1112 | monitor_protocol_event(QEVENT_RESUME, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1116 | /* reset/shutdown handler */ |
| 1117 | |
| 1118 | typedef struct QEMUResetEntry { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1119 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1120 | QEMUResetHandler *func; |
| 1121 | void *opaque; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1122 | } QEMUResetEntry; |
| 1123 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1124 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
| 1125 | QTAILQ_HEAD_INITIALIZER(reset_handlers); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1126 | static int reset_requested; |
| 1127 | static int shutdown_requested; |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1128 | static int powerdown_requested; |
Blue Swirl | 296af7c | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1129 | int debug_requested; |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 1130 | int vmstop_requested; |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1131 | |
aurel32 | cf7a2fe | 2008-03-18 06:53:05 +0000 | [diff] [blame] | 1132 | int qemu_shutdown_requested(void) |
| 1133 | { |
| 1134 | int r = shutdown_requested; |
| 1135 | shutdown_requested = 0; |
| 1136 | return r; |
| 1137 | } |
| 1138 | |
| 1139 | int qemu_reset_requested(void) |
| 1140 | { |
| 1141 | int r = reset_requested; |
| 1142 | reset_requested = 0; |
| 1143 | return r; |
| 1144 | } |
| 1145 | |
| 1146 | int qemu_powerdown_requested(void) |
| 1147 | { |
| 1148 | int r = powerdown_requested; |
| 1149 | powerdown_requested = 0; |
| 1150 | return r; |
| 1151 | } |
| 1152 | |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1153 | static int qemu_debug_requested(void) |
| 1154 | { |
| 1155 | int r = debug_requested; |
| 1156 | debug_requested = 0; |
| 1157 | return r; |
| 1158 | } |
| 1159 | |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1160 | static int qemu_vmstop_requested(void) |
| 1161 | { |
| 1162 | int r = vmstop_requested; |
| 1163 | vmstop_requested = 0; |
| 1164 | return r; |
| 1165 | } |
| 1166 | |
Jan Kiszka | a08d436 | 2009-06-27 09:25:07 +0200 | [diff] [blame] | 1167 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1168 | { |
Jan Kiszka | 55ddfe8 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1169 | QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry)); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1170 | |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1171 | re->func = func; |
| 1172 | re->opaque = opaque; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1173 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1176 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1177 | { |
| 1178 | QEMUResetEntry *re; |
| 1179 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1180 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1181 | if (re->func == func && re->opaque == opaque) { |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1182 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
Jan Kiszka | dda9b29 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 1183 | qemu_free(re); |
| 1184 | return; |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | void qemu_system_reset(void) |
| 1190 | { |
| 1191 | QEMUResetEntry *re, *nre; |
| 1192 | |
| 1193 | /* reset all devices */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1194 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1195 | re->func(re->opaque); |
| 1196 | } |
Luiz Capitulino | 81d9b78 | 2010-03-10 09:06:34 -0600 | [diff] [blame] | 1197 | monitor_protocol_event(QEVENT_RESET, NULL); |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 1198 | cpu_synchronize_all_post_reset(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | void qemu_system_reset_request(void) |
| 1202 | { |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 1203 | if (no_reboot) { |
| 1204 | shutdown_requested = 1; |
| 1205 | } else { |
| 1206 | reset_requested = 1; |
| 1207 | } |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1208 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | void qemu_system_shutdown_request(void) |
| 1212 | { |
| 1213 | shutdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1214 | qemu_notify_event(); |
bellard | bb0c672 | 2004-06-20 12:37:32 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 1217 | void qemu_system_powerdown_request(void) |
| 1218 | { |
| 1219 | powerdown_requested = 1; |
aliguori | d9f75a4 | 2009-04-24 18:03:11 +0000 | [diff] [blame] | 1220 | qemu_notify_event(); |
| 1221 | } |
| 1222 | |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1223 | void main_loop_wait(int nonblocking) |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1224 | { |
| 1225 | IOHandlerRecord *ioh; |
| 1226 | fd_set rfds, wfds, xfds; |
| 1227 | int ret, nfds; |
| 1228 | struct timeval tv; |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1229 | int timeout; |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1230 | |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1231 | if (nonblocking) |
| 1232 | timeout = 0; |
| 1233 | else { |
| 1234 | timeout = qemu_calculate_timeout(); |
| 1235 | qemu_bh_update_timeout(&timeout); |
| 1236 | } |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1237 | |
Jes Sorensen | 0d93ca7 | 2010-06-10 11:42:18 +0200 | [diff] [blame] | 1238 | os_host_main_loop_wait(&timeout); |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1239 | |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1240 | /* poll any events */ |
| 1241 | /* XXX: separate device handlers from system ones */ |
aliguori | 6abfbd7 | 2008-11-05 20:49:37 +0000 | [diff] [blame] | 1242 | nfds = -1; |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1243 | FD_ZERO(&rfds); |
| 1244 | FD_ZERO(&wfds); |
bellard | e035649 | 2006-05-01 13:33:02 +0000 | [diff] [blame] | 1245 | FD_ZERO(&xfds); |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1246 | QLIST_FOREACH(ioh, &io_handlers, next) { |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1247 | if (ioh->deleted) |
| 1248 | continue; |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1249 | if (ioh->fd_read && |
| 1250 | (!ioh->fd_read_poll || |
| 1251 | ioh->fd_read_poll(ioh->opaque) != 0)) { |
| 1252 | FD_SET(ioh->fd, &rfds); |
| 1253 | if (ioh->fd > nfds) |
| 1254 | nfds = ioh->fd; |
| 1255 | } |
| 1256 | if (ioh->fd_write) { |
| 1257 | FD_SET(ioh->fd, &wfds); |
| 1258 | if (ioh->fd > nfds) |
| 1259 | nfds = ioh->fd; |
| 1260 | } |
| 1261 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1262 | |
aliguori | 56f3a5d | 2008-10-31 18:07:17 +0000 | [diff] [blame] | 1263 | tv.tv_sec = timeout / 1000; |
| 1264 | tv.tv_usec = (timeout % 1000) * 1000; |
| 1265 | |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 1266 | slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
| 1267 | |
aliguori | 4870852 | 2009-04-24 18:03:49 +0000 | [diff] [blame] | 1268 | qemu_mutex_unlock_iothread(); |
bellard | e035649 | 2006-05-01 13:33:02 +0000 | [diff] [blame] | 1269 | ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); |
aliguori | 4870852 | 2009-04-24 18:03:49 +0000 | [diff] [blame] | 1270 | qemu_mutex_lock_iothread(); |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1271 | if (ret > 0) { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1272 | IOHandlerRecord *pioh; |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1273 | |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1274 | QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1275 | if (ioh->deleted) { |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1276 | QLIST_REMOVE(ioh, next); |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1277 | qemu_free(ioh); |
Juan Quintela | 4bed983 | 2010-03-11 17:55:41 +0100 | [diff] [blame] | 1278 | continue; |
| 1279 | } |
| 1280 | if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { |
| 1281 | ioh->fd_read(ioh->opaque); |
| 1282 | } |
| 1283 | if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) { |
| 1284 | ioh->fd_write(ioh->opaque); |
Juan Quintela | 31d4ee6 | 2010-03-11 17:55:37 +0100 | [diff] [blame] | 1285 | } |
ths | cafffd4 | 2007-02-28 21:59:44 +0000 | [diff] [blame] | 1286 | } |
bellard | fd1dff4 | 2006-02-01 21:29:26 +0000 | [diff] [blame] | 1287 | } |
Jan Kiszka | d918f23 | 2009-06-24 14:42:30 +0200 | [diff] [blame] | 1288 | |
| 1289 | slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0)); |
bellard | c20709a | 2004-04-21 23:27:19 +0000 | [diff] [blame] | 1290 | |
Paolo Bonzini | b696482 | 2010-03-10 11:38:45 +0100 | [diff] [blame] | 1291 | qemu_run_all_timers(); |
Jan Kiszka | 21d5d12 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 1292 | |
pbrook | 423f074 | 2007-05-23 00:06:54 +0000 | [diff] [blame] | 1293 | /* Check bottom-halves last in case any of the earlier events triggered |
| 1294 | them. */ |
| 1295 | qemu_bh_poll(); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1296 | |
bellard | 5905b2e | 2004-08-01 21:53:26 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1299 | static int vm_can_run(void) |
| 1300 | { |
| 1301 | if (powerdown_requested) |
| 1302 | return 0; |
| 1303 | if (reset_requested) |
| 1304 | return 0; |
| 1305 | if (shutdown_requested) |
| 1306 | return 0; |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1307 | if (debug_requested) |
| 1308 | return 0; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1309 | return 1; |
| 1310 | } |
| 1311 | |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1312 | qemu_irq qemu_system_powerdown; |
| 1313 | |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1314 | static void main_loop(void) |
| 1315 | { |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1316 | int r; |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1317 | |
Blue Swirl | 7277e02 | 2010-04-12 17:19:06 +0000 | [diff] [blame] | 1318 | qemu_main_loop_start(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1319 | |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1320 | for (;;) { |
aliguori | e6e35b1 | 2009-04-24 18:03:57 +0000 | [diff] [blame] | 1321 | do { |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1322 | bool nonblocking = false; |
aliguori | e6e35b1 | 2009-04-24 18:03:57 +0000 | [diff] [blame] | 1323 | #ifdef CONFIG_PROFILER |
| 1324 | int64_t ti; |
| 1325 | #endif |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1326 | #ifndef CONFIG_IOTHREAD |
Jan Kiszka | 472fb0c | 2010-06-25 16:56:55 +0200 | [diff] [blame] | 1327 | nonblocking = cpu_exec_all(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1328 | #endif |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1329 | #ifdef CONFIG_PROFILER |
| 1330 | ti = profile_getclock(); |
| 1331 | #endif |
Paolo Bonzini | d6f4ade | 2010-03-10 11:38:54 +0100 | [diff] [blame] | 1332 | main_loop_wait(nonblocking); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1333 | #ifdef CONFIG_PROFILER |
| 1334 | dev_time += profile_getclock() - ti; |
| 1335 | #endif |
aliguori | e568902 | 2009-04-24 18:03:54 +0000 | [diff] [blame] | 1336 | } while (vm_can_run()); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1337 | |
Blue Swirl | 54fc6ea | 2010-03-29 19:23:46 +0000 | [diff] [blame] | 1338 | if ((r = qemu_debug_requested())) { |
| 1339 | vm_stop(r); |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 1340 | } |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1341 | if (qemu_shutdown_requested()) { |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 1342 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1343 | if (no_shutdown) { |
| 1344 | vm_stop(0); |
| 1345 | no_shutdown = 0; |
| 1346 | } else |
| 1347 | break; |
| 1348 | } |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1349 | if (qemu_reset_requested()) { |
| 1350 | pause_all_vcpus(); |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1351 | qemu_system_reset(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1352 | resume_all_vcpus(); |
| 1353 | } |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1354 | if (qemu_powerdown_requested()) { |
Blue Swirl | 242cd00 | 2009-12-04 18:05:45 +0000 | [diff] [blame] | 1355 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); |
Blue Swirl | d9c3231 | 2009-08-09 08:42:19 +0000 | [diff] [blame] | 1356 | qemu_irq_raise(qemu_system_powerdown); |
| 1357 | } |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 1358 | if ((r = qemu_vmstop_requested())) { |
aliguori | 6e29f5d | 2009-04-24 18:04:02 +0000 | [diff] [blame] | 1359 | vm_stop(r); |
Luiz Capitulino | b1a15e7 | 2009-11-26 22:59:04 -0200 | [diff] [blame] | 1360 | } |
aliguori | 43b9685 | 2009-04-24 18:03:33 +0000 | [diff] [blame] | 1361 | } |
MORITA Kazutaka | 2bc93fe | 2010-05-28 11:44:57 +0900 | [diff] [blame] | 1362 | bdrv_close_all(); |
aliguori | d6dc3d4 | 2009-04-24 18:04:07 +0000 | [diff] [blame] | 1363 | pause_all_vcpus(); |
bellard | b4608c0 | 2003-06-27 17:34:32 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 1366 | static void version(void) |
| 1367 | { |
Thomas Monjalon | f75ca1a | 2010-04-28 14:42:01 +0200 | [diff] [blame] | 1368 | 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] | 1369 | } |
| 1370 | |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1371 | static void help(int exitcode) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1372 | { |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1373 | const char *options_help = |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1374 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ |
| 1375 | opt_help |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1376 | #define DEFHEADING(text) stringify(text) "\n" |
Jes Sorensen | 9f16732 | 2010-06-10 11:42:24 +0200 | [diff] [blame] | 1377 | #include "qemu-options.def" |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1378 | #undef DEF |
| 1379 | #undef DEFHEADING |
| 1380 | #undef GEN_DOCS |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1381 | ; |
| 1382 | version(); |
| 1383 | printf("usage: %s [options] [disk_image]\n" |
malc | 3f020d7 | 2010-02-08 12:04:56 +0300 | [diff] [blame] | 1384 | "\n" |
Thomas Monjalon | f75ca1a | 2010-04-28 14:42:01 +0200 | [diff] [blame] | 1385 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n" |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1386 | "\n" |
| 1387 | "%s\n" |
malc | 3f020d7 | 2010-02-08 12:04:56 +0300 | [diff] [blame] | 1388 | "During emulation, the following keys are useful:\n" |
| 1389 | "ctrl-alt-f toggle full screen\n" |
| 1390 | "ctrl-alt-n switch to virtual console 'n'\n" |
| 1391 | "ctrl-alt toggle mouse and keyboard grab\n" |
| 1392 | "\n" |
Paolo Bonzini | e8105eb | 2010-02-04 16:49:59 +0100 | [diff] [blame] | 1393 | "When using -nographic, press 'ctrl-a h' to get some help.\n", |
| 1394 | "qemu", |
| 1395 | options_help); |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1396 | exit(exitcode); |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1399 | #define HAS_ARG 0x0001 |
| 1400 | |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1401 | typedef struct QEMUOption { |
| 1402 | const char *name; |
| 1403 | int flags; |
| 1404 | int index; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1405 | uint32_t arch_mask; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1406 | } QEMUOption; |
| 1407 | |
blueswir1 | dbed7e4 | 2008-10-01 19:38:09 +0000 | [diff] [blame] | 1408 | static const QEMUOption qemu_options[] = { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1409 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
| 1410 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ |
| 1411 | { option, opt_arg, opt_enum, arch_mask }, |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1412 | #define DEFHEADING(text) |
Jes Sorensen | 9f16732 | 2010-06-10 11:42:24 +0200 | [diff] [blame] | 1413 | #include "qemu-options.def" |
blueswir1 | 5824d65 | 2009-03-28 06:44:27 +0000 | [diff] [blame] | 1414 | #undef DEF |
| 1415 | #undef DEFHEADING |
| 1416 | #undef GEN_DOCS |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1417 | { NULL }, |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1418 | }; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1419 | static void select_vgahw (const char *p) |
| 1420 | { |
| 1421 | const char *opts; |
| 1422 | |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 1423 | default_vga = 0; |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1424 | vga_interface_type = VGA_NONE; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1425 | if (strstart(p, "std", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1426 | vga_interface_type = VGA_STD; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1427 | } else if (strstart(p, "cirrus", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1428 | vga_interface_type = VGA_CIRRUS; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1429 | } else if (strstart(p, "vmware", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1430 | vga_interface_type = VGA_VMWARE; |
aliguori | 94909d9 | 2009-04-22 15:19:53 +0000 | [diff] [blame] | 1431 | } else if (strstart(p, "xenfb", &opts)) { |
Zachary Amsden | 8617675 | 2009-07-30 00:15:02 -1000 | [diff] [blame] | 1432 | vga_interface_type = VGA_XENFB; |
aliguori | 28b85ed | 2009-04-22 15:19:48 +0000 | [diff] [blame] | 1433 | } else if (!strstart(p, "none", &opts)) { |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1434 | invalid_vga: |
| 1435 | fprintf(stderr, "Unknown vga type: %s\n", p); |
| 1436 | exit(1); |
| 1437 | } |
malc | cb5a7aa | 2008-09-28 00:42:12 +0000 | [diff] [blame] | 1438 | while (*opts) { |
| 1439 | const char *nextopt; |
| 1440 | |
| 1441 | if (strstart(opts, ",retrace=", &nextopt)) { |
| 1442 | opts = nextopt; |
| 1443 | if (strstart(opts, "dumb", &nextopt)) |
| 1444 | vga_retrace_method = VGA_RETRACE_DUMB; |
| 1445 | else if (strstart(opts, "precise", &nextopt)) |
| 1446 | vga_retrace_method = VGA_RETRACE_PRECISE; |
| 1447 | else goto invalid_vga; |
| 1448 | } else goto invalid_vga; |
| 1449 | opts = nextopt; |
| 1450 | } |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1453 | static int balloon_parse(const char *arg) |
| 1454 | { |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1455 | QemuOpts *opts; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1456 | |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1457 | if (strcmp(arg, "none") == 0) { |
| 1458 | return 0; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1459 | } |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1460 | |
| 1461 | if (!strncmp(arg, "virtio", 6)) { |
| 1462 | if (arg[6] == ',') { |
| 1463 | /* have params -> parse them */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1464 | opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1465 | if (!opts) |
| 1466 | return -1; |
| 1467 | } else { |
| 1468 | /* create empty opts */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1469 | opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0); |
Gerd Hoffmann | 382f074 | 2009-08-14 10:34:22 +0200 | [diff] [blame] | 1470 | } |
| 1471 | qemu_opt_set(opts, "driver", "virtio-balloon-pci"); |
| 1472 | return 0; |
| 1473 | } |
| 1474 | |
| 1475 | return -1; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1476 | } |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 1477 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1478 | char *qemu_find_file(int type, const char *name) |
| 1479 | { |
| 1480 | int len; |
| 1481 | const char *subdir; |
| 1482 | char *buf; |
| 1483 | |
| 1484 | /* If name contains path separators then try it as a straight path. */ |
| 1485 | if ((strchr(name, '/') || strchr(name, '\\')) |
| 1486 | && access(name, R_OK) == 0) { |
Jean-Christophe DUBOIS | 73ffc80 | 2009-09-02 23:59:06 +0200 | [diff] [blame] | 1487 | return qemu_strdup(name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1488 | } |
| 1489 | switch (type) { |
| 1490 | case QEMU_FILE_TYPE_BIOS: |
| 1491 | subdir = ""; |
| 1492 | break; |
| 1493 | case QEMU_FILE_TYPE_KEYMAP: |
| 1494 | subdir = "keymaps/"; |
| 1495 | break; |
| 1496 | default: |
| 1497 | abort(); |
| 1498 | } |
| 1499 | len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; |
| 1500 | buf = qemu_mallocz(len); |
Blue Swirl | 3a41759 | 2009-06-09 19:12:21 +0000 | [diff] [blame] | 1501 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 1502 | if (access(buf, R_OK)) { |
| 1503 | qemu_free(buf); |
| 1504 | return NULL; |
| 1505 | } |
| 1506 | return buf; |
| 1507 | } |
| 1508 | |
Markus Armbruster | ff952ba | 2010-01-29 19:48:57 +0100 | [diff] [blame] | 1509 | static int device_help_func(QemuOpts *opts, void *opaque) |
| 1510 | { |
| 1511 | return qdev_device_help(opts); |
| 1512 | } |
| 1513 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 1514 | static int device_init_func(QemuOpts *opts, void *opaque) |
| 1515 | { |
| 1516 | DeviceState *dev; |
| 1517 | |
| 1518 | dev = qdev_device_add(opts); |
| 1519 | if (!dev) |
| 1520 | return -1; |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 1524 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
| 1525 | { |
| 1526 | CharDriverState *chr; |
| 1527 | |
| 1528 | chr = qemu_chr_open_opts(opts, NULL); |
| 1529 | if (!chr) |
| 1530 | return -1; |
| 1531 | return 0; |
| 1532 | } |
| 1533 | |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 1534 | #ifdef CONFIG_VIRTFS |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 1535 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
| 1536 | { |
| 1537 | int ret; |
| 1538 | ret = qemu_fsdev_add(opts); |
| 1539 | |
| 1540 | return ret; |
| 1541 | } |
| 1542 | #endif |
| 1543 | |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1544 | static int mon_init_func(QemuOpts *opts, void *opaque) |
| 1545 | { |
| 1546 | CharDriverState *chr; |
| 1547 | const char *chardev; |
| 1548 | const char *mode; |
| 1549 | int flags; |
| 1550 | |
| 1551 | mode = qemu_opt_get(opts, "mode"); |
| 1552 | if (mode == NULL) { |
| 1553 | mode = "readline"; |
| 1554 | } |
| 1555 | if (strcmp(mode, "readline") == 0) { |
| 1556 | flags = MONITOR_USE_READLINE; |
| 1557 | } else if (strcmp(mode, "control") == 0) { |
| 1558 | flags = MONITOR_USE_CONTROL; |
| 1559 | } else { |
| 1560 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); |
| 1561 | exit(1); |
| 1562 | } |
| 1563 | |
| 1564 | if (qemu_opt_get_bool(opts, "default", 0)) |
| 1565 | flags |= MONITOR_IS_DEFAULT; |
| 1566 | |
| 1567 | chardev = qemu_opt_get(opts, "chardev"); |
| 1568 | chr = qemu_chr_find(chardev); |
| 1569 | if (chr == NULL) { |
| 1570 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); |
| 1571 | exit(1); |
| 1572 | } |
| 1573 | |
| 1574 | monitor_init(chr, flags); |
| 1575 | return 0; |
| 1576 | } |
| 1577 | |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 1578 | static void monitor_parse(const char *optarg, const char *mode) |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1579 | { |
| 1580 | static int monitor_device_index = 0; |
| 1581 | QemuOpts *opts; |
| 1582 | const char *p; |
| 1583 | char label[32]; |
| 1584 | int def = 0; |
| 1585 | |
| 1586 | if (strstart(optarg, "chardev:", &p)) { |
| 1587 | snprintf(label, sizeof(label), "%s", p); |
| 1588 | } else { |
Jan Kiszka | 140e065 | 2010-04-06 16:55:52 +0200 | [diff] [blame] | 1589 | snprintf(label, sizeof(label), "compat_monitor%d", |
| 1590 | monitor_device_index); |
| 1591 | if (monitor_device_index == 0) { |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1592 | def = 1; |
| 1593 | } |
| 1594 | opts = qemu_chr_parse_compat(label, optarg); |
| 1595 | if (!opts) { |
| 1596 | fprintf(stderr, "parse error: %s\n", optarg); |
| 1597 | exit(1); |
| 1598 | } |
| 1599 | } |
| 1600 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1601 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1602 | if (!opts) { |
| 1603 | fprintf(stderr, "duplicate chardev: %s\n", label); |
| 1604 | exit(1); |
| 1605 | } |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 1606 | qemu_opt_set(opts, "mode", mode); |
Gerd Hoffmann | 8858934 | 2009-12-08 13:11:50 +0100 | [diff] [blame] | 1607 | qemu_opt_set(opts, "chardev", label); |
| 1608 | if (def) |
| 1609 | qemu_opt_set(opts, "default", "on"); |
| 1610 | monitor_device_index++; |
| 1611 | } |
| 1612 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1613 | struct device_config { |
| 1614 | enum { |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1615 | DEV_USB, /* -usbdevice */ |
| 1616 | DEV_BT, /* -bt */ |
| 1617 | DEV_SERIAL, /* -serial */ |
| 1618 | DEV_PARALLEL, /* -parallel */ |
| 1619 | DEV_VIRTCON, /* -virtioconsole */ |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1620 | DEV_DEBUGCON, /* -debugcon */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1621 | } type; |
| 1622 | const char *cmdline; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1623 | QTAILQ_ENTRY(device_config) next; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1624 | }; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1625 | QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1626 | |
| 1627 | static void add_device_config(int type, const char *cmdline) |
| 1628 | { |
| 1629 | struct device_config *conf; |
| 1630 | |
| 1631 | conf = qemu_mallocz(sizeof(*conf)); |
| 1632 | conf->type = type; |
| 1633 | conf->cmdline = cmdline; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1634 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) |
| 1638 | { |
| 1639 | struct device_config *conf; |
| 1640 | int rc; |
| 1641 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1642 | QTAILQ_FOREACH(conf, &device_configs, next) { |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 1643 | if (conf->type != type) |
| 1644 | continue; |
| 1645 | rc = func(conf->cmdline); |
| 1646 | if (0 != rc) |
| 1647 | return rc; |
| 1648 | } |
| 1649 | return 0; |
| 1650 | } |
| 1651 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 1652 | static int serial_parse(const char *devname) |
| 1653 | { |
| 1654 | static int index = 0; |
| 1655 | char label[32]; |
| 1656 | |
| 1657 | if (strcmp(devname, "none") == 0) |
| 1658 | return 0; |
| 1659 | if (index == MAX_SERIAL_PORTS) { |
| 1660 | fprintf(stderr, "qemu: too many serial ports\n"); |
| 1661 | exit(1); |
| 1662 | } |
| 1663 | snprintf(label, sizeof(label), "serial%d", index); |
| 1664 | serial_hds[index] = qemu_chr_open(label, devname, NULL); |
| 1665 | if (!serial_hds[index]) { |
| 1666 | fprintf(stderr, "qemu: could not open serial device '%s': %s\n", |
| 1667 | devname, strerror(errno)); |
| 1668 | return -1; |
| 1669 | } |
| 1670 | index++; |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 1674 | static int parallel_parse(const char *devname) |
| 1675 | { |
| 1676 | static int index = 0; |
| 1677 | char label[32]; |
| 1678 | |
| 1679 | if (strcmp(devname, "none") == 0) |
| 1680 | return 0; |
| 1681 | if (index == MAX_PARALLEL_PORTS) { |
| 1682 | fprintf(stderr, "qemu: too many parallel ports\n"); |
| 1683 | exit(1); |
| 1684 | } |
| 1685 | snprintf(label, sizeof(label), "parallel%d", index); |
| 1686 | parallel_hds[index] = qemu_chr_open(label, devname, NULL); |
| 1687 | if (!parallel_hds[index]) { |
| 1688 | fprintf(stderr, "qemu: could not open parallel device '%s': %s\n", |
| 1689 | devname, strerror(errno)); |
| 1690 | return -1; |
| 1691 | } |
| 1692 | index++; |
| 1693 | return 0; |
| 1694 | } |
| 1695 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1696 | static int virtcon_parse(const char *devname) |
| 1697 | { |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1698 | QemuOptsList *device = qemu_find_opts("device"); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1699 | static int index = 0; |
| 1700 | char label[32]; |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1701 | QemuOpts *bus_opts, *dev_opts; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1702 | |
| 1703 | if (strcmp(devname, "none") == 0) |
| 1704 | return 0; |
| 1705 | if (index == MAX_VIRTIO_CONSOLES) { |
| 1706 | fprintf(stderr, "qemu: too many virtio consoles\n"); |
| 1707 | exit(1); |
| 1708 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1709 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1710 | bus_opts = qemu_opts_create(device, NULL, 0); |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1711 | qemu_opt_set(bus_opts, "driver", "virtio-serial"); |
| 1712 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1713 | dev_opts = qemu_opts_create(device, NULL, 0); |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1714 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
| 1715 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1716 | snprintf(label, sizeof(label), "virtcon%d", index); |
| 1717 | virtcon_hds[index] = qemu_chr_open(label, devname, NULL); |
| 1718 | if (!virtcon_hds[index]) { |
| 1719 | fprintf(stderr, "qemu: could not open virtio console '%s': %s\n", |
| 1720 | devname, strerror(errno)); |
| 1721 | return -1; |
| 1722 | } |
Amit Shah | 392ecf5 | 2010-01-21 16:19:23 +0530 | [diff] [blame] | 1723 | qemu_opt_set(dev_opts, "chardev", label); |
| 1724 | |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 1725 | index++; |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1729 | static int debugcon_parse(const char *devname) |
| 1730 | { |
| 1731 | QemuOpts *opts; |
| 1732 | |
| 1733 | if (!qemu_chr_open("debugcon", devname, NULL)) { |
| 1734 | exit(1); |
| 1735 | } |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1736 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 1737 | if (!opts) { |
| 1738 | fprintf(stderr, "qemu: already have a debugcon device\n"); |
| 1739 | exit(1); |
| 1740 | } |
| 1741 | qemu_opt_set(opts, "driver", "isa-debugcon"); |
| 1742 | qemu_opt_set(opts, "chardev", "debugcon"); |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 1746 | void qemu_add_exit_notifier(Notifier *notify) |
| 1747 | { |
| 1748 | notifier_list_add(&exit_notifiers, notify); |
| 1749 | } |
| 1750 | |
| 1751 | void qemu_remove_exit_notifier(Notifier *notify) |
| 1752 | { |
| 1753 | notifier_list_remove(&exit_notifiers, notify); |
| 1754 | } |
| 1755 | |
| 1756 | static void qemu_run_exit_notifiers(void) |
| 1757 | { |
| 1758 | notifier_list_notify(&exit_notifiers); |
| 1759 | } |
| 1760 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1761 | static const QEMUOption *lookup_opt(int argc, char **argv, |
| 1762 | const char **poptarg, int *poptind) |
| 1763 | { |
| 1764 | const QEMUOption *popt; |
| 1765 | int optind = *poptind; |
| 1766 | char *r = argv[optind]; |
| 1767 | const char *optarg; |
| 1768 | |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1769 | loc_set_cmdline(argv, optind, 1); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1770 | optind++; |
| 1771 | /* Treat --foo the same as -foo. */ |
| 1772 | if (r[1] == '-') |
| 1773 | r++; |
| 1774 | popt = qemu_options; |
| 1775 | for(;;) { |
| 1776 | if (!popt->name) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1777 | error_report("invalid option"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1778 | exit(1); |
| 1779 | } |
| 1780 | if (!strcmp(popt->name, r + 1)) |
| 1781 | break; |
| 1782 | popt++; |
| 1783 | } |
| 1784 | if (popt->flags & HAS_ARG) { |
| 1785 | if (optind >= argc) { |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1786 | error_report("requires an argument"); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1787 | exit(1); |
| 1788 | } |
| 1789 | optarg = argv[optind++]; |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 1790 | loc_set_cmdline(argv, optind - 2, 2); |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1791 | } else { |
| 1792 | optarg = NULL; |
| 1793 | } |
| 1794 | |
| 1795 | *poptarg = optarg; |
| 1796 | *poptind = optind; |
| 1797 | |
| 1798 | return popt; |
| 1799 | } |
| 1800 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 1801 | int main(int argc, char **argv, char **envp) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1802 | { |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 1803 | const char *gdbstub_dev = NULL; |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1804 | int i; |
Eduardo Habkost | da1fcfd | 2010-04-06 19:22:07 -0300 | [diff] [blame] | 1805 | int snapshot, linux_boot; |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 1806 | const char *icount_option = NULL; |
bellard | 7f7f987 | 2003-10-30 01:11:23 +0000 | [diff] [blame] | 1807 | const char *initrd_filename; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 1808 | const char *kernel_filename, *kernel_cmdline; |
Anthony Liguori | 195325a | 2009-10-30 12:42:29 -0500 | [diff] [blame] | 1809 | char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 1810 | DisplayState *ds; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 1811 | DisplayChangeListener *dcl; |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1812 | int cyls, heads, secs, translation; |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 1813 | QemuOpts *hda_opts = NULL, *opts; |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 1814 | QemuOptsList *olist; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1815 | int optind; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1816 | const char *optarg; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 1817 | const char *loadvm = NULL; |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1818 | QEMUMachine *machine; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1819 | const char *cpu_model; |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 1820 | int tb_size; |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 1821 | const char *pid_file = NULL; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 1822 | const char *incoming = NULL; |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 1823 | int show_vnc_port = 0; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1824 | int defconfig = 1; |
bellard | 0bd4885 | 2005-11-11 00:00:47 +0000 | [diff] [blame] | 1825 | |
Gerd Hoffmann | fd42dee | 2010-06-04 14:08:07 +0200 | [diff] [blame] | 1826 | atexit(qemu_run_exit_notifiers); |
Markus Armbruster | 65abca0 | 2010-02-24 14:37:14 +0100 | [diff] [blame] | 1827 | error_set_progname(argv[0]); |
| 1828 | |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 1829 | init_clocks(); |
| 1830 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 1831 | qemu_cache_utils_init(envp); |
| 1832 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 1833 | QLIST_INIT (&vm_change_state_head); |
Jes Sorensen | fe98ac1 | 2010-06-10 11:42:21 +0200 | [diff] [blame] | 1834 | os_setup_early_signal_handling(); |
bellard | be995c2 | 2006-06-25 16:25:21 +0000 | [diff] [blame] | 1835 | |
Anthony Liguori | f80f9ec | 2009-05-20 18:38:09 -0500 | [diff] [blame] | 1836 | module_call_init(MODULE_INIT_MACHINE); |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1837 | machine = find_default_machine(); |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1838 | cpu_model = NULL; |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1839 | initrd_filename = NULL; |
aurel32 | 4fc5d07 | 2008-04-27 21:39:40 +0000 | [diff] [blame] | 1840 | ram_size = 0; |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 1841 | snapshot = 0; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 1842 | kernel_filename = NULL; |
| 1843 | kernel_cmdline = ""; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 1844 | cyls = heads = secs = 0; |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1845 | translation = BIOS_ATA_TRANSLATION_AUTO; |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 1846 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1847 | for (i = 0; i < MAX_NODES; i++) { |
| 1848 | node_mem[i] = 0; |
| 1849 | node_cpumask[i] = 0; |
| 1850 | } |
| 1851 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 1852 | nb_numa_nodes = 0; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 1853 | nb_nics = 0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1854 | |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 1855 | tb_size = 0; |
blueswir1 | 41bd639 | 2008-10-05 09:56:21 +0000 | [diff] [blame] | 1856 | autostart= 1; |
| 1857 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 1858 | #ifdef CONFIG_VIRTFS |
| 1859 | qemu_add_opts(&qemu_fsdev_opts); |
| 1860 | qemu_add_opts(&qemu_virtfs_opts); |
| 1861 | #endif |
| 1862 | |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1863 | /* first pass of option parsing */ |
| 1864 | optind = 1; |
| 1865 | while (optind < argc) { |
| 1866 | if (argv[optind][0] != '-') { |
| 1867 | /* disk image */ |
Anthony Liguori | 28e68d6 | 2010-01-27 10:46:00 -0600 | [diff] [blame] | 1868 | optind++; |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1869 | continue; |
| 1870 | } else { |
| 1871 | const QEMUOption *popt; |
| 1872 | |
| 1873 | popt = lookup_opt(argc, argv, &optarg, &optind); |
| 1874 | switch (popt->index) { |
| 1875 | case QEMU_OPTION_nodefconfig: |
| 1876 | defconfig=0; |
| 1877 | break; |
| 1878 | } |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | if (defconfig) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1883 | int ret; |
Markus Armbruster | cf5a65a | 2010-02-18 19:48:33 +0100 | [diff] [blame] | 1884 | |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1885 | ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
Kevin Wolf | 019e78b | 2010-05-17 10:36:47 +0200 | [diff] [blame] | 1886 | if (ret < 0 && ret != -ENOENT) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1887 | exit(1); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1888 | } |
| 1889 | |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1890 | ret = qemu_read_config_file(arch_config_name); |
Kevin Wolf | 019e78b | 2010-05-17 10:36:47 +0200 | [diff] [blame] | 1891 | if (ret < 0 && ret != -ENOENT) { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 1892 | exit(1); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1893 | } |
| 1894 | } |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 1895 | cpudef_init(); |
Anthony Liguori | 292444c | 2010-01-21 10:57:58 -0600 | [diff] [blame] | 1896 | |
| 1897 | /* second pass of option parsing */ |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1898 | optind = 1; |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1899 | for(;;) { |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1900 | if (optind >= argc) |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 1901 | break; |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1902 | if (argv[optind][0] != '-') { |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1903 | hda_opts = drive_add(argv[optind++], HD_ALIAS, 0); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1904 | } else { |
| 1905 | const QEMUOption *popt; |
| 1906 | |
Anthony Liguori | 6530a97 | 2010-01-22 09:18:06 -0600 | [diff] [blame] | 1907 | popt = lookup_opt(argc, argv, &optarg, &optind); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1908 | if (!(popt->arch_mask & arch_type)) { |
| 1909 | printf("Option %s not supported for this target\n", popt->name); |
| 1910 | exit(1); |
| 1911 | } |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1912 | switch(popt->index) { |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1913 | case QEMU_OPTION_M: |
| 1914 | machine = find_machine(optarg); |
| 1915 | if (!machine) { |
| 1916 | QEMUMachine *m; |
| 1917 | printf("Supported machines are:\n"); |
| 1918 | for(m = first_machine; m != NULL; m = m->next) { |
Mark McLoughlin | 3f6599e | 2009-07-22 10:02:50 +0100 | [diff] [blame] | 1919 | if (m->alias) |
| 1920 | printf("%-10s %s (alias of %s)\n", |
| 1921 | m->alias, m->desc, m->name); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1922 | printf("%-10s %s%s\n", |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1923 | m->name, m->desc, |
Anthony Liguori | 0c25743 | 2009-05-21 20:41:01 -0500 | [diff] [blame] | 1924 | m->is_default ? " (default)" : ""); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1925 | } |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1926 | exit(*optarg != '?'); |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1927 | } |
| 1928 | break; |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1929 | case QEMU_OPTION_cpu: |
| 1930 | /* hw initialization will check this */ |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1931 | if (*optarg == '?') { |
Blue Swirl | 262353c | 2010-05-04 19:55:35 +0000 | [diff] [blame] | 1932 | list_cpus(stdout, &fprintf, optarg); |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 1933 | exit(0); |
j_mayer | 94fc95c | 2007-03-05 19:44:02 +0000 | [diff] [blame] | 1934 | } else { |
| 1935 | cpu_model = optarg; |
| 1936 | } |
| 1937 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1938 | case QEMU_OPTION_initrd: |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1939 | initrd_filename = optarg; |
| 1940 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1941 | case QEMU_OPTION_hda: |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1942 | if (cyls == 0) |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1943 | hda_opts = drive_add(optarg, HD_ALIAS, 0); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1944 | else |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 1945 | hda_opts = drive_add(optarg, HD_ALIAS |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1946 | ",cyls=%d,heads=%d,secs=%d%s", |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1947 | 0, cyls, heads, secs, |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1948 | translation == BIOS_ATA_TRANSLATION_LBA ? |
| 1949 | ",trans=lba" : |
| 1950 | translation == BIOS_ATA_TRANSLATION_NONE ? |
| 1951 | ",trans=none" : ""); |
| 1952 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1953 | case QEMU_OPTION_hdb: |
bellard | cc1daa4 | 2005-06-05 14:49:17 +0000 | [diff] [blame] | 1954 | case QEMU_OPTION_hdc: |
| 1955 | case QEMU_OPTION_hdd: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1956 | drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda); |
bellard | fc01f7e | 2003-06-30 10:03:06 +0000 | [diff] [blame] | 1957 | break; |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1958 | case QEMU_OPTION_drive: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1959 | drive_add(NULL, "%s", optarg); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 1960 | break; |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 1961 | case QEMU_OPTION_set: |
| 1962 | if (qemu_set_option(optarg) != 0) |
| 1963 | exit(1); |
| 1964 | break; |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 1965 | case QEMU_OPTION_global: |
| 1966 | if (qemu_global_option(optarg) != 0) |
| 1967 | exit(1); |
| 1968 | break; |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 1969 | case QEMU_OPTION_mtdblock: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1970 | drive_add(optarg, MTD_ALIAS); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 1971 | break; |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 1972 | case QEMU_OPTION_sd: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1973 | drive_add(optarg, SD_ALIAS); |
pbrook | a1bb27b | 2007-04-06 16:49:48 +0000 | [diff] [blame] | 1974 | break; |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 1975 | case QEMU_OPTION_pflash: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 1976 | drive_add(optarg, PFLASH_ALIAS); |
j_mayer | 86f5566 | 2007-04-24 06:52:59 +0000 | [diff] [blame] | 1977 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1978 | case QEMU_OPTION_snapshot: |
bellard | 33e3963 | 2003-07-06 17:15:21 +0000 | [diff] [blame] | 1979 | snapshot = 1; |
| 1980 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 1981 | case QEMU_OPTION_hdachs: |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1982 | { |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1983 | const char *p; |
| 1984 | p = optarg; |
| 1985 | cyls = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1986 | if (cyls < 1 || cyls > 16383) |
| 1987 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1988 | if (*p != ',') |
| 1989 | goto chs_fail; |
| 1990 | p++; |
| 1991 | heads = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1992 | if (heads < 1 || heads > 16) |
| 1993 | goto chs_fail; |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 1994 | if (*p != ',') |
| 1995 | goto chs_fail; |
| 1996 | p++; |
| 1997 | secs = strtol(p, (char **)&p, 0); |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 1998 | if (secs < 1 || secs > 63) |
| 1999 | goto chs_fail; |
| 2000 | if (*p == ',') { |
| 2001 | p++; |
| 2002 | if (!strcmp(p, "none")) |
| 2003 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 2004 | else if (!strcmp(p, "lba")) |
| 2005 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 2006 | else if (!strcmp(p, "auto")) |
| 2007 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2008 | else |
| 2009 | goto chs_fail; |
| 2010 | } else if (*p != '\0') { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2011 | chs_fail: |
bellard | 46d4767 | 2004-11-16 01:45:27 +0000 | [diff] [blame] | 2012 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
| 2013 | exit(1); |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2014 | } |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 2015 | if (hda_opts != NULL) { |
| 2016 | char num[16]; |
| 2017 | snprintf(num, sizeof(num), "%d", cyls); |
| 2018 | qemu_opt_set(hda_opts, "cyls", num); |
| 2019 | snprintf(num, sizeof(num), "%d", heads); |
| 2020 | qemu_opt_set(hda_opts, "heads", num); |
| 2021 | snprintf(num, sizeof(num), "%d", secs); |
| 2022 | qemu_opt_set(hda_opts, "secs", num); |
| 2023 | if (translation == BIOS_ATA_TRANSLATION_LBA) |
| 2024 | qemu_opt_set(hda_opts, "trans", "lba"); |
| 2025 | if (translation == BIOS_ATA_TRANSLATION_NONE) |
| 2026 | qemu_opt_set(hda_opts, "trans", "none"); |
| 2027 | } |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2028 | } |
| 2029 | break; |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2030 | case QEMU_OPTION_numa: |
| 2031 | if (nb_numa_nodes >= MAX_NODES) { |
| 2032 | fprintf(stderr, "qemu: too many NUMA nodes\n"); |
| 2033 | exit(1); |
| 2034 | } |
| 2035 | numa_add(optarg); |
| 2036 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2037 | case QEMU_OPTION_nographic: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2038 | display_type = DT_NOGRAPHIC; |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2039 | break; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 2040 | #ifdef CONFIG_CURSES |
| 2041 | case QEMU_OPTION_curses: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2042 | display_type = DT_CURSES; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | #endif |
balrog | a171fe3 | 2007-04-30 01:48:07 +0000 | [diff] [blame] | 2045 | case QEMU_OPTION_portrait: |
| 2046 | graphic_rotate = 1; |
| 2047 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2048 | case QEMU_OPTION_kernel: |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2049 | kernel_filename = optarg; |
| 2050 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2051 | case QEMU_OPTION_append: |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2052 | kernel_cmdline = optarg; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2053 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2054 | case QEMU_OPTION_cdrom: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 2055 | drive_add(optarg, CDROM_ALIAS); |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 2056 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2057 | case QEMU_OPTION_boot: |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 2058 | { |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2059 | static const char * const params[] = { |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2060 | "order", "once", "menu", NULL |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2061 | }; |
| 2062 | char buf[sizeof(boot_devices)]; |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2063 | char *standard_boot_devices; |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2064 | int legacy = 0; |
| 2065 | |
| 2066 | if (!strchr(optarg, '=')) { |
| 2067 | legacy = 1; |
| 2068 | pstrcpy(buf, sizeof(buf), optarg); |
| 2069 | } else if (check_params(buf, sizeof(buf), params, optarg) < 0) { |
| 2070 | fprintf(stderr, |
| 2071 | "qemu: unknown boot parameter '%s' in '%s'\n", |
| 2072 | buf, optarg); |
| 2073 | exit(1); |
| 2074 | } |
| 2075 | |
| 2076 | if (legacy || |
| 2077 | get_param_value(buf, sizeof(buf), "order", optarg)) { |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 2078 | validate_bootdevices(buf); |
Jan Kiszka | ef3adf6 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2079 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
j_mayer | 28c5af5 | 2007-11-11 01:50:45 +0000 | [diff] [blame] | 2080 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2081 | if (!legacy) { |
| 2082 | if (get_param_value(buf, sizeof(buf), |
| 2083 | "once", optarg)) { |
Eduardo Habkost | 4e9e9d6 | 2010-04-06 19:22:08 -0300 | [diff] [blame] | 2084 | validate_bootdevices(buf); |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2085 | standard_boot_devices = qemu_strdup(boot_devices); |
| 2086 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
| 2087 | qemu_register_reset(restore_boot_devices, |
| 2088 | standard_boot_devices); |
| 2089 | } |
Jan Kiszka | 9538749 | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2090 | if (get_param_value(buf, sizeof(buf), |
| 2091 | "menu", optarg)) { |
| 2092 | if (!strcmp(buf, "on")) { |
| 2093 | boot_menu = 1; |
| 2094 | } else if (!strcmp(buf, "off")) { |
| 2095 | boot_menu = 0; |
| 2096 | } else { |
| 2097 | fprintf(stderr, |
| 2098 | "qemu: invalid option value '%s'\n", |
| 2099 | buf); |
| 2100 | exit(1); |
| 2101 | } |
| 2102 | } |
Jan Kiszka | e0f084b | 2009-07-02 00:19:02 +0200 | [diff] [blame] | 2103 | } |
bellard | 36b486b | 2003-11-11 13:36:08 +0000 | [diff] [blame] | 2104 | } |
| 2105 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2106 | case QEMU_OPTION_fda: |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2107 | case QEMU_OPTION_fdb: |
balrog | 609497a | 2008-01-14 02:56:53 +0000 | [diff] [blame] | 2108 | drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda); |
bellard | c45886d | 2004-01-05 00:02:06 +0000 | [diff] [blame] | 2109 | break; |
bellard | 52ca8d6 | 2006-06-14 16:03:05 +0000 | [diff] [blame] | 2110 | case QEMU_OPTION_no_fd_bootchk: |
| 2111 | fd_bootchk = 0; |
| 2112 | break; |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 2113 | case QEMU_OPTION_netdev: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2114 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 2115 | exit(1); |
| 2116 | } |
| 2117 | break; |
bellard | 7c9d8e0 | 2005-11-15 22:16:05 +0000 | [diff] [blame] | 2118 | case QEMU_OPTION_net: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2119 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2120 | exit(1); |
| 2121 | } |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 2122 | break; |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 2123 | #ifdef CONFIG_SLIRP |
| 2124 | case QEMU_OPTION_tftp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 2125 | legacy_tftp_prefix = optarg; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2126 | break; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 2127 | case QEMU_OPTION_bootp: |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 2128 | legacy_bootp_filename = optarg; |
ths | 47d5d01 | 2007-02-20 00:05:08 +0000 | [diff] [blame] | 2129 | break; |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2130 | case QEMU_OPTION_redir: |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 2131 | if (net_slirp_redir(optarg) < 0) |
| 2132 | exit(1); |
bellard | 9bf0544 | 2004-08-25 22:12:49 +0000 | [diff] [blame] | 2133 | break; |
bellard | c7f7464 | 2004-08-24 21:57:12 +0000 | [diff] [blame] | 2134 | #endif |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2135 | case QEMU_OPTION_bt: |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2136 | add_device_config(DEV_BT, optarg); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2137 | break; |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2138 | case QEMU_OPTION_audio_help: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2139 | if (!(audio_available())) { |
| 2140 | printf("Option %s not supported for this target\n", popt->name); |
| 2141 | exit(1); |
| 2142 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2143 | AUD_help (); |
| 2144 | exit (0); |
| 2145 | break; |
| 2146 | case QEMU_OPTION_soundhw: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2147 | if (!(audio_available())) { |
| 2148 | printf("Option %s not supported for this target\n", popt->name); |
| 2149 | exit(1); |
| 2150 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 2151 | select_soundhw (optarg); |
| 2152 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2153 | case QEMU_OPTION_h: |
ths | 15f8220 | 2007-06-29 23:26:08 +0000 | [diff] [blame] | 2154 | help(0); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2155 | break; |
pbrook | 9bd7e6d | 2009-04-07 22:58:45 +0000 | [diff] [blame] | 2156 | case QEMU_OPTION_version: |
| 2157 | version(); |
| 2158 | exit(0); |
| 2159 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2160 | case QEMU_OPTION_m: { |
| 2161 | uint64_t value; |
| 2162 | char *ptr; |
| 2163 | |
| 2164 | value = strtoul(optarg, &ptr, 10); |
| 2165 | switch (*ptr) { |
| 2166 | case 0: case 'M': case 'm': |
| 2167 | value <<= 20; |
| 2168 | break; |
| 2169 | case 'G': case 'g': |
| 2170 | value <<= 30; |
| 2171 | break; |
| 2172 | default: |
| 2173 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2174 | exit(1); |
| 2175 | } |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2176 | |
| 2177 | /* On 32-bit hosts, QEMU is limited by virtual address space */ |
Anthony Liguori | 4a1418e | 2009-08-10 17:07:24 -0500 | [diff] [blame] | 2178 | if (value > (2047 << 20) && HOST_LONG_BITS == 32) { |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2179 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); |
| 2180 | exit(1); |
| 2181 | } |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 2182 | if (value != (uint64_t)(ram_addr_t)value) { |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2183 | fprintf(stderr, "qemu: ram size too large\n"); |
| 2184 | exit(1); |
| 2185 | } |
| 2186 | ram_size = value; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2187 | break; |
aurel32 | 00f82b8 | 2008-04-27 21:12:55 +0000 | [diff] [blame] | 2188 | } |
Marcelo Tosatti | c902760 | 2010-03-01 20:25:08 -0300 | [diff] [blame] | 2189 | case QEMU_OPTION_mempath: |
| 2190 | mem_path = optarg; |
| 2191 | break; |
| 2192 | #ifdef MAP_POPULATE |
| 2193 | case QEMU_OPTION_mem_prealloc: |
| 2194 | mem_prealloc = 1; |
| 2195 | break; |
| 2196 | #endif |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2197 | case QEMU_OPTION_d: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2198 | set_cpu_log(optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2199 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2200 | case QEMU_OPTION_s: |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2201 | gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2202 | break; |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2203 | case QEMU_OPTION_gdb: |
| 2204 | gdbstub_dev = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2205 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2206 | case QEMU_OPTION_L: |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2207 | data_dir = optarg; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2208 | break; |
j_mayer | 1192dad | 2007-10-05 13:08:35 +0000 | [diff] [blame] | 2209 | case QEMU_OPTION_bios: |
| 2210 | bios_name = optarg; |
| 2211 | break; |
aurel32 | 1b530a6 | 2009-04-05 20:08:59 +0000 | [diff] [blame] | 2212 | case QEMU_OPTION_singlestep: |
| 2213 | singlestep = 1; |
| 2214 | break; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2215 | case QEMU_OPTION_S: |
pbrook | 3c07f8e | 2007-01-21 16:47:01 +0000 | [diff] [blame] | 2216 | autostart = 0; |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2217 | break; |
bellard | 3d11d0e | 2004-12-12 16:56:30 +0000 | [diff] [blame] | 2218 | case QEMU_OPTION_k: |
| 2219 | keyboard_layout = optarg; |
| 2220 | break; |
bellard | ee22c2f | 2004-06-03 12:49:50 +0000 | [diff] [blame] | 2221 | case QEMU_OPTION_localtime: |
| 2222 | rtc_utc = 0; |
| 2223 | break; |
malc | 3893c12 | 2008-09-28 00:42:05 +0000 | [diff] [blame] | 2224 | case QEMU_OPTION_vga: |
| 2225 | select_vgahw (optarg); |
bellard | 1bfe856 | 2004-07-08 21:17:50 +0000 | [diff] [blame] | 2226 | break; |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2227 | case QEMU_OPTION_g: |
| 2228 | { |
| 2229 | const char *p; |
| 2230 | int w, h, depth; |
| 2231 | p = optarg; |
| 2232 | w = strtol(p, (char **)&p, 10); |
| 2233 | if (w <= 0) { |
| 2234 | graphic_error: |
| 2235 | fprintf(stderr, "qemu: invalid resolution or depth\n"); |
| 2236 | exit(1); |
| 2237 | } |
| 2238 | if (*p != 'x') |
| 2239 | goto graphic_error; |
| 2240 | p++; |
| 2241 | h = strtol(p, (char **)&p, 10); |
| 2242 | if (h <= 0) |
| 2243 | goto graphic_error; |
| 2244 | if (*p == 'x') { |
| 2245 | p++; |
| 2246 | depth = strtol(p, (char **)&p, 10); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 2247 | if (depth != 8 && depth != 15 && depth != 16 && |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2248 | depth != 24 && depth != 32) |
| 2249 | goto graphic_error; |
| 2250 | } else if (*p == '\0') { |
| 2251 | depth = graphic_depth; |
| 2252 | } else { |
| 2253 | goto graphic_error; |
| 2254 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2255 | |
bellard | e9b137c | 2004-06-21 16:46:10 +0000 | [diff] [blame] | 2256 | graphic_width = w; |
| 2257 | graphic_height = h; |
| 2258 | graphic_depth = depth; |
| 2259 | } |
| 2260 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 2261 | case QEMU_OPTION_echr: |
| 2262 | { |
| 2263 | char *r; |
| 2264 | term_escape_char = strtol(optarg, &r, 0); |
| 2265 | if (r == optarg) |
| 2266 | printf("Bad argument to echr\n"); |
| 2267 | break; |
| 2268 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2269 | case QEMU_OPTION_monitor: |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2270 | monitor_parse(optarg, "readline"); |
| 2271 | default_monitor = 0; |
| 2272 | break; |
| 2273 | case QEMU_OPTION_qmp: |
| 2274 | monitor_parse(optarg, "control"); |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 2275 | default_monitor = 0; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2276 | break; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2277 | case QEMU_OPTION_mon: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2278 | opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2279 | if (!opts) { |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2280 | exit(1); |
| 2281 | } |
Anthony Liguori | 2d114dc | 2010-03-21 14:14:38 -0500 | [diff] [blame] | 2282 | default_monitor = 0; |
Gerd Hoffmann | 22a0e04 | 2009-12-08 13:11:51 +0100 | [diff] [blame] | 2283 | break; |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2284 | case QEMU_OPTION_chardev: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2285 | opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2286 | if (!opts) { |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2287 | exit(1); |
| 2288 | } |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 2289 | break; |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2290 | case QEMU_OPTION_fsdev: |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 2291 | olist = qemu_find_opts("fsdev"); |
| 2292 | if (!olist) { |
| 2293 | fprintf(stderr, "fsdev is not supported by this qemu build.\n"); |
| 2294 | exit(1); |
| 2295 | } |
| 2296 | opts = qemu_opts_parse(olist, optarg, 1); |
Gautham R Shenoy | 74db920 | 2010-04-29 17:44:43 +0530 | [diff] [blame] | 2297 | if (!opts) { |
| 2298 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2299 | exit(1); |
| 2300 | } |
| 2301 | break; |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2302 | case QEMU_OPTION_virtfs: { |
| 2303 | char *arg_fsdev = NULL; |
| 2304 | char *arg_9p = NULL; |
| 2305 | int len = 0; |
| 2306 | |
Gerd Hoffmann | 03b0ba7 | 2010-08-20 13:52:02 +0200 | [diff] [blame] | 2307 | olist = qemu_find_opts("virtfs"); |
| 2308 | if (!olist) { |
| 2309 | fprintf(stderr, "virtfs is not supported by this qemu build.\n"); |
| 2310 | exit(1); |
| 2311 | } |
| 2312 | opts = qemu_opts_parse(olist, optarg, 1); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2313 | if (!opts) { |
| 2314 | fprintf(stderr, "parse error: %s\n", optarg); |
| 2315 | exit(1); |
| 2316 | } |
| 2317 | |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 2318 | if (qemu_opt_get(opts, "fstype") == NULL || |
| 2319 | qemu_opt_get(opts, "mount_tag") == NULL || |
| 2320 | qemu_opt_get(opts, "path") == NULL || |
| 2321 | qemu_opt_get(opts, "security_model") == NULL) { |
| 2322 | fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/," |
| 2323 | "security_model=[mapped|passthrough]," |
| 2324 | "mnt_tag=tag.\n"); |
| 2325 | exit(1); |
| 2326 | } |
| 2327 | |
| 2328 | len = strlen(",id=,path=,security_model="); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2329 | len += strlen(qemu_opt_get(opts, "fstype")); |
| 2330 | len += strlen(qemu_opt_get(opts, "mount_tag")); |
| 2331 | len += strlen(qemu_opt_get(opts, "path")); |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 2332 | len += strlen(qemu_opt_get(opts, "security_model")); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2333 | arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev)); |
| 2334 | |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 2335 | sprintf(arg_fsdev, "%s,id=%s,path=%s,security_model=%s", |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2336 | qemu_opt_get(opts, "fstype"), |
| 2337 | qemu_opt_get(opts, "mount_tag"), |
Venkateswararao Jujjuri (JV) | 9ce56db | 2010-06-14 13:34:40 -0700 | [diff] [blame] | 2338 | qemu_opt_get(opts, "path"), |
| 2339 | qemu_opt_get(opts, "security_model")); |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2340 | |
| 2341 | len = strlen("virtio-9p-pci,fsdev=,mount_tag="); |
| 2342 | len += 2*strlen(qemu_opt_get(opts, "mount_tag")); |
| 2343 | arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p)); |
| 2344 | |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2345 | sprintf(arg_9p, "virtio-9p-pci,fsdev=%s,mount_tag=%s", |
| 2346 | qemu_opt_get(opts, "mount_tag"), |
| 2347 | qemu_opt_get(opts, "mount_tag")); |
| 2348 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2349 | if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) { |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2350 | fprintf(stderr, "parse error [fsdev]: %s\n", optarg); |
| 2351 | exit(1); |
| 2352 | } |
| 2353 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2354 | if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) { |
Gautham R Shenoy | 3d54abc | 2010-04-29 17:45:03 +0530 | [diff] [blame] | 2355 | fprintf(stderr, "parse error [device]: %s\n", optarg); |
| 2356 | exit(1); |
| 2357 | } |
| 2358 | |
| 2359 | qemu_free(arg_fsdev); |
| 2360 | qemu_free(arg_9p); |
| 2361 | break; |
| 2362 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2363 | case QEMU_OPTION_serial: |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2364 | add_device_config(DEV_SERIAL, optarg); |
| 2365 | default_serial = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2366 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2367 | default_monitor = 0; |
| 2368 | } |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2369 | break; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 2370 | case QEMU_OPTION_watchdog: |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 2371 | if (watchdog) { |
| 2372 | fprintf(stderr, |
| 2373 | "qemu: only one watchdog option may be given\n"); |
| 2374 | return 1; |
| 2375 | } |
| 2376 | watchdog = optarg; |
Richard W.M. Jones | 9dd986c | 2009-04-25 13:56:19 +0100 | [diff] [blame] | 2377 | break; |
| 2378 | case QEMU_OPTION_watchdog_action: |
| 2379 | if (select_watchdog_action(optarg) == -1) { |
| 2380 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); |
| 2381 | exit(1); |
| 2382 | } |
| 2383 | break; |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 2384 | case QEMU_OPTION_virtiocon: |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2385 | add_device_config(DEV_VIRTCON, optarg); |
| 2386 | default_virtcon = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2387 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2388 | default_monitor = 0; |
| 2389 | } |
aliguori | 51ecf13 | 2009-01-15 20:06:40 +0000 | [diff] [blame] | 2390 | break; |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 2391 | case QEMU_OPTION_parallel: |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2392 | add_device_config(DEV_PARALLEL, optarg); |
| 2393 | default_parallel = 0; |
Jan Kiszka | 18141ed | 2010-03-07 11:28:40 +0100 | [diff] [blame] | 2394 | if (strncmp(optarg, "mon:", 4) == 0) { |
| 2395 | default_monitor = 0; |
| 2396 | } |
bellard | 6508fe5 | 2005-01-15 12:02:56 +0000 | [diff] [blame] | 2397 | break; |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2398 | case QEMU_OPTION_debugcon: |
| 2399 | add_device_config(DEV_DEBUGCON, optarg); |
| 2400 | break; |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2401 | case QEMU_OPTION_loadvm: |
| 2402 | loadvm = optarg; |
| 2403 | break; |
| 2404 | case QEMU_OPTION_full_screen: |
| 2405 | full_screen = 1; |
| 2406 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2407 | #ifdef CONFIG_SDL |
ths | 43523e9 | 2007-02-18 18:19:32 +0000 | [diff] [blame] | 2408 | case QEMU_OPTION_no_frame: |
| 2409 | no_frame = 1; |
| 2410 | break; |
ths | 3780e19 | 2007-06-21 21:08:02 +0000 | [diff] [blame] | 2411 | case QEMU_OPTION_alt_grab: |
| 2412 | alt_grab = 1; |
| 2413 | break; |
Dustin Kirkland | 0ca9f8a | 2009-09-17 15:48:04 -0500 | [diff] [blame] | 2414 | case QEMU_OPTION_ctrl_grab: |
| 2415 | ctrl_grab = 1; |
| 2416 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2417 | case QEMU_OPTION_no_quit: |
| 2418 | no_quit = 1; |
| 2419 | break; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2420 | case QEMU_OPTION_sdl: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2421 | display_type = DT_SDL; |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2422 | break; |
ths | 667acca | 2006-12-11 02:08:05 +0000 | [diff] [blame] | 2423 | #endif |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 2424 | case QEMU_OPTION_pidfile: |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2425 | pid_file = optarg; |
bellard | f7cce89 | 2004-12-08 22:21:25 +0000 | [diff] [blame] | 2426 | break; |
bellard | a09db21 | 2005-04-30 16:10:35 +0000 | [diff] [blame] | 2427 | case QEMU_OPTION_win2k_hack: |
| 2428 | win2k_install_hack = 1; |
| 2429 | break; |
aliguori | 73822ec | 2009-01-15 20:11:34 +0000 | [diff] [blame] | 2430 | case QEMU_OPTION_rtc_td_hack: |
| 2431 | rtc_td_hack = 1; |
| 2432 | break; |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 2433 | case QEMU_OPTION_acpitable: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2434 | do_acpitable_option(optarg); |
aliguori | 8a92ea2 | 2009-02-27 20:12:36 +0000 | [diff] [blame] | 2435 | break; |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 2436 | case QEMU_OPTION_smbios: |
Blue Swirl | de06f8d | 2010-03-29 19:23:50 +0000 | [diff] [blame] | 2437 | do_smbios_option(optarg); |
aliguori | b6f6e3d | 2009-04-17 18:59:56 +0000 | [diff] [blame] | 2438 | break; |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2439 | case QEMU_OPTION_enable_kvm: |
| 2440 | kvm_allowed = 1; |
aliguori | 7ba1e61 | 2008-11-05 16:04:33 +0000 | [diff] [blame] | 2441 | break; |
bellard | bb36d47 | 2005-11-05 14:22:28 +0000 | [diff] [blame] | 2442 | case QEMU_OPTION_usb: |
| 2443 | usb_enabled = 1; |
| 2444 | break; |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 2445 | case QEMU_OPTION_usbdevice: |
| 2446 | usb_enabled = 1; |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2447 | add_device_config(DEV_USB, optarg); |
| 2448 | break; |
| 2449 | case QEMU_OPTION_device: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2450 | if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 2451 | exit(1); |
| 2452 | } |
bellard | a594cfb | 2005-11-06 16:13:29 +0000 | [diff] [blame] | 2453 | break; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2454 | case QEMU_OPTION_smp: |
Andre Przywara | dc6b1c0 | 2009-08-19 15:42:40 +0200 | [diff] [blame] | 2455 | smp_parse(optarg); |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 2456 | if (smp_cpus < 1) { |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2457 | fprintf(stderr, "Invalid number of CPUs\n"); |
| 2458 | exit(1); |
| 2459 | } |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 2460 | if (max_cpus < smp_cpus) { |
| 2461 | fprintf(stderr, "maxcpus must be equal to or greater than " |
| 2462 | "smp\n"); |
| 2463 | exit(1); |
| 2464 | } |
| 2465 | if (max_cpus > 255) { |
| 2466 | fprintf(stderr, "Unsupported number of maxcpus\n"); |
| 2467 | exit(1); |
| 2468 | } |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 2469 | break; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 2470 | case QEMU_OPTION_vnc: |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2471 | display_type = DT_VNC; |
ths | 73fc974 | 2006-12-22 02:09:07 +0000 | [diff] [blame] | 2472 | vnc_display = optarg; |
bellard | 2423686 | 2006-04-30 21:28:36 +0000 | [diff] [blame] | 2473 | break; |
bellard | 6515b20 | 2006-05-03 22:02:44 +0000 | [diff] [blame] | 2474 | case QEMU_OPTION_no_acpi: |
| 2475 | acpi_enabled = 0; |
| 2476 | break; |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 2477 | case QEMU_OPTION_no_hpet: |
| 2478 | no_hpet = 1; |
| 2479 | break; |
Markus Armbruster | 7d4c3d5 | 2009-06-26 19:15:14 +0200 | [diff] [blame] | 2480 | case QEMU_OPTION_balloon: |
| 2481 | if (balloon_parse(optarg) < 0) { |
| 2482 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); |
| 2483 | exit(1); |
| 2484 | } |
Eduardo Habkost | df97b92 | 2009-06-10 16:34:08 -0300 | [diff] [blame] | 2485 | break; |
bellard | d1beab8 | 2006-10-02 19:44:22 +0000 | [diff] [blame] | 2486 | case QEMU_OPTION_no_reboot: |
| 2487 | no_reboot = 1; |
| 2488 | break; |
aurel32 | b2f7616 | 2008-04-11 21:35:52 +0000 | [diff] [blame] | 2489 | case QEMU_OPTION_no_shutdown: |
| 2490 | no_shutdown = 1; |
| 2491 | break; |
balrog | 9467cd4 | 2007-05-01 01:34:14 +0000 | [diff] [blame] | 2492 | case QEMU_OPTION_show_cursor: |
| 2493 | cursor_hide = 0; |
| 2494 | break; |
blueswir1 | 8fcb1b9 | 2008-09-18 18:29:08 +0000 | [diff] [blame] | 2495 | case QEMU_OPTION_uuid: |
| 2496 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
| 2497 | fprintf(stderr, "Fail to parse UUID string." |
| 2498 | " Wrong format.\n"); |
| 2499 | exit(1); |
| 2500 | } |
| 2501 | break; |
ths | 9ae0255 | 2007-01-05 17:39:04 +0000 | [diff] [blame] | 2502 | case QEMU_OPTION_option_rom: |
| 2503 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
| 2504 | fprintf(stderr, "Too many option ROMs\n"); |
| 2505 | exit(1); |
| 2506 | } |
| 2507 | option_rom[nb_option_roms] = optarg; |
| 2508 | nb_option_roms++; |
| 2509 | break; |
pbrook | 8e71621 | 2007-01-20 17:12:09 +0000 | [diff] [blame] | 2510 | case QEMU_OPTION_semihosting: |
| 2511 | semihosting_enabled = 1; |
| 2512 | break; |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 2513 | case QEMU_OPTION_name: |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 2514 | qemu_name = qemu_strdup(optarg); |
| 2515 | { |
| 2516 | char *p = strchr(qemu_name, ','); |
| 2517 | if (p != NULL) { |
| 2518 | *p++ = 0; |
| 2519 | if (strncmp(p, "process=", 8)) { |
| 2520 | fprintf(stderr, "Unknown subargument %s to -name", p); |
| 2521 | exit(1); |
| 2522 | } |
| 2523 | p += 8; |
Jes Sorensen | ce798cf | 2010-06-10 11:42:31 +0200 | [diff] [blame] | 2524 | os_set_proc_name(p); |
Andi Kleen | 1889465 | 2009-07-02 09:34:17 +0200 | [diff] [blame] | 2525 | } |
| 2526 | } |
ths | c35734b | 2007-03-19 15:17:08 +0000 | [diff] [blame] | 2527 | break; |
blueswir1 | 6650860 | 2007-05-01 14:16:52 +0000 | [diff] [blame] | 2528 | case QEMU_OPTION_prom_env: |
| 2529 | if (nb_prom_envs >= MAX_PROM_ENVS) { |
| 2530 | fprintf(stderr, "Too many prom variables\n"); |
| 2531 | exit(1); |
| 2532 | } |
| 2533 | prom_envs[nb_prom_envs] = optarg; |
| 2534 | nb_prom_envs++; |
| 2535 | break; |
balrog | 2b8f2d4 | 2007-07-27 22:08:46 +0000 | [diff] [blame] | 2536 | case QEMU_OPTION_old_param: |
| 2537 | old_param = 1; |
ths | 05ebd53 | 2008-01-08 19:32:16 +0000 | [diff] [blame] | 2538 | break; |
ths | f3dcfad | 2007-08-24 01:26:02 +0000 | [diff] [blame] | 2539 | case QEMU_OPTION_clock: |
| 2540 | configure_alarms(optarg); |
| 2541 | break; |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 2542 | case QEMU_OPTION_startdate: |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2543 | configure_rtc_date_offset(optarg, 1); |
| 2544 | break; |
| 2545 | case QEMU_OPTION_rtc: |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2546 | opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2547 | if (!opts) { |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2548 | exit(1); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 2549 | } |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 2550 | configure_rtc(opts); |
bellard | 7e0af5d0 | 2007-11-07 16:24:33 +0000 | [diff] [blame] | 2551 | break; |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 2552 | case QEMU_OPTION_tb_size: |
| 2553 | tb_size = strtol(optarg, NULL, 0); |
| 2554 | if (tb_size < 0) |
| 2555 | tb_size = 0; |
| 2556 | break; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 2557 | case QEMU_OPTION_icount: |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 2558 | icount_option = optarg; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 2559 | break; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 2560 | case QEMU_OPTION_incoming: |
| 2561 | incoming = optarg; |
Amit Shah | 8e84865 | 2010-07-27 15:49:19 +0530 | [diff] [blame] | 2562 | incoming_expected = true; |
aliguori | 5bb7910 | 2008-10-13 03:12:02 +0000 | [diff] [blame] | 2563 | break; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 2564 | case QEMU_OPTION_nodefaults: |
| 2565 | default_serial = 0; |
| 2566 | default_parallel = 0; |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2567 | default_virtcon = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 2568 | default_monitor = 0; |
| 2569 | default_vga = 0; |
Gerd Hoffmann | cb4522c | 2009-12-08 13:11:47 +0100 | [diff] [blame] | 2570 | default_net = 0; |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2571 | default_floppy = 0; |
| 2572 | default_cdrom = 0; |
| 2573 | default_sdcard = 0; |
Gerd Hoffmann | d8c208d | 2009-12-08 13:11:46 +0100 | [diff] [blame] | 2574 | break; |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2575 | case QEMU_OPTION_xen_domid: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2576 | if (!(xen_available())) { |
| 2577 | printf("Option %s not supported for this target\n", popt->name); |
| 2578 | exit(1); |
| 2579 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2580 | xen_domid = atoi(optarg); |
| 2581 | break; |
| 2582 | case QEMU_OPTION_xen_create: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2583 | if (!(xen_available())) { |
| 2584 | printf("Option %s not supported for this target\n", popt->name); |
| 2585 | exit(1); |
| 2586 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2587 | xen_mode = XEN_CREATE; |
| 2588 | break; |
| 2589 | case QEMU_OPTION_xen_attach: |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 2590 | if (!(xen_available())) { |
| 2591 | printf("Option %s not supported for this target\n", popt->name); |
| 2592 | exit(1); |
| 2593 | } |
aliguori | e37630c | 2009-04-22 15:19:10 +0000 | [diff] [blame] | 2594 | xen_mode = XEN_ATTACH; |
| 2595 | break; |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 2596 | case QEMU_OPTION_readconfig: |
| 2597 | { |
Kevin Wolf | dcfb093 | 2010-03-05 17:25:55 +0100 | [diff] [blame] | 2598 | int ret = qemu_read_config_file(optarg); |
| 2599 | if (ret < 0) { |
| 2600 | fprintf(stderr, "read config %s: %s\n", optarg, |
| 2601 | strerror(-ret)); |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 2602 | exit(1); |
| 2603 | } |
Gerd Hoffmann | 715a664 | 2009-10-14 10:39:28 +0200 | [diff] [blame] | 2604 | break; |
| 2605 | } |
| 2606 | case QEMU_OPTION_writeconfig: |
| 2607 | { |
| 2608 | FILE *fp; |
| 2609 | if (strcmp(optarg, "-") == 0) { |
| 2610 | fp = stdout; |
| 2611 | } else { |
| 2612 | fp = fopen(optarg, "w"); |
| 2613 | if (fp == NULL) { |
| 2614 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); |
| 2615 | exit(1); |
| 2616 | } |
| 2617 | } |
| 2618 | qemu_config_write(fp); |
| 2619 | fclose(fp); |
| 2620 | break; |
| 2621 | } |
Jes Sorensen | 59a5264 | 2010-06-10 11:42:25 +0200 | [diff] [blame] | 2622 | default: |
| 2623 | os_parse_cmd_args(popt->index, optarg); |
bellard | cd6f116 | 2004-05-13 22:02:20 +0000 | [diff] [blame] | 2624 | } |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2625 | } |
| 2626 | } |
Markus Armbruster | 0f0bc3f | 2010-02-18 20:13:51 +0100 | [diff] [blame] | 2627 | loc_set_none(); |
bellard | 330d041 | 2003-07-26 18:11:40 +0000 | [diff] [blame] | 2628 | |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2629 | /* If no data_dir is specified then try to find it relative to the |
| 2630 | executable path. */ |
| 2631 | if (!data_dir) { |
Jes Sorensen | 6170540 | 2010-06-10 11:42:23 +0200 | [diff] [blame] | 2632 | data_dir = os_find_datadir(argv[0]); |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2633 | } |
| 2634 | /* If all else fails use the install patch specified when building. */ |
| 2635 | if (!data_dir) { |
Paolo Bonzini | 1dabe05 | 2010-05-26 16:08:25 +0200 | [diff] [blame] | 2636 | data_dir = CONFIG_QEMU_DATADIR; |
Paul Brook | 5cea859 | 2009-05-30 00:52:44 +0100 | [diff] [blame] | 2637 | } |
| 2638 | |
Jes Sorensen | 6be68d7 | 2009-07-23 17:03:42 +0200 | [diff] [blame] | 2639 | /* |
| 2640 | * Default to max_cpus = smp_cpus, in case the user doesn't |
| 2641 | * specify a max_cpus value. |
| 2642 | */ |
| 2643 | if (!max_cpus) |
| 2644 | max_cpus = smp_cpus; |
| 2645 | |
balrog | 3d878ca | 2008-10-28 10:59:59 +0000 | [diff] [blame] | 2646 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
aliguori | b209700 | 2008-10-07 20:39:39 +0000 | [diff] [blame] | 2647 | if (smp_cpus > machine->max_cpus) { |
| 2648 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " |
| 2649 | "supported by machine `%s' (%d)\n", smp_cpus, machine->name, |
| 2650 | machine->max_cpus); |
| 2651 | exit(1); |
| 2652 | } |
| 2653 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2654 | qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); |
| 2655 | qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0); |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2656 | |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2657 | if (machine->no_serial) { |
| 2658 | default_serial = 0; |
| 2659 | } |
| 2660 | if (machine->no_parallel) { |
| 2661 | default_parallel = 0; |
| 2662 | } |
| 2663 | if (!machine->use_virtcon) { |
| 2664 | default_virtcon = 0; |
| 2665 | } |
| 2666 | if (machine->no_vga) { |
| 2667 | default_vga = 0; |
| 2668 | } |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2669 | if (machine->no_floppy) { |
| 2670 | default_floppy = 0; |
| 2671 | } |
| 2672 | if (machine->no_cdrom) { |
| 2673 | default_cdrom = 0; |
| 2674 | } |
| 2675 | if (machine->no_sdcard) { |
| 2676 | default_sdcard = 0; |
| 2677 | } |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2678 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2679 | if (display_type == DT_NOGRAPHIC) { |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2680 | if (default_parallel) |
| 2681 | add_device_config(DEV_PARALLEL, "null"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2682 | if (default_serial && default_monitor) { |
| 2683 | add_device_config(DEV_SERIAL, "mon:stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2684 | } else if (default_virtcon && default_monitor) { |
| 2685 | add_device_config(DEV_VIRTCON, "mon:stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2686 | } else { |
| 2687 | if (default_serial) |
| 2688 | add_device_config(DEV_SERIAL, "stdio"); |
Gerd Hoffmann | 986c5f7 | 2009-12-08 13:11:54 +0100 | [diff] [blame] | 2689 | if (default_virtcon) |
| 2690 | add_device_config(DEV_VIRTCON, "stdio"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2691 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2692 | monitor_parse("stdio", "readline"); |
Gerd Hoffmann | e1c0917 | 2009-12-08 13:11:44 +0100 | [diff] [blame] | 2693 | } |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2694 | } else { |
| 2695 | if (default_serial) |
| 2696 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2697 | if (default_parallel) |
| 2698 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); |
Gerd Hoffmann | abdeed0 | 2009-12-08 13:11:43 +0100 | [diff] [blame] | 2699 | if (default_monitor) |
Gerd Hoffmann | 6ca5582 | 2009-12-08 13:11:52 +0100 | [diff] [blame] | 2700 | monitor_parse("vc:80Cx24C", "readline"); |
Alexander Graf | 38536da | 2009-12-17 13:06:08 +0100 | [diff] [blame] | 2701 | if (default_virtcon) |
| 2702 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); |
aliguori | bc0129d | 2008-08-01 15:12:34 +0000 | [diff] [blame] | 2703 | } |
Gerd Hoffmann | 6446529 | 2009-12-08 13:11:45 +0100 | [diff] [blame] | 2704 | if (default_vga) |
| 2705 | vga_interface_type = VGA_CIRRUS; |
aliguori | bc0129d | 2008-08-01 15:12:34 +0000 | [diff] [blame] | 2706 | |
TeLeMan | a5829fd | 2010-04-15 12:37:55 +0800 | [diff] [blame] | 2707 | socket_init(); |
| 2708 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2709 | 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] | 2710 | exit(1); |
Venkateswararao Jujjuri (JV) | 758e8e3 | 2010-06-14 13:34:41 -0700 | [diff] [blame] | 2711 | #ifdef CONFIG_VIRTFS |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2712 | 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] | 2713 | exit(1); |
| 2714 | } |
| 2715 | #endif |
Gerd Hoffmann | 1a688d3 | 2009-12-08 13:11:36 +0100 | [diff] [blame] | 2716 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 2717 | os_daemonize(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 2718 | |
ths | aa26bb2 | 2007-03-25 21:33:06 +0000 | [diff] [blame] | 2719 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 2720 | os_pidfile_error(); |
ths | 93815bc | 2007-03-19 15:58:31 +0000 | [diff] [blame] | 2721 | exit(1); |
| 2722 | } |
| 2723 | |
Paolo Bonzini | 98c8573 | 2010-04-19 18:59:30 +0000 | [diff] [blame] | 2724 | if (kvm_allowed) { |
| 2725 | int ret = kvm_init(smp_cpus); |
Marcelo Tosatti | 214910a | 2009-09-18 02:41:23 -0300 | [diff] [blame] | 2726 | if (ret < 0) { |
Paolo Bonzini | 98c8573 | 2010-04-19 18:59:30 +0000 | [diff] [blame] | 2727 | if (!kvm_available()) { |
| 2728 | printf("KVM not supported for this target\n"); |
| 2729 | } else { |
| 2730 | fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret)); |
| 2731 | } |
Marcelo Tosatti | 214910a | 2009-09-18 02:41:23 -0300 | [diff] [blame] | 2732 | exit(1); |
| 2733 | } |
| 2734 | } |
| 2735 | |
aliguori | 3fcf7b6 | 2009-04-24 18:03:25 +0000 | [diff] [blame] | 2736 | if (qemu_init_main_loop()) { |
| 2737 | fprintf(stderr, "qemu_init_main_loop failed\n"); |
| 2738 | exit(1); |
| 2739 | } |
bellard | a20dd50 | 2003-09-30 21:07:02 +0000 | [diff] [blame] | 2740 | linux_boot = (kernel_filename != NULL); |
balrog | 6c41b27 | 2007-11-17 12:12:29 +0000 | [diff] [blame] | 2741 | |
ths | f8d39c0 | 2008-07-03 10:01:15 +0000 | [diff] [blame] | 2742 | if (!linux_boot && *kernel_cmdline != '\0') { |
| 2743 | fprintf(stderr, "-append only allowed with -kernel option\n"); |
| 2744 | exit(1); |
| 2745 | } |
| 2746 | |
| 2747 | if (!linux_boot && initrd_filename != NULL) { |
| 2748 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); |
| 2749 | exit(1); |
| 2750 | } |
| 2751 | |
Jes Sorensen | 9156d76 | 2010-06-10 11:42:30 +0200 | [diff] [blame] | 2752 | os_set_line_buffering(); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 2753 | |
aliguori | 7183b4b | 2008-11-05 20:40:18 +0000 | [diff] [blame] | 2754 | if (init_timer_alarm() < 0) { |
| 2755 | fprintf(stderr, "could not initialize alarm timer\n"); |
| 2756 | exit(1); |
| 2757 | } |
Paolo Bonzini | 4e3de9e | 2010-03-10 11:38:48 +0100 | [diff] [blame] | 2758 | configure_icount(icount_option); |
pbrook | 634fce9 | 2006-07-15 17:40:09 +0000 | [diff] [blame] | 2759 | |
Mark McLoughlin | dc1c9fe | 2009-10-06 12:17:16 +0100 | [diff] [blame] | 2760 | if (net_init_clients() < 0) { |
| 2761 | exit(1); |
bellard | 702c651 | 2004-04-02 21:21:32 +0000 | [diff] [blame] | 2762 | } |
bellard | f1510b2 | 2003-06-25 00:07:40 +0000 | [diff] [blame] | 2763 | |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2764 | /* init the bluetooth world */ |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2765 | if (foreach_device_config(DEV_BT, bt_parse)) |
| 2766 | exit(1); |
balrog | dc72ac1 | 2008-11-09 00:04:26 +0000 | [diff] [blame] | 2767 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2768 | /* init the memory */ |
pbrook | 94a6b54 | 2009-04-11 17:15:54 +0000 | [diff] [blame] | 2769 | if (ram_size == 0) |
| 2770 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
balrog | 7fb4fdc | 2008-04-24 17:59:27 +0000 | [diff] [blame] | 2771 | |
bellard | 26a5f13 | 2008-05-28 12:30:31 +0000 | [diff] [blame] | 2772 | /* init the dynamic translator */ |
| 2773 | cpu_exec_init_all(tb_size * 1024 * 1024); |
| 2774 | |
Markus Armbruster | eb85201 | 2009-10-27 18:41:44 +0100 | [diff] [blame] | 2775 | bdrv_init_with_whitelist(); |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2776 | |
lirans@il.ibm.com | c163b5c | 2009-11-02 15:40:58 +0200 | [diff] [blame] | 2777 | blk_mig_init(); |
| 2778 | |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2779 | if (default_cdrom) { |
Gerd Hoffmann | aa40fc9 | 2009-12-08 13:11:48 +0100 | [diff] [blame] | 2780 | /* we always create the cdrom drive, even if no disk is there */ |
| 2781 | drive_add(NULL, CDROM_ALIAS); |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2782 | } |
ths | e4bcb14 | 2007-12-02 04:51:10 +0000 | [diff] [blame] | 2783 | |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2784 | if (default_floppy) { |
Gerd Hoffmann | aa40fc9 | 2009-12-08 13:11:48 +0100 | [diff] [blame] | 2785 | /* we always create at least one floppy */ |
| 2786 | drive_add(NULL, FD_ALIAS, 0); |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2787 | } |
bellard | c4b1fcc | 2004-03-14 21:44:30 +0000 | [diff] [blame] | 2788 | |
Gerd Hoffmann | ac33f8f | 2009-12-16 14:25:39 +0100 | [diff] [blame] | 2789 | if (default_sdcard) { |
Gerd Hoffmann | aa40fc9 | 2009-12-08 13:11:48 +0100 | [diff] [blame] | 2790 | /* we always create one sd slot, even if no card is in it */ |
| 2791 | drive_add(NULL, SD_ALIAS); |
| 2792 | } |
balrog | 9d413d1 | 2007-12-04 00:10:34 +0000 | [diff] [blame] | 2793 | |
ths | 96d30e4 | 2007-01-07 20:42:14 +0000 | [diff] [blame] | 2794 | /* open the virtual block devices */ |
Gerd Hoffmann | 9dfd7c7 | 2009-07-22 16:43:04 +0200 | [diff] [blame] | 2795 | if (snapshot) |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2796 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
| 2797 | 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] | 2798 | exit(1); |
balrog | 3e3d581 | 2007-04-30 02:09:25 +0000 | [diff] [blame] | 2799 | |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 2800 | 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] | 2801 | ram_load, NULL); |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 2802 | |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2803 | if (nb_numa_nodes > 0) { |
| 2804 | int i; |
| 2805 | |
| 2806 | if (nb_numa_nodes > smp_cpus) { |
| 2807 | nb_numa_nodes = smp_cpus; |
| 2808 | } |
| 2809 | |
| 2810 | /* If no memory size if given for any node, assume the default case |
| 2811 | * and distribute the available memory equally across all nodes |
| 2812 | */ |
| 2813 | for (i = 0; i < nb_numa_nodes; i++) { |
| 2814 | if (node_mem[i] != 0) |
| 2815 | break; |
| 2816 | } |
| 2817 | if (i == nb_numa_nodes) { |
| 2818 | uint64_t usedmem = 0; |
| 2819 | |
| 2820 | /* On Linux, the each node's border has to be 8MB aligned, |
| 2821 | * the final node gets the rest. |
| 2822 | */ |
| 2823 | for (i = 0; i < nb_numa_nodes - 1; i++) { |
| 2824 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
| 2825 | usedmem += node_mem[i]; |
| 2826 | } |
| 2827 | node_mem[i] = ram_size - usedmem; |
| 2828 | } |
| 2829 | |
| 2830 | for (i = 0; i < nb_numa_nodes; i++) { |
| 2831 | if (node_cpumask[i] != 0) |
| 2832 | break; |
| 2833 | } |
| 2834 | /* assigning the VCPUs round-robin is easier to implement, guest OSes |
| 2835 | * must cope with this anyway, because there are BIOSes out there in |
| 2836 | * real machines which also use this scheme. |
| 2837 | */ |
| 2838 | if (i == nb_numa_nodes) { |
| 2839 | for (i = 0; i < smp_cpus; i++) { |
| 2840 | node_cpumask[i % nb_numa_nodes] |= 1 << i; |
| 2841 | } |
| 2842 | } |
| 2843 | } |
| 2844 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2845 | 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] | 2846 | exit(1); |
| 2847 | } |
| 2848 | |
Gerd Hoffmann | 998bbd7 | 2009-12-08 13:11:41 +0100 | [diff] [blame] | 2849 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
| 2850 | exit(1); |
Gerd Hoffmann | 6a5e8b0 | 2009-12-08 13:11:42 +0100 | [diff] [blame] | 2851 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
| 2852 | exit(1); |
Gerd Hoffmann | aee1b93 | 2009-12-08 13:11:53 +0100 | [diff] [blame] | 2853 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
| 2854 | exit(1); |
H. Peter Anvin | c9f398e | 2009-12-29 13:51:36 -0800 | [diff] [blame] | 2855 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
| 2856 | exit(1); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 2857 | |
Paul Brook | aae9460 | 2009-05-14 22:35:06 +0100 | [diff] [blame] | 2858 | module_call_init(MODULE_INIT_DEVICE); |
| 2859 | |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2860 | 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] | 2861 | exit(0); |
| 2862 | |
Markus Armbruster | 09aaa16 | 2009-08-21 10:31:34 +0200 | [diff] [blame] | 2863 | if (watchdog) { |
| 2864 | i = select_watchdog(watchdog); |
| 2865 | if (i > 0) |
| 2866 | exit (i == 1 ? 1 : 0); |
| 2867 | } |
| 2868 | |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 2869 | if (machine->compat_props) { |
Gerd Hoffmann | 458fb67 | 2009-12-08 13:11:33 +0100 | [diff] [blame] | 2870 | qdev_prop_register_global_list(machine->compat_props); |
Gerd Hoffmann | b6b6114 | 2009-07-15 13:48:21 +0200 | [diff] [blame] | 2871 | } |
Gerd Hoffmann | d0fef6f | 2009-12-08 13:11:34 +0100 | [diff] [blame] | 2872 | qemu_add_globals(); |
| 2873 | |
Paul Brook | fbe1b59 | 2009-05-13 17:56:25 +0100 | [diff] [blame] | 2874 | machine->init(ram_size, boot_devices, |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2875 | kernel_filename, kernel_cmdline, initrd_filename, cpu_model); |
| 2876 | |
Jan Kiszka | ea375f9 | 2010-03-01 19:10:30 +0100 | [diff] [blame] | 2877 | cpu_synchronize_all_post_init(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2878 | |
Juan Quintela | 67b3b71 | 2009-08-28 19:25:15 +0200 | [diff] [blame] | 2879 | /* must be after terminal init, SDL library changes signal handlers */ |
Jes Sorensen | 8d963e6 | 2010-06-10 11:42:22 +0200 | [diff] [blame] | 2880 | os_setup_signal_handling(); |
Juan Quintela | 67b3b71 | 2009-08-28 19:25:15 +0200 | [diff] [blame] | 2881 | |
Blue Swirl | 87d0a28 | 2010-03-27 18:24:45 +0000 | [diff] [blame] | 2882 | set_numa_modes(); |
aliguori | 268a362 | 2009-04-21 22:30:27 +0000 | [diff] [blame] | 2883 | |
aliguori | 6f338c3 | 2009-02-11 15:21:54 +0000 | [diff] [blame] | 2884 | current_machine = machine; |
| 2885 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2886 | /* init USB devices */ |
| 2887 | if (usb_enabled) { |
Markus Armbruster | 0752706 | 2009-10-06 12:16:57 +0100 | [diff] [blame] | 2888 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
| 2889 | exit(1); |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
Gerd Hoffmann | bd3c948 | 2009-07-15 13:59:26 +0200 | [diff] [blame] | 2892 | /* init generic devices */ |
Gerd Hoffmann | 3329f07 | 2010-08-20 13:52:01 +0200 | [diff] [blame] | 2893 | 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] | 2894 | exit(1); |
| 2895 | |
Markus Armbruster | 668680f | 2010-02-11 14:44:58 +0100 | [diff] [blame] | 2896 | net_check_clients(); |
| 2897 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2898 | /* just use the first displaystate for the moment */ |
Paolo Bonzini | b473df6 | 2010-02-11 00:29:55 +0100 | [diff] [blame] | 2899 | ds = get_displaystate(); |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2900 | |
| 2901 | if (display_type == DT_DEFAULT) { |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 2902 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2903 | display_type = DT_SDL; |
| 2904 | #else |
| 2905 | display_type = DT_VNC; |
| 2906 | vnc_display = "localhost:0,to=99"; |
| 2907 | show_vnc_port = 1; |
| 2908 | #endif |
| 2909 | } |
| 2910 | |
| 2911 | |
| 2912 | switch (display_type) { |
| 2913 | case DT_NOGRAPHIC: |
| 2914 | break; |
| 2915 | #if defined(CONFIG_CURSES) |
| 2916 | case DT_CURSES: |
| 2917 | curses_display_init(ds, full_screen); |
| 2918 | break; |
| 2919 | #endif |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2920 | #if defined(CONFIG_SDL) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2921 | case DT_SDL: |
| 2922 | sdl_display_init(ds, full_screen, no_frame); |
| 2923 | break; |
bellard | 5b0753e | 2005-03-01 21:37:28 +0000 | [diff] [blame] | 2924 | #elif defined(CONFIG_COCOA) |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2925 | case DT_SDL: |
| 2926 | cocoa_display_init(ds, full_screen); |
| 2927 | break; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2928 | #endif |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2929 | case DT_VNC: |
| 2930 | vnc_display_init(ds); |
| 2931 | if (vnc_display_open(ds, vnc_display) < 0) |
| 2932 | exit(1); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 2933 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2934 | if (show_vnc_port) { |
| 2935 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); |
Anthony Liguori | f92f8af | 2009-05-20 13:01:02 -0500 | [diff] [blame] | 2936 | } |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2937 | break; |
| 2938 | default: |
| 2939 | break; |
bellard | 313aa56 | 2003-08-10 21:52:11 +0000 | [diff] [blame] | 2940 | } |
aliguori | 7d957bd | 2009-01-15 22:14:11 +0000 | [diff] [blame] | 2941 | dpy_resize(ds); |
aliguori | 5b08fc1 | 2008-08-21 20:08:03 +0000 | [diff] [blame] | 2942 | |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2943 | dcl = ds->listeners; |
| 2944 | while (dcl != NULL) { |
| 2945 | if (dcl->dpy_refresh != NULL) { |
| 2946 | ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds); |
| 2947 | qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock)); |
Isaku Yamahata | 0f2ad63 | 2010-05-27 14:38:47 +0900 | [diff] [blame] | 2948 | break; |
ths | 20d8a3e | 2007-02-18 17:04:49 +0000 | [diff] [blame] | 2949 | } |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2950 | dcl = dcl->next; |
bellard | 82c643f | 2004-07-14 17:28:13 +0000 | [diff] [blame] | 2951 | } |
aliguori | 3023f33 | 2009-01-16 19:04:14 +0000 | [diff] [blame] | 2952 | |
Anthony Liguori | 993fbfd | 2009-05-21 16:54:00 -0500 | [diff] [blame] | 2953 | if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) { |
blueswir1 | 9043b62 | 2009-01-21 19:28:13 +0000 | [diff] [blame] | 2954 | nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL); |
| 2955 | qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock)); |
| 2956 | } |
| 2957 | |
Paolo Bonzini | b473df6 | 2010-02-11 00:29:55 +0100 | [diff] [blame] | 2958 | text_consoles_set_display(ds); |
aliguori | 2796dae | 2009-01-16 20:23:27 +0000 | [diff] [blame] | 2959 | |
aliguori | 59030a8 | 2009-04-05 18:43:41 +0000 | [diff] [blame] | 2960 | if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { |
| 2961 | fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n", |
| 2962 | gdbstub_dev); |
| 2963 | exit(1); |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 2964 | } |
balrog | 45669e0 | 2007-07-02 13:20:17 +0000 | [diff] [blame] | 2965 | |
Gerd Hoffmann | 3418bd2 | 2009-09-25 21:42:41 +0200 | [diff] [blame] | 2966 | qdev_machine_creation_done(); |
| 2967 | |
Gerd Hoffmann | 15ff770 | 2009-12-14 16:07:35 +0100 | [diff] [blame] | 2968 | if (rom_load_all() != 0) { |
| 2969 | fprintf(stderr, "rom loading failed\n"); |
| 2970 | exit(1); |
| 2971 | } |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 2972 | |
Juan Quintela | 504c294 | 2009-11-12 00:39:13 +0100 | [diff] [blame] | 2973 | qemu_system_reset(); |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 2974 | if (loadvm) { |
Markus Armbruster | 03cd465 | 2010-02-17 16:24:10 +0100 | [diff] [blame] | 2975 | if (load_vmstate(loadvm) < 0) { |
Juan Quintela | 05f2401 | 2009-08-20 19:42:22 +0200 | [diff] [blame] | 2976 | autostart = 0; |
| 2977 | } |
| 2978 | } |
bellard | d63d307 | 2004-10-03 13:29:03 +0000 | [diff] [blame] | 2979 | |
Glauber Costa | 2bb8c10 | 2009-07-24 16:20:23 -0400 | [diff] [blame] | 2980 | if (incoming) { |
Juan Quintela | 8ca5e80 | 2010-06-09 14:10:54 +0200 | [diff] [blame] | 2981 | int ret = qemu_start_incoming_migration(incoming); |
| 2982 | if (ret < 0) { |
| 2983 | fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n", |
| 2984 | incoming, ret); |
| 2985 | exit(ret); |
| 2986 | } |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 2987 | } else if (autostart) { |
aliguori | c0f4ce7 | 2009-03-05 23:01:01 +0000 | [diff] [blame] | 2988 | vm_start(); |
Avi Kivity | 6b99dad | 2009-08-09 14:39:20 +0300 | [diff] [blame] | 2989 | } |
ths | ffd843b | 2006-12-21 19:46:43 +0000 | [diff] [blame] | 2990 | |
Jes Sorensen | eb505be | 2010-06-10 11:42:28 +0200 | [diff] [blame] | 2991 | os_setup_post(); |
ths | 71e3ceb | 2006-12-22 02:11:31 +0000 | [diff] [blame] | 2992 | |
bellard | 8a7ddc3 | 2004-03-31 19:00:16 +0000 | [diff] [blame] | 2993 | main_loop(); |
bellard | 40c3bac | 2004-04-04 12:56:28 +0000 | [diff] [blame] | 2994 | quit_timers(); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 2995 | net_cleanup(); |
ths | b46a890 | 2007-10-21 23:20:45 +0000 | [diff] [blame] | 2996 | |
bellard | 0824d6f | 2003-06-24 13:42:40 +0000 | [diff] [blame] | 2997 | return 0; |
| 2998 | } |