Statistics
| Branch: | Revision:

root / cpu-defs.h @ 5dba48a8

History | View | Annotate | Download (9 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 ab6d960f bellard
/* target_ulong is the type of a virtual address */
41 35b66fc4 bellard
#if TARGET_LONG_SIZE == 4
42 35b66fc4 bellard
typedef int32_t target_long;
43 35b66fc4 bellard
typedef uint32_t target_ulong;
44 c27004ec bellard
#define TARGET_FMT_lx "%08x"
45 b62b461b j_mayer
#define TARGET_FMT_ld "%d"
46 71c8b8fd j_mayer
#define TARGET_FMT_lu "%u"
47 35b66fc4 bellard
#elif TARGET_LONG_SIZE == 8
48 35b66fc4 bellard
typedef int64_t target_long;
49 35b66fc4 bellard
typedef uint64_t target_ulong;
50 26a76461 bellard
#define TARGET_FMT_lx "%016" PRIx64
51 b62b461b j_mayer
#define TARGET_FMT_ld "%" PRId64
52 71c8b8fd j_mayer
#define TARGET_FMT_lu "%" PRIu64
53 35b66fc4 bellard
#else
54 35b66fc4 bellard
#error TARGET_LONG_SIZE undefined
55 35b66fc4 bellard
#endif
56 35b66fc4 bellard
57 f193c797 bellard
#define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
58 f193c797 bellard
59 2be0071f bellard
#define EXCP_INTERRUPT         0x10000 /* async interruption */
60 2be0071f bellard
#define EXCP_HLT        0x10001 /* hlt instruction reached */
61 2be0071f bellard
#define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
62 5a1e3cfc bellard
#define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
63 ab93bbe2 bellard
64 a316d335 bellard
#define TB_JMP_CACHE_BITS 12
65 a316d335 bellard
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
66 a316d335 bellard
67 b362e5e0 pbrook
/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
68 b362e5e0 pbrook
   addresses on the same page.  The top bits are the same.  This allows
69 b362e5e0 pbrook
   TLB invalidation to quickly clear a subset of the hash table.  */
70 b362e5e0 pbrook
#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
71 b362e5e0 pbrook
#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
72 b362e5e0 pbrook
#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
73 b362e5e0 pbrook
#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
74 b362e5e0 pbrook
75 20cb400d Paul Brook
#if !defined(CONFIG_USER_ONLY)
76 84b7b8e7 bellard
#define CPU_TLB_BITS 8
77 84b7b8e7 bellard
#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
78 ab93bbe2 bellard
79 355b1943 Paul Brook
#if HOST_LONG_BITS == 32 && TARGET_LONG_BITS == 32
80 d656469f bellard
#define CPU_TLB_ENTRY_BITS 4
81 d656469f bellard
#else
82 d656469f bellard
#define CPU_TLB_ENTRY_BITS 5
83 d656469f bellard
#endif
84 d656469f bellard
85 ab93bbe2 bellard
typedef struct CPUTLBEntry {
86 0f459d16 pbrook
    /* bit TARGET_LONG_BITS to TARGET_PAGE_BITS : virtual address
87 0f459d16 pbrook
       bit TARGET_PAGE_BITS-1..4  : Nonzero for accesses that should not
88 0f459d16 pbrook
                                    go directly to ram.
89 db8d7466 bellard
       bit 3                      : indicates that the entry is invalid
90 db8d7466 bellard
       bit 2..0                   : zero
91 db8d7466 bellard
    */
92 5fafdf24 ths
    target_ulong addr_read;
93 5fafdf24 ths
    target_ulong addr_write;
94 5fafdf24 ths
    target_ulong addr_code;
95 355b1943 Paul Brook
    /* Addend to virtual address to get host address.  IO accesses
96 ee50add9 pbrook
       use the corresponding iotlb value.  */
97 355b1943 Paul Brook
    unsigned long addend;
98 d656469f bellard
    /* padding to get a power of two size */
99 d656469f bellard
    uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 
100 d656469f bellard
                  (sizeof(target_ulong) * 3 + 
101 355b1943 Paul Brook
                   ((-sizeof(target_ulong) * 3) & (sizeof(unsigned long) - 1)) + 
102 355b1943 Paul Brook
                   sizeof(unsigned long))];
103 ab93bbe2 bellard
} CPUTLBEntry;
104 ab93bbe2 bellard
105 355b1943 Paul Brook
extern int CPUTLBEntry_wrong_size[sizeof(CPUTLBEntry) == (1 << CPU_TLB_ENTRY_BITS) ? 1 : -1];
106 355b1943 Paul Brook
107 20cb400d Paul Brook
#define CPU_COMMON_TLB \
108 20cb400d Paul Brook
    /* The meaning of the MMU modes is defined in the target code. */   \
