Statistics
| Branch: | Revision:

root / cpu-defs.h @ ebf50fb3

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 d656469f bellard
#if TARGET_PHYS_ADDR_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 0f459d16 pbrook
    /* Addend to virtual address to get physical address.  IO accesses
96 ee50add9 pbrook
       use the corresponding iotlb value.  */
97 d656469f bellard
#if TARGET_PHYS_ADDR_BITS == 64
98 d656469f bellard
    /* on i386 Linux make sure it is aligned */
99 c227f099 Anthony Liguori
    target_phys_addr_t addend __attribute__((aligned(8)));
100 d656469f bellard
#else
101 c227f099 Anthony Liguori
    target_phys_addr_t addend;
102 d656469f bellard
#endif
103 d656469f bellard
    /* padding to get a power of two size */
104 d656469f bellard
    uint8_t dummy[(1 << CPU_TLB_ENTRY_BITS) - 
105 d656469f bellard
                  (sizeof(target_ulong) * 3 + 
106 c227f099 Anthony Liguori
                   ((-sizeof(target_ulong) * 3) & (sizeof(target_phys_addr_t) - 1)) + 
107 c227f099 Anthony Liguori
                   sizeof(target_phys_addr_t))];
108 ab93bbe2 bellard
} CPUTLBEntry;
109 ab93bbe2 bellard
110 20cb400d Paul Brook
#define CPU_COMMON_TLB \
111 20cb400d Paul Brook
    /* The meaning of the MMU modes is defined in the target code. */   \
112 20cb400d Paul Brook
    CPUTLBEntry tlb_table[NB_MMU_MODES][CPU_TLB_SIZE];                  \
113 20cb400d Paul Brook
    target_phys_addr_t iotlb[NB_MMU_MODES][CPU_TLB_SIZE];               \
114 d4c430a8 Paul Brook
    target_ulong tlb_flush_addr;                                        \
115 d4c430a8 Paul Brook
    target_ulong tlb_flush_mask;
116 20cb400d Paul Brook
117 20cb400d Paul Brook
#else
118 20cb400d Paul Brook
119 20cb400d Paul Brook
#define CPU_COMMON_TLB
120 20cb400d Paul Brook
121 20cb400d Paul Brook
#endif
122 20cb400d Paul Brook
123 20cb400d Paul Brook
124 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
125 2e70f6ef pbrook
typedef struct icount_decr_u16 {
126 2e70f6ef pbrook
    uint16_t high;
127 2e70f6ef pbrook
    uint16_t low;
128 2e70f6ef pbrook
} icount_decr_u16;
129 2e70f6ef pbrook
#else
130 2e70f6ef pbrook
typedef struct icount_decr_u16 {
131 2e70f6ef pbrook
    uint16_t low;
132 2e70f6ef pbrook
    uint16_t high;
133 2e70f6ef pbrook
} icount_decr_u16;
134 2e70f6ef pbrook
#endif
135 2e70f6ef pbrook
136 7ba1e619 aliguori
struct kvm_run;
137 7ba1e619 aliguori
struct KVMState;
138 7ba1e619 aliguori
139 a1d1bb31 aliguori
typedef struct CPUBreakpoint {
140 a1d1bb31 aliguori
    target_ulong pc;
141 a1d1bb31 aliguori
    int flags; /* BP_* */
142 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CPUBreakpoint) entry;
143 a1d1bb31 aliguori
} CPUBreakpoint;
144 a1d1bb31 aliguori
145 a1d1bb31 aliguori
typedef struct CPUWatchpoint {
146 a1d1bb31 aliguori
    target_ulong vaddr;
147 a1d1bb31 aliguori
    target_ulong len_mask;
148 a1d1bb31 aliguori
    int flags; /* BP_* */
149 72cf2d4f Blue Swirl
    QTAILQ_ENTRY(CPUWatchpoint) entry;
150 a1d1bb31 aliguori
} CPUWatchpoint;
151 a1d1bb31 aliguori
152 a20e31dc blueswir1
#define CPU_TEMP_BUF_NLONGS 128
153 a316d335 bellard
#define CPU_COMMON                                                      \
154 a316d335 bellard
    struct TranslationBlock *current_tb; /* currently executing TB  */  \
155 a316d335 bellard
    /* soft mmu support */                                              \
156 2e70f6ef pbrook
    /* in order to avoid passing too many arguments to the MMIO         \
157 2e70f6ef pbrook
       helpers, we store some rarely used information in the CPU        \
158 a316d335 bellard
       context) */                                                      \
