2
0

cpu-all.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * defines common to all virtual CPUs
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef CPU_ALL_H
  20. #define CPU_ALL_H
  21. #include "exec/page-protection.h"
  22. #include "exec/cpu-common.h"
  23. #include "exec/cpu-interrupt.h"
  24. #include "exec/memory.h"
  25. #include "exec/tswap.h"
  26. #include "hw/core/cpu.h"
  27. /* Target-endianness CPU memory access functions. These fit into the
  28. * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
  29. */
  30. #if TARGET_BIG_ENDIAN
  31. #define lduw_p(p) lduw_be_p(p)
  32. #define ldsw_p(p) ldsw_be_p(p)
  33. #define ldl_p(p) ldl_be_p(p)
  34. #define ldq_p(p) ldq_be_p(p)
  35. #define stw_p(p, v) stw_be_p(p, v)
  36. #define stl_p(p, v) stl_be_p(p, v)
  37. #define stq_p(p, v) stq_be_p(p, v)
  38. #define ldn_p(p, sz) ldn_be_p(p, sz)
  39. #define stn_p(p, sz, v) stn_be_p(p, sz, v)
  40. #else
  41. #define lduw_p(p) lduw_le_p(p)
  42. #define ldsw_p(p) ldsw_le_p(p)
  43. #define ldl_p(p) ldl_le_p(p)
  44. #define ldq_p(p) ldq_le_p(p)
  45. #define stw_p(p, v) stw_le_p(p, v)
  46. #define stl_p(p, v) stl_le_p(p, v)
  47. #define stq_p(p, v) stq_le_p(p, v)
  48. #define ldn_p(p, sz) ldn_le_p(p, sz)
  49. #define stn_p(p, sz, v) stn_le_p(p, sz, v)
  50. #endif
  51. /* MMU memory access macros */
  52. #if !defined(CONFIG_USER_ONLY)
  53. #include "exec/hwaddr.h"
  54. #define SUFFIX
  55. #define ARG1 as
  56. #define ARG1_DECL AddressSpace *as
  57. #define TARGET_ENDIANNESS
  58. #include "exec/memory_ldst.h.inc"
  59. #define SUFFIX _cached_slow
  60. #define ARG1 cache
  61. #define ARG1_DECL MemoryRegionCache *cache
  62. #define TARGET_ENDIANNESS
  63. #include "exec/memory_ldst.h.inc"
  64. static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
  65. {
  66. address_space_stl_notdirty(as, addr, val,
  67. MEMTXATTRS_UNSPECIFIED, NULL);
  68. }
  69. #define SUFFIX
  70. #define ARG1 as
  71. #define ARG1_DECL AddressSpace *as
  72. #define TARGET_ENDIANNESS
  73. #include "exec/memory_ldst_phys.h.inc"
  74. /* Inline fast path for direct RAM access. */
  75. #define ENDIANNESS
  76. #include "exec/memory_ldst_cached.h.inc"
  77. #define SUFFIX _cached
  78. #define ARG1 cache
  79. #define ARG1_DECL MemoryRegionCache *cache
  80. #define TARGET_ENDIANNESS
  81. #include "exec/memory_ldst_phys.h.inc"
  82. #endif
  83. /* page related stuff */
  84. #include "exec/cpu-defs.h"
  85. #include "exec/target_page.h"
  86. CPUArchState *cpu_copy(CPUArchState *env);
  87. #include "cpu.h"
  88. #ifdef CONFIG_USER_ONLY
  89. static inline int cpu_mmu_index(CPUState *cs, bool ifetch);
  90. /*
  91. * Allow some level of source compatibility with softmmu. We do not
  92. * support any of the more exotic features, so only invalid pages may
  93. * be signaled by probe_access_flags().
  94. */
  95. #define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1))
  96. #define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 2))
  97. #define TLB_WATCHPOINT 0
  98. static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
  99. {
  100. return MMU_USER_IDX;
  101. }
  102. #else
  103. /*
  104. * Flags stored in the low bits of the TLB virtual address.
  105. * These are defined so that fast path ram access is all zeros.
  106. * The flags all must be between TARGET_PAGE_BITS and
  107. * maximum address alignment bit.
  108. *
  109. * Use TARGET_PAGE_BITS_MIN so that these bits are constant
  110. * when TARGET_PAGE_BITS_VARY is in effect.
  111. *
  112. * The count, if not the placement of these bits is known
  113. * to tcg/tcg-op-ldst.c, check_max_alignment().
  114. */
  115. /* Zero if TLB entry is valid. */
  116. #define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1))
  117. /* Set if TLB entry references a clean RAM page. The iotlb entry will
  118. contain the page physical address. */
  119. #define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS_MIN - 2))
  120. /* Set if TLB entry is an IO callback. */
  121. #define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 3))
  122. /* Set if TLB entry writes ignored. */
  123. #define TLB_DISCARD_WRITE (1 << (TARGET_PAGE_BITS_MIN - 4))
  124. /* Set if the slow path must be used; more flags in CPUTLBEntryFull. */
  125. #define TLB_FORCE_SLOW (1 << (TARGET_PAGE_BITS_MIN - 5))
  126. /*
  127. * Use this mask to check interception with an alignment mask
  128. * in a TCG backend.
  129. */
  130. #define TLB_FLAGS_MASK \
  131. (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO \
  132. | TLB_FORCE_SLOW | TLB_DISCARD_WRITE)
  133. /*
  134. * Flags stored in CPUTLBEntryFull.slow_flags[x].
  135. * TLB_FORCE_SLOW must be set in CPUTLBEntry.addr_idx[x].
  136. */
  137. /* Set if TLB entry requires byte swap. */
  138. #define TLB_BSWAP (1 << 0)
  139. /* Set if TLB entry contains a watchpoint. */
  140. #define TLB_WATCHPOINT (1 << 1)
  141. /* Set if TLB entry requires aligned accesses. */
  142. #define TLB_CHECK_ALIGNED (1 << 2)
  143. #define TLB_SLOW_FLAGS_MASK (TLB_BSWAP | TLB_WATCHPOINT | TLB_CHECK_ALIGNED)
  144. /* The two sets of flags must not overlap. */
  145. QEMU_BUILD_BUG_ON(TLB_FLAGS_MASK & TLB_SLOW_FLAGS_MASK);
  146. #endif /* !CONFIG_USER_ONLY */
  147. /* Validate correct placement of CPUArchState. */
  148. QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
  149. QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
  150. #endif /* CPU_ALL_H */