cpu-system.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * QEMU CPU model (system specific)
  3. *
  4. * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see
  18. * <http://www.gnu.org/licenses/gpl-2.0.html>
  19. */
  20. #include "qemu/osdep.h"
  21. #include "qapi/error.h"
  22. #include "exec/tswap.h"
  23. #include "hw/core/sysemu-cpu-ops.h"
  24. bool cpu_paging_enabled(const CPUState *cpu)
  25. {
  26. CPUClass *cc = CPU_GET_CLASS(cpu);
  27. if (cc->sysemu_ops->get_paging_enabled) {
  28. return cc->sysemu_ops->get_paging_enabled(cpu);
  29. }
  30. return false;
  31. }
  32. bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
  33. Error **errp)
  34. {
  35. CPUClass *cc = CPU_GET_CLASS(cpu);
  36. if (cc->sysemu_ops->get_memory_mapping) {
  37. return cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
  38. }
  39. error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
  40. return false;
  41. }
  42. hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
  43. MemTxAttrs *attrs)
  44. {
  45. CPUClass *cc = CPU_GET_CLASS(cpu);
  46. if (cc->sysemu_ops->get_phys_page_attrs_debug) {
  47. return cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs);
  48. }
  49. /* Fallback for CPUs which don't implement the _attrs_ hook */
  50. *attrs = MEMTXATTRS_UNSPECIFIED;
  51. return cc->sysemu_ops->get_phys_page_debug(cpu, addr);
  52. }
  53. hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
  54. {
  55. MemTxAttrs attrs = {};
  56. return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
  57. }
  58. int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
  59. {
  60. int ret = 0;
  61. if (cpu->cc->sysemu_ops->asidx_from_attrs) {
  62. ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
  63. assert(ret < cpu->num_ases && ret >= 0);
  64. }
  65. return ret;
  66. }
  67. int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  68. void *opaque)
  69. {
  70. CPUClass *cc = CPU_GET_CLASS(cpu);
  71. if (!cc->sysemu_ops->write_elf32_qemunote) {
  72. return 0;
  73. }
  74. return (*cc->sysemu_ops->write_elf32_qemunote)(f, cpu, opaque);
  75. }
  76. int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
  77. int cpuid, void *opaque)
  78. {
  79. CPUClass *cc = CPU_GET_CLASS(cpu);
  80. if (!cc->sysemu_ops->write_elf32_note) {
  81. return -1;
  82. }
  83. return (*cc->sysemu_ops->write_elf32_note)(f, cpu, cpuid, opaque);
  84. }
  85. int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  86. void *opaque)
  87. {
  88. CPUClass *cc = CPU_GET_CLASS(cpu);
  89. if (!cc->sysemu_ops->write_elf64_qemunote) {
  90. return 0;
  91. }
  92. return (*cc->sysemu_ops->write_elf64_qemunote)(f, cpu, opaque);
  93. }
  94. int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
  95. int cpuid, void *opaque)
  96. {
  97. CPUClass *cc = CPU_GET_CLASS(cpu);
  98. if (!cc->sysemu_ops->write_elf64_note) {
  99. return -1;
  100. }
  101. return (*cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque);
  102. }
  103. bool cpu_virtio_is_big_endian(CPUState *cpu)
  104. {
  105. CPUClass *cc = CPU_GET_CLASS(cpu);
  106. if (cc->sysemu_ops->virtio_is_big_endian) {
  107. return cc->sysemu_ops->virtio_is_big_endian(cpu);
  108. }
  109. return target_words_bigendian();
  110. }
  111. GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
  112. {
  113. CPUClass *cc = CPU_GET_CLASS(cpu);
  114. GuestPanicInformation *res = NULL;
  115. if (cc->sysemu_ops->get_crash_info) {
  116. res = cc->sysemu_ops->get_crash_info(cpu);
  117. }
  118. return res;
  119. }