Statistics
| Branch: | Revision:

root / cpu-all.h @ 25e5e4c7

History | View | Annotate | Download (17.3 kB)

1 5a9fdfec bellard
/*
2 5a9fdfec bellard
 * defines common to all virtual CPUs
3 5fafdf24 ths
 *
4 5a9fdfec bellard
 *  Copyright (c) 2003 Fabrice Bellard
5 5a9fdfec bellard
 *
6 5a9fdfec bellard
 * This library is free software; you can redistribute it and/or
7 5a9fdfec bellard
 * modify it under the terms of the GNU Lesser General Public
8 5a9fdfec bellard
 * License as published by the Free Software Foundation; either
9 5a9fdfec bellard
 * version 2 of the License, or (at your option) any later version.
10 5a9fdfec bellard
 *
11 5a9fdfec bellard
 * This library is distributed in the hope that it will be useful,
12 5a9fdfec bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 5a9fdfec bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 5a9fdfec bellard
 * Lesser General Public License for more details.
15 5a9fdfec bellard
 *
16 5a9fdfec 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 5a9fdfec bellard
 */
19 5a9fdfec bellard
#ifndef CPU_ALL_H
20 5a9fdfec bellard
#define CPU_ALL_H
21 5a9fdfec bellard
22 7d99a001 blueswir1
#include "qemu-common.h"
23 b3c4bbe5 Paolo Bonzini
#include "qemu-tls.h"
24 1ad2134f Paul Brook
#include "cpu-common.h"
25 fae001f5 Wen Congyang
#include "memory_mapping.h"
26 25ae9c1d Wen Congyang
#include "dump.h"
27 0ac4bd56 bellard
28 5fafdf24 ths
/* some important defines:
29 5fafdf24 ths
 *
30 0ac4bd56 bellard
 * WORDS_ALIGNED : if defined, the host cpu can only make word aligned
31 0ac4bd56 bellard
 * memory accesses.
32 5fafdf24 ths
 *
33 e2542fe2 Juan Quintela
 * HOST_WORDS_BIGENDIAN : if defined, the host cpu is big endian and
34 0ac4bd56 bellard
 * otherwise little endian.
35 5fafdf24 ths
 *
36 0ac4bd56 bellard
 * (TARGET_WORDS_ALIGNED : same for target cpu (not supported yet))
37 5fafdf24 ths
 *
38 0ac4bd56 bellard
 * TARGET_WORDS_BIGENDIAN : same for target cpu
39 0ac4bd56 bellard
 */
