cpu-defs.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * common defines for all 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 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_DEFS_H
  20. #define CPU_DEFS_H
  21. #ifndef NEED_CPU_H
  22. #error cpu.h included from common code
  23. #endif
  24. #include "config.h"
  25. #include <setjmp.h>
  26. #include <inttypes.h>
  27. #include <signal.h>
  28. #include "osdep.h"
  29. #include "qemu-queue.h"
  30. #include "targphys.h"
  31. #ifndef TARGET_LONG_BITS
  32. #error TARGET_LONG_BITS must be defined before including this header
  33. #endif
  34. #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
  35. typedef int16_t target_short __attribute__ ((aligned(TARGET_SHORT_ALIGNMENT)));
  36. typedef uint16_t target_ushort __attribute__((aligned(TARGET_SHORT_ALIGNMENT)));
  37. typedef int32_t target_int __attribute__((aligned(TARGET_INT_ALIGNMENT)));
  38. typedef uint32_t target_uint __attribute__((aligned(TARGET_INT_ALIGNMENT)));
  39. typedef int64_t target_llong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
  40. typedef uint64_t target_ullong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
  41. /* target_ulong is the type of a virtual address */
  42. #if TARGET_LONG_SIZE == 4
  43. typedef int32_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
  44. typedef uint32_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
  45. #define TARGET_FMT_lx "%08x"
  46. #define TARGET_FMT_ld "%d"
  47. #define TARGET_FMT_lu "%u"
  48. #elif TARGET_LONG_SIZE == 8
  49. typedef int64_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
  50. typedef uint64_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
  51. #define TARGET_FMT_lx "%016" PRIx64
  52. #define TARGET_FMT_ld "%" PRId64
  53. #define TARGET_FMT_lu "%" PRIu64
  54. #else
  55. #error TARGET_LONG_SIZE undefined
  56. #endif
  57. #define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
  58. #define EXCP_INTERRUPT 0x10000 /* async interruption */
  59. #define EXCP_HLT 0x10001 /* hlt instruction reached */
  60. #define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */
  61. #define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */
  62. #define TB_JMP_CACHE_BITS 12
  63. #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
  64. /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
  65. addresses on the same page. The top bits are the same. This allows
  66. TLB invalidation to quickly clear a subset of the hash table. */
  67. #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
  68. #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
  69. #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
  70. #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
  71. #if !defined(CONFIG_USER_ONLY)
  72. #define CPU_TLB_BITS 8
  73. #define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
  74. #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
  75. #define CPU_TLB_ENTRY_BITS 4
  76. #else
  77. #define CPU_TLB_ENTRY_BITS 5
  78. #endif
  79. typedef struct CPUTLBEntry {
  80. /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
  81. bit TARGET_PAGE_BITS-1..4 : Nonzero for accesses that should not
  82. go directly to ram.
  83. bit 3 : indicates that the entry is invalid
  84. bit 2..0 : zero
  85. */
  86. target_ulong addr_read;
  87. target_ulong addr_write;
  88. target_ulong addr_code;
  89. /* Addend to virtual address to get host address. IO accesses
  90. use the corresponding iotlb value. */
  91. unsigned long addend;
  92. /* padding to get a power of two size */
  93. uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
  94. (sizeof(target_ulong) * 3 +
  95. ((-sizeof(target_ulong) * 3) & (sizeof(unsigned long) - 1)) +
  96. sizeof(unsigned long))];
  97. } CPUTLBEntry;
  98. extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1];
  99. #define CPU_COMMON_TLB \
  100. /* The meaning of the MMU modes is defined in the target code. */ \
  101. CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE]; \
  102. target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \
  103. target_ulong tlb_flush_addr; \
  104. target_ulong tlb_flush_mask;
  105. #else
  106. #define CPU_COMMON_TLB
  107. #endif
  108. #ifdef HOST_WORDS_BIGENDIAN
  109. typedef struct icount_decr_u16 {
  110. uint16_t high;
  111. uint16_t low;
  112. } icount_decr_u16;
  113. #else
  114. typedef struct icount_decr_u16 {
  115. uint16_t low;
  116. uint16_t high;
  117. } icount_decr_u16;
  118. #endif
  119. struct kvm_run;
  120. struct KVMState;
  121. struct qemu_work_item;
  122. typedef struct CPUBreakpoint {
  123. target_ulong pc;
  124. int flags; /* BP_* */
  125. QTAILQ_ENTRY(CPUBreakpoint) entry;
  126. } CPUBreakpoint;
  127. typedef struct CPUWatchpoint {
  128. target_ulong vaddr;
  129. target_ulong len_mask;
  130. int flags; /* BP_* */
  131. QTAILQ_ENTRY(CPUWatchpoint) entry;
  132. } CPUWatchpoint;
  133. #define CPU_TEMP_BUF_NLONGS 128
  134. #define CPU_COMMON \
  135. struct TranslationBlock *current_tb; /* currently executing TB */ \
  136. /* soft mmu support */ \
  137. /* in order to avoid passing too many arguments to the MMIO \
  138. helpers, we store some rarely used information in the CPU \
  139. context) */ \
  140. unsigned long mem_io_pc; /* host pc at which the memory was \
  141. accessed */ \
  142. target_ulong mem_io_vaddr; /* target virtual addr at which the \
  143. memory was accessed */ \
  144. uint32_t halted; /* Nonzero if the CPU is in suspend state */ \
  145. uint32_t interrupt_request; \
  146. volatile sig_atomic_t exit_request; \
  147. CPU_COMMON_TLB \
  148. struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; \
  149. /* buffer for temporaries in the code generator */ \
  150. long temp_buf[CPU_TEMP_BUF_NLONGS]; \
  151. \
  152. int64_t icount_extra; /* Instructions until next timer event. */ \
  153. /* Number of cycles left, with interrupt flag in high bit. \
  154. This allows a single read-compare-cbranch-write sequence to test \
  155. for both decrementer underflow and exceptions. */ \
  156. union { \
  157. uint32_t u32; \
  158. icount_decr_u16 u16; \
  159. } icount_decr; \
  160. uint32_t can_do_io; /* nonzero if memory mapped IO is safe. */ \
  161. \
  162. /* from this point: preserved by CPU reset */ \
  163. /* ice debug support */ \
  164. QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints; \
  165. int singlestep_enabled; \
  166. \
  167. QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints; \
  168. CPUWatchpoint *watchpoint_hit; \
  169. \
  170. struct GDBRegisterState *gdb_regs; \
  171. \
  172. /* Core interrupt code */ \
  173. jmp_buf jmp_env; \
  174. int exception_index; \
  175. \
  176. CPUState *next_cpu; /* next CPU sharing TB cache */ \
  177. int cpu_index; /* CPU index (informative) */ \
  178. uint32_t host_tid; /* host thread ID */ \
  179. int numa_node; /* NUMA node this cpu is belonging to */ \
  180. int nr_cores; /* number of cores within this CPU package */ \
  181. int nr_threads;/* number of threads within this CPU */ \
  182. int running; /* Nonzero if cpu is currently running(usermode). */ \
  183. int thread_id; \
  184. /* user data */ \
  185. void *opaque; \
  186. \
  187. uint32_t created; \
  188. uint32_t stop; /* Stop request */ \
  189. uint32_t stopped; /* Artificially stopped */ \
  190. struct QemuThread *thread; \
  191. struct QemuCond *halt_cond; \
  192. int thread_kicked; \
  193. struct qemu_work_item *queued_work_first, *queued_work_last; \
  194. const char *cpu_model_str; \
  195. struct KVMState *kvm_state; \
  196. struct kvm_run *kvm_run; \
  197. int kvm_fd; \
  198. int kvm_vcpu_dirty;
  199. #endif