Statistics
| Branch: | Revision:

root / cpu-defs.h @ c4f8e211

History | View | Annotate | Download (9.8 kB)

1 ab93bbe2 bellard
/*
2 ab93bbe2 bellard
 * common defines for all CPUs
3 5fafdf24 ths
 *
4 ab93bbe2 bellard
 * Copyright (c) 2003 Fabrice Bellard
5 ab93bbe2 bellard
 *
6 ab93bbe2 bellard
 * This library is free software; you can redistribute it and/or
7 ab93bbe2 bellard
 * modify it under the terms of the GNU Lesser General Public
8 ab93bbe2 bellard
 * License as published by the Free Software Foundation; either
9 ab93bbe2 bellard
 * version 2 of the License, or (at your option) any later version.
10 ab93bbe2 bellard
 *
11 ab93bbe2 bellard
 * This library is distributed in the hope that it will be useful,
12 ab93bbe2 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ab93bbe2 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ab93bbe2 bellard
 * Lesser General Public License for more details.
15 ab93bbe2 bellard
 *
16 ab93bbe2 bellard
 * You should have received a copy of the GNU Lesser General Public
17 8167ee88 Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 ab93bbe2 bellard
 */
19 ab93bbe2 bellard
#ifndef CPU_DEFS_H
20 ab93bbe2 bellard
#define CPU_DEFS_H
21 ab93bbe2 bellard
22 87ecb68b pbrook
#ifndef NEED_CPU_H
23 87ecb68b pbrook
#error cpu.h included from common code
24 87ecb68b pbrook
#endif
25 87ecb68b pbrook
26 ab93bbe2 bellard
#include "config.h"
27 ab93bbe2 bellard
#include <setjmp.h>
28 ed1c0bcb bellard
#include <inttypes.h>
29 be214e6c aurel32
#include <signal.h>
30 ed1c0bcb bellard
#include "osdep.h"
31 72cf2d4f Blue Swirl
#include "qemu-queue.h"
32 1ad2134f Paul Brook
#include "targphys.h"
33 ab93bbe2 bellard
34 35b66fc4 bellard
#ifndef TARGET_LONG_BITS
35 35b66fc4 bellard
#error TARGET_LONG_BITS must be defined before including this header
36 35b66fc4 bellard
#endif
37 35b66fc4 bellard
38 35b66fc4 bellard
#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
39 35b66fc4 bellard
40 c2e3dee6 Laurent Vivier
typedef int16_t target_short __attribute__ ((aligned(TARGET_SHORT_ALIGNMENT)));
41 c2e3dee6 Laurent Vivier
typedef uint16_t target_ushort __attribute__((aligned(TARGET_SHORT_ALIGNMENT)));
42 c2e3dee6 Laurent Vivier
typedef int32_t target_int __attribute__((aligned(TARGET_INT_ALIGNMENT)));
43 c2e3dee6 Laurent Vivier
typedef uint32_t target_uint __attribute__((aligned(TARGET_INT_ALIGNMENT)));
44 c2e3dee6 Laurent Vivier
typedef int64_t target_llong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
45 c2e3dee6 Laurent Vivier
typedef uint64_t target_ullong __attribute__((aligned(TARGET_LLONG_ALIGNMENT)));
46 ab6d960f bellard
/* target_ulong is the type of a virtual address */
47 35b66fc4 bellard
#if TARGET_LONG_SIZE == 4
48 c2e3dee6 Laurent Vivier
typedef int32_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
49 c2e3dee6 Laurent Vivier
typedef uint32_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
50 c27004ec bellard
#define TARGET_FMT_lx "%08x"
51 b62b461b j_mayer
#define TARGET_FMT_ld "%d"
52 71c8b8fd j_mayer
#define TARGET_FMT_lu "%u"
53 35b66fc4 bellard
#elif TARGET_LONG_SIZE == 8
54 c2e3dee6 Laurent Vivier
typedef int64_t target_long __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
55 c2e3dee6 Laurent Vivier
typedef uint64_t target_ulong __attribute__((aligned(TARGET_LONG_ALIGNMENT)));
56 26a76461 bellard
#define TARGET_FMT_lx "%016" PRIx64
57 b62b461b j_mayer
#define TARGET_FMT_ld "%" PRId64
58 71c8b8fd j_mayer
#define TARGET_FMT_lu "%" PRIu64
59 35b66fc4 bellard
#else
60 35b66fc4 bellard
#error TARGET_LONG_SIZE undefined
61 35b66fc4 bellard
#endif
62 35b66fc4 bellard
63 f193c797 bellard
#define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
64 f193c797 bellard
65 2be0071f bellard
#define EXCP_INTERRUPT         0x10000 /* async interruption */
66 2be0071f bellard
#define EXCP_HLT        0x10001 /* hlt instruction reached */
67 2be0071f bellard
#define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
68 5a1e3cfc bellard
#define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
69 ab93bbe2 bellard
70 a316d335 bellard
#define TB_JMP_CACHE_BITS 12
71 a316d335 bellard
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
72 a316d335 bellard
73 b362e5e0 pbrook
/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
74 b362e5e0 pbrook
   addresses on the same page.  The top bits are the same.  This allows