40 0ac4bd56 bellard
41 e2542fe2 Juan Quintela
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
42 f193c797 bellard
#define BSWAP_NEEDED
43 f193c797 bellard
#endif
44 f193c797 bellard
45 f193c797 bellard
#ifdef BSWAP_NEEDED
46 f193c797 bellard
47 f193c797 bellard
static inline uint16_t tswap16(uint16_t s)
48 f193c797 bellard
{
49 f193c797 bellard
    return bswap16(s);
50 f193c797 bellard
}
51 f193c797 bellard
52 f193c797 bellard
static inline uint32_t tswap32(uint32_t s)
53 f193c797 bellard
{
54 f193c797 bellard
    return bswap32(s);
55 f193c797 bellard
}
56 f193c797 bellard
57 f193c797 bellard
static inline uint64_t tswap64(uint64_t s)
58 f193c797 bellard
{
59 f193c797 bellard
    return bswap64(s);
60 f193c797 bellard
}
61 f193c797 bellard
62 f193c797 bellard
static inline void tswap16s(uint16_t *s)
63 f193c797 bellard
{
64 f193c797 bellard
    *s = bswap16(*s);
65 f193c797 bellard
}
66 f193c797 bellard
67 f193c797 bellard
static inline void tswap32s(uint32_t *s)
68 f193c797 bellard
{
69 f193c797 bellard
    *s = bswap32(*s);
70 f193c797 bellard
}
71 f193c797 bellard
72 f193c797 bellard
static inline void tswap64s(uint64_t *s)
73 f193c797 bellard
{
74 f193c797 bellard
    *s = bswap64(*s);
75 f193c797 bellard
}
76 f193c797 bellard
77 f193c797 bellard
#else
78 f193c797 bellard
79 f193c797 bellard
static inline uint16_t tswap16(uint16_t s)
80 f193c797 bellard
{
81 f193c797 bellard
    return s;
82 f193c797 bellard
}
83 f193c797 bellard
84 f193c797 bellard
static inline uint32_t tswap32(uint32_t s)
85 f193c797 bellard
{
86 f193c797 bellard
    return s;
87 f193c797 bellard
}
88 f193c797 bellard
89 f193c797 bellard
static inline uint64_t tswap64(uint64_t s)
90 f193c797 bellard
{
91 f193c797 bellard
    return s;
92 f193c797 bellard
}
93 f193c797 bellard
94 f193c797 bellard
static inline void tswap16s(uint16_t *s)
95 f193c797 bellard
{
96 f193c797 bellard
}
97 f193c797 bellard
98 f193c797 bellard
static inline void tswap32s(uint32_t *s)
99 f193c797 bellard
{
100 f193c797 bellard
}
101 f193c797 bellard
102 f193c797 bellard
static inline void tswap64s(uint64_t *s)
103 f193c797 bellard
{
104 f193c797 bellard
}
105 f193c797 bellard
106 f193c797 bellard
#endif
107 f193c797 bellard
108 f193c797 bellard
#if TARGET_LONG_SIZE == 4
109 f193c797 bellard
#define tswapl(s) tswap32(s)
110 f193c797 bellard
#define tswapls(s) tswap32s((uint32_t *)(s))
111 0a962c02 bellard
#define bswaptls(s) bswap32s(s)
112 f193c797 bellard
#else
113 f193c797 bellard
#define tswapl(s) tswap64(s)
114 f193c797 bellard
#define tswapls(s) tswap64s((uint64_t *)(s))
115 0a962c02 bellard
#define bswaptls(s) bswap64s(s)
116 f193c797 bellard
#endif
117 f193c797 bellard
118 61382a50 bellard
/* CPU memory access without any memory or io remapping */
119 61382a50 bellard
120 83d73968 bellard
/*
121 83d73968 bellard
 * the generic syntax for the memory accesses is:
122 83d73968 bellard
 *
123 83d73968 bellard
 * load: ld{type}{sign}{size}{endian}_{access_type}(ptr)
124 83d73968 bellard
 *
125 83d73968 bellard
 * store: st{type}{size}{endian}_{access_type}(ptr, val)
126 83d73968 bellard
 *
127 83d73968 bellard
 * type is:
128 83d73968 bellard
 * (empty): integer access
129 83d73968 bellard
 *   f    : float access
130 5fafdf24 ths
 *
131 83d73968 bellard
 * sign is:
132 83d73968 bellard
 * (empty): for floats or 32 bit size
133 83d73968 bellard
 *   u    : unsigned
134 83d73968 bellard
 *   s    : signed
135 83d73968 bellard
 *
136 83d73968 bellard
 * size is:
137 83d73968 bellard
 *   b: 8 bits
138 83d73968 bellard
 *   w: 16 bits
139 83d73968 bellard
 *   l: 32 bits
140 83d73968 bellard
 *   q: 64 bits
141 5fafdf24 ths
 *
142 83d73968 bellard
 * endian is:
143 83d73968 bellard
 * (empty): target cpu endianness or 8 bit access
144 83d73968 bellard
 *   r    : reversed target cpu endianness (not implemented yet)
145 83d73968 bellard
 *   be   : big endian (not implemented yet)
146 83d73968 bellard
 *   le   : little endian (not implemented yet)
147 83d73968 bellard
 *
148 83d73968 bellard
 * access_type is:
149 83d73968 bellard
 *   raw    : host memory access
150 83d73968 bellard
 *   user   : user mode access using soft MMU
151 83d73968 bellard
 *   kernel : kernel mode access using soft MMU
152 83d73968 bellard
 */
153 2df3b95d bellard
154 cbbab922 Paolo Bonzini
/* target-endianness CPU memory access functions */
155 2df3b95d bellard
#if defined(TARGET_WORDS_BIGENDIAN)
156 2df3b95d bellard
#define lduw_p(p) lduw_be_p(p)
157 2df3b95d bellard
#define ldsw_p(p) ldsw_be_p(p)
158 2df3b95d bellard
#define ldl_p(p) ldl_be_p(p)
159 2df3b95d bellard
#define ldq_p(p) ldq_be_p(p)
160 2df3b95d bellard
#define ldfl_p(p) ldfl_be_p(p)
161 2df3b95d bellard
#define ldfq_p(p) ldfq_be_p(p)
162 2df3b95d bellard
#define stw_p(p, v) stw_be_p(p, v)
163 2df3b95d bellard
#define stl_p(p, v) stl_be_p(p, v)
164 2df3b95d bellard
#define stq_p(p, v) stq_be_p(p, v)
165 2df3b95d bellard
#define stfl_p(p, v) stfl_be_p(p, v)
166 2df3b95d bellard
#define stfq_p(p, v) stfq_be_p(p, v)
167 2df3b95d bellard
#else
168 2df3b95d bellard
#define lduw_p(p) lduw_le_p(p)
169 2df3b95d bellard
#define ldsw_p(p) ldsw_le_p(p)
170 2df3b95d bellard
#define ldl_p(p) ldl_le_p(p)
171 2df3b95d bellard
#define ldq_p(p) ldq_le_p(p)
172 2df3b95d bellard
#define ldfl_p(p) ldfl_le_p(p)
173 2df3b95d bellard
#define ldfq_p(p) ldfq_le_p(p)
174 2df3b95d bellard
#define stw_p(p, v) stw_le_p(p, v)
175 2df3b95d bellard
#define stl_p(p, v) stl_le_p(p, v)
176 2df3b95d bellard
#define stq_p(p, v) stq_le_p(p, v)
177 2df3b95d bellard
#define stfl_p(p, v) stfl_le_p(p, v)
178 2df3b95d bellard
#define stfq_p(p, v) stfq_le_p(p, v)
179 5a9fdfec bellard
#endif
180 5a9fdfec bellard
181 61382a50 bellard
/* MMU memory access macros */
182 61382a50 bellard
183 53a5960a pbrook
#if defined(CONFIG_USER_ONLY)
184 0e62fd79 aurel32
#include <assert.h>
185 0e62fd79 aurel32
#include "qemu-types.h"
186 0e62fd79 aurel32
187 53a5960a pbrook
/* On some host systems the guest address space is reserved on the host.
188 53a5960a pbrook
 * This allows the guest address space to be offset to a convenient location.
189 53a5960a pbrook
 */
