migration/rdma: Clean up qemu_rdma_poll()'s return type
[qemu/armbru.git] / include / exec / cpu-all.h
blob5340907cfd051c21c3cf08006b7c91bac695ff8f
1 /*
2 * defines common to all virtual CPUs
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #ifndef CPU_ALL_H
20 #define CPU_ALL_H
22 #include "exec/cpu-common.h"
23 #include "exec/memory.h"
24 #include "exec/tswap.h"
25 #include "qemu/thread.h"
26 #include "hw/core/cpu.h"
27 #include "qemu/rcu.h"
29 /* some important defines:
31 * HOST_BIG_ENDIAN : whether the host cpu is big endian and
32 * otherwise little endian.
34 * TARGET_BIG_ENDIAN : same for the target cpu
37 #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
38 #define BSWAP_NEEDED
39 #endif
41 #if TARGET_LONG_SIZE == 4
42 #define tswapl(s) tswap32(s)
43 #define tswapls(s) tswap32s((uint32_t *)(s))
44 #define bswaptls(s) bswap32s(s)
45 #else
46 #define tswapl(s) tswap64(s)
47 #define tswapls(s) tswap64s((uint64_t *)(s))
48 #define bswaptls(s) bswap64s(s)
49 #endif
51 /* Target-endianness CPU memory access functions. These fit into the
52 * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
54 #if TARGET_BIG_ENDIAN
55 #define lduw_p(p) lduw_be_p(p)
56 #define ldsw_p(p) ldsw_be_p(p)
57 #define ldl_p(p) ldl_be_p(p)
58 #define ldq_p(p) ldq_be_p(p)
59 #define stw_p(p, v) stw_be_p(p, v)
60 #define stl_p(p, v) stl_be_p(p, v)
61 #define stq_p(p, v) stq_be_p(p, v)
62 #define ldn_p(p, sz) ldn_be_p(p, sz)
63 #define stn_p(p, sz, v) stn_be_p(p, sz, v)
64 #else
65 #define lduw_p(p) lduw_le_p(p)
66 #define ldsw_p(p) ldsw_le_p(p)
67 #define ldl_p(p) ldl_le_p(p)
68 #define ldq_p(p) ldq_le_p(p)
69 #define stw_p(p, v) stw_le_p(p, v)
70 #define stl_p(p, v) stl_le_p(p, v)
71 #define stq_p(p, v) stq_le_p(p, v)
72 #define ldn_p(p, sz) ldn_le_p(p, sz)
73 #define stn_p(p, sz, v) stn_le_p(p, sz, v)
74 #endif
76 /* MMU memory access macros */
78 #if defined(CONFIG_USER_ONLY)
79 #include "exec/user/abitypes.h"
80 #include "exec/user/guest-base.h"
82 extern bool have_guest_base;
85 * If non-zero, the guest virtual address space is a contiguous subset
86 * of the host virtual address space, i.e. '-R reserved_va' is in effect
87 * either from the command-line or by default. The value is the last
88 * byte of the guest address space e.g. UINT32_MAX.
90 * If zero, the host and guest virtual address spaces are intermingled.
92 extern unsigned long reserved_va;
95 * Limit the guest addresses as best we can.
97 * When not using -R reserved_va, we cannot really limit the guest
98 * to less address space than the host. For 32-bit guests, this
99 * acts as a sanity check that we're not giving the guest an address
100 * that it cannot even represent. For 64-bit guests... the address
101 * might not be what the real kernel would give, but it is at least
102 * representable in the guest.
104 * TODO: Improve address allocation to avoid this problem, and to
105 * avoid setting bits at the top of guest addresses that might need
106 * to be used for tags.
108 #define GUEST_ADDR_MAX_ \
109 ((MIN_CONST(TARGET_VIRT_ADDR_SPACE_BITS, TARGET_ABI_BITS) <= 32) ? \
110 UINT32_MAX : ~0ul)
111 #define GUEST_ADDR_MAX (reserved_va ? : GUEST_ADDR_MAX_)
113 #else
115 #include "exec/hwaddr.h"
117 #define SUFFIX
118 #define ARG1 as
119 #define ARG1_DECL AddressSpace *as
120 #define TARGET_ENDIANNESS
121 #include "exec/memory_ldst.h.inc"
123 #define SUFFIX _cached_slow
124 #define ARG1 cache
125 #define ARG1_DECL MemoryRegionCache *cache
126 #define TARGET_ENDIANNESS
127 #include "exec/memory_ldst.h.inc"
129 static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
131 address_space_stl_notdirty(as, addr, val,
132 MEMTXATTRS_UNSPECIFIED, NULL);
135 #define SUFFIX
136 #define ARG1 as
137 #define ARG1_DECL AddressSpace *as
138 #define TARGET_ENDIANNESS
139 #include "exec/memory_ldst_phys.h.inc"
141 /* Inline fast path for direct RAM access. */
142 #define ENDIANNESS
143 #include "exec/memory_ldst_cached.h.inc"
145 #define SUFFIX _cached
146 #define ARG1 cache
147 #define ARG1_DECL MemoryRegionCache *cache
148 #define TARGET_ENDIANNESS
149 #include "exec/memory_ldst_phys.h.inc"
150 #endif
152 /* page related stuff */
154 #ifdef TARGET_PAGE_BITS_VARY
155 # include "exec/page-vary.h"
156 extern const TargetPageBits target_page;
157 #ifdef CONFIG_DEBUG_TCG
158 #define TARGET_PAGE_BITS ({ assert(target_page.decided); target_page.bits; })
159 #define TARGET_PAGE_MASK ({ assert(target_page.decided); \
160 (target_long)target_page.mask; })
161 #else
162 #define TARGET_PAGE_BITS target_page.bits
163 #define TARGET_PAGE_MASK ((target_long)target_page.mask)
164 #endif
165 #define TARGET_PAGE_SIZE (-(int)TARGET_PAGE_MASK)
166 #else
167 #define TARGET_PAGE_BITS_MIN TARGET_PAGE_BITS
168 #define TARGET_PAGE_SIZE (1 << TARGET_PAGE_BITS)
169 #define TARGET_PAGE_MASK ((target_long)-1 << TARGET_PAGE_BITS)
170 #endif
172 #define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
174 /* same as PROT_xxx */
175 #define PAGE_READ 0x0001
176 #define PAGE_WRITE 0x0002
177 #define PAGE_EXEC 0x0004
178 #define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
179 #define PAGE_VALID 0x0008
181 * Original state of the write flag (used when tracking self-modifying code)
183 #define PAGE_WRITE_ORG 0x0010
185 * Invalidate the TLB entry immediately, helpful for s390x
186 * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs()
188 #define PAGE_WRITE_INV 0x0020
189 /* For use with page_set_flags: page is being replaced; target_data cleared. */
190 #define PAGE_RESET 0x0040
191 /* For linux-user, indicates that the page is MAP_ANON. */
192 #define PAGE_ANON 0x0080
194 #if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
195 /* FIXME: Code that sets/uses this is broken and needs to go away. */
196 #define PAGE_RESERVED 0x0100
197 #endif
198 /* Target-specific bits that will be used via page_get_flags(). */
199 #define PAGE_TARGET_1 0x0200
200 #define PAGE_TARGET_2 0x0400
203 * For linux-user, indicates that the page is mapped with the same semantics
204 * in both guest and host.
206 #define PAGE_PASSTHROUGH 0x0800
208 #if defined(CONFIG_USER_ONLY)
209 void page_dump(FILE *f);
211 typedef int (*walk_memory_regions_fn)(void *, target_ulong,
212 target_ulong, unsigned long);
213 int walk_memory_regions(void *, walk_memory_regions_fn);
215 int page_get_flags(target_ulong address);
216 void page_set_flags(target_ulong start, target_ulong last, int flags);
217 void page_reset_target_data(target_ulong start, target_ulong last);
220 * page_check_range
221 * @start: first byte of range
222 * @len: length of range
223 * @flags: flags required for each page
225 * Return true if every page in [@start, @start+@len) has @flags set.
226 * Return false if any page is unmapped. Thus testing flags == 0 is
227 * equivalent to testing for flags == PAGE_VALID.
229 bool page_check_range(target_ulong start, target_ulong last, int flags);
232 * page_check_range_empty:
233 * @start: first byte of range
234 * @last: last byte of range
235 * Context: holding mmap lock
237 * Return true if the entire range [@start, @last] is unmapped.
238 * The memory lock must be held so that the caller will can ensure
239 * the result stays true until a new mapping can be installed.
241 bool page_check_range_empty(target_ulong start, target_ulong last);
244 * page_find_range_empty
245 * @min: first byte of search range
246 * @max: last byte of search range
247 * @len: size of the hole required
248 * @align: alignment of the hole required (power of 2)
250 * If there is a range [x, x+@len) within [@min, @max] such that
251 * x % @align == 0, then return x. Otherwise return -1.
252 * The memory lock must be held, as the caller will want to ensure
253 * the returned range stays empty until a new mapping can be installed.
255 target_ulong page_find_range_empty(target_ulong min, target_ulong max,
256 target_ulong len, target_ulong align);
259 * page_get_target_data(address)
260 * @address: guest virtual address
262 * Return TARGET_PAGE_DATA_SIZE bytes of out-of-band data to associate
263 * with the guest page at @address, allocating it if necessary. The
264 * caller should already have verified that the address is valid.
266 * The memory will be freed when the guest page is deallocated,
267 * e.g. with the munmap system call.
269 void *page_get_target_data(target_ulong address)
270 __attribute__((returns_nonnull));
271 #endif
273 CPUArchState *cpu_copy(CPUArchState *env);
275 /* Flags for use in ENV->INTERRUPT_PENDING.
277 The numbers assigned here are non-sequential in order to preserve
278 binary compatibility with the vmstate dump. Bit 0 (0x0001) was
279 previously used for CPU_INTERRUPT_EXIT, and is cleared when loading
280 the vmstate dump. */
282 /* External hardware interrupt pending. This is typically used for
283 interrupts from devices. */
284 #define CPU_INTERRUPT_HARD 0x0002
286 /* Exit the current TB. This is typically used when some system-level device
287 makes some change to the memory mapping. E.g. the a20 line change. */
288 #define CPU_INTERRUPT_EXITTB 0x0004
290 /* Halt the CPU. */
291 #define CPU_INTERRUPT_HALT 0x0020
293 /* Debug event pending. */
294 #define CPU_INTERRUPT_DEBUG 0x0080
296 /* Reset signal. */
297 #define CPU_INTERRUPT_RESET 0x0400
299 /* Several target-specific external hardware interrupts. Each target/cpu.h
300 should define proper names based on these defines. */
301 #define CPU_INTERRUPT_TGT_EXT_0 0x0008
302 #define CPU_INTERRUPT_TGT_EXT_1 0x0010
303 #define CPU_INTERRUPT_TGT_EXT_2 0x0040
304 #define CPU_INTERRUPT_TGT_EXT_3 0x0200
305 #define CPU_INTERRUPT_TGT_EXT_4 0x1000
307 /* Several target-specific internal interrupts. These differ from the
308 preceding target-specific interrupts in that they are intended to
309 originate from within the cpu itself, typically in response to some
310 instruction being executed. These, therefore, are not masked while
311 single-stepping within the debugger. */
312 #define CPU_INTERRUPT_TGT_INT_0 0x0100
313 #define CPU_INTERRUPT_TGT_INT_1 0x0800
314 #define CPU_INTERRUPT_TGT_INT_2 0x2000
316 /* First unused bit: 0x4000. */
318 /* The set of all bits that should be masked when single-stepping. */
319 #define CPU_INTERRUPT_SSTEP_MASK \
320 (CPU_INTERRUPT_HARD \
321 | CPU_INTERRUPT_TGT_EXT_0 \
322 | CPU_INTERRUPT_TGT_EXT_1 \
323 | CPU_INTERRUPT_TGT_EXT_2 \
324 | CPU_INTERRUPT_TGT_EXT_3 \
325 | CPU_INTERRUPT_TGT_EXT_4)
327 #ifdef CONFIG_USER_ONLY
330 * Allow some level of source compatibility with softmmu. We do not
331 * support any of the more exotic features, so only invalid pages may
332 * be signaled by probe_access_flags().
334 #define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1))
335 #define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 2))
336 #define TLB_WATCHPOINT 0
338 #else
341 * Flags stored in the low bits of the TLB virtual address.
342 * These are defined so that fast path ram access is all zeros.
343 * The flags all must be between TARGET_PAGE_BITS and
344 * maximum address alignment bit.
346 * Use TARGET_PAGE_BITS_MIN so that these bits are constant
347 * when TARGET_PAGE_BITS_VARY is in effect.
349 * The count, if not the placement of these bits is known
350 * to tcg/tcg-op-ldst.c, check_max_alignment().
352 /* Zero if TLB entry is valid. */
353 #define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1))
354 /* Set if TLB entry references a clean RAM page. The iotlb entry will
355 contain the page physical address. */
356 #define TLB_NOTDIRTY (1 << (TARGET_PAGE_BITS_MIN - 2))
357 /* Set if TLB entry is an IO callback. */
358 #define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 3))
359 /* Set if TLB entry writes ignored. */
360 #define TLB_DISCARD_WRITE (1 << (TARGET_PAGE_BITS_MIN - 4))
361 /* Set if the slow path must be used; more flags in CPUTLBEntryFull. */
362 #define TLB_FORCE_SLOW (1 << (TARGET_PAGE_BITS_MIN - 5))
365 * Use this mask to check interception with an alignment mask
366 * in a TCG backend.
368 #define TLB_FLAGS_MASK \
369 (TLB_INVALID_MASK | TLB_NOTDIRTY | TLB_MMIO \
370 | TLB_FORCE_SLOW | TLB_DISCARD_WRITE)
373 * Flags stored in CPUTLBEntryFull.slow_flags[x].
374 * TLB_FORCE_SLOW must be set in CPUTLBEntry.addr_idx[x].
376 /* Set if TLB entry requires byte swap. */
377 #define TLB_BSWAP (1 << 0)
378 /* Set if TLB entry contains a watchpoint. */
379 #define TLB_WATCHPOINT (1 << 1)
381 #define TLB_SLOW_FLAGS_MASK (TLB_BSWAP | TLB_WATCHPOINT)
383 /* The two sets of flags must not overlap. */
384 QEMU_BUILD_BUG_ON(TLB_FLAGS_MASK & TLB_SLOW_FLAGS_MASK);
387 * tlb_hit_page: return true if page aligned @addr is a hit against the
388 * TLB entry @tlb_addr
390 * @addr: virtual address to test (must be page aligned)
391 * @tlb_addr: TLB entry address (a CPUTLBEntry addr_read/write/code value)
393 static inline bool tlb_hit_page(uint64_t tlb_addr, vaddr addr)
395 return addr == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK));
399 * tlb_hit: return true if @addr is a hit against the TLB entry @tlb_addr
401 * @addr: virtual address to test (need not be page aligned)
402 * @tlb_addr: TLB entry address (a CPUTLBEntry addr_read/write/code value)
404 static inline bool tlb_hit(uint64_t tlb_addr, vaddr addr)
406 return tlb_hit_page(tlb_addr, addr & TARGET_PAGE_MASK);
409 #endif /* !CONFIG_USER_ONLY */
411 /* accel/tcg/cpu-exec.c */
412 int cpu_exec(CPUState *cpu);
414 /* Validate correct placement of CPUArchState. */
415 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
416 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
419 * env_archcpu(env)
420 * @env: The architecture environment
422 * Return the ArchCPU associated with the environment.
424 static inline ArchCPU *env_archcpu(CPUArchState *env)
426 return (void *)env - sizeof(CPUState);
430 * env_cpu(env)
431 * @env: The architecture environment
433 * Return the CPUState associated with the environment.
435 static inline CPUState *env_cpu(CPUArchState *env)
437 return (void *)env - sizeof(CPUState);
440 #endif /* CPU_ALL_H */