David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QEMU System Emulator |
| 3 | * |
| 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
| 5 | * |
| 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. |
| 23 | */ |
| 24 | |
| 25 | /* the following is needed on Linux to define ptsname() in stdlib.h */ |
| 26 | #if defined(__linux__) |
| 27 | #define _GNU_SOURCE 1 |
| 28 | #endif |
| 29 | |
| 30 | #include "qemu-common.h" |
| 31 | #include "hw/hw.h" |
| 32 | #include "hw/boards.h" |
| 33 | #include "hw/usb.h" |
| 34 | #include "hw/pcmcia.h" |
David 'Digit' Turner | 2ec695a | 2013-12-17 10:03:39 +0100 | [diff] [blame] | 35 | #include "hw/i386/pc.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 36 | #include "hw/audiodev.h" |
David 'Digit' Turner | 2ec695a | 2013-12-17 10:03:39 +0100 | [diff] [blame] | 37 | #include "hw/isa/isa.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 38 | #include "hw/baum.h" |
David 'Digit' Turner | f066542 | 2013-12-17 10:47:09 +0100 | [diff] [blame] | 39 | #include "hw/android/goldfish/nand.h" |
David 'Digit' Turner | cc330d4 | 2013-12-14 23:26:42 +0100 | [diff] [blame] | 40 | #include "net/net.h" |
David 'Digit' Turner | 1c31e3e | 2013-12-14 20:07:17 +0100 | [diff] [blame] | 41 | #include "ui/console.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 42 | #include "sysemu/sysemu.h" |
David 'Digit' Turner | 852088c | 2013-12-14 23:04:12 +0100 | [diff] [blame] | 43 | #include "exec/gdbstub.h" |
David 'Digit' Turner | 7a78db7 | 2013-12-14 11:46:01 +0100 | [diff] [blame] | 44 | #include "qemu/timer.h" |
David 'Digit' Turner | e7216d8 | 2013-12-15 00:51:13 +0100 | [diff] [blame] | 45 | #include "sysemu/char.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 46 | #include "sysemu/blockdev.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 47 | #include "audio/audio.h" |
| 48 | |
David 'Digit' Turner | 28a09b6 | 2013-12-15 00:16:00 +0100 | [diff] [blame] | 49 | #include "migration/qemu-file.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 50 | #include "android/android.h" |
David 'Digit' Turner | e1e03df | 2013-12-15 00:42:21 +0100 | [diff] [blame] | 51 | #include "android/charpipe.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 52 | #include "modem_driver.h" |
| 53 | #include "android/gps.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 54 | #include "android/hw-kmsg.h" |
David 'Digit' Turner | c0ac733 | 2011-05-02 15:05:35 +0200 | [diff] [blame] | 55 | #include "android/hw-pipe-net.h" |
| 56 | #include "android/hw-qemud.h" |
Vladimir Chtchetkine | c646f5e | 2011-09-03 15:17:13 -0700 | [diff] [blame] | 57 | #include "android/camera/camera-service.h" |
Vladimir Chtchetkine | 8dd31e8 | 2012-02-15 17:16:04 -0800 | [diff] [blame] | 58 | #include "android/multitouch-port.h" |
Vladimir Chtchetkine | eb83825 | 2010-07-15 12:27:56 -0700 | [diff] [blame] | 59 | #include "android/charmap.h" |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 60 | #include "android/globals.h" |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 61 | #include "android/utils/bufprint.h" |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 62 | #include "android/utils/debug.h" |
David 'Digit' Turner | 48a3c66 | 2011-03-01 14:03:20 +0100 | [diff] [blame] | 63 | #include "android/utils/filelock.h" |
| 64 | #include "android/utils/path.h" |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 65 | #include "android/utils/stralloc.h" |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 66 | #include "android/utils/tempfile.h" |
Vladimir Chtchetkine | 72d83df | 2010-12-14 09:24:02 -0800 | [diff] [blame] | 67 | #include "android/display-core.h" |
Vladimir Chtchetkine | 90c6235 | 2011-01-13 11:24:07 -0800 | [diff] [blame] | 68 | #include "android/utils/timezone.h" |
David 'Digit' Turner | bdb6f2d | 2011-02-23 15:57:25 +0100 | [diff] [blame] | 69 | #include "android/snapshot.h" |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 70 | #include "android/opengles.h" |
Vladimir Chtchetkine | 1a820e9 | 2012-04-11 13:22:48 -0700 | [diff] [blame] | 71 | #include "android/multitouch-screen.h" |
David 'Digit' Turner | bcde109 | 2014-01-09 23:19:19 +0100 | [diff] [blame] | 72 | #include "exec/hwaddr.h" |
David 'Digit' Turner | 6e2eb78 | 2013-12-15 00:54:21 +0100 | [diff] [blame] | 73 | #include "android/tcpdump.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 74 | |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 75 | #ifdef CONFIG_MEMCHECK |
| 76 | #include "memcheck/memcheck.h" |
| 77 | #endif // CONFIG_MEMCHECK |
| 78 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 79 | #include <unistd.h> |
| 80 | #include <fcntl.h> |
| 81 | #include <signal.h> |
| 82 | #include <time.h> |
| 83 | #include <errno.h> |
| 84 | #include <sys/time.h> |
| 85 | #include <zlib.h> |
| 86 | |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 87 | /* Needed early for CONFIG_BSD etc. */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 88 | #include "config-host.h" |
| 89 | |
| 90 | #ifndef _WIN32 |
| 91 | #include <libgen.h> |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 92 | #include <sys/times.h> |
| 93 | #include <sys/wait.h> |
| 94 | #include <termios.h> |
| 95 | #include <sys/mman.h> |
| 96 | #include <sys/ioctl.h> |
| 97 | #include <sys/resource.h> |
| 98 | #include <sys/socket.h> |
| 99 | #include <netinet/in.h> |
| 100 | #include <net/if.h> |
| 101 | #if defined(__NetBSD__) |
| 102 | #include <net/if_tap.h> |
| 103 | #endif |
| 104 | #ifdef __linux__ |
| 105 | #include <linux/if_tun.h> |
| 106 | #endif |
| 107 | #include <arpa/inet.h> |
| 108 | #include <dirent.h> |
| 109 | #include <netdb.h> |
| 110 | #include <sys/select.h> |
David 'Digit' Turner | 2c538c8 | 2010-05-10 16:48:20 -0700 | [diff] [blame] | 111 | #ifdef CONFIG_BSD |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 112 | #include <sys/stat.h> |
| 113 | #if defined(__FreeBSD__) || defined(__DragonFly__) |
| 114 | #include <libutil.h> |
| 115 | #else |
| 116 | #include <util.h> |
| 117 | #endif |
| 118 | #elif defined (__GLIBC__) && defined (__FreeBSD_kernel__) |
| 119 | #include <freebsd/stdlib.h> |
| 120 | #else |
| 121 | #ifdef __linux__ |
| 122 | #include <pty.h> |
| 123 | #include <malloc.h> |
| 124 | #include <linux/rtc.h> |
| 125 | |
| 126 | /* For the benefit of older linux systems which don't supply it, |
| 127 | we use a local copy of hpet.h. */ |
| 128 | /* #include <linux/hpet.h> */ |
David 'Digit' Turner | 2dbdad5 | 2013-12-17 09:24:18 +0100 | [diff] [blame] | 129 | #include "hw/timer/hpet.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 130 | |
| 131 | #include <linux/ppdev.h> |
| 132 | #include <linux/parport.h> |
| 133 | #endif |
| 134 | #ifdef __sun__ |
| 135 | #include <sys/stat.h> |
| 136 | #include <sys/ethernet.h> |
| 137 | #include <sys/sockio.h> |
| 138 | #include <netinet/arp.h> |
| 139 | #include <netinet/in.h> |
| 140 | #include <netinet/in_systm.h> |
| 141 | #include <netinet/ip.h> |
| 142 | #include <netinet/ip_icmp.h> // must come after ip.h |
| 143 | #include <netinet/udp.h> |
| 144 | #include <netinet/tcp.h> |
| 145 | #include <net/if.h> |
| 146 | #include <syslog.h> |
| 147 | #include <stropts.h> |
| 148 | #endif |
| 149 | #endif |
| 150 | #endif |
| 151 | |
| 152 | #if defined(__OpenBSD__) |
| 153 | #include <util.h> |
| 154 | #endif |
| 155 | |
| 156 | #if defined(CONFIG_VDE) |
| 157 | #include <libvdeplug.h> |
| 158 | #endif |
| 159 | |
| 160 | #ifdef _WIN32 |
| 161 | #include <windows.h> |
| 162 | #include <malloc.h> |
| 163 | #include <sys/timeb.h> |
| 164 | #include <mmsystem.h> |
| 165 | #define getopt_long_only getopt_long |
| 166 | #define memalign(align, size) malloc(size) |
| 167 | #endif |
| 168 | |
David 'Digit' Turner | 1182284 | 2013-12-17 09:16:47 +0100 | [diff] [blame] | 169 | #include "sysemu/cpus.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 170 | #include "sysemu/arch_init.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 171 | |
| 172 | #ifdef CONFIG_COCOA |
David 'Digit' Turner | ae3098a | 2011-05-11 16:01:57 +0200 | [diff] [blame] | 173 | int qemu_main(int argc, char **argv, char **envp); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 174 | #undef main |
| 175 | #define main qemu_main |
| 176 | #endif /* CONFIG_COCOA */ |
| 177 | |
| 178 | #include "hw/hw.h" |
| 179 | #include "hw/boards.h" |
| 180 | #include "hw/usb.h" |
| 181 | #include "hw/pcmcia.h" |
David 'Digit' Turner | 2ec695a | 2013-12-17 10:03:39 +0100 | [diff] [blame] | 182 | #include "hw/i386/pc.h" |
| 183 | #include "hw/isa/isa.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 184 | #include "hw/baum.h" |
| 185 | #include "hw/bt.h" |
David 'Digit' Turner | 7821d63 | 2013-12-17 11:27:50 +0100 | [diff] [blame] | 186 | #include "sysemu/watchdog.h" |
David 'Digit' Turner | 73a93a1 | 2013-12-17 11:26:01 +0100 | [diff] [blame] | 187 | #include "hw/i386/smbios.h" |
David 'Digit' Turner | 5031918 | 2013-12-17 11:28:54 +0100 | [diff] [blame] | 188 | #include "hw/xen/xen.h" |
David 'Digit' Turner | 6800f0a | 2013-12-17 09:12:54 +0100 | [diff] [blame] | 189 | #include "sysemu/bt.h" |
David 'Digit' Turner | cc330d4 | 2013-12-14 23:26:42 +0100 | [diff] [blame] | 190 | #include "net/net.h" |
David 'Digit' Turner | 6af6765 | 2013-12-14 23:49:32 +0100 | [diff] [blame] | 191 | #include "monitor/monitor.h" |
David 'Digit' Turner | 1c31e3e | 2013-12-14 20:07:17 +0100 | [diff] [blame] | 192 | #include "ui/console.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 193 | #include "sysemu/sysemu.h" |
David 'Digit' Turner | 852088c | 2013-12-14 23:04:12 +0100 | [diff] [blame] | 194 | #include "exec/gdbstub.h" |
David 'Digit' Turner | 7a78db7 | 2013-12-14 11:46:01 +0100 | [diff] [blame] | 195 | #include "qemu/timer.h" |
David 'Digit' Turner | e7216d8 | 2013-12-15 00:51:13 +0100 | [diff] [blame] | 196 | #include "sysemu/char.h" |
David 'Digit' Turner | 37dc41a | 2013-12-14 14:45:51 +0100 | [diff] [blame] | 197 | #include "qemu/cache-utils.h" |
David 'Digit' Turner | e1e03df | 2013-12-15 00:42:21 +0100 | [diff] [blame] | 198 | #include "block/block.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 199 | #include "sysemu/dma.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 200 | #include "audio/audio.h" |
David 'Digit' Turner | 28a09b6 | 2013-12-15 00:16:00 +0100 | [diff] [blame] | 201 | #include "migration/migration.h" |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 202 | #include "sysemu/kvm.h" |
David 'Digit' Turner | e1e03df | 2013-12-15 00:42:21 +0100 | [diff] [blame] | 203 | #include "exec/hax.h" |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 204 | #ifdef CONFIG_KVM |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 205 | #include "android/kvm.h" |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 206 | #endif |
David 'Digit' Turner | 34c48ff | 2013-12-15 00:25:03 +0100 | [diff] [blame] | 207 | #include "sysemu/balloon.h" |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 208 | #include "android/hw-lcd.h" |
| 209 | #include "android/boot-properties.h" |
David 'Digit' Turner | ca95059 | 2011-04-27 12:26:15 +0200 | [diff] [blame] | 210 | #include "android/hw-control.h" |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 211 | #include "android/core-init-utils.h" |
David 'Digit' Turner | ca29fbb | 2011-01-02 13:17:22 +0100 | [diff] [blame] | 212 | #include "android/audio-test.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 213 | |
Vladimir Chtchetkine | db450d7 | 2012-01-12 13:37:40 -0800 | [diff] [blame] | 214 | #include "android/snaphost-android.h" |
| 215 | |
Vladimir Chtchetkine | 5758404 | 2011-01-20 16:15:30 -0800 | [diff] [blame] | 216 | #if !defined(CONFIG_STANDALONE_CORE) |
| 217 | /* in android/qemulator.c */ |
| 218 | extern void android_emulator_set_base_port(int port); |
| 219 | #endif |
| 220 | |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 221 | #if defined(CONFIG_SKINS) && !defined(CONFIG_STANDALONE_CORE) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 222 | #undef main |
| 223 | #define main qemu_main |
| 224 | #endif |
| 225 | |
David 'Digit' Turner | cc33b2d | 2013-12-15 00:09:42 +0100 | [diff] [blame] | 226 | #include "disas/disas.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 227 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 228 | #ifdef CONFIG_TRACE |
David 'Digit' Turner | d4e803c | 2013-12-14 23:45:50 +0100 | [diff] [blame] | 229 | #include "android/trace.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 230 | #endif |
| 231 | |
David 'Digit' Turner | d0edecb | 2013-12-17 09:32:26 +0100 | [diff] [blame] | 232 | #include "qemu/sockets.h" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 233 | |
| 234 | #if defined(CONFIG_SLIRP) |
| 235 | #include "libslirp.h" |
| 236 | #endif |
| 237 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 238 | #define DEFAULT_RAM_SIZE 128 |
| 239 | |
| 240 | /* Max number of USB devices that can be specified on the commandline. */ |
| 241 | #define MAX_USB_CMDLINE 8 |
| 242 | |
| 243 | /* Max number of bluetooth switches on the commandline. */ |
| 244 | #define MAX_BT_CMDLINE 10 |
| 245 | |
| 246 | /* XXX: use a two level table to limit memory usage */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 247 | |
| 248 | static const char *data_dir; |
| 249 | const char *bios_name = NULL; |
| 250 | static void *ioport_opaque[MAX_IOPORTS]; |
| 251 | static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS]; |
| 252 | static IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS]; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 253 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 254 | /* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available |
| 255 | to store the VM snapshots */ |
| 256 | DriveInfo drives_table[MAX_DRIVES+1]; |
| 257 | int nb_drives; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 258 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 259 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 260 | DisplayType display_type = DT_DEFAULT; |
| 261 | const char* keyboard_layout = NULL; |
| 262 | int64_t ticks_per_sec; |
| 263 | ram_addr_t ram_size; |
David 'Digit' Turner | 280afa0 | 2011-05-11 17:37:44 +0200 | [diff] [blame] | 264 | const char *mem_path = NULL; |
| 265 | #ifdef MAP_POPULATE |
| 266 | int mem_prealloc = 0; /* force preallocation of physical target memory */ |
| 267 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 268 | int nb_nics; |
| 269 | NICInfo nd_table[MAX_NICS]; |
| 270 | int vm_running; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 271 | int autostart; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 272 | static int rtc_utc = 1; |
| 273 | static int rtc_date_offset = -1; /* -1 means no change */ |
| 274 | int cirrus_vga_enabled = 1; |
| 275 | int std_vga_enabled = 0; |
| 276 | int vmsvga_enabled = 0; |
| 277 | int xenfb_enabled = 0; |
David 'Digit' Turner | a7fb77d | 2010-05-10 23:50:54 -0700 | [diff] [blame] | 278 | QEMUClock *rtc_clock; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 279 | static int full_screen = 0; |
| 280 | #ifdef CONFIG_SDL |
| 281 | static int no_frame = 0; |
| 282 | #endif |
| 283 | int no_quit = 0; |
| 284 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 285 | int serial_hds_count; |
| 286 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 287 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
| 288 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
| 289 | #ifdef TARGET_I386 |
| 290 | int win2k_install_hack = 0; |
| 291 | int rtc_td_hack = 0; |
| 292 | #endif |
| 293 | int usb_enabled = 0; |
| 294 | int singlestep = 0; |
| 295 | int smp_cpus = 1; |
| 296 | const char *vnc_display; |
| 297 | int acpi_enabled = 1; |
| 298 | int no_hpet = 0; |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 299 | int hax_disabled = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 300 | int no_virtio_balloon = 0; |
| 301 | int fd_bootchk = 1; |
| 302 | int no_reboot = 0; |
| 303 | int no_shutdown = 0; |
| 304 | int cursor_hide = 1; |
| 305 | int graphic_rotate = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 306 | WatchdogTimerModel *watchdog = NULL; |
| 307 | int watchdog_action = WDT_RESET; |
| 308 | const char *option_rom[MAX_OPTION_ROMS]; |
| 309 | int nb_option_roms; |
| 310 | int semihosting_enabled = 0; |
| 311 | #ifdef TARGET_ARM |
| 312 | int old_param = 0; |
| 313 | #endif |
| 314 | const char *qemu_name; |
| 315 | int alt_grab = 0; |
| 316 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) |
| 317 | unsigned int nb_prom_envs = 0; |
| 318 | const char *prom_envs[MAX_PROM_ENVS]; |
| 319 | #endif |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 320 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 321 | int nb_drives_opt; |
| 322 | struct drive_opt drives_opt[MAX_DRIVES]; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 323 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 324 | int nb_numa_nodes; |
| 325 | uint64_t node_mem[MAX_NODES]; |
| 326 | uint64_t node_cpumask[MAX_NODES]; |
| 327 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 328 | static QEMUTimer *nographic_timer; |
| 329 | |
| 330 | uint8_t qemu_uuid[16]; |
| 331 | |
| 332 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 333 | int qemu_cpu_delay; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 334 | extern char* audio_input_source; |
| 335 | |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 336 | extern char* android_op_ports; |
| 337 | extern char* android_op_port; |
| 338 | extern char* android_op_report_console; |
| 339 | extern char* op_http_proxy; |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 340 | // Path to the file containing specific key character map. |
| 341 | char* op_charmap_file = NULL; |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 342 | |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 343 | /* Path to hardware initialization file passed with -android-hw option. */ |
| 344 | char* android_op_hwini = NULL; |
| 345 | |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 346 | /* Memory checker options. */ |
| 347 | char* android_op_memcheck = NULL; |
| 348 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 349 | /* -dns-server option value. */ |
| 350 | char* android_op_dns_server = NULL; |
| 351 | |
Vladimir Chtchetkine | 13f3b6c | 2010-08-25 09:49:25 -0700 | [diff] [blame] | 352 | /* -radio option value. */ |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 353 | char* android_op_radio = NULL; |
| 354 | |
| 355 | /* -gps option value. */ |
| 356 | char* android_op_gps = NULL; |
| 357 | |
| 358 | /* -audio option value. */ |
| 359 | char* android_op_audio = NULL; |
| 360 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 361 | /* -cpu-delay option value. */ |
| 362 | char* android_op_cpu_delay = NULL; |
| 363 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 364 | #ifdef CONFIG_NAND_LIMITS |
| 365 | /* -nand-limits option value. */ |
| 366 | char* android_op_nand_limits = NULL; |
| 367 | #endif // CONFIG_NAND_LIMITS |
| 368 | |
| 369 | /* -netspeed option value. */ |
| 370 | char* android_op_netspeed = NULL; |
| 371 | |
| 372 | /* -netdelay option value. */ |
| 373 | char* android_op_netdelay = NULL; |
| 374 | |
| 375 | /* -netfast option value. */ |
| 376 | int android_op_netfast = 0; |
| 377 | |
Vladimir Chtchetkine | 318f17a | 2010-08-27 09:09:45 -0700 | [diff] [blame] | 378 | /* -tcpdump option value. */ |
| 379 | char* android_op_tcpdump = NULL; |
| 380 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 381 | /* -lcd-density option value. */ |
| 382 | char* android_op_lcd_density = NULL; |
| 383 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 384 | /* -ui-port option value. This port will be used to report the core |
| 385 | * initialization completion. |
| 386 | */ |
| 387 | char* android_op_ui_port = NULL; |
| 388 | |
| 389 | /* -ui-settings option value. This value will be passed to the UI when new UI |
| 390 | * process is attaching to the core. |
| 391 | */ |
| 392 | char* android_op_ui_settings = NULL; |
| 393 | |
Vladimir Chtchetkine | 90c6235 | 2011-01-13 11:24:07 -0800 | [diff] [blame] | 394 | /* -android-avdname option value. */ |
| 395 | char* android_op_avd_name = "unknown"; |
| 396 | |
Vladimir Chtchetkine | dd50f7d | 2010-07-30 09:16:41 -0700 | [diff] [blame] | 397 | extern int android_display_width; |
| 398 | extern int android_display_height; |
| 399 | extern int android_display_bpp; |
| 400 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 401 | extern void dprint( const char* format, ... ); |
| 402 | |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 403 | const char* dns_log_filename = NULL; |
| 404 | const char* drop_log_filename = NULL; |
| 405 | static int rotate_logs_requested = 0; |
| 406 | |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 407 | const char* savevm_on_exit = NULL; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 408 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 409 | #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) |
| 410 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 411 | /* Reports the core initialization failure to the error stdout and to the UI |
| 412 | * socket before exiting the application. |
| 413 | * Parameters that are passed to this macro are used to format the error |
| 414 | * mesage using sprintf routine. |
| 415 | */ |
| 416 | #ifdef CONFIG_ANDROID |
| 417 | #define PANIC(...) android_core_init_failure(__VA_ARGS__) |
| 418 | #else |
| 419 | #define PANIC(...) do { fprintf(stderr, __VA_ARGS__); \ |
| 420 | exit(1); \ |
| 421 | } while (0) |
| 422 | #endif // CONFIG_ANDROID |
| 423 | |
| 424 | /* Exits the core during initialization. */ |
| 425 | #ifdef CONFIG_ANDROID |
| 426 | #define QEMU_EXIT(exit_code) android_core_init_exit(exit_code) |
| 427 | #else |
| 428 | #define QEMU_EXIT(exit_code) exit(exit_code) |
| 429 | #endif // CONFIG_ANDROID |
| 430 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 431 | /***********************************************************/ |
| 432 | /* x86 ISA bus support */ |
| 433 | |
David 'Digit' Turner | bcde109 | 2014-01-09 23:19:19 +0100 | [diff] [blame] | 434 | hwaddr isa_mem_base = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 435 | PicState2 *isa_pic; |
| 436 | |
| 437 | static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl; |
| 438 | static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel; |
| 439 | |
| 440 | static uint32_t ioport_read(int index, uint32_t address) |
| 441 | { |
| 442 | static IOPortReadFunc *default_func[3] = { |
| 443 | default_ioport_readb, |
| 444 | default_ioport_readw, |
| 445 | default_ioport_readl |
| 446 | }; |
| 447 | IOPortReadFunc *func = ioport_read_table[index][address]; |
| 448 | if (!func) |
| 449 | func = default_func[index]; |
| 450 | return func(ioport_opaque[address], address); |
| 451 | } |
| 452 | |
| 453 | static void ioport_write(int index, uint32_t address, uint32_t data) |
| 454 | { |
| 455 | static IOPortWriteFunc *default_func[3] = { |
| 456 | default_ioport_writeb, |
| 457 | default_ioport_writew, |
| 458 | default_ioport_writel |
| 459 | }; |
| 460 | IOPortWriteFunc *func = ioport_write_table[index][address]; |
| 461 | if (!func) |
| 462 | func = default_func[index]; |
| 463 | func(ioport_opaque[address], address, data); |
| 464 | } |
| 465 | |
| 466 | static uint32_t default_ioport_readb(void *opaque, uint32_t address) |
| 467 | { |
| 468 | #ifdef DEBUG_UNUSED_IOPORT |
| 469 | fprintf(stderr, "unused inb: port=0x%04x\n", address); |
| 470 | #endif |
| 471 | return 0xff; |
| 472 | } |
| 473 | |
| 474 | static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data) |
| 475 | { |
| 476 | #ifdef DEBUG_UNUSED_IOPORT |
| 477 | fprintf(stderr, "unused outb: port=0x%04x data=0x%02x\n", address, data); |
| 478 | #endif |
| 479 | } |
| 480 | |
| 481 | /* default is to make two byte accesses */ |
| 482 | static uint32_t default_ioport_readw(void *opaque, uint32_t address) |
| 483 | { |
| 484 | uint32_t data; |
| 485 | data = ioport_read(0, address); |
| 486 | address = (address + 1) & (MAX_IOPORTS - 1); |
| 487 | data |= ioport_read(0, address) << 8; |
| 488 | return data; |
| 489 | } |
| 490 | |
| 491 | static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data) |
| 492 | { |
| 493 | ioport_write(0, address, data & 0xff); |
| 494 | address = (address + 1) & (MAX_IOPORTS - 1); |
| 495 | ioport_write(0, address, (data >> 8) & 0xff); |
| 496 | } |
| 497 | |
| 498 | static uint32_t default_ioport_readl(void *opaque, uint32_t address) |
| 499 | { |
| 500 | #ifdef DEBUG_UNUSED_IOPORT |
| 501 | fprintf(stderr, "unused inl: port=0x%04x\n", address); |
| 502 | #endif |
| 503 | return 0xffffffff; |
| 504 | } |
| 505 | |
| 506 | static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data) |
| 507 | { |
| 508 | #ifdef DEBUG_UNUSED_IOPORT |
| 509 | fprintf(stderr, "unused outl: port=0x%04x data=0x%02x\n", address, data); |
| 510 | #endif |
| 511 | } |
| 512 | |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 513 | /* |
| 514 | * Sets a flag (rotate_logs_requested) to clear both the DNS and the |
| 515 | * drop logs upon receiving a SIGUSR1 signal. We need to clear the logs |
| 516 | * between the tasks that do not require restarting Qemu. |
| 517 | */ |
| 518 | void rotate_qemu_logs_handler(int signum) { |
| 519 | rotate_logs_requested = 1; |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | * Resets the rotate_log_requested_flag. Normally called after qemu |
| 524 | * logs has been rotated. |
| 525 | */ |
| 526 | void reset_rotate_qemu_logs_request(void) { |
| 527 | rotate_logs_requested = 0; |
| 528 | } |
| 529 | |
| 530 | /* |
| 531 | * Clears the passed qemu log when the rotate_logs_requested |
| 532 | * is set. We need to clear the logs between the tasks that do not |
| 533 | * require restarting Qemu. |
| 534 | */ |
| 535 | FILE* rotate_qemu_log(FILE* old_log_fd, const char* filename) { |
| 536 | FILE* new_log_fd = NULL; |
| 537 | if (old_log_fd) { |
| 538 | if (fclose(old_log_fd) == -1) { |
| 539 | fprintf(stderr, "Cannot close old_log fd\n"); |
| 540 | exit(errno); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | if (!filename) { |
| 545 | fprintf(stderr, "The log filename to be rotated is not provided"); |
| 546 | exit(-1); |
| 547 | } |
| 548 | |
| 549 | new_log_fd = fopen(filename , "wb+"); |
| 550 | if (new_log_fd == NULL) { |
| 551 | fprintf(stderr, "Cannot open the log file: %s for write.\n", |
| 552 | filename); |
| 553 | exit(1); |
| 554 | } |
| 555 | |
| 556 | return new_log_fd; |
| 557 | } |
| 558 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 559 | /***************/ |
| 560 | /* ballooning */ |
| 561 | |
| 562 | static QEMUBalloonEvent *qemu_balloon_event; |
| 563 | void *qemu_balloon_event_opaque; |
| 564 | |
| 565 | void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) |
| 566 | { |
| 567 | qemu_balloon_event = func; |
| 568 | qemu_balloon_event_opaque = opaque; |
| 569 | } |
| 570 | |
| 571 | void qemu_balloon(ram_addr_t target) |
| 572 | { |
| 573 | if (qemu_balloon_event) |
| 574 | qemu_balloon_event(qemu_balloon_event_opaque, target); |
| 575 | } |
| 576 | |
| 577 | ram_addr_t qemu_balloon_status(void) |
| 578 | { |
| 579 | if (qemu_balloon_event) |
| 580 | return qemu_balloon_event(qemu_balloon_event_opaque, 0); |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | /***********************************************************/ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 585 | /* host time/date access */ |
| 586 | void qemu_get_timedate(struct tm *tm, int offset) |
| 587 | { |
| 588 | time_t ti; |
| 589 | struct tm *ret; |
| 590 | |
| 591 | time(&ti); |
| 592 | ti += offset; |
| 593 | if (rtc_date_offset == -1) { |
| 594 | if (rtc_utc) |
| 595 | ret = gmtime(&ti); |
| 596 | else |
| 597 | ret = localtime(&ti); |
| 598 | } else { |
| 599 | ti -= rtc_date_offset; |
| 600 | ret = gmtime(&ti); |
| 601 | } |
| 602 | |
| 603 | memcpy(tm, ret, sizeof(struct tm)); |
| 604 | } |
| 605 | |
| 606 | int qemu_timedate_diff(struct tm *tm) |
| 607 | { |
| 608 | time_t seconds; |
| 609 | |
| 610 | if (rtc_date_offset == -1) |
| 611 | if (rtc_utc) |
| 612 | seconds = mktimegm(tm); |
| 613 | else |
| 614 | seconds = mktime(tm); |
| 615 | else |
| 616 | seconds = mktimegm(tm) + rtc_date_offset; |
| 617 | |
| 618 | return seconds - time(NULL); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | #ifdef CONFIG_TRACE |
David 'Digit' Turner | 23ca2ae | 2011-06-01 16:14:53 +0200 | [diff] [blame] | 623 | int tbflush_requested; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 624 | static int exit_requested; |
| 625 | |
| 626 | void start_tracing() |
| 627 | { |
| 628 | if (trace_filename == NULL) |
| 629 | return; |
| 630 | if (!tracing) { |
| 631 | fprintf(stderr,"-- start tracing --\n"); |
| 632 | start_time = Now(); |
| 633 | } |
| 634 | tracing = 1; |
| 635 | tbflush_requested = 1; |
| 636 | qemu_notify_event(); |
| 637 | } |
| 638 | |
| 639 | void stop_tracing() |
| 640 | { |
| 641 | if (trace_filename == NULL) |
| 642 | return; |
| 643 | if (tracing) { |
| 644 | end_time = Now(); |
| 645 | elapsed_usecs += end_time - start_time; |
| 646 | fprintf(stderr,"-- stop tracing --\n"); |
| 647 | } |
| 648 | tracing = 0; |
| 649 | tbflush_requested = 1; |
| 650 | qemu_notify_event(); |
| 651 | } |
| 652 | |
| 653 | #ifndef _WIN32 |
| 654 | /* This is the handler for the SIGUSR1 and SIGUSR2 signals. |
| 655 | * SIGUSR1 turns tracing on. SIGUSR2 turns tracing off. |
| 656 | */ |
| 657 | void sigusr_handler(int sig) |
| 658 | { |
| 659 | if (sig == SIGUSR1) |
| 660 | start_tracing(); |
| 661 | else |
| 662 | stop_tracing(); |
| 663 | } |
| 664 | #endif |
| 665 | |
| 666 | /* This is the handler to catch control-C so that we can exit cleanly. |
| 667 | * This is needed when tracing to flush the buffers to disk. |
| 668 | */ |
| 669 | void sigint_handler(int sig) |
| 670 | { |
| 671 | exit_requested = 1; |
| 672 | qemu_notify_event(); |
| 673 | } |
| 674 | #endif /* CONFIG_TRACE */ |
| 675 | |
| 676 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 677 | /***********************************************************/ |
| 678 | /* Bluetooth support */ |
| 679 | static int nb_hcis; |
| 680 | static int cur_hci; |
| 681 | static struct HCIInfo *hci_table[MAX_NICS]; |
| 682 | |
| 683 | static struct bt_vlan_s { |
| 684 | struct bt_scatternet_s net; |
| 685 | int id; |
| 686 | struct bt_vlan_s *next; |
| 687 | } *first_bt_vlan; |
| 688 | |
| 689 | /* find or alloc a new bluetooth "VLAN" */ |
| 690 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
| 691 | { |
| 692 | struct bt_vlan_s **pvlan, *vlan; |
| 693 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { |
| 694 | if (vlan->id == id) |
| 695 | return &vlan->net; |
| 696 | } |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 697 | vlan = g_malloc0(sizeof(struct bt_vlan_s)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 698 | vlan->id = id; |
| 699 | pvlan = &first_bt_vlan; |
| 700 | while (*pvlan != NULL) |
| 701 | pvlan = &(*pvlan)->next; |
| 702 | *pvlan = vlan; |
| 703 | return &vlan->net; |
| 704 | } |
| 705 | |
| 706 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) |
| 707 | { |
| 708 | } |
| 709 | |
| 710 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) |
| 711 | { |
| 712 | return -ENOTSUP; |
| 713 | } |
| 714 | |
| 715 | static struct HCIInfo null_hci = { |
| 716 | .cmd_send = null_hci_send, |
| 717 | .sco_send = null_hci_send, |
| 718 | .acl_send = null_hci_send, |
| 719 | .bdaddr_set = null_hci_addr_set, |
| 720 | }; |
| 721 | |
| 722 | struct HCIInfo *qemu_next_hci(void) |
| 723 | { |
| 724 | if (cur_hci == nb_hcis) |
| 725 | return &null_hci; |
| 726 | |
| 727 | return hci_table[cur_hci++]; |
| 728 | } |
| 729 | |
| 730 | static struct HCIInfo *hci_init(const char *str) |
| 731 | { |
| 732 | char *endp; |
| 733 | struct bt_scatternet_s *vlan = 0; |
| 734 | |
| 735 | if (!strcmp(str, "null")) |
| 736 | /* null */ |
| 737 | return &null_hci; |
| 738 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) |
| 739 | /* host[:hciN] */ |
| 740 | return bt_host_hci(str[4] ? str + 5 : "hci0"); |
| 741 | else if (!strncmp(str, "hci", 3)) { |
| 742 | /* hci[,vlan=n] */ |
| 743 | if (str[3]) { |
| 744 | if (!strncmp(str + 3, ",vlan=", 6)) { |
| 745 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); |
| 746 | if (*endp) |
| 747 | vlan = 0; |
| 748 | } |
| 749 | } else |
| 750 | vlan = qemu_find_bt_vlan(0); |
| 751 | if (vlan) |
| 752 | return bt_new_hci(vlan); |
| 753 | } |
| 754 | |
| 755 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); |
| 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | static int bt_hci_parse(const char *str) |
| 761 | { |
| 762 | struct HCIInfo *hci; |
| 763 | bdaddr_t bdaddr; |
| 764 | |
| 765 | if (nb_hcis >= MAX_NICS) { |
| 766 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); |
| 767 | return -1; |
| 768 | } |
| 769 | |
| 770 | hci = hci_init(str); |
| 771 | if (!hci) |
| 772 | return -1; |
| 773 | |
| 774 | bdaddr.b[0] = 0x52; |
| 775 | bdaddr.b[1] = 0x54; |
| 776 | bdaddr.b[2] = 0x00; |
| 777 | bdaddr.b[3] = 0x12; |
| 778 | bdaddr.b[4] = 0x34; |
| 779 | bdaddr.b[5] = 0x56 + nb_hcis; |
| 780 | hci->bdaddr_set(hci, bdaddr.b); |
| 781 | |
| 782 | hci_table[nb_hcis++] = hci; |
| 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | static void bt_vhci_add(int vlan_id) |
| 788 | { |
| 789 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); |
| 790 | |
| 791 | if (!vlan->slave) |
| 792 | fprintf(stderr, "qemu: warning: adding a VHCI to " |
| 793 | "an empty scatternet %i\n", vlan_id); |
| 794 | |
| 795 | bt_vhci_init(bt_new_hci(vlan)); |
| 796 | } |
| 797 | |
| 798 | static struct bt_device_s *bt_device_add(const char *opt) |
| 799 | { |
| 800 | struct bt_scatternet_s *vlan; |
| 801 | int vlan_id = 0; |
| 802 | char *endp = strstr(opt, ",vlan="); |
| 803 | int len = (endp ? endp - opt : strlen(opt)) + 1; |
| 804 | char devname[10]; |
| 805 | |
| 806 | pstrcpy(devname, MIN(sizeof(devname), len), opt); |
| 807 | |
| 808 | if (endp) { |
| 809 | vlan_id = strtol(endp + 6, &endp, 0); |
| 810 | if (*endp) { |
| 811 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); |
| 812 | return 0; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | vlan = qemu_find_bt_vlan(vlan_id); |
| 817 | |
| 818 | if (!vlan->slave) |
| 819 | fprintf(stderr, "qemu: warning: adding a slave device to " |
| 820 | "an empty scatternet %i\n", vlan_id); |
| 821 | |
| 822 | if (!strcmp(devname, "keyboard")) |
| 823 | return bt_keyboard_init(vlan); |
| 824 | |
| 825 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | static int bt_parse(const char *opt) |
| 830 | { |
| 831 | const char *endp, *p; |
| 832 | int vlan; |
| 833 | |
| 834 | if (strstart(opt, "hci", &endp)) { |
| 835 | if (!*endp || *endp == ',') { |
| 836 | if (*endp) |
| 837 | if (!strstart(endp, ",vlan=", 0)) |
| 838 | opt = endp + 1; |
| 839 | |
| 840 | return bt_hci_parse(opt); |
| 841 | } |
| 842 | } else if (strstart(opt, "vhci", &endp)) { |
| 843 | if (!*endp || *endp == ',') { |
| 844 | if (*endp) { |
| 845 | if (strstart(endp, ",vlan=", &p)) { |
| 846 | vlan = strtol(p, (char **) &endp, 0); |
| 847 | if (*endp) { |
| 848 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); |
| 849 | return 1; |
| 850 | } |
| 851 | } else { |
| 852 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); |
| 853 | return 1; |
| 854 | } |
| 855 | } else |
| 856 | vlan = 0; |
| 857 | |
| 858 | bt_vhci_add(vlan); |
| 859 | return 0; |
| 860 | } |
| 861 | } else if (strstart(opt, "device:", &endp)) |
| 862 | return !bt_device_add(endp); |
| 863 | |
| 864 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); |
| 865 | return 1; |
| 866 | } |
| 867 | |
| 868 | /***********************************************************/ |
| 869 | /* QEMU Block devices */ |
| 870 | |
| 871 | #define HD_ALIAS "index=%d,media=disk" |
| 872 | #define CDROM_ALIAS "index=2,media=cdrom" |
| 873 | #define FD_ALIAS "index=%d,if=floppy" |
| 874 | #define PFLASH_ALIAS "if=pflash" |
| 875 | #define MTD_ALIAS "if=mtd" |
| 876 | #define SD_ALIAS "index=0,if=sd" |
| 877 | |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 878 | static int drive_init_func(QemuOpts *opts, void *opaque) |
| 879 | { |
| 880 | int *use_scsi = opaque; |
| 881 | int fatal_error = 0; |
| 882 | |
| 883 | if (drive_init(opts, *use_scsi, &fatal_error) == NULL) { |
| 884 | if (fatal_error) |
| 885 | return 1; |
| 886 | } |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) |
| 891 | { |
| 892 | if (NULL == qemu_opt_get(opts, "snapshot")) { |
| 893 | qemu_opt_set(opts, "snapshot", "on"); |
| 894 | } |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 899 | static int drive_opt_get_free_idx(void) |
| 900 | { |
| 901 | int index; |
| 902 | |
| 903 | for (index = 0; index < MAX_DRIVES; index++) |
| 904 | if (!drives_opt[index].used) { |
| 905 | drives_opt[index].used = 1; |
| 906 | return index; |
| 907 | } |
| 908 | |
| 909 | return -1; |
| 910 | } |
| 911 | |
| 912 | static int drive_get_free_idx(void) |
| 913 | { |
| 914 | int index; |
| 915 | |
| 916 | for (index = 0; index < MAX_DRIVES; index++) |
| 917 | if (!drives_table[index].used) { |
| 918 | drives_table[index].used = 1; |
| 919 | return index; |
| 920 | } |
| 921 | |
| 922 | return -1; |
| 923 | } |
| 924 | |
| 925 | int drive_add(const char *file, const char *fmt, ...) |
| 926 | { |
| 927 | va_list ap; |
| 928 | int index = drive_opt_get_free_idx(); |
| 929 | |
| 930 | if (nb_drives_opt >= MAX_DRIVES || index == -1) { |
| 931 | fprintf(stderr, "qemu: too many drives\n"); |
| 932 | return -1; |
| 933 | } |
| 934 | |
| 935 | drives_opt[index].file = file; |
| 936 | va_start(ap, fmt); |
| 937 | vsnprintf(drives_opt[index].opt, |
| 938 | sizeof(drives_opt[0].opt), fmt, ap); |
| 939 | va_end(ap); |
David 'Digit' Turner | 9256895 | 2010-04-15 15:04:16 -0700 | [diff] [blame] | 940 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 941 | nb_drives_opt++; |
| 942 | return index; |
| 943 | } |
| 944 | |
| 945 | void drive_remove(int index) |
| 946 | { |
| 947 | drives_opt[index].used = 0; |
| 948 | nb_drives_opt--; |
| 949 | } |
| 950 | |
| 951 | int drive_get_index(BlockInterfaceType type, int bus, int unit) |
| 952 | { |
| 953 | int index; |
| 954 | |
| 955 | /* seek interface, bus and unit */ |
| 956 | |
| 957 | for (index = 0; index < MAX_DRIVES; index++) |
| 958 | if (drives_table[index].type == type && |
| 959 | drives_table[index].bus == bus && |
| 960 | drives_table[index].unit == unit && |
| 961 | drives_table[index].used) |
| 962 | return index; |
| 963 | |
| 964 | return -1; |
| 965 | } |
| 966 | |
| 967 | int drive_get_max_bus(BlockInterfaceType type) |
| 968 | { |
| 969 | int max_bus; |
| 970 | int index; |
| 971 | |
| 972 | max_bus = -1; |
| 973 | for (index = 0; index < nb_drives; index++) { |
| 974 | if(drives_table[index].type == type && |
| 975 | drives_table[index].bus > max_bus) |
| 976 | max_bus = drives_table[index].bus; |
| 977 | } |
| 978 | return max_bus; |
| 979 | } |
| 980 | |
| 981 | const char *drive_get_serial(BlockDriverState *bdrv) |
| 982 | { |
| 983 | int index; |
| 984 | |
| 985 | for (index = 0; index < nb_drives; index++) |
| 986 | if (drives_table[index].bdrv == bdrv) |
| 987 | return drives_table[index].serial; |
| 988 | |
| 989 | return "\0"; |
| 990 | } |
| 991 | |
| 992 | BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv) |
| 993 | { |
| 994 | int index; |
| 995 | |
| 996 | for (index = 0; index < nb_drives; index++) |
| 997 | if (drives_table[index].bdrv == bdrv) |
| 998 | return drives_table[index].onerror; |
| 999 | |
| 1000 | return BLOCK_ERR_STOP_ENOSPC; |
| 1001 | } |
| 1002 | |
| 1003 | static void bdrv_format_print(void *opaque, const char *name) |
| 1004 | { |
| 1005 | fprintf(stderr, " %s", name); |
| 1006 | } |
| 1007 | |
| 1008 | void drive_uninit(BlockDriverState *bdrv) |
| 1009 | { |
| 1010 | int i; |
| 1011 | |
| 1012 | for (i = 0; i < MAX_DRIVES; i++) |
| 1013 | if (drives_table[i].bdrv == bdrv) { |
| 1014 | drives_table[i].bdrv = NULL; |
| 1015 | drives_table[i].used = 0; |
| 1016 | drive_remove(drives_table[i].drive_opt_idx); |
| 1017 | nb_drives--; |
| 1018 | break; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | int drive_init(struct drive_opt *arg, int snapshot, void *opaque) |
| 1023 | { |
| 1024 | char buf[128]; |
| 1025 | char file[1024]; |
| 1026 | char devname[128]; |
| 1027 | char serial[21]; |
| 1028 | const char *mediastr = ""; |
| 1029 | BlockInterfaceType type; |
| 1030 | enum { MEDIA_DISK, MEDIA_CDROM } media; |
| 1031 | int bus_id, unit_id; |
| 1032 | int cyls, heads, secs, translation; |
| 1033 | BlockDriverState *bdrv; |
| 1034 | BlockDriver *drv = NULL; |
| 1035 | QEMUMachine *machine = opaque; |
| 1036 | int max_devs; |
| 1037 | int index; |
| 1038 | int cache; |
| 1039 | int bdrv_flags, onerror; |
| 1040 | int drives_table_idx; |
| 1041 | char *str = arg->opt; |
| 1042 | static const char * const params[] = { "bus", "unit", "if", "index", |
| 1043 | "cyls", "heads", "secs", "trans", |
| 1044 | "media", "snapshot", "file", |
| 1045 | "cache", "format", "serial", "werror", |
| 1046 | NULL }; |
| 1047 | |
| 1048 | if (check_params(buf, sizeof(buf), params, str) < 0) { |
| 1049 | fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n", |
| 1050 | buf, str); |
| 1051 | return -1; |
| 1052 | } |
| 1053 | |
| 1054 | file[0] = 0; |
| 1055 | cyls = heads = secs = 0; |
| 1056 | bus_id = 0; |
| 1057 | unit_id = -1; |
| 1058 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 1059 | index = -1; |
| 1060 | cache = 3; |
| 1061 | |
| 1062 | if (machine->use_scsi) { |
| 1063 | type = IF_SCSI; |
| 1064 | max_devs = MAX_SCSI_DEVS; |
| 1065 | pstrcpy(devname, sizeof(devname), "scsi"); |
| 1066 | } else { |
| 1067 | type = IF_IDE; |
| 1068 | max_devs = MAX_IDE_DEVS; |
| 1069 | pstrcpy(devname, sizeof(devname), "ide"); |
| 1070 | } |
| 1071 | media = MEDIA_DISK; |
| 1072 | |
| 1073 | /* extract parameters */ |
| 1074 | |
| 1075 | if (get_param_value(buf, sizeof(buf), "bus", str)) { |
| 1076 | bus_id = strtol(buf, NULL, 0); |
| 1077 | if (bus_id < 0) { |
| 1078 | fprintf(stderr, "qemu: '%s' invalid bus id\n", str); |
| 1079 | return -1; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | if (get_param_value(buf, sizeof(buf), "unit", str)) { |
| 1084 | unit_id = strtol(buf, NULL, 0); |
| 1085 | if (unit_id < 0) { |
| 1086 | fprintf(stderr, "qemu: '%s' invalid unit id\n", str); |
| 1087 | return -1; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | if (get_param_value(buf, sizeof(buf), "if", str)) { |
| 1092 | pstrcpy(devname, sizeof(devname), buf); |
| 1093 | if (!strcmp(buf, "ide")) { |
| 1094 | type = IF_IDE; |
| 1095 | max_devs = MAX_IDE_DEVS; |
| 1096 | } else if (!strcmp(buf, "scsi")) { |
| 1097 | type = IF_SCSI; |
| 1098 | max_devs = MAX_SCSI_DEVS; |
| 1099 | } else if (!strcmp(buf, "floppy")) { |
| 1100 | type = IF_FLOPPY; |
| 1101 | max_devs = 0; |
| 1102 | } else if (!strcmp(buf, "pflash")) { |
| 1103 | type = IF_PFLASH; |
| 1104 | max_devs = 0; |
| 1105 | } else if (!strcmp(buf, "mtd")) { |
| 1106 | type = IF_MTD; |
| 1107 | max_devs = 0; |
| 1108 | } else if (!strcmp(buf, "sd")) { |
| 1109 | type = IF_SD; |
| 1110 | max_devs = 0; |
| 1111 | } else if (!strcmp(buf, "virtio")) { |
| 1112 | type = IF_VIRTIO; |
| 1113 | max_devs = 0; |
| 1114 | } else if (!strcmp(buf, "xen")) { |
| 1115 | type = IF_XEN; |
| 1116 | max_devs = 0; |
| 1117 | } else { |
| 1118 | fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf); |
| 1119 | return -1; |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | if (get_param_value(buf, sizeof(buf), "index", str)) { |
| 1124 | index = strtol(buf, NULL, 0); |
| 1125 | if (index < 0) { |
| 1126 | fprintf(stderr, "qemu: '%s' invalid index\n", str); |
| 1127 | return -1; |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | if (get_param_value(buf, sizeof(buf), "cyls", str)) { |
| 1132 | cyls = strtol(buf, NULL, 0); |
| 1133 | } |
| 1134 | |
| 1135 | if (get_param_value(buf, sizeof(buf), "heads", str)) { |
| 1136 | heads = strtol(buf, NULL, 0); |
| 1137 | } |
| 1138 | |
| 1139 | if (get_param_value(buf, sizeof(buf), "secs", str)) { |
| 1140 | secs = strtol(buf, NULL, 0); |
| 1141 | } |
| 1142 | |
| 1143 | if (cyls || heads || secs) { |
| 1144 | if (cyls < 1 || cyls > 16383) { |
| 1145 | fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str); |
| 1146 | return -1; |
| 1147 | } |
| 1148 | if (heads < 1 || heads > 16) { |
| 1149 | fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str); |
| 1150 | return -1; |
| 1151 | } |
| 1152 | if (secs < 1 || secs > 63) { |
| 1153 | fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str); |
| 1154 | return -1; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | if (get_param_value(buf, sizeof(buf), "trans", str)) { |
| 1159 | if (!cyls) { |
| 1160 | fprintf(stderr, |
| 1161 | "qemu: '%s' trans must be used with cyls,heads and secs\n", |
| 1162 | str); |
| 1163 | return -1; |
| 1164 | } |
| 1165 | if (!strcmp(buf, "none")) |
| 1166 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 1167 | else if (!strcmp(buf, "lba")) |
| 1168 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 1169 | else if (!strcmp(buf, "auto")) |
| 1170 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 1171 | else { |
| 1172 | fprintf(stderr, "qemu: '%s' invalid translation type\n", str); |
| 1173 | return -1; |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | if (get_param_value(buf, sizeof(buf), "media", str)) { |
| 1178 | if (!strcmp(buf, "disk")) { |
| 1179 | media = MEDIA_DISK; |
| 1180 | } else if (!strcmp(buf, "cdrom")) { |
| 1181 | if (cyls || secs || heads) { |
| 1182 | fprintf(stderr, |
| 1183 | "qemu: '%s' invalid physical CHS format\n", str); |
| 1184 | return -1; |
| 1185 | } |
| 1186 | media = MEDIA_CDROM; |
| 1187 | } else { |
| 1188 | fprintf(stderr, "qemu: '%s' invalid media\n", str); |
| 1189 | return -1; |
| 1190 | } |
| 1191 | } |
| 1192 | |
| 1193 | if (get_param_value(buf, sizeof(buf), "snapshot", str)) { |
| 1194 | if (!strcmp(buf, "on")) |
| 1195 | snapshot = 1; |
| 1196 | else if (!strcmp(buf, "off")) |
| 1197 | snapshot = 0; |
| 1198 | else { |
| 1199 | fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str); |
| 1200 | return -1; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | if (get_param_value(buf, sizeof(buf), "cache", str)) { |
| 1205 | if (!strcmp(buf, "off") || !strcmp(buf, "none")) |
| 1206 | cache = 0; |
| 1207 | else if (!strcmp(buf, "writethrough")) |
| 1208 | cache = 1; |
| 1209 | else if (!strcmp(buf, "writeback")) |
| 1210 | cache = 2; |
| 1211 | else { |
| 1212 | fprintf(stderr, "qemu: invalid cache option\n"); |
| 1213 | return -1; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (get_param_value(buf, sizeof(buf), "format", str)) { |
| 1218 | if (strcmp(buf, "?") == 0) { |
| 1219 | fprintf(stderr, "qemu: Supported formats:"); |
| 1220 | bdrv_iterate_format(bdrv_format_print, NULL); |
| 1221 | fprintf(stderr, "\n"); |
| 1222 | return -1; |
| 1223 | } |
| 1224 | drv = bdrv_find_format(buf); |
| 1225 | if (!drv) { |
| 1226 | fprintf(stderr, "qemu: '%s' invalid format\n", buf); |
| 1227 | return -1; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | if (arg->file == NULL) |
| 1232 | get_param_value(file, sizeof(file), "file", str); |
| 1233 | else |
| 1234 | pstrcpy(file, sizeof(file), arg->file); |
| 1235 | |
| 1236 | if (!get_param_value(serial, sizeof(serial), "serial", str)) |
| 1237 | memset(serial, 0, sizeof(serial)); |
| 1238 | |
| 1239 | onerror = BLOCK_ERR_STOP_ENOSPC; |
| 1240 | if (get_param_value(buf, sizeof(serial), "werror", str)) { |
| 1241 | if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) { |
| 1242 | fprintf(stderr, "werror is no supported by this format\n"); |
| 1243 | return -1; |
| 1244 | } |
| 1245 | if (!strcmp(buf, "ignore")) |
| 1246 | onerror = BLOCK_ERR_IGNORE; |
| 1247 | else if (!strcmp(buf, "enospc")) |
| 1248 | onerror = BLOCK_ERR_STOP_ENOSPC; |
| 1249 | else if (!strcmp(buf, "stop")) |
| 1250 | onerror = BLOCK_ERR_STOP_ANY; |
| 1251 | else if (!strcmp(buf, "report")) |
| 1252 | onerror = BLOCK_ERR_REPORT; |
| 1253 | else { |
| 1254 | fprintf(stderr, "qemu: '%s' invalid write error action\n", buf); |
| 1255 | return -1; |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | /* compute bus and unit according index */ |
| 1260 | |
| 1261 | if (index != -1) { |
| 1262 | if (bus_id != 0 || unit_id != -1) { |
| 1263 | fprintf(stderr, |
| 1264 | "qemu: '%s' index cannot be used with bus and unit\n", str); |
| 1265 | return -1; |
| 1266 | } |
| 1267 | if (max_devs == 0) |
| 1268 | { |
| 1269 | unit_id = index; |
| 1270 | bus_id = 0; |
| 1271 | } else { |
| 1272 | unit_id = index % max_devs; |
| 1273 | bus_id = index / max_devs; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /* if user doesn't specify a unit_id, |
| 1278 | * try to find the first free |
| 1279 | */ |
| 1280 | |
| 1281 | if (unit_id == -1) { |
| 1282 | unit_id = 0; |
| 1283 | while (drive_get_index(type, bus_id, unit_id) != -1) { |
| 1284 | unit_id++; |
| 1285 | if (max_devs && unit_id >= max_devs) { |
| 1286 | unit_id -= max_devs; |
| 1287 | bus_id++; |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | /* check unit id */ |
| 1293 | |
| 1294 | if (max_devs && unit_id >= max_devs) { |
| 1295 | fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n", |
| 1296 | str, unit_id, max_devs - 1); |
| 1297 | return -1; |
| 1298 | } |
| 1299 | |
| 1300 | /* |
| 1301 | * ignore multiple definitions |
| 1302 | */ |
| 1303 | |
| 1304 | if (drive_get_index(type, bus_id, unit_id) != -1) |
| 1305 | return -2; |
| 1306 | |
| 1307 | /* init */ |
| 1308 | |
| 1309 | if (type == IF_IDE || type == IF_SCSI) |
| 1310 | mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; |
| 1311 | if (max_devs) |
| 1312 | snprintf(buf, sizeof(buf), "%s%i%s%i", |
| 1313 | devname, bus_id, mediastr, unit_id); |
| 1314 | else |
| 1315 | snprintf(buf, sizeof(buf), "%s%s%i", |
| 1316 | devname, mediastr, unit_id); |
| 1317 | bdrv = bdrv_new(buf); |
| 1318 | drives_table_idx = drive_get_free_idx(); |
| 1319 | drives_table[drives_table_idx].bdrv = bdrv; |
| 1320 | drives_table[drives_table_idx].type = type; |
| 1321 | drives_table[drives_table_idx].bus = bus_id; |
| 1322 | drives_table[drives_table_idx].unit = unit_id; |
| 1323 | drives_table[drives_table_idx].onerror = onerror; |
| 1324 | drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt; |
| 1325 | strncpy(drives_table[drives_table_idx].serial, serial, sizeof(serial)); |
| 1326 | nb_drives++; |
| 1327 | |
| 1328 | switch(type) { |
| 1329 | case IF_IDE: |
| 1330 | case IF_SCSI: |
| 1331 | case IF_XEN: |
| 1332 | switch(media) { |
| 1333 | case MEDIA_DISK: |
| 1334 | if (cyls != 0) { |
| 1335 | bdrv_set_geometry_hint(bdrv, cyls, heads, secs); |
| 1336 | bdrv_set_translation_hint(bdrv, translation); |
| 1337 | } |
| 1338 | break; |
| 1339 | case MEDIA_CDROM: |
| 1340 | bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM); |
| 1341 | break; |
| 1342 | } |
| 1343 | break; |
| 1344 | case IF_SD: |
| 1345 | /* FIXME: This isn't really a floppy, but it's a reasonable |
| 1346 | approximation. */ |
| 1347 | case IF_FLOPPY: |
| 1348 | bdrv_set_type_hint(bdrv, BDRV_TYPE_FLOPPY); |
| 1349 | break; |
| 1350 | case IF_PFLASH: |
| 1351 | case IF_MTD: |
| 1352 | case IF_VIRTIO: |
| 1353 | break; |
| 1354 | case IF_COUNT: |
David 'Digit' Turner | c34e8dc | 2010-09-13 02:47:01 -0700 | [diff] [blame] | 1355 | case IF_NONE: |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1356 | abort(); |
| 1357 | } |
| 1358 | if (!file[0]) |
| 1359 | return -2; |
| 1360 | bdrv_flags = 0; |
| 1361 | if (snapshot) { |
| 1362 | bdrv_flags |= BDRV_O_SNAPSHOT; |
| 1363 | cache = 2; /* always use write-back with snapshot */ |
| 1364 | } |
| 1365 | if (cache == 0) /* no caching */ |
| 1366 | bdrv_flags |= BDRV_O_NOCACHE; |
| 1367 | else if (cache == 2) /* write-back */ |
| 1368 | bdrv_flags |= BDRV_O_CACHE_WB; |
| 1369 | else if (cache == 3) /* not specified */ |
| 1370 | bdrv_flags |= BDRV_O_CACHE_DEF; |
| 1371 | if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) { |
| 1372 | fprintf(stderr, "qemu: could not open disk image %s\n", |
| 1373 | file); |
| 1374 | return -1; |
| 1375 | } |
| 1376 | if (bdrv_key_required(bdrv)) |
| 1377 | autostart = 0; |
| 1378 | return drives_table_idx; |
| 1379 | } |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 1380 | #endif /* MAX_DRIVES */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1381 | |
| 1382 | static void numa_add(const char *optarg) |
| 1383 | { |
| 1384 | char option[128]; |
| 1385 | char *endptr; |
| 1386 | unsigned long long value, endvalue; |
| 1387 | int nodenr; |
| 1388 | |
| 1389 | optarg = get_opt_name(option, 128, optarg, ',') + 1; |
| 1390 | if (!strcmp(option, "node")) { |
| 1391 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { |
| 1392 | nodenr = nb_numa_nodes; |
| 1393 | } else { |
| 1394 | nodenr = strtoull(option, NULL, 10); |
| 1395 | } |
| 1396 | |
| 1397 | if (get_param_value(option, 128, "mem", optarg) == 0) { |
| 1398 | node_mem[nodenr] = 0; |
| 1399 | } else { |
| 1400 | value = strtoull(option, &endptr, 0); |
| 1401 | switch (*endptr) { |
| 1402 | case 0: case 'M': case 'm': |
| 1403 | value <<= 20; |
| 1404 | break; |
| 1405 | case 'G': case 'g': |
| 1406 | value <<= 30; |
| 1407 | break; |
| 1408 | } |
| 1409 | node_mem[nodenr] = value; |
| 1410 | } |
| 1411 | if (get_param_value(option, 128, "cpus", optarg) == 0) { |
| 1412 | node_cpumask[nodenr] = 0; |
| 1413 | } else { |
| 1414 | value = strtoull(option, &endptr, 10); |
| 1415 | if (value >= 64) { |
| 1416 | value = 63; |
| 1417 | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n"); |
| 1418 | } else { |
| 1419 | if (*endptr == '-') { |
| 1420 | endvalue = strtoull(endptr+1, &endptr, 10); |
| 1421 | if (endvalue >= 63) { |
| 1422 | endvalue = 62; |
| 1423 | fprintf(stderr, |
| 1424 | "only 63 CPUs in NUMA mode supported.\n"); |
| 1425 | } |
| 1426 | value = (1 << (endvalue + 1)) - (1 << value); |
| 1427 | } else { |
| 1428 | value = 1 << value; |
| 1429 | } |
| 1430 | } |
| 1431 | node_cpumask[nodenr] = value; |
| 1432 | } |
| 1433 | nb_numa_nodes++; |
| 1434 | } |
| 1435 | return; |
| 1436 | } |
| 1437 | |
| 1438 | /***********************************************************/ |
| 1439 | /* USB devices */ |
| 1440 | |
| 1441 | static USBPort *used_usb_ports; |
| 1442 | static USBPort *free_usb_ports; |
| 1443 | |
| 1444 | /* ??? Maybe change this to register a hub to keep track of the topology. */ |
| 1445 | void qemu_register_usb_port(USBPort *port, void *opaque, int index, |
| 1446 | usb_attachfn attach) |
| 1447 | { |
| 1448 | port->opaque = opaque; |
| 1449 | port->index = index; |
| 1450 | port->attach = attach; |
| 1451 | port->next = free_usb_ports; |
| 1452 | free_usb_ports = port; |
| 1453 | } |
| 1454 | |
| 1455 | int usb_device_add_dev(USBDevice *dev) |
| 1456 | { |
| 1457 | USBPort *port; |
| 1458 | |
| 1459 | /* Find a USB port to add the device to. */ |
| 1460 | port = free_usb_ports; |
Manuel Francisco Naranjo | 58ecd74 | 2012-07-18 11:22:09 -0300 | [diff] [blame] | 1461 | if (!port){ |
| 1462 | USBDevice *hub = usb_hub_init(VM_USB_HUB_SIZE); |
| 1463 | port = free_usb_ports; |
| 1464 | usb_attach(port, hub); |
| 1465 | } |
| 1466 | else if (!port->next){ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1467 | USBDevice *hub; |
| 1468 | |
| 1469 | /* Create a new hub and chain it on. */ |
| 1470 | free_usb_ports = NULL; |
| 1471 | port->next = used_usb_ports; |
| 1472 | used_usb_ports = port; |
| 1473 | |
| 1474 | hub = usb_hub_init(VM_USB_HUB_SIZE); |
| 1475 | usb_attach(port, hub); |
| 1476 | port = free_usb_ports; |
| 1477 | } |
| 1478 | |
| 1479 | free_usb_ports = port->next; |
| 1480 | port->next = used_usb_ports; |
| 1481 | used_usb_ports = port; |
| 1482 | usb_attach(port, dev); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
David 'Digit' Turner | 3266b51 | 2010-05-10 18:44:56 -0700 | [diff] [blame] | 1486 | #if 0 |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1487 | static void usb_msd_password_cb(void *opaque, int err) |
| 1488 | { |
| 1489 | USBDevice *dev = opaque; |
| 1490 | |
| 1491 | if (!err) |
| 1492 | usb_device_add_dev(dev); |
| 1493 | else |
| 1494 | dev->handle_destroy(dev); |
| 1495 | } |
David 'Digit' Turner | 3266b51 | 2010-05-10 18:44:56 -0700 | [diff] [blame] | 1496 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1497 | |
| 1498 | static int usb_device_add(const char *devname, int is_hotplug) |
| 1499 | { |
| 1500 | const char *p; |
| 1501 | USBDevice *dev; |
| 1502 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1503 | if (strstart(devname, "host:", &p)) { |
| 1504 | dev = usb_host_device_open(p); |
| 1505 | } else if (!strcmp(devname, "mouse")) { |
| 1506 | dev = usb_mouse_init(); |
| 1507 | } else if (!strcmp(devname, "tablet")) { |
| 1508 | dev = usb_tablet_init(); |
| 1509 | } else if (!strcmp(devname, "keyboard")) { |
| 1510 | dev = usb_keyboard_init(); |
| 1511 | } else if (strstart(devname, "disk:", &p)) { |
| 1512 | #if 0 |
| 1513 | BlockDriverState *bs; |
| 1514 | #endif |
| 1515 | dev = usb_msd_init(p); |
| 1516 | if (!dev) |
| 1517 | return -1; |
| 1518 | #if 0 |
| 1519 | bs = usb_msd_get_bdrv(dev); |
| 1520 | if (bdrv_key_required(bs)) { |
| 1521 | autostart = 0; |
| 1522 | if (is_hotplug) { |
| 1523 | monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb, |
| 1524 | dev); |
| 1525 | return 0; |
| 1526 | } |
| 1527 | } |
| 1528 | } else if (!strcmp(devname, "wacom-tablet")) { |
| 1529 | dev = usb_wacom_init(); |
| 1530 | } else if (strstart(devname, "serial:", &p)) { |
| 1531 | dev = usb_serial_init(p); |
| 1532 | #ifdef CONFIG_BRLAPI |
| 1533 | } else if (!strcmp(devname, "braille")) { |
| 1534 | dev = usb_baum_init(); |
| 1535 | #endif |
| 1536 | } else if (strstart(devname, "net:", &p)) { |
| 1537 | int nic = nb_nics; |
| 1538 | |
| 1539 | if (net_client_init("nic", p) < 0) |
| 1540 | return -1; |
| 1541 | nd_table[nic].model = "usb"; |
| 1542 | dev = usb_net_init(&nd_table[nic]); |
| 1543 | } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { |
| 1544 | dev = usb_bt_init(devname[2] ? hci_init(p) : |
| 1545 | bt_new_hci(qemu_find_bt_vlan(0))); |
| 1546 | #endif |
| 1547 | } else { |
| 1548 | return -1; |
| 1549 | } |
| 1550 | if (!dev) |
| 1551 | return -1; |
| 1552 | |
| 1553 | return usb_device_add_dev(dev); |
| 1554 | } |
| 1555 | |
| 1556 | int usb_device_del_addr(int bus_num, int addr) |
| 1557 | { |
| 1558 | USBPort *port; |
| 1559 | USBPort **lastp; |
| 1560 | USBDevice *dev; |
| 1561 | |
| 1562 | if (!used_usb_ports) |
| 1563 | return -1; |
| 1564 | |
| 1565 | if (bus_num != 0) |
| 1566 | return -1; |
| 1567 | |
| 1568 | lastp = &used_usb_ports; |
| 1569 | port = used_usb_ports; |
| 1570 | while (port && port->dev->addr != addr) { |
| 1571 | lastp = &port->next; |
| 1572 | port = port->next; |
| 1573 | } |
| 1574 | |
| 1575 | if (!port) |
| 1576 | return -1; |
| 1577 | |
| 1578 | dev = port->dev; |
| 1579 | *lastp = port->next; |
| 1580 | usb_attach(port, NULL); |
| 1581 | dev->handle_destroy(dev); |
| 1582 | port->next = free_usb_ports; |
| 1583 | free_usb_ports = port; |
| 1584 | return 0; |
| 1585 | } |
| 1586 | |
| 1587 | static int usb_device_del(const char *devname) |
| 1588 | { |
| 1589 | int bus_num, addr; |
| 1590 | const char *p; |
| 1591 | |
| 1592 | if (strstart(devname, "host:", &p)) |
| 1593 | return usb_host_device_close(p); |
| 1594 | |
| 1595 | if (!used_usb_ports) |
| 1596 | return -1; |
| 1597 | |
| 1598 | p = strchr(devname, '.'); |
| 1599 | if (!p) |
| 1600 | return -1; |
| 1601 | bus_num = strtoul(devname, NULL, 0); |
| 1602 | addr = strtoul(p + 1, NULL, 0); |
| 1603 | |
| 1604 | return usb_device_del_addr(bus_num, addr); |
| 1605 | } |
| 1606 | |
| 1607 | void do_usb_add(Monitor *mon, const char *devname) |
| 1608 | { |
| 1609 | usb_device_add(devname, 1); |
| 1610 | } |
| 1611 | |
| 1612 | void do_usb_del(Monitor *mon, const char *devname) |
| 1613 | { |
| 1614 | usb_device_del(devname); |
| 1615 | } |
| 1616 | |
| 1617 | void usb_info(Monitor *mon) |
| 1618 | { |
| 1619 | USBDevice *dev; |
| 1620 | USBPort *port; |
| 1621 | const char *speed_str; |
| 1622 | |
| 1623 | if (!usb_enabled) { |
| 1624 | monitor_printf(mon, "USB support not enabled\n"); |
| 1625 | return; |
| 1626 | } |
| 1627 | |
| 1628 | for (port = used_usb_ports; port; port = port->next) { |
| 1629 | dev = port->dev; |
| 1630 | if (!dev) |
| 1631 | continue; |
| 1632 | switch(dev->speed) { |
| 1633 | case USB_SPEED_LOW: |
| 1634 | speed_str = "1.5"; |
| 1635 | break; |
| 1636 | case USB_SPEED_FULL: |
| 1637 | speed_str = "12"; |
| 1638 | break; |
| 1639 | case USB_SPEED_HIGH: |
| 1640 | speed_str = "480"; |
| 1641 | break; |
| 1642 | default: |
| 1643 | speed_str = "?"; |
| 1644 | break; |
| 1645 | } |
| 1646 | monitor_printf(mon, " Device %d.%d, Speed %s Mb/s, Product %s\n", |
| 1647 | 0, dev->addr, speed_str, dev->devname); |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | /***********************************************************/ |
| 1652 | /* PCMCIA/Cardbus */ |
| 1653 | |
| 1654 | static struct pcmcia_socket_entry_s { |
| 1655 | PCMCIASocket *socket; |
| 1656 | struct pcmcia_socket_entry_s *next; |
| 1657 | } *pcmcia_sockets = 0; |
| 1658 | |
| 1659 | void pcmcia_socket_register(PCMCIASocket *socket) |
| 1660 | { |
| 1661 | struct pcmcia_socket_entry_s *entry; |
| 1662 | |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1663 | entry = g_malloc(sizeof(struct pcmcia_socket_entry_s)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1664 | entry->socket = socket; |
| 1665 | entry->next = pcmcia_sockets; |
| 1666 | pcmcia_sockets = entry; |
| 1667 | } |
| 1668 | |
| 1669 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
| 1670 | { |
| 1671 | struct pcmcia_socket_entry_s *entry, **ptr; |
| 1672 | |
| 1673 | ptr = &pcmcia_sockets; |
| 1674 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) |
| 1675 | if (entry->socket == socket) { |
| 1676 | *ptr = entry->next; |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1677 | g_free(entry); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | void pcmcia_info(Monitor *mon) |
| 1682 | { |
| 1683 | struct pcmcia_socket_entry_s *iter; |
| 1684 | |
| 1685 | if (!pcmcia_sockets) |
| 1686 | monitor_printf(mon, "No PCMCIA sockets\n"); |
| 1687 | |
| 1688 | for (iter = pcmcia_sockets; iter; iter = iter->next) |
| 1689 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
| 1690 | iter->socket->attached ? iter->socket->card_string : |
| 1691 | "Empty"); |
| 1692 | } |
| 1693 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1694 | /***********************************************************/ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1695 | /* machine registration */ |
| 1696 | |
| 1697 | static QEMUMachine *first_machine = NULL; |
| 1698 | QEMUMachine *current_machine = NULL; |
| 1699 | |
| 1700 | int qemu_register_machine(QEMUMachine *m) |
| 1701 | { |
| 1702 | QEMUMachine **pm; |
| 1703 | pm = &first_machine; |
| 1704 | while (*pm != NULL) |
| 1705 | pm = &(*pm)->next; |
| 1706 | m->next = NULL; |
| 1707 | *pm = m; |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
| 1711 | static QEMUMachine *find_machine(const char *name) |
| 1712 | { |
| 1713 | QEMUMachine *m; |
| 1714 | |
| 1715 | for(m = first_machine; m != NULL; m = m->next) { |
| 1716 | if (!strcmp(m->name, name)) |
| 1717 | return m; |
| 1718 | } |
| 1719 | return NULL; |
| 1720 | } |
| 1721 | |
| 1722 | static QEMUMachine *find_default_machine(void) |
| 1723 | { |
| 1724 | QEMUMachine *m; |
| 1725 | |
| 1726 | for(m = first_machine; m != NULL; m = m->next) { |
| 1727 | if (m->is_default) { |
| 1728 | return m; |
| 1729 | } |
| 1730 | } |
| 1731 | return NULL; |
| 1732 | } |
| 1733 | |
| 1734 | /***********************************************************/ |
| 1735 | /* main execution loop */ |
| 1736 | |
| 1737 | static void gui_update(void *opaque) |
| 1738 | { |
| 1739 | uint64_t interval = GUI_REFRESH_INTERVAL; |
| 1740 | DisplayState *ds = opaque; |
| 1741 | DisplayChangeListener *dcl = ds->listeners; |
| 1742 | |
| 1743 | dpy_refresh(ds); |
| 1744 | |
| 1745 | while (dcl != NULL) { |
| 1746 | if (dcl->gui_timer_interval && |
| 1747 | dcl->gui_timer_interval < interval) |
| 1748 | interval = dcl->gui_timer_interval; |
| 1749 | dcl = dcl->next; |
| 1750 | } |
David 'Digit' Turner | 5973c77 | 2011-05-10 07:06:00 +0200 | [diff] [blame] | 1751 | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | static void nographic_update(void *opaque) |
| 1755 | { |
| 1756 | uint64_t interval = GUI_REFRESH_INTERVAL; |
| 1757 | |
David 'Digit' Turner | 5973c77 | 2011-05-10 07:06:00 +0200 | [diff] [blame] | 1758 | qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | struct vm_change_state_entry { |
| 1762 | VMChangeStateHandler *cb; |
| 1763 | void *opaque; |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1764 | QLIST_ENTRY (vm_change_state_entry) entries; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1765 | }; |
| 1766 | |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1767 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1768 | |
| 1769 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, |
| 1770 | void *opaque) |
| 1771 | { |
| 1772 | VMChangeStateEntry *e; |
| 1773 | |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1774 | e = g_malloc0(sizeof (*e)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1775 | |
| 1776 | e->cb = cb; |
| 1777 | e->opaque = opaque; |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1778 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1779 | return e; |
| 1780 | } |
| 1781 | |
| 1782 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) |
| 1783 | { |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 1784 | QLIST_REMOVE (e, entries); |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1785 | g_free (e); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
David 'Digit' Turner | 23ca2ae | 2011-06-01 16:14:53 +0200 | [diff] [blame] | 1788 | void vm_state_notify(int running, int reason) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1789 | { |
| 1790 | VMChangeStateEntry *e; |
| 1791 | |
| 1792 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
| 1793 | e->cb(e->opaque, running, reason); |
| 1794 | } |
| 1795 | } |
| 1796 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1797 | void vm_start(void) |
| 1798 | { |
| 1799 | if (!vm_running) { |
| 1800 | cpu_enable_ticks(); |
| 1801 | vm_running = 1; |
| 1802 | vm_state_notify(1, 0); |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 1803 | //qemu_rearm_alarm_timer(alarm_timer); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1804 | resume_all_vcpus(); |
| 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | /* reset/shutdown handler */ |
| 1809 | |
| 1810 | typedef struct QEMUResetEntry { |
| 1811 | QEMUResetHandler *func; |
| 1812 | void *opaque; |
| 1813 | int order; |
| 1814 | struct QEMUResetEntry *next; |
| 1815 | } QEMUResetEntry; |
| 1816 | |
| 1817 | static QEMUResetEntry *first_reset_entry; |
| 1818 | static int reset_requested; |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1819 | static int shutdown_requested, shutdown_signal = -1; |
| 1820 | static pid_t shutdown_pid; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1821 | static int powerdown_requested; |
David 'Digit' Turner | 23ca2ae | 2011-06-01 16:14:53 +0200 | [diff] [blame] | 1822 | int debug_requested; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1823 | static int vmstop_requested; |
| 1824 | |
| 1825 | int qemu_shutdown_requested(void) |
| 1826 | { |
| 1827 | int r = shutdown_requested; |
| 1828 | shutdown_requested = 0; |
| 1829 | return r; |
| 1830 | } |
| 1831 | |
| 1832 | int qemu_reset_requested(void) |
| 1833 | { |
| 1834 | int r = reset_requested; |
| 1835 | reset_requested = 0; |
| 1836 | return r; |
| 1837 | } |
| 1838 | |
| 1839 | int qemu_powerdown_requested(void) |
| 1840 | { |
| 1841 | int r = powerdown_requested; |
| 1842 | powerdown_requested = 0; |
| 1843 | return r; |
| 1844 | } |
| 1845 | |
| 1846 | static int qemu_debug_requested(void) |
| 1847 | { |
| 1848 | int r = debug_requested; |
| 1849 | debug_requested = 0; |
| 1850 | return r; |
| 1851 | } |
| 1852 | |
| 1853 | static int qemu_vmstop_requested(void) |
| 1854 | { |
| 1855 | int r = vmstop_requested; |
| 1856 | vmstop_requested = 0; |
| 1857 | return r; |
| 1858 | } |
| 1859 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1860 | void qemu_register_reset(QEMUResetHandler *func, int order, void *opaque) |
| 1861 | { |
| 1862 | QEMUResetEntry **pre, *re; |
| 1863 | |
| 1864 | pre = &first_reset_entry; |
| 1865 | while (*pre != NULL && (*pre)->order >= order) { |
| 1866 | pre = &(*pre)->next; |
| 1867 | } |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 1868 | re = g_malloc0(sizeof(QEMUResetEntry)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1869 | re->func = func; |
| 1870 | re->opaque = opaque; |
| 1871 | re->order = order; |
| 1872 | re->next = NULL; |
| 1873 | *pre = re; |
| 1874 | } |
| 1875 | |
| 1876 | void qemu_system_reset(void) |
| 1877 | { |
| 1878 | QEMUResetEntry *re; |
| 1879 | |
| 1880 | /* reset all devices */ |
| 1881 | for(re = first_reset_entry; re != NULL; re = re->next) { |
| 1882 | re->func(re->opaque); |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | void qemu_system_reset_request(void) |
| 1887 | { |
| 1888 | if (no_reboot) { |
| 1889 | shutdown_requested = 1; |
| 1890 | } else { |
| 1891 | reset_requested = 1; |
| 1892 | } |
| 1893 | qemu_notify_event(); |
| 1894 | } |
| 1895 | |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 1896 | void qemu_system_killed(int signal, pid_t pid) |
| 1897 | { |
| 1898 | shutdown_signal = signal; |
| 1899 | shutdown_pid = pid; |
| 1900 | qemu_system_shutdown_request(); |
| 1901 | } |
| 1902 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1903 | void qemu_system_shutdown_request(void) |
| 1904 | { |
| 1905 | shutdown_requested = 1; |
| 1906 | qemu_notify_event(); |
| 1907 | } |
| 1908 | |
| 1909 | void qemu_system_powerdown_request(void) |
| 1910 | { |
| 1911 | powerdown_requested = 1; |
| 1912 | qemu_notify_event(); |
| 1913 | } |
| 1914 | |
| 1915 | #ifdef CONFIG_IOTHREAD |
| 1916 | static void qemu_system_vmstop_request(int reason) |
| 1917 | { |
| 1918 | vmstop_requested = reason; |
| 1919 | qemu_notify_event(); |
| 1920 | } |
| 1921 | #endif |
| 1922 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1923 | void main_loop_wait(int timeout) |
| 1924 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1925 | fd_set rfds, wfds, xfds; |
| 1926 | int ret, nfds; |
| 1927 | struct timeval tv; |
| 1928 | |
| 1929 | qemu_bh_update_timeout(&timeout); |
| 1930 | |
David 'Digit' Turner | 23ca2ae | 2011-06-01 16:14:53 +0200 | [diff] [blame] | 1931 | os_host_main_loop_wait(&timeout); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1932 | |
David 'Digit' Turner | 8354d2d | 2011-05-11 00:19:06 +0200 | [diff] [blame] | 1933 | |
| 1934 | tv.tv_sec = timeout / 1000; |
| 1935 | tv.tv_usec = (timeout % 1000) * 1000; |
| 1936 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1937 | /* poll any events */ |
David 'Digit' Turner | 8354d2d | 2011-05-11 00:19:06 +0200 | [diff] [blame] | 1938 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1939 | /* XXX: separate device handlers from system ones */ |
| 1940 | nfds = -1; |
| 1941 | FD_ZERO(&rfds); |
| 1942 | FD_ZERO(&wfds); |
| 1943 | FD_ZERO(&xfds); |
David 'Digit' Turner | 8354d2d | 2011-05-11 00:19:06 +0200 | [diff] [blame] | 1944 | qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1945 | if (slirp_is_inited()) { |
| 1946 | slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
| 1947 | } |
David 'Digit' Turner | 8354d2d | 2011-05-11 00:19:06 +0200 | [diff] [blame] | 1948 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1949 | qemu_mutex_unlock_iothread(); |
| 1950 | ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); |
| 1951 | qemu_mutex_lock_iothread(); |
David 'Digit' Turner | 8354d2d | 2011-05-11 00:19:06 +0200 | [diff] [blame] | 1952 | qemu_iohandler_poll(&rfds, &wfds, &xfds, ret); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1953 | if (slirp_is_inited()) { |
| 1954 | if (ret < 0) { |
| 1955 | FD_ZERO(&rfds); |
| 1956 | FD_ZERO(&wfds); |
| 1957 | FD_ZERO(&xfds); |
| 1958 | } |
| 1959 | slirp_select_poll(&rfds, &wfds, &xfds); |
| 1960 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1961 | charpipe_poll(); |
| 1962 | |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 1963 | qemu_run_all_timers(); |
David 'Digit' Turner | a7fb77d | 2010-05-10 23:50:54 -0700 | [diff] [blame] | 1964 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1965 | /* Check bottom-halves last in case any of the earlier events triggered |
| 1966 | them. */ |
| 1967 | qemu_bh_poll(); |
| 1968 | |
| 1969 | } |
| 1970 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1971 | static int vm_can_run(void) |
| 1972 | { |
| 1973 | if (powerdown_requested) |
| 1974 | return 0; |
| 1975 | if (reset_requested) |
| 1976 | return 0; |
| 1977 | if (shutdown_requested) |
| 1978 | return 0; |
| 1979 | if (debug_requested) |
| 1980 | return 0; |
| 1981 | return 1; |
| 1982 | } |
| 1983 | |
| 1984 | static void main_loop(void) |
| 1985 | { |
| 1986 | int r; |
| 1987 | |
| 1988 | #ifdef CONFIG_IOTHREAD |
| 1989 | qemu_system_ready = 1; |
| 1990 | qemu_cond_broadcast(&qemu_system_cond); |
| 1991 | #endif |
| 1992 | |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 1993 | #ifdef CONFIG_HAX |
| 1994 | if (hax_enabled()) |
| 1995 | hax_sync_vcpus(); |
| 1996 | #endif |
| 1997 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 1998 | for (;;) { |
| 1999 | do { |
| 2000 | #ifdef CONFIG_PROFILER |
| 2001 | int64_t ti; |
| 2002 | #endif |
| 2003 | #ifndef CONFIG_IOTHREAD |
| 2004 | tcg_cpu_exec(); |
| 2005 | #endif |
| 2006 | #ifdef CONFIG_PROFILER |
| 2007 | ti = profile_getclock(); |
| 2008 | #endif |
| 2009 | main_loop_wait(qemu_calculate_timeout()); |
| 2010 | #ifdef CONFIG_PROFILER |
| 2011 | dev_time += profile_getclock() - ti; |
| 2012 | #endif |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 2013 | |
| 2014 | if (rotate_logs_requested) { |
| 2015 | FILE* new_dns_log_fd = rotate_qemu_log(get_slirp_dns_log_fd(), |
| 2016 | dns_log_filename); |
| 2017 | FILE* new_drop_log_fd = rotate_qemu_log(get_slirp_drop_log_fd(), |
| 2018 | drop_log_filename); |
| 2019 | slirp_dns_log_fd(new_dns_log_fd); |
| 2020 | slirp_drop_log_fd(new_drop_log_fd); |
| 2021 | reset_rotate_qemu_logs_request(); |
| 2022 | } |
| 2023 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2024 | } while (vm_can_run()); |
| 2025 | |
| 2026 | if (qemu_debug_requested()) |
| 2027 | vm_stop(EXCP_DEBUG); |
| 2028 | if (qemu_shutdown_requested()) { |
| 2029 | if (no_shutdown) { |
| 2030 | vm_stop(0); |
| 2031 | no_shutdown = 0; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 2032 | } else { |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 2033 | if (savevm_on_exit != NULL) { |
Vladimir Chtchetkine | db450d7 | 2012-01-12 13:37:40 -0800 | [diff] [blame] | 2034 | /* Prior to saving VM to the snapshot file, save HW config |
| 2035 | * settings for that VM, so we can match them when VM gets |
| 2036 | * loaded from the snapshot. */ |
| 2037 | snaphost_save_config(savevm_on_exit); |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 2038 | do_savevm(cur_mon, savevm_on_exit); |
| 2039 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2040 | break; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 2041 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2042 | } |
| 2043 | if (qemu_reset_requested()) { |
| 2044 | pause_all_vcpus(); |
| 2045 | qemu_system_reset(); |
| 2046 | resume_all_vcpus(); |
| 2047 | } |
| 2048 | if (qemu_powerdown_requested()) |
| 2049 | qemu_system_powerdown(); |
| 2050 | if ((r = qemu_vmstop_requested())) |
| 2051 | vm_stop(r); |
| 2052 | } |
| 2053 | pause_all_vcpus(); |
| 2054 | } |
| 2055 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 2056 | void version(void) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2057 | { |
| 2058 | printf("QEMU PC emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
| 2059 | } |
| 2060 | |
| 2061 | void qemu_help(int exitcode) |
| 2062 | { |
| 2063 | version(); |
| 2064 | printf("usage: %s [options] [disk_image]\n" |
| 2065 | "\n" |
| 2066 | "'disk_image' is a raw hard image image for IDE hard disk 0\n" |
| 2067 | "\n" |
| 2068 | #define DEF(option, opt_arg, opt_enum, opt_help) \ |
| 2069 | opt_help |
| 2070 | #define DEFHEADING(text) stringify(text) "\n" |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 2071 | #include "qemu-options.def" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2072 | #undef DEF |
| 2073 | #undef DEFHEADING |
| 2074 | #undef GEN_DOCS |
| 2075 | "\n" |
| 2076 | "During emulation, the following keys are useful:\n" |
| 2077 | "ctrl-alt-f toggle full screen\n" |
| 2078 | "ctrl-alt-n switch to virtual console 'n'\n" |
| 2079 | "ctrl-alt toggle mouse and keyboard grab\n" |
| 2080 | "\n" |
| 2081 | "When using -nographic, press 'ctrl-a h' to get some help.\n" |
| 2082 | , |
| 2083 | "qemu", |
| 2084 | DEFAULT_RAM_SIZE, |
| 2085 | #ifndef _WIN32 |
| 2086 | DEFAULT_NETWORK_SCRIPT, |
| 2087 | DEFAULT_NETWORK_DOWN_SCRIPT, |
| 2088 | #endif |
| 2089 | DEFAULT_GDBSTUB_PORT, |
| 2090 | "/tmp/qemu.log"); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2091 | QEMU_EXIT(exitcode); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | #define HAS_ARG 0x0001 |
| 2095 | |
| 2096 | enum { |
| 2097 | #define DEF(option, opt_arg, opt_enum, opt_help) \ |
| 2098 | opt_enum, |
| 2099 | #define DEFHEADING(text) |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 2100 | #include "qemu-options.def" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2101 | #undef DEF |
| 2102 | #undef DEFHEADING |
| 2103 | #undef GEN_DOCS |
| 2104 | }; |
| 2105 | |
| 2106 | typedef struct QEMUOption { |
| 2107 | const char *name; |
| 2108 | int flags; |
| 2109 | int index; |
| 2110 | } QEMUOption; |
| 2111 | |
| 2112 | static const QEMUOption qemu_options[] = { |
| 2113 | { "h", 0, QEMU_OPTION_h }, |
| 2114 | #define DEF(option, opt_arg, opt_enum, opt_help) \ |
| 2115 | { option, opt_arg, opt_enum }, |
| 2116 | #define DEFHEADING(text) |
David 'Digit' Turner | 088edf8 | 2011-05-09 15:59:28 +0200 | [diff] [blame] | 2117 | #include "qemu-options.def" |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2118 | #undef DEF |
| 2119 | #undef DEFHEADING |
| 2120 | #undef GEN_DOCS |
| 2121 | { NULL, 0, 0 }, |
| 2122 | }; |
| 2123 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2124 | static void select_vgahw (const char *p) |
| 2125 | { |
| 2126 | const char *opts; |
| 2127 | |
| 2128 | cirrus_vga_enabled = 0; |
| 2129 | std_vga_enabled = 0; |
| 2130 | vmsvga_enabled = 0; |
| 2131 | xenfb_enabled = 0; |
| 2132 | if (strstart(p, "std", &opts)) { |
| 2133 | std_vga_enabled = 1; |
| 2134 | } else if (strstart(p, "cirrus", &opts)) { |
| 2135 | cirrus_vga_enabled = 1; |
| 2136 | } else if (strstart(p, "vmware", &opts)) { |
| 2137 | vmsvga_enabled = 1; |
| 2138 | } else if (strstart(p, "xenfb", &opts)) { |
| 2139 | xenfb_enabled = 1; |
| 2140 | } else if (!strstart(p, "none", &opts)) { |
| 2141 | invalid_vga: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2142 | PANIC("Unknown vga type: %s", p); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2143 | } |
| 2144 | while (*opts) { |
| 2145 | const char *nextopt; |
| 2146 | |
| 2147 | if (strstart(opts, ",retrace=", &nextopt)) { |
| 2148 | opts = nextopt; |
| 2149 | if (strstart(opts, "dumb", &nextopt)) |
| 2150 | vga_retrace_method = VGA_RETRACE_DUMB; |
| 2151 | else if (strstart(opts, "precise", &nextopt)) |
| 2152 | vga_retrace_method = VGA_RETRACE_PRECISE; |
| 2153 | else goto invalid_vga; |
| 2154 | } else goto invalid_vga; |
| 2155 | opts = nextopt; |
| 2156 | } |
| 2157 | } |
| 2158 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2159 | #define MAX_NET_CLIENTS 32 |
| 2160 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2161 | #ifdef _WIN32 |
| 2162 | /* Look for support files in the same directory as the executable. */ |
| 2163 | static char *find_datadir(const char *argv0) |
| 2164 | { |
| 2165 | char *p; |
| 2166 | char buf[MAX_PATH]; |
| 2167 | DWORD len; |
| 2168 | |
| 2169 | len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); |
| 2170 | if (len == 0) { |
| 2171 | return NULL; |
| 2172 | } |
| 2173 | |
| 2174 | buf[len] = 0; |
| 2175 | p = buf + len - 1; |
| 2176 | while (p != buf && *p != '\\') |
| 2177 | p--; |
| 2178 | *p = 0; |
| 2179 | if (access(buf, R_OK) == 0) { |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 2180 | return g_strdup(buf); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2181 | } |
| 2182 | return NULL; |
| 2183 | } |
| 2184 | #else /* !_WIN32 */ |
| 2185 | |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2186 | /* Similarly, return the location of the executable */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2187 | static char *find_datadir(const char *argv0) |
| 2188 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2189 | char *p = NULL; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2190 | char buf[PATH_MAX]; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2191 | |
| 2192 | #if defined(__linux__) |
| 2193 | { |
| 2194 | int len; |
| 2195 | len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); |
| 2196 | if (len > 0) { |
| 2197 | buf[len] = 0; |
| 2198 | p = buf; |
| 2199 | } |
| 2200 | } |
| 2201 | #elif defined(__FreeBSD__) |
| 2202 | { |
| 2203 | int len; |
| 2204 | len = readlink("/proc/curproc/file", buf, sizeof(buf) - 1); |
| 2205 | if (len > 0) { |
| 2206 | buf[len] = 0; |
| 2207 | p = buf; |
| 2208 | } |
| 2209 | } |
| 2210 | #endif |
| 2211 | /* If we don't have any way of figuring out the actual executable |
| 2212 | location then try argv[0]. */ |
| 2213 | if (!p) { |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2214 | p = realpath(argv0, buf); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2215 | if (!p) { |
| 2216 | return NULL; |
| 2217 | } |
| 2218 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2219 | |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 2220 | return g_strdup(dirname(buf)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2221 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2222 | #endif |
| 2223 | |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2224 | static char* |
| 2225 | qemu_find_file_with_subdir(const char* data_dir, const char* subdir, const char* name) |
| 2226 | { |
| 2227 | int len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 2228 | char* buf = g_malloc0(len); |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2229 | |
| 2230 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
| 2231 | VERBOSE_PRINT(init," trying to find: %s\n", buf); |
| 2232 | if (access(buf, R_OK)) { |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 2233 | g_free(buf); |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2234 | return NULL; |
| 2235 | } |
| 2236 | return buf; |
| 2237 | } |
| 2238 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2239 | char *qemu_find_file(int type, const char *name) |
| 2240 | { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2241 | const char *subdir; |
| 2242 | char *buf; |
| 2243 | |
| 2244 | /* If name contains path separators then try it as a straight path. */ |
| 2245 | if ((strchr(name, '/') || strchr(name, '\\')) |
| 2246 | && access(name, R_OK) == 0) { |
| 2247 | return strdup(name); |
| 2248 | } |
| 2249 | switch (type) { |
| 2250 | case QEMU_FILE_TYPE_BIOS: |
| 2251 | subdir = ""; |
| 2252 | break; |
| 2253 | case QEMU_FILE_TYPE_KEYMAP: |
| 2254 | subdir = "keymaps/"; |
| 2255 | break; |
| 2256 | default: |
| 2257 | abort(); |
| 2258 | } |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2259 | buf = qemu_find_file_with_subdir(data_dir, subdir, name); |
| 2260 | #ifdef CONFIG_ANDROID |
| 2261 | if (type == QEMU_FILE_TYPE_BIOS) { |
| 2262 | /* This case corresponds to the emulator being used as part of an |
| 2263 | * SDK installation. NOTE: data_dir is really $bindir. */ |
| 2264 | if (buf == NULL) |
| 2265 | buf = qemu_find_file_with_subdir(data_dir, "lib/pc-bios/", name); |
| 2266 | /* This case corresponds to platform builds. */ |
| 2267 | if (buf == NULL) |
| 2268 | buf = qemu_find_file_with_subdir(data_dir, "../usr/share/pc-bios/", name); |
| 2269 | /* Finally, try this for standalone builds under external/qemu */ |
| 2270 | if (buf == NULL) |
Andrew Hsieh | 3d89428 | 2012-05-02 12:06:12 +0800 | [diff] [blame] | 2271 | buf = qemu_find_file_with_subdir(data_dir, "../../../prebuilts/qemu-kernel/x86/pc-bios/", name); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2272 | } |
David 'Digit' Turner | 24d2752 | 2011-06-01 16:50:56 +0200 | [diff] [blame] | 2273 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2274 | return buf; |
| 2275 | } |
| 2276 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 2277 | static int |
| 2278 | add_dns_server( const char* server_name ) |
| 2279 | { |
| 2280 | SockAddress addr; |
| 2281 | |
| 2282 | if (sock_address_init_resolve( &addr, server_name, 55, 0 ) < 0) { |
| 2283 | fprintf(stdout, |
| 2284 | "### WARNING: can't resolve DNS server name '%s'\n", |
| 2285 | server_name ); |
| 2286 | return -1; |
| 2287 | } |
| 2288 | |
| 2289 | fprintf(stderr, |
| 2290 | "DNS server name '%s' resolved to %s\n", server_name, sock_address_to_string(&addr) ); |
| 2291 | |
| 2292 | if ( slirp_add_dns_server( &addr ) < 0 ) { |
| 2293 | fprintf(stderr, |
| 2294 | "### WARNING: could not add DNS server '%s' to the network stack\n", server_name); |
| 2295 | return -1; |
| 2296 | } |
| 2297 | return 0; |
| 2298 | } |
| 2299 | |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2300 | /* Parses an integer |
| 2301 | * Pararm: |
| 2302 | * str String containing a number to be parsed. |
| 2303 | * result Passes the parsed integer in this argument |
| 2304 | * returns 0 if ok, -1 if failed |
| 2305 | */ |
| 2306 | int |
| 2307 | parse_int(const char *str, int *result) |
| 2308 | { |
| 2309 | char* r; |
| 2310 | *result = strtol(str, &r, 0); |
| 2311 | if (r == NULL || *r != '\0') |
| 2312 | return -1; |
| 2313 | |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 2317 | #ifndef _WIN32 |
| 2318 | /* |
| 2319 | * Initializes the SIGUSR1 signal handler to clear Qemu logs. |
| 2320 | */ |
| 2321 | void init_qemu_clear_logs_sig() { |
| 2322 | struct sigaction act; |
| 2323 | sigfillset(&act.sa_mask); |
| 2324 | act.sa_flags = 0; |
| 2325 | act.sa_handler = rotate_qemu_logs_handler; |
| 2326 | if (sigaction(SIGUSR1, &act, NULL) == -1) { |
| 2327 | fprintf(stderr, "Failed to setup SIGUSR1 handler to clear Qemu logs\n"); |
| 2328 | exit(-1); |
| 2329 | } |
| 2330 | } |
| 2331 | #endif |
| 2332 | |
| 2333 | |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2334 | |
| 2335 | /* parses a null-terminated string specifying a network port (e.g., "80") or |
| 2336 | * port range (e.g., "[6666-7000]"). In case of a single port, lport and hport |
| 2337 | * are the same. Returns 0 on success, -1 on error. */ |
| 2338 | |
| 2339 | int parse_port_range(const char *str, unsigned short *lport, |
| 2340 | unsigned short *hport) { |
| 2341 | |
| 2342 | unsigned int low = 0, high = 0; |
| 2343 | char *p, *arg = strdup(str); |
| 2344 | |
| 2345 | if ((*arg == '[') && ((p = strrchr(arg, ']')) != NULL)) { |
| 2346 | p = arg + 1; /* skip '[' */ |
| 2347 | low = atoi(strtok(p, "-")); |
| 2348 | high = atoi(strtok(NULL, "-")); |
| 2349 | if ((low > 0) && (high > 0) && (low < high) && (high < 65535)) { |
| 2350 | *lport = low; |
| 2351 | *hport = high; |
| 2352 | } |
| 2353 | } |
| 2354 | else { |
| 2355 | low = atoi(arg); |
| 2356 | if ((0 < low) && (low < 65535)) { |
| 2357 | *lport = low; |
| 2358 | *hport = low; |
| 2359 | } |
| 2360 | } |
| 2361 | free(arg); |
| 2362 | if (low != 0) |
| 2363 | return 0; |
| 2364 | return -1; |
| 2365 | } |
| 2366 | |
| 2367 | /* |
| 2368 | * Implements the generic port forwarding option |
| 2369 | */ |
| 2370 | void |
| 2371 | net_slirp_forward(const char *optarg) |
| 2372 | { |
| 2373 | /* |
| 2374 | * we expect the following format: |
| 2375 | * dst_net:dst_mask:dst_port:redirect_ip:redirect_port OR |
| 2376 | * dst_net:dst_mask:[dp_range_start-dp_range_end]:redirect_ip:redirect_port |
| 2377 | */ |
| 2378 | char *argument = strdup(optarg), *p = argument; |
| 2379 | char *dst_net, *dst_mask, *dst_port; |
| 2380 | char *redirect_ip, *redirect_port; |
| 2381 | uint32_t dnet, dmask, rip; |
Vladimir Chtchetkine | b557e9f | 2012-03-22 15:38:08 -0700 | [diff] [blame] | 2382 | unsigned short dlport = 0, dhport = 0, rport; |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2383 | |
| 2384 | |
| 2385 | dst_net = strtok(p, ":"); |
| 2386 | dst_mask = strtok(NULL, ":"); |
| 2387 | dst_port = strtok(NULL, ":"); |
| 2388 | redirect_ip = strtok(NULL, ":"); |
| 2389 | redirect_port = strtok(NULL, ":"); |
| 2390 | |
| 2391 | if (dst_net == NULL || dst_mask == NULL || dst_port == NULL || |
| 2392 | redirect_ip == NULL || redirect_port == NULL) { |
| 2393 | fprintf(stderr, |
| 2394 | "Invalid argument for -net-forward, we expect " |
| 2395 | "dst_net:dst_mask:dst_port:redirect_ip:redirect_port or " |
| 2396 | "dst_net:dst_mask:[dp_range_start-dp_range_end]" |
| 2397 | ":redirect_ip:redirect_port: %s\n", |
| 2398 | optarg); |
| 2399 | exit(1); |
| 2400 | } |
| 2401 | |
| 2402 | /* inet_strtoip converts dotted address to host byte order */ |
| 2403 | if (inet_strtoip(dst_net, &dnet) == -1) { |
| 2404 | fprintf(stderr, "Invalid destination IP net: %s\n", dst_net); |
| 2405 | exit(1); |
| 2406 | } |
| 2407 | if (inet_strtoip(dst_mask, &dmask) == -1) { |
| 2408 | fprintf(stderr, "Invalid destination IP mask: %s\n", dst_mask); |
| 2409 | exit(1); |
| 2410 | } |
| 2411 | if (inet_strtoip(redirect_ip, &rip) == -1) { |
| 2412 | fprintf(stderr, "Invalid redirect IP address: %s\n", redirect_ip); |
| 2413 | exit(1); |
| 2414 | } |
| 2415 | |
| 2416 | if (parse_port_range(dst_port, &dlport, &dhport) == -1) { |
| 2417 | fprintf(stderr, "Invalid destination port or port range\n"); |
| 2418 | exit(1); |
| 2419 | } |
| 2420 | |
| 2421 | rport = atoi(redirect_port); |
| 2422 | if (!rport) { |
| 2423 | fprintf(stderr, "Invalid redirect port: %s\n", redirect_port); |
| 2424 | exit(1); |
| 2425 | } |
| 2426 | |
| 2427 | dnet &= dmask; |
| 2428 | |
| 2429 | slirp_add_net_forward(dnet, dmask, dlport, dhport, |
| 2430 | rip, rport); |
| 2431 | |
| 2432 | free(argument); |
| 2433 | } |
| 2434 | |
| 2435 | |
| 2436 | /* Parses an -allow-tcp or -allow-udp argument and inserts a corresponding |
| 2437 | * entry in the allows list */ |
| 2438 | void |
| 2439 | slirp_allow(const char *optarg, u_int8_t proto) |
| 2440 | { |
| 2441 | /* |
| 2442 | * we expect the following format: |
| 2443 | * dst_ip:dst_port OR dst_ip:[dst_lport-dst_hport] |
| 2444 | */ |
| 2445 | char *argument = strdup(optarg), *p = argument; |
| 2446 | char *dst_ip_str, *dst_port_str; |
| 2447 | uint32_t dst_ip; |
Vladimir Chtchetkine | b557e9f | 2012-03-22 15:38:08 -0700 | [diff] [blame] | 2448 | unsigned short dst_lport = 0, dst_hport = 0; |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 2449 | |
| 2450 | dst_ip_str = strtok(p, ":"); |
| 2451 | dst_port_str = strtok(NULL, ":"); |
| 2452 | |
| 2453 | if (dst_ip_str == NULL || dst_port_str == NULL) { |
| 2454 | fprintf(stderr, |
| 2455 | "Invalid argument %s for -allow. We expect " |
| 2456 | "dst_ip:dst_port or dst_ip:[dst_lport-dst_hport]\n", |
| 2457 | optarg); |
| 2458 | exit(1); |
| 2459 | } |
| 2460 | |
| 2461 | if (inet_strtoip(dst_ip_str, &dst_ip) == -1) { |
| 2462 | fprintf(stderr, "Invalid destination IP address: %s\n", dst_ip_str); |
| 2463 | exit(1); |
| 2464 | } |
| 2465 | if (parse_port_range(dst_port_str, &dst_lport, &dst_hport) == -1) { |
| 2466 | fprintf(stderr, "Invalid destination port or port range\n"); |
| 2467 | exit(1); |
| 2468 | } |
| 2469 | |
| 2470 | slirp_add_allow(dst_ip, dst_lport, dst_hport, proto); |
| 2471 | |
| 2472 | free(argument); |
| 2473 | } |
| 2474 | |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 2475 | /* Add a serial device at a given location in the emulated hardware table. |
| 2476 | * On failure, this function aborts the program with an error message. |
| 2477 | */ |
| 2478 | static void |
| 2479 | serial_hds_add_at(int index, const char* devname) |
| 2480 | { |
| 2481 | char label[32]; |
| 2482 | |
| 2483 | if (!devname || !strcmp(devname,"none")) |
| 2484 | return; |
| 2485 | |
| 2486 | if (index >= MAX_SERIAL_PORTS) { |
| 2487 | PANIC("qemu: invalid serial index for %s (%d >= %d)", |
| 2488 | devname, index, MAX_SERIAL_PORTS); |
| 2489 | } |
| 2490 | if (serial_hds[index] != NULL) { |
| 2491 | PANIC("qemu: invalid serial index for %s (%d: already taken!)", |
| 2492 | devname, index); |
| 2493 | } |
| 2494 | snprintf(label, sizeof(label), "serial%d", index); |
| 2495 | serial_hds[index] = qemu_chr_open(label, devname, NULL); |
| 2496 | if (!serial_hds[index]) { |
| 2497 | PANIC("qemu: could not open serial device '%s'", devname); |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | |
| 2502 | /* Find a free slot in the emulated serial device table, and register |
| 2503 | * it. Return the allocated table index. |
| 2504 | */ |
| 2505 | static int |
| 2506 | serial_hds_add(const char* devname) |
| 2507 | { |
| 2508 | int index; |
| 2509 | |
| 2510 | /* Find first free slot */ |
| 2511 | for (index = 0; index < MAX_SERIAL_PORTS; index++) { |
| 2512 | if (serial_hds[index] == NULL) { |
| 2513 | serial_hds_add_at(index, devname); |
| 2514 | return index; |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | PANIC("qemu: too many serial devices registered (%d)", index); |
| 2519 | return -1; /* shouldn't happen */ |
| 2520 | } |
| 2521 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2522 | int main(int argc, char **argv, char **envp) |
| 2523 | { |
| 2524 | const char *gdbstub_dev = NULL; |
| 2525 | uint32_t boot_devices_bitmap = 0; |
| 2526 | int i; |
David 'Digit' Turner | a2c14f9 | 2014-02-04 01:02:30 +0100 | [diff] [blame] | 2527 | int snapshot, linux_boot, __attribute__((unused)) net_boot; |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 2528 | const char *icount_option = NULL; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2529 | const char *initrd_filename; |
| 2530 | const char *kernel_filename, *kernel_cmdline; |
| 2531 | const char *boot_devices = ""; |
| 2532 | DisplayState *ds; |
| 2533 | DisplayChangeListener *dcl; |
| 2534 | int cyls, heads, secs, translation; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2535 | QemuOpts *hda_opts = NULL; |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 2536 | QemuOpts *hdb_opts = NULL; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2537 | const char *net_clients[MAX_NET_CLIENTS]; |
| 2538 | int nb_net_clients; |
| 2539 | const char *bt_opts[MAX_BT_CMDLINE]; |
| 2540 | int nb_bt_opts; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2541 | int optind; |
| 2542 | const char *r, *optarg; |
| 2543 | CharDriverState *monitor_hd = NULL; |
| 2544 | const char *monitor_device; |
| 2545 | const char *serial_devices[MAX_SERIAL_PORTS]; |
| 2546 | int serial_device_index; |
| 2547 | const char *parallel_devices[MAX_PARALLEL_PORTS]; |
| 2548 | int parallel_device_index; |
| 2549 | const char *virtio_consoles[MAX_VIRTIO_CONSOLES]; |
| 2550 | int virtio_console_index; |
| 2551 | const char *loadvm = NULL; |
| 2552 | QEMUMachine *machine; |
| 2553 | const char *cpu_model; |
| 2554 | const char *usb_devices[MAX_USB_CMDLINE]; |
| 2555 | int usb_devices_index; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2556 | int tb_size; |
| 2557 | const char *pid_file = NULL; |
| 2558 | const char *incoming = NULL; |
David 'Digit' Turner | e2678e1 | 2014-01-16 15:56:43 +0100 | [diff] [blame] | 2559 | CPUOldState *env; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2560 | int show_vnc_port = 0; |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 2561 | IniFile* hw_ini = NULL; |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 2562 | STRALLOC_DEFINE(kernel_params); |
| 2563 | STRALLOC_DEFINE(kernel_config); |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 2564 | int dns_count = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2565 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2566 | /* Initialize sockets before anything else, so we can properly report |
| 2567 | * initialization failures back to the UI. */ |
| 2568 | #ifdef _WIN32 |
| 2569 | socket_init(); |
| 2570 | #endif |
| 2571 | |
David 'Digit' Turner | a7fb77d | 2010-05-10 23:50:54 -0700 | [diff] [blame] | 2572 | init_clocks(); |
| 2573 | |
David 'Digit' Turner | 8848f63 | 2014-01-16 18:10:21 +0100 | [diff] [blame^] | 2574 | qemu_cache_utils_init(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2575 | |
David 'Digit' Turner | a5d4120 | 2010-05-10 18:37:10 -0700 | [diff] [blame] | 2576 | QLIST_INIT (&vm_change_state_head); |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 2577 | os_setup_early_signal_handling(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2578 | |
| 2579 | module_call_init(MODULE_INIT_MACHINE); |
| 2580 | machine = find_default_machine(); |
| 2581 | cpu_model = NULL; |
| 2582 | initrd_filename = NULL; |
| 2583 | ram_size = 0; |
| 2584 | snapshot = 0; |
| 2585 | kernel_filename = NULL; |
| 2586 | kernel_cmdline = ""; |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 2587 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2588 | cyls = heads = secs = 0; |
| 2589 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2590 | monitor_device = "vc:80Cx24C"; |
| 2591 | |
| 2592 | serial_devices[0] = "vc:80Cx24C"; |
| 2593 | for(i = 1; i < MAX_SERIAL_PORTS; i++) |
| 2594 | serial_devices[i] = NULL; |
| 2595 | serial_device_index = 0; |
| 2596 | |
| 2597 | parallel_devices[0] = "vc:80Cx24C"; |
| 2598 | for(i = 1; i < MAX_PARALLEL_PORTS; i++) |
| 2599 | parallel_devices[i] = NULL; |
| 2600 | parallel_device_index = 0; |
| 2601 | |
| 2602 | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) |
| 2603 | virtio_consoles[i] = NULL; |
| 2604 | virtio_console_index = 0; |
| 2605 | |
| 2606 | for (i = 0; i < MAX_NODES; i++) { |
| 2607 | node_mem[i] = 0; |
| 2608 | node_cpumask[i] = 0; |
| 2609 | } |
| 2610 | |
| 2611 | usb_devices_index = 0; |
| 2612 | |
| 2613 | nb_net_clients = 0; |
| 2614 | nb_bt_opts = 0; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2615 | #ifdef MAX_DRIVES |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2616 | nb_drives = 0; |
| 2617 | nb_drives_opt = 0; |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2618 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2619 | nb_numa_nodes = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2620 | |
| 2621 | nb_nics = 0; |
| 2622 | |
| 2623 | tb_size = 0; |
| 2624 | autostart= 1; |
| 2625 | |
| 2626 | register_watchdogs(); |
| 2627 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 2628 | /* Initialize boot properties. */ |
| 2629 | boot_property_init_service(); |
David 'Digit' Turner | ca95059 | 2011-04-27 12:26:15 +0200 | [diff] [blame] | 2630 | android_hw_control_init(); |
David 'Digit' Turner | d4d688e | 2011-04-26 18:09:17 +0200 | [diff] [blame] | 2631 | android_net_pipes_init(); |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 2632 | |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 2633 | #ifdef CONFIG_KVM |
| 2634 | /* By default, force auto-detection for kvm */ |
| 2635 | kvm_allowed = -1; |
| 2636 | #endif |
| 2637 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2638 | optind = 1; |
| 2639 | for(;;) { |
| 2640 | if (optind >= argc) |
| 2641 | break; |
| 2642 | r = argv[optind]; |
| 2643 | if (r[0] != '-') { |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2644 | hda_opts = drive_add(argv[optind++], HD_ALIAS, 0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2645 | } else { |
| 2646 | const QEMUOption *popt; |
| 2647 | |
| 2648 | optind++; |
| 2649 | /* Treat --foo the same as -foo. */ |
| 2650 | if (r[1] == '-') |
| 2651 | r++; |
| 2652 | popt = qemu_options; |
| 2653 | for(;;) { |
| 2654 | if (!popt->name) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2655 | PANIC("%s: invalid option -- '%s'", |
| 2656 | argv[0], r); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2657 | } |
| 2658 | if (!strcmp(popt->name, r + 1)) |
| 2659 | break; |
| 2660 | popt++; |
| 2661 | } |
| 2662 | if (popt->flags & HAS_ARG) { |
| 2663 | if (optind >= argc) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2664 | PANIC("%s: option '%s' requires an argument", |
| 2665 | argv[0], r); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2666 | } |
| 2667 | optarg = argv[optind++]; |
| 2668 | } else { |
| 2669 | optarg = NULL; |
| 2670 | } |
| 2671 | |
| 2672 | switch(popt->index) { |
| 2673 | case QEMU_OPTION_M: |
| 2674 | machine = find_machine(optarg); |
| 2675 | if (!machine) { |
| 2676 | QEMUMachine *m; |
| 2677 | printf("Supported machines are:\n"); |
| 2678 | for(m = first_machine; m != NULL; m = m->next) { |
| 2679 | printf("%-10s %s%s\n", |
| 2680 | m->name, m->desc, |
| 2681 | m->is_default ? " (default)" : ""); |
| 2682 | } |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2683 | if (*optarg != '?') { |
| 2684 | PANIC("Invalid machine parameter: %s", |
| 2685 | optarg); |
| 2686 | } else { |
| 2687 | QEMU_EXIT(0); |
| 2688 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2689 | } |
| 2690 | break; |
| 2691 | case QEMU_OPTION_cpu: |
| 2692 | /* hw initialization will check this */ |
| 2693 | if (*optarg == '?') { |
| 2694 | /* XXX: implement xxx_cpu_list for targets that still miss it */ |
| 2695 | #if defined(cpu_list) |
| 2696 | cpu_list(stdout, &fprintf); |
| 2697 | #endif |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2698 | QEMU_EXIT(0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2699 | } else { |
| 2700 | cpu_model = optarg; |
| 2701 | } |
| 2702 | break; |
| 2703 | case QEMU_OPTION_initrd: |
| 2704 | initrd_filename = optarg; |
| 2705 | break; |
| 2706 | case QEMU_OPTION_hda: |
| 2707 | if (cyls == 0) |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2708 | hda_opts = drive_add(optarg, HD_ALIAS, 0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2709 | else |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2710 | hda_opts = drive_add(optarg, HD_ALIAS |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2711 | ",cyls=%d,heads=%d,secs=%d%s", |
| 2712 | 0, cyls, heads, secs, |
| 2713 | translation == BIOS_ATA_TRANSLATION_LBA ? |
| 2714 | ",trans=lba" : |
| 2715 | translation == BIOS_ATA_TRANSLATION_NONE ? |
| 2716 | ",trans=none" : ""); |
| 2717 | break; |
| 2718 | case QEMU_OPTION_hdb: |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 2719 | hdb_opts = drive_add(optarg, HD_ALIAS, 1); |
| 2720 | break; |
| 2721 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2722 | case QEMU_OPTION_hdc: |
| 2723 | case QEMU_OPTION_hdd: |
| 2724 | drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda); |
| 2725 | break; |
| 2726 | case QEMU_OPTION_drive: |
| 2727 | drive_add(NULL, "%s", optarg); |
| 2728 | break; |
| 2729 | case QEMU_OPTION_mtdblock: |
| 2730 | drive_add(optarg, MTD_ALIAS); |
| 2731 | break; |
| 2732 | case QEMU_OPTION_sd: |
| 2733 | drive_add(optarg, SD_ALIAS); |
| 2734 | break; |
| 2735 | case QEMU_OPTION_pflash: |
| 2736 | drive_add(optarg, PFLASH_ALIAS); |
| 2737 | break; |
| 2738 | case QEMU_OPTION_snapshot: |
| 2739 | snapshot = 1; |
| 2740 | break; |
| 2741 | case QEMU_OPTION_hdachs: |
| 2742 | { |
| 2743 | const char *p; |
| 2744 | p = optarg; |
| 2745 | cyls = strtol(p, (char **)&p, 0); |
| 2746 | if (cyls < 1 || cyls > 16383) |
| 2747 | goto chs_fail; |
| 2748 | if (*p != ',') |
| 2749 | goto chs_fail; |
| 2750 | p++; |
| 2751 | heads = strtol(p, (char **)&p, 0); |
| 2752 | if (heads < 1 || heads > 16) |
| 2753 | goto chs_fail; |
| 2754 | if (*p != ',') |
| 2755 | goto chs_fail; |
| 2756 | p++; |
| 2757 | secs = strtol(p, (char **)&p, 0); |
| 2758 | if (secs < 1 || secs > 63) |
| 2759 | goto chs_fail; |
| 2760 | if (*p == ',') { |
| 2761 | p++; |
| 2762 | if (!strcmp(p, "none")) |
| 2763 | translation = BIOS_ATA_TRANSLATION_NONE; |
| 2764 | else if (!strcmp(p, "lba")) |
| 2765 | translation = BIOS_ATA_TRANSLATION_LBA; |
| 2766 | else if (!strcmp(p, "auto")) |
| 2767 | translation = BIOS_ATA_TRANSLATION_AUTO; |
| 2768 | else |
| 2769 | goto chs_fail; |
| 2770 | } else if (*p != '\0') { |
| 2771 | chs_fail: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2772 | PANIC("qemu: invalid physical CHS format"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2773 | } |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 2774 | if (hda_opts != NULL) { |
| 2775 | char num[16]; |
| 2776 | snprintf(num, sizeof(num), "%d", cyls); |
| 2777 | qemu_opt_set(hda_opts, "cyls", num); |
| 2778 | snprintf(num, sizeof(num), "%d", heads); |
| 2779 | qemu_opt_set(hda_opts, "heads", num); |
| 2780 | snprintf(num, sizeof(num), "%d", secs); |
| 2781 | qemu_opt_set(hda_opts, "secs", num); |
| 2782 | if (translation == BIOS_ATA_TRANSLATION_LBA) |
| 2783 | qemu_opt_set(hda_opts, "trans", "lba"); |
| 2784 | if (translation == BIOS_ATA_TRANSLATION_NONE) |
| 2785 | qemu_opt_set(hda_opts, "trans", "none"); |
| 2786 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2787 | } |
| 2788 | break; |
| 2789 | case QEMU_OPTION_numa: |
| 2790 | if (nb_numa_nodes >= MAX_NODES) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2791 | PANIC("qemu: too many NUMA nodes"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2792 | } |
| 2793 | numa_add(optarg); |
| 2794 | break; |
| 2795 | case QEMU_OPTION_nographic: |
| 2796 | display_type = DT_NOGRAPHIC; |
| 2797 | break; |
| 2798 | #ifdef CONFIG_CURSES |
| 2799 | case QEMU_OPTION_curses: |
| 2800 | display_type = DT_CURSES; |
| 2801 | break; |
| 2802 | #endif |
| 2803 | case QEMU_OPTION_portrait: |
| 2804 | graphic_rotate = 1; |
| 2805 | break; |
| 2806 | case QEMU_OPTION_kernel: |
| 2807 | kernel_filename = optarg; |
| 2808 | break; |
| 2809 | case QEMU_OPTION_append: |
| 2810 | kernel_cmdline = optarg; |
| 2811 | break; |
| 2812 | case QEMU_OPTION_cdrom: |
| 2813 | drive_add(optarg, CDROM_ALIAS); |
| 2814 | break; |
| 2815 | case QEMU_OPTION_boot: |
| 2816 | boot_devices = optarg; |
| 2817 | /* We just do some generic consistency checks */ |
| 2818 | { |
| 2819 | /* Could easily be extended to 64 devices if needed */ |
| 2820 | const char *p; |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 2821 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2822 | boot_devices_bitmap = 0; |
| 2823 | for (p = boot_devices; *p != '\0'; p++) { |
| 2824 | /* Allowed boot devices are: |
| 2825 | * a b : floppy disk drives |
| 2826 | * c ... f : IDE disk drives |
| 2827 | * g ... m : machine implementation dependant drives |
| 2828 | * n ... p : network devices |
| 2829 | * It's up to each machine implementation to check |
| 2830 | * if the given boot devices match the actual hardware |
| 2831 | * implementation and firmware features. |
| 2832 | */ |
| 2833 | if (*p < 'a' || *p > 'q') { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2834 | PANIC("Invalid boot device '%c'", *p); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2835 | } |
| 2836 | if (boot_devices_bitmap & (1 << (*p - 'a'))) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2837 | PANIC( |
| 2838 | "Boot device '%c' was given twice",*p); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2839 | } |
| 2840 | boot_devices_bitmap |= 1 << (*p - 'a'); |
| 2841 | } |
| 2842 | } |
| 2843 | break; |
| 2844 | case QEMU_OPTION_fda: |
| 2845 | case QEMU_OPTION_fdb: |
| 2846 | drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda); |
| 2847 | break; |
| 2848 | #ifdef TARGET_I386 |
| 2849 | case QEMU_OPTION_no_fd_bootchk: |
| 2850 | fd_bootchk = 0; |
| 2851 | break; |
| 2852 | #endif |
| 2853 | case QEMU_OPTION_net: |
| 2854 | if (nb_net_clients >= MAX_NET_CLIENTS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2855 | PANIC("qemu: too many network clients"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2856 | } |
| 2857 | net_clients[nb_net_clients] = optarg; |
| 2858 | nb_net_clients++; |
| 2859 | break; |
| 2860 | #ifdef CONFIG_SLIRP |
| 2861 | case QEMU_OPTION_tftp: |
| 2862 | tftp_prefix = optarg; |
| 2863 | break; |
| 2864 | case QEMU_OPTION_bootp: |
| 2865 | bootp_filename = optarg; |
| 2866 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2867 | case QEMU_OPTION_redir: |
| 2868 | net_slirp_redir(NULL, optarg, NULL); |
| 2869 | break; |
| 2870 | #endif |
| 2871 | case QEMU_OPTION_bt: |
| 2872 | if (nb_bt_opts >= MAX_BT_CMDLINE) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2873 | PANIC("qemu: too many bluetooth options"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2874 | } |
| 2875 | bt_opts[nb_bt_opts++] = optarg; |
| 2876 | break; |
| 2877 | #ifdef HAS_AUDIO |
| 2878 | case QEMU_OPTION_audio_help: |
| 2879 | AUD_help (); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2880 | QEMU_EXIT(0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2881 | break; |
| 2882 | case QEMU_OPTION_soundhw: |
| 2883 | select_soundhw (optarg); |
| 2884 | break; |
| 2885 | #endif |
| 2886 | case QEMU_OPTION_h: |
| 2887 | qemu_help(0); |
| 2888 | break; |
| 2889 | case QEMU_OPTION_version: |
| 2890 | version(); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2891 | QEMU_EXIT(0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2892 | break; |
| 2893 | case QEMU_OPTION_m: { |
| 2894 | uint64_t value; |
| 2895 | char *ptr; |
| 2896 | |
| 2897 | value = strtoul(optarg, &ptr, 10); |
| 2898 | switch (*ptr) { |
| 2899 | case 0: case 'M': case 'm': |
| 2900 | value <<= 20; |
| 2901 | break; |
| 2902 | case 'G': case 'g': |
| 2903 | value <<= 30; |
| 2904 | break; |
| 2905 | default: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2906 | PANIC("qemu: invalid ram size: %s", optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | /* On 32-bit hosts, QEMU is limited by virtual address space */ |
| 2910 | if (value > (2047 << 20) |
| 2911 | #ifndef CONFIG_KQEMU |
| 2912 | && HOST_LONG_BITS == 32 |
| 2913 | #endif |
| 2914 | ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2915 | PANIC("qemu: at most 2047 MB RAM can be simulated"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2916 | } |
| 2917 | if (value != (uint64_t)(ram_addr_t)value) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2918 | PANIC("qemu: ram size too large"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2919 | } |
| 2920 | ram_size = value; |
| 2921 | break; |
| 2922 | } |
| 2923 | case QEMU_OPTION_d: |
| 2924 | { |
| 2925 | int mask; |
| 2926 | const CPULogItem *item; |
| 2927 | |
| 2928 | mask = cpu_str_to_log_mask(optarg); |
| 2929 | if (!mask) { |
| 2930 | printf("Log items (comma separated):\n"); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2931 | for(item = cpu_log_items; item->mask != 0; item++) { |
| 2932 | printf("%-10s %s\n", item->name, item->help); |
| 2933 | } |
| 2934 | PANIC("Invalid parameter -d=%s", optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2935 | } |
| 2936 | cpu_set_log(mask); |
| 2937 | } |
| 2938 | break; |
| 2939 | case QEMU_OPTION_s: |
| 2940 | gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; |
| 2941 | break; |
| 2942 | case QEMU_OPTION_gdb: |
| 2943 | gdbstub_dev = optarg; |
| 2944 | break; |
| 2945 | case QEMU_OPTION_L: |
| 2946 | data_dir = optarg; |
| 2947 | break; |
| 2948 | case QEMU_OPTION_bios: |
| 2949 | bios_name = optarg; |
| 2950 | break; |
| 2951 | case QEMU_OPTION_singlestep: |
| 2952 | singlestep = 1; |
| 2953 | break; |
| 2954 | case QEMU_OPTION_S: |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2955 | autostart = 0; |
| 2956 | break; |
| 2957 | #ifndef _WIN32 |
| 2958 | case QEMU_OPTION_k: |
| 2959 | keyboard_layout = optarg; |
| 2960 | break; |
| 2961 | #endif |
| 2962 | case QEMU_OPTION_localtime: |
| 2963 | rtc_utc = 0; |
| 2964 | break; |
| 2965 | case QEMU_OPTION_vga: |
| 2966 | select_vgahw (optarg); |
| 2967 | break; |
| 2968 | #if defined(TARGET_PPC) || defined(TARGET_SPARC) |
| 2969 | case QEMU_OPTION_g: |
| 2970 | { |
| 2971 | const char *p; |
| 2972 | int w, h, depth; |
| 2973 | p = optarg; |
| 2974 | w = strtol(p, (char **)&p, 10); |
| 2975 | if (w <= 0) { |
| 2976 | graphic_error: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 2977 | PANIC("qemu: invalid resolution or depth"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 2978 | } |
| 2979 | if (*p != 'x') |
| 2980 | goto graphic_error; |
| 2981 | p++; |
| 2982 | h = strtol(p, (char **)&p, 10); |
| 2983 | if (h <= 0) |
| 2984 | goto graphic_error; |
| 2985 | if (*p == 'x') { |
| 2986 | p++; |
| 2987 | depth = strtol(p, (char **)&p, 10); |
| 2988 | if (depth != 8 && depth != 15 && depth != 16 && |
| 2989 | depth != 24 && depth != 32) |
| 2990 | goto graphic_error; |
| 2991 | } else if (*p == '\0') { |
| 2992 | depth = graphic_depth; |
| 2993 | } else { |
| 2994 | goto graphic_error; |
| 2995 | } |
| 2996 | |
| 2997 | graphic_width = w; |
| 2998 | graphic_height = h; |
| 2999 | graphic_depth = depth; |
| 3000 | } |
| 3001 | break; |
| 3002 | #endif |
| 3003 | case QEMU_OPTION_echr: |
| 3004 | { |
| 3005 | char *r; |
| 3006 | term_escape_char = strtol(optarg, &r, 0); |
| 3007 | if (r == optarg) |
| 3008 | printf("Bad argument to echr\n"); |
| 3009 | break; |
| 3010 | } |
| 3011 | case QEMU_OPTION_monitor: |
| 3012 | monitor_device = optarg; |
| 3013 | break; |
| 3014 | case QEMU_OPTION_serial: |
| 3015 | if (serial_device_index >= MAX_SERIAL_PORTS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3016 | PANIC("qemu: too many serial ports"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3017 | } |
| 3018 | serial_devices[serial_device_index] = optarg; |
| 3019 | serial_device_index++; |
| 3020 | break; |
| 3021 | case QEMU_OPTION_watchdog: |
| 3022 | i = select_watchdog(optarg); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3023 | if (i > 0) { |
| 3024 | if (i == 1) { |
| 3025 | PANIC("Invalid watchdog parameter: %s", |
| 3026 | optarg); |
| 3027 | } else { |
| 3028 | QEMU_EXIT(0); |
| 3029 | } |
| 3030 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3031 | break; |
| 3032 | case QEMU_OPTION_watchdog_action: |
| 3033 | if (select_watchdog_action(optarg) == -1) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3034 | PANIC("Unknown -watchdog-action parameter"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3035 | } |
| 3036 | break; |
| 3037 | case QEMU_OPTION_virtiocon: |
| 3038 | if (virtio_console_index >= MAX_VIRTIO_CONSOLES) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3039 | PANIC("qemu: too many virtio consoles"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3040 | } |
| 3041 | virtio_consoles[virtio_console_index] = optarg; |
| 3042 | virtio_console_index++; |
| 3043 | break; |
| 3044 | case QEMU_OPTION_parallel: |
| 3045 | if (parallel_device_index >= MAX_PARALLEL_PORTS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3046 | PANIC("qemu: too many parallel ports"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3047 | } |
| 3048 | parallel_devices[parallel_device_index] = optarg; |
| 3049 | parallel_device_index++; |
| 3050 | break; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 3051 | case QEMU_OPTION_loadvm: |
| 3052 | loadvm = optarg; |
| 3053 | break; |
Tim Baverstock | 24204cc | 2010-11-25 11:37:43 +0000 | [diff] [blame] | 3054 | case QEMU_OPTION_savevm_on_exit: |
| 3055 | savevm_on_exit = optarg; |
| 3056 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3057 | case QEMU_OPTION_full_screen: |
| 3058 | full_screen = 1; |
| 3059 | break; |
| 3060 | #ifdef CONFIG_SDL |
| 3061 | case QEMU_OPTION_no_frame: |
| 3062 | no_frame = 1; |
| 3063 | break; |
| 3064 | case QEMU_OPTION_alt_grab: |
| 3065 | alt_grab = 1; |
| 3066 | break; |
| 3067 | case QEMU_OPTION_no_quit: |
| 3068 | no_quit = 1; |
| 3069 | break; |
| 3070 | case QEMU_OPTION_sdl: |
| 3071 | display_type = DT_SDL; |
| 3072 | break; |
| 3073 | #endif |
| 3074 | case QEMU_OPTION_pidfile: |
| 3075 | pid_file = optarg; |
| 3076 | break; |
| 3077 | #ifdef TARGET_I386 |
| 3078 | case QEMU_OPTION_win2k_hack: |
| 3079 | win2k_install_hack = 1; |
| 3080 | break; |
| 3081 | case QEMU_OPTION_rtc_td_hack: |
| 3082 | rtc_td_hack = 1; |
| 3083 | break; |
Jun Nakajima | 334ab47 | 2011-02-02 23:49:59 -0800 | [diff] [blame] | 3084 | #ifndef CONFIG_ANDROID |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3085 | case QEMU_OPTION_acpitable: |
| 3086 | if(acpi_table_add(optarg) < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3087 | PANIC("Wrong acpi table provided"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3088 | } |
| 3089 | break; |
Jun Nakajima | 334ab47 | 2011-02-02 23:49:59 -0800 | [diff] [blame] | 3090 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3091 | case QEMU_OPTION_smbios: |
David 'Digit' Turner | ae3098a | 2011-05-11 16:01:57 +0200 | [diff] [blame] | 3092 | do_smbios_option(optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3093 | break; |
| 3094 | #endif |
| 3095 | #ifdef CONFIG_KVM |
| 3096 | case QEMU_OPTION_enable_kvm: |
| 3097 | kvm_allowed = 1; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3098 | break; |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 3099 | case QEMU_OPTION_disable_kvm: |
| 3100 | kvm_allowed = 0; |
| 3101 | break; |
| 3102 | #endif /* CONFIG_KVM */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3103 | case QEMU_OPTION_usb: |
| 3104 | usb_enabled = 1; |
| 3105 | break; |
| 3106 | case QEMU_OPTION_usbdevice: |
| 3107 | usb_enabled = 1; |
| 3108 | if (usb_devices_index >= MAX_USB_CMDLINE) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3109 | PANIC("Too many USB devices"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3110 | } |
| 3111 | usb_devices[usb_devices_index] = optarg; |
| 3112 | usb_devices_index++; |
| 3113 | break; |
| 3114 | case QEMU_OPTION_smp: |
| 3115 | smp_cpus = atoi(optarg); |
| 3116 | if (smp_cpus < 1) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3117 | PANIC("Invalid number of CPUs"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3118 | } |
| 3119 | break; |
| 3120 | case QEMU_OPTION_vnc: |
| 3121 | display_type = DT_VNC; |
| 3122 | vnc_display = optarg; |
| 3123 | break; |
| 3124 | #ifdef TARGET_I386 |
| 3125 | case QEMU_OPTION_no_acpi: |
| 3126 | acpi_enabled = 0; |
| 3127 | break; |
| 3128 | case QEMU_OPTION_no_hpet: |
| 3129 | no_hpet = 1; |
| 3130 | break; |
| 3131 | case QEMU_OPTION_no_virtio_balloon: |
| 3132 | no_virtio_balloon = 1; |
| 3133 | break; |
| 3134 | #endif |
| 3135 | case QEMU_OPTION_no_reboot: |
| 3136 | no_reboot = 1; |
| 3137 | break; |
| 3138 | case QEMU_OPTION_no_shutdown: |
| 3139 | no_shutdown = 1; |
| 3140 | break; |
| 3141 | case QEMU_OPTION_show_cursor: |
| 3142 | cursor_hide = 0; |
| 3143 | break; |
| 3144 | case QEMU_OPTION_uuid: |
| 3145 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3146 | PANIC("Fail to parse UUID string. Wrong format."); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3147 | } |
| 3148 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3149 | case QEMU_OPTION_option_rom: |
| 3150 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3151 | PANIC("Too many option ROMs"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3152 | } |
| 3153 | option_rom[nb_option_roms] = optarg; |
| 3154 | nb_option_roms++; |
| 3155 | break; |
| 3156 | #if defined(TARGET_ARM) || defined(TARGET_M68K) |
| 3157 | case QEMU_OPTION_semihosting: |
| 3158 | semihosting_enabled = 1; |
| 3159 | break; |
| 3160 | #endif |
| 3161 | case QEMU_OPTION_name: |
| 3162 | qemu_name = optarg; |
| 3163 | break; |
| 3164 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) |
| 3165 | case QEMU_OPTION_prom_env: |
| 3166 | if (nb_prom_envs >= MAX_PROM_ENVS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3167 | PANIC("Too many prom variables"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3168 | } |
| 3169 | prom_envs[nb_prom_envs] = optarg; |
| 3170 | nb_prom_envs++; |
| 3171 | break; |
| 3172 | #endif |
| 3173 | #ifdef TARGET_ARM |
| 3174 | case QEMU_OPTION_old_param: |
| 3175 | old_param = 1; |
| 3176 | break; |
| 3177 | #endif |
| 3178 | case QEMU_OPTION_clock: |
| 3179 | configure_alarms(optarg); |
| 3180 | break; |
| 3181 | case QEMU_OPTION_startdate: |
| 3182 | { |
| 3183 | struct tm tm; |
David 'Digit' Turner | dc46820 | 2010-10-27 02:34:46 +0200 | [diff] [blame] | 3184 | time_t rtc_start_date = 0; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3185 | if (!strcmp(optarg, "now")) { |
| 3186 | rtc_date_offset = -1; |
| 3187 | } else { |
| 3188 | if (sscanf(optarg, "%d-%d-%dT%d:%d:%d", |
| 3189 | &tm.tm_year, |
| 3190 | &tm.tm_mon, |
| 3191 | &tm.tm_mday, |
| 3192 | &tm.tm_hour, |
| 3193 | &tm.tm_min, |
| 3194 | &tm.tm_sec) == 6) { |
| 3195 | /* OK */ |
| 3196 | } else if (sscanf(optarg, "%d-%d-%d", |
| 3197 | &tm.tm_year, |
| 3198 | &tm.tm_mon, |
| 3199 | &tm.tm_mday) == 3) { |
| 3200 | tm.tm_hour = 0; |
| 3201 | tm.tm_min = 0; |
| 3202 | tm.tm_sec = 0; |
| 3203 | } else { |
| 3204 | goto date_fail; |
| 3205 | } |
| 3206 | tm.tm_year -= 1900; |
| 3207 | tm.tm_mon--; |
| 3208 | rtc_start_date = mktimegm(&tm); |
| 3209 | if (rtc_start_date == -1) { |
| 3210 | date_fail: |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3211 | PANIC("Invalid date format. Valid format are:\n" |
| 3212 | "'now' or '2006-06-17T16:01:21' or '2006-06-17'"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3213 | } |
| 3214 | rtc_date_offset = time(NULL) - rtc_start_date; |
| 3215 | } |
| 3216 | } |
| 3217 | break; |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 3218 | |
| 3219 | /* -------------------------------------------------------*/ |
| 3220 | /* User mode network stack restrictions */ |
| 3221 | case QEMU_OPTION_drop_udp: |
| 3222 | slirp_drop_udp(); |
| 3223 | break; |
| 3224 | case QEMU_OPTION_drop_tcp: |
| 3225 | slirp_drop_tcp(); |
| 3226 | break; |
| 3227 | case QEMU_OPTION_allow_tcp: |
| 3228 | slirp_allow(optarg, IPPROTO_TCP); |
| 3229 | break; |
| 3230 | case QEMU_OPTION_allow_udp: |
| 3231 | slirp_allow(optarg, IPPROTO_UDP); |
| 3232 | break; |
| 3233 | case QEMU_OPTION_drop_log: |
| 3234 | { |
| 3235 | FILE* drop_log_fd; |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 3236 | drop_log_filename = optarg; |
| 3237 | drop_log_fd = fopen(optarg, "w+"); |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 3238 | |
| 3239 | if (!drop_log_fd) { |
| 3240 | fprintf(stderr, "Cannot open drop log: %s\n", optarg); |
| 3241 | exit(1); |
| 3242 | } |
| 3243 | |
| 3244 | slirp_drop_log_fd(drop_log_fd); |
| 3245 | } |
| 3246 | break; |
| 3247 | |
| 3248 | case QEMU_OPTION_dns_log: |
| 3249 | { |
| 3250 | FILE* dns_log_fd; |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 3251 | dns_log_filename = optarg; |
| 3252 | dns_log_fd = fopen(optarg, "wb+"); |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 3253 | |
| 3254 | if (dns_log_fd == NULL) { |
| 3255 | fprintf(stderr, "Cannot open dns log: %s\n", optarg); |
| 3256 | exit(1); |
| 3257 | } |
| 3258 | |
| 3259 | slirp_dns_log_fd(dns_log_fd); |
| 3260 | } |
| 3261 | break; |
| 3262 | |
| 3263 | |
| 3264 | case QEMU_OPTION_max_dns_conns: |
| 3265 | { |
| 3266 | int max_dns_conns = 0; |
| 3267 | if (parse_int(optarg, &max_dns_conns)) { |
| 3268 | fprintf(stderr, |
| 3269 | "qemu: syntax: -max-dns-conns max_connections\n"); |
| 3270 | exit(1); |
| 3271 | } |
| 3272 | if (max_dns_conns <= 0 || max_dns_conns == LONG_MAX) { |
| 3273 | fprintf(stderr, |
| 3274 | "Invalid arg for max dns connections: %s\n", |
| 3275 | optarg); |
| 3276 | exit(1); |
| 3277 | } |
| 3278 | slirp_set_max_dns_conns(max_dns_conns); |
| 3279 | } |
| 3280 | break; |
| 3281 | |
| 3282 | case QEMU_OPTION_net_forward: |
| 3283 | net_slirp_forward(optarg); |
| 3284 | break; |
| 3285 | case QEMU_OPTION_net_forward_tcp2sink: |
| 3286 | { |
| 3287 | SockAddress saddr; |
| 3288 | |
| 3289 | if (parse_host_port(&saddr, optarg)) { |
| 3290 | fprintf(stderr, |
| 3291 | "Invalid ip/port %s for " |
| 3292 | "-forward-dropped-tcp2sink. " |
| 3293 | "We expect 'sink_ip:sink_port'\n", |
| 3294 | optarg); |
| 3295 | exit(1); |
| 3296 | } |
| 3297 | slirp_forward_dropped_tcp2sink(saddr.u.inet.address, |
| 3298 | saddr.u.inet.port); |
| 3299 | } |
| 3300 | break; |
| 3301 | /* -------------------------------------------------------*/ |
| 3302 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3303 | case QEMU_OPTION_tb_size: |
| 3304 | tb_size = strtol(optarg, NULL, 0); |
| 3305 | if (tb_size < 0) |
| 3306 | tb_size = 0; |
| 3307 | break; |
| 3308 | case QEMU_OPTION_icount: |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 3309 | icount_option = optarg; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3310 | break; |
| 3311 | case QEMU_OPTION_incoming: |
| 3312 | incoming = optarg; |
| 3313 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3314 | #ifdef CONFIG_XEN |
| 3315 | case QEMU_OPTION_xen_domid: |
| 3316 | xen_domid = atoi(optarg); |
| 3317 | break; |
| 3318 | case QEMU_OPTION_xen_create: |
| 3319 | xen_mode = XEN_CREATE; |
| 3320 | break; |
| 3321 | case QEMU_OPTION_xen_attach: |
| 3322 | xen_mode = XEN_ATTACH; |
| 3323 | break; |
| 3324 | #endif |
| 3325 | |
| 3326 | |
| 3327 | case QEMU_OPTION_mic: |
| 3328 | audio_input_source = (char*)optarg; |
| 3329 | break; |
| 3330 | #ifdef CONFIG_TRACE |
David 'Digit' Turner | a577fca | 2009-10-15 18:18:09 -0700 | [diff] [blame] | 3331 | case QEMU_OPTION_trace: |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3332 | trace_filename = optarg; |
| 3333 | tracing = 1; |
| 3334 | break; |
| 3335 | #if 0 |
| 3336 | case QEMU_OPTION_trace_miss: |
| 3337 | trace_cache_miss = 1; |
| 3338 | break; |
| 3339 | case QEMU_OPTION_trace_addr: |
| 3340 | trace_all_addr = 1; |
| 3341 | break; |
| 3342 | #endif |
| 3343 | case QEMU_OPTION_tracing: |
| 3344 | if (strcmp(optarg, "off") == 0) |
| 3345 | tracing = 0; |
| 3346 | else if (strcmp(optarg, "on") == 0 && trace_filename) |
| 3347 | tracing = 1; |
| 3348 | else { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3349 | PANIC("Unexpected option to -tracing ('%s')", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3350 | optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3351 | } |
| 3352 | break; |
| 3353 | #if 0 |
| 3354 | case QEMU_OPTION_dcache_load_miss: |
| 3355 | dcache_load_miss_penalty = atoi(optarg); |
| 3356 | break; |
| 3357 | case QEMU_OPTION_dcache_store_miss: |
| 3358 | dcache_store_miss_penalty = atoi(optarg); |
| 3359 | break; |
| 3360 | #endif |
| 3361 | #endif |
| 3362 | #ifdef CONFIG_NAND |
| 3363 | case QEMU_OPTION_nand: |
| 3364 | nand_add_dev(optarg); |
| 3365 | break; |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 3366 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3367 | #endif |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 3368 | case QEMU_OPTION_disable_hax: |
| 3369 | hax_disabled = 1; |
| 3370 | break; |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 3371 | case QEMU_OPTION_android_ports: |
| 3372 | android_op_ports = (char*)optarg; |
| 3373 | break; |
| 3374 | |
| 3375 | case QEMU_OPTION_android_port: |
| 3376 | android_op_port = (char*)optarg; |
| 3377 | break; |
| 3378 | |
| 3379 | case QEMU_OPTION_android_report_console: |
| 3380 | android_op_report_console = (char*)optarg; |
| 3381 | break; |
| 3382 | |
| 3383 | case QEMU_OPTION_http_proxy: |
| 3384 | op_http_proxy = (char*)optarg; |
| 3385 | break; |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3386 | |
| 3387 | case QEMU_OPTION_charmap: |
| 3388 | op_charmap_file = (char*)optarg; |
| 3389 | break; |
Vladimir Chtchetkine | dd50f7d | 2010-07-30 09:16:41 -0700 | [diff] [blame] | 3390 | |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3391 | case QEMU_OPTION_android_hw: |
| 3392 | android_op_hwini = (char*)optarg; |
| 3393 | break; |
Vladimir Chtchetkine | 13f3b6c | 2010-08-25 09:49:25 -0700 | [diff] [blame] | 3394 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3395 | case QEMU_OPTION_dns_server: |
| 3396 | android_op_dns_server = (char*)optarg; |
| 3397 | break; |
| 3398 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3399 | case QEMU_OPTION_radio: |
| 3400 | android_op_radio = (char*)optarg; |
| 3401 | break; |
| 3402 | |
| 3403 | case QEMU_OPTION_gps: |
| 3404 | android_op_gps = (char*)optarg; |
| 3405 | break; |
| 3406 | |
| 3407 | case QEMU_OPTION_audio: |
| 3408 | android_op_audio = (char*)optarg; |
| 3409 | break; |
| 3410 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3411 | case QEMU_OPTION_cpu_delay: |
| 3412 | android_op_cpu_delay = (char*)optarg; |
| 3413 | break; |
| 3414 | |
Vladimir Chtchetkine | 13f3b6c | 2010-08-25 09:49:25 -0700 | [diff] [blame] | 3415 | case QEMU_OPTION_show_kernel: |
| 3416 | android_kmsg_init(ANDROID_KMSG_PRINT_MESSAGES); |
| 3417 | break; |
| 3418 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3419 | #ifdef CONFIG_NAND_LIMITS |
| 3420 | case QEMU_OPTION_nand_limits: |
| 3421 | android_op_nand_limits = (char*)optarg; |
| 3422 | break; |
| 3423 | #endif // CONFIG_NAND_LIMITS |
| 3424 | |
| 3425 | case QEMU_OPTION_netspeed: |
| 3426 | android_op_netspeed = (char*)optarg; |
| 3427 | break; |
| 3428 | |
| 3429 | case QEMU_OPTION_netdelay: |
| 3430 | android_op_netdelay = (char*)optarg; |
| 3431 | break; |
| 3432 | |
| 3433 | case QEMU_OPTION_netfast: |
| 3434 | android_op_netfast = 1; |
| 3435 | break; |
| 3436 | |
Vladimir Chtchetkine | 318f17a | 2010-08-27 09:09:45 -0700 | [diff] [blame] | 3437 | case QEMU_OPTION_tcpdump: |
| 3438 | android_op_tcpdump = (char*)optarg; |
| 3439 | break; |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3440 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3441 | case QEMU_OPTION_boot_property: |
| 3442 | boot_property_parse_option((char*)optarg); |
| 3443 | break; |
| 3444 | |
| 3445 | case QEMU_OPTION_lcd_density: |
| 3446 | android_op_lcd_density = (char*)optarg; |
| 3447 | break; |
| 3448 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3449 | case QEMU_OPTION_ui_port: |
| 3450 | android_op_ui_port = (char*)optarg; |
| 3451 | break; |
| 3452 | |
| 3453 | case QEMU_OPTION_ui_settings: |
| 3454 | android_op_ui_settings = (char*)optarg; |
| 3455 | break; |
| 3456 | |
David 'Digit' Turner | ca29fbb | 2011-01-02 13:17:22 +0100 | [diff] [blame] | 3457 | case QEMU_OPTION_audio_test_out: |
| 3458 | android_audio_test_start_out(); |
| 3459 | break; |
| 3460 | |
Vladimir Chtchetkine | 90c6235 | 2011-01-13 11:24:07 -0800 | [diff] [blame] | 3461 | case QEMU_OPTION_android_avdname: |
| 3462 | android_op_avd_name = (char*)optarg; |
| 3463 | break; |
| 3464 | |
| 3465 | case QEMU_OPTION_timezone: |
| 3466 | if (timezone_set((char*)optarg)) { |
| 3467 | fprintf(stderr, "emulator: it seems the timezone '%s' is not in zoneinfo format\n", |
| 3468 | (char*)optarg); |
| 3469 | } |
| 3470 | break; |
| 3471 | |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3472 | #ifdef CONFIG_MEMCHECK |
| 3473 | case QEMU_OPTION_android_memcheck: |
| 3474 | android_op_memcheck = (char*)optarg; |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3475 | /* This will set ro.kernel.memcheck system property |
| 3476 | * to memcheck's tracing flags. */ |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 3477 | stralloc_add_format(kernel_config, " memcheck=%s", android_op_memcheck); |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3478 | break; |
| 3479 | #endif // CONFIG_MEMCHECK |
David 'Digit' Turner | bdb6f2d | 2011-02-23 15:57:25 +0100 | [diff] [blame] | 3480 | |
| 3481 | case QEMU_OPTION_snapshot_no_time_update: |
| 3482 | android_snapshot_update_time = 0; |
| 3483 | break; |
Vladimir Chtchetkine | b8dcaff | 2011-09-17 11:15:47 -0700 | [diff] [blame] | 3484 | |
| 3485 | case QEMU_OPTION_list_webcam: |
| 3486 | android_list_web_cameras(); |
| 3487 | exit(0); |
| 3488 | |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 3489 | default: |
| 3490 | os_parse_cmd_args(popt->index, optarg); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | } |
| 3494 | |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3495 | /* Initialize character map. */ |
| 3496 | if (android_charmap_setup(op_charmap_file)) { |
| 3497 | if (op_charmap_file) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3498 | PANIC( |
| 3499 | "Unable to initialize character map from file %s.", |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3500 | op_charmap_file); |
| 3501 | } else { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3502 | PANIC( |
| 3503 | "Unable to initialize default character map."); |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3504 | } |
Vladimir Chtchetkine | 43552dc | 2010-07-22 11:23:19 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3507 | /* If no data_dir is specified then try to find it relative to the |
| 3508 | executable path. */ |
| 3509 | if (!data_dir) { |
| 3510 | data_dir = find_datadir(argv[0]); |
| 3511 | } |
| 3512 | /* If all else fails use the install patch specified when building. */ |
| 3513 | if (!data_dir) { |
| 3514 | data_dir = CONFIG_QEMU_SHAREDIR; |
| 3515 | } |
| 3516 | |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3517 | if (!android_op_hwini) { |
| 3518 | PANIC("Missing -android-hw <file> option!"); |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3519 | } |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3520 | hw_ini = iniFile_newFromFile(android_op_hwini); |
| 3521 | if (hw_ini == NULL) { |
| 3522 | PANIC("Could not find %s file.", android_op_hwini); |
| 3523 | } |
David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 3524 | |
| 3525 | androidHwConfig_init(android_hw, 0); |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3526 | androidHwConfig_read(android_hw, hw_ini); |
David 'Digit' Turner | b64325d | 2011-03-22 16:07:01 +0100 | [diff] [blame] | 3527 | |
Vladimir Chtchetkine | db450d7 | 2012-01-12 13:37:40 -0800 | [diff] [blame] | 3528 | /* If we're loading VM from a snapshot, make sure that the current HW config |
| 3529 | * matches the one with which the VM has been saved. */ |
| 3530 | if (loadvm && *loadvm && !snaphost_match_configs(hw_ini, loadvm)) { |
| 3531 | exit(0); |
| 3532 | } |
| 3533 | |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3534 | iniFile_free(hw_ini); |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 3535 | |
| 3536 | { |
| 3537 | int width = android_hw->hw_lcd_width; |
| 3538 | int height = android_hw->hw_lcd_height; |
| 3539 | int depth = android_hw->hw_lcd_depth; |
| 3540 | |
| 3541 | /* A bit of sanity checking */ |
| 3542 | if (width <= 0 || height <= 0 || |
| 3543 | (depth != 16 && depth != 32) || |
| 3544 | (((width|height) & 3) != 0) ) |
| 3545 | { |
| 3546 | PANIC("Invalid display configuration (%d,%d,%d)", |
| 3547 | width, height, depth); |
| 3548 | } |
| 3549 | android_display_width = width; |
| 3550 | android_display_height = height; |
| 3551 | android_display_bpp = depth; |
| 3552 | } |
Vladimir Chtchetkine | 074d1f9 | 2010-08-06 09:29:50 -0700 | [diff] [blame] | 3553 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3554 | #ifdef CONFIG_NAND_LIMITS |
| 3555 | /* Init nand stuff. */ |
| 3556 | if (android_op_nand_limits) { |
| 3557 | parse_nand_limits(android_op_nand_limits); |
| 3558 | } |
| 3559 | #endif // CONFIG_NAND_LIMITS |
| 3560 | |
David 'Digit' Turner | 53eb66d | 2011-03-01 14:58:23 +0100 | [diff] [blame] | 3561 | /* Initialize AVD name from hardware configuration if needed */ |
| 3562 | if (!android_op_avd_name) { |
| 3563 | if (android_hw->avd_name && *android_hw->avd_name) { |
| 3564 | android_op_avd_name = android_hw->avd_name; |
| 3565 | VERBOSE_PRINT(init,"AVD Name: %s", android_op_avd_name); |
| 3566 | } |
| 3567 | } |
| 3568 | |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3569 | /* Initialize system partition image */ |
| 3570 | { |
| 3571 | char tmp[PATH_MAX+32]; |
| 3572 | const char* sysImage = android_hw->disk_systemPartition_path; |
| 3573 | const char* initImage = android_hw->disk_systemPartition_initPath; |
| 3574 | uint64_t sysBytes = android_hw->disk_systemPartition_size; |
| 3575 | |
| 3576 | if (sysBytes == 0) { |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3577 | PANIC("Invalid system partition size: %" PRIu64, sysBytes); |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3578 | } |
| 3579 | |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3580 | snprintf(tmp,sizeof(tmp),"system,size=0x%" PRIx64, sysBytes); |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3581 | |
| 3582 | if (sysImage && *sysImage) { |
| 3583 | if (filelock_create(sysImage) == NULL) { |
| 3584 | fprintf(stderr,"WARNING: System image already in use, changes will not persist!\n"); |
| 3585 | /* If there is no file= parameters, nand_add_dev will create |
| 3586 | * a temporary file to back the partition image. */ |
| 3587 | } else { |
| 3588 | pstrcat(tmp,sizeof(tmp),",file="); |
| 3589 | pstrcat(tmp,sizeof(tmp),sysImage); |
| 3590 | } |
| 3591 | } |
| 3592 | if (initImage && *initImage) { |
| 3593 | if (!path_exists(initImage)) { |
| 3594 | PANIC("Invalid initial system image path: %s", initImage); |
| 3595 | } |
| 3596 | pstrcat(tmp,sizeof(tmp),",initfile="); |
| 3597 | pstrcat(tmp,sizeof(tmp),initImage); |
| 3598 | } else { |
| 3599 | PANIC("Missing initial system image path!"); |
| 3600 | } |
Deepanshu Gupta | 04b20f4 | 2013-09-11 12:04:27 -0700 | [diff] [blame] | 3601 | if (android_hw->hw_useext4) { |
| 3602 | /* Using a nand device to approximate a block device until full |
| 3603 | * support is added */ |
| 3604 | pstrcat(tmp,sizeof(tmp),",pagesize=512,extrasize=0"); |
| 3605 | } |
David 'Digit' Turner | 40841b2 | 2011-03-01 14:04:00 +0100 | [diff] [blame] | 3606 | nand_add_dev(tmp); |
| 3607 | } |
| 3608 | |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3609 | /* Initialize data partition image */ |
| 3610 | { |
| 3611 | char tmp[PATH_MAX+32]; |
| 3612 | const char* dataImage = android_hw->disk_dataPartition_path; |
| 3613 | const char* initImage = android_hw->disk_dataPartition_initPath; |
| 3614 | uint64_t dataBytes = android_hw->disk_dataPartition_size; |
| 3615 | |
| 3616 | if (dataBytes == 0) { |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3617 | PANIC("Invalid data partition size: %" PRIu64, dataBytes); |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3618 | } |
| 3619 | |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3620 | snprintf(tmp,sizeof(tmp),"userdata,size=0x%" PRIx64, dataBytes); |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3621 | |
| 3622 | if (dataImage && *dataImage) { |
| 3623 | if (filelock_create(dataImage) == NULL) { |
| 3624 | fprintf(stderr, "WARNING: Data partition already in use. Changes will not persist!\n"); |
| 3625 | /* Note: if there is no file= parameters, nand_add_dev() will |
| 3626 | * create a temporary file to back the partition image. */ |
| 3627 | } else { |
| 3628 | /* Create the file if needed */ |
| 3629 | if (!path_exists(dataImage)) { |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3630 | if (path_empty_file(dataImage) < 0) { |
| 3631 | PANIC("Could not create data image file %s: %s", dataImage, strerror(errno)); |
| 3632 | } |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3633 | } |
| 3634 | pstrcat(tmp, sizeof(tmp), ",file="); |
| 3635 | pstrcat(tmp, sizeof(tmp), dataImage); |
| 3636 | } |
| 3637 | } |
| 3638 | if (initImage && *initImage) { |
| 3639 | pstrcat(tmp, sizeof(tmp), ",initfile="); |
| 3640 | pstrcat(tmp, sizeof(tmp), initImage); |
| 3641 | } |
Deepanshu Gupta | 04b20f4 | 2013-09-11 12:04:27 -0700 | [diff] [blame] | 3642 | if (android_hw->hw_useext4) { |
| 3643 | /* Using a nand device to approximate a block device until full |
| 3644 | * support is added */ |
| 3645 | pstrcat(tmp, sizeof(tmp), ",pagesize=512,extrasize=0"); |
| 3646 | } |
David 'Digit' Turner | fd59c33 | 2011-03-01 00:48:52 +0100 | [diff] [blame] | 3647 | nand_add_dev(tmp); |
| 3648 | } |
| 3649 | |
David 'Digit' Turner | 48a3c66 | 2011-03-01 14:03:20 +0100 | [diff] [blame] | 3650 | /* Init SD-Card stuff. For Android, it is always hda */ |
| 3651 | /* If the -hda option was used, ignore the Android-provided one */ |
| 3652 | if (hda_opts == NULL) { |
| 3653 | const char* sdPath = android_hw->hw_sdCard_path; |
| 3654 | if (sdPath && *sdPath) { |
| 3655 | if (!path_exists(sdPath)) { |
| 3656 | fprintf(stderr, "WARNING: SD Card image is missing: %s\n", sdPath); |
| 3657 | } else if (filelock_create(sdPath) == NULL) { |
| 3658 | fprintf(stderr, "WARNING: SD Card image already in use: %s\n", sdPath); |
| 3659 | } else { |
| 3660 | /* Successful locking */ |
| 3661 | hda_opts = drive_add(sdPath, HD_ALIAS, 0); |
David 'Digit' Turner | 8fc3e6e | 2011-05-09 10:17:20 +0200 | [diff] [blame] | 3662 | /* Set this property of any operation involving the SD Card |
| 3663 | * will be x100 slower, due to the corresponding file being |
| 3664 | * mounted as O_DIRECT. Note that this is only 'unsafe' in |
| 3665 | * the context of an emulator crash. The data is already |
| 3666 | * synced properly when the emulator exits (either normally or through ^C). |
| 3667 | */ |
| 3668 | qemu_opt_set(hda_opts, "cache", "unsafe"); |
David 'Digit' Turner | 48a3c66 | 2011-03-01 14:03:20 +0100 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | } |
| 3672 | |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 3673 | if (hdb_opts == NULL) { |
| 3674 | const char* spath = android_hw->disk_snapStorage_path; |
| 3675 | if (spath && *spath) { |
| 3676 | if (!path_exists(spath)) { |
| 3677 | PANIC("Snapshot storage file does not exist: %s", spath); |
| 3678 | } |
| 3679 | if (filelock_create(spath) == NULL) { |
David 'Digit' Turner | 4297b82 | 2011-05-04 19:18:15 +0200 | [diff] [blame] | 3680 | PANIC("Snapshot storage already in use: %s", spath); |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 3681 | } |
| 3682 | hdb_opts = drive_add(spath, HD_ALIAS, 1); |
David 'Digit' Turner | 8fc3e6e | 2011-05-09 10:17:20 +0200 | [diff] [blame] | 3683 | /* See comment above to understand why this is needed. */ |
David 'Digit' Turner | 9fb360e | 2011-05-04 22:01:28 +0200 | [diff] [blame] | 3684 | qemu_opt_set(hdb_opts, "cache", "unsafe"); |
David 'Digit' Turner | 5f64b87 | 2011-02-28 23:23:05 +0100 | [diff] [blame] | 3685 | } |
| 3686 | } |
| 3687 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3688 | /* Set the VM's max heap size, passed as a boot property */ |
| 3689 | if (android_hw->vm_heapSize > 0) { |
| 3690 | char tmp[64]; |
| 3691 | snprintf(tmp, sizeof(tmp), "%dm", android_hw->vm_heapSize); |
| 3692 | boot_property_add("dalvik.vm.heapsize",tmp); |
| 3693 | } |
| 3694 | |
Siva Velusamy | 0faeb3a | 2013-10-29 14:23:35 -0700 | [diff] [blame] | 3695 | /* From API 19 and above, the platform provides an explicit property for low memory devices. */ |
| 3696 | if (android_hw->hw_ramSize <= 512) { |
| 3697 | boot_property_add("ro.config.low_ram", "true"); |
| 3698 | } |
| 3699 | |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3700 | /* Initialize net speed and delays stuff. */ |
| 3701 | if (android_parse_network_speed(android_op_netspeed) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3702 | PANIC("invalid -netspeed parameter '%s'", |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3703 | android_op_netspeed); |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | if ( android_parse_network_latency(android_op_netdelay) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3707 | PANIC("invalid -netdelay parameter '%s'", |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3708 | android_op_netdelay); |
Vladimir Chtchetkine | e131686 | 2010-08-26 09:03:54 -0700 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | if (android_op_netfast) { |
| 3712 | qemu_net_download_speed = 0; |
| 3713 | qemu_net_upload_speed = 0; |
| 3714 | qemu_net_min_latency = 0; |
| 3715 | qemu_net_max_latency = 0; |
| 3716 | } |
| 3717 | |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3718 | /* Initialize LCD density */ |
David 'Digit' Turner | 5377c5b | 2011-02-10 16:52:19 +0100 | [diff] [blame] | 3719 | if (android_hw->hw_lcd_density) { |
| 3720 | long density = android_hw->hw_lcd_density; |
| 3721 | if (density <= 0) { |
| 3722 | PANIC("Invalid hw.lcd.density value: %ld", density); |
Vladimir Chtchetkine | b25bf2a | 2010-09-08 11:09:23 -0700 | [diff] [blame] | 3723 | } |
| 3724 | hwLcd_setBootProperty(density); |
| 3725 | } |
| 3726 | |
Xavier Ducrohet | fa0c8e2 | 2011-10-04 10:41:26 -0700 | [diff] [blame] | 3727 | /* Initialize presence of hardware nav button */ |
| 3728 | boot_property_add("qemu.hw.mainkeys", android_hw->hw_mainKeys ? "1" : "0"); |
| 3729 | |
Vladimir Chtchetkine | 318f17a | 2010-08-27 09:09:45 -0700 | [diff] [blame] | 3730 | /* Initialize TCP dump */ |
| 3731 | if (android_op_tcpdump) { |
| 3732 | if (qemu_tcpdump_start(android_op_tcpdump) < 0) { |
| 3733 | fprintf(stdout, "could not start packet capture: %s\n", strerror(errno)); |
| 3734 | } |
| 3735 | } |
| 3736 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3737 | /* Initialize modem */ |
| 3738 | if (android_op_radio) { |
| 3739 | CharDriverState* cs = qemu_chr_open("radio", android_op_radio, NULL); |
| 3740 | if (cs == NULL) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3741 | PANIC("unsupported character device specification: %s\n" |
| 3742 | "used -help-char-devices for list of available formats", |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3743 | android_op_radio); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3744 | } |
| 3745 | android_qemud_set_channel( ANDROID_QEMUD_GSM, cs); |
| 3746 | } else if (android_hw->hw_gsmModem != 0 ) { |
| 3747 | if ( android_qemud_get_channel( ANDROID_QEMUD_GSM, &android_modem_cs ) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3748 | PANIC("could not initialize qemud 'gsm' channel"); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | /* Initialize GPS */ |
| 3753 | if (android_op_gps) { |
| 3754 | CharDriverState* cs = qemu_chr_open("gps", android_op_gps, NULL); |
| 3755 | if (cs == NULL) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3756 | PANIC("unsupported character device specification: %s\n" |
| 3757 | "used -help-char-devices for list of available formats", |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3758 | android_op_gps); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3759 | } |
| 3760 | android_qemud_set_channel( ANDROID_QEMUD_GPS, cs); |
| 3761 | } else if (android_hw->hw_gps != 0) { |
| 3762 | if ( android_qemud_get_channel( "gps", &android_gps_cs ) < 0 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3763 | PANIC("could not initialize qemud 'gps' channel"); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3764 | } |
| 3765 | } |
| 3766 | |
| 3767 | /* Initialize audio. */ |
| 3768 | if (android_op_audio) { |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3769 | if ( !audio_check_backend_name( 0, android_op_audio ) ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3770 | PANIC("'%s' is not a valid audio output backend. see -help-audio-out", |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3771 | android_op_audio); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3772 | } |
David 'Digit' Turner | f816a75 | 2011-06-23 18:40:11 +0200 | [diff] [blame] | 3773 | setenv("QEMU_AUDIO_DRV", android_op_audio, 1); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
David 'Digit' Turner | 5b48149 | 2011-04-11 17:37:32 +0200 | [diff] [blame] | 3776 | /* Initialize OpenGLES emulation */ |
David 'Digit' Turner | d4d688e | 2011-04-26 18:09:17 +0200 | [diff] [blame] | 3777 | //android_hw_opengles_init(); |
David 'Digit' Turner | 5b48149 | 2011-04-11 17:37:32 +0200 | [diff] [blame] | 3778 | |
Vladimir Chtchetkine | ae0d813 | 2011-09-13 10:48:02 -0700 | [diff] [blame] | 3779 | /* Initialize fake camera */ |
Vladimir Chtchetkine | 7485c29 | 2012-03-19 11:35:29 -0700 | [diff] [blame] | 3780 | if (strcmp(android_hw->hw_camera_back, "emulated") && |
| 3781 | strcmp(android_hw->hw_camera_front, "emulated")) { |
| 3782 | /* Fake camera is not used for camera emulation. */ |
| 3783 | boot_property_add("qemu.sf.fake_camera", "none"); |
Vladimir Chtchetkine | ae0d813 | 2011-09-13 10:48:02 -0700 | [diff] [blame] | 3784 | } else { |
Vladimir Chtchetkine | 7485c29 | 2012-03-19 11:35:29 -0700 | [diff] [blame] | 3785 | /* Fake camera is used for at least one camera emulation. */ |
| 3786 | if (!strcmp(android_hw->hw_camera_back, "emulated") && |
| 3787 | !strcmp(android_hw->hw_camera_front, "emulated")) { |
| 3788 | /* Fake camera is used for both, front and back camera emulation. */ |
| 3789 | boot_property_add("qemu.sf.fake_camera", "both"); |
| 3790 | } else if (!strcmp(android_hw->hw_camera_back, "emulated")) { |
| 3791 | boot_property_add("qemu.sf.fake_camera", "back"); |
| 3792 | } else { |
| 3793 | boot_property_add("qemu.sf.fake_camera", "front"); |
| 3794 | } |
Vladimir Chtchetkine | ae0d813 | 2011-09-13 10:48:02 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Vladimir Chtchetkine | 035f805 | 2012-05-18 12:19:32 -0700 | [diff] [blame] | 3797 | /* Set LCD density (if required by -qemu, and AVD is missing it. */ |
| 3798 | if (android_op_lcd_density && !android_hw->hw_lcd_density) { |
| 3799 | int density; |
| 3800 | if (parse_int(android_op_lcd_density, &density) || density <= 0) { |
| 3801 | PANIC("-lcd-density : %d", density); |
| 3802 | } |
| 3803 | hwLcd_setBootProperty(density); |
| 3804 | } |
| 3805 | |
Vladimir Chtchetkine | b8dcaff | 2011-09-17 11:15:47 -0700 | [diff] [blame] | 3806 | /* Initialize camera emulation. */ |
| 3807 | android_camera_service_init(); |
| 3808 | |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3809 | if (android_op_cpu_delay) { |
| 3810 | char* end; |
| 3811 | long delay = strtol(android_op_cpu_delay, &end, 0); |
| 3812 | if (end == NULL || *end || delay < 0 || delay > 1000 ) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3813 | PANIC("option -cpu-delay must be an integer between 0 and 1000" ); |
Vladimir Chtchetkine | b243840 | 2010-08-24 08:55:33 -0700 | [diff] [blame] | 3814 | } |
| 3815 | if (delay > 0) |
| 3816 | delay = (1000-delay); |
| 3817 | |
| 3818 | qemu_cpu_delay = (int) delay; |
| 3819 | } |
| 3820 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3821 | if (android_op_dns_server) { |
| 3822 | char* x = strchr(android_op_dns_server, ','); |
| 3823 | dns_count = 0; |
| 3824 | if (x == NULL) |
| 3825 | { |
| 3826 | if ( add_dns_server( android_op_dns_server ) == 0 ) |
| 3827 | dns_count = 1; |
| 3828 | } |
| 3829 | else |
| 3830 | { |
| 3831 | x = android_op_dns_server; |
| 3832 | while (*x) { |
| 3833 | char* y = strchr(x, ','); |
| 3834 | |
| 3835 | if (y != NULL) { |
| 3836 | *y = 0; |
| 3837 | y++; |
| 3838 | } else { |
| 3839 | y = x + strlen(x); |
| 3840 | } |
| 3841 | |
| 3842 | if (y > x && add_dns_server( x ) == 0) { |
| 3843 | dns_count += 1; |
| 3844 | } |
| 3845 | x = y; |
| 3846 | } |
| 3847 | } |
| 3848 | if (dns_count == 0) |
| 3849 | fprintf( stdout, "### WARNING: will use system default DNS server\n" ); |
| 3850 | } |
| 3851 | |
| 3852 | if (dns_count == 0) |
| 3853 | dns_count = slirp_get_system_dns_servers(); |
| 3854 | if (dns_count) { |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 3855 | stralloc_add_format(kernel_config, " ndns=%d", dns_count); |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 3856 | } |
| 3857 | |
Vladimir Chtchetkine | b5365f3 | 2010-08-09 13:33:57 -0700 | [diff] [blame] | 3858 | #ifdef CONFIG_MEMCHECK |
| 3859 | if (android_op_memcheck) { |
| 3860 | memcheck_init(android_op_memcheck); |
| 3861 | } |
| 3862 | #endif // CONFIG_MEMCHECK |
| 3863 | |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3864 | /* Initialize cache partition, if any */ |
| 3865 | if (android_hw->disk_cachePartition != 0) { |
| 3866 | char tmp[PATH_MAX+32]; |
| 3867 | const char* partPath = android_hw->disk_cachePartition_path; |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3868 | uint64_t partSize = android_hw->disk_cachePartition_size; |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3869 | |
Andrew Hsieh | c7389bd | 2012-03-13 02:13:40 -0700 | [diff] [blame] | 3870 | snprintf(tmp,sizeof(tmp),"cache,size=0x%" PRIx64, partSize); |
David 'Digit' Turner | e8ab08c | 2011-03-15 23:08:50 +0100 | [diff] [blame] | 3871 | |
| 3872 | if (partPath && *partPath && strcmp(partPath, "<temp>") != 0) { |
| 3873 | if (filelock_create(partPath) == NULL) { |
| 3874 | fprintf(stderr, "WARNING: Cache partition already in use. Changes will not persist!\n"); |
| 3875 | /* Note: if there is no file= parameters, nand_add_dev() will |
| 3876 | * create a temporary file to back the partition image. */ |
| 3877 | } else { |
| 3878 | /* Create the file if needed */ |
| 3879 | if (!path_exists(partPath)) { |
| 3880 | if (path_empty_file(partPath) < 0) { |
| 3881 | PANIC("Could not create cache image file %s: %s", partPath, strerror(errno)); |
| 3882 | } |
| 3883 | } |
| 3884 | pstrcat(tmp, sizeof(tmp), ",file="); |
| 3885 | pstrcat(tmp, sizeof(tmp), partPath); |
| 3886 | } |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3887 | } |
Deepanshu Gupta | 04b20f4 | 2013-09-11 12:04:27 -0700 | [diff] [blame] | 3888 | if (android_hw->hw_useext4) { |
| 3889 | /* Using a nand device to approximate a block device until full |
| 3890 | * support is added */ |
| 3891 | pstrcat(tmp, sizeof(tmp), ",pagesize=512,extrasize=0"); |
| 3892 | } |
David 'Digit' Turner | c480cca | 2011-02-25 16:43:34 +0100 | [diff] [blame] | 3893 | nand_add_dev(tmp); |
| 3894 | } |
| 3895 | |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3896 | /* qemu.gles will be read by the OpenGL ES emulation libraries. |
| 3897 | * If set to 0, the software GL ES renderer will be used as a fallback. |
| 3898 | * If the parameter is undefined, this means the system image runs |
| 3899 | * inside an emulator that doesn't support GPU emulation at all. |
| 3900 | * |
| 3901 | * We always start the GL ES renderer so we can gather stats on the |
| 3902 | * underlying GL implementation. If GL ES acceleration is disabled, |
| 3903 | * we just shut it down again once we have the strings. */ |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3904 | { |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3905 | int qemu_gles = 0; |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3906 | if (android_initOpenglesEmulation() == 0 && |
Jesse Hall | ba5c1f6 | 2012-05-08 15:44:35 -0700 | [diff] [blame] | 3907 | android_startOpenglesRenderer(android_hw->hw_lcd_width, android_hw->hw_lcd_height) == 0) |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3908 | { |
| 3909 | android_getOpenglesHardwareStrings( |
| 3910 | android_gl_vendor, sizeof(android_gl_vendor), |
| 3911 | android_gl_renderer, sizeof(android_gl_renderer), |
| 3912 | android_gl_version, sizeof(android_gl_version)); |
| 3913 | if (android_hw->hw_gpu_enabled) { |
| 3914 | qemu_gles = 1; |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3915 | } else { |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3916 | android_stopOpenglesRenderer(); |
| 3917 | qemu_gles = 0; |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3918 | } |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3919 | } else { |
| 3920 | dwarning("Could not initialize OpenglES emulation, using software renderer."); |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3921 | } |
Jesse Hall | 733fffa | 2012-04-26 11:07:32 -0700 | [diff] [blame] | 3922 | if (qemu_gles) { |
David 'Digit' Turner | cb88e79 | 2011-08-26 01:35:14 +0200 | [diff] [blame] | 3923 | stralloc_add_str(kernel_params, " qemu.gles=1"); |
| 3924 | } else { |
| 3925 | stralloc_add_str(kernel_params, " qemu.gles=0"); |
| 3926 | } |
| 3927 | } |
| 3928 | |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 3929 | /* We always force qemu=1 when running inside QEMU */ |
| 3930 | stralloc_add_str(kernel_params, " qemu=1"); |
| 3931 | |
| 3932 | /* We always initialize the first serial port for the android-kmsg |
| 3933 | * character device (used to send kernel messages) */ |
| 3934 | serial_hds_add_at(0, "android-kmsg"); |
| 3935 | stralloc_add_str(kernel_params, " console=ttyS0"); |
| 3936 | |
| 3937 | /* We always initialize the second serial port for the android-qemud |
| 3938 | * character device as well */ |
| 3939 | serial_hds_add_at(1, "android-qemud"); |
| 3940 | stralloc_add_str(kernel_params, " android.qemud=ttyS1"); |
| 3941 | |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 3942 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
| 3943 | os_pidfile_error(); |
| 3944 | exit(1); |
| 3945 | } |
| 3946 | |
David 'Digit' Turner | 3659775 | 2011-05-20 01:18:01 +0200 | [diff] [blame] | 3947 | #if defined(CONFIG_KVM) |
| 3948 | if (kvm_allowed < 0) { |
| 3949 | kvm_allowed = kvm_check_allowed(); |
| 3950 | } |
| 3951 | #endif |
| 3952 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3953 | #if defined(CONFIG_KVM) && defined(CONFIG_KQEMU) |
| 3954 | if (kvm_allowed && kqemu_allowed) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3955 | PANIC( |
| 3956 | "You can not enable both KVM and kqemu at the same time"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3957 | } |
| 3958 | #endif |
| 3959 | |
| 3960 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
| 3961 | if (smp_cpus > machine->max_cpus) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3962 | PANIC("Number of SMP cpus requested (%d), exceeds max cpus " |
| 3963 | "supported by machine `%s' (%d)", smp_cpus, machine->name, |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3964 | machine->max_cpus); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | if (display_type == DT_NOGRAPHIC) { |
| 3968 | if (serial_device_index == 0) |
| 3969 | serial_devices[0] = "stdio"; |
| 3970 | if (parallel_device_index == 0) |
| 3971 | parallel_devices[0] = "null"; |
| 3972 | if (strncmp(monitor_device, "vc", 2) == 0) |
| 3973 | monitor_device = "stdio"; |
| 3974 | } |
| 3975 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3976 | #ifdef CONFIG_KQEMU |
| 3977 | if (smp_cpus > 1) |
| 3978 | kqemu_allowed = 0; |
| 3979 | #endif |
| 3980 | if (qemu_init_main_loop()) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3981 | PANIC("qemu_init_main_loop failed"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3982 | } |
David 'Digit' Turner | 0b01949 | 2011-03-01 14:02:42 +0100 | [diff] [blame] | 3983 | |
| 3984 | if (kernel_filename == NULL) { |
| 3985 | kernel_filename = android_hw->kernel_path; |
| 3986 | } |
| 3987 | if (initrd_filename == NULL) { |
| 3988 | initrd_filename = android_hw->disk_ramdisk_path; |
| 3989 | } |
| 3990 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3991 | linux_boot = (kernel_filename != NULL); |
| 3992 | net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF; |
| 3993 | |
| 3994 | if (!linux_boot && *kernel_cmdline != '\0') { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3995 | PANIC("-append only allowed with -kernel option"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | if (!linux_boot && initrd_filename != NULL) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 3999 | PANIC("-initrd only allowed with -kernel option"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | /* boot to floppy or the default cd if no hard disk defined yet */ |
| 4003 | if (!boot_devices[0]) { |
| 4004 | boot_devices = "cad"; |
| 4005 | } |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 4006 | os_set_line_buffering(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4007 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4008 | if (init_timer_alarm() < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4009 | PANIC("could not initialize alarm timer"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4010 | } |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 4011 | configure_icount(icount_option); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4012 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4013 | /* init network clients */ |
| 4014 | if (nb_net_clients == 0) { |
| 4015 | /* if no clients, we use a default config */ |
| 4016 | net_clients[nb_net_clients++] = "nic"; |
| 4017 | #ifdef CONFIG_SLIRP |
| 4018 | net_clients[nb_net_clients++] = "user"; |
| 4019 | #endif |
| 4020 | } |
| 4021 | |
| 4022 | for(i = 0;i < nb_net_clients; i++) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4023 | if (net_client_parse(net_clients[i]) < 0) { |
| 4024 | PANIC("Unable to parse net clients"); |
| 4025 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4026 | } |
| 4027 | net_client_check(); |
| 4028 | |
| 4029 | #ifdef TARGET_I386 |
| 4030 | /* XXX: this should be moved in the PC machine instantiation code */ |
| 4031 | if (net_boot != 0) { |
| 4032 | int netroms = 0; |
| 4033 | for (i = 0; i < nb_nics && i < 4; i++) { |
| 4034 | const char *model = nd_table[i].model; |
| 4035 | char buf[1024]; |
| 4036 | char *filename; |
| 4037 | if (net_boot & (1 << i)) { |
| 4038 | if (model == NULL) |
| 4039 | model = "ne2k_pci"; |
| 4040 | snprintf(buf, sizeof(buf), "pxe-%s.bin", model); |
| 4041 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, buf); |
| 4042 | if (filename && get_image_size(filename) > 0) { |
| 4043 | if (nb_option_roms >= MAX_OPTION_ROMS) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4044 | PANIC("Too many option ROMs"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4045 | } |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 4046 | option_rom[nb_option_roms] = g_strdup(buf); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4047 | nb_option_roms++; |
| 4048 | netroms++; |
| 4049 | } |
| 4050 | if (filename) { |
David 'Digit' Turner | aa8236d | 2014-01-10 17:02:29 +0100 | [diff] [blame] | 4051 | g_free(filename); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | if (netroms == 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4056 | PANIC("No valid PXE rom found for network device"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | #endif |
| 4060 | |
| 4061 | /* init the bluetooth world */ |
| 4062 | for (i = 0; i < nb_bt_opts; i++) |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4063 | if (bt_parse(bt_opts[i])) { |
| 4064 | PANIC("Unable to parse bluetooth options"); |
| 4065 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4066 | |
| 4067 | /* init the memory */ |
David 'Digit' Turner | 5377c5b | 2011-02-10 16:52:19 +0100 | [diff] [blame] | 4068 | if (ram_size == 0) { |
| 4069 | ram_size = android_hw->hw_ramSize * 1024LL * 1024; |
| 4070 | if (ram_size == 0) { |
| 4071 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; |
| 4072 | } |
| 4073 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4074 | |
Vladimir Chtchetkine | cf289fb | 2012-05-14 08:04:29 -0700 | [diff] [blame] | 4075 | /* Quite often (especially on older XP machines) attempts to allocate large |
| 4076 | * VM RAM is going to fail, and crash the emulator. Since it's failing deep |
| 4077 | * inside QEMU, it's not really possible to provide the user with a |
| 4078 | * meaningful explanation for the crash. So, lets see if QEMU is going to be |
| 4079 | * able to allocate requested amount of RAM, and if not, lets try to come up |
| 4080 | * with a recomendation. */ |
| 4081 | { |
| 4082 | ram_addr_t r_ram = ram_size; |
| 4083 | void* alloc_check = malloc(r_ram); |
| 4084 | while (alloc_check == NULL && r_ram > 1024 * 1024) { |
| 4085 | /* Make it 25% less */ |
| 4086 | r_ram -= r_ram / 4; |
| 4087 | alloc_check = malloc(r_ram); |
| 4088 | } |
| 4089 | if (alloc_check != NULL) { |
| 4090 | free(alloc_check); |
| 4091 | } |
| 4092 | if (r_ram != ram_size) { |
| 4093 | /* Requested RAM is too large. Report this, as well as calculated |
| 4094 | * recomendation. */ |
| 4095 | dwarning("Requested RAM size of %dMB is too large for your environment, and is reduced to %dMB.", |
| 4096 | (int)(ram_size / 1024 / 1024), (int)(r_ram / 1024 / 1024)); |
| 4097 | ram_size = r_ram; |
| 4098 | } |
| 4099 | } |
| 4100 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4101 | #ifdef CONFIG_KQEMU |
| 4102 | /* FIXME: This is a nasty hack because kqemu can't cope with dynamic |
| 4103 | guest ram allocation. It needs to go away. */ |
| 4104 | if (kqemu_allowed) { |
| 4105 | kqemu_phys_ram_size = ram_size + 8 * 1024 * 1024 + 4 * 1024 * 1024; |
| 4106 | kqemu_phys_ram_base = qemu_vmalloc(kqemu_phys_ram_size); |
| 4107 | if (!kqemu_phys_ram_base) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4108 | PANIC("Could not allocate physical memory"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4109 | } |
| 4110 | } |
| 4111 | #endif |
| 4112 | |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 4113 | #ifndef _WIN32 |
| 4114 | init_qemu_clear_logs_sig(); |
| 4115 | #endif |
| 4116 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4117 | /* init the dynamic translator */ |
| 4118 | cpu_exec_init_all(tb_size * 1024 * 1024); |
| 4119 | |
| 4120 | bdrv_init(); |
| 4121 | |
| 4122 | /* we always create the cdrom drive, even if no disk is there */ |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 4123 | #if 0 |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4124 | if (nb_drives_opt < MAX_DRIVES) |
| 4125 | drive_add(NULL, CDROM_ALIAS); |
| 4126 | |
| 4127 | /* we always create at least one floppy */ |
| 4128 | |
| 4129 | if (nb_drives_opt < MAX_DRIVES) |
| 4130 | drive_add(NULL, FD_ALIAS, 0); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4131 | /* we always create one sd slot, even if no card is in it */ |
| 4132 | |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 4133 | if (1) { |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4134 | drive_add(NULL, SD_ALIAS); |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 4135 | } |
| 4136 | #endif |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4137 | |
| 4138 | /* open the virtual block devices */ |
David 'Digit' Turner | cb42a1b | 2010-12-23 02:54:08 +0100 | [diff] [blame] | 4139 | if (snapshot) |
| 4140 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
| 4141 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0) |
| 4142 | exit(1); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4143 | |
David Turner | 6a9ef17 | 2010-09-09 22:54:36 +0200 | [diff] [blame] | 4144 | //register_savevm("timer", 0, 2, timer_save, timer_load, &timers_state); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4145 | register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL); |
| 4146 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4147 | /* must be after terminal init, SDL library changes signal handlers */ |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 4148 | os_setup_signal_handling(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4149 | |
| 4150 | /* Maintain compatibility with multiple stdio monitors */ |
| 4151 | if (!strcmp(monitor_device,"stdio")) { |
| 4152 | for (i = 0; i < MAX_SERIAL_PORTS; i++) { |
| 4153 | const char *devname = serial_devices[i]; |
| 4154 | if (devname && !strcmp(devname,"mon:stdio")) { |
| 4155 | monitor_device = NULL; |
| 4156 | break; |
| 4157 | } else if (devname && !strcmp(devname,"stdio")) { |
| 4158 | monitor_device = NULL; |
| 4159 | serial_devices[i] = "mon:stdio"; |
| 4160 | break; |
| 4161 | } |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | if (nb_numa_nodes > 0) { |
| 4166 | int i; |
| 4167 | |
| 4168 | if (nb_numa_nodes > smp_cpus) { |
| 4169 | nb_numa_nodes = smp_cpus; |
| 4170 | } |
| 4171 | |
| 4172 | /* If no memory size if given for any node, assume the default case |
| 4173 | * and distribute the available memory equally across all nodes |
| 4174 | */ |
| 4175 | for (i = 0; i < nb_numa_nodes; i++) { |
| 4176 | if (node_mem[i] != 0) |
| 4177 | break; |
| 4178 | } |
| 4179 | if (i == nb_numa_nodes) { |
| 4180 | uint64_t usedmem = 0; |
| 4181 | |
| 4182 | /* On Linux, the each node's border has to be 8MB aligned, |
| 4183 | * the final node gets the rest. |
| 4184 | */ |
| 4185 | for (i = 0; i < nb_numa_nodes - 1; i++) { |
| 4186 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); |
| 4187 | usedmem += node_mem[i]; |
| 4188 | } |
| 4189 | node_mem[i] = ram_size - usedmem; |
| 4190 | } |
| 4191 | |
| 4192 | for (i = 0; i < nb_numa_nodes; i++) { |
| 4193 | if (node_cpumask[i] != 0) |
| 4194 | break; |
| 4195 | } |
| 4196 | /* assigning the VCPUs round-robin is easier to implement, guest OSes |
| 4197 | * must cope with this anyway, because there are BIOSes out there in |
| 4198 | * real machines which also use this scheme. |
| 4199 | */ |
| 4200 | if (i == nb_numa_nodes) { |
| 4201 | for (i = 0; i < smp_cpus; i++) { |
| 4202 | node_cpumask[i % nb_numa_nodes] |= 1 << i; |
| 4203 | } |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | if (kvm_enabled()) { |
| 4208 | int ret; |
| 4209 | |
| 4210 | ret = kvm_init(smp_cpus); |
| 4211 | if (ret < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4212 | PANIC("failed to initialize KVM"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4213 | } |
| 4214 | } |
| 4215 | |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 4216 | #ifdef CONFIG_HAX |
| 4217 | if (!hax_disabled) |
| 4218 | { |
| 4219 | int ret; |
| 4220 | |
Jiang, Yunhong | 4a5a0ef | 2012-02-23 06:31:12 +0800 | [diff] [blame] | 4221 | hax_set_ramsize(ram_size); |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 4222 | ret = hax_init(smp_cpus); |
| 4223 | fprintf(stderr, "HAX is %s and emulator runs in %s mode\n", |
| 4224 | !ret ? "working" :"not working", !ret ? "fast virt" : "emulation"); |
| 4225 | } |
| 4226 | #endif |
| 4227 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4228 | if (monitor_device) { |
| 4229 | monitor_hd = qemu_chr_open("monitor", monitor_device, NULL); |
| 4230 | if (!monitor_hd) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4231 | PANIC("qemu: could not open monitor device '%s'", |
| 4232 | monitor_device); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4233 | } |
| 4234 | } |
| 4235 | |
| 4236 | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 4237 | serial_hds_add(serial_devices[i]); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { |
| 4241 | const char *devname = parallel_devices[i]; |
| 4242 | if (devname && strcmp(devname, "none")) { |
| 4243 | char label[32]; |
| 4244 | snprintf(label, sizeof(label), "parallel%d", i); |
| 4245 | parallel_hds[i] = qemu_chr_open(label, devname, NULL); |
| 4246 | if (!parallel_hds[i]) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4247 | PANIC("qemu: could not open parallel device '%s'", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4248 | devname); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { |
| 4254 | const char *devname = virtio_consoles[i]; |
| 4255 | if (devname && strcmp(devname, "none")) { |
| 4256 | char label[32]; |
| 4257 | snprintf(label, sizeof(label), "virtcon%d", i); |
| 4258 | virtcon_hds[i] = qemu_chr_open(label, devname, NULL); |
| 4259 | if (!virtcon_hds[i]) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4260 | PANIC("qemu: could not open virtio console '%s'", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4261 | devname); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4262 | } |
| 4263 | } |
| 4264 | } |
| 4265 | |
| 4266 | module_call_init(MODULE_INIT_DEVICE); |
| 4267 | |
| 4268 | |
| 4269 | #ifdef CONFIG_TRACE |
| 4270 | if (trace_filename) { |
| 4271 | trace_init(trace_filename); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4272 | fprintf(stderr, "-- When done tracing, exit the emulator. --\n"); |
| 4273 | } |
| 4274 | #endif |
| 4275 | |
David 'Digit' Turner | 2d238fd | 2011-03-25 10:34:47 +0100 | [diff] [blame] | 4276 | /* Check the CPU Architecture value */ |
| 4277 | #if defined(TARGET_ARM) |
| 4278 | if (strcmp(android_hw->hw_cpu_arch,"arm") != 0) { |
| 4279 | fprintf(stderr, "-- Invalid CPU architecture: %s, expected 'arm'\n", |
| 4280 | android_hw->hw_cpu_arch); |
| 4281 | exit(1); |
| 4282 | } |
Vladimir Chtchetkine | 33f89d0 | 2011-09-28 09:19:09 -0700 | [diff] [blame] | 4283 | #elif defined(TARGET_I386) |
David 'Digit' Turner | 2d238fd | 2011-03-25 10:34:47 +0100 | [diff] [blame] | 4284 | if (strcmp(android_hw->hw_cpu_arch,"x86") != 0) { |
| 4285 | fprintf(stderr, "-- Invalid CPU architecture: %s, expected 'x86'\n", |
| 4286 | android_hw->hw_cpu_arch); |
| 4287 | exit(1); |
| 4288 | } |
| 4289 | #endif |
| 4290 | |
| 4291 | /* Grab CPU model if provided in hardware.ini */ |
| 4292 | if ( !cpu_model |
| 4293 | && android_hw->hw_cpu_model |
| 4294 | && android_hw->hw_cpu_model[0] != '\0') |
| 4295 | { |
| 4296 | cpu_model = android_hw->hw_cpu_model; |
| 4297 | } |
| 4298 | |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 4299 | /* Combine kernel command line passed from the UI with parameters |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4300 | * collected during initialization. |
| 4301 | * |
| 4302 | * The order is the following: |
| 4303 | * - parameters from the hw configuration (kernel.parameters) |
| 4304 | * - additionnal parameters from options (e.g. -memcheck) |
| 4305 | * - the -append parameters. |
| 4306 | */ |
| 4307 | { |
| 4308 | const char* kernel_parameters; |
Vladimir Chtchetkine | 7fbf497 | 2010-08-11 15:30:32 -0700 | [diff] [blame] | 4309 | |
David 'Digit' Turner | 0b01949 | 2011-03-01 14:02:42 +0100 | [diff] [blame] | 4310 | if (android_hw->kernel_parameters) { |
David 'Digit' Turner | 62c7ae5 | 2011-03-08 15:46:53 +0100 | [diff] [blame] | 4311 | stralloc_add_c(kernel_params, ' '); |
David 'Digit' Turner | 0b01949 | 2011-03-01 14:02:42 +0100 | [diff] [blame] | 4312 | stralloc_add_str(kernel_params, android_hw->kernel_parameters); |
| 4313 | } |
| 4314 | |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4315 | /* If not empty, kernel_config always contains a leading space */ |
| 4316 | stralloc_append(kernel_params, kernel_config); |
| 4317 | |
| 4318 | if (*kernel_cmdline) { |
| 4319 | stralloc_add_c(kernel_params, ' '); |
| 4320 | stralloc_add_str(kernel_params, kernel_cmdline); |
| 4321 | } |
| 4322 | |
David 'Digit' Turner | 062dd6a | 2011-03-01 14:50:07 +0100 | [diff] [blame] | 4323 | /* Remove any leading/trailing spaces */ |
| 4324 | stralloc_strip(kernel_params); |
| 4325 | |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4326 | kernel_parameters = stralloc_cstr(kernel_params); |
| 4327 | VERBOSE_PRINT(init, "Kernel parameters: %s", kernel_parameters); |
| 4328 | |
| 4329 | machine->init(ram_size, |
| 4330 | boot_devices, |
| 4331 | kernel_filename, |
| 4332 | kernel_parameters, |
| 4333 | initrd_filename, |
| 4334 | cpu_model); |
| 4335 | |
Vladimir Chtchetkine | 8dd31e8 | 2012-02-15 17:16:04 -0800 | [diff] [blame] | 4336 | /* Initialize multi-touch emulation. */ |
Vladimir Chtchetkine | 863d101 | 2012-03-16 12:25:23 -0700 | [diff] [blame] | 4337 | if (androidHwConfig_isScreenMultiTouch(android_hw)) { |
Vladimir Chtchetkine | 8dd31e8 | 2012-02-15 17:16:04 -0800 | [diff] [blame] | 4338 | mts_port_create(NULL); |
| 4339 | } |
| 4340 | |
David 'Digit' Turner | 5f82411 | 2011-03-01 14:00:26 +0100 | [diff] [blame] | 4341 | stralloc_reset(kernel_params); |
| 4342 | stralloc_reset(kernel_config); |
| 4343 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4344 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4345 | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
| 4346 | for (i = 0; i < nb_numa_nodes; i++) { |
| 4347 | if (node_cpumask[i] & (1 << env->cpu_index)) { |
| 4348 | env->numa_node = i; |
| 4349 | } |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | current_machine = machine; |
| 4354 | |
David 'Digit' Turner | e2678e1 | 2014-01-16 15:56:43 +0100 | [diff] [blame] | 4355 | /* Set KVM's vcpu state to qemu's initial CPUOldState. */ |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4356 | if (kvm_enabled()) { |
| 4357 | int ret; |
| 4358 | |
| 4359 | ret = kvm_sync_vcpus(); |
| 4360 | if (ret < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4361 | PANIC("failed to initialize vcpus"); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4362 | } |
| 4363 | } |
| 4364 | |
Jun Nakajima | a381ef0 | 2011-12-17 19:13:25 -0800 | [diff] [blame] | 4365 | #ifdef CONFIG_HAX |
| 4366 | if (hax_enabled()) |
| 4367 | hax_sync_vcpus(); |
| 4368 | #endif |
| 4369 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4370 | /* init USB devices */ |
| 4371 | if (usb_enabled) { |
| 4372 | for(i = 0; i < usb_devices_index; i++) { |
| 4373 | if (usb_device_add(usb_devices[i], 0) < 0) { |
| 4374 | fprintf(stderr, "Warning: could not add USB device %s\n", |
| 4375 | usb_devices[i]); |
| 4376 | } |
| 4377 | } |
| 4378 | } |
| 4379 | |
Vladimir Chtchetkine | cf755ea | 2011-01-12 14:38:19 -0800 | [diff] [blame] | 4380 | /* just use the first displaystate for the moment */ |
David 'Digit' Turner | 94702b0 | 2011-01-20 02:46:33 +0100 | [diff] [blame] | 4381 | ds = get_displaystate(); |
Vladimir Chtchetkine | cf755ea | 2011-01-12 14:38:19 -0800 | [diff] [blame] | 4382 | |
David 'Digit' Turner | 2507cab | 2011-02-10 16:29:17 +0100 | [diff] [blame] | 4383 | /* Initialize display from the command line parameters. */ |
| 4384 | android_display_reset(ds, |
| 4385 | android_display_width, |
| 4386 | android_display_height, |
| 4387 | android_display_bpp); |
Vladimir Chtchetkine | dd50f7d | 2010-07-30 09:16:41 -0700 | [diff] [blame] | 4388 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4389 | if (display_type == DT_DEFAULT) { |
| 4390 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
| 4391 | display_type = DT_SDL; |
| 4392 | #else |
| 4393 | display_type = DT_VNC; |
| 4394 | vnc_display = "localhost:0,to=99"; |
| 4395 | show_vnc_port = 1; |
| 4396 | #endif |
| 4397 | } |
Vladimir Chtchetkine | d81e6d1 | 2010-06-15 16:46:32 -0700 | [diff] [blame] | 4398 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4399 | |
| 4400 | switch (display_type) { |
| 4401 | case DT_NOGRAPHIC: |
| 4402 | break; |
| 4403 | #if defined(CONFIG_CURSES) |
| 4404 | case DT_CURSES: |
| 4405 | curses_display_init(ds, full_screen); |
| 4406 | break; |
| 4407 | #endif |
Vladimir Chtchetkine | eb83825 | 2010-07-15 12:27:56 -0700 | [diff] [blame] | 4408 | #if defined(CONFIG_SDL) && !defined(CONFIG_STANDALONE_CORE) |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4409 | case DT_SDL: |
| 4410 | sdl_display_init(ds, full_screen, no_frame); |
| 4411 | break; |
| 4412 | #elif defined(CONFIG_COCOA) |
| 4413 | case DT_SDL: |
| 4414 | cocoa_display_init(ds, full_screen); |
| 4415 | break; |
Vladimir Chtchetkine | 72d83df | 2010-12-14 09:24:02 -0800 | [diff] [blame] | 4416 | #elif defined(CONFIG_STANDALONE_CORE) |
| 4417 | case DT_SDL: |
Vladimir Chtchetkine | e95660a | 2010-12-20 08:28:03 -0800 | [diff] [blame] | 4418 | coredisplay_init(ds); |
Vladimir Chtchetkine | 72d83df | 2010-12-14 09:24:02 -0800 | [diff] [blame] | 4419 | break; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4420 | #endif |
| 4421 | case DT_VNC: |
| 4422 | vnc_display_init(ds); |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4423 | if (vnc_display_open(ds, vnc_display) < 0) { |
| 4424 | PANIC("Unable to initialize VNC display"); |
| 4425 | } |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4426 | |
| 4427 | if (show_vnc_port) { |
| 4428 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); |
| 4429 | } |
| 4430 | break; |
| 4431 | default: |
| 4432 | break; |
| 4433 | } |
| 4434 | dpy_resize(ds); |
| 4435 | |
| 4436 | dcl = ds->listeners; |
| 4437 | while (dcl != NULL) { |
| 4438 | if (dcl->dpy_refresh != NULL) { |
David 'Digit' Turner | 5973c77 | 2011-05-10 07:06:00 +0200 | [diff] [blame] | 4439 | ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds); |
| 4440 | qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4441 | } |
| 4442 | dcl = dcl->next; |
| 4443 | } |
| 4444 | |
| 4445 | if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) { |
David 'Digit' Turner | 5973c77 | 2011-05-10 07:06:00 +0200 | [diff] [blame] | 4446 | nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL); |
| 4447 | qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock)); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
David 'Digit' Turner | 94702b0 | 2011-01-20 02:46:33 +0100 | [diff] [blame] | 4450 | text_consoles_set_display(ds); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4451 | qemu_chr_initial_reset(); |
| 4452 | |
| 4453 | if (monitor_device && monitor_hd) |
| 4454 | monitor_init(monitor_hd, MONITOR_USE_READLINE | MONITOR_IS_DEFAULT); |
| 4455 | |
| 4456 | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
| 4457 | const char *devname = serial_devices[i]; |
| 4458 | if (devname && strcmp(devname, "none")) { |
| 4459 | if (strstart(devname, "vc", 0)) |
| 4460 | qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i); |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { |
| 4465 | const char *devname = parallel_devices[i]; |
| 4466 | if (devname && strcmp(devname, "none")) { |
| 4467 | if (strstart(devname, "vc", 0)) |
| 4468 | qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { |
| 4473 | const char *devname = virtio_consoles[i]; |
| 4474 | if (virtcon_hds[i] && devname) { |
| 4475 | if (strstart(devname, "vc", 0)) |
| 4476 | qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i); |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4481 | PANIC("qemu: could not open gdbserver on device '%s'", |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4482 | gdbstub_dev); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4483 | } |
| 4484 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4485 | /* call android-specific setup function */ |
| 4486 | android_emulation_setup(); |
| 4487 | |
Vladimir Chtchetkine | 5758404 | 2011-01-20 16:15:30 -0800 | [diff] [blame] | 4488 | #if !defined(CONFIG_STANDALONE_CORE) |
| 4489 | // For the standalone emulator (UI+core in one executable) we need to |
| 4490 | // set the window title here. |
| 4491 | android_emulator_set_base_port(android_base_port); |
| 4492 | #endif |
| 4493 | |
Ot ten Thije | 871da2a | 2010-09-20 10:29:22 +0100 | [diff] [blame] | 4494 | if (loadvm) |
| 4495 | do_loadvm(cur_mon, loadvm); |
| 4496 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4497 | if (incoming) { |
| 4498 | autostart = 0; /* fixme how to deal with -daemonize */ |
| 4499 | qemu_start_incoming_migration(incoming); |
| 4500 | } |
| 4501 | |
| 4502 | if (autostart) |
| 4503 | vm_start(); |
| 4504 | |
David 'Digit' Turner | c1ac40a | 2011-06-01 16:12:04 +0200 | [diff] [blame] | 4505 | os_setup_post(); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4506 | |
Vladimir Chtchetkine | 7746af0 | 2010-10-07 05:40:39 -0700 | [diff] [blame] | 4507 | #ifdef CONFIG_ANDROID |
| 4508 | // This will notify the UI that the core is successfuly initialized |
| 4509 | android_core_init_completed(); |
| 4510 | #endif // CONFIG_ANDROID |
| 4511 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 4512 | main_loop(); |
| 4513 | quit_timers(); |
| 4514 | net_cleanup(); |
| 4515 | android_emulation_teardown(); |
| 4516 | return 0; |
| 4517 | } |
Vladimir Chtchetkine | eb83825 | 2010-07-15 12:27:56 -0700 | [diff] [blame] | 4518 | |
| 4519 | void |
| 4520 | android_emulation_teardown(void) |
| 4521 | { |
| 4522 | android_charmap_done(); |
| 4523 | } |