75 b362e5e0 pbrook
   TLB invalidation to quickly clear a subset of the hash table.  */
76 b362e5e0 pbrook
#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
77 b362e5e0 pbrook
#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
78 b362e5e0 pbrook
#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
79 b362e5e0 pbrook
#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
80 b362e5e0 pbrook
81 20cb400d Paul Brook
#if !defined(CONFIG_USER_ONLY)
82 84b7b8e7 bellard
#define CPU_TLB_BITS 8
83 84b7b8e7 bellard
#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
84 ab93bbe2 bellard
85 355b1943 Paul Brook
#if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
86 d656469f bellard
#define CPU_TLB_ENTRY_BITS 4
87 d656469f bellard
#else
88 d656469f bellard
#define CPU_TLB_ENTRY_BITS 5
89 d656469f bellard
#endif
90 d656469f bellard
91 ab93bbe2 bellard
typedef struct CPUTLBEntry {
92 0f459d16 pbrook
    /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
93 0f459d16 pbrook
       bit TARGET_PAGE_BITS-1..4  : Nonzero for accesses that should not
94 0f459d16 pbrook
                                    go directly to ram.
95 db8d7466 bellard
       bit 3                      : indicates that the entry is invalid
96 db8d7466 bellard
       bit 2..0                   : zero
97 db8d7466 bellard
    */
98 5fafdf24 ths
    target_ulong addr_read;
99 5fafdf24 ths
    target_ulong addr_write;
100 5fafdf24 ths
    target_ulong addr_code;
101 355b1943 Paul Brook
    /* Addend to virtual address to get host address.  IO accesses
102 ee50add9 pbrook
       use the corresponding iotlb value.  */
103 355b1943 Paul Brook
    unsigned long addend;
104 d656469f bellard
    /* padding to get a power of two size */
105 d656469f bellard
    uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 
106 d656469f bellard
                  (sizeof(target_ulong) * 3 + 
107 355b1943 Paul Brook
                   ((-sizeof(target_ulong) * 3) & (sizeof(unsigned long) - 1)) + 
108 355b1943 Paul Brook
                   sizeof(unsigned long))];
109 ab93bbe2 bellard
} CPUTLBEntry;
110 ab93bbe2 bellard
111 355b1943 Paul Brook
extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1];
112 355b1943 Paul Brook
113 20cb400d Paul Brook
#define CPU_COMMON_TLB \
114 20cb400d Paul Brook
    /* The meaning of the MMU modes is defined in the target code. */   \
115 20cb400d Paul Brook
    CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
116 20cb400d Paul Brook
    target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
117 d4c430a8 Paul Brook
    target_ulong tlb_flush_addr;                                        \
118 d4c430a8 Paul Brook
    target_ulong tlb_flush_mask;
119 20cb400d Paul Brook
120 20cb400d Paul Brook
#else
121 20cb400d Paul Brook
122 20cb400d Paul Brook
#define CPU_COMMON_TLB
123 20cb400d Paul Brook
124 20cb400d Paul Brook
#endif
125 20cb400d Paul Brook
126 20cb400d Paul Brook
127 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
128 2e70f6ef pbrook
typedef struct icount_decr_u16 {
129 2e70f6ef pbrook
    uint16_t high;
130 2e70f6ef pbrook
    uint16_t low;
131 2e70f6ef pbrook
} icount_decr_u16;
132 2e70f6ef pbrook
#else
133 2e70f6ef pbrook
typedef struct icount_decr_u16 {
134 2e70f6ef pbrook
    uint16_t low;
135 2e70f6ef pbrook
    uint16_t high;
136 2e70f6ef pbrook
} icount_decr_u16;
137 2e70f6ef pbrook
#endif
138 2e70f6ef pbrook
139 7ba1e619 aliguori
struct kvm_run;
140 7ba1e619 aliguori
struct KVMState;
141 e82bcec2 Marcelo Tosatti
struct qemu_work_item;
142 7ba1e619 aliguori
143 a1d1bb31 aliguori
typedef struct CPUBreakpoint {
144 a1d1bb31 aliguori
    target_ulong pc;
145 a1d1bb31 aliguori
    int flags; /* BP_* */
146 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CPUBreakpoint) entry;
147 a1d1bb31 aliguori
} CPUBreakpoint;
148 a1d1bb31 aliguori
149 a1d1bb31 aliguori
typedef struct CPUWatchpoint {
150 a1d1bb31 aliguori
    target_ulong vaddr;
151 a1d1bb31 aliguori
    target_ulong len_mask;
152 a1d1bb31 aliguori
    int flags; /* BP_* */
153 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CPUWatchpoint) entry;
154 a1d1bb31 aliguori
} CPUWatchpoint;
155 a1d1bb31 aliguori
156 a20e31dc blueswir1
#define CPU_TEMP_BUF_NLONGS 128
157 a316d335 bellard
#define CPU_COMMON                                                      \
158 a316d335 bellard
    struct TranslationBlock *current_tb; /* currently executing TB  */  \
