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