xref: /qemu/include/exec/cpu-defs.h (revision e85ef5381a512d8f781b862e8b5f9d4cbf0ba494)
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>
291de7afc9SPaolo Bonzini #include "qemu/osdep.h"
301de7afc9SPaolo Bonzini #include "qemu/queue.h"
31022c62cbSPaolo Bonzini #include "exec/hwaddr.h"
32ab93bbe2Sbellard 
3335b66fc4Sbellard #ifndef TARGET_LONG_BITS
3435b66fc4Sbellard #error TARGET_LONG_BITS must be defined before including this header
3535b66fc4Sbellard #endif
3635b66fc4Sbellard 
3735b66fc4Sbellard #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
3835b66fc4Sbellard 
39ab6d960fSbellard /* target_ulong is the type of a virtual address */
4035b66fc4Sbellard #if TARGET_LONG_SIZE == 4
416cfd9b52SPaolo Bonzini typedef int32_t target_long;
426cfd9b52SPaolo Bonzini typedef uint32_t target_ulong;
43c27004ecSbellard #define TARGET_FMT_lx "%08x"
44b62b461bSj_mayer #define TARGET_FMT_ld "%d"
4571c8b8fdSj_mayer #define TARGET_FMT_lu "%u"
4635b66fc4Sbellard #elif TARGET_LONG_SIZE == 8
476cfd9b52SPaolo Bonzini typedef int64_t target_long;
486cfd9b52SPaolo Bonzini typedef uint64_t target_ulong;
4926a76461Sbellard #define TARGET_FMT_lx "%016" PRIx64
50b62b461bSj_mayer #define TARGET_FMT_ld "%" PRId64
5171c8b8fdSj_mayer #define TARGET_FMT_lu "%" PRIu64
5235b66fc4Sbellard #else
5335b66fc4Sbellard #error TARGET_LONG_SIZE undefined
5435b66fc4Sbellard #endif
5535b66fc4Sbellard 
562be0071fSbellard #define EXCP_INTERRUPT 	0x10000 /* async interruption */
572be0071fSbellard #define EXCP_HLT        0x10001 /* hlt instruction reached */
582be0071fSbellard #define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
595a1e3cfcSbellard #define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
60ab93bbe2Sbellard 
61a316d335Sbellard #define TB_JMP_CACHE_BITS 12
62a316d335Sbellard #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
63a316d335Sbellard 
64b362e5e0Spbrook /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
65b362e5e0Spbrook    addresses on the same page.  The top bits are the same.  This allows
66b362e5e0Spbrook    TLB invalidation to quickly clear a subset of the hash table.  */
67b362e5e0Spbrook #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
68b362e5e0Spbrook #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
69b362e5e0Spbrook #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
70b362e5e0Spbrook #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
71b362e5e0Spbrook 
7220cb400dSPaul Brook #if !defined(CONFIG_USER_ONLY)
7384b7b8e7Sbellard #define CPU_TLB_BITS 8
7484b7b8e7Sbellard #define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
75ab93bbe2Sbellard 
76355b1943SPaul Brook #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
77d656469fSbellard #define CPU_TLB_ENTRY_BITS 4
78d656469fSbellard #else
79d656469fSbellard #define CPU_TLB_ENTRY_BITS 5
80d656469fSbellard #endif
81d656469fSbellard 
82ab93bbe2Sbellard typedef struct CPUTLBEntry {
830f459d16Spbrook     /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
840f459d16Spbrook        bit TARGET_PAGE_BITS-1..4  : Nonzero for accesses that should not
850f459d16Spbrook                                     go directly to ram.
86db8d7466Sbellard        bit 3                      : indicates that the entry is invalid
87db8d7466Sbellard        bit 2..0                   : zero
88db8d7466Sbellard     */
8984b7b8e7Sbellard     target_ulong addr_read;
9084b7b8e7Sbellard     target_ulong addr_write;
9184b7b8e7Sbellard     target_ulong addr_code;
92355b1943SPaul Brook     /* Addend to virtual address to get host address.  IO accesses
93ee50add9Spbrook        use the corresponding iotlb value.  */
943b2992e4SStefan Weil     uintptr_t addend;
95d656469fSbellard     /* padding to get a power of two size */
96d656469fSbellard     uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
97d656469fSbellard                   (sizeof(target_ulong) * 3 +
983b2992e4SStefan Weil                    ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) +
993b2992e4SStefan Weil                    sizeof(uintptr_t))];
100ab93bbe2Sbellard } CPUTLBEntry;
101ab93bbe2Sbellard 
102*e85ef538SRichard Henderson QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS));
103355b1943SPaul Brook 
10420cb400dSPaul Brook #define CPU_COMMON_TLB \
10520cb400dSPaul Brook     /* The meaning of the MMU modes is defined in the target code. */   \
10620cb400dSPaul Brook     CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
107a8170e5eSAvi Kivity     hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
108d4c430a8SPaul Brook     target_ulong tlb_flush_addr;                                        \
109d4c430a8SPaul Brook     target_ulong tlb_flush_mask;
11020cb400dSPaul Brook 
11120cb400dSPaul Brook #else
11220cb400dSPaul Brook 
11320cb400dSPaul Brook #define CPU_COMMON_TLB
11420cb400dSPaul Brook 
11520cb400dSPaul Brook #endif
11620cb400dSPaul Brook 
11720cb400dSPaul Brook 
118e2542fe2SJuan Quintela #ifdef HOST_WORDS_BIGENDIAN
1192e70f6efSpbrook typedef struct icount_decr_u16 {
1202e70f6efSpbrook     uint16_t high;
1212e70f6efSpbrook     uint16_t low;
1222e70f6efSpbrook } icount_decr_u16;
1232e70f6efSpbrook #else
1242e70f6efSpbrook typedef struct icount_decr_u16 {
1252e70f6efSpbrook     uint16_t low;
1262e70f6efSpbrook     uint16_t high;
1272e70f6efSpbrook } icount_decr_u16;
1282e70f6efSpbrook #endif
1292e70f6efSpbrook 
130a1d1bb31Saliguori typedef struct CPUBreakpoint {
131a1d1bb31Saliguori     target_ulong pc;
132a1d1bb31Saliguori     int flags; /* BP_* */
13372cf2d4fSBlue Swirl     QTAILQ_ENTRY(CPUBreakpoint) entry;
134a1d1bb31Saliguori } CPUBreakpoint;
135a1d1bb31Saliguori 
136a1d1bb31Saliguori typedef struct CPUWatchpoint {
137a1d1bb31Saliguori     target_ulong vaddr;
138a1d1bb31Saliguori     target_ulong len_mask;
139a1d1bb31Saliguori     int flags; /* BP_* */
14072cf2d4fSBlue Swirl     QTAILQ_ENTRY(CPUWatchpoint) entry;
141a1d1bb31Saliguori } CPUWatchpoint;
142a1d1bb31Saliguori 
143a20e31dcSblueswir1 #define CPU_TEMP_BUF_NLONGS 128
144a316d335Sbellard #define CPU_COMMON                                                      \
145a316d335Sbellard     /* soft mmu support */                                              \
1462e70f6efSpbrook     /* in order to avoid passing too many arguments to the MMIO         \
1472e70f6efSpbrook        helpers, we store some rarely used information in the CPU        \
148a316d335Sbellard        context) */                                                      \
14920503968SBlue Swirl     uintptr_t mem_io_pc; /* host pc at which the memory was             \
1502e70f6efSpbrook                             accessed */                                 \
1512e70f6efSpbrook     target_ulong mem_io_vaddr; /* target virtual addr at which the      \
1522e70f6efSpbrook                                      memory was accessed */             \
15320cb400dSPaul Brook     CPU_COMMON_TLB                                                      \
154a316d335Sbellard     struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
155a20e31dcSblueswir1     /* buffer for temporaries in the code generator */                  \
156a20e31dcSblueswir1     long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
157a316d335Sbellard                                                                         \
1582e70f6efSpbrook     int64_t icount_extra; /* Instructions until next timer event.  */   \
1592e70f6efSpbrook     /* Number of cycles left, with interrupt flag in high bit.          \
1602e70f6efSpbrook        This allows a single read-compare-cbranch-write sequence to test \
1612e70f6efSpbrook        for both decrementer underflow and exceptions.  */               \
1622e70f6efSpbrook     union {                                                             \
1632e70f6efSpbrook         uint32_t u32;                                                   \
1642e70f6efSpbrook         icount_decr_u16 u16;                                            \
1652e70f6efSpbrook     } icount_decr;                                                      \
1662e70f6efSpbrook     uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
1672e70f6efSpbrook                                                                         \
168a316d335Sbellard     /* from this point: preserved by CPU reset */                       \
169a316d335Sbellard     /* ice debug support */                                             \
17072cf2d4fSBlue Swirl     QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
171a316d335Sbellard     int singlestep_enabled;                                             \
172a316d335Sbellard                                                                         \
17372cf2d4fSBlue Swirl     QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
174a1d1bb31Saliguori     CPUWatchpoint *watchpoint_hit;                                      \
1756658ffb8Spbrook                                                                         \
17656aebc89Spbrook     struct GDBRegisterState *gdb_regs;                                  \
17756aebc89Spbrook                                                                         \
1789133e39bSbellard     /* Core interrupt code */                                           \
1796ab7e546SPeter Maydell     sigjmp_buf jmp_env;                                                 \
180acb6685fSAnthony Liguori     int exception_index;                                                \
1819133e39bSbellard                                                                         \
1829349b4f9SAndreas Färber     CPUArchState *next_cpu; /* next CPU sharing TB cache */                 \
183a316d335Sbellard     /* user data */                                                     \
18401ba9816Sths     void *opaque;                                                       \
18501ba9816Sths                                                                         \
186f7575c96SAndreas Färber     const char *cpu_model_str;
187a316d335Sbellard 
188ab93bbe2Sbellard #endif
189