190 379f6698 Paul Brook
#if defined(CONFIG_USE_GUEST_BASE)
191 379f6698 Paul Brook
extern unsigned long guest_base;
192 379f6698 Paul Brook
extern int have_guest_base;
193 68a1c816 Paul Brook
extern unsigned long reserved_va;
194 379f6698 Paul Brook
#define GUEST_BASE guest_base
195 18e9ea8a Aurelien Jarno
#define RESERVED_VA reserved_va
196 379f6698 Paul Brook
#else
197 379f6698 Paul Brook
#define GUEST_BASE 0ul
198 18e9ea8a Aurelien Jarno
#define RESERVED_VA 0ul
199 379f6698 Paul Brook
#endif
200 53a5960a pbrook
201 53a5960a pbrook
/* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
202 8d9dde94 Peter Maydell
#define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + GUEST_BASE))
203 b9f83121 Richard Henderson
204 b9f83121 Richard Henderson
#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
205 b9f83121 Richard Henderson
#define h2g_valid(x) 1
206 b9f83121 Richard Henderson
#else
207 b9f83121 Richard Henderson
#define h2g_valid(x) ({ \
208 b9f83121 Richard Henderson
    unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
209 39879bbb Alexander Graf
    (__guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
210 39879bbb Alexander Graf
    (!RESERVED_VA || (__guest < RESERVED_VA)); \
211 b9f83121 Richard Henderson
})
212 b9f83121 Richard Henderson
#endif
213 b9f83121 Richard Henderson
214 0e62fd79 aurel32
#define h2g(x) ({ \
215 0e62fd79 aurel32
    unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
216 0e62fd79 aurel32
    /* Check if given address fits target address space */ \
217 b9f83121 Richard Henderson
    assert(h2g_valid(x)); \
218 0e62fd79 aurel32
    (abi_ulong)__ret; \
219 0e62fd79 aurel32
})
220 53a5960a pbrook
221 53a5960a pbrook
#define saddr(x) g2h(x)
222 53a5960a pbrook
#define laddr(x) g2h(x)
223 53a5960a pbrook
224 53a5960a pbrook
#else /* !CONFIG_USER_ONLY */
225 c27004ec bellard
/* NOTE: we use double casts if pointers and target_ulong have
226 c27004ec bellard
   different sizes */
