2
0

cpu-defs.h 8.8 KB

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