mirror of
https://github.com/utmapp/qemu.git
synced 2026-12-01 22:23:23 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd46296ce8 | ||
|
|
252beadf13 |
No files matched your search
+30
-7
@@ -169,6 +169,18 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
|
||||
}
|
||||
#endif /* DEBUG_DISAS */
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* We only have to lock the exec memory if we are trying to exec a
|
||||
* block in a page that is potentially unlocked. If we are using a
|
||||
* old block that is under the water mark for unlocked page, then
|
||||
* it is fine to execute without locking anything. We must make
|
||||
* sure that any cached jumps do not go into potentially unlocked
|
||||
* memory here. */
|
||||
if (*itb->p_code_locked_top_page < itb->tc.ptr + itb->tc.size) {
|
||||
tb_exec_memory_lock();
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = tcg_qemu_tb_exec(env, tb_ptr);
|
||||
cpu->can_do_io = 1;
|
||||
last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
|
||||
@@ -297,6 +309,9 @@ static bool tb_lookup_cmp(const void *p, const void *d)
|
||||
const struct tb_desc *desc = d;
|
||||
|
||||
if (tb->pc == desc->pc &&
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
tb_is_exec(tb) &&
|
||||
#endif
|
||||
tb->page_addr[0] == desc->phys_page1 &&
|
||||
tb->cs_base == desc->cs_base &&
|
||||
tb->flags == desc->flags &&
|
||||
@@ -347,12 +362,7 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr)
|
||||
if (TCG_TARGET_HAS_direct_jump) {
|
||||
uintptr_t offset = tb->jmp_target_arg[n];
|
||||
uintptr_t tc_ptr = (uintptr_t)tb->tc.ptr;
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
uintptr_t wr_addr = tc_ptr + offset + tb->code_rw_mirror_diff;
|
||||
#else
|
||||
uintptr_t wr_addr = tc_ptr + offset;
|
||||
#endif
|
||||
tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr, wr_addr);
|
||||
tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr);
|
||||
} else {
|
||||
tb->jmp_target_arg[n] = addr;
|
||||
}
|
||||
@@ -423,8 +433,21 @@ static inline TranslationBlock *tb_find(CPUState *cpu,
|
||||
}
|
||||
#endif
|
||||
/* See if we can patch the calling TB. */
|
||||
|
||||
if (last_tb) {
|
||||
tb_add_jump(last_tb, tb_exit, tb);
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* In case of exec locked/unlocked pages, we don't want to link to a page
|
||||
* that can potentially be unlocked. Therefore, we delay the jump linking
|
||||
* until the next time we fetch it and we know the unlocked watermark is
|
||||
* above the tb OR if it ends in the same page as last_tb. */
|
||||
if (((uintptr_t)(last_tb->tc.ptr + last_tb->tc.size - 1) & qemu_host_page_mask) ==
|
||||
((uintptr_t)(tb->tc.ptr + tb->tc.size) & qemu_host_page_mask) ||
|
||||
(*tb->p_code_locked_top_page >= tb->tc.ptr + tb->tc.size)) {
|
||||
#endif // defined(CONFIG_NO_RWX)
|
||||
tb_add_jump(last_tb, tb_exit, tb);
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
}
|
||||
#endif // defined(CONFIG_NO_RWX)
|
||||
}
|
||||
return tb;
|
||||
}
|
||||
|
||||
@@ -155,6 +155,15 @@ void *HELPER(lookup_tb_ptr)(CPUArchState *env)
|
||||
if (tb == NULL) {
|
||||
return tcg_ctx->code_gen_epilogue;
|
||||
}
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* In the corner case that we're executing WITHOUT locking the exec memory
|
||||
* because the first TB was below the locked mem water level, then we have
|
||||
* to lock the mem here. */
|
||||
if (tcg_ctx->code_locked_top_page == *tb->p_code_locked_top_page &&
|
||||
tcg_ctx->code_locked_top_page < tb->tc.ptr + tb->tc.size) {
|
||||
tb_exec_memory_lock();
|
||||
}
|
||||
#endif
|
||||
qemu_log_mask_and_addr(CPU_LOG_EXEC, pc,
|
||||
"Chain %d: %p ["
|
||||
TARGET_FMT_lx "/" TARGET_FMT_lx "/%#x] %s\n",
|
||||
|
||||
+41
-72
@@ -58,22 +58,6 @@
|
||||
#include "sysemu/cpus.h"
|
||||
#include "sysemu/tcg.h"
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
#include <mach/mach.h>
|
||||
extern kern_return_t mach_vm_remap(vm_map_t target_task,
|
||||
mach_vm_address_t *target_address,
|
||||
mach_vm_size_t size,
|
||||
mach_vm_offset_t mask,
|
||||
int flags,
|
||||
vm_map_t src_task,
|
||||
mach_vm_address_t src_address,
|
||||
boolean_t copy,
|
||||
vm_prot_t *cur_protection,
|
||||
vm_prot_t *max_protection,
|
||||
vm_inherit_t inheritance
|
||||
);
|
||||
#endif
|
||||
|
||||
/* #define DEBUG_TB_INVALIDATE */
|
||||
/* #define DEBUG_TB_FLUSH */
|
||||
/* make various TB consistency checks */
|
||||
@@ -311,12 +295,10 @@ static target_long decode_sleb128(uint8_t **pp)
|
||||
|
||||
static int encode_search(TranslationBlock *tb, uint8_t *block)
|
||||
{
|
||||
uint8_t *highwater;
|
||||
uint8_t *p;
|
||||
uint8_t *highwater = tcg_ctx->code_gen_highwater;
|
||||
uint8_t *p = block;
|
||||
int i, j, n;
|
||||
|
||||
highwater = (uint8_t *)TCG_CODE_PTR_RW(tcg_ctx, tcg_ctx->code_gen_highwater);
|
||||
p = (uint8_t *)TCG_CODE_PTR_RW(tcg_ctx, block);
|
||||
for (i = 0, n = tb->icount; i < n; ++i) {
|
||||
target_ulong prev;
|
||||
|
||||
@@ -340,7 +322,7 @@ static int encode_search(TranslationBlock *tb, uint8_t *block)
|
||||
}
|
||||
}
|
||||
|
||||
return p - (uint8_t *)TCG_CODE_PTR_RW(tcg_ctx, block);
|
||||
return p - block;
|
||||
}
|
||||
|
||||
/* The cpu state corresponding to 'searched_pc' is restored.
|
||||
@@ -1048,8 +1030,8 @@ static inline void *alloc_code_gen_buffer(void)
|
||||
#else
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
{
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
int prot = PROT_READ | PROT_EXEC;
|
||||
#if defined(CONFIG_NO_RWX) // iOS requires W^X
|
||||
int prot = PROT_WRITE | PROT_READ;
|
||||
#else
|
||||
int prot = PROT_WRITE | PROT_READ | PROT_EXEC;
|
||||
#endif
|
||||
@@ -1130,39 +1112,6 @@ static inline void *alloc_code_gen_buffer(void)
|
||||
}
|
||||
#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void *alloc_jit_rw_mirror(void *base, size_t size)
|
||||
{
|
||||
kern_return_t ret;
|
||||
mach_vm_address_t mirror;
|
||||
vm_prot_t cur_prot, max_prot;
|
||||
|
||||
mirror = 0;
|
||||
ret = mach_vm_remap(mach_task_self(),
|
||||
&mirror,
|
||||
size,
|
||||
0,
|
||||
VM_FLAGS_ANYWHERE | VM_FLAGS_RANDOM_ADDR,
|
||||
mach_task_self(),
|
||||
(mach_vm_address_t)base,
|
||||
false,
|
||||
&cur_prot,
|
||||
&max_prot,
|
||||
VM_INHERIT_NONE
|
||||
);
|
||||
if (ret != KERN_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mprotect((void *)mirror, size, PROT_READ | PROT_WRITE) != 0) {
|
||||
munmap((void *)mirror, size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void *)mirror;
|
||||
}
|
||||
#endif /* CONFIG_IOS_JIT */
|
||||
|
||||
static inline void code_gen_alloc(size_t tb_size)
|
||||
{
|
||||
tcg_ctx->code_gen_buffer_size = size_code_gen_buffer(tb_size);
|
||||
@@ -1171,19 +1120,6 @@ static inline void code_gen_alloc(size_t tb_size)
|
||||
fprintf(stderr, "Could not allocate dynamic translator buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
void *mirror;
|
||||
|
||||
/* For iOS JIT we need a mirror mapping for code execution */
|
||||
mirror = alloc_jit_rw_mirror(tcg_ctx->code_gen_buffer,
|
||||
tcg_ctx->code_gen_buffer_size
|
||||
);
|
||||
if (mirror == NULL) {
|
||||
fprintf(stderr, "Could not remap code buffer mirror\n");
|
||||
exit(1);
|
||||
}
|
||||
tcg_ctx->code_rw_mirror_diff = mirror - tcg_ctx->code_gen_buffer;
|
||||
#endif /* CONFIG_IOS_JIT */
|
||||
}
|
||||
|
||||
static bool tb_cmp(const void *ap, const void *bp)
|
||||
@@ -1192,6 +1128,9 @@ static bool tb_cmp(const void *ap, const void *bp)
|
||||
const TranslationBlock *b = bp;
|
||||
|
||||
return a->pc == b->pc &&
|
||||
#if defined(CONFIG_NO_RWX) // check if from different regions
|
||||
a->p_code_locked_top_page == b->p_code_locked_top_page &&
|
||||
#endif
|
||||
a->cs_base == b->cs_base &&
|
||||
a->flags == b->flags &&
|
||||
(tb_cflags(a) & CF_HASH_MASK) == (tb_cflags(b) & CF_HASH_MASK) &&
|
||||
@@ -1779,9 +1718,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
cpu_loop_exit(cpu);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
tb->code_rw_mirror_diff = tcg_ctx->code_rw_mirror_diff;
|
||||
#endif
|
||||
gen_code_buf = tcg_ctx->code_gen_ptr;
|
||||
tb->tc.ptr = gen_code_buf;
|
||||
tb->pc = pc;
|
||||
@@ -1825,6 +1761,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
ti = profile_getclock();
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
tcg_exec_memory_unlock(tcg_ctx);
|
||||
#endif
|
||||
|
||||
gen_code_size = tcg_gen_code(tcg_ctx, tb);
|
||||
if (unlikely(gen_code_size < 0)) {
|
||||
switch (gen_code_size) {
|
||||
@@ -1939,9 +1879,19 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
|
||||
if (unlikely(existing_tb != tb)) {
|
||||
uintptr_t orig_aligned = (uintptr_t)gen_code_buf;
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
g_assert(tcg_ctx->nb_tbs > 0);
|
||||
atomic_dec(&tcg_ctx->nb_tbs);
|
||||
#else // if TB is allocated in the code buffer
|
||||
orig_aligned -= ROUND_UP(sizeof(*tb), qemu_icache_linesize);
|
||||
#endif
|
||||
atomic_set(&tcg_ctx->code_gen_ptr, (void *)orig_aligned);
|
||||
return existing_tb;
|
||||
} else {
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* count total size of code blocks */
|
||||
tcg_ctx->tb_total_sizes += ((uintptr_t)tcg_ctx->code_gen_ptr - (uintptr_t)gen_code_buf);
|
||||
#endif
|
||||
}
|
||||
tcg_tb_insert(tb);
|
||||
return tb;
|
||||
@@ -2745,3 +2695,22 @@ void tcg_flush_softmmu_tlb(CPUState *cs)
|
||||
tlb_flush(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
void tb_exec_memory_lock(void)
|
||||
{
|
||||
tcg_exec_memory_lock(tcg_ctx);
|
||||
}
|
||||
|
||||
/* We can execute a TB if it's either 1) running on the same thread
|
||||
* as the current tcg_ctx or 2) below the exec locked water mark.
|
||||
*/
|
||||
bool tb_is_exec(const TranslationBlock *tb)
|
||||
{
|
||||
const void *code_locked_top_page;
|
||||
|
||||
code_locked_top_page = atomic_read(tb->p_code_locked_top_page);
|
||||
return code_locked_top_page == tcg_ctx->code_locked_top_page ||
|
||||
code_locked_top_page >= tb->tc.ptr + tb->tc.size;
|
||||
}
|
||||
#endif // defined(CONFIG_NO_RWX)
|
||||
@@ -6804,7 +6804,7 @@ fi
|
||||
|
||||
if test "$ios" = "yes" ; then
|
||||
echo "CONFIG_IOS=y" >> $config_host_mak
|
||||
echo "CONFIG_IOS_JIT=y" >> $config_host_mak
|
||||
echo "CONFIG_NO_RWX=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$solaris" = "yes" ; then
|
||||
|
||||
@@ -23,3 +23,4 @@ Contents:
|
||||
secure-coding-practices
|
||||
tcg
|
||||
tcg-plugins
|
||||
ios
|
||||
+94
-14
@@ -3,7 +3,7 @@ iOS Support
|
||||
===========
|
||||
|
||||
To run qemu on the iOS platform, some modifications were required. Most of the
|
||||
modifications are conditioned on the ``CONFIG_IOS`` and ``CONFIG_IOS_JIT``
|
||||
modifications are conditioned on the ``CONFIG_IOS`` and ``CONFIG_NO_RWX``
|
||||
configuration variables.
|
||||
|
||||
Build support
|
||||
@@ -22,19 +22,99 @@ resource cleanup in most cases (open files, allocated memory, etc), it is
|
||||
advisable that the user implements a proxy layer for syscalls so resources can
|
||||
be kept track by the app that uses qemu as a shared library.
|
||||
|
||||
JIT support
|
||||
-----------
|
||||
Executable memory locking
|
||||
-------------------------
|
||||
|
||||
On iOS, allocating RWX pages require special entitlements not usually granted to
|
||||
apps. However, it is possible to use `bulletproof JIT`_ with a development
|
||||
certificate. This means that we need to allocate one chunk of memory with RX
|
||||
permissions and then mirror map the same memory with RW permissions. We generate
|
||||
code to the mirror mapping and execute the original mapping.
|
||||
The iOS kernel does not permit ``mmap()`` pages with
|
||||
``PROT_READ | PROT_WRITE | PROT_EXEC``. However, it does allow allocating pages
|
||||
with only ``PROT_READ | PROT_WRITE`` and then later calling ``mprotect()`` with
|
||||
``PROT_READ | PROT_EXEC``. A page can never be both writable and executable.
|
||||
|
||||
With ``CONFIG_IOS_JIT`` defined, we store inside the TCG context the difference
|
||||
between the two mappings. Then, we make sure that any writes to JIT memory is
|
||||
done to the pointer + the difference (in order to get a pointer to the mirror
|
||||
mapped space). Additionally, we make sure to flush the data cache before we
|
||||
invalidate the instruction cache so the changes are seen in both mappings.
|
||||
In this document, we will refer to a page that is read-writable as "unlocked"
|
||||
and a page that is read-executable as "locked." Because ``mprotect()`` is an
|
||||
expensive call, we try to defer calling it until we need to and also try to
|
||||
avoid calling it unless it is absolutely needed.
|
||||
|
||||
.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf
|
||||
One approach would be to unlock the entire TCG region when a TB translation is
|
||||
being done and then lock the entire region when a TB is about to be executed.
|
||||
This would require thousands of pages to be locked and unlocked all the time.
|
||||
Additionally, it means that different vCPU threads cannot share the same TLB
|
||||
cache.
|
||||
|
||||
TB allocation changes
|
||||
---------------------
|
||||
|
||||
To improve the performance, we first notice that ``tcg_tb_alloc()`` returns a
|
||||
chunk of memory that must be unlocked. A recent change in qemu places the TB
|
||||
structure close to the code buffer in order to improve both cache locality and
|
||||
reduce code size and memory usage. Unfortunately, we have to regress this
|
||||
improvement as any benefit from it is negated with the need to unlock the memory
|
||||
whenever we need to mutate the TB structure.
|
||||
|
||||
We go back to the old method of statically allocating a large buffer for all
|
||||
TBs in a region. However a few improvements are made. First, we try to respect
|
||||
the locality by making this buffer close to the code. Second, whenever we flush
|
||||
the TB cache, we will use the average size of code blocks to divide up the TCG
|
||||
region into space for TB structures and space for code blocks.
|
||||
|
||||
Locked memory water level
|
||||
-------------------------
|
||||
|
||||
By moving the TB allocation, we made it such that the memory only needs to be
|
||||
unlocked in the context of ``tb_gen_code()``. Because the code buffer pointer
|
||||
only grows downwards (we do not ever "free" code blocks and have holes), we
|
||||
only ever need to unlock at most one page.
|
||||
|
||||
We can think of the entire TCG region divided into two sections: the locked
|
||||
section and the unlocked section. At the start, the entire region is unlocked.
|
||||
As more and more code blocks are generated, the allocation pointer moves
|
||||
upwards. We can then lock the memory of any memory below the allocation pointer
|
||||
as the code generated is immutable. Therefore we can keep a second pointer to
|
||||
the highest page boundary the allocation pointer passes and keep all the memory
|
||||
below that pointer (all the way to the start of the region) locked and all the
|
||||
memory above it unlocked. This pointer is our locked water level.
|
||||
|
||||
That way, assuming all pages are unlocked at the start, we will progressively
|
||||
lock more pages as more code is generated. The only page we ever need to unlock
|
||||
would be the page pointed to by our locked water level pointer.
|
||||
|
||||
In ``tb_gen_code()`` we will call ``mprotect()`` on at most one page in order to
|
||||
unlock the top of the water level (if it is currently locked). In
|
||||
``cpu_tb_exec()`` we will call ``mprotect()`` on all pages below the water
|
||||
level that are currently unlocked. This will, in most cases, be one or zero
|
||||
pages with the exception being if multiple pages of code were generated without
|
||||
being executed.
|
||||
|
||||
Multiple threads
|
||||
----------------
|
||||
|
||||
Additional consideration is needed to handle multiple threads. We do not permit
|
||||
one vCPU from executing code on another vCPU if the end of the code is located
|
||||
at it's TCG region's locked water level. The reason is that without having
|
||||
synchronization between threads, we cannot guarantee if the page at the water
|
||||
level is locked or unlocked.
|
||||
|
||||
There are multiple places this may happen: when a TB is being looked up in the
|
||||
main loop, when a TB is being looked up as part of ``goto_tb``, and the TB chain
|
||||
caches (where after lookup, we encode a jump so a future call to the first TB
|
||||
will immediately jump into the second TB without lookup).
|
||||
|
||||
Since adding synchronization is expensive (holding on thread idle while another
|
||||
one is generating code defeats the purpose of parallel TCG contexts), we
|
||||
implement a lock-less solution. In each TB, we store a pointer to the water
|
||||
level pointer. Whenever a TB is looked up, we check that either 1) the TB
|
||||
belongs to the current thread and therefore we can ensure the memory is locked
|
||||
during execution or 2) the water level of the TCG context that the TB belongs to
|
||||
is beyond the end of the TB's code block. This does mean that there might be
|
||||
redundant code generation done by multiple TCG contexts if multiple vCPUs all
|
||||
decide to execute the same block of code at the same time. This should not
|
||||
happen too often.
|
||||
|
||||
Similarly, for the TB chain cache, we will only chain a TB if either 1) both
|
||||
TBs' code buffer end pointer resides in the same page and therefore if the
|
||||
memory is locked to execute the first TB, we can jump to the second TB without
|
||||
issue, or 2) the second TB's code block fully resides below the locked water
|
||||
level of its TCG context. This means in some cases (such as two newly minted
|
||||
TBs from two threads happen to be chained), we will not chain the TB when we
|
||||
see it initially but will only chain it after a few subsequent executions and
|
||||
the locked water level has risen.
|
||||
+10
-7
@@ -430,14 +430,11 @@ struct TranslationBlock {
|
||||
uintptr_t jmp_list_head;
|
||||
uintptr_t jmp_list_next[2];
|
||||
uintptr_t jmp_dest[2];
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
/* Store difference to writable mirror
|
||||
* We need this when patching the jump instructions
|
||||
*/
|
||||
ptrdiff_t code_rw_mirror_diff;
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* Reference to code_locked_top_page in tcg_ctx */
|
||||
void * const *p_code_locked_top_page;
|
||||
#endif
|
||||
};
|
||||
} __attribute__((aligned(TB_EXIT_MASK+1)));
|
||||
|
||||
extern bool parallel_cpus;
|
||||
|
||||
@@ -586,6 +583,12 @@ void tlb_set_dirty(CPUState *cpu, target_ulong vaddr);
|
||||
/* exec.c */
|
||||
void tb_flush_jmp_cache(CPUState *cpu, target_ulong addr);
|
||||
|
||||
/* translate-all.c */
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
void tb_exec_memory_lock(void);
|
||||
bool tb_is_exec(const TranslationBlock *tb);
|
||||
#endif
|
||||
|
||||
MemoryRegionSection *
|
||||
address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
|
||||
hwaddr *xlat, hwaddr *plen,
|
||||
|
||||
@@ -33,6 +33,9 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base,
|
||||
cf_mask |= cpu->cluster_index << CF_CLUSTER_SHIFT;
|
||||
|
||||
if (likely(tb &&
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
tb_is_exec(tb) &&
|
||||
#endif
|
||||
tb->pc == *pc &&
|
||||
tb->cs_base == *cs_base &&
|
||||
tb->flags == *flags &&
|
||||
|
||||
@@ -122,7 +122,12 @@ typedef enum {
|
||||
#define TCG_TARGET_HAS_muls2_i64 0
|
||||
#define TCG_TARGET_HAS_muluh_i64 1
|
||||
#define TCG_TARGET_HAS_mulsh_i64 1
|
||||
|
||||
#if defined(CONFIG_NO_RWX) // In iOS, we have to unlock exe memory which is very slow
|
||||
#define TCG_TARGET_HAS_direct_jump 0
|
||||
#else
|
||||
#define TCG_TARGET_HAS_direct_jump 1
|
||||
#endif
|
||||
|
||||
#define TCG_TARGET_HAS_v64 1
|
||||
#define TCG_TARGET_HAS_v128 1
|
||||
@@ -148,7 +153,6 @@ typedef enum {
|
||||
|
||||
#ifdef __APPLE__
|
||||
void sys_icache_invalidate(void *start, size_t len);
|
||||
void sys_dcache_flush(void *start, size_t len);
|
||||
#endif
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
@@ -162,17 +166,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
#endif
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
sys_dcache_flush((char *)start, stop-start);
|
||||
#else
|
||||
#error "Missing function to flush data cache"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
@@ -78,44 +78,38 @@ static const int tcg_target_call_oarg_regs[1] = {
|
||||
#define TCG_REG_GUEST_BASE TCG_REG_X28
|
||||
#endif
|
||||
|
||||
static inline bool reloc_pc26(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static inline bool reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - code_ptr;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
/* read instruction, mask away previous PC_REL26 parameter contents,
|
||||
set the proper offset, then write back the instruction. */
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, code_ptr), 0, 26, offset);
|
||||
*code_ptr = deposit32(*code_ptr, 0, 26, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool reloc_pc19(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static inline bool reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - code_ptr;
|
||||
if (offset == sextract64(offset, 0, 19)) {
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, code_ptr), 5, 19, offset);
|
||||
*code_ptr = deposit32(*code_ptr, 5, 19, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_debug_assert(addend == 0);
|
||||
switch (type) {
|
||||
case R_AARCH64_JUMP26:
|
||||
case R_AARCH64_CALL26:
|
||||
return reloc_pc26(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc26(code_ptr, (tcg_insn_unit *)value);
|
||||
case R_AARCH64_CONDBR19:
|
||||
return reloc_pc19(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc19(code_ptr, (tcg_insn_unit *)value);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
@@ -1314,14 +1308,14 @@ static void tcg_out_cmp(TCGContext *s, TCGType ext, TCGReg a,
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target)
|
||||
static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
tcg_debug_assert(offset == sextract64(offset, 0, 26));
|
||||
tcg_out_insn(s, 3206, B, offset);
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto_long(TCGContext *s, const tcg_insn_unit *target)
|
||||
static inline void tcg_out_goto_long(TCGContext *s, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
@@ -1337,7 +1331,7 @@ static inline void tcg_out_callr(TCGContext *s, TCGReg reg)
|
||||
tcg_out_insn(s, 3207, BLR, reg);
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
@@ -1349,7 +1343,7 @@ static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr, uintptr_t wr_addr)
|
||||
uintptr_t addr)
|
||||
{
|
||||
tcg_insn_unit i1, i2;
|
||||
TCGType rt = TCG_TYPE_I64;
|
||||
@@ -1370,10 +1364,7 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
i2 = I3401_ADDI | rt << 31 | (addr & 0xfff) << 10 | rd << 5 | rd;
|
||||
}
|
||||
pair = (uint64_t)i2 << 32 | i1;
|
||||
atomic_set((uint64_t *)wr_addr, pair);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 8);
|
||||
#endif
|
||||
atomic_set((uint64_t *)jmp_addr, pair);
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
}
|
||||
|
||||
@@ -1579,7 +1570,7 @@ static void * const qemu_st_helpers[16] = {
|
||||
[MO_BEQ] = helper_be_stq_mmu,
|
||||
};
|
||||
|
||||
static inline void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
|
||||
static inline void tcg_out_adr(TCGContext *s, TCGReg rd, void *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target);
|
||||
tcg_debug_assert(offset == sextract64(offset, 0, 21));
|
||||
@@ -1592,7 +1583,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
MemOp size = opc & MO_SIZE;
|
||||
|
||||
if (!reloc_pc19(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc19(lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1617,7 +1608,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
MemOp size = opc & MO_SIZE;
|
||||
|
||||
if (!reloc_pc19(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc19(lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1633,8 +1624,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
|
||||
static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
TCGType ext, TCGReg data_reg, TCGReg addr_reg,
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr)
|
||||
tcg_insn_unit *raddr, tcg_insn_unit *label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1861,7 +1851,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
|
||||
#endif /* CONFIG_SOFTMMU */
|
||||
}
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg args[TCG_MAX_OP_ARGS],
|
||||
@@ -1908,8 +1898,15 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
} else {
|
||||
/* !TCG_TARGET_HAS_direct_jump */
|
||||
tcg_debug_assert(s->tb_jmp_target_addr != NULL);
|
||||
intptr_t offset = tcg_pcrel_diff(s, (s->tb_jmp_target_addr + a0)) >> 2;
|
||||
tcg_out_insn(s, 3305, LDR, offset, TCG_REG_TMP);
|
||||
uintptr_t target_addr = (uintptr_t)(s->tb_jmp_target_addr + a0);
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, (void *)target_addr);
|
||||
if (offset < 0x100000 && offset > -0x100000) { // check it's in +/- 1MiB range
|
||||
tcg_out_insn(s, 3305, LDR, offset >> 2, TCG_REG_TMP);
|
||||
} else { // TODO: what if +/- 4GiB is not enough?
|
||||
offset = (target_addr >> 12) - ((uintptr_t)s->code_ptr >> 12);
|
||||
tcg_out_insn(s, 3406, ADRP, TCG_REG_TMP, offset);
|
||||
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TMP, TCG_REG_TMP, target_addr & 0xfff);
|
||||
}
|
||||
}
|
||||
tcg_out_insn(s, 3207, BR, TCG_REG_TMP);
|
||||
set_jmp_reset_offset(s, a0);
|
||||
@@ -2880,11 +2877,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_insn(s, 3207, RET, TCG_REG_LR);
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = NOP;
|
||||
p[i] = NOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,15 +139,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
__builtin___clear_cache((char *) start, (char *) stop);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
|
||||
/* not defined -- call should be eliminated at compile time */
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+15
-20
@@ -187,22 +187,17 @@ static const uint8_t tcg_cond_to_arm_cond[] = {
|
||||
[TCG_COND_GTU] = COND_HI,
|
||||
};
|
||||
|
||||
static inline bool reloc_pc24(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static inline bool reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2;
|
||||
if (offset == sextract32(offset, 0, 24)) {
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) =
|
||||
(*TCG_CODE_PTR_RW(s, code_ptr) & ~0xffffff) | (offset & 0xffffff);
|
||||
*code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool reloc_pc13(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static inline bool reloc_pc13(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_ptr_byte_diff(target, code_ptr) - 8;
|
||||
|
||||
@@ -214,21 +209,21 @@ static inline bool reloc_pc13(TCGContext *s,
|
||||
}
|
||||
insn = deposit32(insn, 23, 1, u);
|
||||
insn = deposit32(insn, 0, 12, offset);
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) = insn;
|
||||
*code_ptr = insn;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_debug_assert(addend == 0);
|
||||
|
||||
if (type == R_ARM_PC24) {
|
||||
return reloc_pc24(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc24(code_ptr, (tcg_insn_unit *)value);
|
||||
} else if (type == R_ARM_PC13) {
|
||||
return reloc_pc13(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc13(code_ptr, (tcg_insn_unit *)value);
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
@@ -1027,7 +1022,7 @@ static inline void tcg_out_st8(TCGContext *s, int cond,
|
||||
* with the code buffer limited to 16MB we wouldn't need the long case.
|
||||
* But we also use it for the tail-call to the qemu_ld/st helpers, which does.
|
||||
*/
|
||||
static void tcg_out_goto(TCGContext *s, int cond, const tcg_insn_unit *addr)
|
||||
static void tcg_out_goto(TCGContext *s, int cond, tcg_insn_unit *addr)
|
||||
{
|
||||
intptr_t addri = (intptr_t)addr;
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, addr);
|
||||
@@ -1041,7 +1036,7 @@ static void tcg_out_goto(TCGContext *s, int cond, const tcg_insn_unit *addr)
|
||||
|
||||
/* The call case is mostly used for helpers - so it's not unreasonable
|
||||
* for them to be beyond branch range */
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *addr)
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *addr)
|
||||
{
|
||||
intptr_t addri = (intptr_t)addr;
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, addr);
|
||||
@@ -1334,7 +1329,7 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
|
||||
helper code. */
|
||||
static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
TCGReg datalo, TCGReg datahi, TCGReg addrlo,
|
||||
TCGReg addrhi, const tcg_insn_unit *raddr,
|
||||
TCGReg addrhi, tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
@@ -1356,7 +1351,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
void *func;
|
||||
|
||||
if (!reloc_pc24(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1419,7 +1414,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
TCGMemOpIdx oi = lb->oi;
|
||||
MemOp opc = get_memop(oi);
|
||||
|
||||
if (!reloc_pc24(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1750,7 +1745,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
|
||||
#endif
|
||||
}
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg *args, const int *const_args)
|
||||
@@ -2269,11 +2264,11 @@ static inline void tcg_out_movi(TCGContext *s, TCGType type,
|
||||
tcg_out_movi32(s, COND_AL, ret, arg);
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = INSN_NOP;
|
||||
p[i] = INSN_NOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-22
@@ -133,7 +133,11 @@ extern bool have_avx2;
|
||||
#define TCG_TARGET_HAS_muluh_i32 0
|
||||
#define TCG_TARGET_HAS_mulsh_i32 0
|
||||
#define TCG_TARGET_HAS_goto_ptr 1
|
||||
#if defined(CONFIG_NO_RWX) // In iOS, we have to unlock exe memory which is very slow
|
||||
#define TCG_TARGET_HAS_direct_jump 0
|
||||
#else
|
||||
#define TCG_TARGET_HAS_direct_jump 1
|
||||
#endif
|
||||
|
||||
#if TCG_TARGET_REG_BITS == 64
|
||||
/* Keep target addresses zero-extended in a register. */
|
||||
@@ -204,36 +208,16 @@ extern bool have_avx2;
|
||||
#define TCG_TARGET_extract_i64_valid(ofs, len) \
|
||||
(((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32)
|
||||
|
||||
#ifdef __APPLE__
|
||||
void sys_dcache_flush(void *start, size_t len);
|
||||
#endif
|
||||
|
||||
static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
//sys_dcache_flush((char *)start, stop-start);
|
||||
#else
|
||||
#error "Missing function to flush data cache"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
|
||||
uintptr_t jmp_addr, uintptr_t addr,
|
||||
uintptr_t wr_addr)
|
||||
uintptr_t jmp_addr, uintptr_t addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
atomic_set((int32_t *)wr_addr, addr - (jmp_addr + 4));
|
||||
atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
|
||||
/* no need to flush icache explicitly */
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
/* we do need to flush mirror dcache */
|
||||
flush_dcache_range(wr_addr, wr_addr + 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This defines the natural memory order supported by this
|
||||
|
||||
+14
-14
@@ -165,9 +165,9 @@ static bool have_lzcnt;
|
||||
# define have_lzcnt 0
|
||||
#endif
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
value += addend;
|
||||
@@ -179,14 +179,14 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
}
|
||||
/* FALLTHRU */
|
||||
case R_386_32:
|
||||
tcg_patch32(s, code_ptr, value);
|
||||
tcg_patch32(code_ptr, value);
|
||||
break;
|
||||
case R_386_PC8:
|
||||
value -= (uintptr_t)code_ptr;
|
||||
if (value != (int8_t)value) {
|
||||
return false;
|
||||
}
|
||||
tcg_patch8(s, code_ptr, value);
|
||||
tcg_patch8(code_ptr, value);
|
||||
break;
|
||||
default:
|
||||
tcg_abort();
|
||||
@@ -1602,7 +1602,7 @@ static void tcg_out_clz(TCGContext *s, int rexw, TCGReg dest, TCGReg arg1,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_branch(TCGContext *s, int call, const tcg_insn_unit *dest)
|
||||
static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest)
|
||||
{
|
||||
intptr_t disp = tcg_pcrel_diff(s, dest) - 5;
|
||||
|
||||
@@ -1621,12 +1621,12 @@ static void tcg_out_branch(TCGContext *s, int call, const tcg_insn_unit *dest)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_branch(s, 1, dest);
|
||||
}
|
||||
|
||||
static void tcg_out_jmp(TCGContext *s, const tcg_insn_unit *dest)
|
||||
static void tcg_out_jmp(TCGContext *s, tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_branch(s, 0, dest);
|
||||
}
|
||||
@@ -1785,7 +1785,7 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, bool is_64,
|
||||
TCGMemOpIdx oi,
|
||||
TCGReg datalo, TCGReg datahi,
|
||||
TCGReg addrlo, TCGReg addrhi,
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *raddr,
|
||||
tcg_insn_unit **label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
@@ -1816,9 +1816,9 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
int rexw = (l->type == TCG_TYPE_I64 ? P_REXW : 0);
|
||||
|
||||
/* resolve label address */
|
||||
tcg_patch32(s, label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
tcg_patch32(label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) {
|
||||
tcg_patch32(s, label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
tcg_patch32(label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
}
|
||||
|
||||
if (TCG_TARGET_REG_BITS == 32) {
|
||||
@@ -1901,9 +1901,9 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
TCGReg retaddr;
|
||||
|
||||
/* resolve label address */
|
||||
tcg_patch32(s, label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
tcg_patch32(label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) {
|
||||
tcg_patch32(s, label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
tcg_patch32(label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
}
|
||||
|
||||
if (TCG_TARGET_REG_BITS == 32) {
|
||||
@@ -3762,9 +3762,9 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_opc(s, OPC_RET, 0, 0, 0);
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
memset(TCG_CODE_PTR_RW(s, p), 0x90, count);
|
||||
memset(p, 0x90, count);
|
||||
}
|
||||
|
||||
static void tcg_target_init(TCGContext *s)
|
||||
|
||||
@@ -212,13 +212,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
cacheflush ((void *)start, stop-start, ICACHE);
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+25
-37
@@ -139,13 +139,12 @@ static const TCGReg tcg_target_call_oarg_regs[2] = {
|
||||
TCG_REG_V1
|
||||
};
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *bswap32_addr;
|
||||
static const tcg_insn_unit *bswap32u_addr;
|
||||
static const tcg_insn_unit *bswap64_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *bswap32_addr;
|
||||
static tcg_insn_unit *bswap32u_addr;
|
||||
static tcg_insn_unit *bswap64_addr;
|
||||
|
||||
static inline uint32_t reloc_pc16_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
/* Let the compiler perform the right-shift as part of the arithmetic. */
|
||||
ptrdiff_t disp = target - (pc + 1);
|
||||
@@ -153,35 +152,28 @@ static inline uint32_t reloc_pc16_val(const tcg_insn_unit *pc,
|
||||
return disp & 0xffff;
|
||||
}
|
||||
|
||||
static inline void reloc_pc16(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static inline void reloc_pc16(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, pc), 0, 16, reloc_pc16_val(pc, target));
|
||||
*pc = deposit32(*pc, 0, 16, reloc_pc16_val(pc, target));
|
||||
}
|
||||
|
||||
static inline uint32_t reloc_26_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static inline uint32_t reloc_26_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
tcg_debug_assert((((uintptr_t)pc ^ (uintptr_t)target) & 0xf0000000) == 0);
|
||||
return ((uintptr_t)target >> 2) & 0x3ffffff;
|
||||
}
|
||||
|
||||
static inline void reloc_26(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static inline void reloc_26(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, pc), 0, 26, reloc_26_val(pc, target));
|
||||
*pc = deposit32(*pc, 0, 26, reloc_26_val(pc, target));
|
||||
}
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_debug_assert(type == R_MIPS_PC16);
|
||||
tcg_debug_assert(addend == 0);
|
||||
reloc_pc16(s, code_ptr, (tcg_insn_unit *)value);
|
||||
reloc_pc16(code_ptr, (tcg_insn_unit *)value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -527,7 +519,7 @@ static void tcg_out_opc_sa64(TCGContext *s, MIPSInsn opc1, MIPSInsn opc2,
|
||||
* Type jump.
|
||||
* Returns true if the branch was in range and the insn was emitted.
|
||||
*/
|
||||
static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, const void *target)
|
||||
static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, void *target)
|
||||
{
|
||||
uintptr_t dest = (uintptr_t)target;
|
||||
uintptr_t from = (uintptr_t)s->code_ptr + 4;
|
||||
@@ -642,7 +634,7 @@ static inline void tcg_out_bswap16s(TCGContext *s, TCGReg ret, TCGReg arg)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_bswap_subr(TCGContext *s, const tcg_insn_unit *sub)
|
||||
static void tcg_out_bswap_subr(TCGContext *s, tcg_insn_unit *sub)
|
||||
{
|
||||
bool ok = tcg_out_opc_jmp(s, OPC_JAL, sub);
|
||||
tcg_debug_assert(ok);
|
||||
@@ -936,7 +928,7 @@ static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGReg arg1,
|
||||
|
||||
tcg_out_opc_br(s, b_opc, arg1, arg2);
|
||||
if (l->has_value) {
|
||||
reloc_pc16(s, s->code_ptr - 1, l->u.value_ptr);
|
||||
reloc_pc16(s->code_ptr - 1, l->u.value_ptr);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr - 1, R_MIPS_PC16, l, 0);
|
||||
}
|
||||
@@ -1090,7 +1082,7 @@ static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
{
|
||||
/* Note that the ABI requires the called function's address to be
|
||||
loaded into T9, even if a direct branch is in range. */
|
||||
@@ -1108,7 +1100,7 @@ static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
tcg_out_nop(s);
|
||||
@@ -1300,8 +1292,7 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
TCGType ext,
|
||||
TCGReg datalo, TCGReg datahi,
|
||||
TCGReg addrlo, TCGReg addrhi,
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr[2])
|
||||
void *raddr, tcg_insn_unit *label_ptr[2])
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1327,9 +1318,9 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
int i;
|
||||
|
||||
/* resolve label address */
|
||||
reloc_pc16(s, l->label_ptr[0], s->code_ptr);
|
||||
reloc_pc16(l->label_ptr[0], s->code_ptr);
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
reloc_pc16(s, l->label_ptr[1], s->code_ptr);
|
||||
reloc_pc16(l->label_ptr[1], s->code_ptr);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
@@ -1357,7 +1348,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
tcg_out_opc_br(s, OPC_BEQ, TCG_REG_ZERO, TCG_REG_ZERO);
|
||||
reloc_pc16(s, s->code_ptr - 1, l->raddr);
|
||||
reloc_pc16(s->code_ptr - 1, l->raddr);
|
||||
|
||||
/* delay slot */
|
||||
if (TCG_TARGET_REG_BITS == 64 && l->type == TCG_TYPE_I32) {
|
||||
@@ -1377,9 +1368,9 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
int i;
|
||||
|
||||
/* resolve label address */
|
||||
reloc_pc16(s, l->label_ptr[0], s->code_ptr);
|
||||
reloc_pc16(l->label_ptr[0], s->code_ptr);
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
reloc_pc16(s, l->label_ptr[1], s->code_ptr);
|
||||
reloc_pc16(l->label_ptr[1], s->code_ptr);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
@@ -2442,7 +2433,7 @@ static void tcg_target_detect_isa(void)
|
||||
sigaction(SIGILL, &sa_old, NULL);
|
||||
}
|
||||
|
||||
static const tcg_insn_unit *align_code_ptr(TCGContext *s)
|
||||
static tcg_insn_unit *align_code_ptr(TCGContext *s)
|
||||
{
|
||||
uintptr_t p = (uintptr_t)s->code_ptr;
|
||||
if (p & 15) {
|
||||
@@ -2669,12 +2660,9 @@ static void tcg_target_init(TCGContext *s)
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr, uintptr_t wr_addr)
|
||||
uintptr_t addr)
|
||||
{
|
||||
atomic_set((uint32_t *)jmp_addr, deposit32(OPC_J, 0, 26, addr >> 2));
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 4);
|
||||
#endif
|
||||
flush_icache_range(jmp_addr, jmp_addr + 4);
|
||||
}
|
||||
|
||||
|
||||
@@ -172,13 +172,7 @@ extern bool have_vsx;
|
||||
#define TCG_TARGET_HAS_cmpsel_vec 0
|
||||
|
||||
void flush_icache_range(uintptr_t start, uintptr_t stop);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
+18
-33
@@ -62,7 +62,7 @@
|
||||
#define TCG_CT_CONST_MONE 0x2000
|
||||
#define TCG_CT_CONST_WSZ 0x4000
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
TCGPowerISA have_isa;
|
||||
static bool have_isel;
|
||||
@@ -184,43 +184,35 @@ static inline bool in_range_b(tcg_target_long target)
|
||||
return target == sextract64(target, 0, 26);
|
||||
}
|
||||
|
||||
static uint32_t reloc_pc24_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static uint32_t reloc_pc24_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
tcg_debug_assert(in_range_b(disp));
|
||||
return disp & 0x3fffffc;
|
||||
}
|
||||
|
||||
static bool reloc_pc24(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static bool reloc_pc24(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
if (in_range_b(disp)) {
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
(*TCG_CODE_PTR_RW(s, pc) & ~0x3fffffc) | (disp & 0x3fffffc);
|
||||
*pc = (*pc & ~0x3fffffc) | (disp & 0x3fffffc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint16_t reloc_pc14_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
tcg_debug_assert(disp == (int16_t) disp);
|
||||
return disp & 0xfffc;
|
||||
}
|
||||
|
||||
static bool reloc_pc14(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
static bool reloc_pc14(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
if (disp == (int16_t) disp) {
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
(*TCG_CODE_PTR_RW(s, pc) & ~0xfffc) | (disp & 0xfffc);
|
||||
*pc = (*pc & ~0xfffc) | (disp & 0xfffc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -682,7 +674,7 @@ static const uint32_t tcg_to_isel[] = {
|
||||
[TCG_COND_GTU] = ISEL | BC_(7, CR_GT),
|
||||
};
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_insn_unit *target;
|
||||
@@ -694,9 +686,9 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
|
||||
switch (type) {
|
||||
case R_PPC_REL14:
|
||||
return reloc_pc14(s, code_ptr, target);
|
||||
return reloc_pc14(code_ptr, target);
|
||||
case R_PPC_REL24:
|
||||
return reloc_pc24(s, code_ptr, target);
|
||||
return reloc_pc24(code_ptr, target);
|
||||
case R_PPC_ADDR16:
|
||||
/*
|
||||
* We are (slightly) abusing this relocation type. In particular,
|
||||
@@ -1118,7 +1110,7 @@ static void tcg_out_xori32(TCGContext *s, TCGReg dst, TCGReg src, uint32_t c)
|
||||
tcg_out_zori32(s, dst, src, c, XORI, XORIS);
|
||||
}
|
||||
|
||||
static void tcg_out_b(TCGContext *s, int mask, const tcg_insn_unit *target)
|
||||
static void tcg_out_b(TCGContext *s, int mask, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, target);
|
||||
if (in_range_b(disp)) {
|
||||
@@ -1735,7 +1727,7 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0)
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr, uintptr_t wr_addr)
|
||||
uintptr_t addr)
|
||||
{
|
||||
if (TCG_TARGET_REG_BITS == 64) {
|
||||
tcg_insn_unit i1, i2;
|
||||
@@ -1765,22 +1757,16 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
/* As per the enclosing if, this is ppc64. Avoid the _Static_assert
|
||||
within atomic_set that would fail to build a ppc32 host. */
|
||||
atomic_set__nocheck((uint64_t *)jmp_addr, pair);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 8);
|
||||
#endif
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
} else {
|
||||
intptr_t diff = addr - jmp_addr;
|
||||
tcg_debug_assert(in_range_b(diff));
|
||||
atomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc));
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 8);
|
||||
#endif
|
||||
flush_icache_range(jmp_addr, jmp_addr + 4);
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
|
||||
{
|
||||
#ifdef _CALL_AIX
|
||||
/* Look through the descriptor. If the branch is in range, and we
|
||||
@@ -2005,8 +1991,7 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, MemOp opc,
|
||||
static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
TCGReg datalo_reg, TCGReg datahi_reg,
|
||||
TCGReg addrlo_reg, TCGReg addrhi_reg,
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *lptr)
|
||||
tcg_insn_unit *raddr, tcg_insn_unit *lptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -2026,7 +2011,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
TCGReg hi, lo, arg = TCG_REG_R3;
|
||||
|
||||
if (!reloc_pc14(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc14(lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2074,7 +2059,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp s_bits = opc & MO_SIZE;
|
||||
TCGReg hi, lo, arg = TCG_REG_R3;
|
||||
|
||||
if (!reloc_pc14(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc14(lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2271,11 +2256,11 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = NOP;
|
||||
p[i] = NOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,15 +164,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
__builtin___clear_cache((char *)start, (char *)stop);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
|
||||
/* not defined -- call should be eliminated at compile time */
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
|
||||
|
||||
+22
-29
@@ -415,11 +415,11 @@ static void tcg_out_opc_jump(TCGContext *s, RISCVInsn opc,
|
||||
tcg_out32(s, encode_uj(opc, rd, imm));
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = encode_i(OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0);
|
||||
p[i] = encode_i(OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,52 +427,46 @@ static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
* Relocations
|
||||
*/
|
||||
|
||||
static bool reloc_sbimm12(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
|
||||
if (offset == sextreg(offset, 1, 12) << 1) {
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[0] |= encode_sbimm12(offset);
|
||||
code_ptr[0] |= encode_sbimm12(offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_jimm20(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
|
||||
if (offset == sextreg(offset, 1, 20) << 1) {
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[0] |= encode_ujimm20(offset);
|
||||
code_ptr[0] |= encode_ujimm20(offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_call(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
static bool reloc_call(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
int32_t lo = sextreg(offset, 0, 12);
|
||||
int32_t hi = offset - lo;
|
||||
|
||||
if (offset == hi + lo) {
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[0] |= encode_uimm20(hi);
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[1] |= encode_imm12(lo);
|
||||
code_ptr[0] |= encode_uimm20(hi);
|
||||
code_ptr[1] |= encode_imm12(lo);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
uint32_t insn = *code_ptr;
|
||||
@@ -486,7 +480,7 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
diff = value - (uintptr_t)code_ptr;
|
||||
short_jmp = diff == sextreg(diff, 0, 12);
|
||||
if (short_jmp) {
|
||||
return reloc_sbimm12(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_sbimm12(code_ptr, (tcg_insn_unit *)value);
|
||||
} else {
|
||||
/* Invert the condition */
|
||||
insn = insn ^ (1 << 12);
|
||||
@@ -507,10 +501,10 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
}
|
||||
break;
|
||||
case R_RISCV_JAL:
|
||||
return reloc_jimm20(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_jimm20(code_ptr, (tcg_insn_unit *)value);
|
||||
break;
|
||||
case R_RISCV_CALL:
|
||||
return reloc_call(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_call(code_ptr, (tcg_insn_unit *)value);
|
||||
break;
|
||||
default:
|
||||
tcg_abort();
|
||||
@@ -567,7 +561,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
|
||||
if (tmp == (int32_t)tmp) {
|
||||
tcg_out_opc_upper(s, OPC_AUIPC, rd, 0);
|
||||
tcg_out_opc_imm(s, OPC_ADDI, rd, rd, 0);
|
||||
ret = reloc_call(s, s->code_ptr - 2, (tcg_insn_unit *)val);
|
||||
ret = reloc_call(s->code_ptr - 2, (tcg_insn_unit *)val);
|
||||
tcg_debug_assert(ret == true);
|
||||
return;
|
||||
}
|
||||
@@ -864,14 +858,14 @@ static void tcg_out_setcond2(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto(TCGContext *s, const tcg_insn_unit *target)
|
||||
static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target);
|
||||
tcg_debug_assert(offset == sextreg(offset, 1, 20) << 1);
|
||||
tcg_out_opc_jump(s, OPC_JAL, TCG_REG_ZERO, offset);
|
||||
}
|
||||
|
||||
static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
{
|
||||
TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, arg);
|
||||
@@ -885,7 +879,7 @@ static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
/* long jump: -2147483646 to 2147483648 */
|
||||
tcg_out_opc_upper(s, OPC_AUIPC, TCG_REG_TMP0, 0);
|
||||
tcg_out_opc_imm(s, OPC_JALR, link, TCG_REG_TMP0, 0);
|
||||
ret = reloc_call(s, s->code_ptr - 2, arg);\
|
||||
ret = reloc_call(s->code_ptr - 2, arg);\
|
||||
tcg_debug_assert(ret == true);
|
||||
} else if (TCG_TARGET_REG_BITS == 64) {
|
||||
/* far jump: 64-bit */
|
||||
@@ -898,7 +892,7 @@ static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
}
|
||||
@@ -1032,8 +1026,7 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
TCGType ext,
|
||||
TCGReg datalo, TCGReg datahi,
|
||||
TCGReg addrlo, TCGReg addrhi,
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit **label_ptr)
|
||||
void *raddr, tcg_insn_unit **label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1063,7 +1056,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
/* resolve label address */
|
||||
if (!patch_reloc(s, l->label_ptr[0], R_RISCV_BRANCH,
|
||||
if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH,
|
||||
(intptr_t) s->code_ptr, 0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1098,7 +1091,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
/* resolve label address */
|
||||
if (!patch_reloc(s, l->label_ptr[0], R_RISCV_BRANCH,
|
||||
if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH,
|
||||
(intptr_t) s->code_ptr, 0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1285,7 +1278,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
|
||||
#endif
|
||||
}
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg *args, const int *const_args)
|
||||
|
||||
+1
-12
@@ -149,24 +149,13 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
|
||||
uintptr_t jmp_addr, uintptr_t addr,
|
||||
uintptr_t wr_addr)
|
||||
uintptr_t jmp_addr, uintptr_t addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
intptr_t disp = addr - (jmp_addr - 2);
|
||||
atomic_set((int32_t *)jmp_addr, disp / 2);
|
||||
/* no need to flush icache explicitly */
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
|
||||
+12
-13
@@ -363,10 +363,10 @@ static void * const qemu_st_helpers[16] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
uint64_t s390_facilities;
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
intptr_t pcrel2;
|
||||
@@ -378,13 +378,13 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
switch (type) {
|
||||
case R_390_PC16DBL:
|
||||
if (pcrel2 == (int16_t)pcrel2) {
|
||||
tcg_patch16(s, code_ptr, pcrel2);
|
||||
tcg_patch16(code_ptr, pcrel2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case R_390_PC32DBL:
|
||||
if (pcrel2 == (int32_t)pcrel2) {
|
||||
tcg_patch32(s, code_ptr, pcrel2);
|
||||
tcg_patch32(code_ptr, pcrel2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -392,7 +392,7 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
if (value == sextract64(value, 0, 20)) {
|
||||
old = *(uint32_t *)code_ptr & 0xf00000ff;
|
||||
old |= ((value & 0xfff) << 16) | ((value & 0xff000) >> 4);
|
||||
tcg_patch32(s, code_ptr, old);
|
||||
tcg_patch32(code_ptr, old);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -1306,7 +1306,7 @@ static void tgen_extract(TCGContext *s, TCGReg dest, TCGReg src,
|
||||
tcg_out_risbg(s, dest, src, 64 - len, 63, 64 - ofs, 1);
|
||||
}
|
||||
|
||||
static void tgen_gotoi(TCGContext *s, int cc, const tcg_insn_unit *dest)
|
||||
static void tgen_gotoi(TCGContext *s, int cc, tcg_insn_unit *dest)
|
||||
{
|
||||
ptrdiff_t off = dest - s->code_ptr;
|
||||
if (off == (int16_t)off) {
|
||||
@@ -1419,7 +1419,7 @@ static void tgen_brcond(TCGContext *s, TCGType type, TCGCond c,
|
||||
tgen_branch(s, cc, l);
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
{
|
||||
ptrdiff_t off = dest - s->code_ptr;
|
||||
if (off == (int32_t)off) {
|
||||
@@ -1597,8 +1597,7 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addr_reg, MemOp opc,
|
||||
|
||||
static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
|
||||
TCGReg data, TCGReg addr,
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr)
|
||||
tcg_insn_unit *raddr, tcg_insn_unit *label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1617,7 +1616,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
TCGMemOpIdx oi = lb->oi;
|
||||
MemOp opc = get_memop(oi);
|
||||
|
||||
if (!patch_reloc(s, lb->label_ptr[0], R_390_PC16DBL,
|
||||
if (!patch_reloc(lb->label_ptr[0], R_390_PC16DBL,
|
||||
(intptr_t)s->code_ptr, 2)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1642,7 +1641,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
TCGMemOpIdx oi = lb->oi;
|
||||
MemOp opc = get_memop(oi);
|
||||
|
||||
if (!patch_reloc(s, lb->label_ptr[0], R_390_PC16DBL,
|
||||
if (!patch_reloc(lb->label_ptr[0], R_390_PC16DBL,
|
||||
(intptr_t)s->code_ptr, 2)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2580,9 +2579,9 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_R14);
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
memset(TCG_CODE_PTR_RW(s, p), 0x07, count * sizeof(tcg_insn_unit));
|
||||
memset(p, 0x07, count * sizeof(tcg_insn_unit));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -176,13 +176,7 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
}
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_NEED_POOL_LABELS
|
||||
|
||||
|
||||
+11
-18
@@ -291,14 +291,14 @@ static inline int check_fit_i32(int32_t val, unsigned int bits)
|
||||
# define check_fit_ptr check_fit_i32
|
||||
#endif
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
uint32_t insn = *code_ptr;
|
||||
intptr_t pcrel;
|
||||
|
||||
value += addend;
|
||||
pcrel = tcg_ptr_byte_diff((const tcg_insn_unit *)value, code_ptr);
|
||||
pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr);
|
||||
|
||||
switch (type) {
|
||||
case R_SPARC_WDISP16:
|
||||
@@ -845,7 +845,7 @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
|
||||
tcg_out_mov(s, TCG_TYPE_I64, rl, tmp);
|
||||
}
|
||||
|
||||
static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
|
||||
static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest,
|
||||
bool in_prologue)
|
||||
{
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, dest);
|
||||
@@ -860,7 +860,7 @@ static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_call_nodelay(s, dest, false);
|
||||
tcg_out_nop(s);
|
||||
@@ -873,8 +873,8 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
static const tcg_insn_unit *qemu_ld_trampoline[16];
|
||||
static const tcg_insn_unit *qemu_st_trampoline[16];
|
||||
static tcg_insn_unit *qemu_ld_trampoline[16];
|
||||
static tcg_insn_unit *qemu_st_trampoline[16];
|
||||
|
||||
static void emit_extend(TCGContext *s, TCGReg r, int op)
|
||||
{
|
||||
@@ -1053,11 +1053,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = NOP;
|
||||
p[i] = NOP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1168,7 +1168,7 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
unsigned memi = get_mmuidx(oi);
|
||||
TCGReg addrz, param;
|
||||
const tcg_insn_unit *func;
|
||||
tcg_insn_unit *func;
|
||||
tcg_insn_unit *label_ptr;
|
||||
|
||||
addrz = tcg_out_tlb_load(s, addr, memi, memop,
|
||||
@@ -1231,8 +1231,7 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
|
||||
}
|
||||
}
|
||||
|
||||
*TCG_CODE_PTR_RW(s, label_ptr) |=
|
||||
INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
|
||||
*label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
|
||||
#else
|
||||
if (SPARC64 && TARGET_LONG_BITS == 32) {
|
||||
tcg_out_arithi(s, TCG_REG_T1, addr, 0, SHIFT_SRL);
|
||||
@@ -1828,7 +1827,7 @@ void tcg_register_jit(void *buf, size_t buf_size)
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr, uintptr_t wr_addr)
|
||||
uintptr_t addr)
|
||||
{
|
||||
intptr_t tb_disp = addr - tc_ptr;
|
||||
intptr_t br_disp = addr - jmp_addr;
|
||||
@@ -1841,9 +1840,6 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
|
||||
if (!USE_REG_TB) {
|
||||
atomic_set((uint32_t *)jmp_addr, deposit32(CALL, 0, 30, br_disp >> 2));
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 4);
|
||||
#endif
|
||||
flush_icache_range(jmp_addr, jmp_addr + 4);
|
||||
return;
|
||||
}
|
||||
@@ -1868,8 +1864,5 @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
}
|
||||
|
||||
atomic_set((uint64_t *)jmp_addr, deposit64(i2, 32, 32, i1));
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 8);
|
||||
#endif
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ typedef struct TCGLabelQemuLdst {
|
||||
TCGReg addrhi_reg; /* reg index for high word of guest virtual addr */
|
||||
TCGReg datalo_reg; /* reg index for low word to be loaded or stored */
|
||||
TCGReg datahi_reg; /* reg index for high word to be loaded or stored */
|
||||
const tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st */
|
||||
tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */
|
||||
tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */
|
||||
QSIMPLEQ_ENTRY(TCGLabelQemuLdst) next;
|
||||
} TCGLabelQemuLdst;
|
||||
|
||||
+4
-5
@@ -119,7 +119,7 @@ static inline void new_pool_l8(TCGContext *s, int rtype, tcg_insn_unit *label,
|
||||
}
|
||||
|
||||
/* To be provided by cpu/tcg-target.inc.c. */
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count);
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count);
|
||||
|
||||
static int tcg_out_pool_finalize(TCGContext *s)
|
||||
{
|
||||
@@ -135,7 +135,7 @@ static int tcg_out_pool_finalize(TCGContext *s)
|
||||
again when allocating the next TranslationBlock structure. */
|
||||
a = (void *)ROUND_UP((uintptr_t)s->code_ptr,
|
||||
sizeof(tcg_target_ulong) * p->nlong);
|
||||
tcg_out_nop_fill(s, s->code_ptr, (tcg_insn_unit *)a - s->code_ptr);
|
||||
tcg_out_nop_fill(s->code_ptr, (tcg_insn_unit *)a - s->code_ptr);
|
||||
s->data_gen_ptr = a;
|
||||
|
||||
for (; p != NULL; p = p->next) {
|
||||
@@ -144,12 +144,11 @@ static int tcg_out_pool_finalize(TCGContext *s)
|
||||
if (unlikely(a > s->code_gen_highwater)) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(TCG_CODE_PTR_RW(s, a), p->data, size);
|
||||
memcpy(a, p->data, size);
|
||||
a += size;
|
||||
l = p;
|
||||
}
|
||||
if (!patch_reloc(s, p->label, p->rtype,
|
||||
(intptr_t)a - size, p->addend)) {
|
||||
if (!patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend)) {
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
static void tcg_target_init(TCGContext *s);
|
||||
static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode);
|
||||
static void tcg_target_qemu_prologue(TCGContext *s);
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend);
|
||||
|
||||
/* The CIE and FDE header definitions will be common to all hosts. */
|
||||
@@ -148,7 +148,7 @@ static void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, TCGReg arg1,
|
||||
intptr_t arg2);
|
||||
static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
|
||||
TCGReg base, intptr_t ofs);
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target);
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *target);
|
||||
static int tcg_target_const_match(tcg_target_long val, TCGType type,
|
||||
const TCGArgConstraint *arg_ct);
|
||||
#ifdef TCG_TARGET_NEED_LDST_LABELS
|
||||
@@ -157,6 +157,10 @@ static int tcg_out_ldst_finalize(TCGContext *s);
|
||||
|
||||
#define TCG_HIGHWATER 1024
|
||||
|
||||
/* For computing the average TB code size, if we seen below this threshold,
|
||||
then the average is not meaningful and we ignore it. */
|
||||
#define TCG_TB_SEEN_THRESHOLD 10
|
||||
|
||||
static TCGContext **tcg_ctxs;
|
||||
static unsigned int n_tcg_ctxs;
|
||||
TCGv_env cpu_env = 0;
|
||||
@@ -203,15 +207,13 @@ static TCGRegSet tcg_target_call_clobber_regs;
|
||||
#if TCG_TARGET_INSN_UNIT_SIZE == 1
|
||||
static __attribute__((unused)) inline void tcg_out8(TCGContext *s, uint8_t v)
|
||||
{
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
*s->code_ptr++ = v;
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch8(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch8(tcg_insn_unit *p,
|
||||
uint8_t v)
|
||||
{
|
||||
*TCG_CODE_PTR_RW(s, p) = v;
|
||||
*p = v;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -219,23 +221,21 @@ static __attribute__((unused)) inline void tcg_patch8(TCGContext *s,
|
||||
static __attribute__((unused)) inline void tcg_out16(TCGContext *s, uint16_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 2) {
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
*s->code_ptr++ = v;
|
||||
} else {
|
||||
tcg_insn_unit *p = s->code_ptr;
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
memcpy(p, &v, sizeof(v));
|
||||
s->code_ptr = p + (2 / TCG_TARGET_INSN_UNIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch16(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch16(tcg_insn_unit *p,
|
||||
uint16_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 2) {
|
||||
*TCG_CODE_PTR_RW(s, p) = v;
|
||||
*p = v;
|
||||
} else {
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
memcpy(p, &v, sizeof(v));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -244,23 +244,21 @@ static __attribute__((unused)) inline void tcg_patch16(TCGContext *s,
|
||||
static __attribute__((unused)) inline void tcg_out32(TCGContext *s, uint32_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 4) {
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
*s->code_ptr++ = v;
|
||||
} else {
|
||||
tcg_insn_unit *p = s->code_ptr;
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
memcpy(p, &v, sizeof(v));
|
||||
s->code_ptr = p + (4 / TCG_TARGET_INSN_UNIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch32(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch32(tcg_insn_unit *p,
|
||||
uint32_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 4) {
|
||||
*p = v;
|
||||
} else {
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
memcpy(p, &v, sizeof(v));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -269,23 +267,21 @@ static __attribute__((unused)) inline void tcg_patch32(TCGContext *s,
|
||||
static __attribute__((unused)) inline void tcg_out64(TCGContext *s, uint64_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 8) {
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
*s->code_ptr++ = v;
|
||||
} else {
|
||||
tcg_insn_unit *p = s->code_ptr;
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
memcpy(p, &v, sizeof(v));
|
||||
s->code_ptr = p + (8 / TCG_TARGET_INSN_UNIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch64(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch64(tcg_insn_unit *p,
|
||||
uint64_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 8) {
|
||||
*p = v;
|
||||
} else {
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
memcpy(p, &v, sizeof(v));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -303,7 +299,7 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
QSIMPLEQ_INSERT_TAIL(&l->relocs, r, next);
|
||||
}
|
||||
|
||||
static void tcg_out_label(TCGContext *s, TCGLabel *l, const tcg_insn_unit *ptr)
|
||||
static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)
|
||||
{
|
||||
tcg_debug_assert(!l->has_value);
|
||||
l->has_value = 1;
|
||||
@@ -333,7 +329,7 @@ static bool tcg_resolve_relocs(TCGContext *s)
|
||||
uintptr_t value = l->u.value;
|
||||
|
||||
QSIMPLEQ_FOREACH(r, &l->relocs, next) {
|
||||
if (!patch_reloc(s, r->ptr, r->type, value, r->addend)) {
|
||||
if (!patch_reloc(r->ptr, r->type, value, r->addend)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -543,6 +539,36 @@ static void tcg_region_bounds(size_t curr_region, void **pstart, void **pend)
|
||||
*pend = end;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/*
|
||||
* Called before clearing the TBs from last flush.
|
||||
* Uses the average code block size from the last flush
|
||||
* to set aside a chunk of memory for future translations.
|
||||
* `buffer` must be page aligned
|
||||
*/
|
||||
static void tcg_tbs_alloc(TCGContext *s)
|
||||
{
|
||||
size_t average_block_size;
|
||||
|
||||
if (s->nb_tbs < TCG_TB_SEEN_THRESHOLD) {
|
||||
average_block_size = CODE_GEN_AVG_BLOCK_SIZE;
|
||||
} else {
|
||||
average_block_size = s->tb_total_sizes / s->nb_tbs;
|
||||
}
|
||||
|
||||
s->code_gen_max_blocks = s->code_gen_buffer_size / (sizeof(TranslationBlock) + average_block_size);
|
||||
s->tbs = s->code_gen_ptr;
|
||||
/* if buffer is start of region, it should already be aligned */
|
||||
g_assert(((uintptr_t)s->tbs & ~qemu_host_page_mask) == 0);
|
||||
/* Sanity check since we need bottom 2 bits zero. page_mask should cover this. */
|
||||
g_assert(((uintptr_t)s->tbs & TB_EXIT_MASK) == 0);
|
||||
s->code_gen_ptr = (void *)ROUND_UP((uintptr_t)&s->tbs[s->code_gen_max_blocks], qemu_host_page_size);
|
||||
g_assert(s->code_gen_ptr < s->code_gen_highwater);
|
||||
s->nb_tbs = 0;
|
||||
s->tb_total_sizes = 0;
|
||||
}
|
||||
#endif // defined(CONFIG_NO_RWX)
|
||||
|
||||
static void tcg_region_assign(TCGContext *s, size_t curr_region)
|
||||
{
|
||||
void *start, *end;
|
||||
@@ -553,6 +579,13 @@ static void tcg_region_assign(TCGContext *s, size_t curr_region)
|
||||
s->code_gen_ptr = start;
|
||||
s->code_gen_buffer_size = end - start;
|
||||
s->code_gen_highwater = end - TCG_HIGHWATER;
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
tcg_tbs_alloc(s);
|
||||
s->code_locked = 0;
|
||||
g_assert(((uintptr_t)s->code_gen_ptr & ~qemu_host_page_mask) == 0);
|
||||
s->code_locked_top_page = s->code_gen_ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool tcg_region_alloc__locked(TCGContext *s)
|
||||
@@ -602,6 +635,10 @@ void tcg_region_reset_all(void)
|
||||
qemu_mutex_lock(®ion.lock);
|
||||
region.current = 0;
|
||||
region.agg_size_full = 0;
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* unlock any locked pages from before */
|
||||
tcg_exec_memory_destroy(region.start, region.end - region.start);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < n_ctxs; i++) {
|
||||
TCGContext *s = atomic_read(&tcg_ctxs[i]);
|
||||
@@ -696,6 +733,11 @@ void tcg_region_init(void)
|
||||
|
||||
n_regions = tcg_n_regions();
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* We shouldn't be translating code yet, so it should not be locked */
|
||||
g_assert(!tcg_init_ctx.code_locked);
|
||||
#endif
|
||||
|
||||
/* The first region will be 'aligned - buf' bytes larger than the others */
|
||||
aligned = QEMU_ALIGN_PTR_UP(buf, page_size);
|
||||
g_assert(aligned < tcg_init_ctx.code_gen_buffer + size);
|
||||
@@ -1026,6 +1068,30 @@ void tcg_context_init(TCGContext *s)
|
||||
*/
|
||||
TranslationBlock *tcg_tb_alloc(TCGContext *s)
|
||||
{
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
TranslationBlock *tb;
|
||||
int nb_tbs;
|
||||
|
||||
retry:
|
||||
/* artifical limit of TBs buffer reached OR we hit highwater mark */
|
||||
nb_tbs = atomic_fetch_inc(&s->nb_tbs);
|
||||
if (unlikely(nb_tbs >= s->code_gen_max_blocks ||
|
||||
s->code_gen_ptr > s->code_gen_highwater)) {
|
||||
// lock this region before moving to the next one
|
||||
tcg_exec_memory_lock(s);
|
||||
if (tcg_region_alloc(s)) {
|
||||
return NULL;
|
||||
}
|
||||
goto retry;
|
||||
}
|
||||
/* we have a tb to work with */
|
||||
tb = &s->tbs[nb_tbs];
|
||||
tb->p_code_locked_top_page = &s->code_locked_top_page;
|
||||
/* bottom two bits used in exit_tb, must be zero */
|
||||
g_assert(((uintptr_t)tb & TB_EXIT_MASK) == 0);
|
||||
s->data_gen_ptr = NULL;
|
||||
return tb;
|
||||
#else // !defined(CONFIG_NO_RWX)
|
||||
uintptr_t align = qemu_icache_linesize;
|
||||
TranslationBlock *tb;
|
||||
void *next;
|
||||
@@ -1042,7 +1108,8 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s)
|
||||
}
|
||||
atomic_set(&s->code_gen_ptr, next);
|
||||
s->data_gen_ptr = NULL;
|
||||
return (TranslationBlock *)TCG_CODE_PTR_RW(s, tb);
|
||||
return tb;
|
||||
#endif // defined(CONFIG_NO_RWX)
|
||||
}
|
||||
|
||||
void tcg_prologue_init(TCGContext *s)
|
||||
@@ -1078,21 +1145,34 @@ void tcg_prologue_init(TCGContext *s)
|
||||
}
|
||||
#endif
|
||||
|
||||
buf1 = s->code_ptr;
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range((uintptr_t)TCG_CODE_PTR_RW(s, buf0),
|
||||
(uintptr_t)TCG_CODE_PTR_RW(s, buf1));
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* We need to mark prolog page as W^X, so align to page */
|
||||
s->code_ptr = (void *)ROUND_UP((uintptr_t)s->code_ptr, qemu_host_page_size);
|
||||
#endif
|
||||
|
||||
buf1 = s->code_ptr;
|
||||
prologue_size = tcg_current_code_size(s);
|
||||
flush_icache_range((uintptr_t)buf0, (uintptr_t)buf1);
|
||||
|
||||
/* Deduct the prologue from the buffer. */
|
||||
prologue_size = tcg_current_code_size(s);
|
||||
s->code_gen_ptr = buf1;
|
||||
s->code_gen_buffer = buf1;
|
||||
s->code_buf = buf1;
|
||||
total_size -= prologue_size;
|
||||
s->code_gen_buffer_size = total_size;
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
tcg_tbs_alloc(s);
|
||||
/* Mark prologue as executable */
|
||||
if (mprotect(buf0, prologue_size, PROT_READ | PROT_EXEC) < 0) {
|
||||
fprintf(stderr, "Failed to lock exec memory\n");
|
||||
exit(1);
|
||||
}
|
||||
g_assert(((uintptr_t)buf1 & ~qemu_host_page_mask) == 0);
|
||||
s->code_locked = 0;
|
||||
s->code_locked_top_page = buf1;
|
||||
#endif
|
||||
|
||||
tcg_register_jit(s->code_gen_buffer, total_size);
|
||||
|
||||
#ifdef DEBUG_DISAS
|
||||
@@ -4233,12 +4313,6 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
return -2;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
/* flush data cache on mirror */
|
||||
flush_dcache_range((uintptr_t)TCG_CODE_PTR_RW(s, s->code_buf),
|
||||
(uintptr_t)TCG_CODE_PTR_RW(s, s->code_ptr));
|
||||
#endif
|
||||
|
||||
/* flush instruction cache */
|
||||
flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr);
|
||||
|
||||
@@ -4587,3 +4661,47 @@ void tcg_expand_vec_op(TCGOpcode o, TCGType t, unsigned e, TCGArg a0, ...)
|
||||
g_assert_not_reached();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
void tcg_exec_memory_unlock(TCGContext *s)
|
||||
{
|
||||
/* We only need to unlock the top page as all the pages above it are
|
||||
still unlocked */
|
||||
if (s->code_locked)
|
||||
{
|
||||
if (mprotect(s->code_locked_top_page, qemu_host_page_size, PROT_READ | PROT_WRITE) < 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to lock exec memory\n");
|
||||
exit(1);
|
||||
}
|
||||
s->code_locked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void tcg_exec_memory_lock(TCGContext *s)
|
||||
{
|
||||
if (!s->code_locked)
|
||||
{
|
||||
void *old_top = s->code_locked_top_page;
|
||||
void *new_top = (void *)((uintptr_t)s->code_gen_ptr & qemu_host_page_mask);
|
||||
if (mprotect(old_top, (new_top - old_top) + qemu_host_page_size, PROT_READ | PROT_EXEC) < 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to unlock exec memory\n");
|
||||
exit(1);
|
||||
}
|
||||
s->code_locked_top_page = new_top;
|
||||
s->code_locked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void tcg_exec_memory_destroy(void *start, size_t len)
|
||||
{
|
||||
g_assert(((uintptr_t)start & ~qemu_host_page_mask) == 0);
|
||||
g_assert((len & ~qemu_host_page_mask) == 0);
|
||||
if (mprotect(start, len, PROT_READ | PROT_WRITE) < 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to unlock exec memory\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif // defined(CONFIG_NO_RWX)
|
||||
@@ -258,7 +258,7 @@ struct TCGLabel {
|
||||
unsigned refs : 16;
|
||||
union {
|
||||
uintptr_t value;
|
||||
const tcg_insn_unit *value_ptr;
|
||||
tcg_insn_unit *value_ptr;
|
||||
} u;
|
||||
QSIMPLEQ_HEAD(, TCGRelocation) relocs;
|
||||
QSIMPLEQ_ENTRY(TCGLabel) next;
|
||||
@@ -590,7 +590,7 @@ struct TCGContext {
|
||||
int nb_ops;
|
||||
|
||||
/* goto_tb support */
|
||||
const tcg_insn_unit *code_buf;
|
||||
tcg_insn_unit *code_buf;
|
||||
uint16_t *tb_jmp_reset_offset; /* tb->jmp_reset_offset */
|
||||
uintptr_t *tb_jmp_insn_offset; /* tb->jmp_target_arg if direct_jump */
|
||||
uintptr_t *tb_jmp_target_addr; /* tb->jmp_target_arg if !direct_jump */
|
||||
@@ -624,8 +624,24 @@ struct TCGContext {
|
||||
size_t code_gen_buffer_size;
|
||||
void *code_gen_ptr;
|
||||
void *data_gen_ptr;
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
ptrdiff_t code_rw_mirror_diff;
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
/* Code memory locking/unlocking. On W^X platforms, we need to keep
|
||||
track of when a page is RW or RX. We take advantage of the fact
|
||||
that generated code only grows downwards so at any point in time
|
||||
we only need to have 1 or 0 page unlocked. */
|
||||
int code_locked;
|
||||
void *code_locked_top_page;
|
||||
|
||||
/* On iOS we cannot store TB before the code buffer because of W^X
|
||||
therefore we need to allocate from some other region of memory. */
|
||||
TranslationBlock *tbs;
|
||||
size_t nb_tbs;
|
||||
size_t code_gen_max_blocks;
|
||||
|
||||
/* We can compute the average size of TB blocks last flush and use
|
||||
that to compute the number of blocks needed next flush. */
|
||||
uint64_t tb_total_sizes;
|
||||
#endif
|
||||
|
||||
/* Threshold to flush the translated code buffer. */
|
||||
@@ -677,13 +693,6 @@ struct TCGContext {
|
||||
target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS];
|
||||
};
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
# define TCG_CODE_PTR_RW(s, code_ptr) \
|
||||
(tcg_insn_unit *)((uintptr_t)(code_ptr) + (s)->code_rw_mirror_diff)
|
||||
#else
|
||||
# define TCG_CODE_PTR_RW(s, code_ptr) (code_ptr)
|
||||
#endif
|
||||
|
||||
extern TCGContext tcg_init_ctx;
|
||||
extern __thread TCGContext *tcg_ctx;
|
||||
extern TCGv_env cpu_env;
|
||||
@@ -1096,7 +1105,7 @@ static inline TCGLabel *arg_label(TCGArg i)
|
||||
* correct result.
|
||||
*/
|
||||
|
||||
static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
|
||||
static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
@@ -1110,7 +1119,7 @@ static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
|
||||
* to the destination address.
|
||||
*/
|
||||
|
||||
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
|
||||
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, void *target)
|
||||
{
|
||||
return tcg_ptr_byte_diff(target, s->code_ptr);
|
||||
}
|
||||
@@ -1226,6 +1235,12 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr);
|
||||
|
||||
void tcg_register_jit(void *buf, size_t buf_size);
|
||||
|
||||
#if defined(CONFIG_NO_RWX)
|
||||
void tcg_exec_memory_unlock(TCGContext *s);
|
||||
void tcg_exec_memory_lock(TCGContext *s);
|
||||
void tcg_exec_memory_destroy(void *start, size_t len);
|
||||
#endif
|
||||
|
||||
#if TCG_TARGET_MAYBE_vec
|
||||
/* Return zero if the tuple (opc, type, vece) is unsupportable;
|
||||
return > 0 if it is directly supportable;
|
||||
|
||||
+1
-12
@@ -195,13 +195,6 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
{
|
||||
#error "Unimplemented dcache flush function"
|
||||
}
|
||||
#endif
|
||||
|
||||
/* We could notice __i386__ or __s390x__ and reduce the barriers depending
|
||||
on the host. But if you want performance, you use the normal backend.
|
||||
We prefer consistency across hosts on this. */
|
||||
@@ -210,15 +203,11 @@ static inline void flush_dcache_range(uintptr_t start, uintptr_t stop)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
|
||||
uintptr_t jmp_addr, uintptr_t addr,
|
||||
uintptr_t wr_addr)
|
||||
uintptr_t jmp_addr, uintptr_t addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
|
||||
/* no need to flush icache explicitly */
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 4);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* TCG_TARGET_H */
|
||||
@@ -369,7 +369,7 @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
/* tcg_out_reloc always uses the same type, addend. */
|
||||
@@ -377,9 +377,9 @@ static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
tcg_debug_assert(addend == 0);
|
||||
tcg_debug_assert(value != 0);
|
||||
if (TCG_TARGET_REG_BITS == 32) {
|
||||
tcg_patch32(s, code_ptr, value);
|
||||
tcg_patch32(code_ptr, value);
|
||||
} else {
|
||||
tcg_patch64(s, code_ptr, value);
|
||||
tcg_patch64(code_ptr, value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -546,7 +546,7 @@ static void tcg_out_movi(TCGContext *s, TCGType type,
|
||||
old_code_ptr[1] = s->code_ptr - old_code_ptr;
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
{
|
||||
uint8_t *old_code_ptr = s->code_ptr;
|
||||
tcg_out_op_t(s, INDEX_op_call);
|
||||
|
||||
Reference in new issue
Block a user