xref: /qemu/include/exec/cpu-defs.h (revision 6ab7e5465a4d6188e29398fb43a30dbab1015b75)
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 
39c2e3dee6SLaurent Vivier typedef int16_t target_short __attribute__ ((aligned(TARGET_SHORT_ALIGNMENT)));
40c2e3dee6SLaurent Vivier typedef uint16_t target_ushort __attribute__((aligned(TARGET_SHORT_ALIGNMENT)));
41c2e3dee6SLaurent Vivier typedef int32_t target_int __attribute__((aligned(TARGET_INT_ALIGNMENT)));
42c2e3dee6SLaurent Vivier typedef uint32_t target_uint __attribute__((aligned(TARGET_INT_ALIGNMENT)));
43c2e3dee6SLaurent Vivier typedef int64_t target_llong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
44c2e3dee6SLaurent Vivier typedef uint64_t target_ullong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
45ab6d960fSbellard /* target_ulong is the type of a virtual address */
4635b66fc4Sbellard #if TARGET_LONG_SIZE == 4
47c2e3dee6SLaurent Vivier typedef int32_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
48c2e3dee6SLaurent Vivier typedef uint32_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
49c27004ecSbellard #define TARGET_FMT_lx "%08x"
50b62b461bSj_mayer #define TARGET_FMT_ld "%d"
5171c8b8fdSj_mayer #define TARGET_FMT_lu "%u"
5235b66fc4Sbellard #elif TARGET_LONG_SIZE == 8
53c2e3dee6SLaurent Vivier typedef int64_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
54c2e3dee6SLaurent Vivier typedef uint64_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
5526a76461Sbellard #define TARGET_FMT_lx "%016" PRIx64
56b62b461bSj_mayer #define TARGET_FMT_ld "%" PRId64
5771c8b8fdSj_mayer #define TARGET_FMT_lu "%" PRIu64
5835b66fc4Sbellard #else
5935b66fc4Sbellard #error TARGET_LONG_SIZE undefined
6035b66fc4Sbellard #endif
6135b66fc4Sbellard 
622be0071fSbellard #define EXCP_INTERRUPT 	0x10000 /* async interruption */
632be0071fSbellard #define EXCP_HLT        0x10001 /* hlt instruction reached */
642be0071fSbellard #define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
655a1e3cfcSbellard #define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
66ab93bbe2Sbellard 
67a316d335Sbellard #define TB_JMP_CACHE_BITS 12
68a316d335Sbellard #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
69a316d335Sbellard 
70b362e5e0Spbrook /* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
71b362e5e0Spbrook    addresses on the same page.  The top bits are the same.  This allows
72b362e5e0Spbrook    TLB invalidation to quickly clear a subset of the hash table.  */
73b362e5e0Spbrook #define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
74b362e5e0Spbrook #define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
75b362e5e0Spbrook #define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
76b362e5e0Spbrook #define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
77b362e5e0Spbrook 
7820cb400dSPaul Brook #if !defined(CONFIG_USER_ONLY)
7984b7b8e7Sbellard #define CPU_TLB_BITS 8
8084b7b8e7Sbellard #define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
81ab93bbe2Sbellard 
82355b1943SPaul Brook #if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
83d656469fSbellard #define CPU_TLB_ENTRY_BITS 4
84d656469fSbellard #else
85d656469fSbellard #define CPU_TLB_ENTRY_BITS 5
86d656469fSbellard #endif
87d656469fSbellard 
88ab93bbe2Sbellard typedef struct CPUTLBEntry {
890f459d16Spbrook     /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
900f459d16Spbrook        bit TARGET_PAGE_BITS-1..4  : Nonzero for accesses that should not
910f459d16Spbrook                                     go directly to ram.
92db8d7466Sbellard        bit 3                      : indicates that the entry is invalid
93db8d7466Sbellard        bit 2..0                   : zero
94db8d7466Sbellard     */
9584b7b8e7Sbellard     target_ulong addr_read;
9684b7b8e7Sbellard     target_ulong addr_write;
9784b7b8e7Sbellard     target_ulong addr_code;
98355b1943SPaul Brook     /* Addend to virtual address to get host address.  IO accesses
99ee50add9Spbrook        use the corresponding iotlb value.  */
1003b2992e4SStefan Weil     uintptr_t addend;
101d656469fSbellard     /* padding to get a power of two size */
102d656469fSbellard     uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) -
103d656469fSbellard                   (sizeof(target_ulong) * 3 +
1043b2992e4SStefan Weil                    ((-sizeof(target_ulong) * 3) & (sizeof(uintptr_t) - 1)) +
1053b2992e4SStefan Weil                    sizeof(uintptr_t))];
106ab93bbe2Sbellard } CPUTLBEntry;
107ab93bbe2Sbellard 
108355b1943SPaul Brook extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1];
109355b1943SPaul Brook 
11020cb400dSPaul Brook #define CPU_COMMON_TLB \
11120cb400dSPaul Brook     /* The meaning of the MMU modes is defined in the target code. */   \
11220cb400dSPaul Brook     CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
113a8170e5eSAvi Kivity     hwaddr iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
114d4c430a8SPaul Brook     target_ulong tlb_flush_addr;                                        \
115d4c430a8SPaul Brook     target_ulong tlb_flush_mask;
11620cb400dSPaul Brook 
11720cb400dSPaul Brook #else
11820cb400dSPaul Brook 
11920cb400dSPaul Brook #define CPU_COMMON_TLB
12020cb400dSPaul Brook 
12120cb400dSPaul Brook #endif
12220cb400dSPaul Brook 
12320cb400dSPaul Brook 
124e2542fe2SJuan Quintela #ifdef HOST_WORDS_BIGENDIAN
1252e70f6efSpbrook typedef struct icount_decr_u16 {
1262e70f6efSpbrook     uint16_t high;
1272e70f6efSpbrook     uint16_t low;
1282e70f6efSpbrook } icount_decr_u16;
1292e70f6efSpbrook #else
1302e70f6efSpbrook typedef struct icount_decr_u16 {
1312e70f6efSpbrook     uint16_t low;
1322e70f6efSpbrook     uint16_t high;
1332e70f6efSpbrook } icount_decr_u16;
1342e70f6efSpbrook #endif
1352e70f6efSpbrook 
136a1d1bb31Saliguori typedef struct CPUBreakpoint {
137a1d1bb31Saliguori     target_ulong pc;
138a1d1bb31Saliguori     int flags; /* BP_* */
13972cf2d4fSBlue Swirl     QTAILQ_ENTRY(CPUBreakpoint) entry;
140a1d1bb31Saliguori } CPUBreakpoint;
141a1d1bb31Saliguori 
142a1d1bb31Saliguori typedef struct CPUWatchpoint {
143a1d1bb31Saliguori     target_ulong vaddr;
144a1d1bb31Saliguori     target_ulong len_mask;
145a1d1bb31Saliguori     int flags; /* BP_* */
14672cf2d4fSBlue Swirl     QTAILQ_ENTRY(CPUWatchpoint) entry;
147a1d1bb31Saliguori } CPUWatchpoint;
148a1d1bb31Saliguori 
149a20e31dcSblueswir1 #define CPU_TEMP_BUF_NLONGS 128
150a316d335Sbellard #define CPU_COMMON                                                      \
151a316d335Sbellard     /* soft mmu support */                                              \
1522e70f6efSpbrook     /* in order to avoid passing too many arguments to the MMIO         \
1532e70f6efSpbrook        helpers, we store some rarely used information in the CPU        \
154a316d335Sbellard        context) */                                                      \
15520503968SBlue Swirl     uintptr_t mem_io_pc; /* host pc at which the memory was             \
1562e70f6efSpbrook                             accessed */                                 \
1572e70f6efSpbrook     target_ulong mem_io_vaddr; /* target virtual addr at which the      \
1582e70f6efSpbrook                                      memory was accessed */             \
1599656f324Spbrook     uint32_t halted; /* Nonzero if the CPU is in suspend state */       \
1609656f324Spbrook     uint32_t interrupt_request;                                         \
16120cb400dSPaul Brook     CPU_COMMON_TLB                                                      \
162a316d335Sbellard     struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
163a20e31dcSblueswir1     /* buffer for temporaries in the code generator */                  \
164a20e31dcSblueswir1     long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
165a316d335Sbellard                                                                         \
1662e70f6efSpbrook     int64_t icount_extra; /* Instructions until next timer event.  */   \
1672e70f6efSpbrook     /* Number of cycles left, with interrupt flag in high bit.          \
1682e70f6efSpbrook        This allows a single read-compare-cbranch-write sequence to test \
1692e70f6efSpbrook        for both decrementer underflow and exceptions.  */               \
1702e70f6efSpbrook     union {                                                             \
1712e70f6efSpbrook         uint32_t u32;                                                   \
1722e70f6efSpbrook         icount_decr_u16 u16;                                            \
1732e70f6efSpbrook     } icount_decr;                                                      \
1742e70f6efSpbrook     uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
1752e70f6efSpbrook                                                                         \
176a316d335Sbellard     /* from this point: preserved by CPU reset */                       \
177a316d335Sbellard     /* ice debug support */                                             \
17872cf2d4fSBlue Swirl     QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
179a316d335Sbellard     int singlestep_enabled;                                             \
180a316d335Sbellard                                                                         \
18172cf2d4fSBlue Swirl     QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
182a1d1bb31Saliguori     CPUWatchpoint *watchpoint_hit;                                      \
1836658ffb8Spbrook                                                                         \
18456aebc89Spbrook     struct GDBRegisterState *gdb_regs;                                  \
18556aebc89Spbrook                                                                         \
1869133e39bSbellard     /* Core interrupt code */                                           \
187*6ab7e546SPeter Maydell     sigjmp_buf jmp_env;                                                 \
188acb6685fSAnthony Liguori     int exception_index;                                                \
1899133e39bSbellard                                                                         \
1909349b4f9SAndreas Färber     CPUArchState *next_cpu; /* next CPU sharing TB cache */                 \
191a316d335Sbellard     /* user data */                                                     \
19201ba9816Sths     void *opaque;                                                       \
19301ba9816Sths                                                                         \
194f7575c96SAndreas Färber     const char *cpu_model_str;
195a316d335Sbellard 
196ab93bbe2Sbellard #endif
197