mirror of
https://github.com/utmapp/qemu.git
synced 2026-12-01 22:23:23 -10:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2fb97f4f83 | ||
|
|
8ff0b2c920 | ||
|
|
090e4da589 | ||
|
|
863db125c3 | ||
|
|
f3a53c031b | ||
|
|
7b72c6b9c7 | ||
|
|
bd3929e6b3 | ||
|
|
a9bafced71 |
No files matched your search
+4
-1
@@ -51,10 +51,13 @@
|
||||
url = https://git.qemu.org/git/edk2.git
|
||||
[submodule "slirp"]
|
||||
path = slirp
|
||||
url = https://git.qemu.org/git/libslirp.git
|
||||
url = https://github.com/utmapp/libslirp.git
|
||||
[submodule "roms/opensbi"]
|
||||
path = roms/opensbi
|
||||
url = https://git.qemu.org/git/opensbi.git
|
||||
[submodule "roms/qboot"]
|
||||
path = roms/qboot
|
||||
url = https://github.com/bonzini/qboot
|
||||
[submodule "libucontext"]
|
||||
path = libucontext
|
||||
url = https://github.com/utmapp/libucontext.git
|
||||
@@ -550,6 +550,9 @@ CAP_CFLAGS += -DCAPSTONE_HAS_ARM64
|
||||
CAP_CFLAGS += -DCAPSTONE_HAS_POWERPC
|
||||
CAP_CFLAGS += -DCAPSTONE_HAS_X86
|
||||
|
||||
LIBUCONTEXT_CFLAGS = $(CFLAGS) $(QEMU_CFLAGS)
|
||||
LIBUCONTEXT_CFLAGS += -DCUSTOM_IMPL
|
||||
|
||||
.PHONY: capstone/all
|
||||
capstone/all: .git-submodule-status
|
||||
$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) $(BUILD_DIR)/capstone/$(LIBCAPSTONE))
|
||||
@@ -562,6 +565,13 @@ slirp/all: .git-submodule-status
|
||||
CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \
|
||||
CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
|
||||
|
||||
.PHONY: libucontext/all
|
||||
libucontext/all: .git-submodule-status
|
||||
$(call quiet-command,$(MAKE) -C $(SRC_PATH)/libucontext \
|
||||
ARCH="$(ARCH)" BUILD_DIR="$(BUILD_DIR)/libucontext" \
|
||||
CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" \
|
||||
CFLAGS="$(LIBUCONTEXT_CFLAGS)" LDFLAGS="$(QEMU_LDFLAGS)")
|
||||
|
||||
$(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \
|
||||
$(qom-obj-y)
|
||||
|
||||
@@ -592,6 +602,16 @@ Makefile: $(version-obj-y)
|
||||
libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y)
|
||||
libvhost-user.a: $(libvhost-user-obj-y) $(util-obj-y) $(stub-obj-y)
|
||||
|
||||
ifdef CONFIG_DARWIN
|
||||
QEMU_IMG_SHARED_LIBRARY=libqemu-img.dylib
|
||||
else
|
||||
QEMU_IMG_SHARED_LIBRARY=libqemu-img.so
|
||||
endif
|
||||
SOBJS=$(QEMU_IMG_SHARED_LIBRARY)
|
||||
ifdef CONFIG_SHARED_LIB
|
||||
all: $(SOBJS)
|
||||
endif
|
||||
|
||||
######################################################################
|
||||
|
||||
COMMON_LDADDS = libqemuutil.a
|
||||
@@ -599,6 +619,11 @@ COMMON_LDADDS = libqemuutil.a
|
||||
qemu-img.o: qemu-img-cmds.h
|
||||
|
||||
qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
|
||||
$(QEMU_IMG_SHARED_LIBRARY): QEMU_LDFLAGS += $(LDFLAGS_SHARED)
|
||||
$(QEMU_IMG_SHARED_LIBRARY): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
$(call LINK, $(filter-out %.mak, $^))
|
||||
|
||||
qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS)
|
||||
qemu-storage-daemon$(EXESUF): qemu-storage-daemon.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(chardev-obj-y) $(io-obj-y) $(qom-obj-y) $(storage-daemon-obj-y) $(COMMON_LDADDS)
|
||||
@@ -764,6 +789,7 @@ clean: recurse-clean
|
||||
-exec rm {} +
|
||||
rm -f $(edk2-decompressed)
|
||||
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) TAGS cscope.* *.pod *~ */*~
|
||||
rm -f $(SOBJS)
|
||||
rm -f fsdev/*.pod scsi/*.pod
|
||||
rm -f qemu-img-cmds.h
|
||||
rm -f ui/shader/*-vert.h ui/shader/*-frag.h
|
||||
@@ -930,6 +956,11 @@ install: all $(if $(BUILD_DOCS),install-doc) \
|
||||
ifneq ($(TOOLS),)
|
||||
$(call install-prog,$(TOOLS),$(DESTDIR)$(bindir))
|
||||
endif
|
||||
ifdef CONFIG_SHARED_LIB
|
||||
ifneq ($(SOBJS),)
|
||||
$(call install-so,$(SOBJS),$(DESTDIR)$(libdir))
|
||||
endif
|
||||
endif
|
||||
ifneq ($(CONFIG_MODULES),)
|
||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
|
||||
for s in $(modules-m:.mo=$(DSOSUF)); do \
|
||||
|
||||
+23
-1
@@ -37,6 +37,14 @@ endif
|
||||
endif
|
||||
|
||||
PROGS=$(QEMU_PROG) $(QEMU_PROGW)
|
||||
|
||||
ifdef CONFIG_DARWIN
|
||||
QEMU_SHARED_LIBRARY=lib$(QEMU_PROG).dylib
|
||||
else
|
||||
QEMU_SHARED_LIBRARY=lib$(QEMU_PROG).so
|
||||
endif
|
||||
SOBJS=$(QEMU_SHARED_LIBRARY)
|
||||
|
||||
STPFILES=
|
||||
|
||||
config-target.h: config-target.h-timestamp
|
||||
@@ -98,7 +106,11 @@ stap:
|
||||
endif
|
||||
.PHONY: stap
|
||||
|
||||
ifdef CONFIG_SHARED_LIB
|
||||
all: $(SOBJS) stap
|
||||
else
|
||||
all: $(PROGS) stap
|
||||
endif
|
||||
|
||||
# Dummy command so that make thinks it has done something
|
||||
@true
|
||||
@@ -222,6 +234,10 @@ ifdef CONFIG_DARWIN
|
||||
$(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@")
|
||||
endif
|
||||
|
||||
$(QEMU_SHARED_LIBRARY): QEMU_LDFLAGS += $(LDFLAGS_SHARED)
|
||||
$(QEMU_SHARED_LIBRARY): $(all-obj-y) $(COMMON_LDADDS)
|
||||
$(call LINK, $(filter-out %.mak, $^))
|
||||
|
||||
gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
|
||||
$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"GEN","$(TARGET_DIR)$@")
|
||||
|
||||
@@ -232,7 +248,7 @@ hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
|
||||
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
|
||||
|
||||
clean: clean-target
|
||||
rm -f *.a *~ $(PROGS)
|
||||
rm -f *.a *~ $(PROGS) $(SOBJS)
|
||||
rm -f $(shell find . -name '*.[od]')
|
||||
rm -f hmp-commands.h gdbstub-xml.c
|
||||
rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
|
||||
@@ -257,9 +273,15 @@ $(QEMU_PROG_FUZZ): config-devices.mak $(all-obj-y) $(COMMON_LDADDS) $(fuzz-obj-y
|
||||
endif
|
||||
|
||||
install: all
|
||||
ifdef CONFIG_SHARED_LIB
|
||||
ifneq ($(SOBJS),)
|
||||
$(call install-so,$(SOBJS),$(DESTDIR)$(libdir))
|
||||
endif
|
||||
else
|
||||
ifneq ($(PROGS),)
|
||||
$(call install-prog,$(PROGS),$(DESTDIR)$(bindir))
|
||||
endif
|
||||
endif
|
||||
ifdef CONFIG_TRACE_SYSTEMTAP
|
||||
$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset"
|
||||
$(INSTALL_DATA) $(QEMU_PROG).stp-installed "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG).stp"
|
||||
|
||||
@@ -64,6 +64,8 @@ void cpu_reloading_memory_map(void)
|
||||
|
||||
void cpu_loop_exit(CPUState *cpu)
|
||||
{
|
||||
/* Unlock JIT write protect if applicable. */
|
||||
tb_exec_unlock();
|
||||
/* Undo the setting in cpu_tb_exec. */
|
||||
cpu->can_do_io = 1;
|
||||
siglongjmp(cpu->jmp_env, 1);
|
||||
|
||||
@@ -169,7 +169,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
|
||||
}
|
||||
#endif /* DEBUG_DISAS */
|
||||
|
||||
tb_exec_lock();
|
||||
ret = tcg_qemu_tb_exec(env, tb_ptr);
|
||||
tb_exec_unlock();
|
||||
cpu->can_do_io = 1;
|
||||
last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
|
||||
tb_exit = ret & TB_EXIT_MASK;
|
||||
@@ -348,7 +350,12 @@ 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;
|
||||
tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr);
|
||||
#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);
|
||||
} else {
|
||||
tb->jmp_target_arg[n] = addr;
|
||||
}
|
||||
|
||||
+26
-1
@@ -41,6 +41,7 @@ typedef struct TCGState {
|
||||
|
||||
bool mttcg_enabled;
|
||||
unsigned long tb_size;
|
||||
bool mirror_rwx;
|
||||
} TCGState;
|
||||
|
||||
#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
|
||||
@@ -120,13 +121,14 @@ static void tcg_accel_instance_init(Object *obj)
|
||||
TCGState *s = TCG_STATE(obj);
|
||||
|
||||
s->mttcg_enabled = default_mttcg_enabled();
|
||||
s->mirror_rwx = false;
|
||||
}
|
||||
|
||||
static int tcg_init(MachineState *ms)
|
||||
{
|
||||
TCGState *s = TCG_STATE(current_accel());
|
||||
|
||||
tcg_exec_init(s->tb_size * 1024 * 1024);
|
||||
tcg_exec_init(s->tb_size * 1024 * 1024, s->mirror_rwx);
|
||||
cpu_interrupt_handler = tcg_handle_interrupt;
|
||||
mttcg_enabled = s->mttcg_enabled;
|
||||
return 0;
|
||||
@@ -191,6 +193,22 @@ static void tcg_set_tb_size(Object *obj, Visitor *v,
|
||||
s->tb_size = value;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IOS_JIT
|
||||
static bool tcg_get_mirror_rwx(Object *obj, Error **errp)
|
||||
{
|
||||
TCGState *s = TCG_STATE(obj);
|
||||
|
||||
return s->mirror_rwx;
|
||||
}
|
||||
|
||||
static void tcg_set_mirror_rwx(Object *obj, bool value, Error **errp)
|
||||
{
|
||||
TCGState *s = TCG_STATE(obj);
|
||||
|
||||
s->mirror_rwx = value;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void tcg_accel_class_init(ObjectClass *oc, void *data)
|
||||
{
|
||||
AccelClass *ac = ACCEL_CLASS(oc);
|
||||
@@ -208,6 +226,13 @@ static void tcg_accel_class_init(ObjectClass *oc, void *data)
|
||||
object_class_property_set_description(oc, "tb-size",
|
||||
"TCG translation block cache size");
|
||||
|
||||
#ifdef CONFIG_IOS_JIT
|
||||
object_class_property_add_bool(oc, "mirror-rwx",
|
||||
tcg_get_mirror_rwx, tcg_set_mirror_rwx);
|
||||
object_class_property_set_description(oc, "mirror-rwx",
|
||||
"mirror map executable pages for TCG on iOS");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static const TypeInfo tcg_accel_type = {
|
||||
|
||||
+150
-12
@@ -27,6 +27,9 @@
|
||||
#include "disas/disas.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "tcg/tcg.h"
|
||||
#if defined(CONFIG_DARWIN)
|
||||
#include "tcg/tcg-apple-jit.h"
|
||||
#endif
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
#include "qemu.h"
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
@@ -59,6 +62,25 @@
|
||||
#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
|
||||
|
||||
static bool tb_exec_is_locked(void);
|
||||
static void tb_exec_change(bool locked);
|
||||
|
||||
/* #define DEBUG_TB_INVALIDATE */
|
||||
/* #define DEBUG_TB_FLUSH */
|
||||
/* make various TB consistency checks */
|
||||
@@ -301,10 +323,12 @@ static target_long decode_sleb128(uint8_t **pp)
|
||||
|
||||
static int encode_search(TranslationBlock *tb, uint8_t *block)
|
||||
{
|
||||
uint8_t *highwater = tcg_ctx->code_gen_highwater;
|
||||
uint8_t *p = block;
|
||||
uint8_t *highwater;
|
||||
uint8_t *p;
|
||||
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;
|
||||
|
||||
@@ -328,7 +352,7 @@ static int encode_search(TranslationBlock *tb, uint8_t *block)
|
||||
}
|
||||
}
|
||||
|
||||
return p - block;
|
||||
return p - (uint8_t *)TCG_CODE_PTR_RW(tcg_ctx, block);
|
||||
}
|
||||
|
||||
/* The cpu state corresponding to 'searched_pc' is restored.
|
||||
@@ -1023,12 +1047,15 @@ static inline void *split_cross_256mb(void *buf1, size_t size1)
|
||||
static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE]
|
||||
__attribute__((aligned(CODE_GEN_ALIGN)));
|
||||
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
static inline void *alloc_code_gen_buffer(bool no_rwx_pages)
|
||||
{
|
||||
void *buf = static_code_gen_buffer;
|
||||
void *end = static_code_gen_buffer + sizeof(static_code_gen_buffer);
|
||||
size_t size;
|
||||
|
||||
/* not applicable */
|
||||
assert(!no_rwx_pages);
|
||||
|
||||
/* page-align the beginning and end of the buffer */
|
||||
buf = QEMU_ALIGN_PTR_UP(buf, qemu_real_host_page_size);
|
||||
end = QEMU_ALIGN_PTR_DOWN(end, qemu_real_host_page_size);
|
||||
@@ -1057,20 +1084,32 @@ static inline void *alloc_code_gen_buffer(void)
|
||||
return buf;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
static inline void *alloc_code_gen_buffer(bool no_rwx_pages)
|
||||
{
|
||||
size_t size = tcg_ctx->code_gen_buffer_size;
|
||||
assert(!no_rwx_pages); // not applicable
|
||||
return VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT,
|
||||
PAGE_EXECUTE_READWRITE);
|
||||
}
|
||||
#else
|
||||
static inline void *alloc_code_gen_buffer(void)
|
||||
static inline void *alloc_code_gen_buffer(bool no_rwx_pages)
|
||||
{
|
||||
int prot = PROT_WRITE | PROT_READ | PROT_EXEC;
|
||||
int prot = PROT_READ | PROT_EXEC;
|
||||
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
size_t size = tcg_ctx->code_gen_buffer_size;
|
||||
void *buf;
|
||||
|
||||
#if defined(CONFIG_DARWIN) // both iOS and macOS (Apple Silicon) applicable
|
||||
if (!no_rwx_pages) {
|
||||
prot |= PROT_WRITE;
|
||||
flags |= MAP_JIT;
|
||||
}
|
||||
#else
|
||||
/* not applicable */
|
||||
assert(!no_rwx_pages);
|
||||
prot |= PROT_WRITE;
|
||||
#endif
|
||||
|
||||
buf = mmap(NULL, size, prot, flags, -1, 0);
|
||||
if (buf == MAP_FAILED) {
|
||||
return NULL;
|
||||
@@ -1117,14 +1156,65 @@ static inline void *alloc_code_gen_buffer(void)
|
||||
}
|
||||
#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */
|
||||
|
||||
static inline void code_gen_alloc(size_t tb_size)
|
||||
#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, bool mirror_rwx)
|
||||
{
|
||||
tcg_ctx->code_gen_buffer_size = size_code_gen_buffer(tb_size);
|
||||
tcg_ctx->code_gen_buffer = alloc_code_gen_buffer();
|
||||
tcg_ctx->code_gen_buffer = alloc_code_gen_buffer(mirror_rwx);
|
||||
if (tcg_ctx->code_gen_buffer == NULL) {
|
||||
fprintf(stderr, "Could not allocate dynamic translator buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
void *mirror;
|
||||
|
||||
if (mirror_rwx) {
|
||||
/* 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);
|
||||
}
|
||||
} else {
|
||||
/* If we have JIT entitlements */
|
||||
mirror = tcg_ctx->code_gen_buffer;
|
||||
}
|
||||
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)
|
||||
@@ -1150,14 +1240,15 @@ static void tb_htable_init(void)
|
||||
|
||||
/* Must be called before using the QEMU cpus. 'tb_size' is the size
|
||||
(in bytes) allocated to the translation buffer. Zero means default
|
||||
size. */
|
||||
void tcg_exec_init(unsigned long tb_size)
|
||||
size. mirror_rwx only applicable on iOS. */
|
||||
void tcg_exec_init(unsigned long tb_size, bool mirror_rwx)
|
||||
{
|
||||
tcg_allowed = true;
|
||||
cpu_gen_init();
|
||||
page_init();
|
||||
tb_htable_init();
|
||||
code_gen_alloc(tb_size);
|
||||
code_gen_alloc(tb_size, mirror_rwx);
|
||||
tb_exec_unlock();
|
||||
#if defined(CONFIG_SOFTMMU)
|
||||
/* There's no guest base to take into account, so go ahead and
|
||||
initialize the prologue now. */
|
||||
@@ -1434,8 +1525,11 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
|
||||
PageDesc *p;
|
||||
uint32_t h;
|
||||
tb_page_addr_t phys_pc;
|
||||
bool code_gen_locked;
|
||||
|
||||
assert_memory_lock();
|
||||
code_gen_locked = tb_exec_is_locked();
|
||||
tb_exec_unlock();
|
||||
|
||||
/* make sure no further incoming jumps will be chained to this TB */
|
||||
qemu_spin_lock(&tb->jmp_lock);
|
||||
@@ -1448,6 +1542,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
|
||||
tb->trace_vcpu_dstate);
|
||||
if (!(tb->cflags & CF_NOCACHE) &&
|
||||
!qht_remove(&tb_ctx.htable, tb, h)) {
|
||||
tb_exec_change(code_gen_locked);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1480,6 +1575,8 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
|
||||
|
||||
atomic_set(&tcg_ctx->tb_phys_invalidate_count,
|
||||
tcg_ctx->tb_phys_invalidate_count + 1);
|
||||
|
||||
tb_exec_change(code_gen_locked);
|
||||
}
|
||||
|
||||
static void tb_phys_invalidate__locked(TranslationBlock *tb)
|
||||
@@ -1720,6 +1817,9 @@ 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;
|
||||
@@ -2710,3 +2810,41 @@ void tcg_flush_softmmu_tlb(CPUState *cs)
|
||||
tlb_flush(cs);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CONFIG_DARWIN) && !defined(CONFIG_TCG_INTERPRETER)
|
||||
static bool tb_exec_is_locked(void)
|
||||
{
|
||||
return tcg_ctx->code_gen_locked;
|
||||
}
|
||||
|
||||
static void tb_exec_change(bool locked)
|
||||
{
|
||||
#if defined(HAVE_PTHREAD_JIT_PROTECT)
|
||||
if (__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
|
||||
pthread_jit_write_protect_np(locked);
|
||||
} else
|
||||
#endif
|
||||
if (jit_write_protect_supported()) {
|
||||
jit_write_protect(locked);
|
||||
}
|
||||
tcg_ctx->code_gen_locked = locked;
|
||||
}
|
||||
#else // not needed on non-Darwin platforms
|
||||
static bool tb_exec_is_locked(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static void tb_exec_change(bool locked) {}
|
||||
#endif
|
||||
|
||||
void tb_exec_lock(void)
|
||||
{
|
||||
// assumes sys_icache_invalidate already called
|
||||
tb_exec_change(true);
|
||||
}
|
||||
|
||||
void tb_exec_unlock(void)
|
||||
{
|
||||
tb_exec_change(false);
|
||||
}
|
||||
@@ -52,7 +52,7 @@
|
||||
#ifdef CONFIG_BSD
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/queue.h>
|
||||
#ifndef __DragonFly__
|
||||
#if !defined(__DragonFly__) && !defined(CONFIG_IOS)
|
||||
#include <sys/disk.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+39
-13
@@ -41,7 +41,7 @@
|
||||
#include "scsi/pr-manager.h"
|
||||
#include "scsi/constants.h"
|
||||
|
||||
#if defined(__APPLE__) && (__MACH__)
|
||||
#if defined(CONFIG_HOST_DEVICE) && defined(__APPLE__) && (__MACH__)
|
||||
#include <paths.h>
|
||||
#include <sys/param.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -181,7 +181,16 @@ typedef struct BDRVRawReopenState {
|
||||
bool check_cache_dropped;
|
||||
} BDRVRawReopenState;
|
||||
|
||||
static int fd_open(BlockDriverState *bs);
|
||||
static int fd_open(BlockDriverState *bs)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
|
||||
/* this is just to ensure s->fd is sane (its called by io ops) */
|
||||
if (s->fd >= 0)
|
||||
return 0;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static int64_t raw_getlength(BlockDriverState *bs);
|
||||
|
||||
typedef struct RawPosixAIOData {
|
||||
@@ -252,6 +261,12 @@ static int raw_normalize_devicepath(const char **filename, Error **errp)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_IOS)
|
||||
static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
|
||||
{
|
||||
return -ENOTSUP; // not supported on iOS
|
||||
}
|
||||
#else /* CONFIG_IOS */
|
||||
/*
|
||||
* Get logical block size via ioctl. On success store it in @sector_size_p.
|
||||
*/
|
||||
@@ -284,6 +299,7 @@ static int probe_logical_blocksize(int fd, unsigned int *sector_size_p)
|
||||
|
||||
return success ? 0 : -errno;
|
||||
}
|
||||
#endif /* !CONFIG_IOS */
|
||||
|
||||
/**
|
||||
* Get physical block size of @fd.
|
||||
@@ -1380,12 +1396,26 @@ static bool preadv_present = true;
|
||||
static ssize_t
|
||||
qemu_preadv(int fd, const struct iovec *iov, int nr_iov, off_t offset)
|
||||
{
|
||||
#ifdef CONFIG_DARWIN // preadv introduced in macOS 11
|
||||
if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
|
||||
preadv_present = false;
|
||||
return -ENOSYS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return preadv(fd, iov, nr_iov, offset);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
qemu_pwritev(int fd, const struct iovec *iov, int nr_iov, off_t offset)
|
||||
{
|
||||
#ifdef CONFIG_DARWIN // pwritev introduced in macOS 11
|
||||
if (!__builtin_available(macOS 11, iOS 14, watchOS 7, tvOS 14, *)) {
|
||||
preadv_present = false;
|
||||
return -ENOSYS;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return pwritev(fd, iov, nr_iov, offset);
|
||||
}
|
||||
|
||||
@@ -2309,7 +2339,7 @@ again:
|
||||
}
|
||||
if (size == 0)
|
||||
#endif
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#if !defined(CONFIG_IOS) && defined(__APPLE__) && defined(__MACH__)
|
||||
{
|
||||
uint64_t sectors = 0;
|
||||
uint32_t sector_size = 0;
|
||||
@@ -3251,6 +3281,8 @@ BlockDriver bdrv_file = {
|
||||
/***********************************************/
|
||||
/* host device */
|
||||
|
||||
#if defined(CONFIG_HOST_DEVICE)
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||
CFIndex maxPathSize, int flags);
|
||||
@@ -3543,16 +3575,6 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
|
||||
}
|
||||
#endif /* linux */
|
||||
|
||||
static int fd_open(BlockDriverState *bs)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
|
||||
/* this is just to ensure s->fd is sane (its called by io ops) */
|
||||
if (s->fd >= 0)
|
||||
return 0;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static coroutine_fn int
|
||||
hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
|
||||
{
|
||||
@@ -3876,6 +3898,8 @@ static BlockDriver bdrv_host_cdrom = {
|
||||
};
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#endif /* CONFIG_HOST_DEVICE */
|
||||
|
||||
static void bdrv_file_init(void)
|
||||
{
|
||||
/*
|
||||
@@ -3883,6 +3907,7 @@ static void bdrv_file_init(void)
|
||||
* registered last will get probed first.
|
||||
*/
|
||||
bdrv_register(&bdrv_file);
|
||||
#if defined(CONFIG_HOST_DEVICE)
|
||||
bdrv_register(&bdrv_host_device);
|
||||
#ifdef __linux__
|
||||
bdrv_register(&bdrv_host_cdrom);
|
||||
@@ -3890,6 +3915,7 @@ static void bdrv_file_init(void)
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
bdrv_register(&bdrv_host_cdrom);
|
||||
#endif
|
||||
#endif /* CONFIG_HOST_DEVICE */
|
||||
}
|
||||
|
||||
block_init(bdrv_file_init);
|
||||
+1
-1
@@ -910,7 +910,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* init tcg before creating CPUs and to get qemu_host_page_size */
|
||||
tcg_exec_init(0);
|
||||
tcg_exec_init(0, false);
|
||||
|
||||
cpu_type = parse_cpu_option(cpu_model);
|
||||
cpu = cpu_create(cpu_type);
|
||||
|
||||
@@ -519,6 +519,8 @@ fuzzing="no"
|
||||
rng_none="no"
|
||||
secret_keyring=""
|
||||
libdaxctl=""
|
||||
host_device_support="yes"
|
||||
shared_lib="no"
|
||||
|
||||
supported_cpu="no"
|
||||
supported_os="no"
|
||||
@@ -635,6 +637,19 @@ EOF
|
||||
compile_object
|
||||
}
|
||||
|
||||
check_ios() {
|
||||
cat > $TMPC <<EOF
|
||||
#ifdef __APPLE__
|
||||
#import "TargetConditionals.h"
|
||||
#if !TARGET_OS_IPHONE
|
||||
#error TARGET_OS_IPHONE not true
|
||||
#endif
|
||||
#endif
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
compile_object
|
||||
}
|
||||
|
||||
check_include() {
|
||||
cat > $TMPC <<EOF
|
||||
#include <$1>
|
||||
@@ -677,7 +692,11 @@ elif check_define __DragonFly__ ; then
|
||||
elif check_define __NetBSD__; then
|
||||
targetos='NetBSD'
|
||||
elif check_define __APPLE__; then
|
||||
targetos='Darwin'
|
||||
if check_ios ; then
|
||||
targetos='iOS'
|
||||
else
|
||||
targetos='Darwin'
|
||||
fi
|
||||
else
|
||||
# This is a fatal error, but don't report it yet, because we
|
||||
# might be going to just print the --help text, or it might
|
||||
@@ -867,7 +886,8 @@ Darwin)
|
||||
darwin="yes"
|
||||
hax="yes"
|
||||
hvf="yes"
|
||||
LDFLAGS_SHARED="-bundle -undefined dynamic_lookup"
|
||||
DSOSUF=".dylib"
|
||||
LDFLAGS_SHARED="-dynamiclib -undefined dynamic_lookup"
|
||||
if [ "$cpu" = "x86_64" ] ; then
|
||||
QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
|
||||
QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
|
||||
@@ -875,14 +895,36 @@ Darwin)
|
||||
cocoa="yes"
|
||||
audio_drv_list="coreaudio try-sdl"
|
||||
audio_possible_drivers="coreaudio sdl"
|
||||
QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit $QEMU_LDFLAGS"
|
||||
libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu"
|
||||
QEMU_LDFLAGS="-framework CoreFoundation -framework IOKit -lresolv $QEMU_LDFLAGS"
|
||||
libs_softmmu="-F/System/Library/Frameworks -framework IOKit $libs_softmmu"
|
||||
# Disable attempts to use ObjectiveC features in os/object.h since they
|
||||
# won't work when we're compiling with gcc as a C compiler.
|
||||
QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
|
||||
HOST_VARIANT_DIR="darwin"
|
||||
supported_os="yes"
|
||||
;;
|
||||
iOS)
|
||||
bsd="yes"
|
||||
darwin="yes"
|
||||
ios="yes"
|
||||
hax="yes"
|
||||
hvf="yes"
|
||||
DSOSUF=".dylib"
|
||||
LDFLAGS_SHARED="-dynamiclib"
|
||||
if [ "$cpu" = "x86_64" ] ; then
|
||||
QEMU_CFLAGS="-arch x86_64 $QEMU_CFLAGS"
|
||||
QEMU_LDFLAGS="-arch x86_64 $QEMU_LDFLAGS"
|
||||
fi
|
||||
host_device_support="no"
|
||||
audio_drv_list=""
|
||||
audio_possible_drivers=""
|
||||
QEMU_LDFLAGS="-framework CoreFoundation -lresolv $QEMU_LDFLAGS"
|
||||
# Disable attempts to use ObjectiveC features in os/object.h since they
|
||||
# won't work when we're compiling with gcc as a C compiler.
|
||||
QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS"
|
||||
HOST_VARIANT_DIR="ios"
|
||||
supported_os="yes"
|
||||
;;
|
||||
SunOS)
|
||||
solaris="yes"
|
||||
make="${MAKE-gmake}"
|
||||
@@ -1640,6 +1682,17 @@ for opt do
|
||||
;;
|
||||
--disable-libdaxctl) libdaxctl=no
|
||||
;;
|
||||
--enable-shared-lib)
|
||||
shared_lib=yes
|
||||
want_tools=no
|
||||
cocoa=no
|
||||
gtk=no
|
||||
sdl=no
|
||||
QEMU_CFLAGS="$QEMU_CFLAGS -fPIC"
|
||||
DSOSUF="-module$DSOSUF" # fix for make 2.81 not building target order correctly
|
||||
;;
|
||||
--disable-shared-lib) shared_lib=no
|
||||
;;
|
||||
*)
|
||||
echo "ERROR: unknown option $opt"
|
||||
echo "Try '$0 --help' for more information"
|
||||
@@ -1817,7 +1870,7 @@ Advanced options (experts only):
|
||||
--oss-lib path to OSS library
|
||||
--cpu=CPU Build for host CPU [$cpu]
|
||||
--with-coroutine=BACKEND coroutine backend. Supported options:
|
||||
ucontext, sigaltstack, windows
|
||||
ucontext, libucontext, sigaltstack, windows
|
||||
--enable-gcov enable test coverage analysis with gcov
|
||||
--gcov=GCOV use specified gcov [$gcov_tool]
|
||||
--disable-blobs disable installing provided firmware blobs
|
||||
@@ -1832,6 +1885,7 @@ Advanced options (experts only):
|
||||
enable plugins via shared library loading
|
||||
--disable-containers don't use containers for cross-building
|
||||
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
|
||||
--enable-shared-lib build QEMU as a shared library instead of an application
|
||||
|
||||
Optional features, enabled with --enable-FEATURE and
|
||||
disabled with --disable-FEATURE, default is enabled if available:
|
||||
@@ -2365,6 +2419,7 @@ if test "$cocoa" = "yes"; then
|
||||
if test "$gtk" = "yes"; then
|
||||
error_exit "Cocoa and GTK UIs cannot both be enabled at once"
|
||||
fi
|
||||
libs_softmmu="$libs_softmmu -framework Cocoa"
|
||||
gtk=no
|
||||
sdl=no
|
||||
fi
|
||||
@@ -5615,6 +5670,8 @@ if test "$coroutine" = ""; then
|
||||
coroutine=win32
|
||||
elif test "$ucontext_works" = "yes"; then
|
||||
coroutine=ucontext
|
||||
elif test "$ios" = "yes"; then
|
||||
coroutine=libucontext
|
||||
else
|
||||
coroutine=sigaltstack
|
||||
fi
|
||||
@@ -5638,12 +5695,29 @@ else
|
||||
error_exit "only the 'windows' coroutine backend is valid for Windows"
|
||||
fi
|
||||
;;
|
||||
libucontext)
|
||||
;;
|
||||
*)
|
||||
error_exit "unknown coroutine backend $coroutine"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case $coroutine in
|
||||
libucontext)
|
||||
git_submodules="${git_submodules} libucontext"
|
||||
mkdir -p libucontext
|
||||
QEMU_CFLAGS="$QEMU_CFLAGS -I\$(SRC_PATH)/libucontext/include"
|
||||
LIBS="-L\$(BUILD_DIR)/libucontext -lucontext $LIBS"
|
||||
;;
|
||||
esac
|
||||
|
||||
if test "$coroutine" == "libucontext"; then
|
||||
coroutine_impl=ucontext
|
||||
else
|
||||
coroutine_impl=$coroutine
|
||||
fi
|
||||
|
||||
if test "$coroutine_pool" = ""; then
|
||||
coroutine_pool=yes
|
||||
fi
|
||||
@@ -6514,6 +6588,21 @@ EOF
|
||||
fi
|
||||
fi
|
||||
|
||||
##########################################
|
||||
# check for Apple Silicon JIT function
|
||||
|
||||
if [ "$darwin" = "yes" ] ; then
|
||||
cat > $TMPC << EOF
|
||||
#include <pthread.h>
|
||||
int main() { pthread_jit_write_protect_np(0); return 0; }
|
||||
EOF
|
||||
if ! compile_prog ""; then
|
||||
have_pthread_jit_protect='no'
|
||||
else
|
||||
have_pthread_jit_protect='yes'
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
##########################################
|
||||
# End of CC checks
|
||||
@@ -7019,6 +7108,8 @@ echo "fuzzing support $fuzzing"
|
||||
echo "gdb $gdb_bin"
|
||||
echo "rng-none $rng_none"
|
||||
echo "Linux keyring $secret_keyring"
|
||||
echo "host device support $host_device_support"
|
||||
echo "build shared lib $shared_lib"
|
||||
|
||||
if test "$supported_cpu" = "no"; then
|
||||
echo
|
||||
@@ -7089,6 +7180,12 @@ if test "$default_devices" = "yes" ; then
|
||||
else
|
||||
echo "CONFIG_MINIKCONF_MODE=--allnoconfig" >> $config_host_mak
|
||||
fi
|
||||
if test "$host_device_support" = "yes" ; then
|
||||
echo "CONFIG_HOST_DEVICE=y" >> $config_host_mak
|
||||
fi
|
||||
if test "$shared_lib" = "yes" ; then
|
||||
echo "CONFIG_SHARED_LIB=y" >> $config_host_mak
|
||||
fi
|
||||
if test "$debug_tcg" = "yes" ; then
|
||||
echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
|
||||
fi
|
||||
@@ -7138,6 +7235,11 @@ if test "$darwin" = "yes" ; then
|
||||
echo "CONFIG_DARWIN=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$ios" = "yes" ; then
|
||||
echo "CONFIG_IOS=y" >> $config_host_mak
|
||||
echo "CONFIG_IOS_JIT=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$solaris" = "yes" ; then
|
||||
echo "CONFIG_SOLARIS=y" >> $config_host_mak
|
||||
fi
|
||||
@@ -7638,7 +7740,7 @@ if test "$rbd" = "yes" ; then
|
||||
echo "RBD_LIBS=$rbd_libs" >> $config_host_mak
|
||||
fi
|
||||
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine_impl" >> $config_host_mak
|
||||
if test "$coroutine_pool" = "yes" ; then
|
||||
echo "CONFIG_COROUTINE_POOL=1" >> $config_host_mak
|
||||
else
|
||||
@@ -7934,6 +8036,10 @@ if test "$secret_keyring" = "yes" ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$have_pthread_jit_protect" = "yes" ; then
|
||||
echo "HAVE_PTHREAD_JIT_PROTECT=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$tcg_interpreter" = "yes"; then
|
||||
QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES"
|
||||
elif test "$ARCH" = "sparc64" ; then
|
||||
@@ -8500,6 +8606,10 @@ fi
|
||||
if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then
|
||||
echo "config-host.h: capstone/all" >> $config_host_mak
|
||||
fi
|
||||
if [ "$coroutine" = "libucontext" ]; then
|
||||
echo "config-host.h: libucontext/all" >> $config_host_mak
|
||||
echo "CONFIG_LIBUCONTEXT=y" >> $config_host_mak
|
||||
fi
|
||||
if test -n "$LIBCAPSTONE"; then
|
||||
echo "LIBCAPSTONE=$LIBCAPSTONE" >> $config_host_mak
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
===========
|
||||
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``
|
||||
configuration variables.
|
||||
|
||||
Build support
|
||||
-------------
|
||||
|
||||
For the code to compile, certain changes in the block driver and the slirp
|
||||
driver had to be made. There is no ``system()`` call, so code requiring it had
|
||||
to be disabled.
|
||||
|
||||
``ucontext`` support is broken on iOS. The implementation from ``libucontext``
|
||||
is used instead.
|
||||
|
||||
Because ``fork()`` is not allowed on iOS apps, the option to build qemu and the
|
||||
utilities as shared libraries is added. Note that because qemu does not perform
|
||||
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
|
||||
-----------
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
.. _bulletproof JIT: https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf
|
||||
@@ -483,6 +483,13 @@ 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;
|
||||
#endif
|
||||
};
|
||||
|
||||
extern bool parallel_cpus;
|
||||
@@ -513,6 +520,8 @@ TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
|
||||
target_ulong cs_base, uint32_t flags,
|
||||
uint32_t cf_mask);
|
||||
void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
|
||||
void tb_exec_lock(void);
|
||||
void tb_exec_unlock(void);
|
||||
|
||||
/* GETPC is the true target of the return instruction that we'll execute. */
|
||||
#if defined(CONFIG_TCG_INTERPRETER)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef SYSEMU_TCG_H
|
||||
#define SYSEMU_TCG_H
|
||||
|
||||
void tcg_exec_init(unsigned long tb_size);
|
||||
void tcg_exec_init(unsigned long tb_size, bool mirror_rwx);
|
||||
#ifdef CONFIG_TCG
|
||||
extern bool tcg_allowed;
|
||||
#define tcg_enabled() (tcg_allowed)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Apple Silicon APRR functions for JIT handling
|
||||
*
|
||||
* Copyright (c) 2020 osy
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Credits to: https://siguza.github.io/APRR/
|
||||
// Reversed from /usr/lib/system/libsystem_pthread.dylib
|
||||
|
||||
#ifndef TCG_APPLE_JIT_H
|
||||
#define TCG_APPLE_JIT_H
|
||||
|
||||
#if defined(__aarch64__) && defined(CONFIG_DARWIN)
|
||||
|
||||
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
|
||||
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS+0x10C)
|
||||
#define _COMM_PAGE_APPR_WRITE_ENABLE (_COMM_PAGE_START_ADDRESS+0x110)
|
||||
#define _COMM_PAGE_APRR_WRITE_DISABLE (_COMM_PAGE_START_ADDRESS+0x118)
|
||||
|
||||
static __attribute__ ((__always_inline__)) bool jit_write_protect_supported(void)
|
||||
{
|
||||
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
|
||||
return aprr_support > 0;
|
||||
}
|
||||
|
||||
static __attribute__ ((__always_inline__)) void jit_write_protect(int enabled) // write protect enable = write disable
|
||||
{
|
||||
uint8_t aprr_support = *(volatile uint8_t *)_COMM_PAGE_APRR_SUPPORT;
|
||||
if (aprr_support == 0 || aprr_support > 3) {
|
||||
return;
|
||||
} else if (aprr_support == 1) {
|
||||
__asm__ __volatile__ (
|
||||
"mov x0, %0\n"
|
||||
"ldr x0, [x0]\n"
|
||||
"msr S3_4_c15_c2_7, x0\n"
|
||||
"isb sy\n"
|
||||
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE : _COMM_PAGE_APPR_WRITE_ENABLE) : "memory", "x0"
|
||||
);
|
||||
} else {
|
||||
__asm__ __volatile__ (
|
||||
"mov x0, %0\n"
|
||||
"ldr x0, [x0]\n"
|
||||
"msr S3_6_c15_c1_5, x0\n"
|
||||
"isb sy\n"
|
||||
:: "r" (enabled ? _COMM_PAGE_APRR_WRITE_DISABLE : _COMM_PAGE_APPR_WRITE_ENABLE) : "memory", "x0"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#else // defined(__aarch64__) && defined(CONFIG_DARWIN)
|
||||
|
||||
static __attribute__ ((__always_inline__)) bool jit_write_protect_supported(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static __attribute__ ((__always_inline__)) void jit_write_protect(int enabled)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // define TCG_APPLE_JIT_H
|
||||
+17
-4
@@ -261,7 +261,7 @@ struct TCGLabel {
|
||||
unsigned refs : 16;
|
||||
union {
|
||||
uintptr_t value;
|
||||
tcg_insn_unit *value_ptr;
|
||||
const tcg_insn_unit *value_ptr;
|
||||
} u;
|
||||
QSIMPLEQ_HEAD(, TCGRelocation) relocs;
|
||||
QSIMPLEQ_ENTRY(TCGLabel) next;
|
||||
@@ -593,7 +593,7 @@ struct TCGContext {
|
||||
int nb_ops;
|
||||
|
||||
/* goto_tb support */
|
||||
tcg_insn_unit *code_buf;
|
||||
const 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 */
|
||||
@@ -627,6 +627,12 @@ 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;
|
||||
#endif
|
||||
#if defined(CONFIG_DARWIN) && !defined(CONFIG_TCG_INTERPRETER)
|
||||
bool code_gen_locked; // on Darwin each thread tracks W^X flags
|
||||
#endif
|
||||
|
||||
/* Threshold to flush the translated code buffer. */
|
||||
void *code_gen_highwater;
|
||||
@@ -677,6 +683,13 @@ 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;
|
||||
@@ -1090,7 +1103,7 @@ static inline TCGLabel *arg_label(TCGArg i)
|
||||
* correct result.
|
||||
*/
|
||||
|
||||
static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b)
|
||||
static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
@@ -1104,7 +1117,7 @@ static inline ptrdiff_t tcg_ptr_byte_diff(void *a, void *b)
|
||||
* to the destination address.
|
||||
*/
|
||||
|
||||
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, void *target)
|
||||
static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
|
||||
{
|
||||
return tcg_ptr_byte_diff(target, s->code_ptr);
|
||||
}
|
||||
|
||||
Submodule
+1
Submodule libucontext added at 148ec4c5b6.
+1
-1
@@ -705,7 +705,7 @@ int main(int argc, char **argv, char **envp)
|
||||
cpu_type = parse_cpu_option(cpu_model);
|
||||
|
||||
/* init tcg before creating CPUs and to get qemu_host_page_size */
|
||||
tcg_exec_init(0);
|
||||
tcg_exec_init(0, false);
|
||||
|
||||
cpu = cpu_create(cpu_type);
|
||||
env = cpu->env_ptr;
|
||||
|
||||
+8
-8
@@ -27,7 +27,7 @@
|
||||
#include "net/slirp.h"
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
#include <pwd.h>
|
||||
#include <sys/wait.h>
|
||||
#endif
|
||||
@@ -90,7 +90,7 @@ typedef struct SlirpState {
|
||||
Slirp *slirp;
|
||||
Notifier poll_notifier;
|
||||
Notifier exit_notifier;
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
gchar *smb_dir;
|
||||
#endif
|
||||
GSList *fwd;
|
||||
@@ -103,7 +103,7 @@ static QTAILQ_HEAD(, SlirpState) slirp_stacks =
|
||||
static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp);
|
||||
static int slirp_guestfwd(SlirpState *s, const char *config_str, Error **errp);
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
static int slirp_smb(SlirpState *s, const char *exported_dir,
|
||||
struct in_addr vserver_addr, Error **errp);
|
||||
static void slirp_smb_cleanup(SlirpState *s);
|
||||
@@ -368,7 +368,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
struct in6_addr ip6_prefix;
|
||||
struct in6_addr ip6_host;
|
||||
struct in6_addr ip6_dns;
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
struct in_addr smbsrv = { .s_addr = 0 };
|
||||
#endif
|
||||
NetClientState *nc;
|
||||
@@ -478,7 +478,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
|
||||
error_setg(errp, "Failed to parse SMB address");
|
||||
return -1;
|
||||
@@ -593,7 +593,7 @@ static int net_slirp_init(NetClientState *peer, const char *model,
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
if (smb_export) {
|
||||
if (slirp_smb(s, smb_export, smbsrv, errp) < 0) {
|
||||
goto error;
|
||||
@@ -785,7 +785,7 @@ void hmp_hostfwd_add(Monitor *mon, const QDict *qdict)
|
||||
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(CONFIG_IOS)
|
||||
|
||||
/* automatic user mode samba server configuration */
|
||||
static void slirp_smb_cleanup(SlirpState *s)
|
||||
@@ -900,7 +900,7 @@ static int slirp_smb(SlirpState* s, const char *exported_dir,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !defined(_WIN32) */
|
||||
#endif /* !defined(_WIN32) && !defined(CONFIG_IOS) */
|
||||
|
||||
static int guestfwd_can_read(void *opaque)
|
||||
{
|
||||
|
||||
@@ -50,6 +50,11 @@
|
||||
#include "crypto/init.h"
|
||||
#include "trace/control.h"
|
||||
|
||||
#if defined(CONFIG_SHARED_LIB)
|
||||
#undef main
|
||||
#define main qemu_img_main
|
||||
#endif
|
||||
|
||||
#define QEMU_IMG_VERSION "qemu-img version " QEMU_FULL_VERSION \
|
||||
"\n" QEMU_COPYRIGHT "\n"
|
||||
|
||||
|
||||
@@ -123,6 +123,9 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel,
|
||||
" igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n"
|
||||
" kernel-irqchip=on|off|split controls accelerated irqchip support (default=on)\n"
|
||||
" kvm-shadow-mem=size of KVM shadow MMU in bytes\n"
|
||||
#ifdef CONFIG_IOS_JIT
|
||||
" mirror-rwx=on|off (mirror map executable pages for TCG on iOS)\n"
|
||||
#endif
|
||||
" tb-size=n (TCG translation block cache size)\n"
|
||||
" thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL)
|
||||
SRST
|
||||
@@ -148,6 +151,14 @@ SRST
|
||||
``kvm-shadow-mem=size``
|
||||
Defines the size of the KVM shadow MMU.
|
||||
|
||||
#ifdef CONFIG_IOS_JIT
|
||||
|
||||
``mirror-rwx=on|off``
|
||||
Only applicable to TCG running on iOS hosts. When enabled, TB code
|
||||
is written to a mirror mapped address separate from the address that is
|
||||
executed. By default, this is disabled.
|
||||
#endif
|
||||
|
||||
``tb-size=n``
|
||||
Controls the size (in MiB) of the TCG translation block cache.
|
||||
|
||||
|
||||
@@ -34,6 +34,12 @@
|
||||
|
||||
#ifndef CONFIG_HAS_ENVIRON
|
||||
#ifdef __APPLE__
|
||||
#include "TargetConditionals.h"
|
||||
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
|
||||
#define APPLE_USE_CRT_EXTERNS
|
||||
#endif
|
||||
#endif
|
||||
#ifdef APPLE_USE_CRT_EXTERNS
|
||||
#include <crt_externs.h>
|
||||
#define environ (*_NSGetEnviron())
|
||||
#else
|
||||
|
||||
@@ -154,6 +154,12 @@ define install-prog
|
||||
$(if $(STRIP),$(STRIP) $(foreach T,$1,"$2/$(notdir $T)"),)
|
||||
endef
|
||||
|
||||
# install-so list, dir
|
||||
define install-so
|
||||
$(INSTALL_DIR) "$2"
|
||||
$(INSTALL_LIB) $1 "$2"
|
||||
endef
|
||||
|
||||
# find-in-path
|
||||
# Usage: $(call find-in-path, prog)
|
||||
# Looks in the PATH if the argument contains no slash, else only considers one
|
||||
|
||||
+1
-1
Submodule slirp updated: ce94eba204...452c389d82.
@@ -891,6 +891,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)
|
||||
return clock() / (CLOCKS_PER_SEC / 100);
|
||||
case TARGET_SYS_TIME:
|
||||
return set_swi_errno(env, time(NULL));
|
||||
#if !defined(CONFIG_IOS) // iOS does not have system()
|
||||
case TARGET_SYS_SYSTEM:
|
||||
GET_ARG(0);
|
||||
GET_ARG(1);
|
||||
@@ -907,6 +908,7 @@ target_ulong do_arm_semihosting(CPUARMState *env)
|
||||
unlock_user(s, arg0, 0);
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_IOS */
|
||||
case TARGET_SYS_ERRNO:
|
||||
return get_swi_errno(env);
|
||||
case TARGET_SYS_GET_CMDLINE:
|
||||
|
||||
@@ -402,6 +402,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
|
||||
result = isatty(arg0);
|
||||
}
|
||||
break;
|
||||
#if !defined(CONFIG_IOS) // iOS does not have system()
|
||||
case HOSTED_SYSTEM:
|
||||
GET_ARG(0);
|
||||
GET_ARG(1);
|
||||
@@ -420,6 +421,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_IOS */
|
||||
case HOSTED_INIT_SIM:
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
{
|
||||
|
||||
@@ -426,6 +426,7 @@ void do_nios2_semihosting(CPUNios2State *env)
|
||||
result = isatty(arg0);
|
||||
}
|
||||
break;
|
||||
#if !defined(CONFIG_IOS) // iOS does not have system()
|
||||
case HOSTED_SYSTEM:
|
||||
GET_ARG(0);
|
||||
GET_ARG(1);
|
||||
@@ -444,6 +445,7 @@ void do_nios2_semihosting(CPUNios2State *env)
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
qemu_log_mask(LOG_GUEST_ERROR, "nios2-semihosting: unsupported "
|
||||
"semihosting syscall %d\n", nr);
|
||||
|
||||
@@ -149,12 +149,33 @@ typedef enum {
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
#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)
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
sys_icache_invalidate((char *)start, stop-start);
|
||||
#elif defined(__GNUC__)
|
||||
__builtin___clear_cache((char *)start, (char *)stop);
|
||||
#else
|
||||
#error "Missing builtin to flush instruction cache"
|
||||
#endif
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
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
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
@@ -78,38 +78,44 @@ static const int tcg_target_call_oarg_regs[1] = {
|
||||
#define TCG_REG_GUEST_BASE TCG_REG_X28
|
||||
#endif
|
||||
|
||||
static inline bool reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static inline bool reloc_pc26(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const 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. */
|
||||
*code_ptr = deposit32(*code_ptr, 0, 26, offset);
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, code_ptr), 0, 26, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static inline bool reloc_pc19(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - code_ptr;
|
||||
if (offset == sextract64(offset, 0, 19)) {
|
||||
*code_ptr = deposit32(*code_ptr, 5, 19, offset);
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, code_ptr), 5, 19, offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static inline bool patch_reloc(TCGContext *s, 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(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc26(s, code_ptr, (tcg_insn_unit *)value);
|
||||
case R_AARCH64_CONDBR19:
|
||||
return reloc_pc19(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc19(s, code_ptr, (tcg_insn_unit *)value);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
@@ -1309,14 +1315,14 @@ static void tcg_out_cmp(TCGContext *s, TCGType ext, TCGReg a,
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)
|
||||
static inline void tcg_out_goto(TCGContext *s, const 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, tcg_insn_unit *target)
|
||||
static inline void tcg_out_goto_long(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
@@ -1332,7 +1338,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, tcg_insn_unit *target)
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = target - s->code_ptr;
|
||||
if (offset == sextract64(offset, 0, 26)) {
|
||||
@@ -1344,7 +1350,7 @@ static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target)
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr,
|
||||
uintptr_t addr)
|
||||
uintptr_t addr, uintptr_t wr_addr)
|
||||
{
|
||||
tcg_insn_unit i1, i2;
|
||||
TCGType rt = TCG_TYPE_I64;
|
||||
@@ -1365,7 +1371,10 @@ 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 *)jmp_addr, pair);
|
||||
atomic_set((uint64_t *)wr_addr, pair);
|
||||
#if defined(CONFIG_IOS_JIT)
|
||||
flush_dcache_range(wr_addr, wr_addr + 8);
|
||||
#endif
|
||||
flush_icache_range(jmp_addr, jmp_addr + 8);
|
||||
}
|
||||
|
||||
@@ -1571,7 +1580,7 @@ static void * const qemu_st_helpers[16] = {
|
||||
[MO_BEQ] = helper_be_stq_mmu,
|
||||
};
|
||||
|
||||
static inline void tcg_out_adr(TCGContext *s, TCGReg rd, void *target)
|
||||
static inline void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, target);
|
||||
tcg_debug_assert(offset == sextract64(offset, 0, 21));
|
||||
@@ -1584,7 +1593,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(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc19(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1609,7 +1618,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(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc19(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1625,7 +1634,8 @@ 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,
|
||||
tcg_insn_unit *raddr, tcg_insn_unit *label_ptr)
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1852,7 +1862,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
|
||||
#endif /* CONFIG_SOFTMMU */
|
||||
}
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg args[TCG_MAX_OP_ARGS],
|
||||
@@ -2919,11 +2929,11 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_insn(s, 3207, RET, TCG_REG_LR);
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
p[i] = NOP;
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = NOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,8 +139,15 @@ 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);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+19
-14
@@ -187,17 +187,22 @@ static const uint8_t tcg_cond_to_arm_cond[] = {
|
||||
[TCG_COND_GTU] = COND_HI,
|
||||
};
|
||||
|
||||
static inline bool reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static inline bool reloc_pc24(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2;
|
||||
if (offset == sextract32(offset, 0, 24)) {
|
||||
*code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) =
|
||||
(*TCG_CODE_PTR_RW(s, code_ptr) & ~0xffffff) | (offset & 0xffffff);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool reloc_pc13(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static inline bool reloc_pc13(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t offset = tcg_ptr_byte_diff(target, code_ptr) - 8;
|
||||
|
||||
@@ -209,21 +214,21 @@ static inline bool reloc_pc13(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
}
|
||||
insn = deposit32(insn, 23, 1, u);
|
||||
insn = deposit32(insn, 0, 12, offset);
|
||||
*code_ptr = insn;
|
||||
*TCG_CODE_PTR_RW(s, code_ptr) = insn;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, 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(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc24(s, code_ptr, (tcg_insn_unit *)value);
|
||||
} else if (type == R_ARM_PC13) {
|
||||
return reloc_pc13(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_pc13(s, code_ptr, (tcg_insn_unit *)value);
|
||||
} else {
|
||||
g_assert_not_reached();
|
||||
}
|
||||
@@ -1022,7 +1027,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, tcg_insn_unit *addr)
|
||||
static void tcg_out_goto(TCGContext *s, int cond, const tcg_insn_unit *addr)
|
||||
{
|
||||
intptr_t addri = (intptr_t)addr;
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, addr);
|
||||
@@ -1036,7 +1041,7 @@ static void tcg_out_goto(TCGContext *s, int cond, 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, tcg_insn_unit *addr)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *addr)
|
||||
{
|
||||
intptr_t addri = (intptr_t)addr;
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, addr);
|
||||
@@ -1329,7 +1334,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, tcg_insn_unit *raddr,
|
||||
TCGReg addrhi, const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
@@ -1351,7 +1356,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
|
||||
MemOp opc = get_memop(oi);
|
||||
void *func;
|
||||
|
||||
if (!reloc_pc24(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc24(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1414,7 +1419,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(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc24(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2258,11 +2263,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(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
p[i] = INSN_NOP;
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = INSN_NOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-2
@@ -207,16 +207,36 @@ 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 jmp_addr, uintptr_t addr,
|
||||
uintptr_t wr_addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
|
||||
atomic_set((int32_t *)wr_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 tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
value += addend;
|
||||
@@ -179,14 +179,14 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
}
|
||||
/* FALLTHRU */
|
||||
case R_386_32:
|
||||
tcg_patch32(code_ptr, value);
|
||||
tcg_patch32(s, code_ptr, value);
|
||||
break;
|
||||
case R_386_PC8:
|
||||
value -= (uintptr_t)code_ptr;
|
||||
if (value != (int8_t)value) {
|
||||
return false;
|
||||
}
|
||||
tcg_patch8(code_ptr, value);
|
||||
tcg_patch8(s, 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, tcg_insn_unit *dest)
|
||||
static void tcg_out_branch(TCGContext *s, int call, const 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, tcg_insn_unit *dest)
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
{
|
||||
tcg_out_branch(s, 1, dest);
|
||||
}
|
||||
|
||||
static void tcg_out_jmp(TCGContext *s, tcg_insn_unit *dest)
|
||||
static void tcg_out_jmp(TCGContext *s, const 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,
|
||||
tcg_insn_unit *raddr,
|
||||
const 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(label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
tcg_patch32(s, label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) {
|
||||
tcg_patch32(label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
tcg_patch32(s, 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(label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
tcg_patch32(s, label_ptr[0], s->code_ptr - label_ptr[0] - 4);
|
||||
if (TARGET_LONG_BITS > TCG_TARGET_REG_BITS) {
|
||||
tcg_patch32(label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
tcg_patch32(s, label_ptr[1], s->code_ptr - label_ptr[1] - 4);
|
||||
}
|
||||
|
||||
if (TCG_TARGET_REG_BITS == 32) {
|
||||
@@ -3853,9 +3853,9 @@ static void tcg_target_qemu_prologue(TCGContext *s)
|
||||
tcg_out_opc(s, OPC_RET, 0, 0, 0);
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
memset(p, 0x90, count);
|
||||
memset(TCG_CODE_PTR_RW(s, p), 0x90, count);
|
||||
}
|
||||
|
||||
static void tcg_target_init(TCGContext *s)
|
||||
|
||||
@@ -212,7 +212,13 @@ 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);
|
||||
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
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
#define TCG_TARGET_NEED_LDST_LABELS
|
||||
|
||||
+37
-25
@@ -139,12 +139,13 @@ static const TCGReg tcg_target_call_oarg_regs[2] = {
|
||||
TCG_REG_V1
|
||||
};
|
||||
|
||||
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 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 inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static inline uint32_t reloc_pc16_val(const tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
/* Let the compiler perform the right-shift as part of the arithmetic. */
|
||||
ptrdiff_t disp = target - (pc + 1);
|
||||
@@ -152,28 +153,35 @@ static inline uint32_t reloc_pc16_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
return disp & 0xffff;
|
||||
}
|
||||
|
||||
static inline void reloc_pc16(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static inline void reloc_pc16(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
*pc = deposit32(*pc, 0, 16, reloc_pc16_val(pc, target));
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, pc), 0, 16, reloc_pc16_val(pc, target));
|
||||
}
|
||||
|
||||
static inline uint32_t reloc_26_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static inline uint32_t reloc_26_val(const tcg_insn_unit *pc,
|
||||
const 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(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static inline void reloc_26(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
*pc = deposit32(*pc, 0, 26, reloc_26_val(pc, target));
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
deposit32(*TCG_CODE_PTR_RW(s, pc), 0, 26, reloc_26_val(pc, target));
|
||||
}
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, 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(code_ptr, (tcg_insn_unit *)value);
|
||||
reloc_pc16(s, code_ptr, (tcg_insn_unit *)value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -519,7 +527,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, void *target)
|
||||
static bool tcg_out_opc_jmp(TCGContext *s, MIPSInsn opc, const void *target)
|
||||
{
|
||||
uintptr_t dest = (uintptr_t)target;
|
||||
uintptr_t from = (uintptr_t)s->code_ptr + 4;
|
||||
@@ -634,7 +642,7 @@ static inline void tcg_out_bswap16s(TCGContext *s, TCGReg ret, TCGReg arg)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_bswap_subr(TCGContext *s, tcg_insn_unit *sub)
|
||||
static void tcg_out_bswap_subr(TCGContext *s, const tcg_insn_unit *sub)
|
||||
{
|
||||
bool ok = tcg_out_opc_jmp(s, OPC_JAL, sub);
|
||||
tcg_debug_assert(ok);
|
||||
@@ -928,7 +936,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->code_ptr - 1, l->u.value_ptr);
|
||||
reloc_pc16(s, s->code_ptr - 1, l->u.value_ptr);
|
||||
} else {
|
||||
tcg_out_reloc(s, s->code_ptr - 1, R_MIPS_PC16, l, 0);
|
||||
}
|
||||
@@ -1082,7 +1090,7 @@ static void tcg_out_movcond(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
static void tcg_out_call_int(TCGContext *s, const 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. */
|
||||
@@ -1100,7 +1108,7 @@ static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
tcg_out_nop(s);
|
||||
@@ -1292,7 +1300,8 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
TCGType ext,
|
||||
TCGReg datalo, TCGReg datahi,
|
||||
TCGReg addrlo, TCGReg addrhi,
|
||||
void *raddr, tcg_insn_unit *label_ptr[2])
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr[2])
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1318,9 +1327,9 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
int i;
|
||||
|
||||
/* resolve label address */
|
||||
reloc_pc16(l->label_ptr[0], s->code_ptr);
|
||||
reloc_pc16(s, l->label_ptr[0], s->code_ptr);
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
reloc_pc16(l->label_ptr[1], s->code_ptr);
|
||||
reloc_pc16(s, l->label_ptr[1], s->code_ptr);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
@@ -1348,7 +1357,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->code_ptr - 1, l->raddr);
|
||||
reloc_pc16(s, s->code_ptr - 1, l->raddr);
|
||||
|
||||
/* delay slot */
|
||||
if (TCG_TARGET_REG_BITS == 64 && l->type == TCG_TYPE_I32) {
|
||||
@@ -1368,9 +1377,9 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
int i;
|
||||
|
||||
/* resolve label address */
|
||||
reloc_pc16(l->label_ptr[0], s->code_ptr);
|
||||
reloc_pc16(s, l->label_ptr[0], s->code_ptr);
|
||||
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
|
||||
reloc_pc16(l->label_ptr[1], s->code_ptr);
|
||||
reloc_pc16(s, l->label_ptr[1], s->code_ptr);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
@@ -2433,7 +2442,7 @@ static void tcg_target_detect_isa(void)
|
||||
sigaction(SIGILL, &sa_old, NULL);
|
||||
}
|
||||
|
||||
static tcg_insn_unit *align_code_ptr(TCGContext *s)
|
||||
static const tcg_insn_unit *align_code_ptr(TCGContext *s)
|
||||
{
|
||||
uintptr_t p = (uintptr_t)s->code_ptr;
|
||||
if (p & 15) {
|
||||
@@ -2660,9 +2669,12 @@ 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 addr, uintptr_t wr_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);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,13 @@ 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);
|
||||
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
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
|
||||
|
||||
+33
-18
@@ -62,7 +62,7 @@
|
||||
#define TCG_CT_CONST_MONE 0x2000
|
||||
#define TCG_CT_CONST_WSZ 0x4000
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
TCGPowerISA have_isa;
|
||||
static bool have_isel;
|
||||
@@ -184,35 +184,43 @@ static inline bool in_range_b(tcg_target_long target)
|
||||
return target == sextract64(target, 0, 26);
|
||||
}
|
||||
|
||||
static uint32_t reloc_pc24_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static uint32_t reloc_pc24_val(const tcg_insn_unit *pc,
|
||||
const 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(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static bool reloc_pc24(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
if (in_range_b(disp)) {
|
||||
*pc = (*pc & ~0x3fffffc) | (disp & 0x3fffffc);
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
(*TCG_CODE_PTR_RW(s, pc) & ~0x3fffffc) | (disp & 0x3fffffc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static uint16_t reloc_pc14_val(const tcg_insn_unit *pc,
|
||||
const 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(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||
static bool reloc_pc14(TCGContext *s,
|
||||
tcg_insn_unit *pc,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_ptr_byte_diff(target, pc);
|
||||
if (disp == (int16_t) disp) {
|
||||
*pc = (*pc & ~0xfffc) | (disp & 0xfffc);
|
||||
*TCG_CODE_PTR_RW(s, pc) =
|
||||
(*TCG_CODE_PTR_RW(s, pc) & ~0xfffc) | (disp & 0xfffc);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -674,7 +682,7 @@ static const uint32_t tcg_to_isel[] = {
|
||||
[TCG_COND_GTU] = ISEL | BC_(7, CR_GT),
|
||||
};
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
tcg_insn_unit *target;
|
||||
@@ -686,9 +694,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
|
||||
switch (type) {
|
||||
case R_PPC_REL14:
|
||||
return reloc_pc14(code_ptr, target);
|
||||
return reloc_pc14(s, code_ptr, target);
|
||||
case R_PPC_REL24:
|
||||
return reloc_pc24(code_ptr, target);
|
||||
return reloc_pc24(s, code_ptr, target);
|
||||
case R_PPC_ADDR16:
|
||||
/*
|
||||
* We are (slightly) abusing this relocation type. In particular,
|
||||
@@ -1110,7 +1118,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, tcg_insn_unit *target)
|
||||
static void tcg_out_b(TCGContext *s, int mask, const tcg_insn_unit *target)
|
||||
{
|
||||
ptrdiff_t disp = tcg_pcrel_diff(s, target);
|
||||
if (in_range_b(disp)) {
|
||||
@@ -1727,7 +1735,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 addr, uintptr_t wr_addr)
|
||||
{
|
||||
if (TCG_TARGET_REG_BITS == 64) {
|
||||
tcg_insn_unit i1, i2;
|
||||
@@ -1757,16 +1765,22 @@ 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, tcg_insn_unit *target)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
|
||||
{
|
||||
#ifdef _CALL_AIX
|
||||
/* Look through the descriptor. If the branch is in range, and we
|
||||
@@ -1991,7 +2005,8 @@ 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,
|
||||
tcg_insn_unit *raddr, tcg_insn_unit *lptr)
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *lptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -2011,7 +2026,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(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc14(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2059,7 +2074,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(lb->label_ptr[0], s->code_ptr)) {
|
||||
if (!reloc_pc14(s, lb->label_ptr[0], s->code_ptr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2256,11 +2271,11 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
p[i] = NOP;
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = NOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,8 +164,15 @@ 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);
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
||||
|
||||
#define TCG_TARGET_DEFAULT_MO (0)
|
||||
|
||||
|
||||
+29
-22
@@ -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(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
p[i] = encode_i(OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0);
|
||||
(TCG_CODE_PTR_RW(s, p))[i] = encode_i(OPC_ADDI, TCG_REG_ZERO, TCG_REG_ZERO, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,46 +427,52 @@ static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
|
||||
* Relocations
|
||||
*/
|
||||
|
||||
static bool reloc_sbimm12(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_sbimm12(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
|
||||
if (offset == sextreg(offset, 1, 12) << 1) {
|
||||
code_ptr[0] |= encode_sbimm12(offset);
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[0] |= encode_sbimm12(offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_jimm20(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_jimm20(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const tcg_insn_unit *target)
|
||||
{
|
||||
intptr_t offset = (intptr_t)target - (intptr_t)code_ptr;
|
||||
|
||||
if (offset == sextreg(offset, 1, 20) << 1) {
|
||||
code_ptr[0] |= encode_ujimm20(offset);
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[0] |= encode_ujimm20(offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool reloc_call(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||
static bool reloc_call(TCGContext *s,
|
||||
tcg_insn_unit *code_ptr,
|
||||
const 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) {
|
||||
code_ptr[0] |= encode_uimm20(hi);
|
||||
code_ptr[1] |= encode_imm12(lo);
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[0] |= encode_uimm20(hi);
|
||||
(TCG_CODE_PTR_RW(s, code_ptr))[1] |= encode_imm12(lo);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
uint32_t insn = *code_ptr;
|
||||
@@ -480,7 +486,7 @@ static bool patch_reloc(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(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_sbimm12(s, code_ptr, (tcg_insn_unit *)value);
|
||||
} else {
|
||||
/* Invert the condition */
|
||||
insn = insn ^ (1 << 12);
|
||||
@@ -501,9 +507,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
}
|
||||
break;
|
||||
case R_RISCV_JAL:
|
||||
return reloc_jimm20(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_jimm20(s, code_ptr, (tcg_insn_unit *)value);
|
||||
case R_RISCV_CALL:
|
||||
return reloc_call(code_ptr, (tcg_insn_unit *)value);
|
||||
return reloc_call(s, code_ptr, (tcg_insn_unit *)value);
|
||||
default:
|
||||
tcg_abort();
|
||||
}
|
||||
@@ -559,7 +565,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->code_ptr - 2, (tcg_insn_unit *)val);
|
||||
ret = reloc_call(s, s->code_ptr - 2, (tcg_insn_unit *)val);
|
||||
tcg_debug_assert(ret == true);
|
||||
return;
|
||||
}
|
||||
@@ -856,14 +862,14 @@ static void tcg_out_setcond2(TCGContext *s, TCGCond cond, TCGReg ret,
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target)
|
||||
static inline void tcg_out_goto(TCGContext *s, const 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, tcg_insn_unit *arg, bool tail)
|
||||
static void tcg_out_call_int(TCGContext *s, const tcg_insn_unit *arg, bool tail)
|
||||
{
|
||||
TCGReg link = tail ? TCG_REG_ZERO : TCG_REG_RA;
|
||||
ptrdiff_t offset = tcg_pcrel_diff(s, arg);
|
||||
@@ -877,7 +883,7 @@ static void tcg_out_call_int(TCGContext *s, 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->code_ptr - 2, arg);\
|
||||
ret = reloc_call(s, s->code_ptr - 2, arg);\
|
||||
tcg_debug_assert(ret == true);
|
||||
} else if (TCG_TARGET_REG_BITS == 64) {
|
||||
/* far jump: 64-bit */
|
||||
@@ -890,7 +896,7 @@ static void tcg_out_call_int(TCGContext *s, tcg_insn_unit *arg, bool tail)
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
tcg_out_call_int(s, arg, false);
|
||||
}
|
||||
@@ -1024,7 +1030,8 @@ static void add_qemu_ldst_label(TCGContext *s, int is_ld, TCGMemOpIdx oi,
|
||||
TCGType ext,
|
||||
TCGReg datalo, TCGReg datahi,
|
||||
TCGReg addrlo, TCGReg addrhi,
|
||||
void *raddr, tcg_insn_unit **label_ptr)
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit **label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1054,7 +1061,7 @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
/* resolve label address */
|
||||
if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH,
|
||||
if (!patch_reloc(s, l->label_ptr[0], R_RISCV_BRANCH,
|
||||
(intptr_t) s->code_ptr, 0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1089,7 +1096,7 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
|
||||
}
|
||||
|
||||
/* resolve label address */
|
||||
if (!patch_reloc(l->label_ptr[0], R_RISCV_BRANCH,
|
||||
if (!patch_reloc(s, l->label_ptr[0], R_RISCV_BRANCH,
|
||||
(intptr_t) s->code_ptr, 0)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1276,7 +1283,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
|
||||
#endif
|
||||
}
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
|
||||
static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
||||
const TCGArg *args, const int *const_args)
|
||||
|
||||
+12
-1
@@ -149,13 +149,24 @@ 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 jmp_addr, uintptr_t addr,
|
||||
uintptr_t wr_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
|
||||
|
||||
+13
-12
@@ -363,10 +363,10 @@ static void * const qemu_st_helpers[16] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static tcg_insn_unit *tb_ret_addr;
|
||||
static const tcg_insn_unit *tb_ret_addr;
|
||||
uint64_t s390_facilities;
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||
intptr_t value, intptr_t addend)
|
||||
{
|
||||
intptr_t pcrel2;
|
||||
@@ -378,13 +378,13 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
switch (type) {
|
||||
case R_390_PC16DBL:
|
||||
if (pcrel2 == (int16_t)pcrel2) {
|
||||
tcg_patch16(code_ptr, pcrel2);
|
||||
tcg_patch16(s, code_ptr, pcrel2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case R_390_PC32DBL:
|
||||
if (pcrel2 == (int32_t)pcrel2) {
|
||||
tcg_patch32(code_ptr, pcrel2);
|
||||
tcg_patch32(s, code_ptr, pcrel2);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -392,7 +392,7 @@ static bool patch_reloc(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(code_ptr, old);
|
||||
tcg_patch32(s, 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, tcg_insn_unit *dest)
|
||||
static void tgen_gotoi(TCGContext *s, int cc, const 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, tcg_insn_unit *dest)
|
||||
static void tcg_out_call(TCGContext *s, const tcg_insn_unit *dest)
|
||||
{
|
||||
ptrdiff_t off = dest - s->code_ptr;
|
||||
if (off == (int32_t)off) {
|
||||
@@ -1597,7 +1597,8 @@ 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,
|
||||
tcg_insn_unit *raddr, tcg_insn_unit *label_ptr)
|
||||
const tcg_insn_unit *raddr,
|
||||
tcg_insn_unit *label_ptr)
|
||||
{
|
||||
TCGLabelQemuLdst *label = new_ldst_label(s);
|
||||
|
||||
@@ -1616,7 +1617,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(lb->label_ptr[0], R_390_PC16DBL,
|
||||
if (!patch_reloc(s, lb->label_ptr[0], R_390_PC16DBL,
|
||||
(intptr_t)s->code_ptr, 2)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1641,7 +1642,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(lb->label_ptr[0], R_390_PC16DBL,
|
||||
if (!patch_reloc(s, lb->label_ptr[0], R_390_PC16DBL,
|
||||
(intptr_t)s->code_ptr, 2)) {
|
||||
return false;
|
||||
}
|
||||
@@ -2579,9 +2580,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(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
memset(p, 0x07, count * sizeof(tcg_insn_unit));
|
||||
memset(TCG_CODE_PTR_RW(s, p), 0x07, count * sizeof(tcg_insn_unit));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -176,7 +176,13 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop)
|
||||
}
|
||||
}
|
||||
|
||||
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
|
||||
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
|
||||
|
||||
#define TCG_TARGET_NEED_POOL_LABELS
|
||||
|
||||
|
||||
+18
-11
@@ -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(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, 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((tcg_insn_unit *)value, code_ptr);
|
||||
pcrel = tcg_ptr_byte_diff((const 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, tcg_insn_unit *dest,
|
||||
static void tcg_out_call_nodelay(TCGContext *s, const 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, tcg_insn_unit *dest,
|
||||
}
|
||||
}
|
||||
|
||||
static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest)
|
||||
static void tcg_out_call(TCGContext *s, const 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 tcg_insn_unit *qemu_ld_trampoline[16];
|
||||
static tcg_insn_unit *qemu_st_trampoline[16];
|
||||
static const tcg_insn_unit *qemu_ld_trampoline[16];
|
||||
static const 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(tcg_insn_unit *p, int count)
|
||||
static void tcg_out_nop_fill(TCGContext *s, tcg_insn_unit *p, int count)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < count; ++i) {
|
||||
p[i] = NOP;
|
||||
(TCG_CODE_PTR_RW(s, 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;
|
||||
tcg_insn_unit *func;
|
||||
const tcg_insn_unit *func;
|
||||
tcg_insn_unit *label_ptr;
|
||||
|
||||
addrz = tcg_out_tlb_load(s, addr, memi, memop,
|
||||
@@ -1231,7 +1231,8 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
|
||||
}
|
||||
}
|
||||
|
||||
*label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
|
||||
*TCG_CODE_PTR_RW(s, 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);
|
||||
@@ -1827,7 +1828,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 addr, uintptr_t wr_addr)
|
||||
{
|
||||
intptr_t tb_disp = addr - tc_ptr;
|
||||
intptr_t br_disp = addr - jmp_addr;
|
||||
@@ -1840,6 +1841,9 @@ 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;
|
||||
}
|
||||
@@ -1864,5 +1868,8 @@ 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 */
|
||||
tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st IR */
|
||||
const tcg_insn_unit *raddr; /* gen code addr of the next IR of qemu_ld/st */
|
||||
tcg_insn_unit *label_ptr[2]; /* label pointers to be updated */
|
||||
QSIMPLEQ_ENTRY(TCGLabelQemuLdst) next;
|
||||
} TCGLabelQemuLdst;
|
||||
|
||||
+5
-4
@@ -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(tcg_insn_unit *p, int count);
|
||||
static void tcg_out_nop_fill(TCGContext *s, 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->code_ptr, (tcg_insn_unit *)a - s->code_ptr);
|
||||
tcg_out_nop_fill(s, s->code_ptr, (tcg_insn_unit *)a - s->code_ptr);
|
||||
s->data_gen_ptr = a;
|
||||
|
||||
for (; p != NULL; p = p->next) {
|
||||
@@ -144,11 +144,12 @@ static int tcg_out_pool_finalize(TCGContext *s)
|
||||
if (unlikely(a > s->code_gen_highwater)) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(a, p->data, size);
|
||||
memcpy(TCG_CODE_PTR_RW(s, a), p->data, size);
|
||||
a += size;
|
||||
l = p;
|
||||
}
|
||||
if (!patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend)) {
|
||||
if (!patch_reloc(s, 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(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, 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, tcg_insn_unit *target);
|
||||
static void tcg_out_call(TCGContext *s, const 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
|
||||
@@ -203,13 +203,15 @@ 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)
|
||||
{
|
||||
*s->code_ptr++ = v;
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch8(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch8(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
uint8_t v)
|
||||
{
|
||||
*p = v;
|
||||
*TCG_CODE_PTR_RW(s, p) = v;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -217,21 +219,23 @@ static __attribute__((unused)) inline void tcg_patch8(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_out16(TCGContext *s, uint16_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 2) {
|
||||
*s->code_ptr++ = v;
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
} else {
|
||||
tcg_insn_unit *p = s->code_ptr;
|
||||
memcpy(p, &v, sizeof(v));
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
s->code_ptr = p + (2 / TCG_TARGET_INSN_UNIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch16(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch16(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
uint16_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 2) {
|
||||
*p = v;
|
||||
*TCG_CODE_PTR_RW(s, p) = v;
|
||||
} else {
|
||||
memcpy(p, &v, sizeof(v));
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -240,21 +244,23 @@ static __attribute__((unused)) inline void tcg_patch16(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_out32(TCGContext *s, uint32_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 4) {
|
||||
*s->code_ptr++ = v;
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
} else {
|
||||
tcg_insn_unit *p = s->code_ptr;
|
||||
memcpy(p, &v, sizeof(v));
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
s->code_ptr = p + (4 / TCG_TARGET_INSN_UNIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch32(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch32(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
uint32_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 4) {
|
||||
*p = v;
|
||||
} else {
|
||||
memcpy(p, &v, sizeof(v));
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -263,21 +269,23 @@ static __attribute__((unused)) inline void tcg_patch32(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_out64(TCGContext *s, uint64_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 8) {
|
||||
*s->code_ptr++ = v;
|
||||
*TCG_CODE_PTR_RW(s, s->code_ptr) = v;
|
||||
s->code_ptr++;
|
||||
} else {
|
||||
tcg_insn_unit *p = s->code_ptr;
|
||||
memcpy(p, &v, sizeof(v));
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
s->code_ptr = p + (8 / TCG_TARGET_INSN_UNIT_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((unused)) inline void tcg_patch64(tcg_insn_unit *p,
|
||||
static __attribute__((unused)) inline void tcg_patch64(TCGContext *s,
|
||||
tcg_insn_unit *p,
|
||||
uint64_t v)
|
||||
{
|
||||
if (TCG_TARGET_INSN_UNIT_SIZE == 8) {
|
||||
*p = v;
|
||||
} else {
|
||||
memcpy(p, &v, sizeof(v));
|
||||
memcpy(TCG_CODE_PTR_RW(s, p), &v, sizeof(v));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -295,7 +303,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, tcg_insn_unit *ptr)
|
||||
static void tcg_out_label(TCGContext *s, TCGLabel *l, const tcg_insn_unit *ptr)
|
||||
{
|
||||
tcg_debug_assert(!l->has_value);
|
||||
l->has_value = 1;
|
||||
@@ -325,7 +333,7 @@ static bool tcg_resolve_relocs(TCGContext *s)
|
||||
uintptr_t value = l->u.value;
|
||||
|
||||
QSIMPLEQ_FOREACH(r, &l->relocs, next) {
|
||||
if (!patch_reloc(r->ptr, r->type, value, r->addend)) {
|
||||
if (!patch_reloc(s, r->ptr, r->type, value, r->addend)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -773,6 +781,8 @@ static void alloc_tcg_plugin_context(TCGContext *s)
|
||||
void tcg_register_thread(void)
|
||||
{
|
||||
tcg_ctx = &tcg_init_ctx;
|
||||
|
||||
tb_exec_unlock();
|
||||
}
|
||||
#else
|
||||
void tcg_register_thread(void)
|
||||
@@ -807,6 +817,8 @@ void tcg_register_thread(void)
|
||||
err = tcg_region_initial_alloc__locked(tcg_ctx);
|
||||
g_assert(!err);
|
||||
qemu_mutex_unlock(®ion.lock);
|
||||
|
||||
tb_exec_unlock();
|
||||
}
|
||||
#endif /* !CONFIG_USER_ONLY */
|
||||
|
||||
@@ -1043,7 +1055,7 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s)
|
||||
}
|
||||
atomic_set(&s->code_gen_ptr, next);
|
||||
s->data_gen_ptr = NULL;
|
||||
return tb;
|
||||
return (TranslationBlock *)TCG_CODE_PTR_RW(s, tb);
|
||||
}
|
||||
|
||||
void tcg_prologue_init(TCGContext *s)
|
||||
@@ -1080,6 +1092,10 @@ 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));
|
||||
#endif
|
||||
flush_icache_range((uintptr_t)buf0, (uintptr_t)buf1);
|
||||
|
||||
/* Deduct the prologue from the buffer. */
|
||||
@@ -4279,6 +4295,12 @@ 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);
|
||||
|
||||
|
||||
@@ -195,6 +195,12 @@ 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)
|
||||
{
|
||||
}
|
||||
#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. */
|
||||
@@ -203,7 +209,8 @@ static inline void flush_icache_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 jmp_addr, uintptr_t addr,
|
||||
uintptr_t wr_addr)
|
||||
{
|
||||
/* patch the branch destination */
|
||||
atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
|
||||
|
||||
@@ -369,7 +369,7 @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||
static bool patch_reloc(TCGContext *s, 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(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(code_ptr, value);
|
||||
tcg_patch32(s, code_ptr, value);
|
||||
} else {
|
||||
tcg_patch64(code_ptr, value);
|
||||
tcg_patch64(s, 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, tcg_insn_unit *arg)
|
||||
static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
|
||||
{
|
||||
uint8_t *old_code_ptr = s->code_ptr;
|
||||
tcg_out_op_t(s, INDEX_op_call);
|
||||
|
||||
@@ -23,7 +23,16 @@
|
||||
#undef _FORTIFY_SOURCE
|
||||
#endif
|
||||
#include "qemu/osdep.h"
|
||||
#if defined(CONFIG_LIBUCONTEXT)
|
||||
#include <libucontext.h>
|
||||
#define ucontext_t libucontext_ucontext_t
|
||||
#define getcontext libucontext_getcontext
|
||||
#define setcontext libucontext_setcontext
|
||||
#define swapcontext libucontext_swapcontext
|
||||
#define makecontext libucontext_makecontext
|
||||
#else
|
||||
#include <ucontext.h>
|
||||
#endif
|
||||
#include "qemu/coroutine_int.h"
|
||||
|
||||
#ifdef CONFIG_VALGRIND_H
|
||||
|
||||
Reference in new issue
Block a user