xref: /qemu/include/exec/cpu-defs.h (revision 1de7afc984b49af164e2619e6850b9732b173b34)
1ab93bbe2Sbellard /*
2ab93bbe2Sbellard  * common defines for all CPUs
3ab93bbe2Sbellard  *
4ab93bbe2Sbellard  * Copyright (c) 2003 Fabrice Bellard
5ab93bbe2Sbellard  *
6ab93bbe2Sbellard  * This library is free software; you can redistribute it and/or
7ab93bbe2Sbellard  * modify it under the terms of the GNU Lesser General Public
8ab93bbe2Sbellard  * License as published by the Free Software Foundation; either
9ab93bbe2Sbellard  * version 2 of the License, or (at your option) any later version.
10ab93bbe2Sbellard  *
11ab93bbe2Sbellard  * This library is distributed in the hope that it will be useful,
12ab93bbe2Sbellard  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13ab93bbe2Sbellard  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14ab93bbe2Sbellard  * Lesser General Public License for more details.
15ab93bbe2Sbellard  *
16ab93bbe2Sbellard  * You should have received a copy of the GNU Lesser General Public
178167ee88SBlue Swirl  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18ab93bbe2Sbellard  */
19ab93bbe2Sbellard #ifndef CPU_DEFS_H
20ab93bbe2Sbellard #define CPU_DEFS_H
21ab93bbe2Sbellard 
2287ecb68bSpbrook #ifndef NEED_CPU_H
2387ecb68bSpbrook #error cpu.h included from common code
2487ecb68bSpbrook #endif
2587ecb68bSpbrook 
26ab93bbe2Sbellard #include "config.h"
27ab93bbe2Sbellard #include <setjmp.h>
28ed1c0bcbSbellard #include <inttypes.h>
29be214e6cSaurel32 #include <signal.h>
30*1de7afc9SPaolo Bonzini #include "qemu/osdep.h"
31*1de7afc9SPaolo Bonzini #include "qemu/queue.h"
32022c62cbSPaolo Bonzini #include "exec/hwaddr.h"
33ab93bbe2Sbellard 
3435b66fc4Sbellard #ifndef TARGET_LONG_BITS
3535b66fc4Sbellard #error TARGET_LONG_BITS must be defined before including this header
3635b66fc4Sbellard #endif
3735b66fc4Sbellard 
3835b66fc4Sbellard #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
3935b66fc4Sbellard 
40c2e3dee6SLaurent Vivier typedef int16_t target_short __attribute__ ((aligned(TARGET_SHORT_ALIGNMENT)));
41c2e3dee6SLaurent Vivier typedef uint16_t target_ushort __attribute__((aligned(TARGET_SHORT_ALIGNMENT)));
42c2e3dee6SLaurent Vivier typedef int32_t target_int __attribute__((aligned(TARGET_INT_ALIGNMENT)));
43c2e3dee6SLaurent Vivier typedef uint32_t target_uint __attribute__((aligned(TARGET_INT_ALIGNMENT)));
44c2e3dee6SLaurent Vivier typedef int64_t target_llong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
45c2e3dee6SLaurent Vivier typedef uint64_t target_ullong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
46ab6d960fSbellard /* target_ulong is the type of a virtual address */
4735b66fc4Sbellard #if TARGET_LONG_SIZE == 4
48c2e3dee6SLaurent Vivier typedef int32_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
49c2e3dee6SLaurent Vivier typedef uint32_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
50c27004ecSbellard #define TARGET_FMT_lx "%08x"
51b62b461bSj_mayer #define TARGET_FMT_ld "%d"
5271c8b8fdSj_mayer #define TARGET_FMT_lu "%u"
5335b66fc4Sbellard #elif TARGET_LONG_SIZE == 8
54c2e3dee6SLaurent Vivier typedef int64_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
55c2e3dee6SLaurent Vivier typedef uint64_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
5626a76461Sbellard #define TARGET_FMT_lx "%016" PRIx64
57b62b461bSj_mayer #define TARGET_FMT_ld "%" PRId64
5871c8b8fdSj_mayer #define TARGET_FMT_lu "%" PRIu64
5935b66fc4Sbellard #else
6035b66fc4Sbellard #error TARGET_LONG_SIZE undefined
6135b66fc4Sbellard #endif
6235b66fc4Sbellard 
632be0071fSbellard #define EXCP_INTERRUPT 	0x10000 /* async interruption */
642be0071fSbellard #define EXCP_HLT        0x10001 /* hlt instruction reached */
652be0071fSbellard #define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
665a1e3cfcSbellard #define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
67ab93bbe2Sbellard 
68a316d335Sbellard #define TB_JMP_CACHE_BITS 12
69a316d335Sbellard #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
70a316d335Sbellard 
71b362e5e0Spbrook /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
72b362e5e0Spbrook    addresses on the same page.  The top bits are the same.  This allows
73b362e5e0Spbrook    TLB invalidation to quickly clear a subset of the hash table.  */
74b362e5e0Spbrook #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
75b362e5e0Spbrook #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
76b362e5e0Spbrook #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
77b362e5e0Spbrook #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
78b362e5e0Spbrook 
7920cb400dSPaul Brook #if !defined(CONFIG_USER_ONLY)
8084b7b8e7Sbellard #define CPU_TLB_BITS 8
8184b7b8e7Sbellard #define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
82ab93bbe2Sbellard 
83355b1943SPaul Brook #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
84d656469fSbellard #define CPU_TLB_ENTRY_BITS 4
85d656469fSbellard #else
86d656469fSbellard #define CPU_TLB_ENTRY_BITS 5
87d656469fSbellard #endif
88d656469fSbellard 
89ab93bbe2Sbellard typedef struct CPUTLBEntry {
900f459d16Spbrook     /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
910f459d16Spbrook        bit TARGET_PAGE_BITS-1..4  : Nonzero for accesses that should not
920f459d16Spbrook                                     go directly to ram.
93db8d7466Sbellard        bit 3                      : indicates that the entry is invalid
94db8d7466Sbellard        bit 2..0                   : zero
95db8d7466Sbellard     */
9684b7b8e7Sbellard     target_ulong addr_read;
9784b7b8e7Sbellard     target_ulong addr_write;
9884b7b8e7Sbellard     target_ulong addr_code;
99355b1943SPaul Brook     /* Addend to virtual address to get host address.  IO accesses
100ee50add9Spbrook        use the corresponding iotlb value.  */
1013b2992e4SStefan Weil     uintptr_t addend;
102d656469fSbellard     /* padding to get a power of two size */
103d656469fSbellard     uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
104d656469fSbellard                   (sizeof(target_ulong) * 3 +
1053b2992e4SStefan Weil                    ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) +
1063b2992e4SStefan Weil                    sizeof(uintptr_t))];
107ab93bbe2Sbellard } CPUTLBEntry;
108ab93bbe2Sbellard 
109355b1943SPaul Brook extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1];
110355b1943SPaul Brook 
11120cb400dSPaul Brook #define CPU_COMMON_TLB \
11220cb400dSPaul Brook     /* The meaning of the MMU modes is defined in the target code. */   \
11320cb400dSPaul Brook     CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
114a8170e5eSAvi Kivity     hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
115d4c430a8SPaul Brook     target_ulong tlb_flush_addr;                                        \
116d4c430a8SPaul Brook     target_ulong tlb_flush_mask;
11720cb400dSPaul Brook 
11820cb400dSPaul Brook #else
11920cb400dSPaul Brook 
12020cb400dSPaul Brook #define CPU_COMMON_TLB
12120cb400dSPaul Brook 
12220cb400dSPaul Brook #endif
12320cb400dSPaul Brook 
12420cb400dSPaul Brook 
125e2542fe2SJuan Quintela #ifdef HOST_WORDS_BIGENDIAN
1262e70f6efSpbrook typedef struct icount_decr_u16 {
1272e70f6efSpbrook     uint16_t high;
1282e70f6efSpbrook     uint16_t low;
1292e70f6efSpbrook } icount_decr_u16;
1302e70f6efSpbrook #else
1312e70f6efSpbrook typedef struct icount_decr_u16 {
1322e70f6efSpbrook     uint16_t low;
1332e70f6efSpbrook     uint16_t high;
1342e70f6efSpbrook } icount_decr_u16;
1352e70f6efSpbrook #endif
1362e70f6efSpbrook 
1377ba1e619Saliguori struct kvm_run;
1387ba1e619Saliguori struct KVMState;
139e82bcec2SMarcelo Tosatti struct qemu_work_item;
1407ba1e619Saliguori 
141a1d1bb31Saliguori typedef struct CPUBreakpoint {
142a1d1bb31Saliguori     target_ulong pc;
143a1d1bb31Saliguori     int flags; /* BP_* */
14472cf2d4fSBlue Swirl     QTAILQ_ENTRY(CPUBreakpoint) entry;
145a1d1bb31Saliguori } CPUBreakpoint;
146a1d1bb31Saliguori 
147a1d1bb31Saliguori typedef struct CPUWatchpoint {
148a1d1bb31Saliguori     target_ulong vaddr;
149a1d1bb31Saliguori     target_ulong len_mask;
150a1d1bb31Saliguori     int flags; /* BP_* */
15172cf2d4fSBlue Swirl     QTAILQ_ENTRY(CPUWatchpoint) entry;
152a1d1bb31Saliguori } CPUWatchpoint;
153a1d1bb31Saliguori 
154a20e31dcSblueswir1 #define CPU_TEMP_BUF_NLONGS 128
155a316d335Sbellard #define CPU_COMMON                                                      \
156a316d335Sbellard     struct TranslationBlock *current_tb; /* currently executing TB  */  \
157a316d335Sbellard     /* soft mmu support */                                              \
1582e70f6efSpbrook     /* in order to avoid passing too many arguments to the MMIO         \
1592e70f6efSpbrook        helpers, we store some rarely used information in the CPU        \
160a316d335Sbellard        context) */                                                      \
16120503968SBlue Swirl     uintptr_t mem_io_pc; /* host pc at which the memory was             \
1622e70f6efSpbrook                             accessed */                                 \
1632e70f6efSpbrook     target_ulong mem_io_vaddr; /* target virtual addr at which the      \
1642e70f6efSpbrook                                      memory was accessed */             \
1659656f324Spbrook     uint32_t halted; /* Nonzero if the CPU is in suspend state */       \
1669656f324Spbrook     uint32_t interrupt_request;                                         \
167be214e6cSaurel32     volatile sig_atomic_t exit_request;                                 \
16820cb400dSPaul Brook     CPU_COMMON_TLB                                                      \
169a316d335Sbellard     struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
170a20e31dcSblueswir1     /* buffer for temporaries in the code generator */                  \
171a20e31dcSblueswir1     long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
172a316d335Sbellard                                                                         \
1732e70f6efSpbrook     int64_t icount_extra; /* Instructions until next timer event.  */   \
1742e70f6efSpbrook     /* Number of cycles left, with interrupt flag in high bit.          \
1752e70f6efSpbrook        This allows a single read-compare-cbranch-write sequence to test \
1762e70f6efSpbrook        for both decrementer underflow and exceptions.  */               \
1772e70f6efSpbrook     union {                                                             \
1782e70f6efSpbrook         uint32_t u32;                                                   \
1792e70f6efSpbrook         icount_decr_u16 u16;                                            \
1802e70f6efSpbrook     } icount_decr;                                                      \
1812e70f6efSpbrook     uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
1822e70f6efSpbrook                                                                         \
183a316d335Sbellard     /* from this point: preserved by CPU reset */                       \
184a316d335Sbellard     /* ice debug support */                                             \
18572cf2d4fSBlue Swirl     QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
186a316d335Sbellard     int singlestep_enabled;                                             \
187a316d335Sbellard                                                                         \
18872cf2d4fSBlue Swirl     QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
189a1d1bb31Saliguori     CPUWatchpoint *watchpoint_hit;                                      \
1906658ffb8Spbrook                                                                         \
19156aebc89Spbrook     struct GDBRegisterState *gdb_regs;                                  \
19256aebc89Spbrook                                                                         \
1939133e39bSbellard     /* Core interrupt code */                                           \
1949133e39bSbellard     jmp_buf jmp_env;                                                    \
195acb6685fSAnthony Liguori     int exception_index;                                                \
1969133e39bSbellard                                                                         \
1979349b4f9SAndreas Färber     CPUArchState *next_cpu; /* next CPU sharing TB cache */                 \
1986a00d601Sbellard     int cpu_index; /* CPU index (informative) */                        \
1991e9fa730SNathan Froyd     uint32_t host_tid; /* host thread ID */                             \
200268a362cSaliguori     int numa_node; /* NUMA node this cpu is belonging to  */            \
201dc6b1c09SAndre Przywara     int nr_cores;  /* number of cores within this CPU package */        \
202dc6b1c09SAndre Przywara     int nr_threads;/* number of threads within this CPU */              \
203d5975363Spbrook     int running; /* Nonzero if cpu is currently running(usermode).  */  \
204a316d335Sbellard     /* user data */                                                     \
20501ba9816Sths     void *opaque;                                                       \
20601ba9816Sths                                                                         \
2077ba1e619Saliguori     const char *cpu_model_str;                                          \
2087ba1e619Saliguori     struct KVMState *kvm_state;                                         \
2097ba1e619Saliguori     struct kvm_run *kvm_run;                                            \
2109ded2744SJan Kiszka     int kvm_fd;                                                         \
2119ded2744SJan Kiszka     int kvm_vcpu_dirty;
212a316d335Sbellard 
213ab93bbe2Sbellard #endif
214