227 27b0dc16 Stefan Weil
#define saddr(x) (uint8_t *)(intptr_t)(x)
228 27b0dc16 Stefan Weil
#define laddr(x) (uint8_t *)(intptr_t)(x)
229 53a5960a pbrook
#endif
230 53a5960a pbrook
231 53a5960a pbrook
#define ldub_raw(p) ldub_p(laddr((p)))
232 53a5960a pbrook
#define ldsb_raw(p) ldsb_p(laddr((p)))
233 53a5960a pbrook
#define lduw_raw(p) lduw_p(laddr((p)))
234 53a5960a pbrook
#define ldsw_raw(p) ldsw_p(laddr((p)))
235 53a5960a pbrook
#define ldl_raw(p) ldl_p(laddr((p)))
236 53a5960a pbrook
#define ldq_raw(p) ldq_p(laddr((p)))
237 53a5960a pbrook
#define ldfl_raw(p) ldfl_p(laddr((p)))
238 53a5960a pbrook
#define ldfq_raw(p) ldfq_p(laddr((p)))
239 53a5960a pbrook
#define stb_raw(p, v) stb_p(saddr((p)), v)
240 53a5960a pbrook
#define stw_raw(p, v) stw_p(saddr((p)), v)
241 53a5960a pbrook
#define stl_raw(p, v) stl_p(saddr((p)), v)
242 53a5960a pbrook
#define stq_raw(p, v) stq_p(saddr((p)), v)
243 53a5960a pbrook
#define stfl_raw(p, v) stfl_p(saddr((p)), v)
244 53a5960a pbrook
#define stfq_raw(p, v) stfq_p(saddr((p)), v)
245 c27004ec bellard
246 c27004ec bellard
247 5fafdf24 ths
#if defined(CONFIG_USER_ONLY)
248 61382a50 bellard
249 61382a50 bellard
/* if user mode, no other memory access functions */
250 61382a50 bellard
#define ldub(p) ldub_raw(p)
251 61382a50 bellard
#define ldsb(p) ldsb_raw(p)
252 61382a50 bellard
#define lduw(p) lduw_raw(p)
253 61382a50 bellard
#define ldsw(p) ldsw_raw(p)
254 61382a50 bellard
#define ldl(p) ldl_raw(p)
255 61382a50 bellard
#define ldq(p) ldq_raw(p)
256 61382a50 bellard
#define ldfl(p) ldfl_raw(p)
257 61382a50 bellard
#define ldfq(p) ldfq_raw(p)
258 61382a50 bellard
#define stb(p, v) stb_raw(p, v)
259 61382a50 bellard
#define stw(p, v) stw_raw(p, v)
260 61382a50 bellard
#define stl(p, v) stl_raw(p, v)
261 61382a50 bellard
#define stq(p, v) stq_raw(p, v)
262 61382a50 bellard
#define stfl(p, v) stfl_raw(p, v)
263 61382a50 bellard
#define stfq(p, v) stfq_raw(p, v)
264 61382a50 bellard
265 e141ab52 Blue Swirl
#ifndef CONFIG_TCG_PASS_AREG0
266 61382a50 bellard
#define ldub_code(p) ldub_raw(p)
267 61382a50 bellard
#define ldsb_code(p) ldsb_raw(p)
268 61382a50 bellard
#define lduw_code(p) lduw_raw(p)
269 61382a50 bellard
#define ldsw_code(p) ldsw_raw(p)
270 61382a50 bellard
#define ldl_code(p) ldl_raw(p)
271 bc98a7ef j_mayer
#define ldq_code(p) ldq_raw(p)
272 e141ab52 Blue Swirl
#else
273 e141ab52 Blue Swirl
#define cpu_ldub_code(env1, p) ldub_raw(p)
274 e141ab52 Blue Swirl
#define cpu_ldsb_code(env1, p) ldsb_raw(p)
275 e141ab52 Blue Swirl
#define cpu_lduw_code(env1, p) lduw_raw(p)
276 e141ab52 Blue Swirl
#define cpu_ldsw_code(env1, p) ldsw_raw(p)
277 e141ab52 Blue Swirl
#define cpu_ldl_code(env1, p) ldl_raw(p)
278 e141ab52 Blue Swirl
#define cpu_ldq_code(env1, p) ldq_raw(p)
279 e141ab52 Blue Swirl
#endif
280 61382a50 bellard
281 61382a50 bellard
#define ldub_kernel(p) ldub_raw(p)
282 61382a50 bellard
#define ldsb_kernel(p) ldsb_raw(p)
283 61382a50 bellard
#define lduw_kernel(p) lduw_raw(p)
284 61382a50 bellard
#define ldsw_kernel(p) ldsw_raw(p)
285 61382a50 bellard
#define ldl_kernel(p) ldl_raw(p)
286 bc98a7ef j_mayer
#define ldq_kernel(p) ldq_raw(p)
287 0ac4bd56 bellard
#define ldfl_kernel(p) ldfl_raw(p)
288 0ac4bd56 bellard
#define ldfq_kernel(p) ldfq_raw(p)
289 61382a50 bellard
#define stb_kernel(p, v) stb_raw(p, v)
290 61382a50 bellard
#define stw_kernel(p, v) stw_raw(p, v)
291 61382a50 bellard
#define stl_kernel(p, v) stl_raw(p, v)
292 61382a50 bellard
#define stq_kernel(p, v) stq_raw(p, v)
293 0ac4bd56 bellard
#define stfl_kernel(p, v) stfl_raw(p, v)
294 0ac4bd56 bellard
#define stfq_kernel(p, vt) stfq_raw(p, v)
295 61382a50 bellard
296 61382a50 bellard
#endif /* defined(CONFIG_USER_ONLY) */
297 61382a50 bellard
298 5a9fdfec bellard
/* page related stuff */
299 5a9fdfec bellard
300 03875444 aurel32
#define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
301 5a9fdfec bellard
#define TARGET_PAGE_MASK ~(TARGET_PAGE_SIZE - 1)
302 5a9fdfec bellard
#define TARGET_PAGE_ALIGN(addr) (((addr) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK)
303 5a9fdfec bellard
304 c6d50674 Stefan Weil
/* ??? These should be the larger of uintptr_t and target_ulong.  */
305 c6d50674 Stefan Weil
extern uintptr_t qemu_real_host_page_size;
306 c6d50674 Stefan Weil
extern uintptr_t qemu_host_page_size;
307 c6d50674 Stefan Weil
extern uintptr_t qemu_host_page_mask;
308 5a9fdfec bellard
309 83fb7adf bellard
#define HOST_PAGE_ALIGN(addr) (((addr) + qemu_host_page_size - 1) & qemu_host_page_mask)
310 5a9fdfec bellard
311 5a9fdfec bellard
/* same as PROT_xxx */
312 5a9fdfec bellard
#define PAGE_READ      0x0001
313 5a9fdfec bellard
#define PAGE_WRITE     0x0002
314 5a9fdfec bellard
#define PAGE_EXEC      0x0004
315 5a9fdfec bellard
#define PAGE_BITS      (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
316 5a9fdfec bellard
#define PAGE_VALID     0x0008
317 5a9fdfec bellard
/* original state of the write flag (used when tracking self-modifying
318 5a9fdfec bellard
   code */
