Generic jumptables support (needed for ARM NaCl port),

and ARM port support for that.
Code submitted under MIT/X11 license.
This commit is contained in:
Nikolay Igotti committed 2013-02-21 18:03:30 +04:00
1 parent 5079328f9d
commit 8f7a7a74e6
9 files changed
+682 -60

No files matched your search

+18
View File
@@ -237,6 +237,11 @@ case "$host" in
libdl="-ldl"
libgc_threads=pthreads
use_sigposix=yes
if test "x$cross_compiling" != "xno"; then
# to bypass the underscore linker check, not
# available during cross-compilation
mono_cv_uscore=no
fi
;;
*-*-nacl*)
host_win32=no
@@ -555,6 +560,8 @@ AC_ARG_WITH(mcs-path, [ --with-mcs-path=/path/to/mcs Specify an alternate
fi
)
AC_ARG_WITH(jumptables, [ --with-jumptables=yes,no enable/disable support for jumptables (ARM-only for now) (defaults to no)],[],[with_jumptables=no])
#
# A sanity check to catch cases where the package was unpacked
# with an ancient tar program (Solaris)
@@ -2488,6 +2495,11 @@ case "$host" in
JIT_SUPPORTED=yes
sgen_supported=true
AOT_SUPPORTED="yes"
if test "x$cross_compiling" != "xno"; then
# Provide sane defaults when cross-compiling
CPPFLAGS="$CPPFLAGS -DARM_FPU_VFP=1 -D__ARM_EABI__ -DHAVE_ARMV6=1"
NESTED_LIBGC_FLAGS="$NESTED_LIBGC_FLAGS -DHAVE_ARMV6"
fi
;;
s390-*-linux*)
TARGET=S390;
@@ -2881,6 +2893,12 @@ if test ${TARGET} = ARM && test x$cross_compiling = xno && test x$enable_mcs_bui
fi
fi
if test ${TARGET} = ARM; then
if test "x${with_jumptables}" = "xyes"; then
AC_DEFINE(USE_JUMP_TABLES, 1, Use jump tables in JIT)
fi
fi
if test ${TARGET} = unknown; then
CPPFLAGS="$CPPFLAGS -DNO_PORT"
AC_MSG_WARN("mono has not been ported to $host: some things may not work.")
+12
View File
@@ -402,6 +402,18 @@ typedef struct {
#define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
#define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
#ifdef USE_JUMP_TABLES
void
mono_jumptable_init (void) MONO_INTERNAL;
gpointer*
mono_jumptable_add_entry (void) MONO_INTERNAL;
gpointer*
mono_jumptable_add_entries (guint32 entries) MONO_INTERNAL;
void
mono_jumptable_cleanup (void) MONO_INTERNAL;
#endif
typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
void
+94 -1
View File
@@ -952,6 +952,96 @@ mono_jit_info_get_generic_jit_info (MonoJitInfo *ji)
return NULL;
}
#ifdef USE_JUMP_TABLES
#define DEFAULT_JUMPTABLE_CHUNK_ELEMENTS 128
typedef struct MonoJumpTableChunk {
guint32 total;
guint32 active;
struct MonoJumpTableChunk *previous;
/* gpointer entries[total]; */
} MonoJumpTableChunk;
static MonoJumpTableChunk* g_jumptable = NULL;
#define mono_jumptable_lock() EnterCriticalSection (&jumptable_mutex)
#define mono_jumptable_unlock() LeaveCriticalSection (&jumptable_mutex)
static CRITICAL_SECTION jumptable_mutex;
static MonoJumpTableChunk*
mono_create_jumptable_chunk (guint32 max_entries)
{
guint32 size = sizeof (MonoJumpTableChunk) + max_entries * sizeof(gpointer);
MonoJumpTableChunk *chunk = (MonoJumpTableChunk*) g_new0 (guchar, size);
chunk->total = max_entries;
return chunk;
}
void
mono_jumptable_init (void)
{
if (g_jumptable == NULL) {
InitializeCriticalSection (&jumptable_mutex);
g_jumptable = mono_create_jumptable_chunk (DEFAULT_JUMPTABLE_CHUNK_ELEMENTS);
}
}
gpointer*
mono_jumptable_add_entry (void)
{
return mono_jumptable_add_entries (1);
}
gpointer*
mono_jumptable_add_entries (guint32 entries)
{
guint32 index;
gpointer *result;
mono_jumptable_init ();
mono_jumptable_lock ();
index = g_jumptable->active;
if (index + entries >= g_jumptable->total) {
/*
* Grow jumptable, by adding one more chunk.
* We cannot realloc jumptable, as there could be pointers
* to existing jump table entries in the code, so instead
* we just add one more chunk.
*/
guint32 max_entries = entries;
MonoJumpTableChunk *new_chunk;
if (max_entries < DEFAULT_JUMPTABLE_CHUNK_ELEMENTS)
max_entries = DEFAULT_JUMPTABLE_CHUNK_ELEMENTS;
new_chunk = mono_create_jumptable_chunk (max_entries);
/* Link old jumptable, so that we could free it up later. */
new_chunk->previous = g_jumptable;
g_jumptable = new_chunk;
index = 0;
}
g_jumptable->active = index + entries;
result = (gpointer*)((guchar*)g_jumptable + sizeof(MonoJumpTableChunk)) + index;
mono_jumptable_unlock();
return result;
}
void
mono_jumptable_cleanup (void)
{
if (g_jumptable) {
MonoJumpTableChunk *current = g_jumptable, *prev;
while (current != NULL) {
prev = current->previous;
g_free (current);
current = prev;
}
g_jumptable = NULL;
DeleteCriticalSection (&jumptable_mutex);
}
}
#endif
/*
* mono_jit_info_get_generic_sharing_context:
* @ji: a jit info
@@ -1757,6 +1847,10 @@ mono_cleanup (void)
mono_images_cleanup ();
mono_debug_cleanup ();
mono_metadata_cleanup ();
#ifdef USE_JUMP_TABLES
mono_jumptable_cleanup ();
#endif
mono_native_tls_free (appdomain_thread_id);
DeleteCriticalSection (&appdomains_mutex);
@@ -2709,4 +2803,3 @@ mono_framework_version (void)
{
return current_runtime->framework_version [0] - '0';
}
+36 -36
View File
@@ -53,8 +53,8 @@ nop: len:4
relaxed_nop: len:4
break: len:4
jmp: len:92
br: len:4
switch: src1:i len:8
br: len:16
switch: src1:i len:12
# See the comment in resume_from_signal_handler, we can't copy the fp regs from sigctx to MonoContext on linux,
# since the corresponding sigctx structures are not well defined.
seq_point: len:38 clob:c
@@ -63,7 +63,7 @@ throw: src1:i len:24
rethrow: src1:i len:20
start_handler: len:20
endfinally: len:20
call_handler: len:12 clob:c
call_handler: len:16 clob:c
endfilter: src1:i len:16
ckfinite: dest:f src1:f len:64
@@ -81,7 +81,7 @@ setlret: src1:i src2:i len:12
checkthis: src1:b len:4
call: dest:a clob:c len:20
call_reg: dest:a src1:i len:8 clob:c
call_membase: dest:a src1:b len:16 clob:c
call_membase: dest:a src1:b len:24 clob:c
voidcall: len:20 clob:c
voidcall_reg: src1:i len:8 clob:c
voidcall_membase: src1:b len:16 clob:c
@@ -143,19 +143,19 @@ xor_imm: dest:i src1:i len:12
shl_imm: dest:i src1:i len:8
shr_imm: dest:i src1:i len:8
shr_un_imm: dest:i src1:i len:8
cond_exc_eq: len:8
cond_exc_ne_un: len:8
cond_exc_lt: len:8
cond_exc_lt_un: len:8
cond_exc_gt: len:8
cond_exc_gt_un: len:8
cond_exc_ge: len:8
cond_exc_ge_un: len:8
cond_exc_le: len:8
cond_exc_le_un: len:8
cond_exc_ov: len:12
cond_exc_eq: len:16
cond_exc_ne_un: len:16
cond_exc_lt: len:16
cond_exc_lt_un: len:16
cond_exc_gt: len:16
cond_exc_gt_un: len:16
cond_exc_ge: len:16
cond_exc_ge_un: len:16
cond_exc_le: len:16
cond_exc_le_un: len:16
cond_exc_ov: len:16
cond_exc_no: len:8
cond_exc_c: len:12
cond_exc_c: len:16
cond_exc_nc: len:8
#float_beq: src1:f src2:f len:20
#float_bne_un: src1:f src2:f len:20
@@ -233,16 +233,16 @@ int_conv_to_u4: dest:i src1:i
int_conv_to_r_un: dest:f src1:i len:56
int_conv_to_u2: dest:i src1:i len:8
int_conv_to_u1: dest:i src1:i len:4
int_beq: len:8
int_bge: len:8
int_bgt: len:8
int_ble: len:8
int_blt: len:8
int_bne_un: len:8
int_bge_un: len:8
int_bgt_un: len:8
int_ble_un: len:8
int_blt_un: len:8
int_beq: len:16
int_bge: len:16
int_bgt: len:16
int_ble: len:16
int_blt: len:16
int_bne_un: len:16
int_bge_un: len:16
int_bgt_un: len:16
int_ble_un: len:16
int_blt_un: len:16
int_add_ovf: dest:i src1:i src2:i len:16
int_add_ovf_un: dest:i src1:i src2:i len:16
int_mul_ovf: dest:i src1:i src2:i len:16
@@ -316,16 +316,16 @@ vcall2_membase: src1:b len:12 clob:c
dyn_call: src1:i src2:i len:120 clob:c
# This is different from the original JIT opcodes
float_beq: len:20
float_bne_un: len:20
float_blt: len:20
float_blt_un: len:20
float_bgt: len:20
float_bgt_un: len:20
float_bge: len:20
float_bge_un: len:20
float_ble: len:20
float_ble_un: len:20
float_beq: len:32
float_bne_un: len:32
float_blt: len:32
float_blt_un: len:32
float_bgt: len:32
float_bgt_un: len:32
float_bge: len:32
float_bge_un: len:32
float_ble: len:32
float_ble_un: len:32
liverange_start: len:0
liverange_end: len:0
+333 -14
View File
@@ -263,6 +263,9 @@ emit_call_reg (guint8 *code, int reg)
if (v5_supported) {
ARM_BLX_REG (code, reg);
} else {
#ifdef USE_JUMP_TABLES
g_assert_not_reached ();
#endif
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
if (thumb_supported)
ARM_BX (code, reg);
@@ -275,6 +278,9 @@ emit_call_reg (guint8 *code, int reg)
static guint8*
emit_call_seq (MonoCompile *cfg, guint8 *code)
{
#ifdef USE_JUMP_TABLES
code = mono_arm_patchable_bl (code, ARMCOND_AL);
#else
if (cfg->method->dynamic) {
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
ARM_B (code, 0);
@@ -284,9 +290,59 @@ emit_call_seq (MonoCompile *cfg, guint8 *code)
} else {
ARM_BL (code, 0);
}
#endif
return code;
}
guint8*
mono_arm_patchable_b (guint8 *code, int cond)
{
#ifdef USE_JUMP_TABLES
gpointer *jte;
jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
ARM_BX_COND (code, cond, ARMREG_IP);
#else
ARM_B_COND (code, cond, 0);
#endif
return code;
}
guint8*
mono_arm_patchable_bl (guint8 *code, int cond)
{
#ifdef USE_JUMP_TABLES
gpointer *jte;
jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
ARM_BLX_REG_COND (code, cond, ARMREG_IP);
#else
ARM_BL_COND (code, cond, 0);
#endif
return code;
}
#ifdef USE_JUMP_TABLES
guint8*
mono_arm_load_jumptable_entry_addr (guint8 *code, gpointer *jte, ARMReg reg)
{
ARM_MOVW_REG_IMM (code, reg, GPOINTER_TO_UINT(jte) & 0xffff);
ARM_MOVT_REG_IMM (code, reg, (GPOINTER_TO_UINT(jte) >> 16) & 0xffff);
return code;
}
guint8*
mono_arm_load_jumptable_entry (guint8 *code, gpointer* jte, ARMReg reg)
{
code = mono_arm_load_jumptable_entry_addr (code, jte, reg);
ARM_LDR_IMM (code, reg, reg, 0);
return code;
}
#endif
static guint8*
emit_move_return_value (MonoCompile *cfg, MonoInst *ins, guint8 *code)
{
@@ -642,10 +698,18 @@ create_function_wrapper (gpointer function)
ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_FP);
/* call */
#ifdef USE_JUMP_TABLES
{
gpointer *jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
jte [0] = function;
}
#else
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
ARM_B (code, 0);
*(gpointer*)code = function;
code += 4;
#endif
ARM_BLX_REG (code, ARMREG_IP);
/* we're back; save ctx.eip and ctx.esp into the corresponding regs slots. */
@@ -2509,7 +2573,7 @@ if (0 && ins->inst_true_bb->native_offset) { \
ARM_B_COND (code, (condcode), (code - cfg->native_code + ins->inst_true_bb->native_offset) & 0xffffff); \
} else { \
mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_true_bb); \
ARM_B_COND (code, (condcode), 0); \
code = mono_arm_patchable_b (code, (condcode)); \
}
#define EMIT_COND_BRANCH(ins,cond) EMIT_COND_BRANCH_FLAGS(ins, branch_cc_table [(cond)])
@@ -2523,7 +2587,7 @@ if (0 && ins->inst_true_bb->native_offset) { \
do { \
mono_add_patch_info (cfg, code - cfg->native_code, \
MONO_PATCH_INFO_EXC, exc_name); \
ARM_BL_COND (code, (condcode), 0); \
code = mono_arm_patchable_bl (code, (condcode)); \
} while (0);
#define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) EMIT_COND_SYSTEM_EXCEPTION_FLAGS(branch_cc_table [(cond)], (exc_name))
@@ -3215,6 +3279,13 @@ arm_patch_general (MonoDomain *domain, guchar *code, const guchar *target, MonoC
return;
}
#ifdef USE_JUMP_TABLES
{
gpointer *jte = mono_jumptable_get_entry (code);
g_assert (jte);
jte [0] = (gpointer) target;
}
#else
/*
* The alternative call sequences looks like this:
*
@@ -3309,6 +3380,7 @@ arm_patch_general (MonoDomain *domain, guchar *code, const guchar *target, MonoC
g_assert_not_reached ();
}
// g_print ("patched with 0x%08x\n", ins);
#endif
}
void
@@ -3801,10 +3873,16 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
g_assert (arm_is_imm12 (var->inst_offset));
ARM_LDR_IMM (code, dreg, var->inst_basereg, var->inst_offset);
} else {
#ifdef USE_JUMP_TABLES
gpointer *jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, dreg);
jte [0] = ss_trigger_page;
#else
ARM_LDR_IMM (code, dreg, ARMREG_PC, 0);
ARM_B (code, 0);
*(int*)code = (int)ss_trigger_page;
code += 4;
#endif
}
ARM_LDR_IMM (code, dreg, dreg, 0);
}
@@ -4112,7 +4190,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
code += 4;
ARM_LDR_REG_REG (code, ARMREG_PC, ARMREG_PC, ARMREG_IP);
} else {
ARM_B (code, 0);
code = mono_arm_patchable_b (code, ARMCOND_AL);
}
break;
case OP_CHECK_THIS:
@@ -4166,10 +4244,16 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
imt_arg = TRUE;
if (!arm_is_imm12 (ins->inst_offset))
code = mono_arm_emit_load_imm (code, ARMREG_IP, ins->inst_offset);
#ifdef USE_JUMP_TABLES
#define LR_BIAS 0
#else
#define LR_BIAS 4
#endif
if (imt_arg)
ARM_ADD_REG_IMM8 (code, ARMREG_LR, ARMREG_PC, 4);
ARM_ADD_REG_IMM8 (code, ARMREG_LR, ARMREG_PC, LR_BIAS);
else
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
#undef LR_BIAS
if (!arm_is_imm12 (ins->inst_offset))
ARM_LDR_REG_REG (code, ARMREG_PC, ins->sreg1, ARMREG_IP);
else
@@ -4182,11 +4266,16 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
* mono_arch_emit_imt_argument (), and embed NULL here to
* signal the IMT thunk that the value is in V5.
*/
#ifdef USE_JUMP_TABLES
/* In case of jumptables we always use value in V5. */
#else
if (call->dynamic_imt_arg)
*((gpointer*)code) = NULL;
else
*((gpointer*)code) = (gpointer)call->method;
code += 4;
#endif
}
ins->flags |= MONO_INST_GC_CALLSITE;
ins->backend.pc_offset = code - cfg->native_code;
@@ -4347,7 +4436,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
}
case OP_CALL_HANDLER:
mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_BB, ins->inst_target_bb);
ARM_BL (code, 0);
code = mono_arm_patchable_bl (code, ARMCOND_AL);
mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
break;
case OP_LABEL:
@@ -4359,7 +4448,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
//x86_jump_code (code, cfg->native_code + ins->inst_target_bb->native_offset);
} else*/ {
mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_BB, ins->inst_target_bb);
ARM_B (code, 0);
code = mono_arm_patchable_b (code, ARMCOND_AL);
}
break;
case OP_BR_REG:
@@ -4377,6 +4466,14 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
* FIXME: add aot support.
*/
mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_SWITCH, ins->inst_p0);
#ifdef USE_JUMP_TABLES
{
gpointer *jte = mono_jumptable_add_entries (GPOINTER_TO_INT (ins->klass));
code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_IP);
ARM_LDR_REG_REG_SHIFT (code, ARMREG_PC, ARMREG_IP, ins->sreg1, ARMSHIFT_LSL, 2);
}
#else
max_len += 4 * GPOINTER_TO_INT (ins->klass);
if (offset + max_len > (cfg->code_size - 16)) {
cfg->code_size += max_len;
@@ -4387,6 +4484,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ARM_LDR_REG_REG_SHIFT (code, ARMREG_PC, ARMREG_PC, ins->sreg1, ARMSHIFT_LSL, 2);
ARM_NOP (code);
code += 4 * GPOINTER_TO_INT (ins->klass);
#endif
break;
case OP_CEQ:
case OP_ICEQ:
@@ -4525,17 +4623,32 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
break;
case OP_ICONV_TO_R_UN: {
int tmpreg;
#ifdef USE_JUMP_TABLES
gpointer *jte = mono_jumptable_add_entries (2);
#define SKIP_INSTRUCTIONS 5
#else
#define SKIP_INSTRUCTIONS 8
#endif
tmpreg = ins->dreg == 0? 1: 0;
ARM_CMP_REG_IMM8 (code, ins->sreg1, 0);
ARM_FPA_FLTD (code, ins->dreg, ins->sreg1);
ARM_B_COND (code, ARMCOND_GE, 8);
ARM_B_COND (code, ARMCOND_GE, SKIP_INSTRUCTIONS);
/* save the temp register */
ARM_SUB_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, 8);
ARM_FPA_STFD (code, tmpreg, ARMREG_SP, 0);
#ifdef USE_JUMP_TABLES
code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_IP);
ARM_FPA_LDFD (code, tmpreg, ARMREG_IP, 0);
#else
ARM_FPA_LDFD (code, tmpreg, ARMREG_PC, 12);
#endif
ARM_FPA_ADFD (code, ins->dreg, ins->dreg, tmpreg);
ARM_FPA_LDFD (code, tmpreg, ARMREG_SP, 0);
ARM_ADD_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, 8);
#ifdef USE_JUMP_TABLES
jte [0] = GUINT_TO_POINTER (0x41f00000);
jte [1] = GUINT_TO_POINTER (0);
#else
/* skip the constant pool */
ARM_B (code, 8);
code += 4;
@@ -4547,6 +4660,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
* ldfltd ftemp, [pc, #8] 0x41f00000 0x00000000
* adfltd fdest, fdest, ftemp
*/
#endif
#undef SKIP_INSTRUCTIONS
break;
}
case OP_ICONV_TO_R4:
@@ -4846,6 +4961,15 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
if (ins->dreg != ins->sreg1)
ARM_FPA_MVFD (code, ins->dreg, ins->sreg1);
} else if (IS_VFP) {
#ifdef USE_JUMP_TABLES
{
gpointer *jte = mono_jumptable_add_entries (2);
jte [0] = GUINT_TO_POINTER (0xffffffff);
jte [1] = GUINT_TO_POINTER (0x7fefffff);
code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_IP);
ARM_FLDD (code, ARM_VFP_D0, ARMREG_IP, 0);
}
#else
ARM_ABSD (code, ARM_VFP_D1, ins->sreg1);
ARM_FLDD (code, ARM_VFP_D0, ARMREG_PC, 0);
ARM_B (code, 1);
@@ -4853,6 +4977,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
code += 4;
*(guint32*)code = 0x7fefffff;
code += 4;
#endif
ARM_CMPD (code, ARM_VFP_D1, ARM_VFP_D0);
ARM_FMSTAT (code);
EMIT_COND_SYSTEM_EXCEPTION_FLAGS (ARMCOND_GT, "ArithmeticException");
@@ -4931,7 +5056,11 @@ mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, Mono
const unsigned char *target;
if (patch_info->type == MONO_PATCH_INFO_SWITCH && !compile_aot) {
#ifdef USE_JUMP_TABLES
gpointer *jt = mono_jumptable_get_entry (ip);
#else
gpointer *jt = (gpointer*)(ip + 8);
#endif
int i;
/* jt is the inlined jump table, 2 instructions after ip
* In the normal case we store the absolute addresses,
@@ -5358,10 +5487,19 @@ mono_arch_emit_prolog (MonoCompile *cfg)
/* Initialize the variable from a GOT slot */
mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_SEQ_POINT_INFO, cfg->method);
#ifdef USE_JUMP_TABLES
{
gpointer *jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
ARM_LDR_IMM (code, ARMREG_R0, ARMREG_IP, 0);
}
/** XXX: is it correct? */
#else
ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0);
ARM_B (code, 0);
*(gpointer*)code = NULL;
code += 4;
#endif
ARM_LDR_REG_REG (code, ARMREG_R0, ARMREG_PC, ARMREG_R0);
g_assert (ins->opcode == OP_REGOFFSET);
@@ -5395,7 +5533,9 @@ mono_arch_emit_prolog (MonoCompile *cfg)
MonoInst *read_ins = cfg->arch.seq_point_read_var;
MonoInst *ss_method_ins = cfg->arch.seq_point_ss_method_var;
MonoInst *bp_method_ins = cfg->arch.seq_point_bp_method_var;
#ifdef USE_JUMP_TABLES
gpointer *jte;
#endif
g_assert (read_ins->opcode == OP_REGOFFSET);
g_assert (arm_is_imm12 (read_ins->inst_offset));
g_assert (ss_method_ins->opcode == OP_REGOFFSET);
@@ -5403,6 +5543,13 @@ mono_arch_emit_prolog (MonoCompile *cfg)
g_assert (bp_method_ins->opcode == OP_REGOFFSET);
g_assert (arm_is_imm12 (bp_method_ins->inst_offset));
#ifdef USE_JUMP_TABLES
jte = mono_jumptable_add_entries (3);
jte [0] = (gpointer)&ss_trigger_var;
jte [1] = single_step_func_wrapper;
jte [2] = breakpoint_func_wrapper;
code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_LR);
#else
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
ARM_B (code, 2);
*(volatile int **)code = &ss_trigger_var;
@@ -5411,6 +5558,7 @@ mono_arch_emit_prolog (MonoCompile *cfg)
code += 4;
*(gpointer*)code = breakpoint_func_wrapper;
code += 4;
#endif
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_LR, 0);
ARM_STR_IMM (code, ARMREG_IP, read_ins->inst_basereg, read_ins->inst_offset);
@@ -5604,6 +5752,19 @@ mono_arch_emit_exceptions (MonoCompile *cfg)
g_assert (exc_class);
ARM_MOV_REG_REG (code, ARMREG_R1, ARMREG_LR);
#ifdef USE_JUMP_TABLES
{
gpointer *jte = mono_jumptable_add_entries (2);
patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
patch_info->data.name = "mono_arch_throw_corlib_exception";
patch_info->ip.i = code - cfg->native_code;
code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_R0);
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_R0, 0);
ARM_LDR_IMM (code, ARMREG_R0, ARMREG_R0, 4);
ARM_BLX_REG (code, ARMREG_IP);
jte [1] = GUINT_TO_POINTER (exc_class->type_token);
}
#else
ARM_LDR_IMM (code, ARMREG_R0, ARMREG_PC, 0);
patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
patch_info->data.name = "mono_arch_throw_corlib_exception";
@@ -5611,6 +5772,7 @@ mono_arch_emit_exceptions (MonoCompile *cfg)
ARM_BL (code, 0);
*(guint32*)(gpointer)code = exc_class->type_token;
code += 4;
#endif
break;
}
default:
@@ -5678,6 +5840,11 @@ void
mono_arch_emit_imt_argument (MonoCompile *cfg, MonoCallInst *call, MonoInst *imt_arg)
{
int method_reg = mono_alloc_ireg (cfg);
#ifdef USE_JUMP_TABLES
int use_jumptables = TRUE;
#else
int use_jumptables = FALSE;
#endif
if (cfg->compile_aot) {
MonoInst *ins;
@@ -5694,7 +5861,7 @@ mono_arch_emit_imt_argument (MonoCompile *cfg, MonoCallInst *call, MonoInst *imt
MONO_ADD_INS (cfg->cbb, ins);
}
mono_call_inst_add_outarg_reg (cfg, call, method_reg, ARMREG_V5, FALSE);
} else if (cfg->generic_context || imt_arg || mono_use_llvm) {
} else if (cfg->generic_context || imt_arg || mono_use_llvm || use_jumptables) {
/* Always pass in a register for simplicity */
call->dynamic_imt_arg = TRUE;
@@ -5720,8 +5887,13 @@ mono_arch_emit_imt_argument (MonoCompile *cfg, MonoCallInst *call, MonoInst *imt
MonoMethod*
mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
{
#ifdef USE_JUMP_TABLES
return (MonoMethod*)regs [ARMREG_V5];
#else
gpointer method;
guint32 *code_ptr = (guint32*)code;
code_ptr -= 2;
method = GUINT_TO_POINTER (code_ptr [1]);
if (mono_use_llvm)
/* Passed in V5 */
@@ -5735,11 +5907,12 @@ mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
g_assert (IS_LDR_PC (code_ptr [0]));
}
*/
if (code_ptr [1] == 0)
if (method == 0)
/* This is AOTed code, or the gsharedvt trampoline, the IMT method is in V5 */
return (MonoMethod*)regs [ARMREG_V5];
else
return (MonoMethod*) code_ptr [1];
return (MonoMethod*) method;
#endif
}
MonoVTable*
@@ -5757,6 +5930,27 @@ mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
#define WMC_SIZE (5 * 4)
#define DISTANCE(A, B) (((gint32)(B)) - ((gint32)(A)))
#ifdef USE_JUMP_TABLES
static void
set_jumptable_element (gpointer *base, guint32 index, gpointer value)
{
g_assert (base [index] == NULL);
base [index] = value;
}
static arminstr_t *
load_element_with_regbase_cond (arminstr_t *code, ARMReg dreg, ARMReg base, guint32 jti, int cond)
{
if (arm_is_imm12 (jti * 4)) {
ARM_LDR_IMM_COND (code, dreg, base, jti * 4, cond);
} else {
ARM_MOVW_REG_IMM_COND (code, dreg, (jti * 4) & 0xffff, cond);
if ((jti * 4) >> 16)
ARM_MOVT_REG_IMM_COND (code, dreg, ((jti * 4) >> 16) & 0xffff, cond);
ARM_LDR_REG_REG_SHIFT_COND (code, dreg, base, dreg, ARMSHIFT_LSL, 0, cond);
}
return code;
}
#else
static arminstr_t *
arm_emit_value_and_patch_ldr (arminstr_t *code, arminstr_t *target, guint32 value)
{
@@ -5767,17 +5961,33 @@ arm_emit_value_and_patch_ldr (arminstr_t *code, arminstr_t *target, guint32 valu
*code = value;
return code + 1;
}
#endif
gpointer
mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count,
gpointer fail_tramp)
{
int size, i, extra_space = 0;
arminstr_t *code, *start, *vtable_target = NULL;
int size, i;
arminstr_t *code, *start;
#ifdef USE_JUMP_TABLES
gpointer *jte;
#else
gboolean large_offsets = FALSE;
guint32 **constant_pool_starts;
arminstr_t *vtable_target = NULL;
int extra_space = 0;
#endif
size = BASE_SIZE;
#ifdef USE_JUMP_TABLES
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
item->chunk_size += 4 * 16;
if (!item->is_equals)
imt_entries [item->check_target_idx]->compare_done = TRUE;
size += item->chunk_size;
}
#else
constant_pool_starts = g_new0 (guint32*, count);
for (i = 0; i < count; ++i) {
@@ -5813,6 +6023,7 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
if (large_offsets)
size += 4 * count; /* The ARM_ADD_REG_IMM to pop the stack */
#endif
if (fail_tramp)
code = mono_method_alloc_generic_virtual_thunk (domain, size);
@@ -5828,6 +6039,24 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
}
#endif
#ifdef USE_JUMP_TABLES
ARM_PUSH3 (code, ARMREG_R0, ARMREG_R1, ARMREG_R2);
/* If jumptables we always pass the IMT method in R5 */
ARM_MOV_REG_REG (code, ARMREG_R0, ARMREG_V5);
#define VTABLE_JTI 0
#define IMT_METHOD_OFFSET 0
#define TARGET_CODE_OFFSET 1
#define JUMP_CODE_OFFSET 2
#define RECORDS_PER_ENTRY 3
#define IMT_METHOD_JTI(idx) (1 + idx * RECORDS_PER_ENTRY + IMT_METHOD_OFFSET)
#define TARGET_CODE_JTI(idx) (1 + idx * RECORDS_PER_ENTRY + TARGET_CODE_OFFSET)
#define JUMP_CODE_JTI(idx) (1 + idx * RECORDS_PER_ENTRY + JUMP_CODE_OFFSET)
jte = mono_jumptable_add_entries (RECORDS_PER_ENTRY * count + 1 /* vtable */);
code = (arminstr_t *) mono_arm_load_jumptable_entry_addr ((guint8 *) code, jte, ARMREG_R2);
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_R2, VTABLE_JTI);
set_jumptable_element (jte, VTABLE_JTI, vtable);
#else
if (large_offsets)
ARM_PUSH4 (code, ARMREG_R0, ARMREG_R1, ARMREG_IP, ARMREG_PC);
else
@@ -5844,10 +6073,15 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
ARM_CMP_REG_IMM8 (code, ARMREG_R0, 0);
ARM_MOV_REG_REG_COND (code, ARMREG_R0, ARMREG_V5, ARMCOND_EQ);
}
#endif
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
#ifdef USE_JUMP_TABLES
guint32 imt_method_jti = 0, target_code_jti = 0;
#else
arminstr_t *imt_method = NULL, *vtable_offset_ins = NULL, *target_code_ins = NULL;
#endif
gint32 vtable_offset;
item->code_target = (guint8*)code;
@@ -5857,17 +6091,33 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
if (item->check_target_idx || fail_case) {
if (!item->compare_done || fail_case) {
#ifdef USE_JUMP_TABLES
imt_method_jti = IMT_METHOD_JTI (i);
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, imt_method_jti, ARMCOND_AL);
#else
imt_method = code;
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
#endif
ARM_CMP_REG_REG (code, ARMREG_R0, ARMREG_R1);
}
#ifdef USE_JUMP_TABLES
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, JUMP_CODE_JTI (i), ARMCOND_NE);
ARM_BX_COND (code, ARMCOND_NE, ARMREG_R1);
item->jmp_code = GUINT_TO_POINTER (JUMP_CODE_JTI (i));
#else
item->jmp_code = (guint8*)code;
ARM_B_COND (code, ARMCOND_NE, 0);
#endif
} else {
/*Enable the commented code to assert on wrong method*/
#if ENABLE_WRONG_METHOD_CHECK
#ifdef USE_JUMP_TABLES
imt_method_jti = IMT_METHOD_JTI (i);
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, imt_method_jti, ARMCOND_AL);
#else
imt_method = code;
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
#endif
ARM_CMP_REG_REG (code, ARMREG_R0, ARMREG_R1);
ARM_B_COND (code, ARMCOND_NE, 1);
@@ -5876,8 +6126,17 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
}
if (item->has_target_code) {
target_code_ins = code;
/* Load target address */
#ifdef USE_JUMP_TABLES
target_code_jti = TARGET_CODE_JTI (i);
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, target_code_jti, ARMCOND_AL);
/* Restore registers */
ARM_POP3 (code, ARMREG_R0, ARMREG_R1, ARMREG_R2);
/* And branch */
ARM_BX (code, ARMREG_R1);
set_jumptable_element (jte, target_code_jti, item->value.target_code);
#else
target_code_ins = code;
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
/* Save it to the fourth slot */
ARM_STR_IMM (code, ARMREG_R1, ARMREG_SP, 3 * sizeof (gpointer));
@@ -5885,6 +6144,7 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
ARM_POP4 (code, ARMREG_R0, ARMREG_R1, ARMREG_IP, ARMREG_PC);
code = arm_emit_value_and_patch_ldr (code, target_code_ins, (gsize)item->value.target_code);
#endif
} else {
vtable_offset = DISTANCE (vtable, &vtable->vtable[item->value.vtable_slot]);
if (!arm_is_imm12 (vtable_offset)) {
@@ -5895,6 +6155,16 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
* load them both using LDM.
*/
/* Compute target address */
#ifdef USE_JUMP_TABLES
ARM_MOVW_REG_IMM (code, ARMREG_R1, vtable_offset & 0xffff);
if (vtable_offset >> 16)
ARM_MOVT_REG_IMM (code, ARMREG_R1, (vtable_offset >> 16) & 0xffff);
/* IP had vtable base. */
ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_IP, ARMREG_R1);
/* Restore registers and branch */
ARM_POP3 (code, ARMREG_R0, ARMREG_R1, ARMREG_R2);
ARM_BX (code, ARMREG_IP);
#else
vtable_offset_ins = code;
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
ARM_LDR_REG_REG (code, ARMREG_R1, ARMREG_IP, ARMREG_R1);
@@ -5904,15 +6174,33 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
ARM_POP4 (code, ARMREG_R0, ARMREG_R1, ARMREG_IP, ARMREG_PC);
code = arm_emit_value_and_patch_ldr (code, vtable_offset_ins, vtable_offset);
#endif
} else {
#ifdef USE_JUMP_TABLES
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_IP, vtable_offset);
ARM_POP3 (code, ARMREG_R0, ARMREG_R1, ARMREG_R2);
ARM_BX (code, ARMREG_IP);
#else
ARM_POP2 (code, ARMREG_R0, ARMREG_R1);
if (large_offsets)
ARM_ADD_REG_IMM8 (code, ARMREG_SP, ARMREG_SP, 2 * sizeof (gpointer));
ARM_LDR_IMM (code, ARMREG_PC, ARMREG_IP, vtable_offset);
#endif
}
}
if (fail_case) {
#ifdef USE_JUMP_TABLES
set_jumptable_element (jte, GPOINTER_TO_UINT (item->jmp_code), code);
target_code_jti = TARGET_CODE_JTI (i);
/* Load target address */
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, target_code_jti, ARMCOND_AL);
/* Restore registers */
ARM_POP3 (code, ARMREG_R0, ARMREG_R1, ARMREG_R2);
/* And branch */
ARM_BX (code, ARMREG_R1);
set_jumptable_element (jte, target_code_jti, fail_tramp);
#else
arm_patch (item->jmp_code, (guchar*)code);
target_code_ins = code;
@@ -5924,9 +6212,14 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
ARM_POP4 (code, ARMREG_R0, ARMREG_R1, ARMREG_IP, ARMREG_PC);
code = arm_emit_value_and_patch_ldr (code, target_code_ins, (gsize)fail_tramp);
#endif
item->jmp_code = NULL;
}
#ifdef USE_JUMP_TABLES
if (imt_method_jti)
set_jumptable_element (jte, imt_method_jti, item->key);
#else
if (imt_method)
code = arm_emit_value_and_patch_ldr (code, imt_method, (guint32)item->key);
@@ -5943,13 +6236,22 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
code += extra_space;
extra_space = 0;
}
#endif
} else {
#ifdef USE_JUMP_TABLES
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, IMT_METHOD_JTI (i), ARMCOND_AL);
ARM_CMP_REG_REG (code, ARMREG_R0, ARMREG_R1);
code = load_element_with_regbase_cond (code, ARMREG_R1, ARMREG_R2, JUMP_CODE_JTI (i), ARMCOND_GE);
ARM_BX_COND (code, ARMCOND_GE, ARMREG_R1);
item->jmp_code = GUINT_TO_POINTER (JUMP_CODE_JTI (i));
#else
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0);
ARM_CMP_REG_REG (code, ARMREG_R0, ARMREG_R1);
item->jmp_code = (guint8*)code;
ARM_B_COND (code, ARMCOND_GE, 0);
++extra_space;
#endif
}
}
@@ -5957,14 +6259,23 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
MonoIMTCheckItem *item = imt_entries [i];
if (item->jmp_code) {
if (item->check_target_idx)
#ifdef USE_JUMP_TABLES
set_jumptable_element (jte, GPOINTER_TO_UINT (item->jmp_code), imt_entries [item->check_target_idx]->code_target);
#else
arm_patch (item->jmp_code, imt_entries [item->check_target_idx]->code_target);
#endif
}
if (i > 0 && item->is_equals) {
int j;
#ifdef USE_JUMP_TABLES
for (j = i - 1; j >= 0 && !imt_entries [j]->is_equals; --j)
set_jumptable_element (jte, IMT_METHOD_JTI (j), imt_entries [j]->key);
#else
arminstr_t *space_start = constant_pool_starts [i];
for (j = i - 1; j >= 0 && !imt_entries [j]->is_equals; --j) {
space_start = arm_emit_value_and_patch_ldr (space_start, (arminstr_t*)imt_entries [j]->code_target, (guint32)imt_entries [j]->key);
}
#endif
}
}
@@ -5976,7 +6287,9 @@ mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckI
}
#endif
#ifndef USE_JUMP_TABLES
g_free (constant_pool_starts);
#endif
mono_arch_flush_icache ((guint8*)start, size);
mono_stats.imt_thunks_size += code - start;
@@ -6039,10 +6352,16 @@ mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
int dreg = ARMREG_LR;
/* Read from another trigger page */
#ifdef USE_JUMP_TABLES
gpointer *jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, dreg);
jte [0] = bp_trigger_page;
#else
ARM_LDR_IMM (code, dreg, ARMREG_PC, 0);
ARM_B (code, 0);
*(int*)code = (int)bp_trigger_page;
code += 4;
#endif
ARM_LDR_IMM (code, dreg, dreg, 0);
mono_arch_flush_icache (code - 16, 16);
+14
View File
@@ -259,5 +259,19 @@ mono_arm_get_exception_trampolines (gboolean aot) MONO_INTERNAL;
guint8*
mono_arm_get_thumb_plt_entry (guint8 *code) MONO_INTERNAL;
guint8*
mono_arm_patchable_b (guint8 *code, int cond);
guint8*
mono_arm_patchable_bl (guint8 *code, int cond);
#ifdef USE_JUMP_TABLES
guint8*
mono_arm_load_jumptable_entry_addr (guint8 *code, gpointer *jte, ARMReg reg) MONO_INTERNAL;
guint8*
mono_arm_load_jumptable_entry (guint8 *code, gpointer *jte, ARMReg reg) MONO_INTERNAL;
#endif
#endif /* __MONO_MINI_ARM_H__ */
+8
View File
@@ -7444,3 +7444,11 @@ mono_arch_get_gsharedvt_call_info (gpointer addr, MonoMethodSignature *normal_si
}
#endif
#ifdef USE_JUMP_TABLES
gpointer*
mono_jumptable_get_entry (guint8 *code_ptr)
{
return mono_arch_jumptable_entry_from_code (code_ptr);
}
#endif
+7
View File
@@ -2183,6 +2183,13 @@ gpointer mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *cod
void mono_arch_setup_resume_sighandler_ctx (MonoContext *ctx, gpointer func) MONO_INTERNAL;
#endif
#ifdef USE_JUMP_TABLES
gpointer*
mono_arch_jumptable_entry_from_code (guint8 *code);
gpointer*
mono_jumptable_get_entry (guint8 *code);
#endif
gboolean
mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
MonoJitInfo *ji, MonoContext *ctx,
+160 -9
View File
@@ -24,6 +24,53 @@
static guint8* nullified_class_init_trampoline;
#ifdef USE_JUMP_TABLES
static guint16
decode_imm16 (guint32 insn)
{
return (((insn >> 16) & 0xf) << 12) | (insn & 0xfff);
}
#define INSN_MASK 0xff00000
#define MOVW_MASK ((3 << 24) | (0 << 20))
#define MOVT_MASK ((3 << 24) | (4 << 20))
gpointer*
mono_arch_jumptable_entry_from_code (guint8 *code)
{
guint32 insn1 = ((guint32*)code) [0];
guint32 insn2 = ((guint32*)code) [1];
if (((insn1 & INSN_MASK) == MOVW_MASK) &&
((insn2 & INSN_MASK) == MOVT_MASK) ) {
guint32 imm_lo = decode_imm16 (insn1);
guint32 imm_hi = decode_imm16 (insn2);
return (gpointer*) GUINT_TO_POINTER (imm_lo | (imm_hi << 16));
} else {
g_assert_not_reached ();
return NULL;
}
}
#undef INSN_MASK
#undef MOVW_MASK
#undef MOVT_MASK
void
mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
{
gpointer *jte;
/*
* code_ptr is 4 instructions after MOVW/MOVT used to address
* jumptable entry.
*/
jte = mono_jumptable_get_entry (code_ptr - 16);
g_assert ( jte != NULL);
*jte = addr;
}
#else
void
mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
{
@@ -51,6 +98,7 @@ mono_arch_patch_callsite (guint8 *method_start, guint8 *code_ptr, guint8 *addr)
g_assert_not_reached ();
}
#endif
void
mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
@@ -99,6 +147,7 @@ mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
#define arm_is_imm12(v) ((int)(v) > -4096 && (int)(v) < 4096)
#ifndef USE_JUMP_TABLES
/*
* Return the instruction to jump from code to target, 0 if not
* reachable with a single instruction
@@ -118,6 +167,7 @@ branch_for_target_reachable (guint8 *branch, guint8 *target)
}
return 0;
}
#endif
static inline guint8*
emit_bx (guint8* code, int reg)
@@ -143,13 +193,22 @@ guchar*
mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot)
{
guint8 *buf, *code = NULL;
guint8 *load_get_lmf_addr, *load_trampoline;
#ifdef USE_JUMP_TABLES
gpointer *load_get_lmf_addr = NULL, *load_trampoline = NULL;
#else
guint8 *load_get_lmf_addr = NULL, *load_trampoline = NULL;
gpointer *constants;
#endif
int cfa_offset, lmf_offset, regsave_size, lr_offset;
GSList *unwind_ops = NULL;
MonoJumpInfo *ji = NULL;
int buf_len;
#ifdef USE_JUMP_TABLES
g_assert (!aot);
#endif
/* Now we'll create in 'buf' the ARM trampoline code. This
is the trampoline code common to all methods */
@@ -193,8 +252,9 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
ARM_LDR_REG_REG (code, ARMREG_V2, ARMREG_V2, ARMREG_LR);
}
} else {
if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
if (tramp_type != MONO_TRAMPOLINE_GENERIC_CLASS_INIT) {
ARM_LDR_IMM (code, ARMREG_V2, ARMREG_LR, 0);
}
else
ARM_MOV_REG_REG (code, ARMREG_V2, MONO_ARCH_VTABLE_REG);
}
@@ -212,8 +272,13 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
code += 4;
ARM_LDR_REG_REG (code, ARMREG_R0, ARMREG_PC, ARMREG_R0);
} else {
#ifdef USE_JUMP_TABLES
load_get_lmf_addr = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, load_get_lmf_addr, ARMREG_R0);
#else
load_get_lmf_addr = code;
code += 4;
#endif
}
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
code = emit_bx (code, ARMREG_R0);
@@ -289,8 +354,13 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
code += 4;
ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
} else {
#ifdef USE_JUMP_TABLES
load_trampoline = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, load_trampoline, ARMREG_IP);
#else
load_trampoline = code;
code += 4;
#endif
}
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
@@ -316,10 +386,16 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
code += 4;
ARM_LDR_REG_REG (code, ARMREG_IP, ARMREG_PC, ARMREG_IP);
} else {
#ifdef USE_JUMP_TABLES
gpointer *jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
jte [0] = mono_thread_force_interruption_checkpoint;
#else
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 0);
ARM_B (code, 0);
*(gpointer*)code = mono_thread_force_interruption_checkpoint;
code += 4;
#endif
}
ARM_MOV_REG_REG (code, ARMREG_LR, ARMREG_PC);
code = emit_bx (code, ARMREG_IP);
@@ -352,6 +428,10 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
else
code = emit_bx (code, ARMREG_IP);
#ifdef USE_JUMP_TABLES
load_get_lmf_addr [0] = mono_get_lmf_addr;
load_trampoline [0] = (gpointer)mono_get_trampoline_func (tramp_type);
#else
constants = (gpointer*)code;
constants [0] = mono_get_lmf_addr;
constants [1] = (gpointer)mono_get_trampoline_func (tramp_type);
@@ -363,6 +443,7 @@ mono_arch_create_generic_trampoline (MonoTrampolineType tramp_type, MonoTrampInf
}
code += 8;
#endif
/* Flush instruction cache, since we've generated code */
mono_arch_flush_icache (buf, code - buf);
@@ -404,18 +485,42 @@ mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_ty
{
guint8 *code, *buf, *tramp;
gpointer *constants;
guint32 short_branch, size = SPEC_TRAMP_SIZE;
#ifndef USE_JUMP_TABLES
guint32 short_branch;
#endif
guint32 size = SPEC_TRAMP_SIZE;
tramp = mono_get_trampoline_code (tramp_type);
mono_domain_lock (domain);
#ifdef USE_JUMP_TABLES
code = buf = mono_domain_code_reserve_align (domain, size, 4);
#else
code = buf = mono_domain_code_reserve_align (domain, size, 4);
if ((short_branch = branch_for_target_reachable (code + 4, tramp))) {
size = 12;
mono_domain_code_commit (domain, code, SPEC_TRAMP_SIZE, size);
}
#endif
mono_domain_unlock (domain);
#ifdef USE_JUMP_TABLES
/* For jumptables case we always generate the same code for trampolines,
* namely
* push {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, lr}
* movw lr, lo(jte)
* movt lr, hi(jte)
* ldr r1, [lr + 4]
* bx r1
*/
ARM_PUSH (code, 0x5fff);
constants = mono_jumptable_add_entries (2);
code = mono_arm_load_jumptable_entry_addr (code, constants, ARMREG_LR);
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_LR, 4);
code = emit_bx (code, ARMREG_R1);
constants[0] = arg1;
constants[1] = tramp;
#else
/* we could reduce this to 12 bytes if tramp is within reach:
* ARM_PUSH ()
* ARM_BL ()
@@ -445,6 +550,7 @@ mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_ty
constants [1] = tramp;
code += 8;
}
#endif
/* Flush instruction cache, since we've generated code */
mono_arch_flush_icache (buf, code - buf);
@@ -471,16 +577,30 @@ mono_arch_get_unbox_trampoline (MonoMethod *m, gpointer addr)
{
guint8 *code, *start;
MonoDomain *domain = mono_domain_get ();
#ifdef USE_JUMP_TABLES
gpointer *jte;
guint32 size = 20;
#else
guint32 size = 16;
#endif
start = code = mono_domain_code_reserve (domain, 16);
start = code = mono_domain_code_reserve (domain, size);
#ifdef USE_JUMP_TABLES
jte = mono_jumptable_add_entry ();
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_IP);
ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_R0, sizeof (MonoObject));
code = emit_bx (code, ARMREG_IP);
jte [0] = addr;
#else
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_PC, 4);
ARM_ADD_REG_IMM8 (code, ARMREG_R0, ARMREG_R0, sizeof (MonoObject));
code = emit_bx (code, ARMREG_IP);
*(guint32*)code = (guint32)addr;
code += 4;
#endif
mono_arch_flush_icache (start, code - start);
g_assert ((code - start) <= 16);
g_assert ((code - start) <= size);
/*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
g_print ("unbox code is at %p for method at %p\n", start, addr);*/
@@ -491,20 +611,32 @@ gpointer
mono_arch_get_static_rgctx_trampoline (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr)
{
guint8 *code, *start;
int buf_len;
#ifdef USE_JUMP_TABLES
int buf_len = 20;
gpointer *jte;
#else
int buf_len = 16;
#endif
MonoDomain *domain = mono_domain_get ();
buf_len = 16;
start = code = mono_domain_code_reserve (domain, buf_len);
#ifdef USE_JUMP_TABLES
jte = mono_jumptable_add_entries (2);
code = mono_arm_load_jumptable_entry_addr (code, jte, ARMREG_IP);
ARM_LDR_IMM (code, MONO_ARCH_RGCTX_REG, ARMREG_IP, 0);
ARM_LDR_IMM (code, ARMREG_IP, ARMREG_IP, 4);
ARM_BX (code, ARMREG_IP);
jte [0] = mrgctx;
jte [1] = addr;
#else
ARM_LDR_IMM (code, MONO_ARCH_RGCTX_REG, ARMREG_PC, 0);
ARM_LDR_IMM (code, ARMREG_PC, ARMREG_PC, 0);
*(guint32*)code = (guint32)mrgctx;
code += 4;
*(guint32*)code = (guint32)addr;
code += 4;
#endif
g_assert ((code - start) <= buf_len);
@@ -526,6 +658,9 @@ mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info
gboolean mrgctx;
MonoJumpInfo *ji = NULL;
GSList *unwind_ops = NULL;
#ifdef USE_JUMP_TABLES
gpointer *jte;
#endif
mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
index = MONO_RGCTX_SLOT_INDEX (slot);
@@ -613,10 +748,17 @@ mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info
tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), &code_len);
/* Jump to the actual trampoline */
#ifdef USE_JUMP_TABLES
jte = mono_jumptable_add_entry ();
jte [0] = tramp;
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_R1);
code = emit_bx (code, ARMREG_R1);
#else
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
code = emit_bx (code, ARMREG_R1);
*(gpointer*)code = tramp;
code += 4;
#endif
}
mono_arch_flush_icache (buf, code - buf);
@@ -708,13 +850,22 @@ mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean a
code += 4;
ARM_LDR_REG_REG (code, ARMREG_PC, ARMREG_PC, ARMREG_R1);
} else {
#ifdef USE_JUMP_TABLES
gpointer *jte = mono_jumptable_add_entry ();
#endif
tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT, mono_get_root_domain (), &code_len);
/* Jump to the actual trampoline */
#ifdef USE_JUMP_TABLES
code = mono_arm_load_jumptable_entry (code, jte, ARMREG_R1);
jte [0] = tramp;
code = emit_bx (code, ARMREG_R1);
#else
ARM_LDR_IMM (code, ARMREG_R1, ARMREG_PC, 0); /* temp reg */
code = emit_bx (code, ARMREG_R1);
*(gpointer*)code = tramp;
code += 4;
#endif
}
mono_arch_flush_icache (buf, code - buf);