Merge tag 'v8.0.0-rc3'
[qemu/ar7.git] / include / exec / exec-all.h
blobb1a8d17b608522b64fa82827be0b718a24e5f66e
1 /*
2 * internal execution defines for qemu
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/>.
20 #ifndef EXEC_ALL_H
21 #define EXEC_ALL_H
23 #include "cpu.h"
24 #ifdef CONFIG_TCG
25 #include "exec/cpu_ldst.h"
26 #endif
27 #include "qemu/interval-tree.h"
28 #include "qemu/clang-tsa.h"
30 /* allow to see translation results - the slowdown should be negligible, so we leave it */
31 #define DEBUG_DISAS
33 /* Page tracking code uses ram addresses in system mode, and virtual
34 addresses in userspace mode. Define tb_page_addr_t to be an appropriate
35 type. */
36 #if defined(CONFIG_USER_ONLY)
37 typedef abi_ulong tb_page_addr_t;
38 #define TB_PAGE_ADDR_FMT TARGET_ABI_FMT_lx
39 #else
40 typedef ram_addr_t tb_page_addr_t;
41 #define TB_PAGE_ADDR_FMT RAM_ADDR_FMT
42 #endif
44 /* Get a backtrace for the guest code. */
45 const char *qemu_sprint_backtrace(char *buffer, size_t length);
47 /**
48 * cpu_unwind_state_data:
49 * @cpu: the cpu context
50 * @host_pc: the host pc within the translation
51 * @data: output data
53 * Attempt to load the the unwind state for a host pc occurring in
54 * translated code. If @host_pc is not in translated code, the
55 * function returns false; otherwise @data is loaded.
56 * This is the same unwind info as given to restore_state_to_opc.
58 bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data);
60 /**
61 * cpu_restore_state:
62 * @cpu: the cpu context
63 * @host_pc: the host pc within the translation
64 * @return: true if state was restored, false otherwise
66 * Attempt to restore the state for a fault occurring in translated
67 * code. If @host_pc is not in translated code no state is
68 * restored and the function returns false.
70 bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc);
72 G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
73 G_NORETURN void cpu_loop_exit(CPUState *cpu);
74 G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
75 G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
77 /**
78 * cpu_loop_exit_requested:
79 * @cpu: The CPU state to be tested
81 * Indicate if somebody asked for a return of the CPU to the main loop
82 * (e.g., via cpu_exit() or cpu_interrupt()).
84 * This is helpful for architectures that support interruptible
85 * instructions. After writing back all state to registers/memory, this
86 * call can be used to check if it makes sense to return to the main loop
87 * or to continue executing the interruptible instruction.
89 static inline bool cpu_loop_exit_requested(CPUState *cpu)
91 return (int32_t)qatomic_read(&cpu_neg(cpu)->icount_decr.u32) < 0;
94 #if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
95 /* cputlb.c */
96 /**
97 * tlb_init - initialize a CPU's TLB
98 * @cpu: CPU whose TLB should be initialized
100 void tlb_init(CPUState *cpu);
102 * tlb_destroy - destroy a CPU's TLB
103 * @cpu: CPU whose TLB should be destroyed
105 void tlb_destroy(CPUState *cpu);
107 * tlb_flush_page:
108 * @cpu: CPU whose TLB should be flushed
109 * @addr: virtual address of page to be flushed
111 * Flush one page from the TLB of the specified CPU, for all
112 * MMU indexes.
114 void tlb_flush_page(CPUState *cpu, target_ulong addr);
116 * tlb_flush_page_all_cpus:
117 * @cpu: src CPU of the flush
118 * @addr: virtual address of page to be flushed
120 * Flush one page from the TLB of the specified CPU, for all
121 * MMU indexes.
123 void tlb_flush_page_all_cpus(CPUState *src, target_ulong addr);
125 * tlb_flush_page_all_cpus_synced:
126 * @cpu: src CPU of the flush
127 * @addr: virtual address of page to be flushed
129 * Flush one page from the TLB of the specified CPU, for all MMU
130 * indexes like tlb_flush_page_all_cpus except the source vCPUs work
131 * is scheduled as safe work meaning all flushes will be complete once
132 * the source vCPUs safe work is complete. This will depend on when
133 * the guests translation ends the TB.
135 void tlb_flush_page_all_cpus_synced(CPUState *src, target_ulong addr);
137 * tlb_flush:
138 * @cpu: CPU whose TLB should be flushed
140 * Flush the entire TLB for the specified CPU. Most CPU architectures
141 * allow the implementation to drop entries from the TLB at any time
142 * so this is generally safe. If more selective flushing is required
143 * use one of the other functions for efficiency.
145 void tlb_flush(CPUState *cpu);
147 * tlb_flush_all_cpus:
148 * @cpu: src CPU of the flush
150 void tlb_flush_all_cpus(CPUState *src_cpu);
152 * tlb_flush_all_cpus_synced:
153 * @cpu: src CPU of the flush
155 * Like tlb_flush_all_cpus except this except the source vCPUs work is
156 * scheduled as safe work meaning all flushes will be complete once
157 * the source vCPUs safe work is complete. This will depend on when
158 * the guests translation ends the TB.
160 void tlb_flush_all_cpus_synced(CPUState *src_cpu);
162 * tlb_flush_page_by_mmuidx:
163 * @cpu: CPU whose TLB should be flushed
164 * @addr: virtual address of page to be flushed
165 * @idxmap: bitmap of MMU indexes to flush
167 * Flush one page from the TLB of the specified CPU, for the specified
168 * MMU indexes.
170 void tlb_flush_page_by_mmuidx(CPUState *cpu, target_ulong addr,
171 uint16_t idxmap);
173 * tlb_flush_page_by_mmuidx_all_cpus:
174 * @cpu: Originating CPU of the flush
175 * @addr: virtual address of page to be flushed
176 * @idxmap: bitmap of MMU indexes to flush
178 * Flush one page from the TLB of all CPUs, for the specified
179 * MMU indexes.
181 void tlb_flush_page_by_mmuidx_all_cpus(CPUState *cpu, target_ulong addr,
182 uint16_t idxmap);
184 * tlb_flush_page_by_mmuidx_all_cpus_synced:
185 * @cpu: Originating CPU of the flush
186 * @addr: virtual address of page to be flushed
187 * @idxmap: bitmap of MMU indexes to flush
189 * Flush one page from the TLB of all CPUs, for the specified MMU
190 * indexes like tlb_flush_page_by_mmuidx_all_cpus except the source
191 * vCPUs work is scheduled as safe work meaning all flushes will be
192 * complete once the source vCPUs safe work is complete. This will
193 * depend on when the guests translation ends the TB.
195 void tlb_flush_page_by_mmuidx_all_cpus_synced(CPUState *cpu, target_ulong addr,
196 uint16_t idxmap);
198 * tlb_flush_by_mmuidx:
199 * @cpu: CPU whose TLB should be flushed
200 * @wait: If true ensure synchronisation by exiting the cpu_loop
201 * @idxmap: bitmap of MMU indexes to flush
203 * Flush all entries from the TLB of the specified CPU, for the specified
204 * MMU indexes.
206 void tlb_flush_by_mmuidx(CPUState *cpu, uint16_t idxmap);
208 * tlb_flush_by_mmuidx_all_cpus:
209 * @cpu: Originating CPU of the flush
210 * @idxmap: bitmap of MMU indexes to flush
212 * Flush all entries from all TLBs of all CPUs, for the specified
213 * MMU indexes.
215 void tlb_flush_by_mmuidx_all_cpus(CPUState *cpu, uint16_t idxmap);
217 * tlb_flush_by_mmuidx_all_cpus_synced:
218 * @cpu: Originating CPU of the flush
219 * @idxmap: bitmap of MMU indexes to flush
221 * Flush all entries from all TLBs of all CPUs, for the specified
222 * MMU indexes like tlb_flush_by_mmuidx_all_cpus except except the source
223 * vCPUs work is scheduled as safe work meaning all flushes will be
224 * complete once the source vCPUs safe work is complete. This will
225 * depend on when the guests translation ends the TB.
227 void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *cpu, uint16_t idxmap);
230 * tlb_flush_page_bits_by_mmuidx
231 * @cpu: CPU whose TLB should be flushed
232 * @addr: virtual address of page to be flushed
233 * @idxmap: bitmap of mmu indexes to flush
234 * @bits: number of significant bits in address
236 * Similar to tlb_flush_page_mask, but with a bitmap of indexes.
238 void tlb_flush_page_bits_by_mmuidx(CPUState *cpu, target_ulong addr,
239 uint16_t idxmap, unsigned bits);
241 /* Similarly, with broadcast and syncing. */
242 void tlb_flush_page_bits_by_mmuidx_all_cpus(CPUState *cpu, target_ulong addr,
243 uint16_t idxmap, unsigned bits);
244 void tlb_flush_page_bits_by_mmuidx_all_cpus_synced
245 (CPUState *cpu, target_ulong addr, uint16_t idxmap, unsigned bits);
248 * tlb_flush_range_by_mmuidx
249 * @cpu: CPU whose TLB should be flushed
250 * @addr: virtual address of the start of the range to be flushed
251 * @len: length of range to be flushed
252 * @idxmap: bitmap of mmu indexes to flush
253 * @bits: number of significant bits in address
255 * For each mmuidx in @idxmap, flush all pages within [@addr,@addr+@len),
256 * comparing only the low @bits worth of each virtual page.
258 void tlb_flush_range_by_mmuidx(CPUState *cpu, target_ulong addr,
259 target_ulong len, uint16_t idxmap,
260 unsigned bits);
262 /* Similarly, with broadcast and syncing. */
263 void tlb_flush_range_by_mmuidx_all_cpus(CPUState *cpu, target_ulong addr,
264 target_ulong len, uint16_t idxmap,
265 unsigned bits);
266 void tlb_flush_range_by_mmuidx_all_cpus_synced(CPUState *cpu,
267 target_ulong addr,
268 target_ulong len,
269 uint16_t idxmap,
270 unsigned bits);
273 * tlb_set_page_full:
274 * @cpu: CPU context
275 * @mmu_idx: mmu index of the tlb to modify
276 * @vaddr: virtual address of the entry to add
277 * @full: the details of the tlb entry
279 * Add an entry to @cpu tlb index @mmu_idx. All of the fields of
280 * @full must be filled, except for xlat_section, and constitute
281 * the complete description of the translated page.
283 * This is generally called by the target tlb_fill function after
284 * having performed a successful page table walk to find the physical
285 * address and attributes for the translation.
287 * At most one entry for a given virtual address is permitted. Only a
288 * single TARGET_PAGE_SIZE region is mapped; @full->lg_page_size is only
289 * used by tlb_flush_page.
291 void tlb_set_page_full(CPUState *cpu, int mmu_idx, target_ulong vaddr,
292 CPUTLBEntryFull *full);
295 * tlb_set_page_with_attrs:
296 * @cpu: CPU to add this TLB entry for
297 * @vaddr: virtual address of page to add entry for
298 * @paddr: physical address of the page
299 * @attrs: memory transaction attributes
300 * @prot: access permissions (PAGE_READ/PAGE_WRITE/PAGE_EXEC bits)
301 * @mmu_idx: MMU index to insert TLB entry for
302 * @size: size of the page in bytes
304 * Add an entry to this CPU's TLB (a mapping from virtual address
305 * @vaddr to physical address @paddr) with the specified memory
306 * transaction attributes. This is generally called by the target CPU
307 * specific code after it has been called through the tlb_fill()
308 * entry point and performed a successful page table walk to find
309 * the physical address and attributes for the virtual address
310 * which provoked the TLB miss.
312 * At most one entry for a given virtual address is permitted. Only a
313 * single TARGET_PAGE_SIZE region is mapped; the supplied @size is only
314 * used by tlb_flush_page.
316 void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr,
317 hwaddr paddr, MemTxAttrs attrs,
318 int prot, int mmu_idx, target_ulong size);
319 /* tlb_set_page:
321 * This function is equivalent to calling tlb_set_page_with_attrs()
322 * with an @attrs argument of MEMTXATTRS_UNSPECIFIED. It's provided
323 * as a convenience for CPUs which don't use memory transaction attributes.
325 void tlb_set_page(CPUState *cpu, target_ulong vaddr,
326 hwaddr paddr, int prot,
327 int mmu_idx, target_ulong size);
328 #else
329 static inline void tlb_init(CPUState *cpu)
332 static inline void tlb_destroy(CPUState *cpu)
335 static inline void tlb_flush_page(CPUState *cpu, target_ulong addr)
338 static inline void tlb_flush_page_all_cpus(CPUState *src, target_ulong addr)
341 static inline void tlb_flush_page_all_cpus_synced(CPUState *src,
342 target_ulong addr)
345 static inline void tlb_flush(CPUState *cpu)
348 static inline void tlb_flush_all_cpus(CPUState *src_cpu)
351 static inline void tlb_flush_all_cpus_synced(CPUState *src_cpu)
354 static inline void tlb_flush_page_by_mmuidx(CPUState *cpu,
355 target_ulong addr, uint16_t idxmap)
359 static inline void tlb_flush_by_mmuidx(CPUState *cpu, uint16_t idxmap)
362 static inline void tlb_flush_page_by_mmuidx_all_cpus(CPUState *cpu,
363 target_ulong addr,
364 uint16_t idxmap)
367 static inline void tlb_flush_page_by_mmuidx_all_cpus_synced(CPUState *cpu,
368 target_ulong addr,
369 uint16_t idxmap)
372 static inline void tlb_flush_by_mmuidx_all_cpus(CPUState *cpu, uint16_t idxmap)
376 static inline void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *cpu,
377 uint16_t idxmap)
380 static inline void tlb_flush_page_bits_by_mmuidx(CPUState *cpu,
381 target_ulong addr,
382 uint16_t idxmap,
383 unsigned bits)
386 static inline void tlb_flush_page_bits_by_mmuidx_all_cpus(CPUState *cpu,
387 target_ulong addr,
388 uint16_t idxmap,
389 unsigned bits)
392 static inline void
393 tlb_flush_page_bits_by_mmuidx_all_cpus_synced(CPUState *cpu, target_ulong addr,
394 uint16_t idxmap, unsigned bits)
397 static inline void tlb_flush_range_by_mmuidx(CPUState *cpu, target_ulong addr,
398 target_ulong len, uint16_t idxmap,
399 unsigned bits)
402 static inline void tlb_flush_range_by_mmuidx_all_cpus(CPUState *cpu,
403 target_ulong addr,
404 target_ulong len,
405 uint16_t idxmap,
406 unsigned bits)
409 static inline void tlb_flush_range_by_mmuidx_all_cpus_synced(CPUState *cpu,
410 target_ulong addr,
411 target_long len,
412 uint16_t idxmap,
413 unsigned bits)
416 #endif
418 * probe_access:
419 * @env: CPUArchState
420 * @addr: guest virtual address to look up
421 * @size: size of the access
422 * @access_type: read, write or execute permission
423 * @mmu_idx: MMU index to use for lookup
424 * @retaddr: return address for unwinding
426 * Look up the guest virtual address @addr. Raise an exception if the
427 * page does not satisfy @access_type. Raise an exception if the
428 * access (@addr, @size) hits a watchpoint. For writes, mark a clean
429 * page as dirty.
431 * Finally, return the host address for a page that is backed by RAM,
432 * or NULL if the page requires I/O.
434 void *probe_access(CPUArchState *env, target_ulong addr, int size,
435 MMUAccessType access_type, int mmu_idx, uintptr_t retaddr);
437 static inline void *probe_write(CPUArchState *env, target_ulong addr, int size,
438 int mmu_idx, uintptr_t retaddr)
440 return probe_access(env, addr, size, MMU_DATA_STORE, mmu_idx, retaddr);
443 static inline void *probe_read(CPUArchState *env, target_ulong addr, int size,
444 int mmu_idx, uintptr_t retaddr)
446 return probe_access(env, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
450 * probe_access_flags:
451 * @env: CPUArchState
452 * @addr: guest virtual address to look up
453 * @size: size of the access
454 * @access_type: read, write or execute permission
455 * @mmu_idx: MMU index to use for lookup
456 * @nonfault: suppress the fault
457 * @phost: return value for host address
458 * @retaddr: return address for unwinding
460 * Similar to probe_access, loosely returning the TLB_FLAGS_MASK for
461 * the page, and storing the host address for RAM in @phost.
463 * If @nonfault is set, do not raise an exception but return TLB_INVALID_MASK.
464 * Do not handle watchpoints, but include TLB_WATCHPOINT in the returned flags.
465 * Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags.
466 * For simplicity, all "mmio-like" flags are folded to TLB_MMIO.
468 int probe_access_flags(CPUArchState *env, target_ulong addr, int size,
469 MMUAccessType access_type, int mmu_idx,
470 bool nonfault, void **phost, uintptr_t retaddr);
472 #ifndef CONFIG_USER_ONLY
474 * probe_access_full:
475 * Like probe_access_flags, except also return into @pfull.
477 * The CPUTLBEntryFull structure returned via @pfull is transient
478 * and must be consumed or copied immediately, before any further
479 * access or changes to TLB @mmu_idx.
481 int probe_access_full(CPUArchState *env, target_ulong addr, int size,
482 MMUAccessType access_type, int mmu_idx,
483 bool nonfault, void **phost,
484 CPUTLBEntryFull **pfull, uintptr_t retaddr);
485 #endif
487 #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */
489 /* Estimated block size for TB allocation. */
490 /* ??? The following is based on a 2015 survey of x86_64 host output.
491 Better would seem to be some sort of dynamically sized TB array,
492 adapting to the block sizes actually being produced. */
493 #if defined(CONFIG_SOFTMMU)
494 #define CODE_GEN_AVG_BLOCK_SIZE 400
495 #else
496 #define CODE_GEN_AVG_BLOCK_SIZE 150
497 #endif
500 * Translation Cache-related fields of a TB.
501 * This struct exists just for convenience; we keep track of TB's in a binary
502 * search tree, and the only fields needed to compare TB's in the tree are
503 * @ptr and @size.
504 * Note: the address of search data can be obtained by adding @size to @ptr.
506 struct tb_tc {
507 const void *ptr; /* pointer to the translated code */
508 size_t size;
511 struct TranslationBlock {
513 * Guest PC corresponding to this block. This must be the true
514 * virtual address. Therefore e.g. x86 stores EIP + CS_BASE, and
515 * targets like Arm, MIPS, HP-PA, which reuse low bits for ISA or
516 * privilege, must store those bits elsewhere.
518 * If CF_PCREL, the opcodes for the TranslationBlock are written
519 * such that the TB is associated only with the physical page and
520 * may be run in any virtual address context. In this case, PC
521 * must always be taken from ENV in a target-specific manner.
522 * Unwind information is taken as offsets from the page, to be
523 * deposited into the "current" PC.
525 target_ulong pc;
528 * Target-specific data associated with the TranslationBlock, e.g.:
529 * x86: the original user, the Code Segment virtual base,
530 * arm: an extension of tb->flags,
531 * s390x: instruction data for EXECUTE,
532 * sparc: the next pc of the instruction queue (for delay slots).
534 target_ulong cs_base;
536 uint32_t flags; /* flags defining in which context the code was generated */
537 uint32_t cflags; /* compile flags */
539 /* Note that TCG_MAX_INSNS is 512; we validate this match elsewhere. */
540 #define CF_COUNT_MASK 0x000001ff
541 #define CF_NO_GOTO_TB 0x00000200 /* Do not chain with goto_tb */
542 #define CF_NO_GOTO_PTR 0x00000400 /* Do not chain with goto_ptr */
543 #define CF_SINGLE_STEP 0x00000800 /* gdbstub single-step in effect */
544 #define CF_LAST_IO 0x00008000 /* Last insn may be an IO access. */
545 #define CF_MEMI_ONLY 0x00010000 /* Only instrument memory ops */
546 #define CF_USE_ICOUNT 0x00020000
547 #define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */
548 #define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */
549 #define CF_NOIRQ 0x00100000 /* Generate an uninterruptible TB */
550 #define CF_PCREL 0x00200000 /* Opcodes in TB are PC-relative */
551 #define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */
552 #define CF_CLUSTER_SHIFT 24
554 /* Per-vCPU dynamic tracing state used to generate this TB */
555 uint32_t trace_vcpu_dstate;
558 * Above fields used for comparing
561 /* size of target code for this block (1 <= size <= TARGET_PAGE_SIZE) */
562 uint16_t size;
563 uint16_t icount;
565 struct tb_tc tc;
568 * Track tb_page_addr_t intervals that intersect this TB.
569 * For user-only, the virtual addresses are always contiguous,
570 * and we use a unified interval tree. For system, we use a
571 * linked list headed in each PageDesc. Within the list, the lsb
572 * of the previous pointer tells the index of page_next[], and the
573 * list is protected by the PageDesc lock(s).
575 #ifdef CONFIG_USER_ONLY
576 IntervalTreeNode itree;
577 #else
578 uintptr_t page_next[2];
579 tb_page_addr_t page_addr[2];
580 #endif
582 /* jmp_lock placed here to fill a 4-byte hole. Its documentation is below */
583 QemuSpin jmp_lock;
585 /* The following data are used to directly call another TB from
586 * the code of this one. This can be done either by emitting direct or
587 * indirect native jump instructions. These jumps are reset so that the TB
588 * just continues its execution. The TB can be linked to another one by
589 * setting one of the jump targets (or patching the jump instruction). Only
590 * two of such jumps are supported.
592 #define TB_JMP_OFFSET_INVALID 0xffff /* indicates no jump generated */
593 uint16_t jmp_reset_offset[2]; /* offset of original jump target */
594 uint16_t jmp_insn_offset[2]; /* offset of direct jump insn */
595 uintptr_t jmp_target_addr[2]; /* target address */
598 * Each TB has a NULL-terminated list (jmp_list_head) of incoming jumps.
599 * Each TB can have two outgoing jumps, and therefore can participate
600 * in two lists. The list entries are kept in jmp_list_next[2]. The least
601 * significant bit (LSB) of the pointers in these lists is used to encode
602 * which of the two list entries is to be used in the pointed TB.
604 * List traversals are protected by jmp_lock. The destination TB of each
605 * outgoing jump is kept in jmp_dest[] so that the appropriate jmp_lock
606 * can be acquired from any origin TB.
608 * jmp_dest[] are tagged pointers as well. The LSB is set when the TB is
609 * being invalidated, so that no further outgoing jumps from it can be set.
611 * jmp_lock also protects the CF_INVALID cflag; a jump must not be chained
612 * to a destination TB that has CF_INVALID set.
614 uintptr_t jmp_list_head;
615 uintptr_t jmp_list_next[2];
616 uintptr_t jmp_dest[2];
619 /* Hide the qatomic_read to make code a little easier on the eyes */
620 static inline uint32_t tb_cflags(const TranslationBlock *tb)
622 return qatomic_read(&tb->cflags);
625 static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb)
627 #ifdef CONFIG_USER_ONLY
628 return tb->itree.start;
629 #else
630 return tb->page_addr[0];
631 #endif
634 static inline tb_page_addr_t tb_page_addr1(const TranslationBlock *tb)
636 #ifdef CONFIG_USER_ONLY
637 tb_page_addr_t next = tb->itree.last & TARGET_PAGE_MASK;
638 return next == (tb->itree.start & TARGET_PAGE_MASK) ? -1 : next;
639 #else
640 return tb->page_addr[1];
641 #endif
644 static inline void tb_set_page_addr0(TranslationBlock *tb,
645 tb_page_addr_t addr)
647 #ifdef CONFIG_USER_ONLY
648 tb->itree.start = addr;
650 * To begin, we record an interval of one byte. When the translation
651 * loop encounters a second page, the interval will be extended to
652 * include the first byte of the second page, which is sufficient to
653 * allow tb_page_addr1() above to work properly. The final corrected
654 * interval will be set by tb_page_add() from tb->size before the
655 * node is added to the interval tree.
657 tb->itree.last = addr;
658 #else
659 tb->page_addr[0] = addr;
660 #endif
663 static inline void tb_set_page_addr1(TranslationBlock *tb,
664 tb_page_addr_t addr)
666 #ifdef CONFIG_USER_ONLY
667 /* Extend the interval to the first byte of the second page. See above. */
668 tb->itree.last = addr;
669 #else
670 tb->page_addr[1] = addr;
671 #endif
674 /* current cflags for hashing/comparison */
675 uint32_t curr_cflags(CPUState *cpu);
677 /* TranslationBlock invalidate API */
678 #if defined(CONFIG_USER_ONLY)
679 void tb_invalidate_phys_addr(target_ulong addr);
680 #else
681 void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs);
682 #endif
683 void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr);
684 void tb_invalidate_phys_range(tb_page_addr_t start, tb_page_addr_t last);
685 void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
687 /* GETPC is the true target of the return instruction that we'll execute. */
688 #if defined(CONFIG_TCG_INTERPRETER)
689 extern __thread uintptr_t tci_tb_ptr;
690 # define GETPC() tci_tb_ptr
691 #else
692 # define GETPC() \
693 ((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
694 #endif
696 /* The true return address will often point to a host insn that is part of
697 the next translated guest insn. Adjust the address backward to point to
698 the middle of the call insn. Subtracting one would do the job except for
699 several compressed mode architectures (arm, mips) which set the low bit
700 to indicate the compressed mode; subtracting two works around that. It
701 is also the case that there are no host isas that contain a call insn
702 smaller than 4 bytes, so we don't worry about special-casing this. */
703 #define GETPC_ADJ 2
705 #if !defined(CONFIG_USER_ONLY)
708 * iotlb_to_section:
709 * @cpu: CPU performing the access
710 * @index: TCG CPU IOTLB entry
712 * Given a TCG CPU IOTLB entry, return the MemoryRegionSection that
713 * it refers to. @index will have been initially created and returned
714 * by memory_region_section_get_iotlb().
716 struct MemoryRegionSection *iotlb_to_section(CPUState *cpu,
717 hwaddr index, MemTxAttrs attrs);
718 #endif
721 * get_page_addr_code_hostp()
722 * @env: CPUArchState
723 * @addr: guest virtual address of guest code
725 * See get_page_addr_code() (full-system version) for documentation on the
726 * return value.
728 * Sets *@hostp (when @hostp is non-NULL) as follows.
729 * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp
730 * to the host address where @addr's content is kept.
732 * Note: this function can trigger an exception.
734 tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr,
735 void **hostp);
738 * get_page_addr_code()
739 * @env: CPUArchState
740 * @addr: guest virtual address of guest code
742 * If we cannot translate and execute from the entire RAM page, or if
743 * the region is not backed by RAM, returns -1. Otherwise, returns the
744 * ram_addr_t corresponding to the guest code at @addr.
746 * Note: this function can trigger an exception.
748 static inline tb_page_addr_t get_page_addr_code(CPUArchState *env,
749 target_ulong addr)
751 return get_page_addr_code_hostp(env, addr, NULL);
754 #if defined(CONFIG_USER_ONLY)
755 void TSA_NO_TSA mmap_lock(void);
756 void TSA_NO_TSA mmap_unlock(void);
757 bool have_mmap_lock(void);
760 * adjust_signal_pc:
761 * @pc: raw pc from the host signal ucontext_t.
762 * @is_write: host memory operation was write, or read-modify-write.
764 * Alter @pc as required for unwinding. Return the type of the
765 * guest memory access -- host reads may be for guest execution.
767 MMUAccessType adjust_signal_pc(uintptr_t *pc, bool is_write);
770 * handle_sigsegv_accerr_write:
771 * @cpu: the cpu context
772 * @old_set: the sigset_t from the signal ucontext_t
773 * @host_pc: the host pc, adjusted for the signal
774 * @host_addr: the host address of the fault
776 * Return true if the write fault has been handled, and should be re-tried.
778 bool handle_sigsegv_accerr_write(CPUState *cpu, sigset_t *old_set,
779 uintptr_t host_pc, abi_ptr guest_addr);
782 * cpu_loop_exit_sigsegv:
783 * @cpu: the cpu context
784 * @addr: the guest address of the fault
785 * @access_type: access was read/write/execute
786 * @maperr: true for invalid page, false for permission fault
787 * @ra: host pc for unwinding
789 * Use the TCGCPUOps hook to record cpu state, do guest operating system
790 * specific things to raise SIGSEGV, and jump to the main cpu loop.
792 G_NORETURN void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
793 MMUAccessType access_type,
794 bool maperr, uintptr_t ra);
797 * cpu_loop_exit_sigbus:
798 * @cpu: the cpu context
799 * @addr: the guest address of the alignment fault
800 * @access_type: access was read/write/execute
801 * @ra: host pc for unwinding
803 * Use the TCGCPUOps hook to record cpu state, do guest operating system
804 * specific things to raise SIGBUS, and jump to the main cpu loop.
806 G_NORETURN void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
807 MMUAccessType access_type,
808 uintptr_t ra);
810 #else
811 static inline void mmap_lock(void) {}
812 static inline void mmap_unlock(void) {}
814 void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length);
815 void tlb_set_dirty(CPUState *cpu, target_ulong vaddr);
817 MemoryRegionSection *
818 address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
819 hwaddr *xlat, hwaddr *plen,
820 MemTxAttrs attrs, int *prot);
821 hwaddr memory_region_section_get_iotlb(CPUState *cpu,
822 MemoryRegionSection *section);
823 #endif
825 #endif