319 5fafdf24 ths
#define PAGE_WRITE_ORG 0x0010
320 2e9a5713 Paul Brook
#if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
321 2e9a5713 Paul Brook
/* FIXME: Code that sets/uses this is broken and needs to go away.  */
322 50a9569b balrog
#define PAGE_RESERVED  0x0020
323 2e9a5713 Paul Brook
#endif
324 5a9fdfec bellard
325 b480d9b7 Paul Brook
#if defined(CONFIG_USER_ONLY)
326 5a9fdfec bellard
void page_dump(FILE *f);
327 5cd2c5b6 Richard Henderson
328 b480d9b7 Paul Brook
typedef int (*walk_memory_regions_fn)(void *, abi_ulong,
329 b480d9b7 Paul Brook
                                      abi_ulong, unsigned long);
330 5cd2c5b6 Richard Henderson
int walk_memory_regions(void *, walk_memory_regions_fn);
331 5cd2c5b6 Richard Henderson
332 53a5960a pbrook
int page_get_flags(target_ulong address);
333 53a5960a pbrook
void page_set_flags(target_ulong start, target_ulong end, int flags);
334 3d97b40b ths
int page_check_range(target_ulong start, target_ulong len, int flags);
335 b480d9b7 Paul Brook
#endif
336 5a9fdfec bellard
337 9349b4f9 Andreas Färber
CPUArchState *cpu_copy(CPUArchState *env);
338 9349b4f9 Andreas Färber
CPUArchState *qemu_get_cpu(int cpu);
339 c5be9f08 ths
340 f5c848ee Jan Kiszka
#define CPU_DUMP_CODE 0x00010000
341 f5c848ee Jan Kiszka
342 9349b4f9 Andreas Färber
void cpu_dump_state(CPUArchState *env, FILE *f, fprintf_function cpu_fprintf,
343 7fe48483 bellard
                    int flags);
344 9349b4f9 Andreas Färber
void cpu_dump_statistics(CPUArchState *env, FILE *f, fprintf_function cpu_fprintf,
345 9a78eead Stefan Weil
                         int flags);
346 7fe48483 bellard
347 9349b4f9 Andreas Färber
void QEMU_NORETURN cpu_abort(CPUArchState *env, const char *fmt, ...)
348 2c80e423 Stefan Weil
    GCC_FMT_ATTR(2, 3);
349 9349b4f9 Andreas Färber
extern CPUArchState *first_cpu;
350 9349b4f9 Andreas Färber
DECLARE_TLS(CPUArchState *,cpu_single_env);
351 4a2dd92d Jan Kiszka
#define cpu_single_env tls_var(cpu_single_env)
352 db1a4972 Paolo Bonzini
353 9c76219e Richard Henderson
/* Flags for use in ENV->INTERRUPT_PENDING.
354 9c76219e Richard Henderson

355 9c76219e Richard Henderson
   The numbers assigned here are non-sequential in order to preserve
356 9c76219e Richard Henderson
   binary compatibility with the vmstate dump.  Bit 0 (0x0001) was
357 9c76219e Richard Henderson
   previously used for CPU_INTERRUPT_EXIT, and is cleared when loading
358 9c76219e Richard Henderson
   the vmstate dump.  */
359 9c76219e Richard Henderson
360 9c76219e Richard Henderson
/* External hardware interrupt pending.  This is typically used for
361 9c76219e Richard Henderson
   interrupts from devices.  */
362 9c76219e Richard Henderson
#define CPU_INTERRUPT_HARD        0x0002
363 9c76219e Richard Henderson
364 9c76219e Richard Henderson
/* Exit the current TB.  This is typically used when some system-level device
365 9c76219e Richard Henderson
   makes some change to the memory mapping.  E.g. the a20 line change.  */
366 9c76219e Richard Henderson
#define CPU_INTERRUPT_EXITTB      0x0004
367 9c76219e Richard Henderson
368 9c76219e Richard Henderson
/* Halt the CPU.  */
369 9c76219e Richard Henderson
#define CPU_INTERRUPT_HALT        0x0020
370 9c76219e Richard Henderson
371 9c76219e Richard Henderson
/* Debug event pending.  */
372 9c76219e Richard Henderson
#define CPU_INTERRUPT_DEBUG       0x0080
373 9c76219e Richard Henderson
374 9c76219e Richard Henderson
/* Several target-specific external hardware interrupts.  Each target/cpu.h
375 9c76219e Richard Henderson
   should define proper names based on these defines.  */
376 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_EXT_0   0x0008
377 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_EXT_1   0x0010
378 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_EXT_2   0x0040
379 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_EXT_3   0x0200
380 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_EXT_4   0x1000
381 9c76219e Richard Henderson
382 9c76219e Richard Henderson
/* Several target-specific internal interrupts.  These differ from the
383 07f35073 Dong Xu Wang
   preceding target-specific interrupts in that they are intended to
384 9c76219e Richard Henderson
   originate from within the cpu itself, typically in response to some
385 9c76219e Richard Henderson
   instruction being executed.  These, therefore, are not masked while
386 9c76219e Richard Henderson
   single-stepping within the debugger.  */