159 a316d335 bellard
    /* soft mmu support */                                              \
160 2e70f6ef pbrook
    /* in order to avoid passing too many arguments to the MMIO         \
161 2e70f6ef pbrook
       helpers, we store some rarely used information in the CPU        \
162 a316d335 bellard
       context) */                                                      \
163 2e70f6ef pbrook
    unsigned long mem_io_pc; /* host pc at which the memory was         \
164 2e70f6ef pbrook
                                accessed */                             \
165 2e70f6ef pbrook
    target_ulong mem_io_vaddr; /* target virtual addr at which the      \
166 2e70f6ef pbrook
                                     memory was accessed */             \
167 9656f324 pbrook
    uint32_t halted; /* Nonzero if the CPU is in suspend state */       \
168 9656f324 pbrook
    uint32_t interrupt_request;                                         \
169 be214e6c aurel32
    volatile sig_atomic_t exit_request;                                 \
170 20cb400d Paul Brook
    CPU_COMMON_TLB                                                      \
171 a316d335 bellard
    struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
172 a20e31dc blueswir1
    /* buffer for temporaries in the code generator */                  \
173 a20e31dc blueswir1
    long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
174 a316d335 bellard
                                                                        \
175 2e70f6ef pbrook
    int64_t icount_extra; /* Instructions until next timer event.  */   \
176 2e70f6ef pbrook
    /* Number of cycles left, with interrupt flag in high bit.          \
177 2e70f6ef pbrook
       This allows a single read-compare-cbranch-write sequence to test \
178 2e70f6ef pbrook
       for both decrementer underflow and exceptions.  */               \
179 2e70f6ef pbrook
    union {                                                             \
180 2e70f6ef pbrook
        uint32_t u32;                                                   \
181 2e70f6ef pbrook
        icount_decr_u16 u16;                                            \
182 2e70f6ef pbrook
    } icount_decr;                                                      \
183 2e70f6ef pbrook
    uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
184 2e70f6ef pbrook
                                                                        \
185 a316d335 bellard
    /* from this point: preserved by CPU reset */                       \
186 a316d335 bellard
    /* ice debug support */                                             \
187 72cf2d4f Blue Swirl
    QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
188 a316d335 bellard
    int singlestep_enabled;                                             \
189 a316d335 bellard
                                                                        \
190 72cf2d4f Blue Swirl
    QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
191 a1d1bb31 aliguori
    CPUWatchpoint *watchpoint_hit;                                      \
192 56aebc89 pbrook
                                                                        \
193 56aebc89 pbrook
    struct GDBRegisterState *gdb_regs;                                  \
194 6658ffb8 pbrook
                                                                        \
195 9133e39b bellard
    /* Core interrupt code */                                           \
196 9133e39b bellard
    jmp_buf jmp_env;                                                    \
197 acb6685f Anthony Liguori
    int exception_index;                                                \
198 9133e39b bellard
                                                                        \
199 c2764719 pbrook
    CPUState *next_cpu; /* next CPU sharing TB cache */                 \
200 6a00d601 bellard
    int cpu_index; /* CPU index (informative) */                        \
201 1e9fa730 Nathan Froyd
    uint32_t host_tid; /* host thread ID */                             \
202 268a362c aliguori
    int numa_node; /* NUMA node this cpu is belonging to  */            \
203 dc6b1c09 Andre Przywara
    int nr_cores;  /* number of cores within this CPU package */        \
204 dc6b1c09 Andre Przywara
    int nr_threads;/* number of threads within this CPU */              \
205 d5975363 pbrook
    int running; /* Nonzero if cpu is currently running(usermode).  */  \
206 dc7a09cf Jan Kiszka
    int thread_id;                                                      \
207 a316d335 bellard
    /* user data */                                                     \
208 01ba9816 ths
    void *opaque;                                                       \
209 01ba9816 ths
                                                                        \
210 d6dc3d42 aliguori
    uint32_t created;                                                   \
211 ced6c051 Marcelo Tosatti
    uint32_t stop;   /* Stop request */                                 \
212 ced6c051 Marcelo Tosatti
    uint32_t stopped; /* Artificially stopped */                        \
213 d6dc3d42 aliguori
    struct QemuThread *thread;                                          \
214 d6dc3d42 aliguori
    struct QemuCond *halt_cond;                                         \
215 aa2c364b Jan Kiszka
    int thread_kicked;                                                  \
216 e82bcec2 Marcelo Tosatti
    struct qemu_work_item *queued_work_first, *queued_work_last;        \
217 7ba1e619 aliguori
    const char *cpu_model_str;                                          \
218 7ba1e619 aliguori
    struct KVMState *kvm_state;                                         \
219 7ba1e619 aliguori
    struct kvm_run *kvm_run;                                            \
220 9ded2744 Jan Kiszka
    int kvm_fd;                                                         \
221 9ded2744 Jan Kiszka
    int kvm_vcpu_dirty;
222 a316d335 bellard
223 ab93bbe2 bellard
#endif