159 2e70f6ef pbrook
    unsigned long mem_io_pc; /* host pc at which the memory was         \
160 2e70f6ef pbrook
                                accessed */                             \
161 2e70f6ef pbrook
    target_ulong mem_io_vaddr; /* target virtual addr at which the      \
162 2e70f6ef pbrook
                                     memory was accessed */             \
163 9656f324 pbrook
    uint32_t halted; /* Nonzero if the CPU is in suspend state */       \
164 d6dc3d42 aliguori
    uint32_t stop;   /* Stop request */                                 \
165 d6dc3d42 aliguori
    uint32_t stopped; /* Artificially stopped */                        \
166 9656f324 pbrook
    uint32_t interrupt_request;                                         \
167 be214e6c aurel32
    volatile sig_atomic_t exit_request;                                 \
168 20cb400d Paul Brook
    CPU_COMMON_TLB                                                      \
169 a316d335 bellard
    struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
170 a20e31dc blueswir1
    /* buffer for temporaries in the code generator */                  \
171 a20e31dc blueswir1
    long temp_buf[CPU_TEMP_BUF_NLONGS];                                 \
172 a316d335 bellard
                                                                        \
173 2e70f6ef pbrook
    int64_t icount_extra; /* Instructions until next timer event.  */   \
174 2e70f6ef pbrook
    /* Number of cycles left, with interrupt flag in high bit.          \
175 2e70f6ef pbrook
       This allows a single read-compare-cbranch-write sequence to test \
176 2e70f6ef pbrook
       for both decrementer underflow and exceptions.  */               \
177 2e70f6ef pbrook
    union {                                                             \
178 2e70f6ef pbrook
        uint32_t u32;                                                   \
179 2e70f6ef pbrook
        icount_decr_u16 u16;                                            \
180 2e70f6ef pbrook
    } icount_decr;                                                      \
181 2e70f6ef pbrook
    uint32_t can_do_io; /* nonzero if memory mapped IO is safe.  */     \
182 2e70f6ef pbrook
                                                                        \
183 a316d335 bellard
    /* from this point: preserved by CPU reset */                       \
184 a316d335 bellard
    /* ice debug support */                                             \
185 72cf2d4f Blue Swirl
    QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;            \
186 a316d335 bellard
    int singlestep_enabled;                                             \
187 a316d335 bellard
                                                                        \
188 72cf2d4f Blue Swirl
    QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;            \
189 a1d1bb31 aliguori
    CPUWatchpoint *watchpoint_hit;                                      \
190 56aebc89 pbrook
                                                                        \
191 56aebc89 pbrook
    struct GDBRegisterState *gdb_regs;                                  \
192 6658ffb8 pbrook
                                                                        \
193 9133e39b bellard
    /* Core interrupt code */                                           \
194 9133e39b bellard
    jmp_buf jmp_env;                                                    \
195 acb6685f Anthony Liguori
    int exception_index;                                                \
196 9133e39b bellard
                                                                        \
197 c2764719 pbrook
    CPUState *next_cpu; /* next CPU sharing TB cache */                 \
198 6a00d601 bellard
    int cpu_index; /* CPU index (informative) */                        \
199 1e9fa730 Nathan Froyd
    uint32_t host_tid; /* host thread ID */                             \
200 268a362c aliguori
    int numa_node; /* NUMA node this cpu is belonging to  */            \
201 dc6b1c09 Andre Przywara
    int nr_cores;  /* number of cores within this CPU package */        \
202 dc6b1c09 Andre Przywara
    int nr_threads;/* number of threads within this CPU */              \
203 d5975363 pbrook
    int running; /* Nonzero if cpu is currently running(usermode).  */  \
204 a316d335 bellard
    /* user data */                                                     \
205 01ba9816 ths
    void *opaque;                                                       \
206 01ba9816 ths
                                                                        \
207 d6dc3d42 aliguori
    uint32_t created;                                                   \
208 d6dc3d42 aliguori
    struct QemuThread *thread;                                          \
209 d6dc3d42 aliguori
    struct QemuCond *halt_cond;                                         \
210 7ba1e619 aliguori
    const char *cpu_model_str;                                          \
211 7ba1e619 aliguori
    struct KVMState *kvm_state;                                         \
212 7ba1e619 aliguori
    struct kvm_run *kvm_run;                                            \
213 9ded2744 Jan Kiszka
    int kvm_fd;                                                         \
214 9ded2744 Jan Kiszka
    int kvm_vcpu_dirty;
215 a316d335 bellard
216 ab93bbe2 bellard
#endif