387 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_INT_0   0x0100
388 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_INT_1   0x0400
389 9c76219e Richard Henderson
#define CPU_INTERRUPT_TGT_INT_2   0x0800
390 d362e757 Jan Kiszka
#define CPU_INTERRUPT_TGT_INT_3   0x2000
391 9c76219e Richard Henderson
392 d362e757 Jan Kiszka
/* First unused bit: 0x4000.  */
393 9c76219e Richard Henderson
394 3125f763 Richard Henderson
/* The set of all bits that should be masked when single-stepping.  */
395 3125f763 Richard Henderson
#define CPU_INTERRUPT_SSTEP_MASK \
396 3125f763 Richard Henderson
    (CPU_INTERRUPT_HARD          \
397 3125f763 Richard Henderson
     | CPU_INTERRUPT_TGT_EXT_0   \
398 3125f763 Richard Henderson
     | CPU_INTERRUPT_TGT_EXT_1   \
399 3125f763 Richard Henderson
     | CPU_INTERRUPT_TGT_EXT_2   \
400 3125f763 Richard Henderson
     | CPU_INTERRUPT_TGT_EXT_3   \
401 3125f763 Richard Henderson
     | CPU_INTERRUPT_TGT_EXT_4)
402 98699967 bellard
403 ec6959d0 Jan Kiszka
#ifndef CONFIG_USER_ONLY
404 9349b4f9 Andreas Färber
typedef void (*CPUInterruptHandler)(CPUArchState *, int);
405 ec6959d0 Jan Kiszka
406 ec6959d0 Jan Kiszka
extern CPUInterruptHandler cpu_interrupt_handler;
407 ec6959d0 Jan Kiszka
408 9349b4f9 Andreas Färber
static inline void cpu_interrupt(CPUArchState *s, int mask)
409 ec6959d0 Jan Kiszka
{
410 ec6959d0 Jan Kiszka
    cpu_interrupt_handler(s, mask);
411 ec6959d0 Jan Kiszka
}
412 ec6959d0 Jan Kiszka
#else /* USER_ONLY */
413 9349b4f9 Andreas Färber
void cpu_interrupt(CPUArchState *env, int mask);
414 ec6959d0 Jan Kiszka
#endif /* USER_ONLY */
415 ec6959d0 Jan Kiszka
416 9349b4f9 Andreas Färber
void cpu_reset_interrupt(CPUArchState *env, int mask);
417 68a79315 bellard
418 9349b4f9 Andreas Färber
void cpu_exit(CPUArchState *s);
419 3098dba0 aurel32
420 9349b4f9 Andreas Färber
bool qemu_cpu_has_work(CPUArchState *env);
421 6a4955a8 aliguori
422 a1d1bb31 aliguori
/* Breakpoint/watchpoint flags */
423 a1d1bb31 aliguori
#define BP_MEM_READ           0x01
424 a1d1bb31 aliguori
#define BP_MEM_WRITE          0x02
425 a1d1bb31 aliguori
#define BP_MEM_ACCESS         (BP_MEM_READ | BP_MEM_WRITE)
426 06d55cc1 aliguori
#define BP_STOP_BEFORE_ACCESS 0x04
427 6e140f28 aliguori
#define BP_WATCHPOINT_HIT     0x08
428 a1d1bb31 aliguori
#define BP_GDB                0x10
429 2dc9f411 aliguori
#define BP_CPU                0x20
430 a1d1bb31 aliguori
431 9349b4f9 Andreas Färber
int cpu_breakpoint_insert(CPUArchState *env, target_ulong pc, int flags,
432 a1d1bb31 aliguori
                          CPUBreakpoint **breakpoint);
433 9349b4f9 Andreas Färber
int cpu_breakpoint_remove(CPUArchState *env, target_ulong pc, int flags);
434 9349b4f9 Andreas Färber
void cpu_breakpoint_remove_by_ref(CPUArchState *env, CPUBreakpoint *breakpoint);
435 9349b4f9 Andreas Färber
void cpu_breakpoint_remove_all(CPUArchState *env, int mask);
436 9349b4f9 Andreas Färber
int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_ulong len,
437 a1d1bb31 aliguori
                          int flags, CPUWatchpoint **watchpoint);
438 9349b4f9 Andreas Färber
int cpu_watchpoint_remove(CPUArchState *env, target_ulong addr,
439 a1d1bb31 aliguori
                          target_ulong len, int flags);