109 20cb400d Paul Brook
    CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
110 20cb400d Paul Brook
    target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
111 d4c430a8 Paul Brook
    target_ulong tlb_flush_addr;                                        \
112 d4c430a8 Paul Brook
    target_ulong tlb_flush_mask;
113 20cb400d Paul Brook
114 20cb400d Paul Brook
#else
115 20cb400d Paul Brook
116 20cb400d Paul Brook
#define CPU_COMMON_TLB
117 20cb400d Paul Brook
118 20cb400d Paul Brook
#endif
119 20cb400d Paul Brook
120 20cb400d Paul Brook
121 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
122 2e70f6ef pbrook
typedef struct icount_decr_u16 {
123 2e70f6ef pbrook
    uint16_t high;
124 2e70f6ef pbrook
    uint16_t low;
125 2e70f6ef pbrook
} icount_decr_u16;
126 2e70f6ef pbrook
#else
127 2e70f6ef pbrook
typedef struct icount_decr_u16 {
128 2e70f6ef pbrook
    uint16_t low;
129 2e70f6ef pbrook
    uint16_t high;
130 2e70f6ef pbrook
} icount_decr_u16;
131 2e70f6ef pbrook
#endif
132 2e70f6ef pbrook
133 7ba1e619 aliguori
struct kvm_run;
134 7ba1e619 aliguori
struct KVMState;
135 e82bcec2 Marcelo Tosatti
struct qemu_work_item;
136 7ba1e619 aliguori
137 a1d1bb31 aliguori
typedef struct CPUBreakpoint {
138 a1d1bb31 aliguori
    target_ulong pc;
139 a1d1bb31 aliguori
    int flags; /* BP_* */
140 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CPUBreakpoint) entry;
141 a1d1bb31 aliguori
} CPUBreakpoint;
142 a1d1bb31 aliguori
143 a1d1bb31 aliguori
typedef struct CPUWatchpoint {
144 a1d1bb31 aliguori
    target_ulong vaddr;
145 a1d1bb31 aliguori
    target_ulong len_mask;
146 a1d1bb31 aliguori
    int flags; /* BP_* */
147 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CPUWatchpoint) entry;
148 a1d1bb31 aliguori
} CPUWatchpoint;
149 a1d1bb31 aliguori
150 a20e31dc blueswir1
#define CPU_TEMP_BUF_NLONGS 128
151 a316d335 bellard
#define CPU_COMMON                                                      \
152 a316d335 bellard
    struct TranslationBlock *current_tb; /* currently executing TB  */  \
153 a316d335 bellard
    /* soft mmu support */                                              \
154 2e70f6ef pbrook
    /* in order to avoid passing too many arguments to the MMIO         \
155 2e70f6ef pbrook
       helpers, we store some rarely used information in the CPU        \
156 a316d335 bellard
       context) */                                                      \
157 2e70f6ef pbrook
    unsigned long mem_io_pc; /* host pc at which the memory was         \
158 2e70f6ef pbrook
                                accessed */                             \
159 2e70f6ef pbrook
    target_ulong mem_io_vaddr; /* target virtual addr at which the      \
160 2e70f6ef pbrook
                                     memory was accessed */             \
161 9656f324 pbrook
    uint32_t halted; /* Nonzero if the CPU is in suspend state */       \
