arch_init.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*
  2. * QEMU System Emulator
  3. *
  4. * Copyright (c) 2003-2008 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include <stdint.h>
  25. #include <stdarg.h>
  26. #include <stdlib.h>
  27. #ifndef _WIN32
  28. #include <sys/types.h>
  29. #include <sys/mman.h>
  30. #endif
  31. #include "config.h"
  32. #include "monitor.h"
  33. #include "sysemu.h"
  34. #include "arch_init.h"
  35. #include "audio/audio.h"
  36. #include "hw/pc.h"
  37. #include "hw/pci.h"
  38. #include "hw/audiodev.h"
  39. #include "kvm.h"
  40. #include "migration.h"
  41. #include "net.h"
  42. #include "gdbstub.h"
  43. #include "hw/smbios.h"
  44. #include "exec-memory.h"
  45. #include "hw/pcspk.h"
  46. #ifdef TARGET_SPARC
  47. int graphic_width = 1024;
  48. int graphic_height = 768;
  49. int graphic_depth = 8;
  50. #else
  51. int graphic_width = 800;
  52. int graphic_height = 600;
  53. int graphic_depth = 15;
  54. #endif
  55. #if defined(TARGET_ALPHA)
  56. #define QEMU_ARCH QEMU_ARCH_ALPHA
  57. #elif defined(TARGET_ARM)
  58. #define QEMU_ARCH QEMU_ARCH_ARM
  59. #elif defined(TARGET_CRIS)
  60. #define QEMU_ARCH QEMU_ARCH_CRIS
  61. #elif defined(TARGET_I386)
  62. #define QEMU_ARCH QEMU_ARCH_I386
  63. #elif defined(TARGET_M68K)
  64. #define QEMU_ARCH QEMU_ARCH_M68K
  65. #elif defined(TARGET_LM32)
  66. #define QEMU_ARCH QEMU_ARCH_LM32
  67. #elif defined(TARGET_MICROBLAZE)
  68. #define QEMU_ARCH QEMU_ARCH_MICROBLAZE
  69. #elif defined(TARGET_MIPS)
  70. #define QEMU_ARCH QEMU_ARCH_MIPS
  71. #elif defined(TARGET_PPC)
  72. #define QEMU_ARCH QEMU_ARCH_PPC
  73. #elif defined(TARGET_S390X)
  74. #define QEMU_ARCH QEMU_ARCH_S390X
  75. #elif defined(TARGET_SH4)
  76. #define QEMU_ARCH QEMU_ARCH_SH4
  77. #elif defined(TARGET_SPARC)
  78. #define QEMU_ARCH QEMU_ARCH_SPARC
  79. #elif defined(TARGET_XTENSA)
  80. #define QEMU_ARCH QEMU_ARCH_XTENSA
  81. #endif
  82. const uint32_t arch_type = QEMU_ARCH;
  83. /***********************************************************/
  84. /* ram save/restore */
  85. #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
  86. #define RAM_SAVE_FLAG_COMPRESS 0x02
  87. #define RAM_SAVE_FLAG_MEM_SIZE 0x04
  88. #define RAM_SAVE_FLAG_PAGE 0x08
  89. #define RAM_SAVE_FLAG_EOS 0x10
  90. #define RAM_SAVE_FLAG_CONTINUE 0x20
  91. #ifdef __ALTIVEC__
  92. #include <altivec.h>
  93. #define VECTYPE vector unsigned char
  94. #define SPLAT(p) vec_splat(vec_ld(0, p), 0)
  95. #define ALL_EQ(v1, v2) vec_all_eq(v1, v2)
  96. /* altivec.h may redefine the bool macro as vector type.
  97. * Reset it to POSIX semantics. */
  98. #undef bool
  99. #define bool _Bool
  100. #elif defined __SSE2__
  101. #include <emmintrin.h>
  102. #define VECTYPE __m128i
  103. #define SPLAT(p) _mm_set1_epi8(*(p))
  104. #define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF)
  105. #else
  106. #define VECTYPE unsigned long
  107. #define SPLAT(p) (*(p) * (~0UL / 255))
  108. #define ALL_EQ(v1, v2) ((v1) == (v2))
  109. #endif
  110. static struct defconfig_file {
  111. const char *filename;
  112. /* Indicates it is an user config file (disabled by -no-user-config) */
  113. bool userconfig;
  114. } default_config_files[] = {
  115. { CONFIG_QEMU_DATADIR "/cpus-" TARGET_ARCH ".conf", false },
  116. { CONFIG_QEMU_CONFDIR "/qemu.conf", true },
  117. { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true },
  118. { NULL }, /* end of list */
  119. };
  120. int qemu_read_default_config_files(bool userconfig)
  121. {
  122. int ret;
  123. struct defconfig_file *f;
  124. for (f = default_config_files; f->filename; f++) {
  125. if (!userconfig && f->userconfig) {
  126. continue;
  127. }
  128. ret = qemu_read_config_file(f->filename);
  129. if (ret < 0 && ret != -ENOENT) {
  130. return ret;
  131. }
  132. }
  133. return 0;
  134. }
  135. static int is_dup_page(uint8_t *page)
  136. {
  137. VECTYPE *p = (VECTYPE *)page;
  138. VECTYPE val = SPLAT(page);
  139. int i;
  140. for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
  141. if (!ALL_EQ(val, p[i])) {
  142. return 0;
  143. }
  144. }
  145. return 1;
  146. }
  147. static RAMBlock *last_block;
  148. static ram_addr_t last_offset;
  149. static int ram_save_block(QEMUFile *f)
  150. {
  151. RAMBlock *block = last_block;
  152. ram_addr_t offset = last_offset;
  153. int bytes_sent = 0;
  154. MemoryRegion *mr;
  155. if (!block)
  156. block = QLIST_FIRST(&ram_list.blocks);
  157. do {
  158. mr = block->mr;
  159. if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
  160. DIRTY_MEMORY_MIGRATION)) {
  161. uint8_t *p;
  162. int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
  163. memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
  164. DIRTY_MEMORY_MIGRATION);
  165. p = memory_region_get_ram_ptr(mr) + offset;
  166. if (is_dup_page(p)) {
  167. qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
  168. if (!cont) {
  169. qemu_put_byte(f, strlen(block->idstr));
  170. qemu_put_buffer(f, (uint8_t *)block->idstr,
  171. strlen(block->idstr));
  172. }
  173. qemu_put_byte(f, *p);
  174. bytes_sent = 1;
  175. } else {
  176. qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE);
  177. if (!cont) {
  178. qemu_put_byte(f, strlen(block->idstr));
  179. qemu_put_buffer(f, (uint8_t *)block->idstr,
  180. strlen(block->idstr));
  181. }
  182. qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
  183. bytes_sent = TARGET_PAGE_SIZE;
  184. }
  185. break;
  186. }
  187. offset += TARGET_PAGE_SIZE;
  188. if (offset >= block->length) {
  189. offset = 0;
  190. block = QLIST_NEXT(block, next);
  191. if (!block)
  192. block = QLIST_FIRST(&ram_list.blocks);
  193. }
  194. } while (block != last_block || offset != last_offset);
  195. last_block = block;
  196. last_offset = offset;
  197. return bytes_sent;
  198. }
  199. static uint64_t bytes_transferred;
  200. static ram_addr_t ram_save_remaining(void)
  201. {
  202. RAMBlock *block;
  203. ram_addr_t count = 0;
  204. QLIST_FOREACH(block, &ram_list.blocks, next) {
  205. ram_addr_t addr;
  206. for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
  207. if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
  208. DIRTY_MEMORY_MIGRATION)) {
  209. count++;
  210. }
  211. }
  212. }
  213. return count;
  214. }
  215. uint64_t ram_bytes_remaining(void)
  216. {
  217. return ram_save_remaining() * TARGET_PAGE_SIZE;
  218. }
  219. uint64_t ram_bytes_transferred(void)
  220. {
  221. return bytes_transferred;
  222. }
  223. uint64_t ram_bytes_total(void)
  224. {
  225. RAMBlock *block;
  226. uint64_t total = 0;
  227. QLIST_FOREACH(block, &ram_list.blocks, next)
  228. total += block->length;
  229. return total;
  230. }
  231. static int block_compar(const void *a, const void *b)
  232. {
  233. RAMBlock * const *ablock = a;
  234. RAMBlock * const *bblock = b;
  235. return strcmp((*ablock)->idstr, (*bblock)->idstr);
  236. }
  237. static void sort_ram_list(void)
  238. {
  239. RAMBlock *block, *nblock, **blocks;
  240. int n;
  241. n = 0;
  242. QLIST_FOREACH(block, &ram_list.blocks, next) {
  243. ++n;
  244. }
  245. blocks = g_malloc(n * sizeof *blocks);
  246. n = 0;
  247. QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
  248. blocks[n++] = block;
  249. QLIST_REMOVE(block, next);
  250. }
  251. qsort(blocks, n, sizeof *blocks, block_compar);
  252. while (--n >= 0) {
  253. QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
  254. }
  255. g_free(blocks);
  256. }
  257. int ram_save_live(QEMUFile *f, int stage, void *opaque)
  258. {
  259. ram_addr_t addr;
  260. uint64_t bytes_transferred_last;
  261. double bwidth = 0;
  262. uint64_t expected_time = 0;
  263. int ret;
  264. if (stage < 0) {
  265. memory_global_dirty_log_stop();
  266. return 0;
  267. }
  268. memory_global_sync_dirty_bitmap(get_system_memory());
  269. if (stage == 1) {
  270. RAMBlock *block;
  271. bytes_transferred = 0;
  272. last_block = NULL;
  273. last_offset = 0;
  274. sort_ram_list();
  275. /* Make sure all dirty bits are set */
  276. QLIST_FOREACH(block, &ram_list.blocks, next) {
  277. for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
  278. if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
  279. DIRTY_MEMORY_MIGRATION)) {
  280. memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE);
  281. }
  282. }
  283. }
  284. memory_global_dirty_log_start();
  285. qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
  286. QLIST_FOREACH(block, &ram_list.blocks, next) {
  287. qemu_put_byte(f, strlen(block->idstr));
  288. qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
  289. qemu_put_be64(f, block->length);
  290. }
  291. }
  292. bytes_transferred_last = bytes_transferred;
  293. bwidth = qemu_get_clock_ns(rt_clock);
  294. while ((ret = qemu_file_rate_limit(f)) == 0) {
  295. int bytes_sent;
  296. bytes_sent = ram_save_block(f);
  297. bytes_transferred += bytes_sent;
  298. if (bytes_sent == 0) { /* no more blocks */
  299. break;
  300. }
  301. }
  302. if (ret < 0) {
  303. return ret;
  304. }
  305. bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
  306. bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
  307. /* if we haven't transferred anything this round, force expected_time to a
  308. * a very high value, but without crashing */
  309. if (bwidth == 0) {
  310. bwidth = 0.000001;
  311. }
  312. /* try transferring iterative blocks of memory */
  313. if (stage == 3) {
  314. int bytes_sent;
  315. /* flush all remaining blocks regardless of rate limiting */
  316. while ((bytes_sent = ram_save_block(f)) != 0) {
  317. bytes_transferred += bytes_sent;
  318. }
  319. memory_global_dirty_log_stop();
  320. }
  321. qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
  322. expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
  323. return (stage == 2) && (expected_time <= migrate_max_downtime());
  324. }
  325. static inline void *host_from_stream_offset(QEMUFile *f,
  326. ram_addr_t offset,
  327. int flags)
  328. {
  329. static RAMBlock *block = NULL;
  330. char id[256];
  331. uint8_t len;
  332. if (flags & RAM_SAVE_FLAG_CONTINUE) {
  333. if (!block) {
  334. fprintf(stderr, "Ack, bad migration stream!\n");
  335. return NULL;
  336. }
  337. return memory_region_get_ram_ptr(block->mr) + offset;
  338. }
  339. len = qemu_get_byte(f);
  340. qemu_get_buffer(f, (uint8_t *)id, len);
  341. id[len] = 0;
  342. QLIST_FOREACH(block, &ram_list.blocks, next) {
  343. if (!strncmp(id, block->idstr, sizeof(id)))
  344. return memory_region_get_ram_ptr(block->mr) + offset;
  345. }
  346. fprintf(stderr, "Can't find block %s!\n", id);
  347. return NULL;
  348. }
  349. int ram_load(QEMUFile *f, void *opaque, int version_id)
  350. {
  351. ram_addr_t addr;
  352. int flags;
  353. int error;
  354. if (version_id < 4 || version_id > 4) {
  355. return -EINVAL;
  356. }
  357. do {
  358. addr = qemu_get_be64(f);
  359. flags = addr & ~TARGET_PAGE_MASK;
  360. addr &= TARGET_PAGE_MASK;
  361. if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
  362. if (version_id == 4) {
  363. /* Synchronize RAM block list */
  364. char id[256];
  365. ram_addr_t length;
  366. ram_addr_t total_ram_bytes = addr;
  367. while (total_ram_bytes) {
  368. RAMBlock *block;
  369. uint8_t len;
  370. len = qemu_get_byte(f);
  371. qemu_get_buffer(f, (uint8_t *)id, len);
  372. id[len] = 0;
  373. length = qemu_get_be64(f);
  374. QLIST_FOREACH(block, &ram_list.blocks, next) {
  375. if (!strncmp(id, block->idstr, sizeof(id))) {
  376. if (block->length != length)
  377. return -EINVAL;
  378. break;
  379. }
  380. }
  381. if (!block) {
  382. fprintf(stderr, "Unknown ramblock \"%s\", cannot "
  383. "accept migration\n", id);
  384. return -EINVAL;
  385. }
  386. total_ram_bytes -= length;
  387. }
  388. }
  389. }
  390. if (flags & RAM_SAVE_FLAG_COMPRESS) {
  391. void *host;
  392. uint8_t ch;
  393. host = host_from_stream_offset(f, addr, flags);
  394. if (!host) {
  395. return -EINVAL;
  396. }
  397. ch = qemu_get_byte(f);
  398. memset(host, ch, TARGET_PAGE_SIZE);
  399. #ifndef _WIN32
  400. if (ch == 0 &&
  401. (!kvm_enabled() || kvm_has_sync_mmu())) {
  402. qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
  403. }
  404. #endif
  405. } else if (flags & RAM_SAVE_FLAG_PAGE) {
  406. void *host;
  407. host = host_from_stream_offset(f, addr, flags);
  408. qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
  409. }
  410. error = qemu_file_get_error(f);
  411. if (error) {
  412. return error;
  413. }
  414. } while (!(flags & RAM_SAVE_FLAG_EOS));
  415. return 0;
  416. }
  417. #ifdef HAS_AUDIO
  418. struct soundhw {
  419. const char *name;
  420. const char *descr;
  421. int enabled;
  422. int isa;
  423. union {
  424. int (*init_isa) (ISABus *bus);
  425. int (*init_pci) (PCIBus *bus);
  426. } init;
  427. };
  428. static struct soundhw soundhw[] = {
  429. #ifdef HAS_AUDIO_CHOICE
  430. #ifdef CONFIG_PCSPK
  431. {
  432. "pcspk",
  433. "PC speaker",
  434. 0,
  435. 1,
  436. { .init_isa = pcspk_audio_init }
  437. },
  438. #endif
  439. #ifdef CONFIG_SB16
  440. {
  441. "sb16",
  442. "Creative Sound Blaster 16",
  443. 0,
  444. 1,
  445. { .init_isa = SB16_init }
  446. },
  447. #endif
  448. #ifdef CONFIG_CS4231A
  449. {
  450. "cs4231a",
  451. "CS4231A",
  452. 0,
  453. 1,
  454. { .init_isa = cs4231a_init }
  455. },
  456. #endif
  457. #ifdef CONFIG_ADLIB
  458. {
  459. "adlib",
  460. #ifdef HAS_YMF262
  461. "Yamaha YMF262 (OPL3)",
  462. #else
  463. "Yamaha YM3812 (OPL2)",
  464. #endif
  465. 0,
  466. 1,
  467. { .init_isa = Adlib_init }
  468. },
  469. #endif
  470. #ifdef CONFIG_GUS
  471. {
  472. "gus",
  473. "Gravis Ultrasound GF1",
  474. 0,
  475. 1,
  476. { .init_isa = GUS_init }
  477. },
  478. #endif
  479. #ifdef CONFIG_AC97
  480. {
  481. "ac97",
  482. "Intel 82801AA AC97 Audio",
  483. 0,
  484. 0,
  485. { .init_pci = ac97_init }
  486. },
  487. #endif
  488. #ifdef CONFIG_ES1370
  489. {
  490. "es1370",
  491. "ENSONIQ AudioPCI ES1370",
  492. 0,
  493. 0,
  494. { .init_pci = es1370_init }
  495. },
  496. #endif
  497. #ifdef CONFIG_HDA
  498. {
  499. "hda",
  500. "Intel HD Audio",
  501. 0,
  502. 0,
  503. { .init_pci = intel_hda_and_codec_init }
  504. },
  505. #endif
  506. #endif /* HAS_AUDIO_CHOICE */
  507. { NULL, NULL, 0, 0, { NULL } }
  508. };
  509. void select_soundhw(const char *optarg)
  510. {
  511. struct soundhw *c;
  512. if (*optarg == '?') {
  513. show_valid_cards:
  514. printf("Valid sound card names (comma separated):\n");
  515. for (c = soundhw; c->name; ++c) {
  516. printf ("%-11s %s\n", c->name, c->descr);
  517. }
  518. printf("\n-soundhw all will enable all of the above\n");
  519. exit(*optarg != '?');
  520. }
  521. else {
  522. size_t l;
  523. const char *p;
  524. char *e;
  525. int bad_card = 0;
  526. if (!strcmp(optarg, "all")) {
  527. for (c = soundhw; c->name; ++c) {
  528. c->enabled = 1;
  529. }
  530. return;
  531. }
  532. p = optarg;
  533. while (*p) {
  534. e = strchr(p, ',');
  535. l = !e ? strlen(p) : (size_t) (e - p);
  536. for (c = soundhw; c->name; ++c) {
  537. if (!strncmp(c->name, p, l) && !c->name[l]) {
  538. c->enabled = 1;
  539. break;
  540. }
  541. }
  542. if (!c->name) {
  543. if (l > 80) {
  544. fprintf(stderr,
  545. "Unknown sound card name (too big to show)\n");
  546. }
  547. else {
  548. fprintf(stderr, "Unknown sound card name `%.*s'\n",
  549. (int) l, p);
  550. }
  551. bad_card = 1;
  552. }
  553. p += l + (e != NULL);
  554. }
  555. if (bad_card) {
  556. goto show_valid_cards;
  557. }
  558. }
  559. }
  560. void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
  561. {
  562. struct soundhw *c;
  563. for (c = soundhw; c->name; ++c) {
  564. if (c->enabled) {
  565. if (c->isa) {
  566. if (isa_bus) {
  567. c->init.init_isa(isa_bus);
  568. }
  569. } else {
  570. if (pci_bus) {
  571. c->init.init_pci(pci_bus);
  572. }
  573. }
  574. }
  575. }
  576. }
  577. #else
  578. void select_soundhw(const char *optarg)
  579. {
  580. }
  581. void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
  582. {
  583. }
  584. #endif
  585. int qemu_uuid_parse(const char *str, uint8_t *uuid)
  586. {
  587. int ret;
  588. if (strlen(str) != 36) {
  589. return -1;
  590. }
  591. ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
  592. &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
  593. &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
  594. &uuid[15]);
  595. if (ret != 16) {
  596. return -1;
  597. }
  598. #ifdef TARGET_I386
  599. smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
  600. #endif
  601. return 0;
  602. }
  603. void do_acpitable_option(const char *optarg)
  604. {
  605. #ifdef TARGET_I386
  606. if (acpi_table_add(optarg) < 0) {
  607. fprintf(stderr, "Wrong acpi table provided\n");
  608. exit(1);
  609. }
  610. #endif
  611. }
  612. void do_smbios_option(const char *optarg)
  613. {
  614. #ifdef TARGET_I386
  615. if (smbios_entry_add(optarg) < 0) {
  616. fprintf(stderr, "Wrong smbios provided\n");
  617. exit(1);
  618. }
  619. #endif
  620. }
  621. void cpudef_init(void)
  622. {
  623. #if defined(cpudef_setup)
  624. cpudef_setup(); /* parse cpu definitions in target config file */
  625. #endif
  626. }
  627. int audio_available(void)
  628. {
  629. #ifdef HAS_AUDIO
  630. return 1;
  631. #else
  632. return 0;
  633. #endif
  634. }
  635. int tcg_available(void)
  636. {
  637. return 1;
  638. }
  639. int kvm_available(void)
  640. {
  641. #ifdef CONFIG_KVM
  642. return 1;
  643. #else
  644. return 0;
  645. #endif
  646. }
  647. int xen_available(void)
  648. {
  649. #ifdef CONFIG_XEN
  650. return 1;
  651. #else
  652. return 0;
  653. #endif
  654. }