440 9349b4f9 Andreas Färber
void cpu_watchpoint_remove_by_ref(CPUArchState *env, CPUWatchpoint *watchpoint);
441 9349b4f9 Andreas Färber
void cpu_watchpoint_remove_all(CPUArchState *env, int mask);
442 60897d36 edgar_igl
443 60897d36 edgar_igl
#define SSTEP_ENABLE  0x1  /* Enable simulated HW single stepping */
444 60897d36 edgar_igl
#define SSTEP_NOIRQ   0x2  /* Do not use IRQ while single stepping */
445 60897d36 edgar_igl
#define SSTEP_NOTIMER 0x4  /* Do not Timers while single stepping */
446 60897d36 edgar_igl
447 9349b4f9 Andreas Färber
void cpu_single_step(CPUArchState *env, int enabled);
448 9349b4f9 Andreas Färber
int cpu_is_stopped(CPUArchState *env);
449 9349b4f9 Andreas Färber
void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data);
450 4c3a88a2 bellard
451 5fafdf24 ths
#define CPU_LOG_TB_OUT_ASM (1 << 0)
452 9fddaa0c bellard
#define CPU_LOG_TB_IN_ASM  (1 << 1)
453 f193c797 bellard
#define CPU_LOG_TB_OP      (1 << 2)
454 f193c797 bellard
#define CPU_LOG_TB_OP_OPT  (1 << 3)
455 f193c797 bellard
#define CPU_LOG_INT        (1 << 4)
456 f193c797 bellard
#define CPU_LOG_EXEC       (1 << 5)
457 f193c797 bellard
#define CPU_LOG_PCALL      (1 << 6)
458 fd872598 bellard
#define CPU_LOG_IOPORT     (1 << 7)
459 9fddaa0c bellard
#define CPU_LOG_TB_CPU     (1 << 8)
460 eca1bdf4 aliguori
#define CPU_LOG_RESET      (1 << 9)
461 f193c797 bellard
462 f193c797 bellard
/* define log items */
463 f193c797 bellard
typedef struct CPULogItem {
464 f193c797 bellard
    int mask;
465 f193c797 bellard
    const char *name;
466 f193c797 bellard
    const char *help;
467 f193c797 bellard
} CPULogItem;
468 f193c797 bellard
469 c7cd6a37 blueswir1
extern const CPULogItem cpu_log_items[];
470 f193c797 bellard
471 34865134 bellard
void cpu_set_log(int log_flags);
472 34865134 bellard
void cpu_set_log_filename(const char *filename);
473 f193c797 bellard
int cpu_str_to_log_mask(const char *str);
474 34865134 bellard
475 b3755a91 Paul Brook
#if !defined(CONFIG_USER_ONLY)
476 b3755a91 Paul Brook
477 4fcc562b Paul Brook
/* Return the physical page corresponding to a virtual one. Use it
478 4fcc562b Paul Brook
   only for debugging because no protection checks are done. Return -1
479 4fcc562b Paul Brook
   if no page found. */
480 9349b4f9 Andreas Färber
target_phys_addr_t cpu_get_phys_page_debug(CPUArchState *env, target_ulong addr);
481 4fcc562b Paul Brook
482 33417e70 bellard
/* memory API */
483 33417e70 bellard
484 edf75d59 bellard
extern int phys_ram_fd;
485 c227f099 Anthony Liguori
extern ram_addr_t ram_size;
486 f471a17e Alex Williamson
487 cd19cfa2 Huang Ying
/* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */
488 cd19cfa2 Huang Ying
#define RAM_PREALLOC_MASK   (1 << 0)
489 cd19cfa2 Huang Ying
490 f471a17e Alex Williamson
typedef struct RAMBlock {
491 7c637366 Avi Kivity
    struct MemoryRegion *mr;
492 f471a17e Alex Williamson
    uint8_t *host;
493 f471a17e Alex Williamson
    ram_addr_t offset;
494 f471a17e Alex Williamson
    ram_addr_t length;
495 cd19cfa2 Huang Ying
    uint32_t flags;
496 cc9e98cb Alex Williamson
    char idstr[256];
497 f471a17e Alex Williamson
    QLIST_ENTRY(RAMBlock) next;
498 04b16653 Alex Williamson
#if defined(__linux__) && !defined(TARGET_S390X)
499 04b16653 Alex Williamson
    int fd;
500 04b16653 Alex Williamson
#endif
501 f471a17e Alex Williamson
} RAMBlock;
502 f471a17e Alex Williamson
503 f471a17e Alex Williamson
typedef struct RAMList {
504 f471a17e Alex Williamson
    uint8_t *phys_dirty;
505 85d59fef Paolo Bonzini
    QLIST_HEAD(, RAMBlock) blocks;
506 f471a17e Alex Williamson
} RAMList;
507 f471a17e Alex Williamson
extern RAMList ram_list;
508 edf75d59 bellard
509 c902760f Marcelo Tosatti
extern const char *mem_path;
510 c902760f Marcelo Tosatti
extern int mem_prealloc;
511 c902760f Marcelo Tosatti
512 0f459d16 pbrook
/* Flags stored in the low bits of the TLB virtual address.  These are
513 0f459d16 pbrook
   defined so that fast path ram access is all zeros.  */
514 0f459d16 pbrook
/* Zero if TLB entry is valid.  */
515 0f459d16 pbrook
#define TLB_INVALID_MASK   (1 << 3)
516 0f459d16 pbrook
/* Set if TLB entry references a clean RAM page.  The iotlb entry will
517 0f459d16 pbrook
   contain the page physical address.  */
518 0f459d16 pbrook
#define TLB_NOTDIRTY    (1 << 4)
519 0f459d16 pbrook
/* Set if TLB entry is an IO callback.  */
520 0f459d16 pbrook
#define TLB_MMIO        (1 << 5)
521 0f459d16 pbrook
522 055403b2 Stefan Weil
void dump_exec_info(FILE *f, fprintf_function cpu_fprintf);
523 b3755a91 Paul Brook
#endif /* !CONFIG_USER_ONLY */
524 b3755a91 Paul Brook
525 9349b4f9 Andreas Färber
int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
526 b3755a91 Paul Brook
                        uint8_t *buf, int len, int is_write);