162 9656f324 pbrook
    uint32_t interrupt_request;                                         \
163 be214e6c aurel32
    volatile sig_atomic_t exit_request;                                 \
164 20cb400d Paul Brook
    CPU_COMMON_TLB                                                      \
165 a316d335 bellard
    struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
166 a20e31dc blueswir1
    /* buffer for temporaries in the code generator */                  \
167 a20e31dc blueswir1
    long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
168 a316d335 bellard
                                                                        \
169 2e70f6ef pbrook
    int64_t icount_extra; /* Instructions until next timer event.  */   \
170 2e70f6ef pbrook
    /* Number of cycles left, with interrupt flag in high bit.          \
171 2e70f6ef pbrook
       This allows a single read-compare-cbranch-write sequence to test \
172 2e70f6ef pbrook
       for both decrementer underflow and exceptions.  */               \
173 2e70f6ef pbrook
    union {                                                             \
174 2e70f6ef pbrook
        uint32_t u32;                                                   \
175 2e70f6ef pbrook
        icount_decr_u16 u16;                                            \
176 2e70f6ef pbrook
    } icount_decr;                                                      \
177 2e70f6ef pbrook
    uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
178 2e70f6ef pbrook
                                                                        \
179 a316d335 bellard
    /* from this point: preserved by CPU reset */                       \
180 a316d335 bellard
    /* ice debug support */                                             \
181 72cf2d4f Blue Swirl
    QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
182 a316d335 bellard
    int singlestep_enabled;                                             \
183 a316d335 bellard
                                                                        \
184 72cf2d4f Blue Swirl
    QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
185 a1d1bb31 aliguori
    CPUWatchpoint *watchpoint_hit;                                      \
186 56aebc89 pbrook
                                                                        \
187 56aebc89 pbrook
    struct GDBRegisterState *gdb_regs;                                  \
188 6658ffb8 pbrook
                                                                        \
189 9133e39b bellard
    /* Core interrupt code */                                           \
190 9133e39b bellard
    jmp_buf jmp_env;                                                    \
191 acb6685f Anthony Liguori
    int exception_index;                                                \
192 9133e39b bellard
                                                                        \
193 c2764719 pbrook
    CPUState *next_cpu; /* next CPU sharing TB cache */                 \
194 6a00d601 bellard
    int cpu_index; /* CPU index (informative) */                        \
195 1e9fa730 Nathan Froyd
    uint32_t host_tid; /* host thread ID */                             \
196 268a362c aliguori
    int numa_node; /* NUMA node this cpu is belonging to  */            \
197 dc6b1c09 Andre Przywara
    int nr_cores;  /* number of cores within this CPU package */        \
198 dc6b1c09 Andre Przywara
    int nr_threads;/* number of threads within this CPU */              \
199 d5975363 pbrook
    int running; /* Nonzero if cpu is currently running(usermode).  */  \
200 a316d335 bellard
    /* user data */                                                     \
201 01ba9816 ths
    void *opaque;                                                       \
202 01ba9816 ths
                                                                        \
203 d6dc3d42 aliguori
    uint32_t created;                                                   \
204 ced6c051 Marcelo Tosatti
    uint32_t stop;   /* Stop request */                                 \
205 ced6c051 Marcelo Tosatti
    uint32_t stopped; /* Artificially stopped */                        \
206 d6dc3d42 aliguori
    struct QemuThread *thread;                                          \
207 d6dc3d42 aliguori
    struct QemuCond *halt_cond;                                         \
208 e82bcec2 Marcelo Tosatti
    struct qemu_work_item *queued_work_first, *queued_work_last;        \
209 7ba1e619 aliguori
    const char *cpu_model_str;                                          \
210 7ba1e619 aliguori
    struct KVMState *kvm_state;                                         \
211 7ba1e619 aliguori
    struct kvm_run *kvm_run;                                            \
212 9ded2744 Jan Kiszka
    int kvm_fd;                                                         \
213 9ded2744 Jan Kiszka
    int kvm_vcpu_dirty;
214 a316d335 bellard
215 ab93bbe2 bellard
#endif