#ifdef __native_client_codegen__
-const guint kNaClAlignment = kNaClAlignmentX86;
-const guint kNaClAlignmentMask = kNaClAlignmentMaskX86;
/* Default alignment for Native Client is 32-byte. */
gint8 nacl_align_byte = -32; /* signed version of 0xe0 */
gint16 offset;
gint8 reg;
ArgStorage storage;
+ int nslots;
+ gboolean is_pair;
/* Only if storage == ArgValuetypeInReg */
ArgStorage pair_storage [2];
gboolean vtype_retaddr;
/* The index of the vret arg in the argument list */
int vret_arg_index;
+ int vret_arg_offset;
ArgInfo ret;
ArgInfo sig_cookie;
ArgInfo args [1];
ainfo->storage = ArgOnStack;
(*stack_size) += sizeof (gpointer) * 2;
+ ainfo->nslots = 2;
}
static void inline
if (*gr >= FLOAT_PARAM_REGS) {
ainfo->storage = ArgOnStack;
(*stack_size) += is_double ? 8 : 4;
+ ainfo->nslots = is_double ? 2 : 1;
}
else {
/* A double register */
ainfo->offset = *stack_size;
ainfo->storage = ArgOnStack;
*stack_size += ALIGN_TO (size, sizeof (gpointer));
+ ainfo->nslots = ALIGN_TO (size, sizeof (gpointer)) / sizeof (gpointer);
}
/*
gr = 0;
fr = 0;
+ cinfo->nargs = n;
/* return value */
{
case MONO_TYPE_I8:
cinfo->ret.storage = ArgInIReg;
cinfo->ret.reg = X86_EAX;
+ cinfo->ret.is_pair = TRUE;
break;
case MONO_TYPE_R4:
cinfo->ret.storage = ArgOnFloatFpStack;
break;
}
/* Fall through */
- case MONO_TYPE_VALUETYPE: {
+ case MONO_TYPE_VALUETYPE:
+ case MONO_TYPE_TYPEDBYREF: {
guint32 tmp_gr = 0, tmp_fr = 0, tmp_stacksize = 0;
add_valuetype (gsctx, sig, &cinfo->ret, sig->ret, TRUE, &tmp_gr, &tmp_fr, &tmp_stacksize);
}
break;
}
- case MONO_TYPE_TYPEDBYREF:
- /* Same as a valuetype with size 12 */
- cinfo->vtype_retaddr = TRUE;
- break;
case MONO_TYPE_VOID:
cinfo->ret.storage = ArgNone;
break;
add_general (&gr, &stack_size, &cinfo->args [sig->hasthis + 0]);
pstart = 1;
}
+ cinfo->vret_arg_offset = stack_size;
add_general (&gr, &stack_size, &cinfo->ret);
cinfo->vret_arg_index = 1;
} else {
}
/* Fall through */
case MONO_TYPE_VALUETYPE:
- add_valuetype (gsctx, sig, ainfo, sig->params [i], FALSE, &gr, &fr, &stack_size);
- break;
case MONO_TYPE_TYPEDBYREF:
- stack_size += sizeof (MonoTypedRef);
- ainfo->storage = ArgOnStack;
+ add_valuetype (gsctx, sig, ainfo, ptype, FALSE, &gr, &fr, &stack_size);
break;
case MONO_TYPE_U8:
case MONO_TYPE_I8:
* FIXME: The metadata calls might not be signal safe.
*/
int
-mono_arch_get_argument_info (MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
+mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig, int param_count, MonoJitArgumentInfo *arg_info)
{
int len, k, args_size = 0;
int size, pad;
cinfo = (CallInfo*)g_newa (guint8*, len);
memset (cinfo, 0, len);
- cinfo = get_call_info_internal (NULL, cinfo, csig);
+ cinfo = get_call_info_internal (gsctx, cinfo, csig);
arg_info [0].offset = offset;
return res;
}
+#if !defined(__native_client__)
static const guchar cpuid_impl [] = {
0x55, /* push %ebp */
0x89, 0xe5, /* mov %esp,%ebp */
0xc9, /* leave */
0xc3, /* ret */
};
+#else
+static const guchar cpuid_impl [] = {
+ 0x55, /* push %ebp */
+ 0x89, 0xe5, /* mov %esp,%ebp */
+ 0x53, /* push %ebx */
+ 0x8b, 0x45, 0x08, /* mov 0x8(%ebp),%eax */
+ 0x0f, 0xa2, /* cpuid */
+ 0x50, /* push %eax */
+ 0x8b, 0x45, 0x10, /* mov 0x10(%ebp),%eax */
+ 0x89, 0x18, /* mov %ebx,(%eax) */
+ 0x8b, 0x45, 0x14, /* mov 0x14(%ebp),%eax */
+ 0x89, 0x08, /* mov %ecx,(%eax) */
+ 0x8b, 0x45, 0x18, /* mov 0x18(%ebp),%eax */
+ 0x89, 0x10, /* mov %edx,(%eax) */
+ 0x58, /* pop %eax */
+ 0x8b, 0x55, 0x0c, /* mov 0xc(%ebp),%edx */
+ 0x89, 0x02, /* mov %eax,(%edx) */
+ 0x5b, /* pop %ebx */
+ 0xc9, /* leave */
+ 0x59, 0x83, 0xe1, 0xe0, 0xff, 0xe1, /* naclret */
+ 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, /* padding, to provide bundle aligned version */
+ 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+ 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+ 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
+ 0xf4
+};
+#endif
typedef void (*CpuidFunc) (int id, int* p_eax, int* p_ebx, int* p_ecx, int* p_edx);
cpuid (int id, int* p_eax, int* p_ebx, int* p_ecx, int* p_edx)
{
#if defined(__native_client__)
- /* Taken from below, the bug listed in the comment is */
- /* only valid for non-static cases. */
- __asm__ __volatile__ ("cpuid"
- : "=a" (*p_eax), "=b" (*p_ebx), "=c" (*p_ecx), "=d" (*p_edx)
- : "a" (id));
- return 1;
+ static CpuidFunc func = NULL;
+ void *ptr, *end_ptr;
+ if (!func) {
+ ptr = mono_global_codeman_reserve (sizeof (cpuid_impl));
+ memcpy(ptr, cpuid_impl, sizeof(cpuid_impl));
+ end_ptr = ptr + sizeof(cpuid_impl);
+ nacl_global_codeman_validate (&ptr, sizeof(cpuid_impl), &end_ptr);
+ func = (CpuidFunc)ptr;
+ }
+ func (id, p_eax, p_ebx, p_ecx, p_edx);
#else
int have_cpuid = 0;
#ifndef _MSC_VER
mono_aot_register_jit_icall ("mono_x86_throw_exception", mono_x86_throw_exception);
mono_aot_register_jit_icall ("mono_x86_throw_corlib_exception", mono_x86_throw_corlib_exception);
+#if defined(MONOTOUCH) || defined(MONO_EXTENSIONS)
+ mono_aot_register_jit_icall ("mono_x86_start_gsharedvt_call", mono_x86_start_gsharedvt_call);
+#endif
}
/*
void
mono_arch_cleanup (void)
{
+ if (ss_trigger_page)
+ mono_vfree (ss_trigger_page, mono_pagesize ());
+ if (bp_trigger_page)
+ mono_vfree (bp_trigger_page, mono_pagesize ());
DeleteCriticalSection (&mini_arch_mutex);
}
* This function returns the optimizations supported on this cpu.
*/
guint32
-mono_arch_cpu_optimizazions (guint32 *exclude_mask)
+mono_arch_cpu_optimizations (guint32 *exclude_mask)
{
#if !defined(__native_client__)
int eax, ebx, ecx, edx;
return;
}
if (locals_stack_align) {
+ int prev_offset = offset;
+
offset += (locals_stack_align - 1);
offset &= ~(locals_stack_align - 1);
+
+ while (prev_offset < offset) {
+ prev_offset += 4;
+ mini_gc_set_slot_type_from_fp (cfg, - prev_offset, SLOT_NOREF);
+ }
}
cfg->locals_min_stack_offset = - (offset + locals_stack_size);
cfg->locals_max_stack_offset = - offset;
switch (cinfo->ret.storage) {
case ArgOnStack:
- if (MONO_TYPE_ISSTRUCT (sig->ret)) {
+ if (cfg->vret_addr) {
/*
* In the new IR, the cfg->vret_addr variable represents the
* vtype return value.
if (cinfo->ret.storage == ArgValuetypeInReg)
cfg->ret_var_is_local = TRUE;
- if ((cinfo->ret.storage != ArgValuetypeInReg) && MONO_TYPE_ISSTRUCT (sig->ret)) {
+ if ((cinfo->ret.storage != ArgValuetypeInReg) && (MONO_TYPE_ISSTRUCT (sig->ret) || mini_is_gsharedvt_variable_type (cfg, sig->ret))) {
cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
}
+
+ cfg->arch_eh_jit_info = 1;
}
/*
emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
{
MonoMethodSignature *tmp_sig;
-
- /* FIXME: Add support for signature tokens to AOT */
- cfg->disable_aot = TRUE;
+ int sig_reg;
/*
* mono_ArgIterator_Setup assumes the signature cookie is
tmp_sig->sentinelpos = 0;
memcpy (tmp_sig->params, call->signature->params + call->signature->sentinelpos, tmp_sig->param_count * sizeof (MonoType*));
- MONO_EMIT_NEW_BIALU_IMM (cfg, OP_X86_PUSH_IMM, -1, -1, tmp_sig);
+ if (cfg->compile_aot) {
+ sig_reg = mono_alloc_ireg (cfg);
+ MONO_EMIT_NEW_SIGNATURECONST (cfg, sig_reg, tmp_sig);
+ MONO_EMIT_NEW_UNALU (cfg, OP_X86_PUSH, -1, sig_reg);
+ } else {
+ MONO_EMIT_NEW_BIALU_IMM (cfg, OP_X86_PUSH_IMM, -1, -1, tmp_sig);
+ }
}
#ifdef ENABLE_LLVM
*/
}
- if (MONO_TYPE_ISSTRUCT (sig->ret) && cinfo->ret.storage == ArgInIReg) {
+ if (mini_type_is_vtype (cfg, sig->ret) && cinfo->ret.storage == ArgInIReg) {
/* Vtype returned using a hidden argument */
linfo->ret.storage = LLVMArgVtypeRetAddr;
linfo->vret_arg_index = cinfo->vret_arg_index;
}
- if (MONO_TYPE_ISSTRUCT (sig->ret) && cinfo->ret.storage != ArgInIReg) {
+ if (mini_type_is_vtype (cfg, sig->ret) && cinfo->ret.storage != ArgInIReg) {
// FIXME:
cfg->exception_message = g_strdup ("vtype ret in call");
cfg->disable_llvm = TRUE;
linfo->args [i].storage = LLVMArgInFPReg;
break;
case ArgOnStack:
- if (MONO_TYPE_ISSTRUCT (t)) {
+ if (mini_type_is_vtype (cfg, t)) {
if (mono_class_value_size (mono_class_from_mono_type (t), NULL) == 0)
/* LLVM seems to allocate argument space for empty structures too */
linfo->args [i].storage = LLVMArgNone;
}
#endif
+static void
+emit_gc_param_slot_def (MonoCompile *cfg, int sp_offset, MonoType *t)
+{
+ if (cfg->compute_gc_maps) {
+ MonoInst *def;
+
+ /* On x86, the offsets are from the sp value before the start of the call sequence */
+ if (t == NULL)
+ t = &mono_defaults.int_class->byval_arg;
+ EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, sp_offset, t);
+ }
+}
+
void
mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
{
MonoInst *arg, *in;
MonoMethodSignature *sig;
- int i, n;
+ int i, j, n;
CallInfo *cinfo;
- int sentinelpos = 0;
+ int sentinelpos = 0, sp_offset = 0;
sig = call->signature;
n = sig->param_count + sig->hasthis;
arg->sreg1 = X86_ESP;
arg->inst_imm = cinfo->stack_align_amount;
MONO_ADD_INS (cfg->cbb, arg);
+ for (i = 0; i < cinfo->stack_align_amount; i += sizeof (mgreg_t)) {
+ sp_offset += 4;
+
+ emit_gc_param_slot_def (cfg, sp_offset, NULL);
+ }
}
if (sig->ret && MONO_TYPE_ISSTRUCT (sig->ret)) {
}
}
+ // FIXME: Emit EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF everywhere
+
/* Handle the case where there are no implicit arguments */
if (!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG) && (n == sentinelpos)) {
emit_sig_cookie (cfg, call, cinfo);
+ sp_offset += 4;
+ emit_gc_param_slot_def (cfg, sp_offset, NULL);
}
/* Arguments are pushed in the reverse order */
for (i = n - 1; i >= 0; i --) {
ArgInfo *ainfo = cinfo->args + i;
- MonoType *t;
+ MonoType *orig_type, *t;
+ int argsize;
if (cinfo->vtype_retaddr && cinfo->vret_arg_index == 1 && i == 0) {
/* Push the vret arg before the first argument */
vtarg->type = STACK_MP;
vtarg->sreg1 = call->vret_var->dreg;
MONO_ADD_INS (cfg->cbb, vtarg);
+ sp_offset += 4;
+ emit_gc_param_slot_def (cfg, sp_offset, NULL);
}
if (i >= sig->hasthis)
t = sig->params [i - sig->hasthis];
else
t = &mono_defaults.int_class->byval_arg;
+ orig_type = t;
t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
MONO_INST_NEW (cfg, arg, OP_X86_PUSH);
arg->backend.size = size;
MONO_ADD_INS (cfg->cbb, arg);
+ sp_offset += size;
+ emit_gc_param_slot_def (cfg, sp_offset, orig_type);
}
- }
- else {
+ } else {
+ argsize = 4;
+
switch (ainfo->storage) {
case ArgOnStack:
arg->opcode = OP_X86_PUSH;
arg->opcode = OP_STORER4_MEMBASE_REG;
arg->inst_destbasereg = X86_ESP;
arg->inst_offset = 0;
+ argsize = 4;
} else if (t->type == MONO_TYPE_R8) {
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_SUB_IMM, X86_ESP, X86_ESP, 8);
arg->opcode = OP_STORER8_MEMBASE_REG;
arg->inst_destbasereg = X86_ESP;
arg->inst_offset = 0;
+ argsize = 8;
} else if (t->type == MONO_TYPE_I8 || t->type == MONO_TYPE_U8) {
arg->sreg1 ++;
MONO_EMIT_NEW_UNALU (cfg, OP_X86_PUSH, -1, in->dreg + 2);
+ sp_offset += 4;
}
}
break;
}
MONO_ADD_INS (cfg->cbb, arg);
+
+ sp_offset += argsize;
+
+ if (cfg->compute_gc_maps) {
+ if (argsize == 4) {
+ /* FIXME: The == STACK_OBJ check might be fragile ? */
+ if (sig->hasthis && i == 0 && call->args [i]->type == STACK_OBJ) {
+ /* this */
+ if (call->need_unbox_trampoline)
+ /* The unbox trampoline transforms this into a managed pointer */
+ emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.int_class->this_arg);
+ else
+ emit_gc_param_slot_def (cfg, sp_offset, &mono_defaults.object_class->byval_arg);
+ } else {
+ emit_gc_param_slot_def (cfg, sp_offset, orig_type);
+ }
+ } else {
+ /* i8/r8 */
+ for (j = 0; j < argsize; j += 4)
+ emit_gc_param_slot_def (cfg, sp_offset - j, NULL);
+ }
+ }
}
if (!sig->pinvoke && (sig->call_convention == MONO_CALL_VARARG) && (i == sentinelpos)) {
/* Emit the signature cookie just before the implicit arguments */
emit_sig_cookie (cfg, call, cinfo);
+ sp_offset += 4;
+ emit_gc_param_slot_def (cfg, sp_offset, NULL);
}
}
- if (sig->ret && MONO_TYPE_ISSTRUCT (sig->ret)) {
+ if (sig->ret && (MONO_TYPE_ISSTRUCT (sig->ret) || cinfo->vtype_retaddr)) {
MonoInst *vtarg;
if (cinfo->ret.storage == ArgValuetypeInReg) {
vtarg->type = STACK_MP;
vtarg->sreg1 = call->vret_var->dreg;
MONO_ADD_INS (cfg->cbb, vtarg);
+ sp_offset += 4;
+ emit_gc_param_slot_def (cfg, sp_offset, NULL);
}
/* if the function returns a struct on stack, the called method already does a ret $0x4 */
}
call->stack_usage = cinfo->stack_usage;
+ call->stack_align_amount = cinfo->stack_align_amount;
+ cfg->arch.param_area_size = MAX (cfg->arch.param_area_size, sp_offset);
}
void
{
gboolean needs_paddings = TRUE;
guint32 pad_size;
+ MonoJumpInfo *jinfo = NULL;
- if (cfg->abs_patches && g_hash_table_lookup (cfg->abs_patches, data)) {
- } else {
- MonoJitICallInfo *info = mono_find_jit_icall_by_addr (data);
- if (info) {
- if ((cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) && strstr (cfg->method->name, info->name))
- needs_paddings = FALSE; /* A call to the wrapped function */
- }
+ if (cfg->abs_patches) {
+ jinfo = g_hash_table_lookup (cfg->abs_patches, data);
+ if (jinfo && jinfo->type == MONO_PATCH_INFO_JIT_ICALL_ADDR)
+ needs_paddings = FALSE;
}
if (cfg->compile_aot)
#ifdef __APPLE__
static gboolean have_tls_get = FALSE;
static gboolean inited = FALSE;
+ guint32 *ins;
if (inited)
return have_tls_get;
- guint32 *ins = (guint32*)pthread_getspecific;
+ ins = (guint32*)pthread_getspecific;
/*
* We're looking for these two instructions:
*
inited = TRUE;
return have_tls_get;
+#elif defined(TARGET_ANDROID)
+ return FALSE;
#else
return TRUE;
#endif
}
+static guint8*
+mono_x86_emit_tls_set (guint8* code, int sreg, int tls_offset)
+{
+#if defined(__APPLE__)
+ x86_prefix (code, X86_GS_PREFIX);
+ x86_mov_mem_reg (code, tls_gs_offset + (tls_offset * 4), sreg, 4);
+#elif defined(TARGET_WIN32)
+ g_assert_not_reached ();
+#else
+ x86_prefix (code, X86_GS_PREFIX);
+ x86_mov_mem_reg (code, tls_offset, sreg, 4);
+#endif
+ return code;
+}
+
/*
* mono_x86_emit_tls_get:
* @code: buffer to store code to
#define bb_is_loop_start(bb) ((bb)->loop_body_start && (bb)->nesting)
#ifndef DISABLE_JIT
-
-#if defined(__native_client__) || defined(__native_client_codegen__)
-void
-mono_nacl_gc()
-{
-#ifdef __native_client_gc__
- __nacl_suspend_thread_if_needed();
-#endif
-}
-#endif
-
void
mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
{
*/
for (i = 0; i < 6; ++i)
x86_nop (code);
+ /*
+ * Add an additional nop so skipping the bp doesn't cause the ip to point
+ * to another IL offset.
+ */
+ x86_nop (code);
break;
}
case OP_ADDCC:
break;
case OP_IDIV:
case OP_IREM:
+#if defined( __native_client_codegen__ )
+ x86_alu_reg_imm (code, X86_CMP, ins->sreg2, 0);
+ EMIT_COND_SYSTEM_EXCEPTION (X86_CC_EQ, TRUE, "DivideByZeroException");
+#endif
/*
* The code is the same for div/rem, the allocator will allocate dreg
* to RAX/RDX as appropriate.
break;
case OP_IDIV_UN:
case OP_IREM_UN:
+#if defined( __native_client_codegen__ )
+ x86_alu_reg_imm (code, X86_CMP, ins->sreg2, 0);
+ EMIT_COND_SYSTEM_EXCEPTION (X86_CC_EQ, TRUE, "DivideByZeroException");
+#endif
if (ins->sreg2 == X86_EDX) {
x86_push_reg (code, ins->sreg2);
x86_alu_reg_reg (code, X86_XOR, X86_EDX, X86_EDX);
}
break;
case OP_DIV_IMM:
+#if defined( __native_client_codegen__ )
+ if (ins->inst_imm == 0) {
+ mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_EXC, "DivideByZeroException");
+ x86_jump32 (code, 0);
+ break;
+ }
+#endif
x86_mov_reg_imm (code, ins->sreg2, ins->inst_imm);
x86_cdq (code);
x86_div_reg (code, ins->sreg2, TRUE);
MonoCallInst *call = (MonoCallInst*)ins;
int pos = 0, i;
+ ins->flags |= MONO_INST_GC_CALLSITE;
+ ins->backend.pc_offset = code - cfg->native_code;
+
/* FIXME: no tracing support... */
if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
code = mono_arch_instrument_epilog (cfg, mono_profiler_method_leave, code, FALSE);
}
/* Copy arguments on the stack to our argument area */
- for (i = 0; i < call->stack_usage; i += 4) {
+ for (i = 0; i < call->stack_usage - call->stack_align_amount; i += 4) {
x86_mov_reg_membase (code, X86_EAX, X86_ESP, i, 4);
x86_mov_membase_reg (code, X86_EBP, 8 + i, X86_EAX, 4);
}
mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD_JUMP, ins->inst_p0);
x86_jump32 (code, 0);
+ ins->flags |= MONO_INST_GC_CALLSITE;
cfg->disable_aot = TRUE;
break;
}
br = code; x86_branch8 (code, X86_CC_GEZ, 0, TRUE);
/* add correction constant mn */
- x86_fld80_mem (code, mn);
+ if (cfg->compile_aot) {
+ x86_push_imm (code, (((guint32)mn [9]) << 24) | ((guint32)mn [8] << 16) | ((guint32)mn [7] << 8) | ((guint32)mn [6]));
+ x86_push_imm (code, (((guint32)mn [5]) << 24) | ((guint32)mn [4] << 16) | ((guint32)mn [3] << 8) | ((guint32)mn [2]));
+ x86_push_imm (code, (((guint32)mn [1]) << 24) | ((guint32)mn [0] << 16));
+ x86_fld80_membase (code, X86_ESP, 2);
+ x86_alu_reg_imm (code, X86_ADD, X86_ESP, 12);
+ } else {
+ x86_fld80_mem (code, mn);
+ }
x86_fp_op_reg (code, X86_FADD, 1, TRUE);
x86_patch (br, code);
x86_fprem (code);
x86_fnstsw (code);
x86_alu_reg_imm (code, X86_AND, X86_EAX, X86_FP_C2);
- l2 = code + 2;
- x86_branch8 (code, X86_CC_NE, l1 - l2, FALSE);
+ l2 = code;
+ x86_branch8 (code, X86_CC_NE, 0, FALSE);
+ x86_patch (l2, l1);
/* pop result */
x86_fstp (code, 1);
size_t nursery_size;
gulong card_table = (gulong)mono_gc_get_card_table (&card_table_shift, &card_table_mask);
gulong nursery_start = (gulong)mono_gc_get_nursery (&nursery_shift, &nursery_size);
+ gboolean card_table_nursery_check = mono_gc_card_table_nursery_check ();
/*
* We need one register we can clobber, we choose EDX and make sreg1
* done:
*/
- if (value != X86_EDX)
- x86_mov_reg_reg (code, X86_EDX, value, 4);
- x86_shift_reg_imm (code, X86_SHR, X86_EDX, nursery_shift);
- x86_alu_reg_imm (code, X86_CMP, X86_EDX, nursery_start >> nursery_shift);
- br = code; x86_branch8 (code, X86_CC_NE, -1, FALSE);
+ if (card_table_nursery_check) {
+ if (value != X86_EDX)
+ x86_mov_reg_reg (code, X86_EDX, value, 4);
+ x86_shift_reg_imm (code, X86_SHR, X86_EDX, nursery_shift);
+ x86_alu_reg_imm (code, X86_CMP, X86_EDX, nursery_start >> nursery_shift);
+ br = code; x86_branch8 (code, X86_CC_NE, -1, FALSE);
+ }
x86_mov_reg_reg (code, X86_EDX, ptr, 4);
x86_shift_reg_imm (code, X86_SHR, X86_EDX, card_table_shift);
if (card_table_mask)
x86_alu_reg_imm (code, X86_AND, X86_EDX, (int)card_table_mask);
x86_mov_membase_imm (code, X86_EDX, card_table, 1, 1);
- x86_patch (br, code);
+ if (card_table_nursery_check)
+ x86_patch (br, code);
break;
}
#ifdef MONO_ARCH_SIMD_INTRINSICS
break;
}
case OP_NACL_GC_SAFE_POINT: {
-#if defined(__native_client_codegen__)
- code = emit_call (cfg, code, MONO_PATCH_INFO_ABS, (gpointer)mono_nacl_gc);
+#if defined(__native_client_codegen__) && defined(__native_client_gc__)
+ if (cfg->compile_aot)
+ code = emit_call (cfg, code, MONO_PATCH_INFO_ABS, (gpointer)mono_nacl_gc);
+ else {
+ guint8 *br [1];
+
+ x86_test_mem_imm8 (code, (gpointer)&__nacl_thread_suspension_needed, 0xFFFFFFFF);
+ br[0] = code; x86_branch8 (code, X86_CC_EQ, 0, FALSE);
+ code = emit_call (cfg, code, MONO_PATCH_INFO_ABS, (gpointer)mono_nacl_gc);
+ x86_patch (br[0], code);
+ }
#endif
break;
}
case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
case MONO_PATCH_INFO_MONITOR_ENTER:
case MONO_PATCH_INFO_MONITOR_EXIT:
+ case MONO_PATCH_INFO_JIT_ICALL_ADDR:
#if defined(__native_client_codegen__) && defined(__native_client__)
if (nacl_is_code_address (code)) {
/* For tail calls, code is patched after being installed */
}
}
+static G_GNUC_UNUSED void
+stack_unaligned (MonoMethod *m, gpointer caller)
+{
+ printf ("%s\n", mono_method_full_name (m, TRUE));
+ g_assert_not_reached ();
+}
+
guint8 *
mono_arch_emit_prolog (MonoCompile *cfg)
{
code = cfg->native_code = g_malloc (cfg->code_size);
#elif defined(__native_client_codegen__)
/* native_code_alloc is not 32-byte aligned, native_code is. */
+ cfg->code_size = NACL_BUNDLE_ALIGN_UP (cfg->code_size);
cfg->native_code_alloc = g_malloc (cfg->code_size + kNaClAlignment);
/* Align native_code to next nearest kNaclAlignment byte. */
g_assert(alignment_check == 0);
#endif
+#if 0
+ {
+ guint8 *br [16];
+
+ /* Check that the stack is aligned on osx */
+ x86_mov_reg_reg (code, X86_EAX, X86_ESP, sizeof (mgreg_t));
+ x86_alu_reg_imm (code, X86_AND, X86_EAX, 15);
+ x86_alu_reg_imm (code, X86_CMP, X86_EAX, 0xc);
+ br [0] = code;
+ x86_branch_disp (code, X86_CC_Z, 0, FALSE);
+ x86_push_membase (code, X86_ESP, 0);
+ x86_push_imm (code, cfg->method);
+ x86_mov_reg_imm (code, X86_EAX, stack_unaligned);
+ x86_call_reg (code, X86_EAX);
+ x86_patch (br [0], code);
+ }
+#endif
+
/* Offset between RSP and the CFA */
cfa_offset = 0;
alloc_size = cfg->stack_offset;
pos = 0;
- if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
- /* Might need to attach the thread to the JIT or change the domain for the callback */
- if (appdomain_tls_offset != -1 && lmf_tls_offset != -1) {
- guint8 *buf, *no_domain_branch;
-
- code = mono_x86_emit_tls_get (code, X86_EAX, appdomain_tls_offset);
- x86_alu_reg_imm (code, X86_CMP, X86_EAX, GPOINTER_TO_UINT (cfg->domain));
- no_domain_branch = code;
- x86_branch8 (code, X86_CC_NE, 0, 0);
- code = mono_x86_emit_tls_get ( code, X86_EAX, lmf_tls_offset);
- x86_test_reg_reg (code, X86_EAX, X86_EAX);
- buf = code;
- x86_branch8 (code, X86_CC_NE, 0, 0);
- x86_patch (no_domain_branch, code);
- x86_push_imm (code, cfg->domain);
- code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, (gpointer)"mono_jit_thread_attach");
- x86_alu_reg_imm (code, X86_ADD, X86_ESP, 4);
- x86_patch (buf, code);
-#ifdef TARGET_WIN32
- /* The TLS key actually contains a pointer to the MonoJitTlsData structure */
- /* FIXME: Add a separate key for LMF to avoid this */
- x86_alu_reg_imm (code, X86_ADD, X86_EAX, G_STRUCT_OFFSET (MonoJitTlsData, lmf));
-#endif
- }
- else {
- if (cfg->compile_aot) {
- /*
- * This goes before the saving of callee saved regs, so save the got reg
- * ourselves.
- */
- x86_push_reg (code, MONO_ARCH_GOT_REG);
- code = mono_arch_emit_load_got_addr (cfg->native_code, code, cfg, NULL);
- x86_push_imm (code, 0);
- } else {
- x86_push_imm (code, cfg->domain);
- }
- code = emit_call (cfg, code, MONO_PATCH_INFO_INTERNAL_METHOD, (gpointer)"mono_jit_thread_attach");
- x86_alu_reg_imm (code, X86_ADD, X86_ESP, 4);
- if (cfg->compile_aot)
- x86_pop_reg (code, MONO_ARCH_GOT_REG);
- }
- }
-
if (method->save_lmf) {
pos += sizeof (MonoLMF);
x86_push_imm_template (code);
}
cfa_offset += sizeof (gpointer);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
/* save all caller saved regs */
x86_push_reg (code, X86_EBP);
cfa_offset += sizeof (gpointer);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
x86_push_reg (code, X86_ESI);
cfa_offset += sizeof (gpointer);
mono_emit_unwind_op_offset (cfg, code, X86_ESI, - cfa_offset);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
x86_push_reg (code, X86_EDI);
cfa_offset += sizeof (gpointer);
mono_emit_unwind_op_offset (cfg, code, X86_EDI, - cfa_offset);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
x86_push_reg (code, X86_EBX);
cfa_offset += sizeof (gpointer);
mono_emit_unwind_op_offset (cfg, code, X86_EBX, - cfa_offset);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
if ((lmf_tls_offset != -1) && !is_win32 && !optimize_for_xen) {
/*
* through the mono_lmf_addr TLS variable.
*/
/* %eax = previous_lmf */
- x86_prefix (code, X86_GS_PREFIX);
- x86_mov_reg_mem (code, X86_EAX, lmf_tls_offset, 4);
+ code = mono_x86_emit_tls_get (code, X86_EAX, lmf_tls_offset);
/* skip esp + method_info + lmf */
x86_alu_reg_imm (code, X86_SUB, X86_ESP, 12);
+ cfa_offset += 12;
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset + 4, SLOT_NOREF);
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset + 8, SLOT_NOREF);
/* push previous_lmf */
x86_push_reg (code, X86_EAX);
+ cfa_offset += 4;
+ mini_gc_set_slot_type_from_cfa (cfg, -cfa_offset, SLOT_NOREF);
/* new lmf = ESP */
- x86_prefix (code, X86_GS_PREFIX);
- x86_mov_mem_reg (code, lmf_tls_offset, X86_ESP, 4);
+ code = mono_x86_emit_tls_set (code, X86_ESP, lmf_tls_offset);
} else {
/* get the address of lmf for the current thread */
/*
if (need_stack_frame)
tot += 4; /* ebp */
tot &= MONO_ARCH_FRAME_ALIGNMENT - 1;
- if (tot)
+ if (tot) {
alloc_size += MONO_ARCH_FRAME_ALIGNMENT - tot;
+ for (i = 0; i < MONO_ARCH_FRAME_ALIGNMENT - tot; i += sizeof (mgreg_t))
+ mini_gc_set_slot_type_from_fp (cfg, - (alloc_size + pos - i), SLOT_NOREF);
+ }
}
+ cfg->arch.sp_fp_offset = alloc_size + pos;
+
if (alloc_size) {
/* See mono_emit_stack_alloc */
#if defined(TARGET_WIN32) || defined(MONO_ARCH_SIGSEGV_ON_ALTSTACK)
max_offset += LOOP_ALIGNMENT;
#ifdef __native_client_codegen__
/* max alignment for native client */
- max_offset += kNaClAlignment;
+ if (bb->flags & BB_INDIRECT_JUMP_TARGET || bb->flags & BB_EXCEPTION_HANDLER)
+ max_offset += kNaClAlignment;
#endif
MONO_BB_FOR_EACH_INS (bb, ins) {
if (ins->opcode == OP_LABEL)
ins->inst_c1 = max_offset;
#ifdef __native_client_codegen__
+ switch (ins->opcode)
{
- int space_in_block = kNaClAlignment -
- ((max_offset + cfg->code_len) & kNaClAlignmentMask);
- int max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
- if (space_in_block < max_len && max_len < kNaClAlignment) {
- max_offset += space_in_block;
- }
+ case OP_FCALL:
+ case OP_LCALL:
+ case OP_VCALL:
+ case OP_VCALL2:
+ case OP_VOIDCALL:
+ case OP_CALL:
+ case OP_FCALL_REG:
+ case OP_LCALL_REG:
+ case OP_VCALL_REG:
+ case OP_VCALL2_REG:
+ case OP_VOIDCALL_REG:
+ case OP_CALL_REG:
+ case OP_FCALL_MEMBASE:
+ case OP_LCALL_MEMBASE:
+ case OP_VCALL_MEMBASE:
+ case OP_VCALL2_MEMBASE:
+ case OP_VOIDCALL_MEMBASE:
+ case OP_CALL_MEMBASE:
+ max_offset += kNaClAlignment;
+ break;
+ default:
+ max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN] - 1;
+ break;
}
#endif /* __native_client_codegen__ */
max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
x86_mov_reg_membase (code, X86_ECX, X86_EBP, lmf_offset + G_STRUCT_OFFSET (MonoLMF, previous_lmf), 4);
/* lmf = previous_lmf */
- x86_prefix (code, X86_GS_PREFIX);
- x86_mov_mem_reg (code, lmf_tls_offset, X86_ECX, 4);
+ code = mono_x86_emit_tls_set (code, X86_ECX, lmf_tls_offset);
} else {
/* Find a spare register */
switch (mini_type_get_underlying_type (cfg->generic_sharing_context, sig->ret)->type) {
if (CALLCONV_IS_STDCALL (sig)) {
MonoJitArgumentInfo *arg_info = alloca (sizeof (MonoJitArgumentInfo) * (sig->param_count + 1));
- stack_to_pop = mono_arch_get_argument_info (sig, sig->param_count, arg_info);
- } else if (MONO_TYPE_ISSTRUCT (mono_method_signature (cfg->method)->ret) && (cinfo->ret.storage == ArgOnStack))
+ stack_to_pop = mono_arch_get_argument_info (NULL, sig, sig->param_count, arg_info);
+ } else if (cinfo->vtype_retaddr)
stack_to_pop = 4;
else
stack_to_pop = 0;
return TRUE;
}
-/*
- * Support for fast access to the thread-local lmf structure using the GS
- * segment register on NPTL + kernel 2.6.x.
- */
-
-static gboolean tls_offset_inited = FALSE;
-
void
-mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
+mono_arch_finish_init (void)
{
- if (!tls_offset_inited) {
- if (!getenv ("MONO_NO_TLS")) {
+ if (!getenv ("MONO_NO_TLS")) {
#ifdef TARGET_WIN32
- /*
- * We need to init this multiple times, since when we are first called, the key might not
- * be initialized yet.
- */
- appdomain_tls_offset = mono_domain_get_tls_key ();
- lmf_tls_offset = mono_get_jit_tls_key ();
-
- /* Only 64 tls entries can be accessed using inline code */
- if (appdomain_tls_offset >= 64)
- appdomain_tls_offset = -1;
- if (lmf_tls_offset >= 64)
- lmf_tls_offset = -1;
+ /*
+ * We need to init this multiple times, since when we are first called, the key might not
+ * be initialized yet.
+ */
+ appdomain_tls_offset = mono_domain_get_tls_key ();
+ lmf_tls_offset = mono_get_jit_tls_key ();
+
+ /* Only 64 tls entries can be accessed using inline code */
+ if (appdomain_tls_offset >= 64)
+ appdomain_tls_offset = -1;
+ if (lmf_tls_offset >= 64)
+ lmf_tls_offset = -1;
#else
#if MONO_XEN_OPT
- optimize_for_xen = access ("/proc/xen", F_OK) == 0;
+ optimize_for_xen = access ("/proc/xen", F_OK) == 0;
#endif
- tls_offset_inited = TRUE;
- appdomain_tls_offset = mono_domain_get_tls_offset ();
- lmf_tls_offset = mono_get_lmf_tls_offset ();
- lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset ();
+ appdomain_tls_offset = mono_domain_get_tls_offset ();
+ lmf_tls_offset = mono_get_lmf_tls_offset ();
+ lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset ();
#endif
- }
}
}
#if defined(__native_client__) && defined(__native_client_codegen__)
/* In Native Client, we don't re-use thunks, allocate from the */
/* normal code manager paths. */
+ size = NACL_BUNDLE_ALIGN_UP (size);
code = mono_domain_code_reserve (domain, size);
#else
if (fail_tramp)
{
if ((code [0] == 0x8b) && (x86_modrm_mod (code [1]) == 0x2))
return 2;
- else if ((code [0] == 0xba))
+ else if (code [0] == 0xba)
return 1;
- else if ((code [0] == 0x68))
+ else if (code [0] == 0x68)
/* push IMM */
return 1;
else if ((code [0] == 0xff) && (x86_modrm_reg (code [1]) == 0x6))
case X86_EBP: return ctx->ebp;
case X86_ESI: return ctx->esi;
case X86_EDI: return ctx->edi;
- default: g_assert_not_reached ();
+ default:
+ g_assert_not_reached ();
+ return 0;
}
}
#endif
}
-/*
- * mono_arch_get_ip_for_breakpoint:
- *
- * See mini-amd64.c for docs.
- */
-guint8*
-mono_arch_get_ip_for_breakpoint (MonoJitInfo *ji, MonoContext *ctx)
-{
- guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
-
- return ip;
-}
-
#define BREAKPOINT_SIZE 6
-/*
- * mono_arch_get_ip_for_single_step:
- *
- * See mini-amd64.c for docs.
- */
-guint8*
-mono_arch_get_ip_for_single_step (MonoJitInfo *ji, MonoContext *ctx)
-{
- guint8 *ip = MONO_CONTEXT_GET_IP (ctx);
-
- /* Size of x86_alu_reg_imm */
- ip += 6;
-
- return ip;
-}
-
/*
* mono_arch_skip_breakpoint:
*
* See mini-amd64.c for docs.
*/
void
-mono_arch_skip_breakpoint (MonoContext *ctx)
+mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
{
MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
}
#endif
+#if defined(MONOTOUCH) || defined(MONO_EXTENSIONS)
+
+#include "../../../mono-extensions/mono/mini/mini-x86-gsharedvt.c"
+
+#endif /* !MONOTOUCH */