cpu-system.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. hwaddr paddr;
  47. if (cc->sysemu_ops->get_phys_page_attrs_debug) {
  48. paddr = cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs);
  49. } else {
  50. /* Fallback for CPUs which don't implement the _attrs_ hook */
  51. *attrs = MEMTXATTRS_UNSPECIFIED;
  52. paddr = cc->sysemu_ops->get_phys_page_debug(cpu, addr);
  53. }
  54. /* Indicate that this is a debug access. */
  55. attrs->debug = 1;
  56. return paddr;
  57. }
  58. hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
  59. {
  60. MemTxAttrs attrs = {};
  61. return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
  62. }
  63. int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
  64. {
  65. int ret = 0;
  66. if (cpu->cc->sysemu_ops->asidx_from_attrs) {
  67. ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
  68. assert(ret < cpu->num_ases && ret >= 0);
  69. }
  70. return ret;
  71. }
  72. int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  73. void *opaque)
  74. {
  75. CPUClass *cc = CPU_GET_CLASS(cpu);
  76. if (!cc->sysemu_ops->write_elf32_qemunote) {
  77. return 0;
  78. }
  79. return (*cc->sysemu_ops->write_elf32_qemunote)(f, cpu, opaque);
  80. }
  81. int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
  82. int cpuid, void *opaque)
  83. {
  84. CPUClass *cc = CPU_GET_CLASS(cpu);
  85. if (!cc->sysemu_ops->write_elf32_note) {
  86. return -1;
  87. }
  88. return (*cc->sysemu_ops->write_elf32_note)(f, cpu, cpuid, opaque);
  89. }
  90. int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  91. void *opaque)
  92. {
  93. CPUClass *cc = CPU_GET_CLASS(cpu);
  94. if (!cc->sysemu_ops->write_elf64_qemunote) {
  95. return 0;
  96. }
  97. return (*cc->sysemu_ops->write_elf64_qemunote)(f, cpu, opaque);
  98. }
  99. int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
  100. int cpuid, void *opaque)
  101. {
  102. CPUClass *cc = CPU_GET_CLASS(cpu);
  103. if (!cc->sysemu_ops->write_elf64_note) {
  104. return -1;
  105. }
  106. return (*cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque);
  107. }
  108. bool cpu_virtio_is_big_endian(CPUState *cpu)
  109. {
  110. CPUClass *cc = CPU_GET_CLASS(cpu);
  111. if (cc->sysemu_ops->virtio_is_big_endian) {
  112. return cc->sysemu_ops->virtio_is_big_endian(cpu);
  113. }
  114. return target_words_bigendian();
  115. }
  116. GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
  117. {
  118. CPUClass *cc = CPU_GET_CLASS(cpu);
  119. GuestPanicInformation *res = NULL;
  120. if (cc->sysemu_ops->get_crash_info) {
  121. res = cc->sysemu_ops->get_crash_info(cpu);
  122. }
  123. return res;
  124. }