527 b3755a91 Paul Brook
528 fae001f5 Wen Congyang
#if defined(CONFIG_HAVE_GET_MEMORY_MAPPING)
529 fae001f5 Wen Congyang
int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env);
530 31a2207a Wen Congyang
bool cpu_paging_enabled(CPUArchState *env);
531 fae001f5 Wen Congyang
#else
532 fae001f5 Wen Congyang
static inline int cpu_get_memory_mapping(MemoryMappingList *list,
533 fae001f5 Wen Congyang
                                         CPUArchState *env)
534 fae001f5 Wen Congyang
{
535 fae001f5 Wen Congyang
    return -1;
536 fae001f5 Wen Congyang
}
537 31a2207a Wen Congyang
538 31a2207a Wen Congyang
static inline bool cpu_paging_enabled(CPUArchState *env)
539 31a2207a Wen Congyang
{
540 31a2207a Wen Congyang
    return true;
541 31a2207a Wen Congyang
}
542 fae001f5 Wen Congyang
#endif
543 fae001f5 Wen Congyang
544 9fecbed0 Wen Congyang
typedef int (*write_core_dump_function)(void *buf, size_t size, void *opaque);
545 9fecbed0 Wen Congyang
#if defined(CONFIG_HAVE_CORE_DUMP)
546 9fecbed0 Wen Congyang
int cpu_write_elf64_note(write_core_dump_function f, CPUArchState *env,
547 9fecbed0 Wen Congyang
                         int cpuid, void *opaque);
548 9fecbed0 Wen Congyang
int cpu_write_elf32_note(write_core_dump_function f, CPUArchState *env,
549 9fecbed0 Wen Congyang
                         int cpuid, void *opaque);
550 90166b71 Wen Congyang
int cpu_write_elf64_qemunote(write_core_dump_function f, CPUArchState *env,
551 90166b71 Wen Congyang
                             void *opaque);
552 90166b71 Wen Congyang
int cpu_write_elf32_qemunote(write_core_dump_function f, CPUArchState *env,
553 90166b71 Wen Congyang
                             void *opaque);
554 25ae9c1d Wen Congyang
int cpu_get_dump_info(ArchDumpInfo *info);
555 0038ffb0 Wen Congyang
size_t cpu_get_note_size(int class, int machine, int nr_cpus);
556 9fecbed0 Wen Congyang
#else
557 9fecbed0 Wen Congyang
static inline int cpu_write_elf64_note(write_core_dump_function f,
558 9fecbed0 Wen Congyang
                                       CPUArchState *env, int cpuid,
559 9fecbed0 Wen Congyang
                                       void *opaque)
560 9fecbed0 Wen Congyang
{
561 9fecbed0 Wen Congyang
    return -1;
562 9fecbed0 Wen Congyang
}
563 9fecbed0 Wen Congyang
564 9fecbed0 Wen Congyang
static inline int cpu_write_elf32_note(write_core_dump_function f,
565 9fecbed0 Wen Congyang
                                       CPUArchState *env, int cpuid,
566 9fecbed0 Wen Congyang
                                       void *opaque)
567 9fecbed0 Wen Congyang
{
568 9fecbed0 Wen Congyang
    return -1;
569 9fecbed0 Wen Congyang
}
570 90166b71 Wen Congyang
571 90166b71 Wen Congyang
static inline int cpu_write_elf64_qemunote(write_core_dump_function f,
572 90166b71 Wen Congyang
                                           CPUArchState *env,
573 90166b71 Wen Congyang
                                           void *opaque)
574 90166b71 Wen Congyang
{
575 90166b71 Wen Congyang
    return -1;
576 90166b71 Wen Congyang
}
577 90166b71 Wen Congyang
578 90166b71 Wen Congyang
static inline int cpu_write_elf32_qemunote(write_core_dump_function f,
579 90166b71 Wen Congyang
                                           CPUArchState *env,
580 90166b71 Wen Congyang
                                           void *opaque)
581 90166b71 Wen Congyang
{
582 90166b71 Wen Congyang
    return -1;
583 90166b71 Wen Congyang
}
584 25ae9c1d Wen Congyang
585 25ae9c1d Wen Congyang
static inline int cpu_get_dump_info(ArchDumpInfo *info)
586 25ae9c1d Wen Congyang
{
587 25ae9c1d Wen Congyang
    return -1;
588 25ae9c1d Wen Congyang
}
589 0038ffb0 Wen Congyang
590 0038ffb0 Wen Congyang
static inline int cpu_get_note_size(int class, int machine, int nr_cpus)
591 0038ffb0 Wen Congyang
{
592 0038ffb0 Wen Congyang
    return -1;
593 0038ffb0 Wen Congyang
}
594 9fecbed0 Wen Congyang
#endif
595 9fecbed0 Wen Congyang
596 5a9fdfec bellard
#endif /* CPU_ALL_H */