]>
Commit | Line | Data |
---|---|---|
0824d6fc | 1 | /* |
80cabfad | 2 | * QEMU System Emulator |
5fafdf24 | 3 | * |
68d0f70e | 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
5fafdf24 | 5 | * |
1df912cf FB |
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. | |
0824d6fc | 23 | */ |
0824d6fc | 24 | #include <unistd.h> |
0824d6fc FB |
25 | #include <fcntl.h> |
26 | #include <signal.h> | |
27 | #include <time.h> | |
0824d6fc | 28 | #include <errno.h> |
67b915a5 | 29 | #include <sys/time.h> |
c88676f8 | 30 | #include <zlib.h> |
67b915a5 | 31 | |
71e72a19 | 32 | /* Needed early for CONFIG_BSD etc. */ |
d40cdb10 BS |
33 | #include "config-host.h" |
34 | ||
67b915a5 | 35 | #ifndef _WIN32 |
5cea8590 | 36 | #include <libgen.h> |
67b915a5 | 37 | #include <sys/times.h> |
f1510b2c | 38 | #include <sys/wait.h> |
67b915a5 | 39 | #include <termios.h> |
67b915a5 | 40 | #include <sys/mman.h> |
f1510b2c | 41 | #include <sys/ioctl.h> |
24646c7e | 42 | #include <sys/resource.h> |
f1510b2c | 43 | #include <sys/socket.h> |
c94c8d64 | 44 | #include <netinet/in.h> |
24646c7e | 45 | #include <net/if.h> |
24646c7e | 46 | #include <arpa/inet.h> |
9d728e8c | 47 | #include <dirent.h> |
7c9d8e07 | 48 | #include <netdb.h> |
cb4b976b | 49 | #include <sys/select.h> |
ab6540d5 | 50 | |
71e72a19 | 51 | #ifdef CONFIG_BSD |
7d3505c5 | 52 | #include <sys/stat.h> |
a167ba50 | 53 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
7d3505c5 | 54 | #include <libutil.h> |
92c0e657 | 55 | #include <sys/sysctl.h> |
24646c7e BS |
56 | #else |
57 | #include <util.h> | |
128ab2ff | 58 | #endif |
bbe813a2 | 59 | #else |
223f0d72 | 60 | #ifdef __linux__ |
7d3505c5 FB |
61 | #include <pty.h> |
62 | #include <malloc.h> | |
bd494f4c | 63 | |
e57a8c0e | 64 | #include <linux/ppdev.h> |
5867c88a | 65 | #include <linux/parport.h> |
223f0d72 BS |
66 | #endif |
67 | #ifdef __sun__ | |
d5d10bc3 TS |
68 | #include <sys/stat.h> |
69 | #include <sys/ethernet.h> | |
70 | #include <sys/sockio.h> | |
d5d10bc3 | 71 | #include <netinet/arp.h> |
d5d10bc3 TS |
72 | #include <netinet/in_systm.h> |
73 | #include <netinet/ip.h> | |
74 | #include <netinet/ip_icmp.h> // must come after ip.h | |
75 | #include <netinet/udp.h> | |
76 | #include <netinet/tcp.h> | |
77 | #include <net/if.h> | |
78 | #include <syslog.h> | |
79 | #include <stropts.h> | |
67b915a5 | 80 | #endif |
7d3505c5 | 81 | #endif |
ec530c81 | 82 | #endif |
67b915a5 | 83 | |
9892fbfb BS |
84 | #if defined(__OpenBSD__) |
85 | #include <util.h> | |
86 | #endif | |
87 | ||
8a16d273 TS |
88 | #if defined(CONFIG_VDE) |
89 | #include <libvdeplug.h> | |
90 | #endif | |
91 | ||
67b915a5 | 92 | #ifdef _WIN32 |
49dc768d | 93 | #include <windows.h> |
67b915a5 FB |
94 | #endif |
95 | ||
73332e5c | 96 | #ifdef CONFIG_SDL |
59a36a2f | 97 | #if defined(__APPLE__) || defined(main) |
6693665a | 98 | #include <SDL.h> |
880fec5d | 99 | int qemu_main(int argc, char **argv, char **envp); |
100 | int main(int argc, char **argv) | |
101 | { | |
59a36a2f | 102 | return qemu_main(argc, argv, NULL); |
880fec5d | 103 | } |
104 | #undef main | |
105 | #define main qemu_main | |
96bcd4f8 | 106 | #endif |
73332e5c | 107 | #endif /* CONFIG_SDL */ |
0824d6fc | 108 | |
5b0753e0 FB |
109 | #ifdef CONFIG_COCOA |
110 | #undef main | |
111 | #define main qemu_main | |
112 | #endif /* CONFIG_COCOA */ | |
113 | ||
511d2b14 BS |
114 | #include "hw/hw.h" |
115 | #include "hw/boards.h" | |
116 | #include "hw/usb.h" | |
117 | #include "hw/pcmcia.h" | |
118 | #include "hw/pc.h" | |
511d2b14 BS |
119 | #include "hw/isa.h" |
120 | #include "hw/baum.h" | |
121 | #include "hw/bt.h" | |
9dd986cc | 122 | #include "hw/watchdog.h" |
b6f6e3d3 | 123 | #include "hw/smbios.h" |
e37630ca | 124 | #include "hw/xen.h" |
bd3c948d | 125 | #include "hw/qdev.h" |
45a50b16 | 126 | #include "hw/loader.h" |
5ef4efa4 | 127 | #include "bt-host.h" |
511d2b14 | 128 | #include "net.h" |
68ac40d2 | 129 | #include "net/slirp.h" |
511d2b14 BS |
130 | #include "monitor.h" |
131 | #include "console.h" | |
132 | #include "sysemu.h" | |
133 | #include "gdbstub.h" | |
134 | #include "qemu-timer.h" | |
135 | #include "qemu-char.h" | |
136 | #include "cache-utils.h" | |
137 | #include "block.h" | |
666daa68 | 138 | #include "blockdev.h" |
c163b5ca | 139 | #include "block-migration.h" |
a718acec | 140 | #include "dma.h" |
511d2b14 BS |
141 | #include "audio/audio.h" |
142 | #include "migration.h" | |
143 | #include "kvm.h" | |
d3f24367 | 144 | #include "qemu-option.h" |
7282a033 | 145 | #include "qemu-config.h" |
e78c48ec | 146 | #include "qemu-objects.h" |
59a5264b | 147 | #include "qemu-options.h" |
758e8e38 | 148 | #ifdef CONFIG_VIRTFS |
74db920c GS |
149 | #include "fsdev/qemu-fsdev.h" |
150 | #endif | |
511d2b14 | 151 | |
0824d6fc | 152 | #include "disas.h" |
fc01f7e7 | 153 | |
511d2b14 BS |
154 | #include "qemu_socket.h" |
155 | ||
d918f23e | 156 | #include "slirp/libslirp.h" |
511d2b14 | 157 | |
94b0b5ff | 158 | #include "trace.h" |
0b5538c3 | 159 | #include "simpletrace.h" |
72cf2d4f | 160 | #include "qemu-queue.h" |
296af7c9 | 161 | #include "cpus.h" |
ad96090a | 162 | #include "arch_init.h" |
72cf2d4f | 163 | |
29b0040b GH |
164 | #include "ui/qemu-spice.h" |
165 | ||
9dc63a1e BS |
166 | //#define DEBUG_NET |
167 | //#define DEBUG_SLIRP | |
330d0414 | 168 | |
1bfe856e | 169 | #define DEFAULT_RAM_SIZE 128 |
313aa567 | 170 | |
98b19252 AS |
171 | #define MAX_VIRTIO_CONSOLES 1 |
172 | ||
5cea8590 | 173 | static const char *data_dir; |
1192dad8 | 174 | const char *bios_name = NULL; |
cb5a7aa8 | 175 | enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB; |
993fbfdb | 176 | DisplayType display_type = DT_DEFAULT; |
6b62dc2d | 177 | int display_remote = 0; |
3d11d0eb | 178 | const char* keyboard_layout = NULL; |
c227f099 | 179 | ram_addr_t ram_size; |
c902760f MT |
180 | const char *mem_path = NULL; |
181 | #ifdef MAP_POPULATE | |
182 | int mem_prealloc = 0; /* force preallocation of physical target memory */ | |
183 | #endif | |
c4b1fcc0 | 184 | int nb_nics; |
7c9d8e07 | 185 | NICInfo nd_table[MAX_NICS]; |
8a7ddc38 | 186 | int vm_running; |
d399f677 | 187 | int autostart; |
8e84865e | 188 | int incoming_expected; /* Started with -incoming and waiting for incoming */ |
f6503059 AZ |
189 | static int rtc_utc = 1; |
190 | static int rtc_date_offset = -1; /* -1 means no change */ | |
6875204c | 191 | QEMUClock *rtc_clock; |
64465297 | 192 | int vga_interface_type = VGA_NONE; |
dbed7e40 | 193 | static int full_screen = 0; |
634a21f6 | 194 | #ifdef CONFIG_SDL |
dbed7e40 | 195 | static int no_frame = 0; |
634a21f6 | 196 | #endif |
667accab | 197 | int no_quit = 0; |
8d11df9e | 198 | CharDriverState *serial_hds[MAX_SERIAL_PORTS]; |
6508fe59 | 199 | CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; |
9ede2fde | 200 | CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; |
a09db21f | 201 | int win2k_install_hack = 0; |
73822ec8 | 202 | int rtc_td_hack = 0; |
bb36d470 | 203 | int usb_enabled = 0; |
1b530a6d | 204 | int singlestep = 0; |
6a00d601 | 205 | int smp_cpus = 1; |
6be68d7e | 206 | int max_cpus = 0; |
dc6b1c09 AP |
207 | int smp_cores = 1; |
208 | int smp_threads = 1; | |
821601ea | 209 | #ifdef CONFIG_VNC |
73fc9742 | 210 | const char *vnc_display; |
821601ea | 211 | #endif |
6515b203 | 212 | int acpi_enabled = 1; |
16b29ae1 | 213 | int no_hpet = 0; |
52ca8d6a | 214 | int fd_bootchk = 1; |
d1beab82 | 215 | int no_reboot = 0; |
b2f76161 | 216 | int no_shutdown = 0; |
9467cd46 | 217 | int cursor_hide = 1; |
a171fe39 | 218 | int graphic_rotate = 0; |
6b35e7bf | 219 | uint8_t irq0override = 1; |
09aaa160 | 220 | const char *watchdog; |
2e55e842 | 221 | QEMUOptionRom option_rom[MAX_OPTION_ROMS]; |
9ae02555 | 222 | int nb_option_roms; |
8e71621f | 223 | int semihosting_enabled = 0; |
2b8f2d41 | 224 | int old_param = 0; |
c35734b2 | 225 | const char *qemu_name; |
3780e197 | 226 | int alt_grab = 0; |
0ca9f8a4 | 227 | int ctrl_grab = 0; |
66508601 BS |
228 | unsigned int nb_prom_envs = 0; |
229 | const char *prom_envs[MAX_PROM_ENVS]; | |
95387491 | 230 | int boot_menu; |
3d3b8303 WX |
231 | uint8_t *boot_splash_filedata; |
232 | int boot_splash_filedata_size; | |
233 | uint8_t qemu_extra_params_fw[2]; | |
0824d6fc | 234 | |
1ca4d09a GN |
235 | typedef struct FWBootEntry FWBootEntry; |
236 | ||
237 | struct FWBootEntry { | |
238 | QTAILQ_ENTRY(FWBootEntry) link; | |
239 | int32_t bootindex; | |
240 | DeviceState *dev; | |
241 | char *suffix; | |
242 | }; | |
243 | ||
244 | QTAILQ_HEAD(, FWBootEntry) fw_boot_order = QTAILQ_HEAD_INITIALIZER(fw_boot_order); | |
245 | ||
268a362c AL |
246 | int nb_numa_nodes; |
247 | uint64_t node_mem[MAX_NODES]; | |
248 | uint64_t node_cpumask[MAX_NODES]; | |
249 | ||
9043b62d | 250 | static QEMUTimer *nographic_timer; |
ee5605e5 | 251 | |
8fcb1b90 BS |
252 | uint8_t qemu_uuid[16]; |
253 | ||
76e30d0f JK |
254 | static QEMUBootSetHandler *boot_set_handler; |
255 | static void *boot_set_opaque; | |
256 | ||
fd42deeb GH |
257 | static NotifierList exit_notifiers = |
258 | NOTIFIER_LIST_INITIALIZER(exit_notifiers); | |
259 | ||
4cab946a GN |
260 | static NotifierList machine_init_done_notifiers = |
261 | NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); | |
262 | ||
303d4e86 | 263 | static int tcg_allowed = 1; |
d745bef8 | 264 | int kvm_allowed = 0; |
3285cf4f | 265 | int xen_allowed = 0; |
d745bef8 BS |
266 | uint32_t xen_domid; |
267 | enum xen_mode xen_mode = XEN_EMULATE; | |
268 | ||
998bbd74 | 269 | static int default_serial = 1; |
6a5e8b0e | 270 | static int default_parallel = 1; |
986c5f78 | 271 | static int default_virtcon = 1; |
abdeed06 | 272 | static int default_monitor = 1; |
64465297 | 273 | static int default_vga = 1; |
ac33f8fa GH |
274 | static int default_floppy = 1; |
275 | static int default_cdrom = 1; | |
276 | static int default_sdcard = 1; | |
998bbd74 GH |
277 | |
278 | static struct { | |
279 | const char *driver; | |
280 | int *flag; | |
281 | } default_list[] = { | |
6a5e8b0e GH |
282 | { .driver = "isa-serial", .flag = &default_serial }, |
283 | { .driver = "isa-parallel", .flag = &default_parallel }, | |
d8bcbabf | 284 | { .driver = "isa-fdc", .flag = &default_floppy }, |
af6bf132 MA |
285 | { .driver = "ide-cd", .flag = &default_cdrom }, |
286 | { .driver = "ide-hd", .flag = &default_cdrom }, | |
d8bcbabf | 287 | { .driver = "ide-drive", .flag = &default_cdrom }, |
af6bf132 | 288 | { .driver = "scsi-cd", .flag = &default_cdrom }, |
392ecf54 AS |
289 | { .driver = "virtio-serial-pci", .flag = &default_virtcon }, |
290 | { .driver = "virtio-serial-s390", .flag = &default_virtcon }, | |
291 | { .driver = "virtio-serial", .flag = &default_virtcon }, | |
64465297 | 292 | { .driver = "VGA", .flag = &default_vga }, |
69fd02ee GH |
293 | { .driver = "cirrus-vga", .flag = &default_vga }, |
294 | { .driver = "vmware-svga", .flag = &default_vga }, | |
0826c710 | 295 | { .driver = "isa-vga", .flag = &default_vga }, |
42138043 | 296 | { .driver = "qxl-vga", .flag = &default_vga }, |
998bbd74 GH |
297 | }; |
298 | ||
3d3b8303 WX |
299 | static void res_free(void) |
300 | { | |
301 | if (boot_splash_filedata != NULL) { | |
302 | qemu_free(boot_splash_filedata); | |
303 | boot_splash_filedata = NULL; | |
304 | } | |
305 | } | |
306 | ||
998bbd74 GH |
307 | static int default_driver_check(QemuOpts *opts, void *opaque) |
308 | { | |
309 | const char *driver = qemu_opt_get(opts, "driver"); | |
310 | int i; | |
311 | ||
312 | if (!driver) | |
313 | return 0; | |
314 | for (i = 0; i < ARRAY_SIZE(default_list); i++) { | |
315 | if (strcmp(default_list[i].driver, driver) != 0) | |
316 | continue; | |
317 | *(default_list[i].flag) = 0; | |
318 | } | |
319 | return 0; | |
320 | } | |
321 | ||
8f0056b7 PB |
322 | /***********************************************************/ |
323 | /* real time host monotonic timer */ | |
09b26c5e | 324 | |
f6503059 AZ |
325 | /***********************************************************/ |
326 | /* host time/date access */ | |
327 | void qemu_get_timedate(struct tm *tm, int offset) | |
328 | { | |
329 | time_t ti; | |
330 | struct tm *ret; | |
331 | ||
332 | time(&ti); | |
333 | ti += offset; | |
334 | if (rtc_date_offset == -1) { | |
335 | if (rtc_utc) | |
336 | ret = gmtime(&ti); | |
337 | else | |
338 | ret = localtime(&ti); | |
339 | } else { | |
340 | ti -= rtc_date_offset; | |
341 | ret = gmtime(&ti); | |
342 | } | |
343 | ||
344 | memcpy(tm, ret, sizeof(struct tm)); | |
345 | } | |
346 | ||
347 | int qemu_timedate_diff(struct tm *tm) | |
348 | { | |
349 | time_t seconds; | |
350 | ||
351 | if (rtc_date_offset == -1) | |
352 | if (rtc_utc) | |
353 | seconds = mktimegm(tm); | |
354 | else | |
355 | seconds = mktime(tm); | |
356 | else | |
357 | seconds = mktimegm(tm) + rtc_date_offset; | |
358 | ||
359 | return seconds - time(NULL); | |
360 | } | |
361 | ||
80cd3478 LC |
362 | void rtc_change_mon_event(struct tm *tm) |
363 | { | |
364 | QObject *data; | |
365 | ||
366 | data = qobject_from_jsonf("{ 'offset': %d }", qemu_timedate_diff(tm)); | |
367 | monitor_protocol_event(QEVENT_RTC_CHANGE, data); | |
368 | qobject_decref(data); | |
369 | } | |
370 | ||
1ed2fc1f JK |
371 | static void configure_rtc_date_offset(const char *startdate, int legacy) |
372 | { | |
373 | time_t rtc_start_date; | |
374 | struct tm tm; | |
375 | ||
376 | if (!strcmp(startdate, "now") && legacy) { | |
377 | rtc_date_offset = -1; | |
378 | } else { | |
379 | if (sscanf(startdate, "%d-%d-%dT%d:%d:%d", | |
380 | &tm.tm_year, | |
381 | &tm.tm_mon, | |
382 | &tm.tm_mday, | |
383 | &tm.tm_hour, | |
384 | &tm.tm_min, | |
385 | &tm.tm_sec) == 6) { | |
386 | /* OK */ | |
387 | } else if (sscanf(startdate, "%d-%d-%d", | |
388 | &tm.tm_year, | |
389 | &tm.tm_mon, | |
390 | &tm.tm_mday) == 3) { | |
391 | tm.tm_hour = 0; | |
392 | tm.tm_min = 0; | |
393 | tm.tm_sec = 0; | |
394 | } else { | |
395 | goto date_fail; | |
396 | } | |
397 | tm.tm_year -= 1900; | |
398 | tm.tm_mon--; | |
399 | rtc_start_date = mktimegm(&tm); | |
400 | if (rtc_start_date == -1) { | |
401 | date_fail: | |
402 | fprintf(stderr, "Invalid date format. Valid formats are:\n" | |
403 | "'2006-06-17T16:01:21' or '2006-06-17'\n"); | |
404 | exit(1); | |
405 | } | |
406 | rtc_date_offset = time(NULL) - rtc_start_date; | |
407 | } | |
408 | } | |
409 | ||
410 | static void configure_rtc(QemuOpts *opts) | |
411 | { | |
412 | const char *value; | |
413 | ||
414 | value = qemu_opt_get(opts, "base"); | |
415 | if (value) { | |
416 | if (!strcmp(value, "utc")) { | |
417 | rtc_utc = 1; | |
418 | } else if (!strcmp(value, "localtime")) { | |
419 | rtc_utc = 0; | |
420 | } else { | |
421 | configure_rtc_date_offset(value, 0); | |
422 | } | |
423 | } | |
6875204c JK |
424 | value = qemu_opt_get(opts, "clock"); |
425 | if (value) { | |
426 | if (!strcmp(value, "host")) { | |
427 | rtc_clock = host_clock; | |
428 | } else if (!strcmp(value, "vm")) { | |
429 | rtc_clock = vm_clock; | |
430 | } else { | |
431 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); | |
432 | exit(1); | |
433 | } | |
434 | } | |
1ed2fc1f JK |
435 | value = qemu_opt_get(opts, "driftfix"); |
436 | if (value) { | |
7e4c0336 | 437 | if (!strcmp(value, "slew")) { |
1ed2fc1f | 438 | rtc_td_hack = 1; |
7e4c0336 | 439 | } else if (!strcmp(value, "none")) { |
1ed2fc1f JK |
440 | rtc_td_hack = 0; |
441 | } else { | |
442 | fprintf(stderr, "qemu: invalid option value '%s'\n", value); | |
443 | exit(1); | |
444 | } | |
445 | } | |
1ed2fc1f JK |
446 | } |
447 | ||
1ae26a18 AZ |
448 | /***********************************************************/ |
449 | /* Bluetooth support */ | |
450 | static int nb_hcis; | |
451 | static int cur_hci; | |
452 | static struct HCIInfo *hci_table[MAX_NICS]; | |
dc72ac14 | 453 | |
1ae26a18 AZ |
454 | static struct bt_vlan_s { |
455 | struct bt_scatternet_s net; | |
456 | int id; | |
457 | struct bt_vlan_s *next; | |
458 | } *first_bt_vlan; | |
459 | ||
460 | /* find or alloc a new bluetooth "VLAN" */ | |
674bb261 | 461 | static struct bt_scatternet_s *qemu_find_bt_vlan(int id) |
1ae26a18 AZ |
462 | { |
463 | struct bt_vlan_s **pvlan, *vlan; | |
464 | for (vlan = first_bt_vlan; vlan != NULL; vlan = vlan->next) { | |
465 | if (vlan->id == id) | |
466 | return &vlan->net; | |
467 | } | |
468 | vlan = qemu_mallocz(sizeof(struct bt_vlan_s)); | |
469 | vlan->id = id; | |
470 | pvlan = &first_bt_vlan; | |
471 | while (*pvlan != NULL) | |
472 | pvlan = &(*pvlan)->next; | |
473 | *pvlan = vlan; | |
474 | return &vlan->net; | |
475 | } | |
476 | ||
477 | static void null_hci_send(struct HCIInfo *hci, const uint8_t *data, int len) | |
478 | { | |
479 | } | |
480 | ||
481 | static int null_hci_addr_set(struct HCIInfo *hci, const uint8_t *bd_addr) | |
482 | { | |
483 | return -ENOTSUP; | |
484 | } | |
485 | ||
486 | static struct HCIInfo null_hci = { | |
487 | .cmd_send = null_hci_send, | |
488 | .sco_send = null_hci_send, | |
489 | .acl_send = null_hci_send, | |
490 | .bdaddr_set = null_hci_addr_set, | |
491 | }; | |
492 | ||
493 | struct HCIInfo *qemu_next_hci(void) | |
494 | { | |
495 | if (cur_hci == nb_hcis) | |
496 | return &null_hci; | |
497 | ||
498 | return hci_table[cur_hci++]; | |
499 | } | |
500 | ||
dc72ac14 AZ |
501 | static struct HCIInfo *hci_init(const char *str) |
502 | { | |
503 | char *endp; | |
504 | struct bt_scatternet_s *vlan = 0; | |
505 | ||
506 | if (!strcmp(str, "null")) | |
507 | /* null */ | |
508 | return &null_hci; | |
509 | else if (!strncmp(str, "host", 4) && (str[4] == '\0' || str[4] == ':')) | |
510 | /* host[:hciN] */ | |
511 | return bt_host_hci(str[4] ? str + 5 : "hci0"); | |
512 | else if (!strncmp(str, "hci", 3)) { | |
513 | /* hci[,vlan=n] */ | |
514 | if (str[3]) { | |
515 | if (!strncmp(str + 3, ",vlan=", 6)) { | |
516 | vlan = qemu_find_bt_vlan(strtol(str + 9, &endp, 0)); | |
517 | if (*endp) | |
518 | vlan = 0; | |
519 | } | |
520 | } else | |
521 | vlan = qemu_find_bt_vlan(0); | |
522 | if (vlan) | |
523 | return bt_new_hci(vlan); | |
524 | } | |
525 | ||
526 | fprintf(stderr, "qemu: Unknown bluetooth HCI `%s'.\n", str); | |
527 | ||
528 | return 0; | |
529 | } | |
530 | ||
531 | static int bt_hci_parse(const char *str) | |
532 | { | |
533 | struct HCIInfo *hci; | |
c227f099 | 534 | bdaddr_t bdaddr; |
dc72ac14 AZ |
535 | |
536 | if (nb_hcis >= MAX_NICS) { | |
537 | fprintf(stderr, "qemu: Too many bluetooth HCIs (max %i).\n", MAX_NICS); | |
538 | return -1; | |
539 | } | |
540 | ||
541 | hci = hci_init(str); | |
542 | if (!hci) | |
543 | return -1; | |
544 | ||
545 | bdaddr.b[0] = 0x52; | |
546 | bdaddr.b[1] = 0x54; | |
547 | bdaddr.b[2] = 0x00; | |
548 | bdaddr.b[3] = 0x12; | |
549 | bdaddr.b[4] = 0x34; | |
550 | bdaddr.b[5] = 0x56 + nb_hcis; | |
551 | hci->bdaddr_set(hci, bdaddr.b); | |
552 | ||
553 | hci_table[nb_hcis++] = hci; | |
554 | ||
555 | return 0; | |
556 | } | |
557 | ||
558 | static void bt_vhci_add(int vlan_id) | |
559 | { | |
560 | struct bt_scatternet_s *vlan = qemu_find_bt_vlan(vlan_id); | |
561 | ||
562 | if (!vlan->slave) | |
563 | fprintf(stderr, "qemu: warning: adding a VHCI to " | |
564 | "an empty scatternet %i\n", vlan_id); | |
565 | ||
566 | bt_vhci_init(bt_new_hci(vlan)); | |
567 | } | |
568 | ||
569 | static struct bt_device_s *bt_device_add(const char *opt) | |
570 | { | |
571 | struct bt_scatternet_s *vlan; | |
572 | int vlan_id = 0; | |
573 | char *endp = strstr(opt, ",vlan="); | |
574 | int len = (endp ? endp - opt : strlen(opt)) + 1; | |
575 | char devname[10]; | |
576 | ||
577 | pstrcpy(devname, MIN(sizeof(devname), len), opt); | |
578 | ||
579 | if (endp) { | |
580 | vlan_id = strtol(endp + 6, &endp, 0); | |
581 | if (*endp) { | |
582 | fprintf(stderr, "qemu: unrecognised bluetooth vlan Id\n"); | |
583 | return 0; | |
584 | } | |
585 | } | |
586 | ||
587 | vlan = qemu_find_bt_vlan(vlan_id); | |
588 | ||
589 | if (!vlan->slave) | |
590 | fprintf(stderr, "qemu: warning: adding a slave device to " | |
591 | "an empty scatternet %i\n", vlan_id); | |
592 | ||
593 | if (!strcmp(devname, "keyboard")) | |
594 | return bt_keyboard_init(vlan); | |
595 | ||
596 | fprintf(stderr, "qemu: unsupported bluetooth device `%s'\n", devname); | |
597 | return 0; | |
598 | } | |
599 | ||
600 | static int bt_parse(const char *opt) | |
601 | { | |
602 | const char *endp, *p; | |
603 | int vlan; | |
604 | ||
605 | if (strstart(opt, "hci", &endp)) { | |
606 | if (!*endp || *endp == ',') { | |
607 | if (*endp) | |
608 | if (!strstart(endp, ",vlan=", 0)) | |
609 | opt = endp + 1; | |
610 | ||
611 | return bt_hci_parse(opt); | |
612 | } | |
613 | } else if (strstart(opt, "vhci", &endp)) { | |
614 | if (!*endp || *endp == ',') { | |
615 | if (*endp) { | |
616 | if (strstart(endp, ",vlan=", &p)) { | |
617 | vlan = strtol(p, (char **) &endp, 0); | |
618 | if (*endp) { | |
619 | fprintf(stderr, "qemu: bad scatternet '%s'\n", p); | |
620 | return 1; | |
621 | } | |
622 | } else { | |
623 | fprintf(stderr, "qemu: bad parameter '%s'\n", endp + 1); | |
624 | return 1; | |
625 | } | |
626 | } else | |
627 | vlan = 0; | |
628 | ||
629 | bt_vhci_add(vlan); | |
630 | return 0; | |
631 | } | |
632 | } else if (strstart(opt, "device:", &endp)) | |
633 | return !bt_device_add(endp); | |
634 | ||
635 | fprintf(stderr, "qemu: bad bluetooth parameter '%s'\n", opt); | |
636 | return 1; | |
637 | } | |
638 | ||
1ae26a18 AZ |
639 | /***********************************************************/ |
640 | /* QEMU Block devices */ | |
641 | ||
2292ddae MA |
642 | #define HD_OPTS "media=disk" |
643 | #define CDROM_OPTS "media=cdrom" | |
644 | #define FD_OPTS "" | |
645 | #define PFLASH_OPTS "" | |
646 | #define MTD_OPTS "" | |
647 | #define SD_OPTS "" | |
e4bcb14c | 648 | |
9dfd7c7a GH |
649 | static int drive_init_func(QemuOpts *opts, void *opaque) |
650 | { | |
a803cb8e | 651 | int *use_scsi = opaque; |
9dfd7c7a | 652 | |
319ae529 | 653 | return drive_init(opts, *use_scsi) == NULL; |
9dfd7c7a GH |
654 | } |
655 | ||
656 | static int drive_enable_snapshot(QemuOpts *opts, void *opaque) | |
657 | { | |
658 | if (NULL == qemu_opt_get(opts, "snapshot")) { | |
659 | qemu_opt_set(opts, "snapshot", "on"); | |
660 | } | |
661 | return 0; | |
662 | } | |
663 | ||
4e5d9b57 MA |
664 | static void default_drive(int enable, int snapshot, int use_scsi, |
665 | BlockInterfaceType type, int index, | |
666 | const char *optstr) | |
667 | { | |
668 | QemuOpts *opts; | |
669 | ||
670 | if (type == IF_DEFAULT) { | |
671 | type = use_scsi ? IF_SCSI : IF_IDE; | |
672 | } | |
673 | ||
674 | if (!enable || drive_get_by_index(type, index)) { | |
675 | return; | |
676 | } | |
677 | ||
678 | opts = drive_add(type, index, NULL, optstr); | |
679 | if (snapshot) { | |
680 | drive_enable_snapshot(opts, NULL); | |
681 | } | |
319ae529 | 682 | if (!drive_init(opts, use_scsi)) { |
4e5d9b57 MA |
683 | exit(1); |
684 | } | |
685 | } | |
686 | ||
76e30d0f JK |
687 | void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque) |
688 | { | |
689 | boot_set_handler = func; | |
690 | boot_set_opaque = opaque; | |
691 | } | |
692 | ||
693 | int qemu_boot_set(const char *boot_devices) | |
694 | { | |
695 | if (!boot_set_handler) { | |
696 | return -EINVAL; | |
697 | } | |
698 | return boot_set_handler(boot_set_opaque, boot_devices); | |
699 | } | |
700 | ||
4e9e9d6e | 701 | static void validate_bootdevices(char *devices) |
ef3adf68 JK |
702 | { |
703 | /* We just do some generic consistency checks */ | |
704 | const char *p; | |
705 | int bitmap = 0; | |
706 | ||
707 | for (p = devices; *p != '\0'; p++) { | |
708 | /* Allowed boot devices are: | |
709 | * a-b: floppy disk drives | |
710 | * c-f: IDE disk drives | |
711 | * g-m: machine implementation dependant drives | |
712 | * n-p: network devices | |
713 | * It's up to each machine implementation to check if the given boot | |
714 | * devices match the actual hardware implementation and firmware | |
715 | * features. | |
716 | */ | |
717 | if (*p < 'a' || *p > 'p') { | |
718 | fprintf(stderr, "Invalid boot device '%c'\n", *p); | |
719 | exit(1); | |
720 | } | |
721 | if (bitmap & (1 << (*p - 'a'))) { | |
722 | fprintf(stderr, "Boot device '%c' was given twice\n", *p); | |
723 | exit(1); | |
724 | } | |
725 | bitmap |= 1 << (*p - 'a'); | |
726 | } | |
ef3adf68 JK |
727 | } |
728 | ||
e0f084bf JK |
729 | static void restore_boot_devices(void *opaque) |
730 | { | |
731 | char *standard_boot_devices = opaque; | |
37905d6a AW |
732 | static int first = 1; |
733 | ||
734 | /* Restore boot order and remove ourselves after the first boot */ | |
735 | if (first) { | |
736 | first = 0; | |
737 | return; | |
738 | } | |
e0f084bf JK |
739 | |
740 | qemu_boot_set(standard_boot_devices); | |
741 | ||
742 | qemu_unregister_reset(restore_boot_devices, standard_boot_devices); | |
743 | qemu_free(standard_boot_devices); | |
744 | } | |
745 | ||
1ca4d09a GN |
746 | void add_boot_device_path(int32_t bootindex, DeviceState *dev, |
747 | const char *suffix) | |
748 | { | |
749 | FWBootEntry *node, *i; | |
750 | ||
751 | if (bootindex < 0) { | |
752 | return; | |
753 | } | |
754 | ||
755 | assert(dev != NULL || suffix != NULL); | |
756 | ||
757 | node = qemu_mallocz(sizeof(FWBootEntry)); | |
758 | node->bootindex = bootindex; | |
4fef930a | 759 | node->suffix = suffix ? qemu_strdup(suffix) : NULL; |
1ca4d09a GN |
760 | node->dev = dev; |
761 | ||
762 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
763 | if (i->bootindex == bootindex) { | |
764 | fprintf(stderr, "Two devices with same boot index %d\n", bootindex); | |
765 | exit(1); | |
766 | } else if (i->bootindex < bootindex) { | |
767 | continue; | |
768 | } | |
769 | QTAILQ_INSERT_BEFORE(i, node, link); | |
770 | return; | |
771 | } | |
772 | QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); | |
773 | } | |
774 | ||
962630f2 GN |
775 | /* |
776 | * This function returns null terminated string that consist of new line | |
71785aba | 777 | * separated device paths. |
962630f2 GN |
778 | * |
779 | * memory pointed by "size" is assigned total length of the array in bytes | |
780 | * | |
781 | */ | |
782 | char *get_boot_devices_list(uint32_t *size) | |
783 | { | |
784 | FWBootEntry *i; | |
785 | uint32_t total = 0; | |
786 | char *list = NULL; | |
787 | ||
788 | QTAILQ_FOREACH(i, &fw_boot_order, link) { | |
789 | char *devpath = NULL, *bootpath; | |
790 | int len; | |
791 | ||
792 | if (i->dev) { | |
793 | devpath = qdev_get_fw_dev_path(i->dev); | |
794 | assert(devpath); | |
795 | } | |
796 | ||
797 | if (i->suffix && devpath) { | |
4fd37a98 BS |
798 | size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1; |
799 | ||
800 | bootpath = qemu_malloc(bootpathlen); | |
801 | snprintf(bootpath, bootpathlen, "%s%s", devpath, i->suffix); | |
962630f2 GN |
802 | qemu_free(devpath); |
803 | } else if (devpath) { | |
804 | bootpath = devpath; | |
805 | } else { | |
4fef930a | 806 | bootpath = qemu_strdup(i->suffix); |
962630f2 GN |
807 | assert(bootpath); |
808 | } | |
809 | ||
810 | if (total) { | |
811 | list[total-1] = '\n'; | |
812 | } | |
813 | len = strlen(bootpath) + 1; | |
814 | list = qemu_realloc(list, total + len); | |
815 | memcpy(&list[total], bootpath, len); | |
816 | total += len; | |
817 | qemu_free(bootpath); | |
818 | } | |
819 | ||
820 | *size = total; | |
821 | ||
822 | return list; | |
823 | } | |
824 | ||
268a362c AL |
825 | static void numa_add(const char *optarg) |
826 | { | |
827 | char option[128]; | |
828 | char *endptr; | |
829 | unsigned long long value, endvalue; | |
830 | int nodenr; | |
831 | ||
832 | optarg = get_opt_name(option, 128, optarg, ',') + 1; | |
833 | if (!strcmp(option, "node")) { | |
834 | if (get_param_value(option, 128, "nodeid", optarg) == 0) { | |
835 | nodenr = nb_numa_nodes; | |
836 | } else { | |
837 | nodenr = strtoull(option, NULL, 10); | |
838 | } | |
839 | ||
840 | if (get_param_value(option, 128, "mem", optarg) == 0) { | |
841 | node_mem[nodenr] = 0; | |
842 | } else { | |
70b4f4bb | 843 | int64_t sval; |
9f9b17a4 JS |
844 | sval = strtosz(option, NULL); |
845 | if (sval < 0) { | |
846 | fprintf(stderr, "qemu: invalid numa mem size: %s\n", optarg); | |
847 | exit(1); | |
268a362c | 848 | } |
9f9b17a4 | 849 | node_mem[nodenr] = sval; |
268a362c AL |
850 | } |
851 | if (get_param_value(option, 128, "cpus", optarg) == 0) { | |
852 | node_cpumask[nodenr] = 0; | |
853 | } else { | |
854 | value = strtoull(option, &endptr, 10); | |
855 | if (value >= 64) { | |
856 | value = 63; | |
857 | fprintf(stderr, "only 64 CPUs in NUMA mode supported.\n"); | |
858 | } else { | |
859 | if (*endptr == '-') { | |
860 | endvalue = strtoull(endptr+1, &endptr, 10); | |
861 | if (endvalue >= 63) { | |
862 | endvalue = 62; | |
863 | fprintf(stderr, | |
864 | "only 63 CPUs in NUMA mode supported.\n"); | |
865 | } | |
0dfbd514 | 866 | value = (2ULL << endvalue) - (1ULL << value); |
268a362c | 867 | } else { |
0dfbd514 | 868 | value = 1ULL << value; |
268a362c AL |
869 | } |
870 | } | |
871 | node_cpumask[nodenr] = value; | |
872 | } | |
873 | nb_numa_nodes++; | |
874 | } | |
875 | return; | |
876 | } | |
877 | ||
dc6b1c09 AP |
878 | static void smp_parse(const char *optarg) |
879 | { | |
880 | int smp, sockets = 0, threads = 0, cores = 0; | |
881 | char *endptr; | |
882 | char option[128]; | |
883 | ||
884 | smp = strtoul(optarg, &endptr, 10); | |
885 | if (endptr != optarg) { | |
886 | if (*endptr == ',') { | |
887 | endptr++; | |
888 | } | |
889 | } | |
890 | if (get_param_value(option, 128, "sockets", endptr) != 0) | |
891 | sockets = strtoull(option, NULL, 10); | |
892 | if (get_param_value(option, 128, "cores", endptr) != 0) | |
893 | cores = strtoull(option, NULL, 10); | |
894 | if (get_param_value(option, 128, "threads", endptr) != 0) | |
895 | threads = strtoull(option, NULL, 10); | |
896 | if (get_param_value(option, 128, "maxcpus", endptr) != 0) | |
897 | max_cpus = strtoull(option, NULL, 10); | |
898 | ||
899 | /* compute missing values, prefer sockets over cores over threads */ | |
900 | if (smp == 0 || sockets == 0) { | |
901 | sockets = sockets > 0 ? sockets : 1; | |
902 | cores = cores > 0 ? cores : 1; | |
903 | threads = threads > 0 ? threads : 1; | |
904 | if (smp == 0) { | |
905 | smp = cores * threads * sockets; | |
dc6b1c09 AP |
906 | } |
907 | } else { | |
908 | if (cores == 0) { | |
909 | threads = threads > 0 ? threads : 1; | |
910 | cores = smp / (sockets * threads); | |
911 | } else { | |
dca98169 | 912 | threads = smp / (cores * sockets); |
dc6b1c09 AP |
913 | } |
914 | } | |
915 | smp_cpus = smp; | |
916 | smp_cores = cores > 0 ? cores : 1; | |
917 | smp_threads = threads > 0 ? threads : 1; | |
918 | if (max_cpus == 0) | |
919 | max_cpus = smp_cpus; | |
920 | } | |
921 | ||
a594cfbf FB |
922 | /***********************************************************/ |
923 | /* USB devices */ | |
924 | ||
fb08000c | 925 | static int usb_device_add(const char *devname) |
a594cfbf FB |
926 | { |
927 | const char *p; | |
a5d2f727 | 928 | USBDevice *dev = NULL; |
a594cfbf | 929 | |
a5d2f727 | 930 | if (!usb_enabled) |
a594cfbf FB |
931 | return -1; |
932 | ||
0958b4cc GH |
933 | /* drivers with .usbdevice_name entry in USBDeviceInfo */ |
934 | dev = usbdevice_create(devname); | |
935 | if (dev) | |
936 | goto done; | |
937 | ||
a5d2f727 | 938 | /* the other ones */ |
e447fc63 GH |
939 | #ifndef CONFIG_LINUX |
940 | /* only the linux version is qdev-ified, usb-bsd still needs this */ | |
a594cfbf FB |
941 | if (strstart(devname, "host:", &p)) { |
942 | dev = usb_host_device_open(p); | |
e447fc63 GH |
943 | } else |
944 | #endif | |
945 | if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) { | |
dc72ac14 AZ |
946 | dev = usb_bt_init(devname[2] ? hci_init(p) : |
947 | bt_new_hci(qemu_find_bt_vlan(0))); | |
a594cfbf FB |
948 | } else { |
949 | return -1; | |
950 | } | |
0d92ed30 PB |
951 | if (!dev) |
952 | return -1; | |
953 | ||
a5d2f727 | 954 | done: |
a594cfbf FB |
955 | return 0; |
956 | } | |
957 | ||
1f3870ab AL |
958 | static int usb_device_del(const char *devname) |
959 | { | |
960 | int bus_num, addr; | |
961 | const char *p; | |
962 | ||
5d0c5750 AL |
963 | if (strstart(devname, "host:", &p)) |
964 | return usb_host_device_close(p); | |
965 | ||
a5d2f727 | 966 | if (!usb_enabled) |
1f3870ab AL |
967 | return -1; |
968 | ||
969 | p = strchr(devname, '.'); | |
970 | if (!p) | |
971 | return -1; | |
972 | bus_num = strtoul(devname, NULL, 0); | |
973 | addr = strtoul(p + 1, NULL, 0); | |
974 | ||
a5d2f727 | 975 | return usb_device_delete_addr(bus_num, addr); |
1f3870ab AL |
976 | } |
977 | ||
bd3c948d GH |
978 | static int usb_parse(const char *cmdline) |
979 | { | |
59d1c1c2 | 980 | int r; |
fb08000c | 981 | r = usb_device_add(cmdline); |
59d1c1c2 ST |
982 | if (r < 0) { |
983 | fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline); | |
984 | } | |
985 | return r; | |
bd3c948d GH |
986 | } |
987 | ||
d54908a5 | 988 | void do_usb_add(Monitor *mon, const QDict *qdict) |
a594cfbf | 989 | { |
59d1c1c2 | 990 | const char *devname = qdict_get_str(qdict, "devname"); |
fb08000c | 991 | if (usb_device_add(devname) < 0) { |
1ecda02b | 992 | error_report("could not add USB device '%s'", devname); |
59d1c1c2 | 993 | } |
a594cfbf FB |
994 | } |
995 | ||
d54908a5 | 996 | void do_usb_del(Monitor *mon, const QDict *qdict) |
a594cfbf | 997 | { |
59d1c1c2 ST |
998 | const char *devname = qdict_get_str(qdict, "devname"); |
999 | if (usb_device_del(devname) < 0) { | |
1ecda02b | 1000 | error_report("could not delete USB device '%s'", devname); |
59d1c1c2 | 1001 | } |
a594cfbf FB |
1002 | } |
1003 | ||
201a51fc AZ |
1004 | /***********************************************************/ |
1005 | /* PCMCIA/Cardbus */ | |
1006 | ||
1007 | static struct pcmcia_socket_entry_s { | |
bc24a225 | 1008 | PCMCIASocket *socket; |
201a51fc AZ |
1009 | struct pcmcia_socket_entry_s *next; |
1010 | } *pcmcia_sockets = 0; | |
1011 | ||
bc24a225 | 1012 | void pcmcia_socket_register(PCMCIASocket *socket) |
201a51fc AZ |
1013 | { |
1014 | struct pcmcia_socket_entry_s *entry; | |
1015 | ||
1016 | entry = qemu_malloc(sizeof(struct pcmcia_socket_entry_s)); | |
1017 | entry->socket = socket; | |
1018 | entry->next = pcmcia_sockets; | |
1019 | pcmcia_sockets = entry; | |
1020 | } | |
1021 | ||
bc24a225 | 1022 | void pcmcia_socket_unregister(PCMCIASocket *socket) |
201a51fc AZ |
1023 | { |
1024 | struct pcmcia_socket_entry_s *entry, **ptr; | |
1025 | ||
1026 | ptr = &pcmcia_sockets; | |
1027 | for (entry = *ptr; entry; ptr = &entry->next, entry = *ptr) | |
1028 | if (entry->socket == socket) { | |
1029 | *ptr = entry->next; | |
1030 | qemu_free(entry); | |
1031 | } | |
1032 | } | |
1033 | ||
376253ec | 1034 | void pcmcia_info(Monitor *mon) |
201a51fc AZ |
1035 | { |
1036 | struct pcmcia_socket_entry_s *iter; | |
376253ec | 1037 | |
201a51fc | 1038 | if (!pcmcia_sockets) |
376253ec | 1039 | monitor_printf(mon, "No PCMCIA sockets\n"); |
201a51fc AZ |
1040 | |
1041 | for (iter = pcmcia_sockets; iter; iter = iter->next) | |
376253ec AL |
1042 | monitor_printf(mon, "%s: %s\n", iter->socket->slot_string, |
1043 | iter->socket->attached ? iter->socket->card_string : | |
1044 | "Empty"); | |
201a51fc AZ |
1045 | } |
1046 | ||
cc1daa40 FB |
1047 | /***********************************************************/ |
1048 | /* machine registration */ | |
1049 | ||
bdaf78e0 | 1050 | static QEMUMachine *first_machine = NULL; |
6f338c34 | 1051 | QEMUMachine *current_machine = NULL; |
cc1daa40 FB |
1052 | |
1053 | int qemu_register_machine(QEMUMachine *m) | |
1054 | { | |
1055 | QEMUMachine **pm; | |
1056 | pm = &first_machine; | |
1057 | while (*pm != NULL) | |
1058 | pm = &(*pm)->next; | |
1059 | m->next = NULL; | |
1060 | *pm = m; | |
1061 | return 0; | |
1062 | } | |
1063 | ||
9596ebb7 | 1064 | static QEMUMachine *find_machine(const char *name) |
cc1daa40 FB |
1065 | { |
1066 | QEMUMachine *m; | |
1067 | ||
1068 | for(m = first_machine; m != NULL; m = m->next) { | |
1069 | if (!strcmp(m->name, name)) | |
1070 | return m; | |
3f6599e6 MM |
1071 | if (m->alias && !strcmp(m->alias, name)) |
1072 | return m; | |
cc1daa40 FB |
1073 | } |
1074 | return NULL; | |
1075 | } | |
1076 | ||
0c257437 AL |
1077 | static QEMUMachine *find_default_machine(void) |
1078 | { | |
1079 | QEMUMachine *m; | |
1080 | ||
1081 | for(m = first_machine; m != NULL; m = m->next) { | |
1082 | if (m->is_default) { | |
1083 | return m; | |
1084 | } | |
1085 | } | |
1086 | return NULL; | |
1087 | } | |
1088 | ||
8a7ddc38 FB |
1089 | /***********************************************************/ |
1090 | /* main execution loop */ | |
1091 | ||
9596ebb7 | 1092 | static void gui_update(void *opaque) |
8a7ddc38 | 1093 | { |
7d957bd8 | 1094 | uint64_t interval = GUI_REFRESH_INTERVAL; |
740733bb | 1095 | DisplayState *ds = opaque; |
7d957bd8 AL |
1096 | DisplayChangeListener *dcl = ds->listeners; |
1097 | ||
62a2744c | 1098 | qemu_flush_coalesced_mmio_buffer(); |
7d957bd8 AL |
1099 | dpy_refresh(ds); |
1100 | ||
1101 | while (dcl != NULL) { | |
1102 | if (dcl->gui_timer_interval && | |
1103 | dcl->gui_timer_interval < interval) | |
1104 | interval = dcl->gui_timer_interval; | |
1105 | dcl = dcl->next; | |
1106 | } | |
7bd427d8 | 1107 | qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock_ms(rt_clock)); |
8a7ddc38 FB |
1108 | } |
1109 | ||
9043b62d BS |
1110 | static void nographic_update(void *opaque) |
1111 | { | |
1112 | uint64_t interval = GUI_REFRESH_INTERVAL; | |
1113 | ||
62a2744c | 1114 | qemu_flush_coalesced_mmio_buffer(); |
7bd427d8 | 1115 | qemu_mod_timer(nographic_timer, interval + qemu_get_clock_ms(rt_clock)); |
9043b62d BS |
1116 | } |
1117 | ||
0bd48850 FB |
1118 | struct vm_change_state_entry { |
1119 | VMChangeStateHandler *cb; | |
1120 | void *opaque; | |
72cf2d4f | 1121 | QLIST_ENTRY (vm_change_state_entry) entries; |
0bd48850 FB |
1122 | }; |
1123 | ||
72cf2d4f | 1124 | static QLIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head; |
0bd48850 FB |
1125 | |
1126 | VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, | |
1127 | void *opaque) | |
1128 | { | |
1129 | VMChangeStateEntry *e; | |
1130 | ||
1131 | e = qemu_mallocz(sizeof (*e)); | |
0bd48850 FB |
1132 | |
1133 | e->cb = cb; | |
1134 | e->opaque = opaque; | |
72cf2d4f | 1135 | QLIST_INSERT_HEAD(&vm_change_state_head, e, entries); |
0bd48850 FB |
1136 | return e; |
1137 | } | |
1138 | ||
1139 | void qemu_del_vm_change_state_handler(VMChangeStateEntry *e) | |
1140 | { | |
72cf2d4f | 1141 | QLIST_REMOVE (e, entries); |
0bd48850 FB |
1142 | qemu_free (e); |
1143 | } | |
1144 | ||
296af7c9 | 1145 | void vm_state_notify(int running, int reason) |
0bd48850 FB |
1146 | { |
1147 | VMChangeStateEntry *e; | |
1148 | ||
94b0b5ff SH |
1149 | trace_vm_state_notify(running, reason); |
1150 | ||
0bd48850 | 1151 | for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { |
9781e040 | 1152 | e->cb(e->opaque, running, reason); |
0bd48850 FB |
1153 | } |
1154 | } | |
1155 | ||
8a7ddc38 FB |
1156 | void vm_start(void) |
1157 | { | |
1158 | if (!vm_running) { | |
1159 | cpu_enable_ticks(); | |
1160 | vm_running = 1; | |
9781e040 | 1161 | vm_state_notify(1, 0); |
d6dc3d42 | 1162 | resume_all_vcpus(); |
6ed2c484 | 1163 | monitor_protocol_event(QEVENT_RESUME, NULL); |
8a7ddc38 FB |
1164 | } |
1165 | } | |
1166 | ||
bb0c6722 FB |
1167 | /* reset/shutdown handler */ |
1168 | ||
1169 | typedef struct QEMUResetEntry { | |
72cf2d4f | 1170 | QTAILQ_ENTRY(QEMUResetEntry) entry; |
bb0c6722 FB |
1171 | QEMUResetHandler *func; |
1172 | void *opaque; | |
bb0c6722 FB |
1173 | } QEMUResetEntry; |
1174 | ||
72cf2d4f BS |
1175 | static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers = |
1176 | QTAILQ_HEAD_INITIALIZER(reset_handlers); | |
bb0c6722 | 1177 | static int reset_requested; |
f64622c4 GN |
1178 | static int shutdown_requested, shutdown_signal = -1; |
1179 | static pid_t shutdown_pid; | |
3475187d | 1180 | static int powerdown_requested; |
8cf71710 JK |
1181 | static int debug_requested; |
1182 | static int vmstop_requested; | |
bb0c6722 | 1183 | |
1291eb35 AP |
1184 | int qemu_shutdown_requested_get(void) |
1185 | { | |
1186 | return shutdown_requested; | |
1187 | } | |
1188 | ||
1189 | int qemu_reset_requested_get(void) | |
1190 | { | |
1191 | return reset_requested; | |
1192 | } | |
1193 | ||
cf7a2fe2 AJ |
1194 | int qemu_shutdown_requested(void) |
1195 | { | |
1196 | int r = shutdown_requested; | |
1197 | shutdown_requested = 0; | |
1198 | return r; | |
1199 | } | |
1200 | ||
f64622c4 GN |
1201 | void qemu_kill_report(void) |
1202 | { | |
1203 | if (shutdown_signal != -1) { | |
f1d3fb04 PM |
1204 | fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal); |
1205 | if (shutdown_pid == 0) { | |
1206 | /* This happens for eg ^C at the terminal, so it's worth | |
1207 | * avoiding printing an odd message in that case. | |
1208 | */ | |
1209 | fputc('\n', stderr); | |
1210 | } else { | |
953ffe0f | 1211 | fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid); |
f1d3fb04 | 1212 | } |
f64622c4 GN |
1213 | shutdown_signal = -1; |
1214 | } | |
1215 | } | |
1216 | ||
cf7a2fe2 AJ |
1217 | int qemu_reset_requested(void) |
1218 | { | |
1219 | int r = reset_requested; | |
1220 | reset_requested = 0; | |
1221 | return r; | |
1222 | } | |
1223 | ||
1224 | int qemu_powerdown_requested(void) | |
1225 | { | |
1226 | int r = powerdown_requested; | |
1227 | powerdown_requested = 0; | |
1228 | return r; | |
1229 | } | |
1230 | ||
e568902a AL |
1231 | static int qemu_debug_requested(void) |
1232 | { | |
1233 | int r = debug_requested; | |
1234 | debug_requested = 0; | |
1235 | return r; | |
1236 | } | |
1237 | ||
6e29f5da AL |
1238 | static int qemu_vmstop_requested(void) |
1239 | { | |
1240 | int r = vmstop_requested; | |
1241 | vmstop_requested = 0; | |
1242 | return r; | |
1243 | } | |
1244 | ||
a08d4367 | 1245 | void qemu_register_reset(QEMUResetHandler *func, void *opaque) |
bb0c6722 | 1246 | { |
55ddfe8e | 1247 | QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry)); |
bb0c6722 | 1248 | |
bb0c6722 FB |
1249 | re->func = func; |
1250 | re->opaque = opaque; | |
72cf2d4f | 1251 | QTAILQ_INSERT_TAIL(&reset_handlers, re, entry); |
bb0c6722 FB |
1252 | } |
1253 | ||
dda9b29f | 1254 | void qemu_unregister_reset(QEMUResetHandler *func, void *opaque) |
bb0c6722 FB |
1255 | { |
1256 | QEMUResetEntry *re; | |
1257 | ||
72cf2d4f | 1258 | QTAILQ_FOREACH(re, &reset_handlers, entry) { |
dda9b29f | 1259 | if (re->func == func && re->opaque == opaque) { |
72cf2d4f | 1260 | QTAILQ_REMOVE(&reset_handlers, re, entry); |
dda9b29f JK |
1261 | qemu_free(re); |
1262 | return; | |
1263 | } | |
1264 | } | |
1265 | } | |
1266 | ||
e063eb1f | 1267 | void qemu_system_reset(bool report) |
dda9b29f JK |
1268 | { |
1269 | QEMUResetEntry *re, *nre; | |
1270 | ||
1271 | /* reset all devices */ | |
72cf2d4f | 1272 | QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) { |
bb0c6722 FB |
1273 | re->func(re->opaque); |
1274 | } | |
e063eb1f JK |
1275 | if (report) { |
1276 | monitor_protocol_event(QEVENT_RESET, NULL); | |
1277 | } | |
ea375f9a | 1278 | cpu_synchronize_all_post_reset(); |
bb0c6722 FB |
1279 | } |
1280 | ||
1281 | void qemu_system_reset_request(void) | |
1282 | { | |
d1beab82 FB |
1283 | if (no_reboot) { |
1284 | shutdown_requested = 1; | |
1285 | } else { | |
1286 | reset_requested = 1; | |
1287 | } | |
b4a3d965 | 1288 | cpu_stop_current(); |
d9f75a4e | 1289 | qemu_notify_event(); |
bb0c6722 FB |
1290 | } |
1291 | ||
f64622c4 GN |
1292 | void qemu_system_killed(int signal, pid_t pid) |
1293 | { | |
1294 | shutdown_signal = signal; | |
1295 | shutdown_pid = pid; | |
1296 | qemu_system_shutdown_request(); | |
1297 | } | |
1298 | ||
bb0c6722 FB |
1299 | void qemu_system_shutdown_request(void) |
1300 | { | |
1301 | shutdown_requested = 1; | |
d9f75a4e | 1302 | qemu_notify_event(); |
bb0c6722 FB |
1303 | } |
1304 | ||
3475187d FB |
1305 | void qemu_system_powerdown_request(void) |
1306 | { | |
1307 | powerdown_requested = 1; | |
d9f75a4e AL |
1308 | qemu_notify_event(); |
1309 | } | |
1310 | ||
8cf71710 JK |
1311 | void qemu_system_debug_request(void) |
1312 | { | |
1313 | debug_requested = 1; | |
83f338f7 | 1314 | qemu_notify_event(); |
8cf71710 JK |
1315 | } |
1316 | ||
1317 | void qemu_system_vmstop_request(int reason) | |
1318 | { | |
1319 | vmstop_requested = reason; | |
1320 | qemu_notify_event(); | |
1321 | } | |
1322 | ||
d6f4ade2 | 1323 | void main_loop_wait(int nonblocking) |
56f3a5d0 | 1324 | { |
56f3a5d0 AL |
1325 | fd_set rfds, wfds, xfds; |
1326 | int ret, nfds; | |
1327 | struct timeval tv; | |
d6f4ade2 | 1328 | int timeout; |
56f3a5d0 | 1329 | |
d6f4ade2 PB |
1330 | if (nonblocking) |
1331 | timeout = 0; | |
1332 | else { | |
1333 | timeout = qemu_calculate_timeout(); | |
1334 | qemu_bh_update_timeout(&timeout); | |
1335 | } | |
56f3a5d0 | 1336 | |
0d93ca7c | 1337 | os_host_main_loop_wait(&timeout); |
56f3a5d0 | 1338 | |
02981419 PB |
1339 | tv.tv_sec = timeout / 1000; |
1340 | tv.tv_usec = (timeout % 1000) * 1000; | |
1341 | ||
fd1dff4b FB |
1342 | /* poll any events */ |
1343 | /* XXX: separate device handlers from system ones */ | |
6abfbd79 | 1344 | nfds = -1; |
fd1dff4b FB |
1345 | FD_ZERO(&rfds); |
1346 | FD_ZERO(&wfds); | |
e035649e | 1347 | FD_ZERO(&xfds); |
02981419 | 1348 | qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds); |
d918f23e JK |
1349 | slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
1350 | ||
4870852c | 1351 | qemu_mutex_unlock_iothread(); |
e035649e | 1352 | ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv); |
4870852c | 1353 | qemu_mutex_lock_iothread(); |
d918f23e | 1354 | |
02981419 | 1355 | qemu_iohandler_poll(&rfds, &wfds, &xfds, ret); |
d918f23e | 1356 | slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0)); |
b4608c04 | 1357 | |
b6964827 | 1358 | qemu_run_all_timers(); |
21d5d12b | 1359 | |
423f0742 PB |
1360 | /* Check bottom-halves last in case any of the earlier events triggered |
1361 | them. */ | |
1362 | qemu_bh_poll(); | |
3b46e624 | 1363 | |
5905b2e5 FB |
1364 | } |
1365 | ||
46481d39 JK |
1366 | #ifndef CONFIG_IOTHREAD |
1367 | static int vm_request_pending(void) | |
43b96858 | 1368 | { |
46481d39 JK |
1369 | return powerdown_requested || |
1370 | reset_requested || | |
1371 | shutdown_requested || | |
1372 | debug_requested || | |
1373 | vmstop_requested; | |
43b96858 | 1374 | } |
46481d39 | 1375 | #endif |
43b96858 | 1376 | |
d9c32310 BS |
1377 | qemu_irq qemu_system_powerdown; |
1378 | ||
43b96858 AL |
1379 | static void main_loop(void) |
1380 | { | |
8e1b90ec JK |
1381 | bool nonblocking = false; |
1382 | #ifdef CONFIG_PROFILER | |
1383 | int64_t ti; | |
1384 | #endif | |
6e29f5da | 1385 | int r; |
e6e35b1e | 1386 | |
7277e027 | 1387 | qemu_main_loop_start(); |
d6dc3d42 | 1388 | |
6e29f5da | 1389 | for (;;) { |
d6dc3d42 | 1390 | #ifndef CONFIG_IOTHREAD |
46481d39 JK |
1391 | nonblocking = cpu_exec_all(); |
1392 | if (vm_request_pending()) { | |
1393 | nonblocking = true; | |
1394 | } | |
d6dc3d42 | 1395 | #endif |
89bfc105 | 1396 | #ifdef CONFIG_PROFILER |
46481d39 | 1397 | ti = profile_getclock(); |
89bfc105 | 1398 | #endif |
46481d39 | 1399 | main_loop_wait(nonblocking); |
89bfc105 | 1400 | #ifdef CONFIG_PROFILER |
46481d39 | 1401 | dev_time += profile_getclock() - ti; |
89bfc105 | 1402 | #endif |
43b96858 | 1403 | |
8cf71710 JK |
1404 | if (qemu_debug_requested()) { |
1405 | vm_stop(VMSTOP_DEBUG); | |
b1a15e7e | 1406 | } |
43b96858 | 1407 | if (qemu_shutdown_requested()) { |
f64622c4 | 1408 | qemu_kill_report(); |
242cd003 | 1409 | monitor_protocol_event(QEVENT_SHUTDOWN, NULL); |
43b96858 | 1410 | if (no_shutdown) { |
e07bbac5 | 1411 | vm_stop(VMSTOP_SHUTDOWN); |
43b96858 AL |
1412 | } else |
1413 | break; | |
1414 | } | |
d6dc3d42 AL |
1415 | if (qemu_reset_requested()) { |
1416 | pause_all_vcpus(); | |
a7ada151 | 1417 | cpu_synchronize_all_states(); |
e063eb1f | 1418 | qemu_system_reset(VMRESET_REPORT); |
d6dc3d42 AL |
1419 | resume_all_vcpus(); |
1420 | } | |
d9c32310 | 1421 | if (qemu_powerdown_requested()) { |
242cd003 | 1422 | monitor_protocol_event(QEVENT_POWERDOWN, NULL); |
d9c32310 BS |
1423 | qemu_irq_raise(qemu_system_powerdown); |
1424 | } | |
b1a15e7e | 1425 | if ((r = qemu_vmstop_requested())) { |
6e29f5da | 1426 | vm_stop(r); |
b1a15e7e | 1427 | } |
b4608c04 | 1428 | } |
2bc93fed | 1429 | bdrv_close_all(); |
d6dc3d42 | 1430 | pause_all_vcpus(); |
b4608c04 FB |
1431 | } |
1432 | ||
9bd7e6d9 PB |
1433 | static void version(void) |
1434 | { | |
f75ca1ae | 1435 | printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); |
9bd7e6d9 PB |
1436 | } |
1437 | ||
15f82208 | 1438 | static void help(int exitcode) |
0824d6fc | 1439 | { |
e8105ebb | 1440 | const char *options_help = |
ad96090a BS |
1441 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ |
1442 | opt_help | |
5824d651 | 1443 | #define DEFHEADING(text) stringify(text) "\n" |
9f16732a | 1444 | #include "qemu-options.def" |
5824d651 BS |
1445 | #undef DEF |
1446 | #undef DEFHEADING | |
1447 | #undef GEN_DOCS | |
e8105ebb PB |
1448 | ; |
1449 | version(); | |
1450 | printf("usage: %s [options] [disk_image]\n" | |
1451 | "\n" | |
f75ca1ae | 1452 | "'disk_image' is a raw hard disk image for IDE hard disk 0\n" |
3f020d70 | 1453 | "\n" |
e8105ebb | 1454 | "%s\n" |
3f020d70 | 1455 | "During emulation, the following keys are useful:\n" |
1456 | "ctrl-alt-f toggle full screen\n" | |
1457 | "ctrl-alt-n switch to virtual console 'n'\n" | |
1458 | "ctrl-alt toggle mouse and keyboard grab\n" | |
1459 | "\n" | |
e8105ebb PB |
1460 | "When using -nographic, press 'ctrl-a h' to get some help.\n", |
1461 | "qemu", | |
1462 | options_help); | |
15f82208 | 1463 | exit(exitcode); |
0824d6fc FB |
1464 | } |
1465 | ||
cd6f1169 FB |
1466 | #define HAS_ARG 0x0001 |
1467 | ||
cd6f1169 FB |
1468 | typedef struct QEMUOption { |
1469 | const char *name; | |
1470 | int flags; | |
1471 | int index; | |
ad96090a | 1472 | uint32_t arch_mask; |
cd6f1169 FB |
1473 | } QEMUOption; |
1474 | ||
dbed7e40 | 1475 | static const QEMUOption qemu_options[] = { |
ad96090a BS |
1476 | { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL }, |
1477 | #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ | |
1478 | { option, opt_arg, opt_enum, arch_mask }, | |
5824d651 | 1479 | #define DEFHEADING(text) |
9f16732a | 1480 | #include "qemu-options.def" |
5824d651 BS |
1481 | #undef DEF |
1482 | #undef DEFHEADING | |
1483 | #undef GEN_DOCS | |
cd6f1169 | 1484 | { NULL }, |
fc01f7e7 | 1485 | }; |
3893c124 | 1486 | static void select_vgahw (const char *p) |
1487 | { | |
1488 | const char *opts; | |
1489 | ||
64465297 | 1490 | default_vga = 0; |
86176759 | 1491 | vga_interface_type = VGA_NONE; |
3893c124 | 1492 | if (strstart(p, "std", &opts)) { |
86176759 | 1493 | vga_interface_type = VGA_STD; |
3893c124 | 1494 | } else if (strstart(p, "cirrus", &opts)) { |
86176759 | 1495 | vga_interface_type = VGA_CIRRUS; |
3893c124 | 1496 | } else if (strstart(p, "vmware", &opts)) { |
86176759 | 1497 | vga_interface_type = VGA_VMWARE; |
94909d9f | 1498 | } else if (strstart(p, "xenfb", &opts)) { |
86176759 | 1499 | vga_interface_type = VGA_XENFB; |
a19cbfb3 GH |
1500 | } else if (strstart(p, "qxl", &opts)) { |
1501 | vga_interface_type = VGA_QXL; | |
28b85ed8 | 1502 | } else if (!strstart(p, "none", &opts)) { |
3893c124 | 1503 | invalid_vga: |
1504 | fprintf(stderr, "Unknown vga type: %s\n", p); | |
1505 | exit(1); | |
1506 | } | |
cb5a7aa8 | 1507 | while (*opts) { |
1508 | const char *nextopt; | |
1509 | ||
1510 | if (strstart(opts, ",retrace=", &nextopt)) { | |
1511 | opts = nextopt; | |
1512 | if (strstart(opts, "dumb", &nextopt)) | |
1513 | vga_retrace_method = VGA_RETRACE_DUMB; | |
1514 | else if (strstart(opts, "precise", &nextopt)) | |
1515 | vga_retrace_method = VGA_RETRACE_PRECISE; | |
1516 | else goto invalid_vga; | |
1517 | } else goto invalid_vga; | |
1518 | opts = nextopt; | |
1519 | } | |
3893c124 | 1520 | } |
1521 | ||
1472a95b JS |
1522 | static DisplayType select_display(const char *p) |
1523 | { | |
1524 | const char *opts; | |
1525 | DisplayType display = DT_DEFAULT; | |
1526 | ||
1527 | if (strstart(p, "sdl", &opts)) { | |
1528 | #ifdef CONFIG_SDL | |
1529 | display = DT_SDL; | |
1530 | while (*opts) { | |
1531 | const char *nextopt; | |
1532 | ||
1533 | if (strstart(opts, ",frame=", &nextopt)) { | |
1534 | opts = nextopt; | |
1535 | if (strstart(opts, "on", &nextopt)) { | |
1536 | no_frame = 0; | |
1537 | } else if (strstart(opts, "off", &nextopt)) { | |
1538 | no_frame = 1; | |
1539 | } else { | |
05175535 | 1540 | goto invalid_sdl_args; |
1472a95b JS |
1541 | } |
1542 | } else if (strstart(opts, ",alt_grab=", &nextopt)) { | |
1543 | opts = nextopt; | |
1544 | if (strstart(opts, "on", &nextopt)) { | |
1545 | alt_grab = 1; | |
1546 | } else if (strstart(opts, "off", &nextopt)) { | |
1547 | alt_grab = 0; | |
1548 | } else { | |
05175535 | 1549 | goto invalid_sdl_args; |
1472a95b JS |
1550 | } |
1551 | } else if (strstart(opts, ",ctrl_grab=", &nextopt)) { | |
1552 | opts = nextopt; | |
1553 | if (strstart(opts, "on", &nextopt)) { | |
1554 | ctrl_grab = 1; | |
1555 | } else if (strstart(opts, "off", &nextopt)) { | |
1556 | ctrl_grab = 0; | |
1557 | } else { | |
05175535 | 1558 | goto invalid_sdl_args; |
1472a95b JS |
1559 | } |
1560 | } else if (strstart(opts, ",window_close=", &nextopt)) { | |
1561 | opts = nextopt; | |
1562 | if (strstart(opts, "on", &nextopt)) { | |
1563 | no_quit = 0; | |
1564 | } else if (strstart(opts, "off", &nextopt)) { | |
1565 | no_quit = 1; | |
1566 | } else { | |
05175535 | 1567 | goto invalid_sdl_args; |
1472a95b JS |
1568 | } |
1569 | } else { | |
05175535 PM |
1570 | invalid_sdl_args: |
1571 | fprintf(stderr, "Invalid SDL option string: %s\n", p); | |
1572 | exit(1); | |
1472a95b JS |
1573 | } |
1574 | opts = nextopt; | |
1575 | } | |
1576 | #else | |
1577 | fprintf(stderr, "SDL support is disabled\n"); | |
1578 | exit(1); | |
1579 | #endif | |
3264ff12 | 1580 | } else if (strstart(p, "vnc", &opts)) { |
821601ea | 1581 | #ifdef CONFIG_VNC |
3264ff12 JS |
1582 | display_remote++; |
1583 | ||
1584 | if (*opts) { | |
1585 | const char *nextopt; | |
1586 | ||
1587 | if (strstart(opts, "=", &nextopt)) { | |
1588 | vnc_display = nextopt; | |
1589 | } | |
1590 | } | |
1591 | if (!vnc_display) { | |
1592 | fprintf(stderr, "VNC requires a display argument vnc=<display>\n"); | |
1593 | exit(1); | |
1594 | } | |
821601ea JS |
1595 | #else |
1596 | fprintf(stderr, "VNC support is disabled\n"); | |
1597 | exit(1); | |
1598 | #endif | |
1472a95b JS |
1599 | } else if (strstart(p, "curses", &opts)) { |
1600 | #ifdef CONFIG_CURSES | |
1601 | display = DT_CURSES; | |
1602 | #else | |
1603 | fprintf(stderr, "Curses support is disabled\n"); | |
1604 | exit(1); | |
1605 | #endif | |
4171d32e JS |
1606 | } else if (strstart(p, "none", &opts)) { |
1607 | display = DT_NONE; | |
1472a95b | 1608 | } else { |
1472a95b JS |
1609 | fprintf(stderr, "Unknown display type: %s\n", p); |
1610 | exit(1); | |
1611 | } | |
1612 | ||
1613 | return display; | |
1614 | } | |
1615 | ||
7d4c3d53 MA |
1616 | static int balloon_parse(const char *arg) |
1617 | { | |
382f0743 | 1618 | QemuOpts *opts; |
7d4c3d53 | 1619 | |
382f0743 GH |
1620 | if (strcmp(arg, "none") == 0) { |
1621 | return 0; | |
1622 | } | |
1623 | ||
1624 | if (!strncmp(arg, "virtio", 6)) { | |
1625 | if (arg[6] == ',') { | |
1626 | /* have params -> parse them */ | |
3329f07b | 1627 | opts = qemu_opts_parse(qemu_find_opts("device"), arg+7, 0); |
382f0743 GH |
1628 | if (!opts) |
1629 | return -1; | |
1630 | } else { | |
1631 | /* create empty opts */ | |
3329f07b | 1632 | opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0); |
7d4c3d53 | 1633 | } |
29f82b37 | 1634 | qemu_opt_set(opts, "driver", "virtio-balloon"); |
382f0743 | 1635 | return 0; |
7d4c3d53 | 1636 | } |
382f0743 GH |
1637 | |
1638 | return -1; | |
7d4c3d53 | 1639 | } |
7d4c3d53 | 1640 | |
5cea8590 PB |
1641 | char *qemu_find_file(int type, const char *name) |
1642 | { | |
1643 | int len; | |
1644 | const char *subdir; | |
1645 | char *buf; | |
1646 | ||
1647 | /* If name contains path separators then try it as a straight path. */ | |
1648 | if ((strchr(name, '/') || strchr(name, '\\')) | |
1649 | && access(name, R_OK) == 0) { | |
73ffc805 | 1650 | return qemu_strdup(name); |
5cea8590 PB |
1651 | } |
1652 | switch (type) { | |
1653 | case QEMU_FILE_TYPE_BIOS: | |
1654 | subdir = ""; | |
1655 | break; | |
1656 | case QEMU_FILE_TYPE_KEYMAP: | |
1657 | subdir = "keymaps/"; | |
1658 | break; | |
1659 | default: | |
1660 | abort(); | |
1661 | } | |
1662 | len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; | |
1663 | buf = qemu_mallocz(len); | |
3a41759d | 1664 | snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); |
5cea8590 PB |
1665 | if (access(buf, R_OK)) { |
1666 | qemu_free(buf); | |
1667 | return NULL; | |
1668 | } | |
1669 | return buf; | |
1670 | } | |
1671 | ||
ff952ba2 MA |
1672 | static int device_help_func(QemuOpts *opts, void *opaque) |
1673 | { | |
1674 | return qdev_device_help(opts); | |
1675 | } | |
1676 | ||
f31d07d1 GH |
1677 | static int device_init_func(QemuOpts *opts, void *opaque) |
1678 | { | |
1679 | DeviceState *dev; | |
1680 | ||
1681 | dev = qdev_device_add(opts); | |
1682 | if (!dev) | |
1683 | return -1; | |
1684 | return 0; | |
1685 | } | |
1686 | ||
1a688d3b GH |
1687 | static int chardev_init_func(QemuOpts *opts, void *opaque) |
1688 | { | |
1689 | CharDriverState *chr; | |
1690 | ||
1691 | chr = qemu_chr_open_opts(opts, NULL); | |
1692 | if (!chr) | |
1693 | return -1; | |
1694 | return 0; | |
1695 | } | |
1696 | ||
758e8e38 | 1697 | #ifdef CONFIG_VIRTFS |
74db920c GS |
1698 | static int fsdev_init_func(QemuOpts *opts, void *opaque) |
1699 | { | |
1700 | int ret; | |
1701 | ret = qemu_fsdev_add(opts); | |
1702 | ||
1703 | return ret; | |
1704 | } | |
1705 | #endif | |
1706 | ||
88589343 GH |
1707 | static int mon_init_func(QemuOpts *opts, void *opaque) |
1708 | { | |
1709 | CharDriverState *chr; | |
1710 | const char *chardev; | |
1711 | const char *mode; | |
1712 | int flags; | |
1713 | ||
1714 | mode = qemu_opt_get(opts, "mode"); | |
1715 | if (mode == NULL) { | |
1716 | mode = "readline"; | |
1717 | } | |
1718 | if (strcmp(mode, "readline") == 0) { | |
1719 | flags = MONITOR_USE_READLINE; | |
1720 | } else if (strcmp(mode, "control") == 0) { | |
1721 | flags = MONITOR_USE_CONTROL; | |
1722 | } else { | |
1723 | fprintf(stderr, "unknown monitor mode \"%s\"\n", mode); | |
1724 | exit(1); | |
1725 | } | |
1726 | ||
39eaab9a DB |
1727 | if (qemu_opt_get_bool(opts, "pretty", 0)) |
1728 | flags |= MONITOR_USE_PRETTY; | |
1729 | ||
88589343 GH |
1730 | if (qemu_opt_get_bool(opts, "default", 0)) |
1731 | flags |= MONITOR_IS_DEFAULT; | |
1732 | ||
1733 | chardev = qemu_opt_get(opts, "chardev"); | |
1734 | chr = qemu_chr_find(chardev); | |
1735 | if (chr == NULL) { | |
1736 | fprintf(stderr, "chardev \"%s\" not found\n", chardev); | |
1737 | exit(1); | |
1738 | } | |
1739 | ||
1740 | monitor_init(chr, flags); | |
1741 | return 0; | |
1742 | } | |
1743 | ||
6ca5582d | 1744 | static void monitor_parse(const char *optarg, const char *mode) |
88589343 GH |
1745 | { |
1746 | static int monitor_device_index = 0; | |
1747 | QemuOpts *opts; | |
1748 | const char *p; | |
1749 | char label[32]; | |
1750 | int def = 0; | |
1751 | ||
1752 | if (strstart(optarg, "chardev:", &p)) { | |
1753 | snprintf(label, sizeof(label), "%s", p); | |
1754 | } else { | |
140e065d JK |
1755 | snprintf(label, sizeof(label), "compat_monitor%d", |
1756 | monitor_device_index); | |
1757 | if (monitor_device_index == 0) { | |
88589343 GH |
1758 | def = 1; |
1759 | } | |
1760 | opts = qemu_chr_parse_compat(label, optarg); | |
1761 | if (!opts) { | |
1762 | fprintf(stderr, "parse error: %s\n", optarg); | |
1763 | exit(1); | |
1764 | } | |
1765 | } | |
1766 | ||
3329f07b | 1767 | opts = qemu_opts_create(qemu_find_opts("mon"), label, 1); |
88589343 GH |
1768 | if (!opts) { |
1769 | fprintf(stderr, "duplicate chardev: %s\n", label); | |
1770 | exit(1); | |
1771 | } | |
6ca5582d | 1772 | qemu_opt_set(opts, "mode", mode); |
88589343 GH |
1773 | qemu_opt_set(opts, "chardev", label); |
1774 | if (def) | |
1775 | qemu_opt_set(opts, "default", "on"); | |
1776 | monitor_device_index++; | |
1777 | } | |
1778 | ||
bd3c948d GH |
1779 | struct device_config { |
1780 | enum { | |
aee1b935 GH |
1781 | DEV_USB, /* -usbdevice */ |
1782 | DEV_BT, /* -bt */ | |
1783 | DEV_SERIAL, /* -serial */ | |
1784 | DEV_PARALLEL, /* -parallel */ | |
1785 | DEV_VIRTCON, /* -virtioconsole */ | |
c9f398e5 | 1786 | DEV_DEBUGCON, /* -debugcon */ |
bd3c948d GH |
1787 | } type; |
1788 | const char *cmdline; | |
72cf2d4f | 1789 | QTAILQ_ENTRY(device_config) next; |
bd3c948d | 1790 | }; |
72cf2d4f | 1791 | QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); |
bd3c948d GH |
1792 | |
1793 | static void add_device_config(int type, const char *cmdline) | |
1794 | { | |
1795 | struct device_config *conf; | |
1796 | ||
1797 | conf = qemu_mallocz(sizeof(*conf)); | |
1798 | conf->type = type; | |
1799 | conf->cmdline = cmdline; | |
72cf2d4f | 1800 | QTAILQ_INSERT_TAIL(&device_configs, conf, next); |
bd3c948d GH |
1801 | } |
1802 | ||
1803 | static int foreach_device_config(int type, int (*func)(const char *cmdline)) | |
1804 | { | |
1805 | struct device_config *conf; | |
1806 | int rc; | |
1807 | ||
72cf2d4f | 1808 | QTAILQ_FOREACH(conf, &device_configs, next) { |
bd3c948d GH |
1809 | if (conf->type != type) |
1810 | continue; | |
1811 | rc = func(conf->cmdline); | |
1812 | if (0 != rc) | |
1813 | return rc; | |
1814 | } | |
1815 | return 0; | |
1816 | } | |
1817 | ||
998bbd74 GH |
1818 | static int serial_parse(const char *devname) |
1819 | { | |
1820 | static int index = 0; | |
1821 | char label[32]; | |
1822 | ||
1823 | if (strcmp(devname, "none") == 0) | |
1824 | return 0; | |
1825 | if (index == MAX_SERIAL_PORTS) { | |
1826 | fprintf(stderr, "qemu: too many serial ports\n"); | |
1827 | exit(1); | |
1828 | } | |
1829 | snprintf(label, sizeof(label), "serial%d", index); | |
1830 | serial_hds[index] = qemu_chr_open(label, devname, NULL); | |
1831 | if (!serial_hds[index]) { | |
1832 | fprintf(stderr, "qemu: could not open serial device '%s': %s\n", | |
1833 | devname, strerror(errno)); | |
1834 | return -1; | |
1835 | } | |
1836 | index++; | |
1837 | return 0; | |
1838 | } | |
1839 | ||
6a5e8b0e GH |
1840 | static int parallel_parse(const char *devname) |
1841 | { | |
1842 | static int index = 0; | |
1843 | char label[32]; | |
1844 | ||
1845 | if (strcmp(devname, "none") == 0) | |
1846 | return 0; | |
1847 | if (index == MAX_PARALLEL_PORTS) { | |
1848 | fprintf(stderr, "qemu: too many parallel ports\n"); | |
1849 | exit(1); | |
1850 | } | |
1851 | snprintf(label, sizeof(label), "parallel%d", index); | |
1852 | parallel_hds[index] = qemu_chr_open(label, devname, NULL); | |
1853 | if (!parallel_hds[index]) { | |
1854 | fprintf(stderr, "qemu: could not open parallel device '%s': %s\n", | |
1855 | devname, strerror(errno)); | |
1856 | return -1; | |
1857 | } | |
1858 | index++; | |
1859 | return 0; | |
1860 | } | |
1861 | ||
aee1b935 GH |
1862 | static int virtcon_parse(const char *devname) |
1863 | { | |
3329f07b | 1864 | QemuOptsList *device = qemu_find_opts("device"); |
aee1b935 GH |
1865 | static int index = 0; |
1866 | char label[32]; | |
392ecf54 | 1867 | QemuOpts *bus_opts, *dev_opts; |
aee1b935 GH |
1868 | |
1869 | if (strcmp(devname, "none") == 0) | |
1870 | return 0; | |
1871 | if (index == MAX_VIRTIO_CONSOLES) { | |
1872 | fprintf(stderr, "qemu: too many virtio consoles\n"); | |
1873 | exit(1); | |
1874 | } | |
392ecf54 | 1875 | |
3329f07b | 1876 | bus_opts = qemu_opts_create(device, NULL, 0); |
392ecf54 AS |
1877 | qemu_opt_set(bus_opts, "driver", "virtio-serial"); |
1878 | ||
3329f07b | 1879 | dev_opts = qemu_opts_create(device, NULL, 0); |
392ecf54 AS |
1880 | qemu_opt_set(dev_opts, "driver", "virtconsole"); |
1881 | ||
aee1b935 GH |
1882 | snprintf(label, sizeof(label), "virtcon%d", index); |
1883 | virtcon_hds[index] = qemu_chr_open(label, devname, NULL); | |
1884 | if (!virtcon_hds[index]) { | |
1885 | fprintf(stderr, "qemu: could not open virtio console '%s': %s\n", | |
1886 | devname, strerror(errno)); | |
1887 | return -1; | |
1888 | } | |
392ecf54 AS |
1889 | qemu_opt_set(dev_opts, "chardev", label); |
1890 | ||
aee1b935 GH |
1891 | index++; |
1892 | return 0; | |
1893 | } | |
1894 | ||
c9f398e5 PA |
1895 | static int debugcon_parse(const char *devname) |
1896 | { | |
1897 | QemuOpts *opts; | |
1898 | ||
1899 | if (!qemu_chr_open("debugcon", devname, NULL)) { | |
1900 | exit(1); | |
1901 | } | |
3329f07b | 1902 | opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1); |
c9f398e5 PA |
1903 | if (!opts) { |
1904 | fprintf(stderr, "qemu: already have a debugcon device\n"); | |
1905 | exit(1); | |
1906 | } | |
1907 | qemu_opt_set(opts, "driver", "isa-debugcon"); | |
1908 | qemu_opt_set(opts, "chardev", "debugcon"); | |
1909 | return 0; | |
1910 | } | |
1911 | ||
9052ea6b JK |
1912 | static QEMUMachine *machine_parse(const char *name) |
1913 | { | |
1914 | QEMUMachine *m, *machine = NULL; | |
1915 | ||
1916 | if (name) { | |
1917 | machine = find_machine(name); | |
1918 | } | |
1919 | if (machine) { | |
1920 | return machine; | |
1921 | } | |
1922 | printf("Supported machines are:\n"); | |
1923 | for (m = first_machine; m != NULL; m = m->next) { | |
1924 | if (m->alias) { | |
1925 | printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name); | |
1926 | } | |
1927 | printf("%-10s %s%s\n", m->name, m->desc, | |
1928 | m->is_default ? " (default)" : ""); | |
1929 | } | |
1930 | exit(!name || *name != '?'); | |
1931 | } | |
1932 | ||
303d4e86 AP |
1933 | static int tcg_init(void) |
1934 | { | |
1935 | return 0; | |
1936 | } | |
1937 | ||
1938 | static struct { | |
1939 | const char *opt_name; | |
1940 | const char *name; | |
1941 | int (*available)(void); | |
1942 | int (*init)(void); | |
1943 | int *allowed; | |
1944 | } accel_list[] = { | |
1945 | { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, | |
3285cf4f | 1946 | { "xen", "Xen", xen_available, xen_init, &xen_allowed }, |
303d4e86 AP |
1947 | { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, |
1948 | }; | |
1949 | ||
1950 | static int configure_accelerator(void) | |
1951 | { | |
1952 | const char *p = NULL; | |
1953 | char buf[10]; | |
1954 | int i, ret; | |
1955 | bool accel_initalised = 0; | |
1956 | bool init_failed = 0; | |
1957 | ||
1958 | QemuOptsList *list = qemu_find_opts("machine"); | |
1959 | if (!QTAILQ_EMPTY(&list->head)) { | |
1960 | p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel"); | |
1961 | } | |
1962 | ||
1963 | if (p == NULL) { | |
1964 | /* Use the default "accelerator", tcg */ | |
1965 | p = "tcg"; | |
1966 | } | |
1967 | ||
1968 | while (!accel_initalised && *p != '\0') { | |
1969 | if (*p == ':') { | |
1970 | p++; | |
1971 | } | |
1972 | p = get_opt_name(buf, sizeof (buf), p, ':'); | |
1973 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { | |
1974 | if (strcmp(accel_list[i].opt_name, buf) == 0) { | |
a16c53b1 | 1975 | *(accel_list[i].allowed) = 1; |
303d4e86 AP |
1976 | ret = accel_list[i].init(); |
1977 | if (ret < 0) { | |
1978 | init_failed = 1; | |
1979 | if (!accel_list[i].available()) { | |
1980 | printf("%s not supported for this target\n", | |
1981 | accel_list[i].name); | |
1982 | } else { | |
1983 | fprintf(stderr, "failed to initialize %s: %s\n", | |
1984 | accel_list[i].name, | |
1985 | strerror(-ret)); | |
1986 | } | |
a16c53b1 | 1987 | *(accel_list[i].allowed) = 0; |
303d4e86 AP |
1988 | } else { |
1989 | accel_initalised = 1; | |
303d4e86 AP |
1990 | } |
1991 | break; | |
1992 | } | |
1993 | } | |
1994 | if (i == ARRAY_SIZE(accel_list)) { | |
1995 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); | |
1996 | } | |
1997 | } | |
1998 | ||
1999 | if (!accel_initalised) { | |
2000 | fprintf(stderr, "No accelerator found!\n"); | |
2001 | exit(1); | |
2002 | } | |
2003 | ||
2004 | if (init_failed) { | |
2005 | fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); | |
2006 | } | |
2007 | ||
2008 | return !accel_initalised; | |
2009 | } | |
2010 | ||
fd42deeb GH |
2011 | void qemu_add_exit_notifier(Notifier *notify) |
2012 | { | |
2013 | notifier_list_add(&exit_notifiers, notify); | |
2014 | } | |
2015 | ||
2016 | void qemu_remove_exit_notifier(Notifier *notify) | |
2017 | { | |
2018 | notifier_list_remove(&exit_notifiers, notify); | |
2019 | } | |
2020 | ||
2021 | static void qemu_run_exit_notifiers(void) | |
2022 | { | |
9e8dd451 | 2023 | notifier_list_notify(&exit_notifiers, NULL); |
fd42deeb GH |
2024 | } |
2025 | ||
4cab946a GN |
2026 | void qemu_add_machine_init_done_notifier(Notifier *notify) |
2027 | { | |
2028 | notifier_list_add(&machine_init_done_notifiers, notify); | |
2029 | } | |
2030 | ||
2031 | static void qemu_run_machine_init_done_notifiers(void) | |
2032 | { | |
9e8dd451 | 2033 | notifier_list_notify(&machine_init_done_notifiers, NULL); |
4cab946a GN |
2034 | } |
2035 | ||
6530a97b AL |
2036 | static const QEMUOption *lookup_opt(int argc, char **argv, |
2037 | const char **poptarg, int *poptind) | |
2038 | { | |
2039 | const QEMUOption *popt; | |
2040 | int optind = *poptind; | |
2041 | char *r = argv[optind]; | |
2042 | const char *optarg; | |
2043 | ||
0f0bc3f1 | 2044 | loc_set_cmdline(argv, optind, 1); |
6530a97b AL |
2045 | optind++; |
2046 | /* Treat --foo the same as -foo. */ | |
2047 | if (r[1] == '-') | |
2048 | r++; | |
2049 | popt = qemu_options; | |
2050 | for(;;) { | |
2051 | if (!popt->name) { | |
0f0bc3f1 | 2052 | error_report("invalid option"); |
6530a97b AL |
2053 | exit(1); |
2054 | } | |
2055 | if (!strcmp(popt->name, r + 1)) | |
2056 | break; | |
2057 | popt++; | |
2058 | } | |
2059 | if (popt->flags & HAS_ARG) { | |
2060 | if (optind >= argc) { | |
0f0bc3f1 | 2061 | error_report("requires an argument"); |
6530a97b AL |
2062 | exit(1); |
2063 | } | |
2064 | optarg = argv[optind++]; | |
0f0bc3f1 | 2065 | loc_set_cmdline(argv, optind - 2, 2); |
6530a97b AL |
2066 | } else { |
2067 | optarg = NULL; | |
2068 | } | |
2069 | ||
2070 | *poptarg = optarg; | |
2071 | *poptind = optind; | |
2072 | ||
2073 | return popt; | |
2074 | } | |
2075 | ||
902b3d5c | 2076 | int main(int argc, char **argv, char **envp) |
0824d6fc | 2077 | { |
59030a8c | 2078 | const char *gdbstub_dev = NULL; |
e4bcb14c | 2079 | int i; |
da1fcfda | 2080 | int snapshot, linux_boot; |
4e3de9e9 | 2081 | const char *icount_option = NULL; |
7f7f9873 | 2082 | const char *initrd_filename; |
a20dd508 | 2083 | const char *kernel_filename, *kernel_cmdline; |
195325a4 | 2084 | char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */ |
3023f332 | 2085 | DisplayState *ds; |
7d957bd8 | 2086 | DisplayChangeListener *dcl; |
46d4767d | 2087 | int cyls, heads, secs, translation; |
f31d07d1 | 2088 | QemuOpts *hda_opts = NULL, *opts; |
03b0ba70 | 2089 | QemuOptsList *olist; |
cd6f1169 | 2090 | int optind; |
6530a97b | 2091 | const char *optarg; |
d63d307f | 2092 | const char *loadvm = NULL; |
cc1daa40 | 2093 | QEMUMachine *machine; |
94fc95cd | 2094 | const char *cpu_model; |
26a5f13b | 2095 | int tb_size; |
93815bc2 | 2096 | const char *pid_file = NULL; |
5bb7910a | 2097 | const char *incoming = NULL; |
821601ea | 2098 | #ifdef CONFIG_VNC |
993fbfdb | 2099 | int show_vnc_port = 0; |
821601ea | 2100 | #endif |
292444cb | 2101 | int defconfig = 1; |
ab6540d5 | 2102 | const char *trace_file = NULL; |
c235d738 MF |
2103 | const char *log_mask = NULL; |
2104 | const char *log_file = NULL; | |
0b5538c3 | 2105 | |
fd42deeb | 2106 | atexit(qemu_run_exit_notifiers); |
65abca0a MA |
2107 | error_set_progname(argv[0]); |
2108 | ||
6875204c JK |
2109 | init_clocks(); |
2110 | ||
902b3d5c | 2111 | qemu_cache_utils_init(envp); |
2112 | ||
72cf2d4f | 2113 | QLIST_INIT (&vm_change_state_head); |
fe98ac14 | 2114 | os_setup_early_signal_handling(); |
be995c27 | 2115 | |
f80f9ec9 | 2116 | module_call_init(MODULE_INIT_MACHINE); |
0c257437 | 2117 | machine = find_default_machine(); |
94fc95cd | 2118 | cpu_model = NULL; |
fc01f7e7 | 2119 | initrd_filename = NULL; |
4fc5d071 | 2120 | ram_size = 0; |
33e3963e | 2121 | snapshot = 0; |
a20dd508 FB |
2122 | kernel_filename = NULL; |
2123 | kernel_cmdline = ""; | |
c4b1fcc0 | 2124 | cyls = heads = secs = 0; |
46d4767d | 2125 | translation = BIOS_ATA_TRANSLATION_AUTO; |
c4b1fcc0 | 2126 | |
268a362c AL |
2127 | for (i = 0; i < MAX_NODES; i++) { |
2128 | node_mem[i] = 0; | |
2129 | node_cpumask[i] = 0; | |
2130 | } | |
2131 | ||
268a362c | 2132 | nb_numa_nodes = 0; |
7c9d8e07 | 2133 | nb_nics = 0; |
3b46e624 | 2134 | |
26a5f13b | 2135 | tb_size = 0; |
41bd639b BS |
2136 | autostart= 1; |
2137 | ||
292444cb AL |
2138 | /* first pass of option parsing */ |
2139 | optind = 1; | |
2140 | while (optind < argc) { | |
2141 | if (argv[optind][0] != '-') { | |
2142 | /* disk image */ | |
28e68d68 | 2143 | optind++; |
292444cb AL |
2144 | continue; |
2145 | } else { | |
2146 | const QEMUOption *popt; | |
2147 | ||
2148 | popt = lookup_opt(argc, argv, &optarg, &optind); | |
2149 | switch (popt->index) { | |
2150 | case QEMU_OPTION_nodefconfig: | |
2151 | defconfig=0; | |
2152 | break; | |
2153 | } | |
2154 | } | |
2155 | } | |
2156 | ||
2157 | if (defconfig) { | |
dcfb0939 | 2158 | int ret; |
cf5a65aa | 2159 | |
dcfb0939 | 2160 | ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); |
019e78ba | 2161 | if (ret < 0 && ret != -ENOENT) { |
dcfb0939 | 2162 | exit(1); |
292444cb AL |
2163 | } |
2164 | ||
dcfb0939 | 2165 | ret = qemu_read_config_file(arch_config_name); |
019e78ba | 2166 | if (ret < 0 && ret != -ENOENT) { |
dcfb0939 | 2167 | exit(1); |
292444cb AL |
2168 | } |
2169 | } | |
de06f8d1 | 2170 | cpudef_init(); |
292444cb AL |
2171 | |
2172 | /* second pass of option parsing */ | |
cd6f1169 | 2173 | optind = 1; |
0824d6fc | 2174 | for(;;) { |
cd6f1169 | 2175 | if (optind >= argc) |
0824d6fc | 2176 | break; |
6530a97b | 2177 | if (argv[optind][0] != '-') { |
2292ddae | 2178 | hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); |
cd6f1169 FB |
2179 | } else { |
2180 | const QEMUOption *popt; | |
2181 | ||
6530a97b | 2182 | popt = lookup_opt(argc, argv, &optarg, &optind); |
ad96090a BS |
2183 | if (!(popt->arch_mask & arch_type)) { |
2184 | printf("Option %s not supported for this target\n", popt->name); | |
2185 | exit(1); | |
2186 | } | |
cd6f1169 | 2187 | switch(popt->index) { |
cc1daa40 | 2188 | case QEMU_OPTION_M: |
9052ea6b | 2189 | machine = machine_parse(optarg); |
cc1daa40 | 2190 | break; |
94fc95cd JM |
2191 | case QEMU_OPTION_cpu: |
2192 | /* hw initialization will check this */ | |
15f82208 | 2193 | if (*optarg == '?') { |
262353cb | 2194 | list_cpus(stdout, &fprintf, optarg); |
15f82208 | 2195 | exit(0); |
94fc95cd JM |
2196 | } else { |
2197 | cpu_model = optarg; | |
2198 | } | |
2199 | break; | |
cd6f1169 | 2200 | case QEMU_OPTION_initrd: |
fc01f7e7 FB |
2201 | initrd_filename = optarg; |
2202 | break; | |
cd6f1169 | 2203 | case QEMU_OPTION_hda: |
5645b0f4 MA |
2204 | { |
2205 | char buf[256]; | |
2206 | if (cyls == 0) | |
2207 | snprintf(buf, sizeof(buf), "%s", HD_OPTS); | |
2208 | else | |
2209 | snprintf(buf, sizeof(buf), | |
2210 | "%s,cyls=%d,heads=%d,secs=%d%s", | |
2211 | HD_OPTS , cyls, heads, secs, | |
2212 | translation == BIOS_ATA_TRANSLATION_LBA ? | |
e4bcb14c | 2213 | ",trans=lba" : |
5645b0f4 | 2214 | translation == BIOS_ATA_TRANSLATION_NONE ? |
e4bcb14c | 2215 | ",trans=none" : ""); |
5645b0f4 MA |
2216 | drive_add(IF_DEFAULT, 0, optarg, buf); |
2217 | break; | |
2218 | } | |
cd6f1169 | 2219 | case QEMU_OPTION_hdb: |
cc1daa40 FB |
2220 | case QEMU_OPTION_hdc: |
2221 | case QEMU_OPTION_hdd: | |
2292ddae MA |
2222 | drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg, |
2223 | HD_OPTS); | |
fc01f7e7 | 2224 | break; |
e4bcb14c | 2225 | case QEMU_OPTION_drive: |
e2982c3a MT |
2226 | if (drive_def(optarg) == NULL) { |
2227 | exit(1); | |
2228 | } | |
e4bcb14c | 2229 | break; |
d058fe03 GH |
2230 | case QEMU_OPTION_set: |
2231 | if (qemu_set_option(optarg) != 0) | |
2232 | exit(1); | |
2233 | break; | |
d0fef6fb GH |
2234 | case QEMU_OPTION_global: |
2235 | if (qemu_global_option(optarg) != 0) | |
2236 | exit(1); | |
2237 | break; | |
3e3d5815 | 2238 | case QEMU_OPTION_mtdblock: |
2292ddae | 2239 | drive_add(IF_MTD, -1, optarg, MTD_OPTS); |
3e3d5815 | 2240 | break; |
a1bb27b1 | 2241 | case QEMU_OPTION_sd: |
2292ddae | 2242 | drive_add(IF_SD, 0, optarg, SD_OPTS); |
a1bb27b1 | 2243 | break; |
86f55663 | 2244 | case QEMU_OPTION_pflash: |
2292ddae | 2245 | drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS); |
86f55663 | 2246 | break; |
cd6f1169 | 2247 | case QEMU_OPTION_snapshot: |
33e3963e FB |
2248 | snapshot = 1; |
2249 | break; | |
cd6f1169 | 2250 | case QEMU_OPTION_hdachs: |
330d0414 | 2251 | { |
330d0414 FB |
2252 | const char *p; |
2253 | p = optarg; | |
2254 | cyls = strtol(p, (char **)&p, 0); | |
46d4767d FB |
2255 | if (cyls < 1 || cyls > 16383) |
2256 | goto chs_fail; | |
330d0414 FB |
2257 | if (*p != ',') |
2258 | goto chs_fail; | |
2259 | p++; | |
2260 | heads = strtol(p, (char **)&p, 0); | |
46d4767d FB |
2261 | if (heads < 1 || heads > 16) |
2262 | goto chs_fail; | |
330d0414 FB |
2263 | if (*p != ',') |
2264 | goto chs_fail; | |
2265 | p++; | |
2266 | secs = strtol(p, (char **)&p, 0); | |
46d4767d FB |
2267 | if (secs < 1 || secs > 63) |
2268 | goto chs_fail; | |
2269 | if (*p == ',') { | |
2270 | p++; | |
2271 | if (!strcmp(p, "none")) | |
2272 | translation = BIOS_ATA_TRANSLATION_NONE; | |
2273 | else if (!strcmp(p, "lba")) | |
2274 | translation = BIOS_ATA_TRANSLATION_LBA; | |
2275 | else if (!strcmp(p, "auto")) | |
2276 | translation = BIOS_ATA_TRANSLATION_AUTO; | |
2277 | else | |
2278 | goto chs_fail; | |
2279 | } else if (*p != '\0') { | |
c4b1fcc0 | 2280 | chs_fail: |
46d4767d FB |
2281 | fprintf(stderr, "qemu: invalid physical CHS format\n"); |
2282 | exit(1); | |
c4b1fcc0 | 2283 | } |
9dfd7c7a GH |
2284 | if (hda_opts != NULL) { |
2285 | char num[16]; | |
2286 | snprintf(num, sizeof(num), "%d", cyls); | |
2287 | qemu_opt_set(hda_opts, "cyls", num); | |
2288 | snprintf(num, sizeof(num), "%d", heads); | |
2289 | qemu_opt_set(hda_opts, "heads", num); | |
2290 | snprintf(num, sizeof(num), "%d", secs); | |
2291 | qemu_opt_set(hda_opts, "secs", num); | |
2292 | if (translation == BIOS_ATA_TRANSLATION_LBA) | |
2293 | qemu_opt_set(hda_opts, "trans", "lba"); | |
2294 | if (translation == BIOS_ATA_TRANSLATION_NONE) | |
2295 | qemu_opt_set(hda_opts, "trans", "none"); | |
2296 | } | |
330d0414 FB |
2297 | } |
2298 | break; | |
268a362c AL |
2299 | case QEMU_OPTION_numa: |
2300 | if (nb_numa_nodes >= MAX_NODES) { | |
2301 | fprintf(stderr, "qemu: too many NUMA nodes\n"); | |
2302 | exit(1); | |
2303 | } | |
2304 | numa_add(optarg); | |
2305 | break; | |
1472a95b JS |
2306 | case QEMU_OPTION_display: |
2307 | display_type = select_display(optarg); | |
2308 | break; | |
cd6f1169 | 2309 | case QEMU_OPTION_nographic: |
993fbfdb | 2310 | display_type = DT_NOGRAPHIC; |
a20dd508 | 2311 | break; |
4d3b6f6e | 2312 | case QEMU_OPTION_curses: |
47b05369 | 2313 | #ifdef CONFIG_CURSES |
993fbfdb | 2314 | display_type = DT_CURSES; |
47b05369 JS |
2315 | #else |
2316 | fprintf(stderr, "Curses support is disabled\n"); | |
2317 | exit(1); | |
4d3b6f6e | 2318 | #endif |
47b05369 | 2319 | break; |
a171fe39 | 2320 | case QEMU_OPTION_portrait: |
9312805d VK |
2321 | graphic_rotate = 90; |
2322 | break; | |
2323 | case QEMU_OPTION_rotate: | |
2324 | graphic_rotate = strtol(optarg, (char **) &optarg, 10); | |
2325 | if (graphic_rotate != 0 && graphic_rotate != 90 && | |
2326 | graphic_rotate != 180 && graphic_rotate != 270) { | |
2327 | fprintf(stderr, | |
2328 | "qemu: only 90, 180, 270 deg rotation is available\n"); | |
2329 | exit(1); | |
2330 | } | |
a171fe39 | 2331 | break; |
cd6f1169 | 2332 | case QEMU_OPTION_kernel: |
a20dd508 FB |
2333 | kernel_filename = optarg; |
2334 | break; | |
cd6f1169 | 2335 | case QEMU_OPTION_append: |
a20dd508 | 2336 | kernel_cmdline = optarg; |
313aa567 | 2337 | break; |
cd6f1169 | 2338 | case QEMU_OPTION_cdrom: |
2292ddae | 2339 | drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS); |
36b486bb | 2340 | break; |
cd6f1169 | 2341 | case QEMU_OPTION_boot: |
28c5af54 | 2342 | { |
ef3adf68 | 2343 | static const char * const params[] = { |
3d3b8303 WX |
2344 | "order", "once", "menu", |
2345 | "splash", "splash-time", NULL | |
ef3adf68 JK |
2346 | }; |
2347 | char buf[sizeof(boot_devices)]; | |
e0f084bf | 2348 | char *standard_boot_devices; |
ef3adf68 JK |
2349 | int legacy = 0; |
2350 | ||
2351 | if (!strchr(optarg, '=')) { | |
2352 | legacy = 1; | |
2353 | pstrcpy(buf, sizeof(buf), optarg); | |
2354 | } else if (check_params(buf, sizeof(buf), params, optarg) < 0) { | |
2355 | fprintf(stderr, | |
2356 | "qemu: unknown boot parameter '%s' in '%s'\n", | |
2357 | buf, optarg); | |
2358 | exit(1); | |
2359 | } | |
2360 | ||
2361 | if (legacy || | |
2362 | get_param_value(buf, sizeof(buf), "order", optarg)) { | |
4e9e9d6e | 2363 | validate_bootdevices(buf); |
ef3adf68 | 2364 | pstrcpy(boot_devices, sizeof(boot_devices), buf); |
28c5af54 | 2365 | } |
e0f084bf JK |
2366 | if (!legacy) { |
2367 | if (get_param_value(buf, sizeof(buf), | |
2368 | "once", optarg)) { | |
4e9e9d6e | 2369 | validate_bootdevices(buf); |
e0f084bf JK |
2370 | standard_boot_devices = qemu_strdup(boot_devices); |
2371 | pstrcpy(boot_devices, sizeof(boot_devices), buf); | |
2372 | qemu_register_reset(restore_boot_devices, | |
2373 | standard_boot_devices); | |
2374 | } | |
95387491 JK |
2375 | if (get_param_value(buf, sizeof(buf), |
2376 | "menu", optarg)) { | |
2377 | if (!strcmp(buf, "on")) { | |
2378 | boot_menu = 1; | |
2379 | } else if (!strcmp(buf, "off")) { | |
2380 | boot_menu = 0; | |
2381 | } else { | |
2382 | fprintf(stderr, | |
2383 | "qemu: invalid option value '%s'\n", | |
2384 | buf); | |
2385 | exit(1); | |
2386 | } | |
2387 | } | |
3d3b8303 WX |
2388 | qemu_opts_parse(qemu_find_opts("boot-opts"), |
2389 | optarg, 0); | |
e0f084bf | 2390 | } |
36b486bb FB |
2391 | } |
2392 | break; | |
cd6f1169 | 2393 | case QEMU_OPTION_fda: |
cd6f1169 | 2394 | case QEMU_OPTION_fdb: |
2292ddae MA |
2395 | drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda, |
2396 | optarg, FD_OPTS); | |
c45886db | 2397 | break; |
52ca8d6a FB |
2398 | case QEMU_OPTION_no_fd_bootchk: |
2399 | fd_bootchk = 0; | |
2400 | break; | |
a1ea458f | 2401 | case QEMU_OPTION_netdev: |
3329f07b | 2402 | if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) { |
a1ea458f MM |
2403 | exit(1); |
2404 | } | |
2405 | break; | |
7c9d8e07 | 2406 | case QEMU_OPTION_net: |
3329f07b | 2407 | if (net_client_parse(qemu_find_opts("net"), optarg) == -1) { |
c4b1fcc0 FB |
2408 | exit(1); |
2409 | } | |
702c651c | 2410 | break; |
c7f74643 FB |
2411 | #ifdef CONFIG_SLIRP |
2412 | case QEMU_OPTION_tftp: | |
ad196a9d | 2413 | legacy_tftp_prefix = optarg; |
9bf05444 | 2414 | break; |
47d5d01a | 2415 | case QEMU_OPTION_bootp: |
ad196a9d | 2416 | legacy_bootp_filename = optarg; |
47d5d01a | 2417 | break; |
9bf05444 | 2418 | case QEMU_OPTION_redir: |
0752706d MA |
2419 | if (net_slirp_redir(optarg) < 0) |
2420 | exit(1); | |
9bf05444 | 2421 | break; |
c7f74643 | 2422 | #endif |
dc72ac14 | 2423 | case QEMU_OPTION_bt: |
bd3c948d | 2424 | add_device_config(DEV_BT, optarg); |
dc72ac14 | 2425 | break; |
1d14ffa9 | 2426 | case QEMU_OPTION_audio_help: |
ad96090a BS |
2427 | if (!(audio_available())) { |
2428 | printf("Option %s not supported for this target\n", popt->name); | |
2429 | exit(1); | |
2430 | } | |
1d14ffa9 FB |
2431 | AUD_help (); |
2432 | exit (0); | |
2433 | break; | |
2434 | case QEMU_OPTION_soundhw: | |
ad96090a BS |
2435 | if (!(audio_available())) { |
2436 | printf("Option %s not supported for this target\n", popt->name); | |
2437 | exit(1); | |
2438 | } | |
1d14ffa9 FB |
2439 | select_soundhw (optarg); |
2440 | break; | |
cd6f1169 | 2441 | case QEMU_OPTION_h: |
15f82208 | 2442 | help(0); |
cd6f1169 | 2443 | break; |
9bd7e6d9 PB |
2444 | case QEMU_OPTION_version: |
2445 | version(); | |
2446 | exit(0); | |
2447 | break; | |
00f82b8a | 2448 | case QEMU_OPTION_m: { |
70b4f4bb | 2449 | int64_t value; |
9f9b17a4 JS |
2450 | |
2451 | value = strtosz(optarg, NULL); | |
2452 | if (value < 0) { | |
00f82b8a | 2453 | fprintf(stderr, "qemu: invalid ram size: %s\n", optarg); |
cd6f1169 FB |
2454 | exit(1); |
2455 | } | |
00f82b8a AJ |
2456 | |
2457 | /* On 32-bit hosts, QEMU is limited by virtual address space */ | |
4a1418e0 | 2458 | if (value > (2047 << 20) && HOST_LONG_BITS == 32) { |
00f82b8a AJ |
2459 | fprintf(stderr, "qemu: at most 2047 MB RAM can be simulated\n"); |
2460 | exit(1); | |
2461 | } | |
c227f099 | 2462 | if (value != (uint64_t)(ram_addr_t)value) { |
00f82b8a AJ |
2463 | fprintf(stderr, "qemu: ram size too large\n"); |
2464 | exit(1); | |
2465 | } | |
2466 | ram_size = value; | |
cd6f1169 | 2467 | break; |
00f82b8a | 2468 | } |
c902760f MT |
2469 | case QEMU_OPTION_mempath: |
2470 | mem_path = optarg; | |
2471 | break; | |
2472 | #ifdef MAP_POPULATE | |
2473 | case QEMU_OPTION_mem_prealloc: | |
2474 | mem_prealloc = 1; | |
2475 | break; | |
2476 | #endif | |
cd6f1169 | 2477 | case QEMU_OPTION_d: |
c235d738 MF |
2478 | log_mask = optarg; |
2479 | break; | |
2480 | case QEMU_OPTION_D: | |
2481 | log_file = optarg; | |
cd6f1169 | 2482 | break; |
cd6f1169 | 2483 | case QEMU_OPTION_s: |
59030a8c | 2484 | gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; |
cd6f1169 | 2485 | break; |
59030a8c AL |
2486 | case QEMU_OPTION_gdb: |
2487 | gdbstub_dev = optarg; | |
cd6f1169 | 2488 | break; |
cd6f1169 | 2489 | case QEMU_OPTION_L: |
5cea8590 | 2490 | data_dir = optarg; |
cd6f1169 | 2491 | break; |
1192dad8 JM |
2492 | case QEMU_OPTION_bios: |
2493 | bios_name = optarg; | |
2494 | break; | |
1b530a6d AJ |
2495 | case QEMU_OPTION_singlestep: |
2496 | singlestep = 1; | |
2497 | break; | |
cd6f1169 | 2498 | case QEMU_OPTION_S: |
3c07f8e8 | 2499 | autostart = 0; |
cd6f1169 | 2500 | break; |
3d11d0eb FB |
2501 | case QEMU_OPTION_k: |
2502 | keyboard_layout = optarg; | |
2503 | break; | |
ee22c2f7 FB |
2504 | case QEMU_OPTION_localtime: |
2505 | rtc_utc = 0; | |
2506 | break; | |
3893c124 | 2507 | case QEMU_OPTION_vga: |
2508 | select_vgahw (optarg); | |
1bfe856e | 2509 | break; |
e9b137c2 FB |
2510 | case QEMU_OPTION_g: |
2511 | { | |
2512 | const char *p; | |
2513 | int w, h, depth; | |
2514 | p = optarg; | |
2515 | w = strtol(p, (char **)&p, 10); | |
2516 | if (w <= 0) { | |
2517 | graphic_error: | |
2518 | fprintf(stderr, "qemu: invalid resolution or depth\n"); | |
2519 | exit(1); | |
2520 | } | |
2521 | if (*p != 'x') | |
2522 | goto graphic_error; | |
2523 | p++; | |
2524 | h = strtol(p, (char **)&p, 10); | |
2525 | if (h <= 0) | |
2526 | goto graphic_error; | |
2527 | if (*p == 'x') { | |
2528 | p++; | |
2529 | depth = strtol(p, (char **)&p, 10); | |
5fafdf24 | 2530 | if (depth != 8 && depth != 15 && depth != 16 && |
e9b137c2 FB |
2531 | depth != 24 && depth != 32) |
2532 | goto graphic_error; | |
2533 | } else if (*p == '\0') { | |
2534 | depth = graphic_depth; | |
2535 | } else { | |
2536 | goto graphic_error; | |
2537 | } | |
3b46e624 | 2538 | |
e9b137c2 FB |
2539 | graphic_width = w; |
2540 | graphic_height = h; | |
2541 | graphic_depth = depth; | |
2542 | } | |
2543 | break; | |
20d8a3ed TS |
2544 | case QEMU_OPTION_echr: |
2545 | { | |
2546 | char *r; | |
2547 | term_escape_char = strtol(optarg, &r, 0); | |
2548 | if (r == optarg) | |
2549 | printf("Bad argument to echr\n"); | |
2550 | break; | |
2551 | } | |
82c643ff | 2552 | case QEMU_OPTION_monitor: |
6ca5582d GH |
2553 | monitor_parse(optarg, "readline"); |
2554 | default_monitor = 0; | |
2555 | break; | |
2556 | case QEMU_OPTION_qmp: | |
2557 | monitor_parse(optarg, "control"); | |
2d114dc1 | 2558 | default_monitor = 0; |
82c643ff | 2559 | break; |
22a0e04b | 2560 | case QEMU_OPTION_mon: |
3329f07b | 2561 | opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1); |
22a0e04b | 2562 | if (!opts) { |
22a0e04b GH |
2563 | exit(1); |
2564 | } | |
2d114dc1 | 2565 | default_monitor = 0; |
22a0e04b | 2566 | break; |
191bc01b | 2567 | case QEMU_OPTION_chardev: |
3329f07b | 2568 | opts = qemu_opts_parse(qemu_find_opts("chardev"), optarg, 1); |
191bc01b | 2569 | if (!opts) { |
191bc01b GH |
2570 | exit(1); |
2571 | } | |
191bc01b | 2572 | break; |
74db920c | 2573 | case QEMU_OPTION_fsdev: |
03b0ba70 GH |
2574 | olist = qemu_find_opts("fsdev"); |
2575 | if (!olist) { | |
2576 | fprintf(stderr, "fsdev is not supported by this qemu build.\n"); | |
2577 | exit(1); | |
2578 | } | |
2579 | opts = qemu_opts_parse(olist, optarg, 1); | |
74db920c GS |
2580 | if (!opts) { |
2581 | fprintf(stderr, "parse error: %s\n", optarg); | |
2582 | exit(1); | |
2583 | } | |
2584 | break; | |
3d54abc7 | 2585 | case QEMU_OPTION_virtfs: { |
e14ea479 SH |
2586 | QemuOpts *fsdev; |
2587 | QemuOpts *device; | |
3d54abc7 | 2588 | |
03b0ba70 GH |
2589 | olist = qemu_find_opts("virtfs"); |
2590 | if (!olist) { | |
2591 | fprintf(stderr, "virtfs is not supported by this qemu build.\n"); | |
2592 | exit(1); | |
2593 | } | |
2594 | opts = qemu_opts_parse(olist, optarg, 1); | |
3d54abc7 GS |
2595 | if (!opts) { |
2596 | fprintf(stderr, "parse error: %s\n", optarg); | |
2597 | exit(1); | |
2598 | } | |
2599 | ||
9ce56db6 VJ |
2600 | if (qemu_opt_get(opts, "fstype") == NULL || |
2601 | qemu_opt_get(opts, "mount_tag") == NULL || | |
2602 | qemu_opt_get(opts, "path") == NULL || | |
2603 | qemu_opt_get(opts, "security_model") == NULL) { | |
2604 | fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/," | |
12848bfc | 2605 | "security_model=[mapped|passthrough|none]," |
e14ea479 | 2606 | "mount_tag=tag.\n"); |
9ce56db6 VJ |
2607 | exit(1); |
2608 | } | |
2609 | ||
e14ea479 SH |
2610 | fsdev = qemu_opts_create(qemu_find_opts("fsdev"), |
2611 | qemu_opt_get(opts, "mount_tag"), 1); | |
2612 | if (!fsdev) { | |
2613 | fprintf(stderr, "duplicate fsdev id: %s\n", | |
2614 | qemu_opt_get(opts, "mount_tag")); | |
3d54abc7 GS |
2615 | exit(1); |
2616 | } | |
e14ea479 SH |
2617 | qemu_opt_set(fsdev, "fstype", qemu_opt_get(opts, "fstype")); |
2618 | qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); | |
2619 | qemu_opt_set(fsdev, "security_model", | |
2620 | qemu_opt_get(opts, "security_model")); | |
2621 | ||
2622 | device = qemu_opts_create(qemu_find_opts("device"), NULL, 0); | |
2623 | qemu_opt_set(device, "driver", "virtio-9p-pci"); | |
2624 | qemu_opt_set(device, "fsdev", | |
2625 | qemu_opt_get(opts, "mount_tag")); | |
2626 | qemu_opt_set(device, "mount_tag", | |
2627 | qemu_opt_get(opts, "mount_tag")); | |
3d54abc7 GS |
2628 | break; |
2629 | } | |
82c643ff | 2630 | case QEMU_OPTION_serial: |
998bbd74 GH |
2631 | add_device_config(DEV_SERIAL, optarg); |
2632 | default_serial = 0; | |
18141ed6 JK |
2633 | if (strncmp(optarg, "mon:", 4) == 0) { |
2634 | default_monitor = 0; | |
2635 | } | |
82c643ff | 2636 | break; |
9dd986cc | 2637 | case QEMU_OPTION_watchdog: |
09aaa160 MA |
2638 | if (watchdog) { |
2639 | fprintf(stderr, | |
2640 | "qemu: only one watchdog option may be given\n"); | |
2641 | return 1; | |
2642 | } | |
2643 | watchdog = optarg; | |
9dd986cc RJ |
2644 | break; |
2645 | case QEMU_OPTION_watchdog_action: | |
2646 | if (select_watchdog_action(optarg) == -1) { | |
2647 | fprintf(stderr, "Unknown -watchdog-action parameter\n"); | |
2648 | exit(1); | |
2649 | } | |
2650 | break; | |
51ecf136 | 2651 | case QEMU_OPTION_virtiocon: |
aee1b935 GH |
2652 | add_device_config(DEV_VIRTCON, optarg); |
2653 | default_virtcon = 0; | |
18141ed6 JK |
2654 | if (strncmp(optarg, "mon:", 4) == 0) { |
2655 | default_monitor = 0; | |
2656 | } | |
51ecf136 | 2657 | break; |
6508fe59 | 2658 | case QEMU_OPTION_parallel: |
6a5e8b0e GH |
2659 | add_device_config(DEV_PARALLEL, optarg); |
2660 | default_parallel = 0; | |
18141ed6 JK |
2661 | if (strncmp(optarg, "mon:", 4) == 0) { |
2662 | default_monitor = 0; | |
2663 | } | |
6508fe59 | 2664 | break; |
c9f398e5 PA |
2665 | case QEMU_OPTION_debugcon: |
2666 | add_device_config(DEV_DEBUGCON, optarg); | |
2667 | break; | |
d63d307f FB |
2668 | case QEMU_OPTION_loadvm: |
2669 | loadvm = optarg; | |
2670 | break; | |
2671 | case QEMU_OPTION_full_screen: | |
2672 | full_screen = 1; | |
2673 | break; | |
667accab | 2674 | #ifdef CONFIG_SDL |
43523e93 TS |
2675 | case QEMU_OPTION_no_frame: |
2676 | no_frame = 1; | |
2677 | break; | |
3780e197 TS |
2678 | case QEMU_OPTION_alt_grab: |
2679 | alt_grab = 1; | |
2680 | break; | |
0ca9f8a4 DK |
2681 | case QEMU_OPTION_ctrl_grab: |
2682 | ctrl_grab = 1; | |
2683 | break; | |
667accab TS |
2684 | case QEMU_OPTION_no_quit: |
2685 | no_quit = 1; | |
2686 | break; | |
7d957bd8 | 2687 | case QEMU_OPTION_sdl: |
993fbfdb | 2688 | display_type = DT_SDL; |
7d957bd8 | 2689 | break; |
58fc096c JS |
2690 | #else |
2691 | case QEMU_OPTION_no_frame: | |
2692 | case QEMU_OPTION_alt_grab: | |
2693 | case QEMU_OPTION_ctrl_grab: | |
2694 | case QEMU_OPTION_no_quit: | |
2695 | case QEMU_OPTION_sdl: | |
2696 | fprintf(stderr, "SDL support is disabled\n"); | |
2697 | exit(1); | |
667accab | 2698 | #endif |
f7cce898 | 2699 | case QEMU_OPTION_pidfile: |
93815bc2 | 2700 | pid_file = optarg; |
f7cce898 | 2701 | break; |
a09db21f FB |
2702 | case QEMU_OPTION_win2k_hack: |
2703 | win2k_install_hack = 1; | |
2704 | break; | |
73822ec8 AL |
2705 | case QEMU_OPTION_rtc_td_hack: |
2706 | rtc_td_hack = 1; | |
2707 | break; | |
8a92ea2f | 2708 | case QEMU_OPTION_acpitable: |
de06f8d1 | 2709 | do_acpitable_option(optarg); |
8a92ea2f | 2710 | break; |
b6f6e3d3 | 2711 | case QEMU_OPTION_smbios: |
de06f8d1 | 2712 | do_smbios_option(optarg); |
b6f6e3d3 | 2713 | break; |
7ba1e619 | 2714 | case QEMU_OPTION_enable_kvm: |
303d4e86 AP |
2715 | olist = qemu_find_opts("machine"); |
2716 | qemu_opts_reset(olist); | |
2717 | qemu_opts_parse(olist, "accel=kvm", 0); | |
2718 | break; | |
2719 | case QEMU_OPTION_machine: | |
2720 | olist = qemu_find_opts("machine"); | |
2721 | qemu_opts_reset(olist); | |
9052ea6b | 2722 | opts = qemu_opts_parse(olist, optarg, 1); |
303d4e86 AP |
2723 | if (!opts) { |
2724 | fprintf(stderr, "parse error: %s\n", optarg); | |
2725 | exit(1); | |
2726 | } | |
2645c6dc JK |
2727 | optarg = qemu_opt_get(opts, "type"); |
2728 | if (optarg) { | |
2729 | machine = machine_parse(optarg); | |
2730 | } | |
7ba1e619 | 2731 | break; |
bb36d470 FB |
2732 | case QEMU_OPTION_usb: |
2733 | usb_enabled = 1; | |
2734 | break; | |
a594cfbf FB |
2735 | case QEMU_OPTION_usbdevice: |
2736 | usb_enabled = 1; | |
bd3c948d GH |
2737 | add_device_config(DEV_USB, optarg); |
2738 | break; | |
2739 | case QEMU_OPTION_device: | |
3329f07b | 2740 | if (!qemu_opts_parse(qemu_find_opts("device"), optarg, 1)) { |
f31d07d1 GH |
2741 | exit(1); |
2742 | } | |
a594cfbf | 2743 | break; |
6a00d601 | 2744 | case QEMU_OPTION_smp: |
dc6b1c09 | 2745 | smp_parse(optarg); |
b2097003 | 2746 | if (smp_cpus < 1) { |
6a00d601 FB |
2747 | fprintf(stderr, "Invalid number of CPUs\n"); |
2748 | exit(1); | |
2749 | } | |
6be68d7e JS |
2750 | if (max_cpus < smp_cpus) { |
2751 | fprintf(stderr, "maxcpus must be equal to or greater than " | |
2752 | "smp\n"); | |
2753 | exit(1); | |
2754 | } | |
2755 | if (max_cpus > 255) { | |
2756 | fprintf(stderr, "Unsupported number of maxcpus\n"); | |
2757 | exit(1); | |
2758 | } | |
6a00d601 | 2759 | break; |
24236869 | 2760 | case QEMU_OPTION_vnc: |
821601ea | 2761 | #ifdef CONFIG_VNC |
6b62dc2d | 2762 | display_remote++; |
821601ea JS |
2763 | vnc_display = optarg; |
2764 | #else | |
2765 | fprintf(stderr, "VNC support is disabled\n"); | |
2766 | exit(1); | |
2767 | #endif | |
2768 | break; | |
6515b203 FB |
2769 | case QEMU_OPTION_no_acpi: |
2770 | acpi_enabled = 0; | |
2771 | break; | |
16b29ae1 AL |
2772 | case QEMU_OPTION_no_hpet: |
2773 | no_hpet = 1; | |
2774 | break; | |
7d4c3d53 MA |
2775 | case QEMU_OPTION_balloon: |
2776 | if (balloon_parse(optarg) < 0) { | |
2777 | fprintf(stderr, "Unknown -balloon argument %s\n", optarg); | |
2778 | exit(1); | |
2779 | } | |
df97b920 | 2780 | break; |
d1beab82 FB |
2781 | case QEMU_OPTION_no_reboot: |
2782 | no_reboot = 1; | |
2783 | break; | |
b2f76161 AJ |
2784 | case QEMU_OPTION_no_shutdown: |
2785 | no_shutdown = 1; | |
2786 | break; | |
9467cd46 AZ |
2787 | case QEMU_OPTION_show_cursor: |
2788 | cursor_hide = 0; | |
2789 | break; | |
8fcb1b90 BS |
2790 | case QEMU_OPTION_uuid: |
2791 | if(qemu_uuid_parse(optarg, qemu_uuid) < 0) { | |
2792 | fprintf(stderr, "Fail to parse UUID string." | |
2793 | " Wrong format.\n"); | |
2794 | exit(1); | |
2795 | } | |
2796 | break; | |
9ae02555 TS |
2797 | case QEMU_OPTION_option_rom: |
2798 | if (nb_option_roms >= MAX_OPTION_ROMS) { | |
2799 | fprintf(stderr, "Too many option ROMs\n"); | |
2800 | exit(1); | |
2801 | } | |
2e55e842 GN |
2802 | opts = qemu_opts_parse(qemu_find_opts("option-rom"), optarg, 1); |
2803 | option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile"); | |
2804 | option_rom[nb_option_roms].bootindex = | |
2805 | qemu_opt_get_number(opts, "bootindex", -1); | |
2806 | if (!option_rom[nb_option_roms].name) { | |
2807 | fprintf(stderr, "Option ROM file is not specified\n"); | |
2808 | exit(1); | |
2809 | } | |
9ae02555 TS |
2810 | nb_option_roms++; |
2811 | break; | |
8e71621f PB |
2812 | case QEMU_OPTION_semihosting: |
2813 | semihosting_enabled = 1; | |
2814 | break; | |
c35734b2 | 2815 | case QEMU_OPTION_name: |
1889465a AK |
2816 | qemu_name = qemu_strdup(optarg); |
2817 | { | |
2818 | char *p = strchr(qemu_name, ','); | |
2819 | if (p != NULL) { | |
2820 | *p++ = 0; | |
2821 | if (strncmp(p, "process=", 8)) { | |
5697f6ae | 2822 | fprintf(stderr, "Unknown subargument %s to -name\n", p); |
1889465a AK |
2823 | exit(1); |
2824 | } | |
2825 | p += 8; | |
ce798cf2 | 2826 | os_set_proc_name(p); |
1889465a AK |
2827 | } |
2828 | } | |
c35734b2 | 2829 | break; |
66508601 BS |
2830 | case QEMU_OPTION_prom_env: |
2831 | if (nb_prom_envs >= MAX_PROM_ENVS) { | |
2832 | fprintf(stderr, "Too many prom variables\n"); | |
2833 | exit(1); | |
2834 | } | |
2835 | prom_envs[nb_prom_envs] = optarg; | |
2836 | nb_prom_envs++; | |
2837 | break; | |
2b8f2d41 AZ |
2838 | case QEMU_OPTION_old_param: |
2839 | old_param = 1; | |
05ebd537 | 2840 | break; |
f3dcfada TS |
2841 | case QEMU_OPTION_clock: |
2842 | configure_alarms(optarg); | |
2843 | break; | |
7e0af5d0 | 2844 | case QEMU_OPTION_startdate: |
1ed2fc1f JK |
2845 | configure_rtc_date_offset(optarg, 1); |
2846 | break; | |
2847 | case QEMU_OPTION_rtc: | |
3329f07b | 2848 | opts = qemu_opts_parse(qemu_find_opts("rtc"), optarg, 0); |
1ed2fc1f | 2849 | if (!opts) { |
1ed2fc1f | 2850 | exit(1); |
7e0af5d0 | 2851 | } |
1ed2fc1f | 2852 | configure_rtc(opts); |
7e0af5d0 | 2853 | break; |
26a5f13b FB |
2854 | case QEMU_OPTION_tb_size: |
2855 | tb_size = strtol(optarg, NULL, 0); | |
2856 | if (tb_size < 0) | |
2857 | tb_size = 0; | |
2858 | break; | |
2e70f6ef | 2859 | case QEMU_OPTION_icount: |
4e3de9e9 | 2860 | icount_option = optarg; |
2e70f6ef | 2861 | break; |
5bb7910a AL |
2862 | case QEMU_OPTION_incoming: |
2863 | incoming = optarg; | |
8e84865e | 2864 | incoming_expected = true; |
5bb7910a | 2865 | break; |
d8c208dd GH |
2866 | case QEMU_OPTION_nodefaults: |
2867 | default_serial = 0; | |
2868 | default_parallel = 0; | |
aee1b935 | 2869 | default_virtcon = 0; |
d8c208dd GH |
2870 | default_monitor = 0; |
2871 | default_vga = 0; | |
cb4522cc | 2872 | default_net = 0; |
ac33f8fa GH |
2873 | default_floppy = 0; |
2874 | default_cdrom = 0; | |
2875 | default_sdcard = 0; | |
d8c208dd | 2876 | break; |
e37630ca | 2877 | case QEMU_OPTION_xen_domid: |
ad96090a BS |
2878 | if (!(xen_available())) { |
2879 | printf("Option %s not supported for this target\n", popt->name); | |
2880 | exit(1); | |
2881 | } | |
e37630ca AL |
2882 | xen_domid = atoi(optarg); |
2883 | break; | |
2884 | case QEMU_OPTION_xen_create: | |
ad96090a BS |
2885 | if (!(xen_available())) { |
2886 | printf("Option %s not supported for this target\n", popt->name); | |
2887 | exit(1); | |
2888 | } | |
e37630ca AL |
2889 | xen_mode = XEN_CREATE; |
2890 | break; | |
2891 | case QEMU_OPTION_xen_attach: | |
ad96090a BS |
2892 | if (!(xen_available())) { |
2893 | printf("Option %s not supported for this target\n", popt->name); | |
2894 | exit(1); | |
2895 | } | |
e37630ca AL |
2896 | xen_mode = XEN_ATTACH; |
2897 | break; | |
ab6540d5 PS |
2898 | #ifdef CONFIG_SIMPLE_TRACE |
2899 | case QEMU_OPTION_trace: | |
2900 | opts = qemu_opts_parse(qemu_find_opts("trace"), optarg, 0); | |
2901 | if (opts) { | |
2902 | trace_file = qemu_opt_get(opts, "file"); | |
2903 | } | |
2904 | break; | |
2905 | #endif | |
715a664a GH |
2906 | case QEMU_OPTION_readconfig: |
2907 | { | |
dcfb0939 KW |
2908 | int ret = qemu_read_config_file(optarg); |
2909 | if (ret < 0) { | |
2910 | fprintf(stderr, "read config %s: %s\n", optarg, | |
2911 | strerror(-ret)); | |
715a664a GH |
2912 | exit(1); |
2913 | } | |
715a664a GH |
2914 | break; |
2915 | } | |
29b0040b GH |
2916 | case QEMU_OPTION_spice: |
2917 | olist = qemu_find_opts("spice"); | |
2918 | if (!olist) { | |
2919 | fprintf(stderr, "spice is not supported by this qemu build.\n"); | |
2920 | exit(1); | |
2921 | } | |
2922 | opts = qemu_opts_parse(olist, optarg, 0); | |
2923 | if (!opts) { | |
2924 | fprintf(stderr, "parse error: %s\n", optarg); | |
2925 | exit(1); | |
2926 | } | |
2927 | break; | |
715a664a GH |
2928 | case QEMU_OPTION_writeconfig: |
2929 | { | |
2930 | FILE *fp; | |
2931 | if (strcmp(optarg, "-") == 0) { | |
2932 | fp = stdout; | |
2933 | } else { | |
2934 | fp = fopen(optarg, "w"); | |
2935 | if (fp == NULL) { | |
2936 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); | |
2937 | exit(1); | |
2938 | } | |
2939 | } | |
2940 | qemu_config_write(fp); | |
2941 | fclose(fp); | |
2942 | break; | |
2943 | } | |
59a5264b JS |
2944 | default: |
2945 | os_parse_cmd_args(popt->index, optarg); | |
cd6f1169 | 2946 | } |
0824d6fc FB |
2947 | } |
2948 | } | |
0f0bc3f1 | 2949 | loc_set_none(); |
c235d738 MF |
2950 | |
2951 | /* Open the logfile at this point, if necessary. We can't open the logfile | |
2952 | * when encountering either of the logging options (-d or -D) because the | |
2953 | * other one may be encountered later on the command line, changing the | |
2954 | * location or level of logging. | |
2955 | */ | |
2956 | if (log_mask) { | |
2957 | if (log_file) { | |
2958 | set_cpu_log_filename(log_file); | |
2959 | } | |
2960 | set_cpu_log(log_mask); | |
2961 | } | |
330d0414 | 2962 | |
31d3c9b8 SH |
2963 | if (!st_init(trace_file)) { |
2964 | fprintf(stderr, "warning: unable to initialize simple trace backend\n"); | |
2965 | } | |
0b5538c3 | 2966 | |
5cea8590 PB |
2967 | /* If no data_dir is specified then try to find it relative to the |
2968 | executable path. */ | |
2969 | if (!data_dir) { | |
6170540b | 2970 | data_dir = os_find_datadir(argv[0]); |
5cea8590 PB |
2971 | } |
2972 | /* If all else fails use the install patch specified when building. */ | |
2973 | if (!data_dir) { | |
1dabe05c | 2974 | data_dir = CONFIG_QEMU_DATADIR; |
5cea8590 PB |
2975 | } |
2976 | ||
6be68d7e JS |
2977 | /* |
2978 | * Default to max_cpus = smp_cpus, in case the user doesn't | |
2979 | * specify a max_cpus value. | |
2980 | */ | |
2981 | if (!max_cpus) | |
2982 | max_cpus = smp_cpus; | |
2983 | ||
3d878caa | 2984 | machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */ |
b2097003 AL |
2985 | if (smp_cpus > machine->max_cpus) { |
2986 | fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus " | |
2987 | "supported by machine `%s' (%d)\n", smp_cpus, machine->name, | |
2988 | machine->max_cpus); | |
2989 | exit(1); | |
2990 | } | |
2991 | ||
67b724e6 AP |
2992 | /* |
2993 | * Get the default machine options from the machine if it is not already | |
2994 | * specified either by the configuration file or by the command line. | |
2995 | */ | |
2996 | if (machine->default_machine_opts) { | |
2997 | QemuOptsList *list = qemu_find_opts("machine"); | |
2998 | const char *p = NULL; | |
2999 | ||
3000 | if (!QTAILQ_EMPTY(&list->head)) { | |
3001 | p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel"); | |
3002 | } | |
3003 | if (p == NULL) { | |
9052ea6b JK |
3004 | qemu_opts_reset(list); |
3005 | opts = qemu_opts_parse(list, machine->default_machine_opts, 0); | |
67b724e6 AP |
3006 | if (!opts) { |
3007 | fprintf(stderr, "parse error for machine %s: %s\n", | |
3008 | machine->name, machine->default_machine_opts); | |
3009 | exit(1); | |
3010 | } | |
3011 | } | |
3012 | } | |
3013 | ||
3329f07b GH |
3014 | qemu_opts_foreach(qemu_find_opts("device"), default_driver_check, NULL, 0); |
3015 | qemu_opts_foreach(qemu_find_opts("global"), default_driver_check, NULL, 0); | |
998bbd74 | 3016 | |
986c5f78 GH |
3017 | if (machine->no_serial) { |
3018 | default_serial = 0; | |
3019 | } | |
3020 | if (machine->no_parallel) { | |
3021 | default_parallel = 0; | |
3022 | } | |
3023 | if (!machine->use_virtcon) { | |
3024 | default_virtcon = 0; | |
3025 | } | |
3026 | if (machine->no_vga) { | |
3027 | default_vga = 0; | |
3028 | } | |
ac33f8fa GH |
3029 | if (machine->no_floppy) { |
3030 | default_floppy = 0; | |
3031 | } | |
3032 | if (machine->no_cdrom) { | |
3033 | default_cdrom = 0; | |
3034 | } | |
3035 | if (machine->no_sdcard) { | |
3036 | default_sdcard = 0; | |
3037 | } | |
986c5f78 | 3038 | |
993fbfdb | 3039 | if (display_type == DT_NOGRAPHIC) { |
6a5e8b0e GH |
3040 | if (default_parallel) |
3041 | add_device_config(DEV_PARALLEL, "null"); | |
e1c09175 GH |
3042 | if (default_serial && default_monitor) { |
3043 | add_device_config(DEV_SERIAL, "mon:stdio"); | |
986c5f78 GH |
3044 | } else if (default_virtcon && default_monitor) { |
3045 | add_device_config(DEV_VIRTCON, "mon:stdio"); | |
e1c09175 GH |
3046 | } else { |
3047 | if (default_serial) | |
3048 | add_device_config(DEV_SERIAL, "stdio"); | |
986c5f78 GH |
3049 | if (default_virtcon) |
3050 | add_device_config(DEV_VIRTCON, "stdio"); | |
e1c09175 | 3051 | if (default_monitor) |
6ca5582d | 3052 | monitor_parse("stdio", "readline"); |
e1c09175 | 3053 | } |
998bbd74 GH |
3054 | } else { |
3055 | if (default_serial) | |
3056 | add_device_config(DEV_SERIAL, "vc:80Cx24C"); | |
6a5e8b0e GH |
3057 | if (default_parallel) |
3058 | add_device_config(DEV_PARALLEL, "vc:80Cx24C"); | |
abdeed06 | 3059 | if (default_monitor) |
6ca5582d | 3060 | monitor_parse("vc:80Cx24C", "readline"); |
38536da1 AG |
3061 | if (default_virtcon) |
3062 | add_device_config(DEV_VIRTCON, "vc:80Cx24C"); | |
bc0129d9 | 3063 | } |
64465297 GH |
3064 | if (default_vga) |
3065 | vga_interface_type = VGA_CIRRUS; | |
bc0129d9 | 3066 | |
a5829fd9 T |
3067 | socket_init(); |
3068 | ||
3329f07b | 3069 | if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) |
1a688d3b | 3070 | exit(1); |
758e8e38 | 3071 | #ifdef CONFIG_VIRTFS |
3329f07b | 3072 | if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) { |
74db920c GS |
3073 | exit(1); |
3074 | } | |
3075 | #endif | |
1a688d3b | 3076 | |
eb505be1 | 3077 | os_daemonize(); |
71e3ceb8 | 3078 | |
aa26bb2d | 3079 | if (pid_file && qemu_create_pidfile(pid_file) != 0) { |
eb505be1 | 3080 | os_pidfile_error(); |
93815bc2 TS |
3081 | exit(1); |
3082 | } | |
3083 | ||
303d4e86 | 3084 | configure_accelerator(); |
214910a7 | 3085 | |
3fcf7b6b AL |
3086 | if (qemu_init_main_loop()) { |
3087 | fprintf(stderr, "qemu_init_main_loop failed\n"); | |
3088 | exit(1); | |
3089 | } | |
a20dd508 | 3090 | linux_boot = (kernel_filename != NULL); |
6c41b272 | 3091 | |
f8d39c01 TS |
3092 | if (!linux_boot && *kernel_cmdline != '\0') { |
3093 | fprintf(stderr, "-append only allowed with -kernel option\n"); | |
3094 | exit(1); | |
3095 | } | |
3096 | ||
3097 | if (!linux_boot && initrd_filename != NULL) { | |
3098 | fprintf(stderr, "-initrd only allowed with -kernel option\n"); | |
3099 | exit(1); | |
3100 | } | |
3101 | ||
9156d763 | 3102 | os_set_line_buffering(); |
3b46e624 | 3103 | |
7183b4b4 AL |
3104 | if (init_timer_alarm() < 0) { |
3105 | fprintf(stderr, "could not initialize alarm timer\n"); | |
3106 | exit(1); | |
3107 | } | |
4e3de9e9 | 3108 | configure_icount(icount_option); |
634fce96 | 3109 | |
dc1c9fe8 MM |
3110 | if (net_init_clients() < 0) { |
3111 | exit(1); | |
702c651c | 3112 | } |
f1510b2c | 3113 | |
dc72ac14 | 3114 | /* init the bluetooth world */ |
bd3c948d GH |
3115 | if (foreach_device_config(DEV_BT, bt_parse)) |
3116 | exit(1); | |
dc72ac14 | 3117 | |
0824d6fc | 3118 | /* init the memory */ |
94a6b54f PB |
3119 | if (ram_size == 0) |
3120 | ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; | |
9ae02555 | 3121 | |
26a5f13b FB |
3122 | /* init the dynamic translator */ |
3123 | cpu_exec_init_all(tb_size * 1024 * 1024); | |
3124 | ||
eb852011 | 3125 | bdrv_init_with_whitelist(); |
c4b1fcc0 | 3126 | |
c163b5ca LS |
3127 | blk_mig_init(); |
3128 | ||
e4bcb14c | 3129 | /* open the virtual block devices */ |
9dfd7c7a | 3130 | if (snapshot) |
3329f07b GH |
3131 | qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, NULL, 0); |
3132 | if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0) | |
9dfd7c7a | 3133 | exit(1); |
3e3d5815 | 3134 | |
4e5d9b57 MA |
3135 | default_drive(default_cdrom, snapshot, machine->use_scsi, |
3136 | IF_DEFAULT, 2, CDROM_OPTS); | |
3137 | default_drive(default_floppy, snapshot, machine->use_scsi, | |
3138 | IF_FLOPPY, 0, FD_OPTS); | |
3139 | default_drive(default_sdcard, snapshot, machine->use_scsi, | |
3140 | IF_SD, 0, SD_OPTS); | |
3141 | ||
97ab12d4 | 3142 | register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL, |
c163b5ca | 3143 | ram_load, NULL); |
8a7ddc38 | 3144 | |
268a362c AL |
3145 | if (nb_numa_nodes > 0) { |
3146 | int i; | |
3147 | ||
ea0e5418 SL |
3148 | if (nb_numa_nodes > MAX_NODES) { |
3149 | nb_numa_nodes = MAX_NODES; | |
268a362c AL |
3150 | } |
3151 | ||
3152 | /* If no memory size if given for any node, assume the default case | |
3153 | * and distribute the available memory equally across all nodes | |
3154 | */ | |
3155 | for (i = 0; i < nb_numa_nodes; i++) { | |
3156 | if (node_mem[i] != 0) | |
3157 | break; | |
3158 | } | |
3159 | if (i == nb_numa_nodes) { | |
3160 | uint64_t usedmem = 0; | |
3161 | ||
3162 | /* On Linux, the each node's border has to be 8MB aligned, | |
3163 | * the final node gets the rest. | |
3164 | */ | |
3165 | for (i = 0; i < nb_numa_nodes - 1; i++) { | |
3166 | node_mem[i] = (ram_size / nb_numa_nodes) & ~((1 << 23UL) - 1); | |
3167 | usedmem += node_mem[i]; | |
3168 | } | |
3169 | node_mem[i] = ram_size - usedmem; | |
3170 | } | |
3171 | ||
3172 | for (i = 0; i < nb_numa_nodes; i++) { | |
3173 | if (node_cpumask[i] != 0) | |
3174 | break; | |
3175 | } | |
3176 | /* assigning the VCPUs round-robin is easier to implement, guest OSes | |
3177 | * must cope with this anyway, because there are BIOSes out there in | |
3178 | * real machines which also use this scheme. | |
3179 | */ | |
3180 | if (i == nb_numa_nodes) { | |
3181 | for (i = 0; i < smp_cpus; i++) { | |
3182 | node_cpumask[i % nb_numa_nodes] |= 1 << i; | |
3183 | } | |
3184 | } | |
3185 | } | |
3186 | ||
3329f07b | 3187 | if (qemu_opts_foreach(qemu_find_opts("mon"), mon_init_func, NULL, 1) != 0) { |
157b9319 JK |
3188 | exit(1); |
3189 | } | |
3190 | ||
998bbd74 GH |
3191 | if (foreach_device_config(DEV_SERIAL, serial_parse) < 0) |
3192 | exit(1); | |
6a5e8b0e GH |
3193 | if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0) |
3194 | exit(1); | |
aee1b935 GH |
3195 | if (foreach_device_config(DEV_VIRTCON, virtcon_parse) < 0) |
3196 | exit(1); | |
c9f398e5 PA |
3197 | if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0) |
3198 | exit(1); | |
2796dae0 | 3199 | |
aae9460e PB |
3200 | module_call_init(MODULE_INIT_DEVICE); |
3201 | ||
3329f07b | 3202 | if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0) != 0) |
ff952ba2 MA |
3203 | exit(0); |
3204 | ||
09aaa160 MA |
3205 | if (watchdog) { |
3206 | i = select_watchdog(watchdog); | |
3207 | if (i > 0) | |
3208 | exit (i == 1 ? 1 : 0); | |
3209 | } | |
3210 | ||
b6b61144 | 3211 | if (machine->compat_props) { |
458fb679 | 3212 | qdev_prop_register_global_list(machine->compat_props); |
b6b61144 | 3213 | } |
d0fef6fb GH |
3214 | qemu_add_globals(); |
3215 | ||
fbe1b595 | 3216 | machine->init(ram_size, boot_devices, |
3023f332 AL |
3217 | kernel_filename, kernel_cmdline, initrd_filename, cpu_model); |
3218 | ||
ea375f9a | 3219 | cpu_synchronize_all_post_init(); |
268a362c | 3220 | |
87d0a28e | 3221 | set_numa_modes(); |
268a362c | 3222 | |
6f338c34 AL |
3223 | current_machine = machine; |
3224 | ||
3023f332 AL |
3225 | /* init USB devices */ |
3226 | if (usb_enabled) { | |
0752706d MA |
3227 | if (foreach_device_config(DEV_USB, usb_parse) < 0) |
3228 | exit(1); | |
3023f332 AL |
3229 | } |
3230 | ||
bd3c948d | 3231 | /* init generic devices */ |
3329f07b | 3232 | if (qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, 1) != 0) |
bd3c948d GH |
3233 | exit(1); |
3234 | ||
668680f7 MA |
3235 | net_check_clients(); |
3236 | ||
3023f332 | 3237 | /* just use the first displaystate for the moment */ |
b473df6e | 3238 | ds = get_displaystate(); |
993fbfdb | 3239 | |
a3e22260 GH |
3240 | if (using_spice) |
3241 | display_remote++; | |
6b62dc2d | 3242 | if (display_type == DT_DEFAULT && !display_remote) { |
993fbfdb AL |
3243 | #if defined(CONFIG_SDL) || defined(CONFIG_COCOA) |
3244 | display_type = DT_SDL; | |
821601ea | 3245 | #elif defined(CONFIG_VNC) |
993fbfdb AL |
3246 | vnc_display = "localhost:0,to=99"; |
3247 | show_vnc_port = 1; | |
821601ea JS |
3248 | #else |
3249 | display_type = DT_NONE; | |
993fbfdb AL |
3250 | #endif |
3251 | } | |
821601ea | 3252 | |
993fbfdb | 3253 | |
6b62dc2d | 3254 | /* init local displays */ |
993fbfdb AL |
3255 | switch (display_type) { |
3256 | case DT_NOGRAPHIC: | |
3257 | break; | |
4d3b6f6e | 3258 | #if defined(CONFIG_CURSES) |
993fbfdb AL |
3259 | case DT_CURSES: |
3260 | curses_display_init(ds, full_screen); | |
3261 | break; | |
4d3b6f6e | 3262 | #endif |
5b0753e0 | 3263 | #if defined(CONFIG_SDL) |
993fbfdb AL |
3264 | case DT_SDL: |
3265 | sdl_display_init(ds, full_screen, no_frame); | |
3266 | break; | |
5b0753e0 | 3267 | #elif defined(CONFIG_COCOA) |
993fbfdb AL |
3268 | case DT_SDL: |
3269 | cocoa_display_init(ds, full_screen); | |
3270 | break; | |
313aa567 | 3271 | #endif |
6b62dc2d GH |
3272 | default: |
3273 | break; | |
3274 | } | |
3275 | ||
0ce235a7 GN |
3276 | /* must be after terminal init, SDL library changes signal handlers */ |
3277 | os_setup_signal_handling(); | |
3278 | ||
821601ea | 3279 | #ifdef CONFIG_VNC |
6b62dc2d GH |
3280 | /* init remote displays */ |
3281 | if (vnc_display) { | |
993fbfdb AL |
3282 | vnc_display_init(ds); |
3283 | if (vnc_display_open(ds, vnc_display) < 0) | |
3284 | exit(1); | |
f92f8afe | 3285 | |
993fbfdb AL |
3286 | if (show_vnc_port) { |
3287 | printf("VNC server running on `%s'\n", vnc_display_local_addr(ds)); | |
f92f8afe | 3288 | } |
313aa567 | 3289 | } |
821601ea | 3290 | #endif |
a3e22260 | 3291 | #ifdef CONFIG_SPICE |
a19cbfb3 | 3292 | if (using_spice && !qxl_enabled) { |
a3e22260 GH |
3293 | qemu_spice_display_init(ds); |
3294 | } | |
3295 | #endif | |
5b08fc10 | 3296 | |
6b62dc2d GH |
3297 | /* display setup */ |
3298 | dpy_resize(ds); | |
3023f332 AL |
3299 | dcl = ds->listeners; |
3300 | while (dcl != NULL) { | |
3301 | if (dcl->dpy_refresh != NULL) { | |
7bd427d8 PB |
3302 | ds->gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds); |
3303 | qemu_mod_timer(ds->gui_timer, qemu_get_clock_ms(rt_clock)); | |
0f2ad63f | 3304 | break; |
20d8a3ed | 3305 | } |
3023f332 | 3306 | dcl = dcl->next; |
20d8a3ed | 3307 | } |
6b62dc2d | 3308 | if (ds->gui_timer == NULL) { |
7bd427d8 PB |
3309 | nographic_timer = qemu_new_timer_ms(rt_clock, nographic_update, NULL); |
3310 | qemu_mod_timer(nographic_timer, qemu_get_clock_ms(rt_clock)); | |
9043b62d | 3311 | } |
b473df6e | 3312 | text_consoles_set_display(ds); |
2796dae0 | 3313 | |
59030a8c AL |
3314 | if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) { |
3315 | fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n", | |
3316 | gdbstub_dev); | |
3317 | exit(1); | |
45669e00 | 3318 | } |
45669e00 | 3319 | |
3418bd25 GH |
3320 | qdev_machine_creation_done(); |
3321 | ||
15ff7705 GH |
3322 | if (rom_load_all() != 0) { |
3323 | fprintf(stderr, "rom loading failed\n"); | |
3324 | exit(1); | |
3325 | } | |
45a50b16 | 3326 | |
80376c3f IY |
3327 | /* TODO: once all bus devices are qdevified, this should be done |
3328 | * when bus is created by qdev.c */ | |
3329 | qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); | |
4cab946a GN |
3330 | qemu_run_machine_init_done_notifiers(); |
3331 | ||
e063eb1f | 3332 | qemu_system_reset(VMRESET_SILENT); |
05f2401e | 3333 | if (loadvm) { |
03cd4655 | 3334 | if (load_vmstate(loadvm) < 0) { |
05f2401e JQ |
3335 | autostart = 0; |
3336 | } | |
3337 | } | |
d63d307f | 3338 | |
2bb8c10c | 3339 | if (incoming) { |
8ca5e801 JQ |
3340 | int ret = qemu_start_incoming_migration(incoming); |
3341 | if (ret < 0) { | |
3342 | fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n", | |
3343 | incoming, ret); | |
3344 | exit(ret); | |
3345 | } | |
6b99dadc | 3346 | } else if (autostart) { |
c0f4ce77 | 3347 | vm_start(); |
6b99dadc | 3348 | } |
ffd843bc | 3349 | |
eb505be1 | 3350 | os_setup_post(); |
71e3ceb8 | 3351 | |
8a7ddc38 | 3352 | main_loop(); |
40c3bac3 | 3353 | quit_timers(); |
63a01ef8 | 3354 | net_cleanup(); |
3d3b8303 | 3355 | res_free(); |
b46a8906 | 3356 | |
0824d6fc FB |
3357 | return 0; |
3358 | } |