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:
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 */
+};
+#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
}
/*
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);
}
*/
}
- 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;
}
}
- 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) {
{
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)
#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)
{
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);
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 (mono_gc_card_table_nursery_check ()) {
+ 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);
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);
- if (mono_gc_card_table_nursery_check ())
+ if (card_table_nursery_check)
x86_patch (br, code);
break;
}
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)
{
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;
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];
if (CALLCONV_IS_STDCALL (sig)) {
MonoJitArgumentInfo *arg_info = alloca (sizeof (MonoJitArgumentInfo) * (sig->param_count + 1));
- stack_to_pop = mono_arch_get_argument_info (cfg->generic_sharing_context, 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;
#endif
+#if defined(MONOTOUCH) || defined(MONO_EXTENSIONS)
+
+#include "../../../mono-extensions/mono/mini/mini-x86-gsharedvt.c"
+
+#endif /* !MONOTOUCH */