cpu-defs.h 9.6 KB

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