blob: 0271f9c29448c7691081e7c09e01bedfd363e71c [file] [log] [blame]
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001/*
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"
35#include "hw/pc.h"
36#include "hw/audiodev.h"
37#include "hw/isa.h"
38#include "hw/baum.h"
39#include "hw/goldfish_nand.h"
40#include "net.h"
41#include "console.h"
42#include "sysemu.h"
43#include "gdbstub.h"
44#include "qemu-timer.h"
45#include "qemu-char.h"
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +010046#include "blockdev.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070047#include "audio/audio.h"
48
49#include "qemu_file.h"
50#include "android/android.h"
51#include "charpipe.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070052#include "modem_driver.h"
53#include "android/gps.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070054#include "android/hw-kmsg.h"
David 'Digit' Turnerc0ac7332011-05-02 15:05:35 +020055#include "android/hw-pipe-net.h"
56#include "android/hw-qemud.h"
Vladimir Chtchetkineeb838252010-07-15 12:27:56 -070057#include "android/charmap.h"
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -070058#include "android/globals.h"
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -070059#include "android/utils/bufprint.h"
David 'Digit' Turner5f824112011-03-01 14:00:26 +010060#include "android/utils/debug.h"
David 'Digit' Turner48a3c662011-03-01 14:03:20 +010061#include "android/utils/filelock.h"
62#include "android/utils/path.h"
David 'Digit' Turner5f824112011-03-01 14:00:26 +010063#include "android/utils/stralloc.h"
David 'Digit' Turner40841b22011-03-01 14:04:00 +010064#include "android/utils/tempfile.h"
Vladimir Chtchetkine72d83df2010-12-14 09:24:02 -080065#include "android/display-core.h"
Vladimir Chtchetkine90c62352011-01-13 11:24:07 -080066#include "android/utils/timezone.h"
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +010067#include "android/snapshot.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070068#include "targphys.h"
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -070069#include "tcpdump.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070070
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -070071#ifdef CONFIG_MEMCHECK
72#include "memcheck/memcheck.h"
73#endif // CONFIG_MEMCHECK
74
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070075#include <unistd.h>
76#include <fcntl.h>
77#include <signal.h>
78#include <time.h>
79#include <errno.h>
80#include <sys/time.h>
81#include <zlib.h>
82
David 'Digit' Turner2c538c82010-05-10 16:48:20 -070083/* Needed early for CONFIG_BSD etc. */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070084#include "config-host.h"
85
86#ifndef _WIN32
87#include <libgen.h>
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -070088#include <sys/times.h>
89#include <sys/wait.h>
90#include <termios.h>
91#include <sys/mman.h>
92#include <sys/ioctl.h>
93#include <sys/resource.h>
94#include <sys/socket.h>
95#include <netinet/in.h>
96#include <net/if.h>
97#if defined(__NetBSD__)
98#include <net/if_tap.h>
99#endif
100#ifdef __linux__
101#include <linux/if_tun.h>
102#endif
103#include <arpa/inet.h>
104#include <dirent.h>
105#include <netdb.h>
106#include <sys/select.h>
David 'Digit' Turner2c538c82010-05-10 16:48:20 -0700107#ifdef CONFIG_BSD
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700108#include <sys/stat.h>
109#if defined(__FreeBSD__) || defined(__DragonFly__)
110#include <libutil.h>
111#else
112#include <util.h>
113#endif
114#elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
115#include <freebsd/stdlib.h>
116#else
117#ifdef __linux__
118#include <pty.h>
119#include <malloc.h>
120#include <linux/rtc.h>
121
122/* For the benefit of older linux systems which don't supply it,
123 we use a local copy of hpet.h. */
124/* #include <linux/hpet.h> */
125#include "hpet.h"
126
127#include <linux/ppdev.h>
128#include <linux/parport.h>
129#endif
130#ifdef __sun__
131#include <sys/stat.h>
132#include <sys/ethernet.h>
133#include <sys/sockio.h>
134#include <netinet/arp.h>
135#include <netinet/in.h>
136#include <netinet/in_systm.h>
137#include <netinet/ip.h>
138#include <netinet/ip_icmp.h> // must come after ip.h
139#include <netinet/udp.h>
140#include <netinet/tcp.h>
141#include <net/if.h>
142#include <syslog.h>
143#include <stropts.h>
144#endif
145#endif
146#endif
147
148#if defined(__OpenBSD__)
149#include <util.h>
150#endif
151
152#if defined(CONFIG_VDE)
153#include <libvdeplug.h>
154#endif
155
156#ifdef _WIN32
157#include <windows.h>
158#include <malloc.h>
159#include <sys/timeb.h>
160#include <mmsystem.h>
161#define getopt_long_only getopt_long
162#define memalign(align, size) malloc(size)
163#endif
164
David 'Digit' Turner23ca2ae2011-06-01 16:14:53 +0200165#include "cpus.h"
David 'Digit' Turnerae3098a2011-05-11 16:01:57 +0200166#include "arch_init.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700167
168#ifdef CONFIG_COCOA
David 'Digit' Turnerae3098a2011-05-11 16:01:57 +0200169int qemu_main(int argc, char **argv, char **envp);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700170#undef main
171#define main qemu_main
172#endif /* CONFIG_COCOA */
173
174#include "hw/hw.h"
175#include "hw/boards.h"
176#include "hw/usb.h"
177#include "hw/pcmcia.h"
178#include "hw/pc.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700179#include "hw/isa.h"
180#include "hw/baum.h"
181#include "hw/bt.h"
182#include "hw/watchdog.h"
183#include "hw/smbios.h"
184#include "hw/xen.h"
185#include "bt-host.h"
186#include "net.h"
187#include "monitor.h"
188#include "console.h"
189#include "sysemu.h"
190#include "gdbstub.h"
191#include "qemu-timer.h"
192#include "qemu-char.h"
193#include "cache-utils.h"
194#include "block.h"
195#include "dma.h"
196#include "audio/audio.h"
197#include "migration.h"
198#include "kvm.h"
David 'Digit' Turner36597752011-05-20 01:18:01 +0200199#ifdef CONFIG_KVM
200#include "kvm-android.h"
201#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700202#include "balloon.h"
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700203#include "android/hw-lcd.h"
204#include "android/boot-properties.h"
David 'Digit' Turnerca950592011-04-27 12:26:15 +0200205#include "android/hw-control.h"
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -0700206#include "android/core-init-utils.h"
David 'Digit' Turnerca29fbb2011-01-02 13:17:22 +0100207#include "android/audio-test.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700208
Vladimir Chtchetkineeb838252010-07-15 12:27:56 -0700209#ifdef CONFIG_STANDALONE_CORE
210/* Verbose value used by the standalone emulator core (without UI) */
211unsigned long android_verbose;
212#endif // CONFIG_STANDALONE_CORE
213
Vladimir Chtchetkine57584042011-01-20 16:15:30 -0800214#if !defined(CONFIG_STANDALONE_CORE)
215/* in android/qemulator.c */
216extern void android_emulator_set_base_port(int port);
217#endif
218
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -0700219#if defined(CONFIG_SKINS) && !defined(CONFIG_STANDALONE_CORE)
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700220#undef main
221#define main qemu_main
222#endif
223
224#include "disas.h"
225
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700226#ifdef CONFIG_TRACE
227#include "trace.h"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700228#endif
229
230#include "qemu_socket.h"
231
232#if defined(CONFIG_SLIRP)
233#include "libslirp.h"
234#endif
235
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700236
237
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700238#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' Turner5d8f37a2009-09-14 14:32:27 -0700247
248static const char *data_dir;
249const char *bios_name = NULL;
250static void *ioport_opaque[MAX_IOPORTS];
251static IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
252static IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +0100253#ifdef MAX_DRIVES
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700254/* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
255 to store the VM snapshots */
256DriveInfo drives_table[MAX_DRIVES+1];
257int nb_drives;
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +0100258#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700259enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700260DisplayType display_type = DT_DEFAULT;
261const char* keyboard_layout = NULL;
262int64_t ticks_per_sec;
263ram_addr_t ram_size;
264int nb_nics;
265NICInfo nd_table[MAX_NICS];
266int vm_running;
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +0100267int autostart;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700268static int rtc_utc = 1;
269static int rtc_date_offset = -1; /* -1 means no change */
270int cirrus_vga_enabled = 1;
271int std_vga_enabled = 0;
272int vmsvga_enabled = 0;
273int xenfb_enabled = 0;
David 'Digit' Turnera7fb77d2010-05-10 23:50:54 -0700274QEMUClock *rtc_clock;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700275static int full_screen = 0;
276#ifdef CONFIG_SDL
277static int no_frame = 0;
278#endif
279int no_quit = 0;
280CharDriverState *serial_hds[MAX_SERIAL_PORTS];
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +0100281int serial_hds_count;
282
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700283CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
284CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
285#ifdef TARGET_I386
286int win2k_install_hack = 0;
287int rtc_td_hack = 0;
288#endif
289int usb_enabled = 0;
290int singlestep = 0;
291int smp_cpus = 1;
292const char *vnc_display;
293int acpi_enabled = 1;
294int no_hpet = 0;
295int no_virtio_balloon = 0;
296int fd_bootchk = 1;
297int no_reboot = 0;
298int no_shutdown = 0;
299int cursor_hide = 1;
300int graphic_rotate = 0;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700301WatchdogTimerModel *watchdog = NULL;
302int watchdog_action = WDT_RESET;
303const char *option_rom[MAX_OPTION_ROMS];
304int nb_option_roms;
305int semihosting_enabled = 0;
306#ifdef TARGET_ARM
307int old_param = 0;
308#endif
309const char *qemu_name;
310int alt_grab = 0;
311#if defined(TARGET_SPARC) || defined(TARGET_PPC)
312unsigned int nb_prom_envs = 0;
313const char *prom_envs[MAX_PROM_ENVS];
314#endif
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +0100315#ifdef MAX_DRIVES
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700316int nb_drives_opt;
317struct drive_opt drives_opt[MAX_DRIVES];
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +0100318#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700319int nb_numa_nodes;
320uint64_t node_mem[MAX_NODES];
321uint64_t node_cpumask[MAX_NODES];
322
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700323static QEMUTimer *nographic_timer;
324
325uint8_t qemu_uuid[16];
326
327
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700328int qemu_cpu_delay;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700329extern char* audio_input_source;
330
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -0700331extern char* android_op_ports;
332extern char* android_op_port;
333extern char* android_op_report_console;
334extern char* op_http_proxy;
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -0700335// Path to the file containing specific key character map.
336char* op_charmap_file = NULL;
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -0700337
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -0700338/* Path to hardware initialization file passed with -android-hw option. */
339char* android_op_hwini = NULL;
340
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -0700341/* Memory checker options. */
342char* android_op_memcheck = NULL;
343
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -0700344/* -dns-server option value. */
345char* android_op_dns_server = NULL;
346
Vladimir Chtchetkine13f3b6c2010-08-25 09:49:25 -0700347/* -radio option value. */
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700348char* android_op_radio = NULL;
349
350/* -gps option value. */
351char* android_op_gps = NULL;
352
353/* -audio option value. */
354char* android_op_audio = NULL;
355
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -0700356/* -cpu-delay option value. */
357char* android_op_cpu_delay = NULL;
358
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -0700359#ifdef CONFIG_NAND_LIMITS
360/* -nand-limits option value. */
361char* android_op_nand_limits = NULL;
362#endif // CONFIG_NAND_LIMITS
363
364/* -netspeed option value. */
365char* android_op_netspeed = NULL;
366
367/* -netdelay option value. */
368char* android_op_netdelay = NULL;
369
370/* -netfast option value. */
371int android_op_netfast = 0;
372
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -0700373/* -tcpdump option value. */
374char* android_op_tcpdump = NULL;
375
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -0700376/* -lcd-density option value. */
377char* android_op_lcd_density = NULL;
378
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -0700379/* -ui-port option value. This port will be used to report the core
380 * initialization completion.
381 */
382char* android_op_ui_port = NULL;
383
384/* -ui-settings option value. This value will be passed to the UI when new UI
385 * process is attaching to the core.
386 */
387char* android_op_ui_settings = NULL;
388
Vladimir Chtchetkine90c62352011-01-13 11:24:07 -0800389/* -android-avdname option value. */
390char* android_op_avd_name = "unknown";
391
Vladimir Chtchetkinedd50f7d2010-07-30 09:16:41 -0700392extern int android_display_width;
393extern int android_display_height;
394extern int android_display_bpp;
395
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700396extern void dprint( const char* format, ... );
397
rich canningsd952f282011-03-01 15:40:09 -0800398const char* dns_log_filename = NULL;
399const char* drop_log_filename = NULL;
400static int rotate_logs_requested = 0;
401
Tim Baverstock24204cc2010-11-25 11:37:43 +0000402const char* savevm_on_exit = NULL;
Tim Baverstock24204cc2010-11-25 11:37:43 +0000403
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700404#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
405
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -0700406/* Reports the core initialization failure to the error stdout and to the UI
407 * socket before exiting the application.
408 * Parameters that are passed to this macro are used to format the error
409 * mesage using sprintf routine.
410 */
411#ifdef CONFIG_ANDROID
412#define PANIC(...) android_core_init_failure(__VA_ARGS__)
413#else
414#define PANIC(...) do { fprintf(stderr, __VA_ARGS__); \
415 exit(1); \
416 } while (0)
417#endif // CONFIG_ANDROID
418
419/* Exits the core during initialization. */
420#ifdef CONFIG_ANDROID
421#define QEMU_EXIT(exit_code) android_core_init_exit(exit_code)
422#else
423#define QEMU_EXIT(exit_code) exit(exit_code)
424#endif // CONFIG_ANDROID
425
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700426/***********************************************************/
427/* x86 ISA bus support */
428
429target_phys_addr_t isa_mem_base = 0;
430PicState2 *isa_pic;
431
432static IOPortReadFunc default_ioport_readb, default_ioport_readw, default_ioport_readl;
433static IOPortWriteFunc default_ioport_writeb, default_ioport_writew, default_ioport_writel;
434
435static uint32_t ioport_read(int index, uint32_t address)
436{
437 static IOPortReadFunc *default_func[3] = {
438 default_ioport_readb,
439 default_ioport_readw,
440 default_ioport_readl
441 };
442 IOPortReadFunc *func = ioport_read_table[index][address];
443 if (!func)
444 func = default_func[index];
445 return func(ioport_opaque[address], address);
446}
447
448static void ioport_write(int index, uint32_t address, uint32_t data)
449{
450 static IOPortWriteFunc *default_func[3] = {
451 default_ioport_writeb,
452 default_ioport_writew,
453 default_ioport_writel
454 };
455 IOPortWriteFunc *func = ioport_write_table[index][address];
456 if (!func)
457 func = default_func[index];
458 func(ioport_opaque[address], address, data);
459}
460
461static uint32_t default_ioport_readb(void *opaque, uint32_t address)
462{
463#ifdef DEBUG_UNUSED_IOPORT
464 fprintf(stderr, "unused inb: port=0x%04x\n", address);
465#endif
466 return 0xff;
467}
468
469static void default_ioport_writeb(void *opaque, uint32_t address, uint32_t data)
470{
471#ifdef DEBUG_UNUSED_IOPORT
472 fprintf(stderr, "unused outb: port=0x%04x data=0x%02x\n", address, data);
473#endif
474}
475
476/* default is to make two byte accesses */
477static uint32_t default_ioport_readw(void *opaque, uint32_t address)
478{
479 uint32_t data;
480 data = ioport_read(0, address);
481 address = (address + 1) & (MAX_IOPORTS - 1);
482 data |= ioport_read(0, address) << 8;
483 return data;
484}
485
486static void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
487{
488 ioport_write(0, address, data & 0xff);
489 address = (address + 1) & (MAX_IOPORTS - 1);
490 ioport_write(0, address, (data >> 8) & 0xff);
491}
492
493static uint32_t default_ioport_readl(void *opaque, uint32_t address)
494{
495#ifdef DEBUG_UNUSED_IOPORT
496 fprintf(stderr, "unused inl: port=0x%04x\n", address);
497#endif
498 return 0xffffffff;
499}
500
501static void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
502{
503#ifdef DEBUG_UNUSED_IOPORT
504 fprintf(stderr, "unused outl: port=0x%04x data=0x%02x\n", address, data);
505#endif
506}
507
rich canningsd952f282011-03-01 15:40:09 -0800508/*
509 * Sets a flag (rotate_logs_requested) to clear both the DNS and the
510 * drop logs upon receiving a SIGUSR1 signal. We need to clear the logs
511 * between the tasks that do not require restarting Qemu.
512 */
513void rotate_qemu_logs_handler(int signum) {
514 rotate_logs_requested = 1;
515}
516
517/*
518 * Resets the rotate_log_requested_flag. Normally called after qemu
519 * logs has been rotated.
520 */
521void reset_rotate_qemu_logs_request(void) {
522 rotate_logs_requested = 0;
523}
524
525/*
526 * Clears the passed qemu log when the rotate_logs_requested
527 * is set. We need to clear the logs between the tasks that do not
528 * require restarting Qemu.
529 */
530FILE* rotate_qemu_log(FILE* old_log_fd, const char* filename) {
531 FILE* new_log_fd = NULL;
532 if (old_log_fd) {
533 if (fclose(old_log_fd) == -1) {
534 fprintf(stderr, "Cannot close old_log fd\n");
535 exit(errno);
536 }
537 }
538
539 if (!filename) {
540 fprintf(stderr, "The log filename to be rotated is not provided");
541 exit(-1);
542 }
543
544 new_log_fd = fopen(filename , "wb+");
545 if (new_log_fd == NULL) {
546 fprintf(stderr, "Cannot open the log file: %s for write.\n",
547 filename);
548 exit(1);
549 }
550
551 return new_log_fd;
552}
553
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700554/***************/
555/* ballooning */
556
557static QEMUBalloonEvent *qemu_balloon_event;
558void *qemu_balloon_event_opaque;
559
560void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
561{
562 qemu_balloon_event = func;
563 qemu_balloon_event_opaque = opaque;
564}
565
566void qemu_balloon(ram_addr_t target)
567{
568 if (qemu_balloon_event)
569 qemu_balloon_event(qemu_balloon_event_opaque, target);
570}
571
572ram_addr_t qemu_balloon_status(void)
573{
574 if (qemu_balloon_event)
575 return qemu_balloon_event(qemu_balloon_event_opaque, 0);
576 return 0;
577}
578
579/***********************************************************/
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700580/* host time/date access */
581void qemu_get_timedate(struct tm *tm, int offset)
582{
583 time_t ti;
584 struct tm *ret;
585
586 time(&ti);
587 ti += offset;
588 if (rtc_date_offset == -1) {
589 if (rtc_utc)
590 ret = gmtime(&ti);
591 else
592 ret = localtime(&ti);
593 } else {
594 ti -= rtc_date_offset;
595 ret = gmtime(&ti);
596 }
597
598 memcpy(tm, ret, sizeof(struct tm));
599}
600
601int qemu_timedate_diff(struct tm *tm)
602{
603 time_t seconds;
604
605 if (rtc_date_offset == -1)
606 if (rtc_utc)
607 seconds = mktimegm(tm);
608 else
609 seconds = mktime(tm);
610 else
611 seconds = mktimegm(tm) + rtc_date_offset;
612
613 return seconds - time(NULL);
614}
615
616
617#ifdef CONFIG_TRACE
David 'Digit' Turner23ca2ae2011-06-01 16:14:53 +0200618int tbflush_requested;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700619static int exit_requested;
620
621void start_tracing()
622{
623 if (trace_filename == NULL)
624 return;
625 if (!tracing) {
626 fprintf(stderr,"-- start tracing --\n");
627 start_time = Now();
628 }
629 tracing = 1;
630 tbflush_requested = 1;
631 qemu_notify_event();
632}
633
634void stop_tracing()
635{
636 if (trace_filename == NULL)
637 return;
638 if (tracing) {
639 end_time = Now();
640 elapsed_usecs += end_time - start_time;
641 fprintf(stderr,"-- stop tracing --\n");
642 }
643 tracing = 0;
644 tbflush_requested = 1;
645 qemu_notify_event();
646}
647
648#ifndef _WIN32
649/* This is the handler for the SIGUSR1 and SIGUSR2 signals.
650 * SIGUSR1 turns tracing on. SIGUSR2 turns tracing off.
651 */
652void sigusr_handler(int sig)
653{
654 if (sig == SIGUSR1)
655 start_tracing();
656 else
657 stop_tracing();
658}
659#endif
660
661/* This is the handler to catch control-C so that we can exit cleanly.
662 * This is needed when tracing to flush the buffers to disk.
663 */
664void sigint_handler(int sig)
665{
666 exit_requested = 1;
667 qemu_notify_event();
668}
669#endif /* CONFIG_TRACE */
670
671
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700672/***********************************************************/
673/* Bluetooth support */
674static int nb_hcis;
675static int cur_hci;
676static struct HCIInfo *hci_table[MAX_NICS];
677
678static struct bt_vlan_s {
679 struct bt_scatternet_s net;
680 int id;
681 struct bt_vlan_s *next;
682} *first_bt_vlan;
683
684/* find or alloc a new bluetooth "VLAN" */
685static struct bt_scatternet_s *qemu_find_bt_vlan(int id)
686{
687 struct bt_vlan_s **pvlan, *vlan;
688 for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) {
689 if (vlan->id == id)
690 return &vlan->net;
691 }
692 vlan = qemu_mallocz(sizeof(struct bt_vlan_s));
693 vlan->id = id;
694 pvlan = &first_bt_vlan;
695 while (*pvlan != NULL)
696 pvlan = &(*pvlan)->next;
697 *pvlan = vlan;
698 return &vlan->net;
699}
700
701static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len)
702{
703}
704
705static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr)
706{
707 return -ENOTSUP;
708}
709
710static struct HCIInfo null_hci = {
711 .cmd_send = null_hci_send,
712 .sco_send = null_hci_send,
713 .acl_send = null_hci_send,
714 .bdaddr_set = null_hci_addr_set,
715};
716
717struct HCIInfo *qemu_next_hci(void)
718{
719 if (cur_hci == nb_hcis)
720 return &null_hci;
721
722 return hci_table[cur_hci++];
723}
724
725static struct HCIInfo *hci_init(const char *str)
726{
727 char *endp;
728 struct bt_scatternet_s *vlan = 0;
729
730 if (!strcmp(str, "null"))
731 /* null */
732 return &null_hci;
733 else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':'))
734 /* host[:hciN] */
735 return bt_host_hci(str[4] ? str + 5 : "hci0");
736 else if (!strncmp(str, "hci", 3)) {
737 /* hci[,vlan=n] */
738 if (str[3]) {
739 if (!strncmp(str + 3, ",vlan=", 6)) {
740 vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0));
741 if (*endp)
742 vlan = 0;
743 }
744 } else
745 vlan = qemu_find_bt_vlan(0);
746 if (vlan)
747 return bt_new_hci(vlan);
748 }
749
750 fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str);
751
752 return 0;
753}
754
755static int bt_hci_parse(const char *str)
756{
757 struct HCIInfo *hci;
758 bdaddr_t bdaddr;
759
760 if (nb_hcis >= MAX_NICS) {
761 fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS);
762 return -1;
763 }
764
765 hci = hci_init(str);
766 if (!hci)
767 return -1;
768
769 bdaddr.b[0] = 0x52;
770 bdaddr.b[1] = 0x54;
771 bdaddr.b[2] = 0x00;
772 bdaddr.b[3] = 0x12;
773 bdaddr.b[4] = 0x34;
774 bdaddr.b[5] = 0x56 + nb_hcis;
775 hci->bdaddr_set(hci, bdaddr.b);
776
777 hci_table[nb_hcis++] = hci;
778
779 return 0;
780}
781
782static void bt_vhci_add(int vlan_id)
783{
784 struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id);
785
786 if (!vlan->slave)
787 fprintf(stderr, "qemu: warning: adding a VHCI to "
788 "an empty scatternet %i\n", vlan_id);
789
790 bt_vhci_init(bt_new_hci(vlan));
791}
792
793static struct bt_device_s *bt_device_add(const char *opt)
794{
795 struct bt_scatternet_s *vlan;
796 int vlan_id = 0;
797 char *endp = strstr(opt, ",vlan=");
798 int len = (endp ? endp - opt : strlen(opt)) + 1;
799 char devname[10];
800
801 pstrcpy(devname, MIN(sizeof(devname), len), opt);
802
803 if (endp) {
804 vlan_id = strtol(endp + 6, &endp, 0);
805 if (*endp) {
806 fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n");
807 return 0;
808 }
809 }
810
811 vlan = qemu_find_bt_vlan(vlan_id);
812
813 if (!vlan->slave)
814 fprintf(stderr, "qemu: warning: adding a slave device to "
815 "an empty scatternet %i\n", vlan_id);
816
817 if (!strcmp(devname, "keyboard"))
818 return bt_keyboard_init(vlan);
819
820 fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname);
821 return 0;
822}
823
824static int bt_parse(const char *opt)
825{
826 const char *endp, *p;
827 int vlan;
828
829 if (strstart(opt, "hci", &endp)) {
830 if (!*endp || *endp == ',') {
831 if (*endp)
832 if (!strstart(endp, ",vlan=", 0))
833 opt = endp + 1;
834
835 return bt_hci_parse(opt);
836 }
837 } else if (strstart(opt, "vhci", &endp)) {
838 if (!*endp || *endp == ',') {
839 if (*endp) {
840 if (strstart(endp, ",vlan=", &p)) {
841 vlan = strtol(p, (char **) &endp, 0);
842 if (*endp) {
843 fprintf(stderr, "qemu: bad scatternet '%s'\n", p);
844 return 1;
845 }
846 } else {
847 fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1);
848 return 1;
849 }
850 } else
851 vlan = 0;
852
853 bt_vhci_add(vlan);
854 return 0;
855 }
856 } else if (strstart(opt, "device:", &endp))
857 return !bt_device_add(endp);
858
859 fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt);
860 return 1;
861}
862
863/***********************************************************/
864/* QEMU Block devices */
865
866#define HD_ALIAS "index=%d,media=disk"
867#define CDROM_ALIAS "index=2,media=cdrom"
868#define FD_ALIAS "index=%d,if=floppy"
869#define PFLASH_ALIAS "if=pflash"
870#define MTD_ALIAS "if=mtd"
871#define SD_ALIAS "index=0,if=sd"
872
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +0100873static int drive_init_func(QemuOpts *opts, void *opaque)
874{
875 int *use_scsi = opaque;
876 int fatal_error = 0;
877
878 if (drive_init(opts, *use_scsi, &fatal_error) == NULL) {
879 if (fatal_error)
880 return 1;
881 }
882 return 0;
883}
884
885static int drive_enable_snapshot(QemuOpts *opts, void *opaque)
886{
887 if (NULL == qemu_opt_get(opts, "snapshot")) {
888 qemu_opt_set(opts, "snapshot", "on");
889 }
890 return 0;
891}
892
893#ifdef MAX_DRIVES
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700894static int drive_opt_get_free_idx(void)
895{
896 int index;
897
898 for (index = 0; index < MAX_DRIVES; index++)
899 if (!drives_opt[index].used) {
900 drives_opt[index].used = 1;
901 return index;
902 }
903
904 return -1;
905}
906
907static int drive_get_free_idx(void)
908{
909 int index;
910
911 for (index = 0; index < MAX_DRIVES; index++)
912 if (!drives_table[index].used) {
913 drives_table[index].used = 1;
914 return index;
915 }
916
917 return -1;
918}
919
920int drive_add(const char *file, const char *fmt, ...)
921{
922 va_list ap;
923 int index = drive_opt_get_free_idx();
924
925 if (nb_drives_opt >= MAX_DRIVES || index == -1) {
926 fprintf(stderr, "qemu: too many drives\n");
927 return -1;
928 }
929
930 drives_opt[index].file = file;
931 va_start(ap, fmt);
932 vsnprintf(drives_opt[index].opt,
933 sizeof(drives_opt[0].opt), fmt, ap);
934 va_end(ap);
David 'Digit' Turner92568952010-04-15 15:04:16 -0700935
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -0700936 nb_drives_opt++;
937 return index;
938}
939
940void drive_remove(int index)
941{
942 drives_opt[index].used = 0;
943 nb_drives_opt--;
944}
945
946int drive_get_index(BlockInterfaceType type, int bus, int unit)
947{
948 int index;
949
950 /* seek interface, bus and unit */
951
952 for (index = 0; index < MAX_DRIVES; index++)
953 if (drives_table[index].type == type &&
954 drives_table[index].bus == bus &&
955 drives_table[index].unit == unit &&
956 drives_table[index].used)
957 return index;
958
959 return -1;
960}
961
962int drive_get_max_bus(BlockInterfaceType type)
963{
964 int max_bus;
965 int index;
966
967 max_bus = -1;
968 for (index = 0; index < nb_drives; index++) {
969 if(drives_table[index].type == type &&
970 drives_table[index].bus > max_bus)
971 max_bus = drives_table[index].bus;
972 }
973 return max_bus;
974}
975
976const char *drive_get_serial(BlockDriverState *bdrv)
977{
978 int index;
979
980 for (index = 0; index < nb_drives; index++)
981 if (drives_table[index].bdrv == bdrv)
982 return drives_table[index].serial;
983
984 return "\0";
985}
986
987BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv)
988{
989 int index;
990
991 for (index = 0; index < nb_drives; index++)
992 if (drives_table[index].bdrv == bdrv)
993 return drives_table[index].onerror;
994
995 return BLOCK_ERR_STOP_ENOSPC;
996}
997
998static void bdrv_format_print(void *opaque, const char *name)
999{
1000 fprintf(stderr, " %s", name);
1001}
1002
1003void drive_uninit(BlockDriverState *bdrv)
1004{
1005 int i;
1006
1007 for (i = 0; i < MAX_DRIVES; i++)
1008 if (drives_table[i].bdrv == bdrv) {
1009 drives_table[i].bdrv = NULL;
1010 drives_table[i].used = 0;
1011 drive_remove(drives_table[i].drive_opt_idx);
1012 nb_drives--;
1013 break;
1014 }
1015}
1016
1017int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
1018{
1019 char buf[128];
1020 char file[1024];
1021 char devname[128];
1022 char serial[21];
1023 const char *mediastr = "";
1024 BlockInterfaceType type;
1025 enum { MEDIA_DISK, MEDIA_CDROM } media;
1026 int bus_id, unit_id;
1027 int cyls, heads, secs, translation;
1028 BlockDriverState *bdrv;
1029 BlockDriver *drv = NULL;
1030 QEMUMachine *machine = opaque;
1031 int max_devs;
1032 int index;
1033 int cache;
1034 int bdrv_flags, onerror;
1035 int drives_table_idx;
1036 char *str = arg->opt;
1037 static const char * const params[] = { "bus", "unit", "if", "index",
1038 "cyls", "heads", "secs", "trans",
1039 "media", "snapshot", "file",
1040 "cache", "format", "serial", "werror",
1041 NULL };
1042
1043 if (check_params(buf, sizeof(buf), params, str) < 0) {
1044 fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n",
1045 buf, str);
1046 return -1;
1047 }
1048
1049 file[0] = 0;
1050 cyls = heads = secs = 0;
1051 bus_id = 0;
1052 unit_id = -1;
1053 translation = BIOS_ATA_TRANSLATION_AUTO;
1054 index = -1;
1055 cache = 3;
1056
1057 if (machine->use_scsi) {
1058 type = IF_SCSI;
1059 max_devs = MAX_SCSI_DEVS;
1060 pstrcpy(devname, sizeof(devname), "scsi");
1061 } else {
1062 type = IF_IDE;
1063 max_devs = MAX_IDE_DEVS;
1064 pstrcpy(devname, sizeof(devname), "ide");
1065 }
1066 media = MEDIA_DISK;
1067
1068 /* extract parameters */
1069
1070 if (get_param_value(buf, sizeof(buf), "bus", str)) {
1071 bus_id = strtol(buf, NULL, 0);
1072 if (bus_id < 0) {
1073 fprintf(stderr, "qemu: '%s' invalid bus id\n", str);
1074 return -1;
1075 }
1076 }
1077
1078 if (get_param_value(buf, sizeof(buf), "unit", str)) {
1079 unit_id = strtol(buf, NULL, 0);
1080 if (unit_id < 0) {
1081 fprintf(stderr, "qemu: '%s' invalid unit id\n", str);
1082 return -1;
1083 }
1084 }
1085
1086 if (get_param_value(buf, sizeof(buf), "if", str)) {
1087 pstrcpy(devname, sizeof(devname), buf);
1088 if (!strcmp(buf, "ide")) {
1089 type = IF_IDE;
1090 max_devs = MAX_IDE_DEVS;
1091 } else if (!strcmp(buf, "scsi")) {
1092 type = IF_SCSI;
1093 max_devs = MAX_SCSI_DEVS;
1094 } else if (!strcmp(buf, "floppy")) {
1095 type = IF_FLOPPY;
1096 max_devs = 0;
1097 } else if (!strcmp(buf, "pflash")) {
1098 type = IF_PFLASH;
1099 max_devs = 0;
1100 } else if (!strcmp(buf, "mtd")) {
1101 type = IF_MTD;
1102 max_devs = 0;
1103 } else if (!strcmp(buf, "sd")) {
1104 type = IF_SD;
1105 max_devs = 0;
1106 } else if (!strcmp(buf, "virtio")) {
1107 type = IF_VIRTIO;
1108 max_devs = 0;
1109 } else if (!strcmp(buf, "xen")) {
1110 type = IF_XEN;
1111 max_devs = 0;
1112 } else {
1113 fprintf(stderr, "qemu: '%s' unsupported bus type '%s'\n", str, buf);
1114 return -1;
1115 }
1116 }
1117
1118 if (get_param_value(buf, sizeof(buf), "index", str)) {
1119 index = strtol(buf, NULL, 0);
1120 if (index < 0) {
1121 fprintf(stderr, "qemu: '%s' invalid index\n", str);
1122 return -1;
1123 }
1124 }
1125
1126 if (get_param_value(buf, sizeof(buf), "cyls", str)) {
1127 cyls = strtol(buf, NULL, 0);
1128 }
1129
1130 if (get_param_value(buf, sizeof(buf), "heads", str)) {
1131 heads = strtol(buf, NULL, 0);
1132 }
1133
1134 if (get_param_value(buf, sizeof(buf), "secs", str)) {
1135 secs = strtol(buf, NULL, 0);
1136 }
1137
1138 if (cyls || heads || secs) {
1139 if (cyls < 1 || cyls > 16383) {
1140 fprintf(stderr, "qemu: '%s' invalid physical cyls number\n", str);
1141 return -1;
1142 }
1143 if (heads < 1 || heads > 16) {
1144 fprintf(stderr, "qemu: '%s' invalid physical heads number\n", str);
1145 return -1;
1146 }
1147 if (secs < 1 || secs > 63) {
1148 fprintf(stderr, "qemu: '%s' invalid physical secs number\n", str);
1149 return -1;
1150 }
1151 }
1152
1153 if (get_param_value(buf, sizeof(buf), "trans", str)) {
1154 if (!cyls) {
1155 fprintf(stderr,
1156 "qemu: '%s' trans must be used with cyls,heads and secs\n",
1157 str);
1158 return -1;
1159 }
1160 if (!strcmp(buf, "none"))
1161 translation = BIOS_ATA_TRANSLATION_NONE;
1162 else if (!strcmp(buf, "lba"))
1163 translation = BIOS_ATA_TRANSLATION_LBA;
1164 else if (!strcmp(buf, "auto"))
1165 translation = BIOS_ATA_TRANSLATION_AUTO;
1166 else {
1167 fprintf(stderr, "qemu: '%s' invalid translation type\n", str);
1168 return -1;
1169 }
1170 }
1171
1172 if (get_param_value(buf, sizeof(buf), "media", str)) {
1173 if (!strcmp(buf, "disk")) {
1174 media = MEDIA_DISK;
1175 } else if (!strcmp(buf, "cdrom")) {
1176 if (cyls || secs || heads) {
1177 fprintf(stderr,
1178 "qemu: '%s' invalid physical CHS format\n", str);
1179 return -1;
1180 }
1181 media = MEDIA_CDROM;
1182 } else {
1183 fprintf(stderr, "qemu: '%s' invalid media\n", str);
1184 return -1;
1185 }
1186 }
1187
1188 if (get_param_value(buf, sizeof(buf), "snapshot", str)) {
1189 if (!strcmp(buf, "on"))
1190 snapshot = 1;
1191 else if (!strcmp(buf, "off"))
1192 snapshot = 0;
1193 else {
1194 fprintf(stderr, "qemu: '%s' invalid snapshot option\n", str);
1195 return -1;
1196 }
1197 }
1198
1199 if (get_param_value(buf, sizeof(buf), "cache", str)) {
1200 if (!strcmp(buf, "off") || !strcmp(buf, "none"))
1201 cache = 0;
1202 else if (!strcmp(buf, "writethrough"))
1203 cache = 1;
1204 else if (!strcmp(buf, "writeback"))
1205 cache = 2;
1206 else {
1207 fprintf(stderr, "qemu: invalid cache option\n");
1208 return -1;
1209 }
1210 }
1211
1212 if (get_param_value(buf, sizeof(buf), "format", str)) {
1213 if (strcmp(buf, "?") == 0) {
1214 fprintf(stderr, "qemu: Supported formats:");
1215 bdrv_iterate_format(bdrv_format_print, NULL);
1216 fprintf(stderr, "\n");
1217 return -1;
1218 }
1219 drv = bdrv_find_format(buf);
1220 if (!drv) {
1221 fprintf(stderr, "qemu: '%s' invalid format\n", buf);
1222 return -1;
1223 }
1224 }
1225
1226 if (arg->file == NULL)
1227 get_param_value(file, sizeof(file), "file", str);
1228 else
1229 pstrcpy(file, sizeof(file), arg->file);
1230
1231 if (!get_param_value(serial, sizeof(serial), "serial", str))
1232 memset(serial, 0, sizeof(serial));
1233
1234 onerror = BLOCK_ERR_STOP_ENOSPC;
1235 if (get_param_value(buf, sizeof(serial), "werror", str)) {
1236 if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) {
1237 fprintf(stderr, "werror is no supported by this format\n");
1238 return -1;
1239 }
1240 if (!strcmp(buf, "ignore"))
1241 onerror = BLOCK_ERR_IGNORE;
1242 else if (!strcmp(buf, "enospc"))
1243 onerror = BLOCK_ERR_STOP_ENOSPC;
1244 else if (!strcmp(buf, "stop"))
1245 onerror = BLOCK_ERR_STOP_ANY;
1246 else if (!strcmp(buf, "report"))
1247 onerror = BLOCK_ERR_REPORT;
1248 else {
1249 fprintf(stderr, "qemu: '%s' invalid write error action\n", buf);
1250 return -1;
1251 }
1252 }
1253
1254 /* compute bus and unit according index */
1255
1256 if (index != -1) {
1257 if (bus_id != 0 || unit_id != -1) {
1258 fprintf(stderr,
1259 "qemu: '%s' index cannot be used with bus and unit\n", str);
1260 return -1;
1261 }
1262 if (max_devs == 0)
1263 {
1264 unit_id = index;
1265 bus_id = 0;
1266 } else {
1267 unit_id = index % max_devs;
1268 bus_id = index / max_devs;
1269 }
1270 }
1271
1272 /* if user doesn't specify a unit_id,
1273 * try to find the first free
1274 */
1275
1276 if (unit_id == -1) {
1277 unit_id = 0;
1278 while (drive_get_index(type, bus_id, unit_id) != -1) {
1279 unit_id++;
1280 if (max_devs && unit_id >= max_devs) {
1281 unit_id -= max_devs;
1282 bus_id++;
1283 }
1284 }
1285 }
1286
1287 /* check unit id */
1288
1289 if (max_devs && unit_id >= max_devs) {
1290 fprintf(stderr, "qemu: '%s' unit %d too big (max is %d)\n",
1291 str, unit_id, max_devs - 1);
1292 return -1;
1293 }
1294
1295 /*
1296 * ignore multiple definitions
1297 */
1298
1299 if (drive_get_index(type, bus_id, unit_id) != -1)
1300 return -2;
1301
1302 /* init */
1303
1304 if (type == IF_IDE || type == IF_SCSI)
1305 mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
1306 if (max_devs)
1307 snprintf(buf, sizeof(buf), "%s%i%s%i",
1308 devname, bus_id, mediastr, unit_id);
1309 else
1310 snprintf(buf, sizeof(buf), "%s%s%i",
1311 devname, mediastr, unit_id);
1312 bdrv = bdrv_new(buf);
1313 drives_table_idx = drive_get_free_idx();
1314 drives_table[drives_table_idx].bdrv = bdrv;
1315 drives_table[drives_table_idx].type = type;
1316 drives_table[drives_table_idx].bus = bus_id;
1317 drives_table[drives_table_idx].unit = unit_id;
1318 drives_table[drives_table_idx].onerror = onerror;
1319 drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt;
1320 strncpy(drives_table[drives_table_idx].serial, serial, sizeof(serial));
1321 nb_drives++;
1322
1323 switch(type) {
1324 case IF_IDE:
1325 case IF_SCSI:
1326 case IF_XEN:
1327 switch(media) {
1328 case MEDIA_DISK:
1329 if (cyls != 0) {
1330 bdrv_set_geometry_hint(bdrv, cyls, heads, secs);
1331 bdrv_set_translation_hint(bdrv, translation);
1332 }
1333 break;
1334 case MEDIA_CDROM:
1335 bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM);
1336 break;
1337 }
1338 break;
1339 case IF_SD:
1340 /* FIXME: This isn't really a floppy, but it's a reasonable
1341 approximation. */
1342 case IF_FLOPPY:
1343 bdrv_set_type_hint(bdrv, BDRV_TYPE_FLOPPY);
1344 break;
1345 case IF_PFLASH:
1346 case IF_MTD:
1347 case IF_VIRTIO:
1348 break;
1349 case IF_COUNT:
David 'Digit' Turnerc34e8dc2010-09-13 02:47:01 -07001350 case IF_NONE:
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001351 abort();
1352 }
1353 if (!file[0])
1354 return -2;
1355 bdrv_flags = 0;
1356 if (snapshot) {
1357 bdrv_flags |= BDRV_O_SNAPSHOT;
1358 cache = 2; /* always use write-back with snapshot */
1359 }
1360 if (cache == 0) /* no caching */
1361 bdrv_flags |= BDRV_O_NOCACHE;
1362 else if (cache == 2) /* write-back */
1363 bdrv_flags |= BDRV_O_CACHE_WB;
1364 else if (cache == 3) /* not specified */
1365 bdrv_flags |= BDRV_O_CACHE_DEF;
1366 if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
1367 fprintf(stderr, "qemu: could not open disk image %s\n",
1368 file);
1369 return -1;
1370 }
1371 if (bdrv_key_required(bdrv))
1372 autostart = 0;
1373 return drives_table_idx;
1374}
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01001375#endif /* MAX_DRIVES */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001376
1377static void numa_add(const char *optarg)
1378{
1379 char option[128];
1380 char *endptr;
1381 unsigned long long value, endvalue;
1382 int nodenr;
1383
1384 optarg = get_opt_name(option, 128, optarg, ',') + 1;
1385 if (!strcmp(option, "node")) {
1386 if (get_param_value(option, 128, "nodeid", optarg) == 0) {
1387 nodenr = nb_numa_nodes;
1388 } else {
1389 nodenr = strtoull(option, NULL, 10);
1390 }
1391
1392 if (get_param_value(option, 128, "mem", optarg) == 0) {
1393 node_mem[nodenr] = 0;
1394 } else {
1395 value = strtoull(option, &endptr, 0);
1396 switch (*endptr) {
1397 case 0: case 'M': case 'm':
1398 value <<= 20;
1399 break;
1400 case 'G': case 'g':
1401 value <<= 30;
1402 break;
1403 }
1404 node_mem[nodenr] = value;
1405 }
1406 if (get_param_value(option, 128, "cpus", optarg) == 0) {
1407 node_cpumask[nodenr] = 0;
1408 } else {
1409 value = strtoull(option, &endptr, 10);
1410 if (value >= 64) {
1411 value = 63;
1412 fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n");
1413 } else {
1414 if (*endptr == '-') {
1415 endvalue = strtoull(endptr+1, &endptr, 10);
1416 if (endvalue >= 63) {
1417 endvalue = 62;
1418 fprintf(stderr,
1419 "only 63 CPUs in NUMA mode supported.\n");
1420 }
1421 value = (1 << (endvalue + 1)) - (1 << value);
1422 } else {
1423 value = 1 << value;
1424 }
1425 }
1426 node_cpumask[nodenr] = value;
1427 }
1428 nb_numa_nodes++;
1429 }
1430 return;
1431}
1432
1433/***********************************************************/
1434/* USB devices */
1435
1436static USBPort *used_usb_ports;
1437static USBPort *free_usb_ports;
1438
1439/* ??? Maybe change this to register a hub to keep track of the topology. */
1440void qemu_register_usb_port(USBPort *port, void *opaque, int index,
1441 usb_attachfn attach)
1442{
1443 port->opaque = opaque;
1444 port->index = index;
1445 port->attach = attach;
1446 port->next = free_usb_ports;
1447 free_usb_ports = port;
1448}
1449
1450int usb_device_add_dev(USBDevice *dev)
1451{
1452 USBPort *port;
1453
1454 /* Find a USB port to add the device to. */
1455 port = free_usb_ports;
1456 if (!port->next) {
1457 USBDevice *hub;
1458
1459 /* Create a new hub and chain it on. */
1460 free_usb_ports = NULL;
1461 port->next = used_usb_ports;
1462 used_usb_ports = port;
1463
1464 hub = usb_hub_init(VM_USB_HUB_SIZE);
1465 usb_attach(port, hub);
1466 port = free_usb_ports;
1467 }
1468
1469 free_usb_ports = port->next;
1470 port->next = used_usb_ports;
1471 used_usb_ports = port;
1472 usb_attach(port, dev);
1473 return 0;
1474}
1475
David 'Digit' Turner3266b512010-05-10 18:44:56 -07001476#if 0
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001477static void usb_msd_password_cb(void *opaque, int err)
1478{
1479 USBDevice *dev = opaque;
1480
1481 if (!err)
1482 usb_device_add_dev(dev);
1483 else
1484 dev->handle_destroy(dev);
1485}
David 'Digit' Turner3266b512010-05-10 18:44:56 -07001486#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001487
1488static int usb_device_add(const char *devname, int is_hotplug)
1489{
1490 const char *p;
1491 USBDevice *dev;
1492
1493 if (!free_usb_ports)
1494 return -1;
1495
1496 if (strstart(devname, "host:", &p)) {
1497 dev = usb_host_device_open(p);
1498 } else if (!strcmp(devname, "mouse")) {
1499 dev = usb_mouse_init();
1500 } else if (!strcmp(devname, "tablet")) {
1501 dev = usb_tablet_init();
1502 } else if (!strcmp(devname, "keyboard")) {
1503 dev = usb_keyboard_init();
1504 } else if (strstart(devname, "disk:", &p)) {
1505#if 0
1506 BlockDriverState *bs;
1507#endif
1508 dev = usb_msd_init(p);
1509 if (!dev)
1510 return -1;
1511#if 0
1512 bs = usb_msd_get_bdrv(dev);
1513 if (bdrv_key_required(bs)) {
1514 autostart = 0;
1515 if (is_hotplug) {
1516 monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb,
1517 dev);
1518 return 0;
1519 }
1520 }
1521 } else if (!strcmp(devname, "wacom-tablet")) {
1522 dev = usb_wacom_init();
1523 } else if (strstart(devname, "serial:", &p)) {
1524 dev = usb_serial_init(p);
1525#ifdef CONFIG_BRLAPI
1526 } else if (!strcmp(devname, "braille")) {
1527 dev = usb_baum_init();
1528#endif
1529 } else if (strstart(devname, "net:", &p)) {
1530 int nic = nb_nics;
1531
1532 if (net_client_init("nic", p) < 0)
1533 return -1;
1534 nd_table[nic].model = "usb";
1535 dev = usb_net_init(&nd_table[nic]);
1536 } else if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
1537 dev = usb_bt_init(devname[2] ? hci_init(p) :
1538 bt_new_hci(qemu_find_bt_vlan(0)));
1539#endif
1540 } else {
1541 return -1;
1542 }
1543 if (!dev)
1544 return -1;
1545
1546 return usb_device_add_dev(dev);
1547}
1548
1549int usb_device_del_addr(int bus_num, int addr)
1550{
1551 USBPort *port;
1552 USBPort **lastp;
1553 USBDevice *dev;
1554
1555 if (!used_usb_ports)
1556 return -1;
1557
1558 if (bus_num != 0)
1559 return -1;
1560
1561 lastp = &used_usb_ports;
1562 port = used_usb_ports;
1563 while (port && port->dev->addr != addr) {
1564 lastp = &port->next;
1565 port = port->next;
1566 }
1567
1568 if (!port)
1569 return -1;
1570
1571 dev = port->dev;
1572 *lastp = port->next;
1573 usb_attach(port, NULL);
1574 dev->handle_destroy(dev);
1575 port->next = free_usb_ports;
1576 free_usb_ports = port;
1577 return 0;
1578}
1579
1580static int usb_device_del(const char *devname)
1581{
1582 int bus_num, addr;
1583 const char *p;
1584
1585 if (strstart(devname, "host:", &p))
1586 return usb_host_device_close(p);
1587
1588 if (!used_usb_ports)
1589 return -1;
1590
1591 p = strchr(devname, '.');
1592 if (!p)
1593 return -1;
1594 bus_num = strtoul(devname, NULL, 0);
1595 addr = strtoul(p + 1, NULL, 0);
1596
1597 return usb_device_del_addr(bus_num, addr);
1598}
1599
1600void do_usb_add(Monitor *mon, const char *devname)
1601{
1602 usb_device_add(devname, 1);
1603}
1604
1605void do_usb_del(Monitor *mon, const char *devname)
1606{
1607 usb_device_del(devname);
1608}
1609
1610void usb_info(Monitor *mon)
1611{
1612 USBDevice *dev;
1613 USBPort *port;
1614 const char *speed_str;
1615
1616 if (!usb_enabled) {
1617 monitor_printf(mon, "USB support not enabled\n");
1618 return;
1619 }
1620
1621 for (port = used_usb_ports; port; port = port->next) {
1622 dev = port->dev;
1623 if (!dev)
1624 continue;
1625 switch(dev->speed) {
1626 case USB_SPEED_LOW:
1627 speed_str = "1.5";
1628 break;
1629 case USB_SPEED_FULL:
1630 speed_str = "12";
1631 break;
1632 case USB_SPEED_HIGH:
1633 speed_str = "480";
1634 break;
1635 default:
1636 speed_str = "?";
1637 break;
1638 }
1639 monitor_printf(mon, " Device %d.%d, Speed %s Mb/s, Product %s\n",
1640 0, dev->addr, speed_str, dev->devname);
1641 }
1642}
1643
1644/***********************************************************/
1645/* PCMCIA/Cardbus */
1646
1647static struct pcmcia_socket_entry_s {
1648 PCMCIASocket *socket;
1649 struct pcmcia_socket_entry_s *next;
1650} *pcmcia_sockets = 0;
1651
1652void pcmcia_socket_register(PCMCIASocket *socket)
1653{
1654 struct pcmcia_socket_entry_s *entry;
1655
1656 entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s));
1657 entry->socket = socket;
1658 entry->next = pcmcia_sockets;
1659 pcmcia_sockets = entry;
1660}
1661
1662void pcmcia_socket_unregister(PCMCIASocket *socket)
1663{
1664 struct pcmcia_socket_entry_s *entry, **ptr;
1665
1666 ptr = &pcmcia_sockets;
1667 for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr)
1668 if (entry->socket == socket) {
1669 *ptr = entry->next;
1670 qemu_free(entry);
1671 }
1672}
1673
1674void pcmcia_info(Monitor *mon)
1675{
1676 struct pcmcia_socket_entry_s *iter;
1677
1678 if (!pcmcia_sockets)
1679 monitor_printf(mon, "No PCMCIA sockets\n");
1680
1681 for (iter = pcmcia_sockets; iter; iter = iter->next)
1682 monitor_printf(mon, "%s: %s\n", iter->socket->slot_string,
1683 iter->socket->attached ? iter->socket->card_string :
1684 "Empty");
1685}
1686
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001687/***********************************************************/
1688/* ram save/restore */
1689
1690static int ram_get_page(QEMUFile *f, uint8_t *buf, int len)
1691{
1692 int v;
1693
1694 v = qemu_get_byte(f);
1695 switch(v) {
1696 case 0:
1697 if (qemu_get_buffer(f, buf, len) != len)
1698 return -EIO;
1699 break;
1700 case 1:
1701 v = qemu_get_byte(f);
1702 memset(buf, v, len);
1703 break;
1704 default:
1705 return -EINVAL;
1706 }
1707
1708 if (qemu_file_has_error(f))
1709 return -EIO;
1710
1711 return 0;
1712}
1713
1714static int ram_load_v1(QEMUFile *f, void *opaque)
1715{
1716 int ret;
1717 ram_addr_t i;
1718
1719 if (qemu_get_be32(f) != last_ram_offset)
1720 return -EINVAL;
1721 for(i = 0; i < last_ram_offset; i+= TARGET_PAGE_SIZE) {
1722 ret = ram_get_page(f, qemu_get_ram_ptr(i), TARGET_PAGE_SIZE);
1723 if (ret)
1724 return ret;
1725 }
1726 return 0;
1727}
1728
1729#define BDRV_HASH_BLOCK_SIZE 1024
1730#define IOBUF_SIZE 4096
1731#define RAM_CBLOCK_MAGIC 0xfabe
1732
1733typedef struct RamDecompressState {
1734 z_stream zstream;
1735 QEMUFile *f;
1736 uint8_t buf[IOBUF_SIZE];
1737} RamDecompressState;
1738
1739static int ram_decompress_open(RamDecompressState *s, QEMUFile *f)
1740{
1741 int ret;
1742 memset(s, 0, sizeof(*s));
1743 s->f = f;
1744 ret = inflateInit(&s->zstream);
1745 if (ret != Z_OK)
1746 return -1;
1747 return 0;
1748}
1749
1750static int ram_decompress_buf(RamDecompressState *s, uint8_t *buf, int len)
1751{
1752 int ret, clen;
1753
1754 s->zstream.avail_out = len;
1755 s->zstream.next_out = buf;
1756 while (s->zstream.avail_out > 0) {
1757 if (s->zstream.avail_in == 0) {
1758 if (qemu_get_be16(s->f) != RAM_CBLOCK_MAGIC)
1759 return -1;
1760 clen = qemu_get_be16(s->f);
1761 if (clen > IOBUF_SIZE)
1762 return -1;
1763 qemu_get_buffer(s->f, s->buf, clen);
1764 s->zstream.avail_in = clen;
1765 s->zstream.next_in = s->buf;
1766 }
1767 ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
1768 if (ret != Z_OK && ret != Z_STREAM_END) {
1769 return -1;
1770 }
1771 }
1772 return 0;
1773}
1774
1775static void ram_decompress_close(RamDecompressState *s)
1776{
1777 inflateEnd(&s->zstream);
1778}
1779
1780#define RAM_SAVE_FLAG_FULL 0x01
1781#define RAM_SAVE_FLAG_COMPRESS 0x02
1782#define RAM_SAVE_FLAG_MEM_SIZE 0x04
1783#define RAM_SAVE_FLAG_PAGE 0x08
1784#define RAM_SAVE_FLAG_EOS 0x10
1785
1786static int is_dup_page(uint8_t *page, uint8_t ch)
1787{
1788 uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
1789 uint32_t *array = (uint32_t *)page;
1790 int i;
1791
1792 for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
1793 if (array[i] != val)
1794 return 0;
1795 }
1796
1797 return 1;
1798}
1799
1800static int ram_save_block(QEMUFile *f)
1801{
1802 static ram_addr_t current_addr = 0;
1803 ram_addr_t saved_addr = current_addr;
1804 ram_addr_t addr = 0;
1805 int found = 0;
1806
1807 while (addr < last_ram_offset) {
1808 if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) {
1809 uint8_t *p;
1810
1811 cpu_physical_memory_reset_dirty(current_addr,
1812 current_addr + TARGET_PAGE_SIZE,
1813 MIGRATION_DIRTY_FLAG);
1814
1815 p = qemu_get_ram_ptr(current_addr);
1816
1817 if (is_dup_page(p, *p)) {
1818 qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_COMPRESS);
1819 qemu_put_byte(f, *p);
1820 } else {
1821 qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_PAGE);
1822 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
1823 }
1824
1825 found = 1;
1826 break;
1827 }
1828 addr += TARGET_PAGE_SIZE;
1829 current_addr = (saved_addr + addr) % last_ram_offset;
1830 }
1831
1832 return found;
1833}
1834
1835static uint64_t bytes_transferred = 0;
1836
1837static ram_addr_t ram_save_remaining(void)
1838{
1839 ram_addr_t addr;
1840 ram_addr_t count = 0;
1841
1842 for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) {
1843 if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG))
1844 count++;
1845 }
1846
1847 return count;
1848}
1849
1850uint64_t ram_bytes_remaining(void)
1851{
1852 return ram_save_remaining() * TARGET_PAGE_SIZE;
1853}
1854
1855uint64_t ram_bytes_transferred(void)
1856{
1857 return bytes_transferred;
1858}
1859
1860uint64_t ram_bytes_total(void)
1861{
1862 return last_ram_offset;
1863}
1864
1865static int ram_save_live(QEMUFile *f, int stage, void *opaque)
1866{
1867 ram_addr_t addr;
1868 uint64_t bytes_transferred_last;
1869 double bwidth = 0;
1870 uint64_t expected_time = 0;
1871
1872 cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX);
1873
1874 if (stage == 1) {
David 'Digit' Turnerae3098a2011-05-11 16:01:57 +02001875 bytes_transferred = 0;
1876
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001877 /* Make sure all dirty bits are set */
1878 for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) {
1879 if (!cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG))
1880 cpu_physical_memory_set_dirty(addr);
1881 }
1882
1883 /* Enable dirty memory tracking */
1884 cpu_physical_memory_set_dirty_tracking(1);
1885
1886 qemu_put_be64(f, last_ram_offset | RAM_SAVE_FLAG_MEM_SIZE);
1887 }
1888
1889 bytes_transferred_last = bytes_transferred;
David Turner6a9ef172010-09-09 22:54:36 +02001890 bwidth = qemu_get_clock_ns(rt_clock);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001891
1892 while (!qemu_file_rate_limit(f)) {
1893 int ret;
1894
1895 ret = ram_save_block(f);
1896 bytes_transferred += ret * TARGET_PAGE_SIZE;
1897 if (ret == 0) /* no more blocks */
1898 break;
1899 }
1900
David Turner6a9ef172010-09-09 22:54:36 +02001901 bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001902 bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
1903
1904 /* if we haven't transferred anything this round, force expected_time to a
1905 * a very high value, but without crashing */
1906 if (bwidth == 0)
1907 bwidth = 0.000001;
1908
1909 /* try transferring iterative blocks of memory */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001910 if (stage == 3) {
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001911 /* flush all remaining blocks regardless of rate limiting */
1912 while (ram_save_block(f) != 0) {
1913 bytes_transferred += TARGET_PAGE_SIZE;
1914 }
1915 cpu_physical_memory_set_dirty_tracking(0);
1916 }
1917
1918 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
1919
1920 expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
1921
1922 return (stage == 2) && (expected_time <= migrate_max_downtime());
1923}
1924
1925static int ram_load_dead(QEMUFile *f, void *opaque)
1926{
1927 RamDecompressState s1, *s = &s1;
1928 uint8_t buf[10];
1929 ram_addr_t i;
1930
1931 if (ram_decompress_open(s, f) < 0)
1932 return -EINVAL;
1933 for(i = 0; i < last_ram_offset; i+= BDRV_HASH_BLOCK_SIZE) {
1934 if (ram_decompress_buf(s, buf, 1) < 0) {
1935 fprintf(stderr, "Error while reading ram block header\n");
1936 goto error;
1937 }
1938 if (buf[0] == 0) {
1939 if (ram_decompress_buf(s, qemu_get_ram_ptr(i),
1940 BDRV_HASH_BLOCK_SIZE) < 0) {
1941 fprintf(stderr, "Error while reading ram block address=0x%08" PRIx64, (uint64_t)i);
1942 goto error;
1943 }
1944 } else {
1945 error:
1946 printf("Error block header\n");
1947 return -EINVAL;
1948 }
1949 }
1950 ram_decompress_close(s);
1951
1952 return 0;
1953}
1954
1955static int ram_load(QEMUFile *f, void *opaque, int version_id)
1956{
1957 ram_addr_t addr;
1958 int flags;
1959
1960 if (version_id == 1)
1961 return ram_load_v1(f, opaque);
1962
1963 if (version_id == 2) {
1964 if (qemu_get_be32(f) != last_ram_offset)
1965 return -EINVAL;
1966 return ram_load_dead(f, opaque);
1967 }
1968
1969 if (version_id != 3)
1970 return -EINVAL;
1971
1972 do {
1973 addr = qemu_get_be64(f);
1974
1975 flags = addr & ~TARGET_PAGE_MASK;
1976 addr &= TARGET_PAGE_MASK;
1977
1978 if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
1979 if (addr != last_ram_offset)
1980 return -EINVAL;
1981 }
1982
1983 if (flags & RAM_SAVE_FLAG_FULL) {
1984 if (ram_load_dead(f, opaque) < 0)
1985 return -EINVAL;
1986 }
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07001987
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001988 if (flags & RAM_SAVE_FLAG_COMPRESS) {
1989 uint8_t ch = qemu_get_byte(f);
1990 memset(qemu_get_ram_ptr(addr), ch, TARGET_PAGE_SIZE);
1991 } else if (flags & RAM_SAVE_FLAG_PAGE)
1992 qemu_get_buffer(f, qemu_get_ram_ptr(addr), TARGET_PAGE_SIZE);
1993 } while (!(flags & RAM_SAVE_FLAG_EOS));
1994
1995 return 0;
1996}
1997
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001998/***********************************************************/
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07001999/* machine registration */
2000
2001static QEMUMachine *first_machine = NULL;
2002QEMUMachine *current_machine = NULL;
2003
2004int qemu_register_machine(QEMUMachine *m)
2005{
2006 QEMUMachine **pm;
2007 pm = &first_machine;
2008 while (*pm != NULL)
2009 pm = &(*pm)->next;
2010 m->next = NULL;
2011 *pm = m;
2012 return 0;
2013}
2014
2015static QEMUMachine *find_machine(const char *name)
2016{
2017 QEMUMachine *m;
2018
2019 for(m = first_machine; m != NULL; m = m->next) {
2020 if (!strcmp(m->name, name))
2021 return m;
2022 }
2023 return NULL;
2024}
2025
2026static QEMUMachine *find_default_machine(void)
2027{
2028 QEMUMachine *m;
2029
2030 for(m = first_machine; m != NULL; m = m->next) {
2031 if (m->is_default) {
2032 return m;
2033 }
2034 }
2035 return NULL;
2036}
2037
2038/***********************************************************/
2039/* main execution loop */
2040
2041static void gui_update(void *opaque)
2042{
2043 uint64_t interval = GUI_REFRESH_INTERVAL;
2044 DisplayState *ds = opaque;
2045 DisplayChangeListener *dcl = ds->listeners;
2046
2047 dpy_refresh(ds);
2048
2049 while (dcl != NULL) {
2050 if (dcl->gui_timer_interval &&
2051 dcl->gui_timer_interval < interval)
2052 interval = dcl->gui_timer_interval;
2053 dcl = dcl->next;
2054 }
David 'Digit' Turner5973c772011-05-10 07:06:00 +02002055 qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002056}
2057
2058static void nographic_update(void *opaque)
2059{
2060 uint64_t interval = GUI_REFRESH_INTERVAL;
2061
David 'Digit' Turner5973c772011-05-10 07:06:00 +02002062 qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002063}
2064
2065struct vm_change_state_entry {
2066 VMChangeStateHandler *cb;
2067 void *opaque;
David 'Digit' Turnera5d41202010-05-10 18:37:10 -07002068 QLIST_ENTRY (vm_change_state_entry) entries;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002069};
2070
David 'Digit' Turnera5d41202010-05-10 18:37:10 -07002071static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002072
2073VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
2074 void *opaque)
2075{
2076 VMChangeStateEntry *e;
2077
2078 e = qemu_mallocz(sizeof (*e));
2079
2080 e->cb = cb;
2081 e->opaque = opaque;
David 'Digit' Turnera5d41202010-05-10 18:37:10 -07002082 QLIST_INSERT_HEAD(&vm_change_state_head, e, entries);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002083 return e;
2084}
2085
2086void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
2087{
David 'Digit' Turnera5d41202010-05-10 18:37:10 -07002088 QLIST_REMOVE (e, entries);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002089 qemu_free (e);
2090}
2091
David 'Digit' Turner23ca2ae2011-06-01 16:14:53 +02002092void vm_state_notify(int running, int reason)
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002093{
2094 VMChangeStateEntry *e;
2095
2096 for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
2097 e->cb(e->opaque, running, reason);
2098 }
2099}
2100
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002101void vm_start(void)
2102{
2103 if (!vm_running) {
2104 cpu_enable_ticks();
2105 vm_running = 1;
2106 vm_state_notify(1, 0);
David Turner6a9ef172010-09-09 22:54:36 +02002107 //qemu_rearm_alarm_timer(alarm_timer);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002108 resume_all_vcpus();
2109 }
2110}
2111
2112/* reset/shutdown handler */
2113
2114typedef struct QEMUResetEntry {
2115 QEMUResetHandler *func;
2116 void *opaque;
2117 int order;
2118 struct QEMUResetEntry *next;
2119} QEMUResetEntry;
2120
2121static QEMUResetEntry *first_reset_entry;
2122static int reset_requested;
David 'Digit' Turner088edf82011-05-09 15:59:28 +02002123static int shutdown_requested, shutdown_signal = -1;
2124static pid_t shutdown_pid;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002125static int powerdown_requested;
David 'Digit' Turner23ca2ae2011-06-01 16:14:53 +02002126int debug_requested;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002127static int vmstop_requested;
2128
2129int qemu_shutdown_requested(void)
2130{
2131 int r = shutdown_requested;
2132 shutdown_requested = 0;
2133 return r;
2134}
2135
2136int qemu_reset_requested(void)
2137{
2138 int r = reset_requested;
2139 reset_requested = 0;
2140 return r;
2141}
2142
2143int qemu_powerdown_requested(void)
2144{
2145 int r = powerdown_requested;
2146 powerdown_requested = 0;
2147 return r;
2148}
2149
2150static int qemu_debug_requested(void)
2151{
2152 int r = debug_requested;
2153 debug_requested = 0;
2154 return r;
2155}
2156
2157static int qemu_vmstop_requested(void)
2158{
2159 int r = vmstop_requested;
2160 vmstop_requested = 0;
2161 return r;
2162}
2163
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002164void qemu_register_reset(QEMUResetHandler *func, int order, void *opaque)
2165{
2166 QEMUResetEntry **pre, *re;
2167
2168 pre = &first_reset_entry;
2169 while (*pre != NULL && (*pre)->order >= order) {
2170 pre = &(*pre)->next;
2171 }
2172 re = qemu_mallocz(sizeof(QEMUResetEntry));
2173 re->func = func;
2174 re->opaque = opaque;
2175 re->order = order;
2176 re->next = NULL;
2177 *pre = re;
2178}
2179
2180void qemu_system_reset(void)
2181{
2182 QEMUResetEntry *re;
2183
2184 /* reset all devices */
2185 for(re = first_reset_entry; re != NULL; re = re->next) {
2186 re->func(re->opaque);
2187 }
2188}
2189
2190void qemu_system_reset_request(void)
2191{
2192 if (no_reboot) {
2193 shutdown_requested = 1;
2194 } else {
2195 reset_requested = 1;
2196 }
2197 qemu_notify_event();
2198}
2199
David 'Digit' Turner088edf82011-05-09 15:59:28 +02002200void qemu_system_killed(int signal, pid_t pid)
2201{
2202 shutdown_signal = signal;
2203 shutdown_pid = pid;
2204 qemu_system_shutdown_request();
2205}
2206
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002207void qemu_system_shutdown_request(void)
2208{
2209 shutdown_requested = 1;
2210 qemu_notify_event();
2211}
2212
2213void qemu_system_powerdown_request(void)
2214{
2215 powerdown_requested = 1;
2216 qemu_notify_event();
2217}
2218
2219#ifdef CONFIG_IOTHREAD
2220static void qemu_system_vmstop_request(int reason)
2221{
2222 vmstop_requested = reason;
2223 qemu_notify_event();
2224}
2225#endif
2226
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002227void main_loop_wait(int timeout)
2228{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002229 fd_set rfds, wfds, xfds;
2230 int ret, nfds;
2231 struct timeval tv;
2232
2233 qemu_bh_update_timeout(&timeout);
2234
David 'Digit' Turner23ca2ae2011-06-01 16:14:53 +02002235 os_host_main_loop_wait(&timeout);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002236
David 'Digit' Turner8354d2d2011-05-11 00:19:06 +02002237
2238 tv.tv_sec = timeout / 1000;
2239 tv.tv_usec = (timeout % 1000) * 1000;
2240
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002241 /* poll any events */
David 'Digit' Turner8354d2d2011-05-11 00:19:06 +02002242
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002243 /* XXX: separate device handlers from system ones */
2244 nfds = -1;
2245 FD_ZERO(&rfds);
2246 FD_ZERO(&wfds);
2247 FD_ZERO(&xfds);
David 'Digit' Turner8354d2d2011-05-11 00:19:06 +02002248 qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002249 if (slirp_is_inited()) {
2250 slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
2251 }
David 'Digit' Turner8354d2d2011-05-11 00:19:06 +02002252
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002253 qemu_mutex_unlock_iothread();
2254 ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
2255 qemu_mutex_lock_iothread();
David 'Digit' Turner8354d2d2011-05-11 00:19:06 +02002256 qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002257 if (slirp_is_inited()) {
2258 if (ret < 0) {
2259 FD_ZERO(&rfds);
2260 FD_ZERO(&wfds);
2261 FD_ZERO(&xfds);
2262 }
2263 slirp_select_poll(&rfds, &wfds, &xfds);
2264 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002265 charpipe_poll();
2266
David Turner6a9ef172010-09-09 22:54:36 +02002267 qemu_run_all_timers();
David 'Digit' Turnera7fb77d2010-05-10 23:50:54 -07002268
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002269 /* Check bottom-halves last in case any of the earlier events triggered
2270 them. */
2271 qemu_bh_poll();
2272
2273}
2274
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002275static int vm_can_run(void)
2276{
2277 if (powerdown_requested)
2278 return 0;
2279 if (reset_requested)
2280 return 0;
2281 if (shutdown_requested)
2282 return 0;
2283 if (debug_requested)
2284 return 0;
2285 return 1;
2286}
2287
2288static void main_loop(void)
2289{
2290 int r;
2291
2292#ifdef CONFIG_IOTHREAD
2293 qemu_system_ready = 1;
2294 qemu_cond_broadcast(&qemu_system_cond);
2295#endif
2296
2297 for (;;) {
2298 do {
2299#ifdef CONFIG_PROFILER
2300 int64_t ti;
2301#endif
2302#ifndef CONFIG_IOTHREAD
2303 tcg_cpu_exec();
2304#endif
2305#ifdef CONFIG_PROFILER
2306 ti = profile_getclock();
2307#endif
2308 main_loop_wait(qemu_calculate_timeout());
2309#ifdef CONFIG_PROFILER
2310 dev_time += profile_getclock() - ti;
2311#endif
rich canningsd952f282011-03-01 15:40:09 -08002312
2313 if (rotate_logs_requested) {
2314 FILE* new_dns_log_fd = rotate_qemu_log(get_slirp_dns_log_fd(),
2315 dns_log_filename);
2316 FILE* new_drop_log_fd = rotate_qemu_log(get_slirp_drop_log_fd(),
2317 drop_log_filename);
2318 slirp_dns_log_fd(new_dns_log_fd);
2319 slirp_drop_log_fd(new_drop_log_fd);
2320 reset_rotate_qemu_logs_request();
2321 }
2322
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002323 } while (vm_can_run());
2324
2325 if (qemu_debug_requested())
2326 vm_stop(EXCP_DEBUG);
2327 if (qemu_shutdown_requested()) {
2328 if (no_shutdown) {
2329 vm_stop(0);
2330 no_shutdown = 0;
Tim Baverstock24204cc2010-11-25 11:37:43 +00002331 } else {
Tim Baverstock24204cc2010-11-25 11:37:43 +00002332 if (savevm_on_exit != NULL) {
2333 do_savevm(cur_mon, savevm_on_exit);
2334 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002335 break;
Tim Baverstock24204cc2010-11-25 11:37:43 +00002336 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002337 }
2338 if (qemu_reset_requested()) {
2339 pause_all_vcpus();
2340 qemu_system_reset();
2341 resume_all_vcpus();
2342 }
2343 if (qemu_powerdown_requested())
2344 qemu_system_powerdown();
2345 if ((r = qemu_vmstop_requested()))
2346 vm_stop(r);
2347 }
2348 pause_all_vcpus();
2349}
2350
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07002351void version(void)
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002352{
2353 printf("QEMU PC emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n");
2354}
2355
2356void qemu_help(int exitcode)
2357{
2358 version();
2359 printf("usage: %s [options] [disk_image]\n"
2360 "\n"
2361 "'disk_image' is a raw hard image image for IDE hard disk 0\n"
2362 "\n"
2363#define DEF(option, opt_arg, opt_enum, opt_help) \
2364 opt_help
2365#define DEFHEADING(text) stringify(text) "\n"
David 'Digit' Turner088edf82011-05-09 15:59:28 +02002366#include "qemu-options.def"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002367#undef DEF
2368#undef DEFHEADING
2369#undef GEN_DOCS
2370 "\n"
2371 "During emulation, the following keys are useful:\n"
2372 "ctrl-alt-f toggle full screen\n"
2373 "ctrl-alt-n switch to virtual console 'n'\n"
2374 "ctrl-alt toggle mouse and keyboard grab\n"
2375 "\n"
2376 "When using -nographic, press 'ctrl-a h' to get some help.\n"
2377 ,
2378 "qemu",
2379 DEFAULT_RAM_SIZE,
2380#ifndef _WIN32
2381 DEFAULT_NETWORK_SCRIPT,
2382 DEFAULT_NETWORK_DOWN_SCRIPT,
2383#endif
2384 DEFAULT_GDBSTUB_PORT,
2385 "/tmp/qemu.log");
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002386 QEMU_EXIT(exitcode);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002387}
2388
2389#define HAS_ARG 0x0001
2390
2391enum {
2392#define DEF(option, opt_arg, opt_enum, opt_help) \
2393 opt_enum,
2394#define DEFHEADING(text)
David 'Digit' Turner088edf82011-05-09 15:59:28 +02002395#include "qemu-options.def"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002396#undef DEF
2397#undef DEFHEADING
2398#undef GEN_DOCS
2399};
2400
2401typedef struct QEMUOption {
2402 const char *name;
2403 int flags;
2404 int index;
2405} QEMUOption;
2406
2407static const QEMUOption qemu_options[] = {
2408 { "h", 0, QEMU_OPTION_h },
2409#define DEF(option, opt_arg, opt_enum, opt_help) \
2410 { option, opt_arg, opt_enum },
2411#define DEFHEADING(text)
David 'Digit' Turner088edf82011-05-09 15:59:28 +02002412#include "qemu-options.def"
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002413#undef DEF
2414#undef DEFHEADING
2415#undef GEN_DOCS
2416 { NULL, 0, 0 },
2417};
2418
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002419static void select_vgahw (const char *p)
2420{
2421 const char *opts;
2422
2423 cirrus_vga_enabled = 0;
2424 std_vga_enabled = 0;
2425 vmsvga_enabled = 0;
2426 xenfb_enabled = 0;
2427 if (strstart(p, "std", &opts)) {
2428 std_vga_enabled = 1;
2429 } else if (strstart(p, "cirrus", &opts)) {
2430 cirrus_vga_enabled = 1;
2431 } else if (strstart(p, "vmware", &opts)) {
2432 vmsvga_enabled = 1;
2433 } else if (strstart(p, "xenfb", &opts)) {
2434 xenfb_enabled = 1;
2435 } else if (!strstart(p, "none", &opts)) {
2436 invalid_vga:
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002437 PANIC("Unknown vga type: %s", p);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002438 }
2439 while (*opts) {
2440 const char *nextopt;
2441
2442 if (strstart(opts, ",retrace=", &nextopt)) {
2443 opts = nextopt;
2444 if (strstart(opts, "dumb", &nextopt))
2445 vga_retrace_method = VGA_RETRACE_DUMB;
2446 else if (strstart(opts, "precise", &nextopt))
2447 vga_retrace_method = VGA_RETRACE_PRECISE;
2448 else goto invalid_vga;
2449 } else goto invalid_vga;
2450 opts = nextopt;
2451 }
2452}
2453
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002454#define MAX_NET_CLIENTS 32
2455
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002456#ifdef _WIN32
2457/* Look for support files in the same directory as the executable. */
2458static char *find_datadir(const char *argv0)
2459{
2460 char *p;
2461 char buf[MAX_PATH];
2462 DWORD len;
2463
2464 len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
2465 if (len == 0) {
2466 return NULL;
2467 }
2468
2469 buf[len] = 0;
2470 p = buf + len - 1;
2471 while (p != buf && *p != '\\')
2472 p--;
2473 *p = 0;
2474 if (access(buf, R_OK) == 0) {
2475 return qemu_strdup(buf);
2476 }
2477 return NULL;
2478}
2479#else /* !_WIN32 */
2480
David 'Digit' Turner24d27522011-06-01 16:50:56 +02002481/* Similarly, return the location of the executable */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002482static char *find_datadir(const char *argv0)
2483{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002484 char *p = NULL;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002485 char buf[PATH_MAX];
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002486
2487#if defined(__linux__)
2488 {
2489 int len;
2490 len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
2491 if (len > 0) {
2492 buf[len] = 0;
2493 p = buf;
2494 }
2495 }
2496#elif defined(__FreeBSD__)
2497 {
2498 int len;
2499 len = readlink("/proc/curproc/file", buf, sizeof(buf) - 1);
2500 if (len > 0) {
2501 buf[len] = 0;
2502 p = buf;
2503 }
2504 }
2505#endif
2506 /* If we don't have any way of figuring out the actual executable
2507 location then try argv[0]. */
2508 if (!p) {
David 'Digit' Turner24d27522011-06-01 16:50:56 +02002509 p = realpath(argv0, buf);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002510 if (!p) {
2511 return NULL;
2512 }
2513 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002514
David 'Digit' Turner24d27522011-06-01 16:50:56 +02002515 return qemu_strdup(dirname(buf));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002516}
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002517#endif
2518
David 'Digit' Turner24d27522011-06-01 16:50:56 +02002519static char*
2520qemu_find_file_with_subdir(const char* data_dir, const char* subdir, const char* name)
2521{
2522 int len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2;
2523 char* buf = qemu_mallocz(len);
2524
2525 snprintf(buf, len, "%s/%s%s", data_dir, subdir, name);
2526 VERBOSE_PRINT(init," trying to find: %s\n", buf);
2527 if (access(buf, R_OK)) {
2528 qemu_free(buf);
2529 return NULL;
2530 }
2531 return buf;
2532}
2533
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002534char *qemu_find_file(int type, const char *name)
2535{
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002536 const char *subdir;
2537 char *buf;
2538
2539 /* If name contains path separators then try it as a straight path. */
2540 if ((strchr(name, '/') || strchr(name, '\\'))
2541 && access(name, R_OK) == 0) {
2542 return strdup(name);
2543 }
2544 switch (type) {
2545 case QEMU_FILE_TYPE_BIOS:
2546 subdir = "";
2547 break;
2548 case QEMU_FILE_TYPE_KEYMAP:
2549 subdir = "keymaps/";
2550 break;
2551 default:
2552 abort();
2553 }
David 'Digit' Turner24d27522011-06-01 16:50:56 +02002554 buf = qemu_find_file_with_subdir(data_dir, subdir, name);
2555#ifdef CONFIG_ANDROID
2556 if (type == QEMU_FILE_TYPE_BIOS) {
2557 /* This case corresponds to the emulator being used as part of an
2558 * SDK installation. NOTE: data_dir is really $bindir. */
2559 if (buf == NULL)
2560 buf = qemu_find_file_with_subdir(data_dir, "lib/pc-bios/", name);
2561 /* This case corresponds to platform builds. */
2562 if (buf == NULL)
2563 buf = qemu_find_file_with_subdir(data_dir, "../usr/share/pc-bios/", name);
2564 /* Finally, try this for standalone builds under external/qemu */
2565 if (buf == NULL)
2566 buf = qemu_find_file_with_subdir(data_dir, "../../../prebuilt/common/pc-bios/", name);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002567 }
David 'Digit' Turner24d27522011-06-01 16:50:56 +02002568#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002569 return buf;
2570}
2571
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07002572static int
2573add_dns_server( const char* server_name )
2574{
2575 SockAddress addr;
2576
2577 if (sock_address_init_resolve( &addr, server_name, 55, 0 ) < 0) {
2578 fprintf(stdout,
2579 "### WARNING: can't resolve DNS server name '%s'\n",
2580 server_name );
2581 return -1;
2582 }
2583
2584 fprintf(stderr,
2585 "DNS server name '%s' resolved to %s\n", server_name, sock_address_to_string(&addr) );
2586
2587 if ( slirp_add_dns_server( &addr ) < 0 ) {
2588 fprintf(stderr,
2589 "### WARNING: could not add DNS server '%s' to the network stack\n", server_name);
2590 return -1;
2591 }
2592 return 0;
2593}
2594
rich cannings7339b552011-02-16 13:43:44 -08002595/* Parses an integer
2596 * Pararm:
2597 * str String containing a number to be parsed.
2598 * result Passes the parsed integer in this argument
2599 * returns 0 if ok, -1 if failed
2600 */
2601int
2602parse_int(const char *str, int *result)
2603{
2604 char* r;
2605 *result = strtol(str, &r, 0);
2606 if (r == NULL || *r != '\0')
2607 return -1;
2608
2609 return 0;
2610}
2611
rich canningsd952f282011-03-01 15:40:09 -08002612#ifndef _WIN32
2613/*
2614 * Initializes the SIGUSR1 signal handler to clear Qemu logs.
2615 */
2616void init_qemu_clear_logs_sig() {
2617 struct sigaction act;
2618 sigfillset(&act.sa_mask);
2619 act.sa_flags = 0;
2620 act.sa_handler = rotate_qemu_logs_handler;
2621 if (sigaction(SIGUSR1, &act, NULL) == -1) {
2622 fprintf(stderr, "Failed to setup SIGUSR1 handler to clear Qemu logs\n");
2623 exit(-1);
2624 }
2625}
2626#endif
2627
2628
rich cannings7339b552011-02-16 13:43:44 -08002629
2630/* parses a null-terminated string specifying a network port (e.g., "80") or
2631 * port range (e.g., "[6666-7000]"). In case of a single port, lport and hport
2632 * are the same. Returns 0 on success, -1 on error. */
2633
2634int parse_port_range(const char *str, unsigned short *lport,
2635 unsigned short *hport) {
2636
2637 unsigned int low = 0, high = 0;
2638 char *p, *arg = strdup(str);
2639
2640 if ((*arg == '[') && ((p = strrchr(arg, ']')) != NULL)) {
2641 p = arg + 1; /* skip '[' */
2642 low = atoi(strtok(p, "-"));
2643 high = atoi(strtok(NULL, "-"));
2644 if ((low > 0) && (high > 0) && (low < high) && (high < 65535)) {
2645 *lport = low;
2646 *hport = high;
2647 }
2648 }
2649 else {
2650 low = atoi(arg);
2651 if ((0 < low) && (low < 65535)) {
2652 *lport = low;
2653 *hport = low;
2654 }
2655 }
2656 free(arg);
2657 if (low != 0)
2658 return 0;
2659 return -1;
2660}
2661
2662/*
2663 * Implements the generic port forwarding option
2664 */
2665void
2666net_slirp_forward(const char *optarg)
2667{
2668 /*
2669 * we expect the following format:
2670 * dst_net:dst_mask:dst_port:redirect_ip:redirect_port OR
2671 * dst_net:dst_mask:[dp_range_start-dp_range_end]:redirect_ip:redirect_port
2672 */
2673 char *argument = strdup(optarg), *p = argument;
2674 char *dst_net, *dst_mask, *dst_port;
2675 char *redirect_ip, *redirect_port;
2676 uint32_t dnet, dmask, rip;
2677 unsigned short dlport, dhport, rport;
2678
2679
2680 dst_net = strtok(p, ":");
2681 dst_mask = strtok(NULL, ":");
2682 dst_port = strtok(NULL, ":");
2683 redirect_ip = strtok(NULL, ":");
2684 redirect_port = strtok(NULL, ":");
2685
2686 if (dst_net == NULL || dst_mask == NULL || dst_port == NULL ||
2687 redirect_ip == NULL || redirect_port == NULL) {
2688 fprintf(stderr,
2689 "Invalid argument for -net-forward, we expect "
2690 "dst_net:dst_mask:dst_port:redirect_ip:redirect_port or "
2691 "dst_net:dst_mask:[dp_range_start-dp_range_end]"
2692 ":redirect_ip:redirect_port: %s\n",
2693 optarg);
2694 exit(1);
2695 }
2696
2697 /* inet_strtoip converts dotted address to host byte order */
2698 if (inet_strtoip(dst_net, &dnet) == -1) {
2699 fprintf(stderr, "Invalid destination IP net: %s\n", dst_net);
2700 exit(1);
2701 }
2702 if (inet_strtoip(dst_mask, &dmask) == -1) {
2703 fprintf(stderr, "Invalid destination IP mask: %s\n", dst_mask);
2704 exit(1);
2705 }
2706 if (inet_strtoip(redirect_ip, &rip) == -1) {
2707 fprintf(stderr, "Invalid redirect IP address: %s\n", redirect_ip);
2708 exit(1);
2709 }
2710
2711 if (parse_port_range(dst_port, &dlport, &dhport) == -1) {
2712 fprintf(stderr, "Invalid destination port or port range\n");
2713 exit(1);
2714 }
2715
2716 rport = atoi(redirect_port);
2717 if (!rport) {
2718 fprintf(stderr, "Invalid redirect port: %s\n", redirect_port);
2719 exit(1);
2720 }
2721
2722 dnet &= dmask;
2723
2724 slirp_add_net_forward(dnet, dmask, dlport, dhport,
2725 rip, rport);
2726
2727 free(argument);
2728}
2729
2730
2731/* Parses an -allow-tcp or -allow-udp argument and inserts a corresponding
2732 * entry in the allows list */
2733void
2734slirp_allow(const char *optarg, u_int8_t proto)
2735{
2736 /*
2737 * we expect the following format:
2738 * dst_ip:dst_port OR dst_ip:[dst_lport-dst_hport]
2739 */
2740 char *argument = strdup(optarg), *p = argument;
2741 char *dst_ip_str, *dst_port_str;
2742 uint32_t dst_ip;
2743 unsigned short dst_lport, dst_hport;
2744
2745 dst_ip_str = strtok(p, ":");
2746 dst_port_str = strtok(NULL, ":");
2747
2748 if (dst_ip_str == NULL || dst_port_str == NULL) {
2749 fprintf(stderr,
2750 "Invalid argument %s for -allow. We expect "
2751 "dst_ip:dst_port or dst_ip:[dst_lport-dst_hport]\n",
2752 optarg);
2753 exit(1);
2754 }
2755
2756 if (inet_strtoip(dst_ip_str, &dst_ip) == -1) {
2757 fprintf(stderr, "Invalid destination IP address: %s\n", dst_ip_str);
2758 exit(1);
2759 }
2760 if (parse_port_range(dst_port_str, &dst_lport, &dst_hport) == -1) {
2761 fprintf(stderr, "Invalid destination port or port range\n");
2762 exit(1);
2763 }
2764
2765 slirp_add_allow(dst_ip, dst_lport, dst_hport, proto);
2766
2767 free(argument);
2768}
2769
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01002770/* Add a serial device at a given location in the emulated hardware table.
2771 * On failure, this function aborts the program with an error message.
2772 */
2773static void
2774serial_hds_add_at(int index, const char* devname)
2775{
2776 char label[32];
2777
2778 if (!devname || !strcmp(devname,"none"))
2779 return;
2780
2781 if (index >= MAX_SERIAL_PORTS) {
2782 PANIC("qemu: invalid serial index for %s (%d >= %d)",
2783 devname, index, MAX_SERIAL_PORTS);
2784 }
2785 if (serial_hds[index] != NULL) {
2786 PANIC("qemu: invalid serial index for %s (%d: already taken!)",
2787 devname, index);
2788 }
2789 snprintf(label, sizeof(label), "serial%d", index);
2790 serial_hds[index] = qemu_chr_open(label, devname, NULL);
2791 if (!serial_hds[index]) {
2792 PANIC("qemu: could not open serial device '%s'", devname);
2793 }
2794}
2795
2796
2797/* Find a free slot in the emulated serial device table, and register
2798 * it. Return the allocated table index.
2799 */
2800static int
2801serial_hds_add(const char* devname)
2802{
2803 int index;
2804
2805 /* Find first free slot */
2806 for (index = 0; index < MAX_SERIAL_PORTS; index++) {
2807 if (serial_hds[index] == NULL) {
2808 serial_hds_add_at(index, devname);
2809 return index;
2810 }
2811 }
2812
2813 PANIC("qemu: too many serial devices registered (%d)", index);
2814 return -1; /* shouldn't happen */
2815}
2816
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002817int main(int argc, char **argv, char **envp)
2818{
2819 const char *gdbstub_dev = NULL;
2820 uint32_t boot_devices_bitmap = 0;
2821 int i;
2822 int snapshot, linux_boot, net_boot;
David Turner6a9ef172010-09-09 22:54:36 +02002823 const char *icount_option = NULL;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002824 const char *initrd_filename;
2825 const char *kernel_filename, *kernel_cmdline;
2826 const char *boot_devices = "";
2827 DisplayState *ds;
2828 DisplayChangeListener *dcl;
2829 int cyls, heads, secs, translation;
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01002830 QemuOpts *hda_opts = NULL;
David 'Digit' Turner5f64b872011-02-28 23:23:05 +01002831 QemuOpts *hdb_opts = NULL;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002832 const char *net_clients[MAX_NET_CLIENTS];
2833 int nb_net_clients;
2834 const char *bt_opts[MAX_BT_CMDLINE];
2835 int nb_bt_opts;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002836 int optind;
2837 const char *r, *optarg;
2838 CharDriverState *monitor_hd = NULL;
2839 const char *monitor_device;
2840 const char *serial_devices[MAX_SERIAL_PORTS];
2841 int serial_device_index;
2842 const char *parallel_devices[MAX_PARALLEL_PORTS];
2843 int parallel_device_index;
2844 const char *virtio_consoles[MAX_VIRTIO_CONSOLES];
2845 int virtio_console_index;
2846 const char *loadvm = NULL;
2847 QEMUMachine *machine;
2848 const char *cpu_model;
2849 const char *usb_devices[MAX_USB_CMDLINE];
2850 int usb_devices_index;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002851 int tb_size;
2852 const char *pid_file = NULL;
2853 const char *incoming = NULL;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002854 CPUState *env;
2855 int show_vnc_port = 0;
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -07002856 IniFile* hw_ini = NULL;
David 'Digit' Turner5f824112011-03-01 14:00:26 +01002857 STRALLOC_DEFINE(kernel_params);
2858 STRALLOC_DEFINE(kernel_config);
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07002859 int dns_count = 0;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002860
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002861 /* Initialize sockets before anything else, so we can properly report
2862 * initialization failures back to the UI. */
2863#ifdef _WIN32
2864 socket_init();
2865#endif
2866
David 'Digit' Turnera7fb77d2010-05-10 23:50:54 -07002867 init_clocks();
2868
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002869 qemu_cache_utils_init(envp);
2870
David 'Digit' Turnera5d41202010-05-10 18:37:10 -07002871 QLIST_INIT (&vm_change_state_head);
David 'Digit' Turnerc1ac40a2011-06-01 16:12:04 +02002872 os_setup_early_signal_handling();
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002873
2874 module_call_init(MODULE_INIT_MACHINE);
2875 machine = find_default_machine();
2876 cpu_model = NULL;
2877 initrd_filename = NULL;
2878 ram_size = 0;
2879 snapshot = 0;
2880 kernel_filename = NULL;
2881 kernel_cmdline = "";
David 'Digit' Turner5f824112011-03-01 14:00:26 +01002882
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002883 cyls = heads = secs = 0;
2884 translation = BIOS_ATA_TRANSLATION_AUTO;
2885 monitor_device = "vc:80Cx24C";
2886
2887 serial_devices[0] = "vc:80Cx24C";
2888 for(i = 1; i < MAX_SERIAL_PORTS; i++)
2889 serial_devices[i] = NULL;
2890 serial_device_index = 0;
2891
2892 parallel_devices[0] = "vc:80Cx24C";
2893 for(i = 1; i < MAX_PARALLEL_PORTS; i++)
2894 parallel_devices[i] = NULL;
2895 parallel_device_index = 0;
2896
2897 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++)
2898 virtio_consoles[i] = NULL;
2899 virtio_console_index = 0;
2900
2901 for (i = 0; i < MAX_NODES; i++) {
2902 node_mem[i] = 0;
2903 node_cpumask[i] = 0;
2904 }
2905
2906 usb_devices_index = 0;
2907
2908 nb_net_clients = 0;
2909 nb_bt_opts = 0;
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01002910#ifdef MAX_DRIVES
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002911 nb_drives = 0;
2912 nb_drives_opt = 0;
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01002913#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002914 nb_numa_nodes = 0;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002915
2916 nb_nics = 0;
2917
2918 tb_size = 0;
2919 autostart= 1;
2920
2921 register_watchdogs();
2922
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07002923 /* Initialize boot properties. */
2924 boot_property_init_service();
David 'Digit' Turnerca950592011-04-27 12:26:15 +02002925 android_hw_control_init();
David 'Digit' Turnerd4d688e2011-04-26 18:09:17 +02002926 android_net_pipes_init();
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07002927
David 'Digit' Turner36597752011-05-20 01:18:01 +02002928#ifdef CONFIG_KVM
2929 /* By default, force auto-detection for kvm */
2930 kvm_allowed = -1;
2931#endif
2932
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002933 optind = 1;
2934 for(;;) {
2935 if (optind >= argc)
2936 break;
2937 r = argv[optind];
2938 if (r[0] != '-') {
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01002939 hda_opts = drive_add(argv[optind++], HD_ALIAS, 0);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002940 } else {
2941 const QEMUOption *popt;
2942
2943 optind++;
2944 /* Treat --foo the same as -foo. */
2945 if (r[1] == '-')
2946 r++;
2947 popt = qemu_options;
2948 for(;;) {
2949 if (!popt->name) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002950 PANIC("%s: invalid option -- '%s'",
2951 argv[0], r);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002952 }
2953 if (!strcmp(popt->name, r + 1))
2954 break;
2955 popt++;
2956 }
2957 if (popt->flags & HAS_ARG) {
2958 if (optind >= argc) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002959 PANIC("%s: option '%s' requires an argument",
2960 argv[0], r);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002961 }
2962 optarg = argv[optind++];
2963 } else {
2964 optarg = NULL;
2965 }
2966
2967 switch(popt->index) {
2968 case QEMU_OPTION_M:
2969 machine = find_machine(optarg);
2970 if (!machine) {
2971 QEMUMachine *m;
2972 printf("Supported machines are:\n");
2973 for(m = first_machine; m != NULL; m = m->next) {
2974 printf("%-10s %s%s\n",
2975 m->name, m->desc,
2976 m->is_default ? " (default)" : "");
2977 }
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002978 if (*optarg != '?') {
2979 PANIC("Invalid machine parameter: %s",
2980 optarg);
2981 } else {
2982 QEMU_EXIT(0);
2983 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002984 }
2985 break;
2986 case QEMU_OPTION_cpu:
2987 /* hw initialization will check this */
2988 if (*optarg == '?') {
2989/* XXX: implement xxx_cpu_list for targets that still miss it */
2990#if defined(cpu_list)
2991 cpu_list(stdout, &fprintf);
2992#endif
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07002993 QEMU_EXIT(0);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07002994 } else {
2995 cpu_model = optarg;
2996 }
2997 break;
2998 case QEMU_OPTION_initrd:
2999 initrd_filename = optarg;
3000 break;
3001 case QEMU_OPTION_hda:
3002 if (cyls == 0)
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01003003 hda_opts = drive_add(optarg, HD_ALIAS, 0);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003004 else
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01003005 hda_opts = drive_add(optarg, HD_ALIAS
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003006 ",cyls=%d,heads=%d,secs=%d%s",
3007 0, cyls, heads, secs,
3008 translation == BIOS_ATA_TRANSLATION_LBA ?
3009 ",trans=lba" :
3010 translation == BIOS_ATA_TRANSLATION_NONE ?
3011 ",trans=none" : "");
3012 break;
3013 case QEMU_OPTION_hdb:
David 'Digit' Turner5f64b872011-02-28 23:23:05 +01003014 hdb_opts = drive_add(optarg, HD_ALIAS, 1);
3015 break;
3016
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003017 case QEMU_OPTION_hdc:
3018 case QEMU_OPTION_hdd:
3019 drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda);
3020 break;
3021 case QEMU_OPTION_drive:
3022 drive_add(NULL, "%s", optarg);
3023 break;
3024 case QEMU_OPTION_mtdblock:
3025 drive_add(optarg, MTD_ALIAS);
3026 break;
3027 case QEMU_OPTION_sd:
3028 drive_add(optarg, SD_ALIAS);
3029 break;
3030 case QEMU_OPTION_pflash:
3031 drive_add(optarg, PFLASH_ALIAS);
3032 break;
3033 case QEMU_OPTION_snapshot:
3034 snapshot = 1;
3035 break;
3036 case QEMU_OPTION_hdachs:
3037 {
3038 const char *p;
3039 p = optarg;
3040 cyls = strtol(p, (char **)&p, 0);
3041 if (cyls < 1 || cyls > 16383)
3042 goto chs_fail;
3043 if (*p != ',')
3044 goto chs_fail;
3045 p++;
3046 heads = strtol(p, (char **)&p, 0);
3047 if (heads < 1 || heads > 16)
3048 goto chs_fail;
3049 if (*p != ',')
3050 goto chs_fail;
3051 p++;
3052 secs = strtol(p, (char **)&p, 0);
3053 if (secs < 1 || secs > 63)
3054 goto chs_fail;
3055 if (*p == ',') {
3056 p++;
3057 if (!strcmp(p, "none"))
3058 translation = BIOS_ATA_TRANSLATION_NONE;
3059 else if (!strcmp(p, "lba"))
3060 translation = BIOS_ATA_TRANSLATION_LBA;
3061 else if (!strcmp(p, "auto"))
3062 translation = BIOS_ATA_TRANSLATION_AUTO;
3063 else
3064 goto chs_fail;
3065 } else if (*p != '\0') {
3066 chs_fail:
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003067 PANIC("qemu: invalid physical CHS format");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003068 }
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01003069 if (hda_opts != NULL) {
3070 char num[16];
3071 snprintf(num, sizeof(num), "%d", cyls);
3072 qemu_opt_set(hda_opts, "cyls", num);
3073 snprintf(num, sizeof(num), "%d", heads);
3074 qemu_opt_set(hda_opts, "heads", num);
3075 snprintf(num, sizeof(num), "%d", secs);
3076 qemu_opt_set(hda_opts, "secs", num);
3077 if (translation == BIOS_ATA_TRANSLATION_LBA)
3078 qemu_opt_set(hda_opts, "trans", "lba");
3079 if (translation == BIOS_ATA_TRANSLATION_NONE)
3080 qemu_opt_set(hda_opts, "trans", "none");
3081 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003082 }
3083 break;
3084 case QEMU_OPTION_numa:
3085 if (nb_numa_nodes >= MAX_NODES) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003086 PANIC("qemu: too many NUMA nodes");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003087 }
3088 numa_add(optarg);
3089 break;
3090 case QEMU_OPTION_nographic:
3091 display_type = DT_NOGRAPHIC;
3092 break;
3093#ifdef CONFIG_CURSES
3094 case QEMU_OPTION_curses:
3095 display_type = DT_CURSES;
3096 break;
3097#endif
3098 case QEMU_OPTION_portrait:
3099 graphic_rotate = 1;
3100 break;
3101 case QEMU_OPTION_kernel:
3102 kernel_filename = optarg;
3103 break;
3104 case QEMU_OPTION_append:
3105 kernel_cmdline = optarg;
3106 break;
3107 case QEMU_OPTION_cdrom:
3108 drive_add(optarg, CDROM_ALIAS);
3109 break;
3110 case QEMU_OPTION_boot:
3111 boot_devices = optarg;
3112 /* We just do some generic consistency checks */
3113 {
3114 /* Could easily be extended to 64 devices if needed */
3115 const char *p;
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07003116
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003117 boot_devices_bitmap = 0;
3118 for (p = boot_devices; *p != '\0'; p++) {
3119 /* Allowed boot devices are:
3120 * a b : floppy disk drives
3121 * c ... f : IDE disk drives
3122 * g ... m : machine implementation dependant drives
3123 * n ... p : network devices
3124 * It's up to each machine implementation to check
3125 * if the given boot devices match the actual hardware
3126 * implementation and firmware features.
3127 */
3128 if (*p < 'a' || *p > 'q') {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003129 PANIC("Invalid boot device '%c'", *p);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003130 }
3131 if (boot_devices_bitmap & (1 << (*p - 'a'))) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003132 PANIC(
3133 "Boot device '%c' was given twice",*p);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003134 }
3135 boot_devices_bitmap |= 1 << (*p - 'a');
3136 }
3137 }
3138 break;
3139 case QEMU_OPTION_fda:
3140 case QEMU_OPTION_fdb:
3141 drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda);
3142 break;
3143#ifdef TARGET_I386
3144 case QEMU_OPTION_no_fd_bootchk:
3145 fd_bootchk = 0;
3146 break;
3147#endif
3148 case QEMU_OPTION_net:
3149 if (nb_net_clients >= MAX_NET_CLIENTS) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003150 PANIC("qemu: too many network clients");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003151 }
3152 net_clients[nb_net_clients] = optarg;
3153 nb_net_clients++;
3154 break;
3155#ifdef CONFIG_SLIRP
3156 case QEMU_OPTION_tftp:
3157 tftp_prefix = optarg;
3158 break;
3159 case QEMU_OPTION_bootp:
3160 bootp_filename = optarg;
3161 break;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003162 case QEMU_OPTION_redir:
3163 net_slirp_redir(NULL, optarg, NULL);
3164 break;
3165#endif
3166 case QEMU_OPTION_bt:
3167 if (nb_bt_opts >= MAX_BT_CMDLINE) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003168 PANIC("qemu: too many bluetooth options");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003169 }
3170 bt_opts[nb_bt_opts++] = optarg;
3171 break;
3172#ifdef HAS_AUDIO
3173 case QEMU_OPTION_audio_help:
3174 AUD_help ();
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003175 QEMU_EXIT(0);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003176 break;
3177 case QEMU_OPTION_soundhw:
3178 select_soundhw (optarg);
3179 break;
3180#endif
3181 case QEMU_OPTION_h:
3182 qemu_help(0);
3183 break;
3184 case QEMU_OPTION_version:
3185 version();
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003186 QEMU_EXIT(0);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003187 break;
3188 case QEMU_OPTION_m: {
3189 uint64_t value;
3190 char *ptr;
3191
3192 value = strtoul(optarg, &ptr, 10);
3193 switch (*ptr) {
3194 case 0: case 'M': case 'm':
3195 value <<= 20;
3196 break;
3197 case 'G': case 'g':
3198 value <<= 30;
3199 break;
3200 default:
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003201 PANIC("qemu: invalid ram size: %s", optarg);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003202 }
3203
3204 /* On 32-bit hosts, QEMU is limited by virtual address space */
3205 if (value > (2047 << 20)
3206#ifndef CONFIG_KQEMU
3207 && HOST_LONG_BITS == 32
3208#endif
3209 ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003210 PANIC("qemu: at most 2047 MB RAM can be simulated");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003211 }
3212 if (value != (uint64_t)(ram_addr_t)value) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003213 PANIC("qemu: ram size too large");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003214 }
3215 ram_size = value;
3216 break;
3217 }
3218 case QEMU_OPTION_d:
3219 {
3220 int mask;
3221 const CPULogItem *item;
3222
3223 mask = cpu_str_to_log_mask(optarg);
3224 if (!mask) {
3225 printf("Log items (comma separated):\n");
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003226 for(item = cpu_log_items; item->mask != 0; item++) {
3227 printf("%-10s %s\n", item->name, item->help);
3228 }
3229 PANIC("Invalid parameter -d=%s", optarg);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003230 }
3231 cpu_set_log(mask);
3232 }
3233 break;
3234 case QEMU_OPTION_s:
3235 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
3236 break;
3237 case QEMU_OPTION_gdb:
3238 gdbstub_dev = optarg;
3239 break;
3240 case QEMU_OPTION_L:
3241 data_dir = optarg;
3242 break;
3243 case QEMU_OPTION_bios:
3244 bios_name = optarg;
3245 break;
3246 case QEMU_OPTION_singlestep:
3247 singlestep = 1;
3248 break;
3249 case QEMU_OPTION_S:
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003250 autostart = 0;
3251 break;
3252#ifndef _WIN32
3253 case QEMU_OPTION_k:
3254 keyboard_layout = optarg;
3255 break;
3256#endif
3257 case QEMU_OPTION_localtime:
3258 rtc_utc = 0;
3259 break;
3260 case QEMU_OPTION_vga:
3261 select_vgahw (optarg);
3262 break;
3263#if defined(TARGET_PPC) || defined(TARGET_SPARC)
3264 case QEMU_OPTION_g:
3265 {
3266 const char *p;
3267 int w, h, depth;
3268 p = optarg;
3269 w = strtol(p, (char **)&p, 10);
3270 if (w <= 0) {
3271 graphic_error:
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003272 PANIC("qemu: invalid resolution or depth");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003273 }
3274 if (*p != 'x')
3275 goto graphic_error;
3276 p++;
3277 h = strtol(p, (char **)&p, 10);
3278 if (h <= 0)
3279 goto graphic_error;
3280 if (*p == 'x') {
3281 p++;
3282 depth = strtol(p, (char **)&p, 10);
3283 if (depth != 8 && depth != 15 && depth != 16 &&
3284 depth != 24 && depth != 32)
3285 goto graphic_error;
3286 } else if (*p == '\0') {
3287 depth = graphic_depth;
3288 } else {
3289 goto graphic_error;
3290 }
3291
3292 graphic_width = w;
3293 graphic_height = h;
3294 graphic_depth = depth;
3295 }
3296 break;
3297#endif
3298 case QEMU_OPTION_echr:
3299 {
3300 char *r;
3301 term_escape_char = strtol(optarg, &r, 0);
3302 if (r == optarg)
3303 printf("Bad argument to echr\n");
3304 break;
3305 }
3306 case QEMU_OPTION_monitor:
3307 monitor_device = optarg;
3308 break;
3309 case QEMU_OPTION_serial:
3310 if (serial_device_index >= MAX_SERIAL_PORTS) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003311 PANIC("qemu: too many serial ports");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003312 }
3313 serial_devices[serial_device_index] = optarg;
3314 serial_device_index++;
3315 break;
3316 case QEMU_OPTION_watchdog:
3317 i = select_watchdog(optarg);
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003318 if (i > 0) {
3319 if (i == 1) {
3320 PANIC("Invalid watchdog parameter: %s",
3321 optarg);
3322 } else {
3323 QEMU_EXIT(0);
3324 }
3325 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003326 break;
3327 case QEMU_OPTION_watchdog_action:
3328 if (select_watchdog_action(optarg) == -1) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003329 PANIC("Unknown -watchdog-action parameter");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003330 }
3331 break;
3332 case QEMU_OPTION_virtiocon:
3333 if (virtio_console_index >= MAX_VIRTIO_CONSOLES) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003334 PANIC("qemu: too many virtio consoles");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003335 }
3336 virtio_consoles[virtio_console_index] = optarg;
3337 virtio_console_index++;
3338 break;
3339 case QEMU_OPTION_parallel:
3340 if (parallel_device_index >= MAX_PARALLEL_PORTS) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003341 PANIC("qemu: too many parallel ports");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003342 }
3343 parallel_devices[parallel_device_index] = optarg;
3344 parallel_device_index++;
3345 break;
Tim Baverstock24204cc2010-11-25 11:37:43 +00003346 case QEMU_OPTION_loadvm:
3347 loadvm = optarg;
3348 break;
Tim Baverstock24204cc2010-11-25 11:37:43 +00003349 case QEMU_OPTION_savevm_on_exit:
3350 savevm_on_exit = optarg;
3351 break;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003352 case QEMU_OPTION_full_screen:
3353 full_screen = 1;
3354 break;
3355#ifdef CONFIG_SDL
3356 case QEMU_OPTION_no_frame:
3357 no_frame = 1;
3358 break;
3359 case QEMU_OPTION_alt_grab:
3360 alt_grab = 1;
3361 break;
3362 case QEMU_OPTION_no_quit:
3363 no_quit = 1;
3364 break;
3365 case QEMU_OPTION_sdl:
3366 display_type = DT_SDL;
3367 break;
3368#endif
3369 case QEMU_OPTION_pidfile:
3370 pid_file = optarg;
3371 break;
3372#ifdef TARGET_I386
3373 case QEMU_OPTION_win2k_hack:
3374 win2k_install_hack = 1;
3375 break;
3376 case QEMU_OPTION_rtc_td_hack:
3377 rtc_td_hack = 1;
3378 break;
Jun Nakajima334ab472011-02-02 23:49:59 -08003379#ifndef CONFIG_ANDROID
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003380 case QEMU_OPTION_acpitable:
3381 if(acpi_table_add(optarg) < 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003382 PANIC("Wrong acpi table provided");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003383 }
3384 break;
Jun Nakajima334ab472011-02-02 23:49:59 -08003385#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003386 case QEMU_OPTION_smbios:
David 'Digit' Turnerae3098a2011-05-11 16:01:57 +02003387 do_smbios_option(optarg);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003388 break;
3389#endif
3390#ifdef CONFIG_KVM
3391 case QEMU_OPTION_enable_kvm:
3392 kvm_allowed = 1;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003393 break;
David 'Digit' Turner36597752011-05-20 01:18:01 +02003394 case QEMU_OPTION_disable_kvm:
3395 kvm_allowed = 0;
3396 break;
3397#endif /* CONFIG_KVM */
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003398 case QEMU_OPTION_usb:
3399 usb_enabled = 1;
3400 break;
3401 case QEMU_OPTION_usbdevice:
3402 usb_enabled = 1;
3403 if (usb_devices_index >= MAX_USB_CMDLINE) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003404 PANIC("Too many USB devices");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003405 }
3406 usb_devices[usb_devices_index] = optarg;
3407 usb_devices_index++;
3408 break;
3409 case QEMU_OPTION_smp:
3410 smp_cpus = atoi(optarg);
3411 if (smp_cpus < 1) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003412 PANIC("Invalid number of CPUs");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003413 }
3414 break;
3415 case QEMU_OPTION_vnc:
3416 display_type = DT_VNC;
3417 vnc_display = optarg;
3418 break;
3419#ifdef TARGET_I386
3420 case QEMU_OPTION_no_acpi:
3421 acpi_enabled = 0;
3422 break;
3423 case QEMU_OPTION_no_hpet:
3424 no_hpet = 1;
3425 break;
3426 case QEMU_OPTION_no_virtio_balloon:
3427 no_virtio_balloon = 1;
3428 break;
3429#endif
3430 case QEMU_OPTION_no_reboot:
3431 no_reboot = 1;
3432 break;
3433 case QEMU_OPTION_no_shutdown:
3434 no_shutdown = 1;
3435 break;
3436 case QEMU_OPTION_show_cursor:
3437 cursor_hide = 0;
3438 break;
3439 case QEMU_OPTION_uuid:
3440 if(qemu_uuid_parse(optarg, qemu_uuid) < 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003441 PANIC("Fail to parse UUID string. Wrong format.");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003442 }
3443 break;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003444 case QEMU_OPTION_option_rom:
3445 if (nb_option_roms >= MAX_OPTION_ROMS) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003446 PANIC("Too many option ROMs");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003447 }
3448 option_rom[nb_option_roms] = optarg;
3449 nb_option_roms++;
3450 break;
3451#if defined(TARGET_ARM) || defined(TARGET_M68K)
3452 case QEMU_OPTION_semihosting:
3453 semihosting_enabled = 1;
3454 break;
3455#endif
3456 case QEMU_OPTION_name:
3457 qemu_name = optarg;
3458 break;
3459#if defined(TARGET_SPARC) || defined(TARGET_PPC)
3460 case QEMU_OPTION_prom_env:
3461 if (nb_prom_envs >= MAX_PROM_ENVS) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003462 PANIC("Too many prom variables");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003463 }
3464 prom_envs[nb_prom_envs] = optarg;
3465 nb_prom_envs++;
3466 break;
3467#endif
3468#ifdef TARGET_ARM
3469 case QEMU_OPTION_old_param:
3470 old_param = 1;
3471 break;
3472#endif
3473 case QEMU_OPTION_clock:
3474 configure_alarms(optarg);
3475 break;
3476 case QEMU_OPTION_startdate:
3477 {
3478 struct tm tm;
David 'Digit' Turnerdc468202010-10-27 02:34:46 +02003479 time_t rtc_start_date = 0;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003480 if (!strcmp(optarg, "now")) {
3481 rtc_date_offset = -1;
3482 } else {
3483 if (sscanf(optarg, "%d-%d-%dT%d:%d:%d",
3484 &tm.tm_year,
3485 &tm.tm_mon,
3486 &tm.tm_mday,
3487 &tm.tm_hour,
3488 &tm.tm_min,
3489 &tm.tm_sec) == 6) {
3490 /* OK */
3491 } else if (sscanf(optarg, "%d-%d-%d",
3492 &tm.tm_year,
3493 &tm.tm_mon,
3494 &tm.tm_mday) == 3) {
3495 tm.tm_hour = 0;
3496 tm.tm_min = 0;
3497 tm.tm_sec = 0;
3498 } else {
3499 goto date_fail;
3500 }
3501 tm.tm_year -= 1900;
3502 tm.tm_mon--;
3503 rtc_start_date = mktimegm(&tm);
3504 if (rtc_start_date == -1) {
3505 date_fail:
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003506 PANIC("Invalid date format. Valid format are:\n"
3507 "'now' or '2006-06-17T16:01:21' or '2006-06-17'");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003508 }
3509 rtc_date_offset = time(NULL) - rtc_start_date;
3510 }
3511 }
3512 break;
rich cannings7339b552011-02-16 13:43:44 -08003513
3514 /* -------------------------------------------------------*/
3515 /* User mode network stack restrictions */
3516 case QEMU_OPTION_drop_udp:
3517 slirp_drop_udp();
3518 break;
3519 case QEMU_OPTION_drop_tcp:
3520 slirp_drop_tcp();
3521 break;
3522 case QEMU_OPTION_allow_tcp:
3523 slirp_allow(optarg, IPPROTO_TCP);
3524 break;
3525 case QEMU_OPTION_allow_udp:
3526 slirp_allow(optarg, IPPROTO_UDP);
3527 break;
3528 case QEMU_OPTION_drop_log:
3529 {
3530 FILE* drop_log_fd;
rich canningsd952f282011-03-01 15:40:09 -08003531 drop_log_filename = optarg;
3532 drop_log_fd = fopen(optarg, "w+");
rich cannings7339b552011-02-16 13:43:44 -08003533
3534 if (!drop_log_fd) {
3535 fprintf(stderr, "Cannot open drop log: %s\n", optarg);
3536 exit(1);
3537 }
3538
3539 slirp_drop_log_fd(drop_log_fd);
3540 }
3541 break;
3542
3543 case QEMU_OPTION_dns_log:
3544 {
3545 FILE* dns_log_fd;
rich canningsd952f282011-03-01 15:40:09 -08003546 dns_log_filename = optarg;
3547 dns_log_fd = fopen(optarg, "wb+");
rich cannings7339b552011-02-16 13:43:44 -08003548
3549 if (dns_log_fd == NULL) {
3550 fprintf(stderr, "Cannot open dns log: %s\n", optarg);
3551 exit(1);
3552 }
3553
3554 slirp_dns_log_fd(dns_log_fd);
3555 }
3556 break;
3557
3558
3559 case QEMU_OPTION_max_dns_conns:
3560 {
3561 int max_dns_conns = 0;
3562 if (parse_int(optarg, &max_dns_conns)) {
3563 fprintf(stderr,
3564 "qemu: syntax: -max-dns-conns max_connections\n");
3565 exit(1);
3566 }
3567 if (max_dns_conns <= 0 || max_dns_conns == LONG_MAX) {
3568 fprintf(stderr,
3569 "Invalid arg for max dns connections: %s\n",
3570 optarg);
3571 exit(1);
3572 }
3573 slirp_set_max_dns_conns(max_dns_conns);
3574 }
3575 break;
3576
3577 case QEMU_OPTION_net_forward:
3578 net_slirp_forward(optarg);
3579 break;
3580 case QEMU_OPTION_net_forward_tcp2sink:
3581 {
3582 SockAddress saddr;
3583
3584 if (parse_host_port(&saddr, optarg)) {
3585 fprintf(stderr,
3586 "Invalid ip/port %s for "
3587 "-forward-dropped-tcp2sink. "
3588 "We expect 'sink_ip:sink_port'\n",
3589 optarg);
3590 exit(1);
3591 }
3592 slirp_forward_dropped_tcp2sink(saddr.u.inet.address,
3593 saddr.u.inet.port);
3594 }
3595 break;
3596 /* -------------------------------------------------------*/
3597
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003598 case QEMU_OPTION_tb_size:
3599 tb_size = strtol(optarg, NULL, 0);
3600 if (tb_size < 0)
3601 tb_size = 0;
3602 break;
3603 case QEMU_OPTION_icount:
David Turner6a9ef172010-09-09 22:54:36 +02003604 icount_option = optarg;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003605 break;
3606 case QEMU_OPTION_incoming:
3607 incoming = optarg;
3608 break;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003609#ifdef CONFIG_XEN
3610 case QEMU_OPTION_xen_domid:
3611 xen_domid = atoi(optarg);
3612 break;
3613 case QEMU_OPTION_xen_create:
3614 xen_mode = XEN_CREATE;
3615 break;
3616 case QEMU_OPTION_xen_attach:
3617 xen_mode = XEN_ATTACH;
3618 break;
3619#endif
3620
3621
3622 case QEMU_OPTION_mic:
3623 audio_input_source = (char*)optarg;
3624 break;
3625#ifdef CONFIG_TRACE
David 'Digit' Turnera577fca2009-10-15 18:18:09 -07003626 case QEMU_OPTION_trace:
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003627 trace_filename = optarg;
3628 tracing = 1;
3629 break;
3630#if 0
3631 case QEMU_OPTION_trace_miss:
3632 trace_cache_miss = 1;
3633 break;
3634 case QEMU_OPTION_trace_addr:
3635 trace_all_addr = 1;
3636 break;
3637#endif
3638 case QEMU_OPTION_tracing:
3639 if (strcmp(optarg, "off") == 0)
3640 tracing = 0;
3641 else if (strcmp(optarg, "on") == 0 && trace_filename)
3642 tracing = 1;
3643 else {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003644 PANIC("Unexpected option to -tracing ('%s')",
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003645 optarg);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003646 }
3647 break;
3648#if 0
3649 case QEMU_OPTION_dcache_load_miss:
3650 dcache_load_miss_penalty = atoi(optarg);
3651 break;
3652 case QEMU_OPTION_dcache_store_miss:
3653 dcache_store_miss_penalty = atoi(optarg);
3654 break;
3655#endif
3656#endif
3657#ifdef CONFIG_NAND
3658 case QEMU_OPTION_nand:
3659 nand_add_dev(optarg);
3660 break;
3661#endif
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07003662 case QEMU_OPTION_android_ports:
3663 android_op_ports = (char*)optarg;
3664 break;
3665
3666 case QEMU_OPTION_android_port:
3667 android_op_port = (char*)optarg;
3668 break;
3669
3670 case QEMU_OPTION_android_report_console:
3671 android_op_report_console = (char*)optarg;
3672 break;
3673
3674 case QEMU_OPTION_http_proxy:
3675 op_http_proxy = (char*)optarg;
3676 break;
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07003677
3678 case QEMU_OPTION_charmap:
3679 op_charmap_file = (char*)optarg;
3680 break;
Vladimir Chtchetkinedd50f7d2010-07-30 09:16:41 -07003681
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -07003682 case QEMU_OPTION_android_hw:
3683 android_op_hwini = (char*)optarg;
3684 break;
Vladimir Chtchetkine13f3b6c2010-08-25 09:49:25 -07003685
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07003686 case QEMU_OPTION_dns_server:
3687 android_op_dns_server = (char*)optarg;
3688 break;
3689
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07003690 case QEMU_OPTION_radio:
3691 android_op_radio = (char*)optarg;
3692 break;
3693
3694 case QEMU_OPTION_gps:
3695 android_op_gps = (char*)optarg;
3696 break;
3697
3698 case QEMU_OPTION_audio:
3699 android_op_audio = (char*)optarg;
3700 break;
3701
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07003702 case QEMU_OPTION_cpu_delay:
3703 android_op_cpu_delay = (char*)optarg;
3704 break;
3705
Vladimir Chtchetkine13f3b6c2010-08-25 09:49:25 -07003706 case QEMU_OPTION_show_kernel:
3707 android_kmsg_init(ANDROID_KMSG_PRINT_MESSAGES);
3708 break;
3709
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003710#ifdef CONFIG_NAND_LIMITS
3711 case QEMU_OPTION_nand_limits:
3712 android_op_nand_limits = (char*)optarg;
3713 break;
3714#endif // CONFIG_NAND_LIMITS
3715
3716 case QEMU_OPTION_netspeed:
3717 android_op_netspeed = (char*)optarg;
3718 break;
3719
3720 case QEMU_OPTION_netdelay:
3721 android_op_netdelay = (char*)optarg;
3722 break;
3723
3724 case QEMU_OPTION_netfast:
3725 android_op_netfast = 1;
3726 break;
3727
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -07003728 case QEMU_OPTION_tcpdump:
3729 android_op_tcpdump = (char*)optarg;
3730 break;
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003731
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07003732 case QEMU_OPTION_boot_property:
3733 boot_property_parse_option((char*)optarg);
3734 break;
3735
3736 case QEMU_OPTION_lcd_density:
3737 android_op_lcd_density = (char*)optarg;
3738 break;
3739
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003740 case QEMU_OPTION_ui_port:
3741 android_op_ui_port = (char*)optarg;
3742 break;
3743
3744 case QEMU_OPTION_ui_settings:
3745 android_op_ui_settings = (char*)optarg;
3746 break;
3747
David 'Digit' Turnerca29fbb2011-01-02 13:17:22 +01003748 case QEMU_OPTION_audio_test_out:
3749 android_audio_test_start_out();
3750 break;
3751
Vladimir Chtchetkine90c62352011-01-13 11:24:07 -08003752 case QEMU_OPTION_android_avdname:
3753 android_op_avd_name = (char*)optarg;
3754 break;
3755
3756 case QEMU_OPTION_timezone:
3757 if (timezone_set((char*)optarg)) {
3758 fprintf(stderr, "emulator: it seems the timezone '%s' is not in zoneinfo format\n",
3759 (char*)optarg);
3760 }
3761 break;
3762
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07003763#ifdef CONFIG_MEMCHECK
3764 case QEMU_OPTION_android_memcheck:
3765 android_op_memcheck = (char*)optarg;
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07003766 /* This will set ro.kernel.memcheck system property
3767 * to memcheck's tracing flags. */
David 'Digit' Turner5f824112011-03-01 14:00:26 +01003768 stralloc_add_format(kernel_config, " memcheck=%s", android_op_memcheck);
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07003769 break;
3770#endif // CONFIG_MEMCHECK
David 'Digit' Turnerbdb6f2d2011-02-23 15:57:25 +01003771
3772 case QEMU_OPTION_snapshot_no_time_update:
3773 android_snapshot_update_time = 0;
3774 break;
David 'Digit' Turnerc1ac40a2011-06-01 16:12:04 +02003775 default:
3776 os_parse_cmd_args(popt->index, optarg);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003777 }
3778 }
3779 }
3780
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07003781 /* Initialize character map. */
3782 if (android_charmap_setup(op_charmap_file)) {
3783 if (op_charmap_file) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003784 PANIC(
3785 "Unable to initialize character map from file %s.",
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07003786 op_charmap_file);
3787 } else {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003788 PANIC(
3789 "Unable to initialize default character map.");
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07003790 }
Vladimir Chtchetkine43552dc2010-07-22 11:23:19 -07003791 }
3792
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07003793 /* If no data_dir is specified then try to find it relative to the
3794 executable path. */
3795 if (!data_dir) {
3796 data_dir = find_datadir(argv[0]);
3797 }
3798 /* If all else fails use the install patch specified when building. */
3799 if (!data_dir) {
3800 data_dir = CONFIG_QEMU_SHAREDIR;
3801 }
3802
David 'Digit' Turner2507cab2011-02-10 16:29:17 +01003803 if (!android_op_hwini) {
3804 PANIC("Missing -android-hw <file> option!");
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -07003805 }
David 'Digit' Turner2507cab2011-02-10 16:29:17 +01003806 hw_ini = iniFile_newFromFile(android_op_hwini);
3807 if (hw_ini == NULL) {
3808 PANIC("Could not find %s file.", android_op_hwini);
3809 }
David 'Digit' Turnerb64325d2011-03-22 16:07:01 +01003810
3811 androidHwConfig_init(android_hw, 0);
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -07003812 androidHwConfig_read(android_hw, hw_ini);
David 'Digit' Turnerb64325d2011-03-22 16:07:01 +01003813
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -07003814 iniFile_free(hw_ini);
David 'Digit' Turner2507cab2011-02-10 16:29:17 +01003815
3816 {
3817 int width = android_hw->hw_lcd_width;
3818 int height = android_hw->hw_lcd_height;
3819 int depth = android_hw->hw_lcd_depth;
3820
3821 /* A bit of sanity checking */
3822 if (width <= 0 || height <= 0 ||
3823 (depth != 16 && depth != 32) ||
3824 (((width|height) & 3) != 0) )
3825 {
3826 PANIC("Invalid display configuration (%d,%d,%d)",
3827 width, height, depth);
3828 }
3829 android_display_width = width;
3830 android_display_height = height;
3831 android_display_bpp = depth;
3832 }
Vladimir Chtchetkine074d1f92010-08-06 09:29:50 -07003833
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003834#ifdef CONFIG_NAND_LIMITS
3835 /* Init nand stuff. */
3836 if (android_op_nand_limits) {
3837 parse_nand_limits(android_op_nand_limits);
3838 }
3839#endif // CONFIG_NAND_LIMITS
3840
David 'Digit' Turner53eb66d2011-03-01 14:58:23 +01003841 /* Initialize AVD name from hardware configuration if needed */
3842 if (!android_op_avd_name) {
3843 if (android_hw->avd_name && *android_hw->avd_name) {
3844 android_op_avd_name = android_hw->avd_name;
3845 VERBOSE_PRINT(init,"AVD Name: %s", android_op_avd_name);
3846 }
3847 }
3848
David 'Digit' Turner40841b22011-03-01 14:04:00 +01003849 /* Initialize system partition image */
3850 {
3851 char tmp[PATH_MAX+32];
3852 const char* sysImage = android_hw->disk_systemPartition_path;
3853 const char* initImage = android_hw->disk_systemPartition_initPath;
3854 uint64_t sysBytes = android_hw->disk_systemPartition_size;
3855
3856 if (sysBytes == 0) {
3857 PANIC("Invalid system partition size: %" PRUd64, sysBytes);
3858 }
3859
3860 snprintf(tmp,sizeof(tmp),"system,size=0x%" PRUx64, sysBytes);
3861
3862 if (sysImage && *sysImage) {
3863 if (filelock_create(sysImage) == NULL) {
3864 fprintf(stderr,"WARNING: System image already in use, changes will not persist!\n");
3865 /* If there is no file= parameters, nand_add_dev will create
3866 * a temporary file to back the partition image. */
3867 } else {
3868 pstrcat(tmp,sizeof(tmp),",file=");
3869 pstrcat(tmp,sizeof(tmp),sysImage);
3870 }
3871 }
3872 if (initImage && *initImage) {
3873 if (!path_exists(initImage)) {
3874 PANIC("Invalid initial system image path: %s", initImage);
3875 }
3876 pstrcat(tmp,sizeof(tmp),",initfile=");
3877 pstrcat(tmp,sizeof(tmp),initImage);
3878 } else {
3879 PANIC("Missing initial system image path!");
3880 }
3881 nand_add_dev(tmp);
3882 }
3883
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +01003884 /* Initialize data partition image */
3885 {
3886 char tmp[PATH_MAX+32];
3887 const char* dataImage = android_hw->disk_dataPartition_path;
3888 const char* initImage = android_hw->disk_dataPartition_initPath;
3889 uint64_t dataBytes = android_hw->disk_dataPartition_size;
3890
3891 if (dataBytes == 0) {
3892 PANIC("Invalid data partition size: %" PRUd64, dataBytes);
3893 }
3894
3895 snprintf(tmp,sizeof(tmp),"userdata,size=0x%" PRUx64, dataBytes);
3896
3897 if (dataImage && *dataImage) {
3898 if (filelock_create(dataImage) == NULL) {
3899 fprintf(stderr, "WARNING: Data partition already in use. Changes will not persist!\n");
3900 /* Note: if there is no file= parameters, nand_add_dev() will
3901 * create a temporary file to back the partition image. */
3902 } else {
3903 /* Create the file if needed */
3904 if (!path_exists(dataImage)) {
David 'Digit' Turnere8ab08c2011-03-15 23:08:50 +01003905 if (path_empty_file(dataImage) < 0) {
3906 PANIC("Could not create data image file %s: %s", dataImage, strerror(errno));
3907 }
David 'Digit' Turnerfd59c332011-03-01 00:48:52 +01003908 }
3909 pstrcat(tmp, sizeof(tmp), ",file=");
3910 pstrcat(tmp, sizeof(tmp), dataImage);
3911 }
3912 }
3913 if (initImage && *initImage) {
3914 pstrcat(tmp, sizeof(tmp), ",initfile=");
3915 pstrcat(tmp, sizeof(tmp), initImage);
3916 }
3917 nand_add_dev(tmp);
3918 }
3919
David 'Digit' Turner48a3c662011-03-01 14:03:20 +01003920 /* Init SD-Card stuff. For Android, it is always hda */
3921 /* If the -hda option was used, ignore the Android-provided one */
3922 if (hda_opts == NULL) {
3923 const char* sdPath = android_hw->hw_sdCard_path;
3924 if (sdPath && *sdPath) {
3925 if (!path_exists(sdPath)) {
3926 fprintf(stderr, "WARNING: SD Card image is missing: %s\n", sdPath);
3927 } else if (filelock_create(sdPath) == NULL) {
3928 fprintf(stderr, "WARNING: SD Card image already in use: %s\n", sdPath);
3929 } else {
3930 /* Successful locking */
3931 hda_opts = drive_add(sdPath, HD_ALIAS, 0);
David 'Digit' Turner8fc3e6e2011-05-09 10:17:20 +02003932 /* Set this property of any operation involving the SD Card
3933 * will be x100 slower, due to the corresponding file being
3934 * mounted as O_DIRECT. Note that this is only 'unsafe' in
3935 * the context of an emulator crash. The data is already
3936 * synced properly when the emulator exits (either normally or through ^C).
3937 */
3938 qemu_opt_set(hda_opts, "cache", "unsafe");
David 'Digit' Turner48a3c662011-03-01 14:03:20 +01003939 }
3940 }
3941 }
3942
David 'Digit' Turner5f64b872011-02-28 23:23:05 +01003943 if (hdb_opts == NULL) {
3944 const char* spath = android_hw->disk_snapStorage_path;
3945 if (spath && *spath) {
3946 if (!path_exists(spath)) {
3947 PANIC("Snapshot storage file does not exist: %s", spath);
3948 }
3949 if (filelock_create(spath) == NULL) {
David 'Digit' Turner4297b822011-05-04 19:18:15 +02003950 PANIC("Snapshot storage already in use: %s", spath);
David 'Digit' Turner5f64b872011-02-28 23:23:05 +01003951 }
3952 hdb_opts = drive_add(spath, HD_ALIAS, 1);
David 'Digit' Turner8fc3e6e2011-05-09 10:17:20 +02003953 /* See comment above to understand why this is needed. */
David 'Digit' Turner9fb360e2011-05-04 22:01:28 +02003954 qemu_opt_set(hdb_opts, "cache", "unsafe");
David 'Digit' Turner5f64b872011-02-28 23:23:05 +01003955 }
3956 }
3957
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07003958 /* Set the VM's max heap size, passed as a boot property */
3959 if (android_hw->vm_heapSize > 0) {
3960 char tmp[64];
3961 snprintf(tmp, sizeof(tmp), "%dm", android_hw->vm_heapSize);
3962 boot_property_add("dalvik.vm.heapsize",tmp);
3963 }
3964
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003965 /* Initialize net speed and delays stuff. */
3966 if (android_parse_network_speed(android_op_netspeed) < 0 ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003967 PANIC("invalid -netspeed parameter '%s'",
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003968 android_op_netspeed);
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003969 }
3970
3971 if ( android_parse_network_latency(android_op_netdelay) < 0 ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07003972 PANIC("invalid -netdelay parameter '%s'",
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003973 android_op_netdelay);
Vladimir Chtchetkinee1316862010-08-26 09:03:54 -07003974 }
3975
3976 if (android_op_netfast) {
3977 qemu_net_download_speed = 0;
3978 qemu_net_upload_speed = 0;
3979 qemu_net_min_latency = 0;
3980 qemu_net_max_latency = 0;
3981 }
3982
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07003983 /* Initialize LCD density */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01003984 if (android_hw->hw_lcd_density) {
3985 long density = android_hw->hw_lcd_density;
3986 if (density <= 0) {
3987 PANIC("Invalid hw.lcd.density value: %ld", density);
Vladimir Chtchetkineb25bf2a2010-09-08 11:09:23 -07003988 }
3989 hwLcd_setBootProperty(density);
3990 }
3991
Vladimir Chtchetkine318f17a2010-08-27 09:09:45 -07003992 /* Initialize TCP dump */
3993 if (android_op_tcpdump) {
3994 if (qemu_tcpdump_start(android_op_tcpdump) < 0) {
3995 fprintf(stdout, "could not start packet capture: %s\n", strerror(errno));
3996 }
3997 }
3998
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07003999 /* Initialize modem */
4000 if (android_op_radio) {
4001 CharDriverState* cs = qemu_chr_open("radio", android_op_radio, NULL);
4002 if (cs == NULL) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004003 PANIC("unsupported character device specification: %s\n"
4004 "used -help-char-devices for list of available formats",
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004005 android_op_radio);
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004006 }
4007 android_qemud_set_channel( ANDROID_QEMUD_GSM, cs);
4008 } else if (android_hw->hw_gsmModem != 0 ) {
4009 if ( android_qemud_get_channel( ANDROID_QEMUD_GSM, &android_modem_cs ) < 0 ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004010 PANIC("could not initialize qemud 'gsm' channel");
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004011 }
4012 }
4013
4014 /* Initialize GPS */
4015 if (android_op_gps) {
4016 CharDriverState* cs = qemu_chr_open("gps", android_op_gps, NULL);
4017 if (cs == NULL) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004018 PANIC("unsupported character device specification: %s\n"
4019 "used -help-char-devices for list of available formats",
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004020 android_op_gps);
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004021 }
4022 android_qemud_set_channel( ANDROID_QEMUD_GPS, cs);
4023 } else if (android_hw->hw_gps != 0) {
4024 if ( android_qemud_get_channel( "gps", &android_gps_cs ) < 0 ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004025 PANIC("could not initialize qemud 'gps' channel");
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004026 }
4027 }
4028
4029 /* Initialize audio. */
4030 if (android_op_audio) {
David 'Digit' Turnercc3b2192011-05-21 00:42:27 +02004031 char temp[128];
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004032 if ( !audio_check_backend_name( 0, android_op_audio ) ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004033 PANIC("'%s' is not a valid audio output backend. see -help-audio-out",
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004034 android_op_audio);
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004035 }
David 'Digit' Turnercc3b2192011-05-21 00:42:27 +02004036 snprintf(temp, sizeof temp, "QEMU_AUDIO_DRV=%s", android_op_audio);
4037 putenv(temp);
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004038 }
4039
David 'Digit' Turner5b481492011-04-11 17:37:32 +02004040 /* Initialize OpenGLES emulation */
David 'Digit' Turnerd4d688e2011-04-26 18:09:17 +02004041 //android_hw_opengles_init();
David 'Digit' Turner5b481492011-04-11 17:37:32 +02004042
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004043 if (android_op_cpu_delay) {
4044 char* end;
4045 long delay = strtol(android_op_cpu_delay, &end, 0);
4046 if (end == NULL || *end || delay < 0 || delay > 1000 ) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004047 PANIC("option -cpu-delay must be an integer between 0 and 1000" );
Vladimir Chtchetkineb2438402010-08-24 08:55:33 -07004048 }
4049 if (delay > 0)
4050 delay = (1000-delay);
4051
4052 qemu_cpu_delay = (int) delay;
4053 }
4054
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07004055 if (android_op_dns_server) {
4056 char* x = strchr(android_op_dns_server, ',');
4057 dns_count = 0;
4058 if (x == NULL)
4059 {
4060 if ( add_dns_server( android_op_dns_server ) == 0 )
4061 dns_count = 1;
4062 }
4063 else
4064 {
4065 x = android_op_dns_server;
4066 while (*x) {
4067 char* y = strchr(x, ',');
4068
4069 if (y != NULL) {
4070 *y = 0;
4071 y++;
4072 } else {
4073 y = x + strlen(x);
4074 }
4075
4076 if (y > x && add_dns_server( x ) == 0) {
4077 dns_count += 1;
4078 }
4079 x = y;
4080 }
4081 }
4082 if (dns_count == 0)
4083 fprintf( stdout, "### WARNING: will use system default DNS server\n" );
4084 }
4085
4086 if (dns_count == 0)
4087 dns_count = slirp_get_system_dns_servers();
4088 if (dns_count) {
David 'Digit' Turner5f824112011-03-01 14:00:26 +01004089 stralloc_add_format(kernel_config, " ndns=%d", dns_count);
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07004090 }
4091
Vladimir Chtchetkineb5365f32010-08-09 13:33:57 -07004092#ifdef CONFIG_MEMCHECK
4093 if (android_op_memcheck) {
4094 memcheck_init(android_op_memcheck);
4095 }
4096#endif // CONFIG_MEMCHECK
4097
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +01004098 /* Initialize cache partition, if any */
4099 if (android_hw->disk_cachePartition != 0) {
4100 char tmp[PATH_MAX+32];
4101 const char* partPath = android_hw->disk_cachePartition_path;
David 'Digit' Turnere8ab08c2011-03-15 23:08:50 +01004102 uint64_t partSize = android_hw->disk_cachePartition_size;
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +01004103
David 'Digit' Turnere8ab08c2011-03-15 23:08:50 +01004104 snprintf(tmp,sizeof(tmp),"cache,size=0x%" PRUx64, partSize);
4105
4106 if (partPath && *partPath && strcmp(partPath, "<temp>") != 0) {
4107 if (filelock_create(partPath) == NULL) {
4108 fprintf(stderr, "WARNING: Cache partition already in use. Changes will not persist!\n");
4109 /* Note: if there is no file= parameters, nand_add_dev() will
4110 * create a temporary file to back the partition image. */
4111 } else {
4112 /* Create the file if needed */
4113 if (!path_exists(partPath)) {
4114 if (path_empty_file(partPath) < 0) {
4115 PANIC("Could not create cache image file %s: %s", partPath, strerror(errno));
4116 }
4117 }
4118 pstrcat(tmp, sizeof(tmp), ",file=");
4119 pstrcat(tmp, sizeof(tmp), partPath);
4120 }
David 'Digit' Turnerc480cca2011-02-25 16:43:34 +01004121 }
4122 nand_add_dev(tmp);
4123 }
4124
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01004125 /* We always force qemu=1 when running inside QEMU */
4126 stralloc_add_str(kernel_params, " qemu=1");
4127
4128 /* We always initialize the first serial port for the android-kmsg
4129 * character device (used to send kernel messages) */
4130 serial_hds_add_at(0, "android-kmsg");
4131 stralloc_add_str(kernel_params, " console=ttyS0");
4132
4133 /* We always initialize the second serial port for the android-qemud
4134 * character device as well */
4135 serial_hds_add_at(1, "android-qemud");
4136 stralloc_add_str(kernel_params, " android.qemud=ttyS1");
4137
David 'Digit' Turnerc1ac40a2011-06-01 16:12:04 +02004138 if (pid_file && qemu_create_pidfile(pid_file) != 0) {
4139 os_pidfile_error();
4140 exit(1);
4141 }
4142
David 'Digit' Turner36597752011-05-20 01:18:01 +02004143#if defined(CONFIG_KVM)
4144 if (kvm_allowed < 0) {
4145 kvm_allowed = kvm_check_allowed();
4146 }
4147#endif
4148
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004149#if defined(CONFIG_KVM) && defined(CONFIG_KQEMU)
4150 if (kvm_allowed && kqemu_allowed) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004151 PANIC(
4152 "You can not enable both KVM and kqemu at the same time");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004153 }
4154#endif
4155
4156 machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
4157 if (smp_cpus > machine->max_cpus) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004158 PANIC("Number of SMP cpus requested (%d), exceeds max cpus "
4159 "supported by machine `%s' (%d)", smp_cpus, machine->name,
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004160 machine->max_cpus);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004161 }
4162
4163 if (display_type == DT_NOGRAPHIC) {
4164 if (serial_device_index == 0)
4165 serial_devices[0] = "stdio";
4166 if (parallel_device_index == 0)
4167 parallel_devices[0] = "null";
4168 if (strncmp(monitor_device, "vc", 2) == 0)
4169 monitor_device = "stdio";
4170 }
4171
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004172#ifdef CONFIG_KQEMU
4173 if (smp_cpus > 1)
4174 kqemu_allowed = 0;
4175#endif
4176 if (qemu_init_main_loop()) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004177 PANIC("qemu_init_main_loop failed");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004178 }
David 'Digit' Turner0b019492011-03-01 14:02:42 +01004179
4180 if (kernel_filename == NULL) {
4181 kernel_filename = android_hw->kernel_path;
4182 }
4183 if (initrd_filename == NULL) {
4184 initrd_filename = android_hw->disk_ramdisk_path;
4185 }
4186
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004187 linux_boot = (kernel_filename != NULL);
4188 net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF;
4189
4190 if (!linux_boot && *kernel_cmdline != '\0') {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004191 PANIC("-append only allowed with -kernel option");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004192 }
4193
4194 if (!linux_boot && initrd_filename != NULL) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004195 PANIC("-initrd only allowed with -kernel option");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004196 }
4197
4198 /* boot to floppy or the default cd if no hard disk defined yet */
4199 if (!boot_devices[0]) {
4200 boot_devices = "cad";
4201 }
David 'Digit' Turnerc1ac40a2011-06-01 16:12:04 +02004202 os_set_line_buffering();
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004203
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004204 if (init_timer_alarm() < 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004205 PANIC("could not initialize alarm timer");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004206 }
David Turner6a9ef172010-09-09 22:54:36 +02004207 configure_icount(icount_option);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004208
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004209 /* init network clients */
4210 if (nb_net_clients == 0) {
4211 /* if no clients, we use a default config */
4212 net_clients[nb_net_clients++] = "nic";
4213#ifdef CONFIG_SLIRP
4214 net_clients[nb_net_clients++] = "user";
4215#endif
4216 }
4217
4218 for(i = 0;i < nb_net_clients; i++) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004219 if (net_client_parse(net_clients[i]) < 0) {
4220 PANIC("Unable to parse net clients");
4221 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004222 }
4223 net_client_check();
4224
4225#ifdef TARGET_I386
4226 /* XXX: this should be moved in the PC machine instantiation code */
4227 if (net_boot != 0) {
4228 int netroms = 0;
4229 for (i = 0; i < nb_nics && i < 4; i++) {
4230 const char *model = nd_table[i].model;
4231 char buf[1024];
4232 char *filename;
4233 if (net_boot & (1 << i)) {
4234 if (model == NULL)
4235 model = "ne2k_pci";
4236 snprintf(buf, sizeof(buf), "pxe-%s.bin", model);
4237 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, buf);
4238 if (filename && get_image_size(filename) > 0) {
4239 if (nb_option_roms >= MAX_OPTION_ROMS) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004240 PANIC("Too many option ROMs");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004241 }
4242 option_rom[nb_option_roms] = qemu_strdup(buf);
4243 nb_option_roms++;
4244 netroms++;
4245 }
4246 if (filename) {
4247 qemu_free(filename);
4248 }
4249 }
4250 }
4251 if (netroms == 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004252 PANIC("No valid PXE rom found for network device");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004253 }
4254 }
4255#endif
4256
4257 /* init the bluetooth world */
4258 for (i = 0; i < nb_bt_opts; i++)
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004259 if (bt_parse(bt_opts[i])) {
4260 PANIC("Unable to parse bluetooth options");
4261 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004262
4263 /* init the memory */
David 'Digit' Turner5377c5b2011-02-10 16:52:19 +01004264 if (ram_size == 0) {
4265 ram_size = android_hw->hw_ramSize * 1024LL * 1024;
4266 if (ram_size == 0) {
4267 ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
4268 }
4269 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004270
4271#ifdef CONFIG_KQEMU
4272 /* FIXME: This is a nasty hack because kqemu can't cope with dynamic
4273 guest ram allocation. It needs to go away. */
4274 if (kqemu_allowed) {
4275 kqemu_phys_ram_size = ram_size + 8 * 1024 * 1024 + 4 * 1024 * 1024;
4276 kqemu_phys_ram_base = qemu_vmalloc(kqemu_phys_ram_size);
4277 if (!kqemu_phys_ram_base) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004278 PANIC("Could not allocate physical memory");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004279 }
4280 }
4281#endif
4282
rich canningsd952f282011-03-01 15:40:09 -08004283#ifndef _WIN32
4284 init_qemu_clear_logs_sig();
4285#endif
4286
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004287 /* init the dynamic translator */
4288 cpu_exec_init_all(tb_size * 1024 * 1024);
4289
4290 bdrv_init();
4291
4292 /* we always create the cdrom drive, even if no disk is there */
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01004293#if 0
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004294 if (nb_drives_opt < MAX_DRIVES)
4295 drive_add(NULL, CDROM_ALIAS);
4296
4297 /* we always create at least one floppy */
4298
4299 if (nb_drives_opt < MAX_DRIVES)
4300 drive_add(NULL, FD_ALIAS, 0);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004301 /* we always create one sd slot, even if no card is in it */
4302
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01004303 if (1) {
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004304 drive_add(NULL, SD_ALIAS);
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01004305 }
4306#endif
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004307
4308 /* open the virtual block devices */
David 'Digit' Turnercb42a1b2010-12-23 02:54:08 +01004309 if (snapshot)
4310 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0);
4311 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
4312 exit(1);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004313
David Turner6a9ef172010-09-09 22:54:36 +02004314 //register_savevm("timer", 0, 2, timer_save, timer_load, &timers_state);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004315 register_savevm_live("ram", 0, 3, ram_save_live, NULL, ram_load, NULL);
4316
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004317 /* must be after terminal init, SDL library changes signal handlers */
David 'Digit' Turnerc1ac40a2011-06-01 16:12:04 +02004318 os_setup_signal_handling();
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004319
4320 /* Maintain compatibility with multiple stdio monitors */
4321 if (!strcmp(monitor_device,"stdio")) {
4322 for (i = 0; i < MAX_SERIAL_PORTS; i++) {
4323 const char *devname = serial_devices[i];
4324 if (devname && !strcmp(devname,"mon:stdio")) {
4325 monitor_device = NULL;
4326 break;
4327 } else if (devname && !strcmp(devname,"stdio")) {
4328 monitor_device = NULL;
4329 serial_devices[i] = "mon:stdio";
4330 break;
4331 }
4332 }
4333 }
4334
4335 if (nb_numa_nodes > 0) {
4336 int i;
4337
4338 if (nb_numa_nodes > smp_cpus) {
4339 nb_numa_nodes = smp_cpus;
4340 }
4341
4342 /* If no memory size if given for any node, assume the default case
4343 * and distribute the available memory equally across all nodes
4344 */
4345 for (i = 0; i < nb_numa_nodes; i++) {
4346 if (node_mem[i] != 0)
4347 break;
4348 }
4349 if (i == nb_numa_nodes) {
4350 uint64_t usedmem = 0;
4351
4352 /* On Linux, the each node's border has to be 8MB aligned,
4353 * the final node gets the rest.
4354 */
4355 for (i = 0; i < nb_numa_nodes - 1; i++) {
4356 node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1);
4357 usedmem += node_mem[i];
4358 }
4359 node_mem[i] = ram_size - usedmem;
4360 }
4361
4362 for (i = 0; i < nb_numa_nodes; i++) {
4363 if (node_cpumask[i] != 0)
4364 break;
4365 }
4366 /* assigning the VCPUs round-robin is easier to implement, guest OSes
4367 * must cope with this anyway, because there are BIOSes out there in
4368 * real machines which also use this scheme.
4369 */
4370 if (i == nb_numa_nodes) {
4371 for (i = 0; i < smp_cpus; i++) {
4372 node_cpumask[i % nb_numa_nodes] |= 1 << i;
4373 }
4374 }
4375 }
4376
4377 if (kvm_enabled()) {
4378 int ret;
4379
4380 ret = kvm_init(smp_cpus);
4381 if (ret < 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004382 PANIC("failed to initialize KVM");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004383 }
4384 }
4385
4386 if (monitor_device) {
4387 monitor_hd = qemu_chr_open("monitor", monitor_device, NULL);
4388 if (!monitor_hd) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004389 PANIC("qemu: could not open monitor device '%s'",
4390 monitor_device);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004391 }
4392 }
4393
4394 for(i = 0; i < MAX_SERIAL_PORTS; i++) {
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01004395 serial_hds_add(serial_devices[i]);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004396 }
4397
4398 for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
4399 const char *devname = parallel_devices[i];
4400 if (devname && strcmp(devname, "none")) {
4401 char label[32];
4402 snprintf(label, sizeof(label), "parallel%d", i);
4403 parallel_hds[i] = qemu_chr_open(label, devname, NULL);
4404 if (!parallel_hds[i]) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004405 PANIC("qemu: could not open parallel device '%s'",
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004406 devname);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004407 }
4408 }
4409 }
4410
4411 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
4412 const char *devname = virtio_consoles[i];
4413 if (devname && strcmp(devname, "none")) {
4414 char label[32];
4415 snprintf(label, sizeof(label), "virtcon%d", i);
4416 virtcon_hds[i] = qemu_chr_open(label, devname, NULL);
4417 if (!virtcon_hds[i]) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004418 PANIC("qemu: could not open virtio console '%s'",
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004419 devname);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004420 }
4421 }
4422 }
4423
4424 module_call_init(MODULE_INIT_DEVICE);
4425
4426
4427#ifdef CONFIG_TRACE
4428 if (trace_filename) {
4429 trace_init(trace_filename);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004430 fprintf(stderr, "-- When done tracing, exit the emulator. --\n");
4431 }
4432#endif
4433
David 'Digit' Turner2d238fd2011-03-25 10:34:47 +01004434 /* Check the CPU Architecture value */
4435#if defined(TARGET_ARM)
4436 if (strcmp(android_hw->hw_cpu_arch,"arm") != 0) {
4437 fprintf(stderr, "-- Invalid CPU architecture: %s, expected 'arm'\n",
4438 android_hw->hw_cpu_arch);
4439 exit(1);
4440 }
4441#elif defined(TARGET_X86)
4442 if (strcmp(android_hw->hw_cpu_arch,"x86") != 0) {
4443 fprintf(stderr, "-- Invalid CPU architecture: %s, expected 'x86'\n",
4444 android_hw->hw_cpu_arch);
4445 exit(1);
4446 }
4447#endif
4448
4449 /* Grab CPU model if provided in hardware.ini */
4450 if ( !cpu_model
4451 && android_hw->hw_cpu_model
4452 && android_hw->hw_cpu_model[0] != '\0')
4453 {
4454 cpu_model = android_hw->hw_cpu_model;
4455 }
4456
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07004457 /* Combine kernel command line passed from the UI with parameters
David 'Digit' Turner5f824112011-03-01 14:00:26 +01004458 * collected during initialization.
4459 *
4460 * The order is the following:
4461 * - parameters from the hw configuration (kernel.parameters)
4462 * - additionnal parameters from options (e.g. -memcheck)
4463 * - the -append parameters.
4464 */
4465 {
4466 const char* kernel_parameters;
Vladimir Chtchetkine7fbf4972010-08-11 15:30:32 -07004467
David 'Digit' Turner0b019492011-03-01 14:02:42 +01004468 if (android_hw->kernel_parameters) {
David 'Digit' Turner62c7ae52011-03-08 15:46:53 +01004469 stralloc_add_c(kernel_params, ' ');
David 'Digit' Turner0b019492011-03-01 14:02:42 +01004470 stralloc_add_str(kernel_params, android_hw->kernel_parameters);
4471 }
4472
David 'Digit' Turner5f824112011-03-01 14:00:26 +01004473 /* If not empty, kernel_config always contains a leading space */
4474 stralloc_append(kernel_params, kernel_config);
4475
4476 if (*kernel_cmdline) {
4477 stralloc_add_c(kernel_params, ' ');
4478 stralloc_add_str(kernel_params, kernel_cmdline);
4479 }
4480
David 'Digit' Turner062dd6a2011-03-01 14:50:07 +01004481 /* Remove any leading/trailing spaces */
4482 stralloc_strip(kernel_params);
4483
David 'Digit' Turner5f824112011-03-01 14:00:26 +01004484 kernel_parameters = stralloc_cstr(kernel_params);
4485 VERBOSE_PRINT(init, "Kernel parameters: %s", kernel_parameters);
4486
4487 machine->init(ram_size,
4488 boot_devices,
4489 kernel_filename,
4490 kernel_parameters,
4491 initrd_filename,
4492 cpu_model);
4493
4494 stralloc_reset(kernel_params);
4495 stralloc_reset(kernel_config);
4496 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004497
4498
4499 for (env = first_cpu; env != NULL; env = env->next_cpu) {
4500 for (i = 0; i < nb_numa_nodes; i++) {
4501 if (node_cpumask[i] & (1 << env->cpu_index)) {
4502 env->numa_node = i;
4503 }
4504 }
4505 }
4506
4507 current_machine = machine;
4508
4509 /* Set KVM's vcpu state to qemu's initial CPUState. */
4510 if (kvm_enabled()) {
4511 int ret;
4512
4513 ret = kvm_sync_vcpus();
4514 if (ret < 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004515 PANIC("failed to initialize vcpus");
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004516 }
4517 }
4518
4519 /* init USB devices */
4520 if (usb_enabled) {
4521 for(i = 0; i < usb_devices_index; i++) {
4522 if (usb_device_add(usb_devices[i], 0) < 0) {
4523 fprintf(stderr, "Warning: could not add USB device %s\n",
4524 usb_devices[i]);
4525 }
4526 }
4527 }
4528
Vladimir Chtchetkinecf755ea2011-01-12 14:38:19 -08004529 /* just use the first displaystate for the moment */
David 'Digit' Turner94702b02011-01-20 02:46:33 +01004530 ds = get_displaystate();
Vladimir Chtchetkinecf755ea2011-01-12 14:38:19 -08004531
David 'Digit' Turner2507cab2011-02-10 16:29:17 +01004532 /* Initialize display from the command line parameters. */
4533 android_display_reset(ds,
4534 android_display_width,
4535 android_display_height,
4536 android_display_bpp);
Vladimir Chtchetkinedd50f7d2010-07-30 09:16:41 -07004537
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004538 if (display_type == DT_DEFAULT) {
4539#if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
4540 display_type = DT_SDL;
4541#else
4542 display_type = DT_VNC;
4543 vnc_display = "localhost:0,to=99";
4544 show_vnc_port = 1;
4545#endif
4546 }
Vladimir Chtchetkined81e6d12010-06-15 16:46:32 -07004547
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004548
4549 switch (display_type) {
4550 case DT_NOGRAPHIC:
4551 break;
4552#if defined(CONFIG_CURSES)
4553 case DT_CURSES:
4554 curses_display_init(ds, full_screen);
4555 break;
4556#endif
Vladimir Chtchetkineeb838252010-07-15 12:27:56 -07004557#if defined(CONFIG_SDL) && !defined(CONFIG_STANDALONE_CORE)
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004558 case DT_SDL:
4559 sdl_display_init(ds, full_screen, no_frame);
4560 break;
4561#elif defined(CONFIG_COCOA)
4562 case DT_SDL:
4563 cocoa_display_init(ds, full_screen);
4564 break;
Vladimir Chtchetkine72d83df2010-12-14 09:24:02 -08004565#elif defined(CONFIG_STANDALONE_CORE)
4566 case DT_SDL:
Vladimir Chtchetkinee95660a2010-12-20 08:28:03 -08004567 coredisplay_init(ds);
Vladimir Chtchetkine72d83df2010-12-14 09:24:02 -08004568 break;
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004569#endif
4570 case DT_VNC:
4571 vnc_display_init(ds);
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004572 if (vnc_display_open(ds, vnc_display) < 0) {
4573 PANIC("Unable to initialize VNC display");
4574 }
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004575
4576 if (show_vnc_port) {
4577 printf("VNC server running on `%s'\n", vnc_display_local_addr(ds));
4578 }
4579 break;
4580 default:
4581 break;
4582 }
4583 dpy_resize(ds);
4584
4585 dcl = ds->listeners;
4586 while (dcl != NULL) {
4587 if (dcl->dpy_refresh != NULL) {
David 'Digit' Turner5973c772011-05-10 07:06:00 +02004588 ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
4589 qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004590 }
4591 dcl = dcl->next;
4592 }
4593
4594 if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
David 'Digit' Turner5973c772011-05-10 07:06:00 +02004595 nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL);
4596 qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock));
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004597 }
4598
David 'Digit' Turner94702b02011-01-20 02:46:33 +01004599 text_consoles_set_display(ds);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004600 qemu_chr_initial_reset();
4601
4602 if (monitor_device && monitor_hd)
4603 monitor_init(monitor_hd, MONITOR_USE_READLINE | MONITOR_IS_DEFAULT);
4604
4605 for(i = 0; i < MAX_SERIAL_PORTS; i++) {
4606 const char *devname = serial_devices[i];
4607 if (devname && strcmp(devname, "none")) {
4608 if (strstart(devname, "vc", 0))
4609 qemu_chr_printf(serial_hds[i], "serial%d console\r\n", i);
4610 }
4611 }
4612
4613 for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
4614 const char *devname = parallel_devices[i];
4615 if (devname && strcmp(devname, "none")) {
4616 if (strstart(devname, "vc", 0))
4617 qemu_chr_printf(parallel_hds[i], "parallel%d console\r\n", i);
4618 }
4619 }
4620
4621 for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
4622 const char *devname = virtio_consoles[i];
4623 if (virtcon_hds[i] && devname) {
4624 if (strstart(devname, "vc", 0))
4625 qemu_chr_printf(virtcon_hds[i], "virtio console%d\r\n", i);
4626 }
4627 }
4628
4629 if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004630 PANIC("qemu: could not open gdbserver on device '%s'",
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004631 gdbstub_dev);
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004632 }
4633
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004634 /* call android-specific setup function */
4635 android_emulation_setup();
4636
Vladimir Chtchetkine57584042011-01-20 16:15:30 -08004637#if !defined(CONFIG_STANDALONE_CORE)
4638 // For the standalone emulator (UI+core in one executable) we need to
4639 // set the window title here.
4640 android_emulator_set_base_port(android_base_port);
4641#endif
4642
Ot ten Thije871da2a2010-09-20 10:29:22 +01004643 if (loadvm)
4644 do_loadvm(cur_mon, loadvm);
4645
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004646 if (incoming) {
4647 autostart = 0; /* fixme how to deal with -daemonize */
4648 qemu_start_incoming_migration(incoming);
4649 }
4650
4651 if (autostart)
4652 vm_start();
4653
David 'Digit' Turnerc1ac40a2011-06-01 16:12:04 +02004654 os_setup_post();
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004655
Vladimir Chtchetkine7746af02010-10-07 05:40:39 -07004656#ifdef CONFIG_ANDROID
4657 // This will notify the UI that the core is successfuly initialized
4658 android_core_init_completed();
4659#endif // CONFIG_ANDROID
4660
David 'Digit' Turner5d8f37a2009-09-14 14:32:27 -07004661 main_loop();
4662 quit_timers();
4663 net_cleanup();
4664 android_emulation_teardown();
4665 return 0;
4666}
Vladimir Chtchetkineeb838252010-07-15 12:27:56 -07004667
4668void
4669android_emulation_teardown(void)
4670{
4671 android_charmap_done();
4672}