/*------------------------------------------------------------------*/
#define NOT_IMPLEMENTED(x) \
- g_error ("FIXME: %s is not yet implemented. (trampoline)", x);
+ g_error ("FIXME: %s is not yet implemented.", x);
#define EMIT_COND_BRANCH(ins,cond) \
{ \
#undef DEBUG
#define DEBUG(a) if (cfg->verbose_level > 1) a
-#define reg_is_freeable(r) ((r) >= 3 && (r) <= 10)
-#define freg_is_freeable(r) ((r) >= 1 && (r) <= 14)
+
+#define MAX_EXC 16
/*----------------------------------------*/
-/* use s390_r3-s390_r10 as temp registers */
+/* use s390_r2-s390_r5 as temp registers */
/*----------------------------------------*/
-#define S390_CALLER_REGS (0x03f8)
+#define S390_CALLER_REGS (0x10fc)
+#define reg_is_freeable(r) (S390_CALLER_REGS & 1 << (r))
/*----------------------------------------*/
-/* use s390_f2-s390_f14 as temp registers */
+/* use s390_f1/s390_f3-s390_f15 as temps */
/*----------------------------------------*/
-#define S390_CALLER_FREGS (0x73f8)
+#define S390_CALLER_FREGS (0xfffa)
+#define freg_is_freeable(r) ((r) >= 1 && (r) <= 14)
#define S390_TRACE_STACK_SIZE (5*sizeof(gint32)+3*sizeof(gdouble))
+#define MAX (a, b) ((a) > (b) ? (a) : (b))
+
/*========================= End of Defines =========================*/
/*------------------------------------------------------------------*/
guint32 stack_usage;
guint32 struct_ret;
ArgInfo ret;
+ ArgInfo sigCookie;
ArgInfo args [1];
} CallInfo;
static guint32 * emit_memcpy (guint8 *, int, int, int, int, int);
static void indent (int);
-static guint8 * restoreLMF(MonoCompile *, guint8 *);
static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
static void decodeParm (MonoType *, void *, int);
static void enter_method (MonoMethod *, RegParm *, char *);
static const char*const * ins_spec = s390;
+static gboolean tls_offset_inited = FALSE;
+
+static int appdomain_tls_offset = -1,
+ lmf_tls_offset = -1,
+ thread_tls_offset = -1;
+
+#if 0
+
+extern __thread MonoDomain *tls_appdomain;
+extern __thread MonoThread *tls_current_object;
+extern __thread gpointer mono_lmf_addr;
+
+#endif
+
/*====================== End of Global Variables ===================*/
/*------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/* */
-/* Name - restoreLMF */
+/* Name - retFitsInReg. */
/* */
-/* Function - Restore the LMF state prior to exiting a method. */
+/* Function - Determines if a value can be returned in one or */
+/* two registers. */
/* */
/*------------------------------------------------------------------*/
-static inline guint8 *
-restoreLMF(MonoCompile *cfg, guint8 *code)
+static inline gboolean
+retFitsInReg(guint32 size)
{
- int lmfOffset = 0;
-
- s390_lr (code, s390_r13, cfg->frame_reg);
-
- lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
-
- /*-------------------------------------------------*/
- /* r13 = my lmf */
- /*-------------------------------------------------*/
- s390_ahi (code, s390_r13, lmfOffset);
-
- /*-------------------------------------------------*/
- /* r6 = &jit_tls->lmf */
- /*-------------------------------------------------*/
- s390_l (code, s390_r6, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
-
- /*-------------------------------------------------*/
- /* r0 = lmf.previous_lmf */
- /*-------------------------------------------------*/
- s390_l (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
-
- /*-------------------------------------------------*/
- /* jit_tls->lmf = previous_lmf */
- /*-------------------------------------------------*/
- s390_l (code, s390_r13, 0, s390_r6, 0);
- s390_st (code, s390_r0, 0, s390_r6, 0);
- return (code);
+ switch (size) {
+ case 0:
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ return (TRUE);
+ break;
+ default:
+ return (FALSE);
+ }
}
/*========================= End of Function ========================*/
{
int stackSize = cfg->stack_usage;
- if (s390_is_imm16 (cfg->stack_usage)) {
+ if (s390_is_uimm16 (cfg->stack_usage)) {
s390_ahi (code, STK_BASE, cfg->stack_usage);
} else {
while (stackSize > 32767) {
- s390_ahi (code, STK_BASE, -32767);
+ s390_ahi (code, STK_BASE, 32767);
stackSize -= 32767;
}
- s390_ahi (code, STK_BASE, -stackSize);
+ s390_ahi (code, STK_BASE, stackSize);
}
return (code);
}
if (type->byref) {
printf("[BYREF:%p], ", *((char **) curParm));
} else {
- simpleType = type->type;
+ simpleType = mono_type_get_underlying_type(type)->type;
enum_parmtype:
switch (simpleType) {
case MONO_TYPE_I :
case MONO_TYPE_OBJECT : {
MonoObject *obj = *((MonoObject **) curParm);
MonoClass *class;
- if (obj) {
+ if ((obj) && (obj->vtable)) {
printf("[CLASS/OBJ:");
class = obj->vtable->klass;
if (class == mono_defaults.string_class) {
printf("]");
break;
}
+ case MONO_TYPE_TYPEDBYREF: {
+ int i;
+ printf("[TYPEDBYREF:");
+ for (i = 0; i < size; i++)
+ printf("%02x,", *((guint8 *)curParm+i));
+ printf("]");
+ break;
+ }
default :
printf("[?? - %d], ",simpleType);
}
/* */
/*------------------------------------------------------------------*/
-static int methodCount = 0;
-
static void
enter_method (MonoMethod *method, RegParm *rParm, char *sp)
{
size_data sz;
void *curParm;
-methodCount++;
-if (methodCount > 150000) {
-methodCount = 0;
-rewind(stdout);
-}
fname = mono_method_full_name (method, TRUE);
+if (strcmp("(wrapper native-to-managed) Tests:call_int_delegate (Tests/return_int_delegate)",fname) == 0)
+printf("!!\n");
indent (1);
printf ("ENTER: %s(", fname);
g_free (fname);
ip = (*(guint32 *) (sp+S390_RET_ADDR_OFFSET)) & 0x7fffffff;
- printf (") ip: %p sp: %p\n", ip, sp);
+ printf (") ip: %p sp: %p - ", ip, sp);
if (rParm == NULL)
return;
else
curParm = sp+ainfo->offset;
- switch (ainfo->vtsize) {
- case 0:
- case 1:
- case 2:
- case 4:
- case 8:
- decodeParm(sig->params[i],
+ if (retFitsInReg (ainfo->vtsize))
+ decodeParm(sig->params[i],
curParm,
ainfo->size);
- break;
- default:
- decodeParm(sig->params[i],
+ else
+ decodeParm(sig->params[i],
*((char **) curParm),
ainfo->vtsize);
- }
break;
case RegTypeStructByAddr :
if (ainfo->reg != STK_BASE)
case MONO_TYPE_OBJECT: {
MonoObject *o = va_arg (ap, MonoObject *);
- if (o) {
+ if ((o) && (o->vtable)) {
if (o->vtable->klass == mono_defaults.boolean_class) {
printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
} else if (o->vtable->klass == mono_defaults.int32_class) {
printf ("]");
}
break;
+ case MONO_TYPE_TYPEDBYREF: {
+ guint8 *p = va_arg (ap, gpointer);
+ int j, size, align;
+ size = mono_type_size (type, &align);
+ printf ("[");
+ for (j = 0; p && j < size; j++)
+ printf ("%02x,", p [j]);
+ printf ("]");
+ }
+ break;
default:
printf ("(unknown return type %x)",
method->signature->ret->type);
{
guint32 opts = 0;
- /* no s390-specific optimizations yet */
+ /*----------------------------------------------------------*/
+ /* no s390-specific optimizations yet */
+ /*----------------------------------------------------------*/
*exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
+// *exclude_mask = MONO_OPT_INLINE;
return opts;
}
is_regsize_var (MonoType *t) {
if (t->byref)
return TRUE;
- switch (t->type) {
+ switch (mono_type_get_underlying_type (t)->type) {
case MONO_TYPE_I4:
case MONO_TYPE_U4:
case MONO_TYPE_I:
mono_arch_get_global_int_regs (MonoCompile *cfg)
{
GList *regs = NULL;
- int i, top = 12;
+ int i, top = 13;
- for (i = 3; i < top; ++i)
- regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
+ if (cfg->flags & MONO_CFG_HAS_ALLOCA)
+ cfg->frame_reg = s390_r11;
+
+ for (i = 8; i < top; ++i) {
+ if (cfg->frame_reg != i)
+ regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
+ }
return regs;
}
fr = 0;
gr = s390_r2;
+ nParm = 0;
cinfo->struct_ret = 0;
sz->retStruct = 0;
sz->stack_size = S390_MINIMAL_STACK_SIZE;
sz->code_size = 0;
sz->local_size = 0;
- nParm = 0;
/*----------------------------------------------------------*/
/* We determine the size of the return code/stack in case we*/
/* need to reserve a register to be used to address a stack */
/* area that the callee will use. */
/*----------------------------------------------------------*/
-// if (sig->ret->byref || string_ctor) {
-// sz->code_size += 8;
-// add_general (&gr, sz, cinfo->args+nParm, TRUE);
-// cinfo->args[nParm].size = sizeof(gpointer);
-// nParm++;
-// } else {
- {
- simpletype = sig->ret->type;
+ simpletype = mono_type_get_underlying_type (sig->ret)->type;
enum_retvalue:
- switch (simpletype) {
+ switch (simpletype) {
case MONO_TYPE_BOOLEAN:
case MONO_TYPE_I1:
case MONO_TYPE_U1:
cinfo->ret.reg = s390_r2;
sz->code_size += 4;
break;
- case MONO_TYPE_VALUETYPE:
+ case MONO_TYPE_VALUETYPE: {
+ MonoClass *klass = mono_class_from_mono_type (sig->ret);
if (sig->ret->data.klass->enumtype) {
simpletype = sig->ret->data.klass->enum_basetype->type;
goto enum_retvalue;
}
if (sig->pinvoke)
- size = mono_class_native_size (sig->ret->data.klass, &align);
+ size = mono_class_native_size (klass, &align);
else
- size = mono_class_value_size (sig->ret->data.klass, &align);
+ size = mono_class_value_size (klass, &align);
cinfo->ret.reg = s390_r2;
cinfo->struct_ret = 1;
cinfo->ret.size = size;
sz->stack_size += S390_ALIGN(size, align);
gr++;
break;
+ }
case MONO_TYPE_TYPEDBYREF:
+ size = sizeof (MonoTypedRef);
+ cinfo->ret.reg = s390_r2;
+ cinfo->struct_ret = 1;
+ cinfo->ret.size = size;
+ cinfo->ret.vtsize = size;
+ cinfo->ret.offset = sz->stack_size;
+ sz->stack_size += S390_ALIGN(size, align);
+ gr++;
+ break;
case MONO_TYPE_VOID:
break;
default:
g_error ("Can't handle as return value 0x%x", sig->ret->type);
- }
}
if (sig->hasthis) {
/*----------------------------------------------------------*/
for (i = 0; i < sig->param_count; ++i) {
+ /*--------------------------------------------------*/
+ /* Handle vararg type calls. All args are put on */
+ /* the stack. */
+ /*--------------------------------------------------*/
+ if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (i == sig->sentinelpos)) {
+ gr = S390_LAST_ARG_REG + 1;
+ add_general (&gr, sz, &cinfo->sigCookie, TRUE);
+ }
+
if (sig->params [i]->byref) {
add_general (&gr, sz, cinfo->args+nParm, TRUE);
cinfo->args[nParm].size = sizeof(gpointer);
nParm++;
continue;
}
- simpletype = sig->params [i]->type;
+ simpletype = mono_type_get_underlying_type(sig->params [i])->type;
enum_calc_size:
switch (simpletype) {
case MONO_TYPE_BOOLEAN:
add_general (&gr, sz, cinfo->args+nParm, TRUE);
nParm++;
break;
- case MONO_TYPE_VALUETYPE:
- if (sig->params [i]->data.klass->enumtype) {
- simpletype = sig->params [i]->data.klass->enum_basetype->type;
- goto enum_calc_size;
- }
+ case MONO_TYPE_VALUETYPE: {
+ MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
if (sig->pinvoke)
- size = mono_class_native_size (sig->params [i]->data.klass, &align);
+ size = mono_class_native_size (klass, &align);
else
- size = mono_class_value_size (sig->params [i]->data.klass, &align);
+ size = mono_class_value_size (klass, &align);
+ nWords = (size + sizeof(gpointer) - 1) /
+ sizeof(gpointer);
+
+ cinfo->args[nParm].vtsize = 0;
+ cinfo->args[nParm].size = 0;
+ cinfo->args[nParm].offparm = sz->local_size;
+
+ switch (size) {
+ /*----------------------------------*/
+ /* On S/390, structures of size 1, */
+ /* 2, 4, and 8 bytes are passed in */
+ /* (a) register(s). */
+ /*----------------------------------*/
+ case 0:
+ case 1:
+ case 2:
+ case 4:
+ add_general(&gr, sz, cinfo->args+nParm, TRUE);
+ cinfo->args[nParm].size = size;
+ cinfo->args[nParm].regtype = RegTypeStructByVal;
+ nParm++;
+ sz->local_size += sizeof(long);
+ break;
+ case 8:
+ add_general(&gr, sz, cinfo->args+nParm, FALSE);
+ cinfo->args[nParm].size = sizeof(long long);
+ cinfo->args[nParm].regtype = RegTypeStructByVal;
+ nParm++;
+ sz->local_size += sizeof(long);
+ break;
+ default:
+ add_general(&gr, sz, cinfo->args+nParm, TRUE);
+ cinfo->args[nParm].size = sizeof(int);
+ cinfo->args[nParm].regtype = RegTypeStructByAddr;
+ cinfo->args[nParm].vtsize = size;
+ sz->code_size += 40;
+ sz->local_size += size;
+ if (cinfo->args[nParm].reg == STK_BASE)
+ sz->local_size += sizeof(gpointer);
+ nParm++;
+ }
+ }
+ break;
+ case MONO_TYPE_TYPEDBYREF: {
+ int size = sizeof (MonoTypedRef);
+
nWords = (size + sizeof(gpointer) - 1) /
sizeof(gpointer);
case 2:
case 4:
add_general(&gr, sz, cinfo->args+nParm, TRUE);
-// cinfo->args[nParm].size = sizeof(int);
cinfo->args[nParm].size = size;
cinfo->args[nParm].regtype = RegTypeStructByVal;
nParm++;
sz->local_size += sizeof(gpointer);
nParm++;
}
+ }
break;
case MONO_TYPE_I8:
case MONO_TYPE_U8:
sz->code_size += 4;
fr += 2;
} else {
-// sz->stack_size = S390_ALIGN(sz->stack_size,
-// S390_STACK_ALIGNMENT);
cinfo->args[nParm].offset = sz->stack_size;
cinfo->args[nParm].reg = STK_BASE;
cinfo->args[nParm].regtype = RegTypeBase;
}
}
-
- /* align stack size */
cinfo->stack_usage = S390_ALIGN(sz->stack_size+sz->local_size,
S390_STACK_ALIGNMENT);
return (cinfo);
/*------------------------------------------------------------------*/
void
-mono_arch_allocate_vars (MonoCompile *m)
+mono_arch_allocate_vars (MonoCompile *cfg)
{
MonoMethodSignature *sig;
MonoMethodHeader *header;
int frame_reg = STK_BASE;
int sArg, eArg;
- header = ((MonoMethodNormal *)m->method)->header;
-
- /*
- * We use the frame register also for any method that has
- * filter clauses. This way, when the handlers are called,
- * the code will reference local variables using the frame reg instead of
- * the stack pointer: if we had to restore the stack pointer, we'd
- * corrupt the method frames that are already on the stack (since
- * filters get called before stack unwinding happens) when the filter
- * code would call any method.
- */
- if ((m->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
-// if (m->flags & MONO_CFG_HAS_ALLOCA)
+ header = mono_method_get_header (cfg->method);
+
+ /*---------------------------------------------------------*/
+ /* We use the frame register also for any method that has */
+ /* filter clauses. This way, when the handlers are called, */
+ /* the code will reference local variables using the frame */
+ /* reg instead of the stack pointer: if we had to restore */
+ /* the stack pointer, we'd corrupt the method frames that */
+ /* are already on the stack (since filters get called */
+ /* before stack unwinding happens) when the filter code */
+ /* would call any method. */
+ /*---------------------------------------------------------*/
+ if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
frame_reg = s390_r11;
- m->frame_reg = frame_reg;
+ cfg->frame_reg = frame_reg;
if (frame_reg != STK_BASE)
- m->used_int_regs |= 1 << frame_reg;
+ cfg->used_int_regs |= 1 << frame_reg;
- sig = m->method->signature;
+ sig = cfg->method->signature;
cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
if (cinfo->struct_ret) {
- m->ret->opcode = OP_REGVAR;
- m->ret->inst_c0 = s390_r2;
+ cfg->ret->opcode = OP_REGVAR;
+ cfg->ret->inst_c0 = s390_r2;
} else {
- /* FIXME: handle long and FP values */
- switch (sig->ret->type) {
+ switch (mono_type_get_underlying_type (sig->ret)->type) {
case MONO_TYPE_VOID:
break;
default:
- m->ret->opcode = OP_REGVAR;
- m->ret->dreg = s390_r2;
+ cfg->ret->opcode = OP_REGVAR;
+ cfg->ret->dreg = s390_r2;
break;
}
}
/*--------------------------------------------------------------*/
/* local vars are at a positive offset from the stack pointer */
- /* */
/* also note that if the function uses alloca, we use s390_r11 */
/* to point at the local variables. */
/* add parameter area size for called functions */
/*--------------------------------------------------------------*/
- offset = (m->param_area + S390_MINIMAL_STACK_SIZE);
+ offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
+ cfg->sig_cookie = 0;
if (cinfo->struct_ret) {
- inst = m->ret;
+ inst = cfg->ret;
offset = S390_ALIGN(offset, sizeof(gpointer));
inst->inst_offset = offset;
inst->opcode = OP_REGOFFSET;
inst->inst_basereg = frame_reg;
offset += sizeof(gpointer);
+ if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (!retFitsInReg (cinfo->ret.size)))
+ cfg->sig_cookie += cinfo->ret.size;
}
if (sig->hasthis) {
- inst = m->varinfo [0];
+ inst = cfg->varinfo [0];
if (inst->opcode != OP_REGVAR) {
inst->opcode = OP_REGOFFSET;
inst->inst_basereg = frame_reg;
eArg = sig->param_count + sArg;
+ if (sig->call_convention == MONO_CALL_VARARG)
+ cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
+
for (iParm = sArg; iParm < eArg; ++iParm) {
- inst = m->varinfo [curinst];
+ inst = cfg->varinfo [curinst];
if (inst->opcode != OP_REGVAR) {
switch (cinfo->args[iParm].regtype) {
case RegTypeStructByAddr :
inst->opcode = OP_S390_LOADARG;
inst->inst_basereg = frame_reg;
-// size = sizeof(long);
size = abs(cinfo->args[iParm].vtsize);
offset = S390_ALIGN(offset, size);
inst->inst_offset = offset;
: 0);
inst->inst_offset = cinfo->args[iParm].offset +
size;
-// inst->unused = stackOffset;
inst->unused = 0;
size = sizeof(long);
}
}
+ if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (cinfo->args[iParm].regtype != RegTypeGeneral) &&
+ (iParm < sig->sentinelpos))
+ cfg->sig_cookie += size;
+
offset += size;
}
curinst++;
}
- curinst = m->locals_start;
- for (iVar = curinst; iVar < m->num_varinfo; ++iVar) {
- inst = m->varinfo [iVar];
- if (inst->opcode == OP_REGVAR)
+ curinst = cfg->locals_start;
+ for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
+ inst = cfg->varinfo [iVar];
+ if ((inst->flags & MONO_INST_IS_DEAD) ||
+ (inst->opcode == OP_REGVAR))
continue;
- /* inst->unused indicates native sized value types, this is used by the
- * pinvoke wrappers when they call functions returning structure */
+ /*--------------------------------------------------*/
+ /* inst->unused indicates native sized value types, */
+ /* this is used by the pinvoke wrappers when they */
+ /* call functions returning structure */
+ /*--------------------------------------------------*/
if (inst->unused && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
- size = mono_class_native_size (inst->inst_vtype->data.klass, &align);
+ size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype), &align);
else
size = mono_type_size (inst->inst_vtype, &align);
inst->opcode = OP_REGOFFSET;
inst->inst_basereg = frame_reg;
offset += size;
- //DEBUG (g_print("allocating local %d to %d\n", iVar, inst->inst_offset));
+ DEBUG (g_print("allocating local %d to %d\n", iVar, inst->inst_offset));
}
-// if (sig->hasthis)
-// curinst = sArg = 1;
-// else
-// curinst = sArg = 0;
-//
-
/*------------------------------------------------------*/
/* Allow space for the trace method stack area if needed*/
/*------------------------------------------------------*/
- if (mono_jit_trace_calls != NULL && mono_trace_eval (m))
+ if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg))
offset += S390_TRACE_STACK_SIZE;
/*------------------------------------------------------*/
/* Reserve space to save LMF and caller saved registers */
/*------------------------------------------------------*/
- if (m->method->save_lmf)
+ if (cfg->method->save_lmf)
offset += sizeof (MonoLMF);
/*------------------------------------------------------*/
/* align the offset */
/*------------------------------------------------------*/
- m->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
+ cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
}
/*------------------------------------------------------------------*/
MonoCallInst*
-mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, MonoCallInst *call, int is_virtual) {
+mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
+ MonoCallInst *call, int is_virtual) {
MonoInst *arg, *in;
MonoMethodSignature *sig;
int i, n, lParamArea;
cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
call->stack_usage = cinfo->stack_usage;
- lParamArea = cinfo->stack_usage - S390_MINIMAL_STACK_SIZE;
- cfg->param_area = MAX (cfg->param_area, lParamArea);
+ lParamArea = MAX((cinfo->stack_usage - S390_MINIMAL_STACK_SIZE), 0);
+ cfg->param_area = MAX (((signed) cfg->param_area), lParamArea);
cfg->flags |= MONO_CFG_HAS_CALLS;
- /*----------------------------------------------------------*/
- /* should set more info in call, such as the stack space */
- /* used by the args that needs to be added back to esp */
- /*----------------------------------------------------------*/
if (cinfo->struct_ret)
- call->used_iregs |= 1 << cinfo->struct_ret;
+ call->used_iregs |= 1 << cinfo->ret.reg;
for (i = 0; i < n; ++i) {
ainfo = cinfo->args + i;
- DEBUG (g_print ("Parameter %d - Register: %d Type: %d\n",
- i+1,ainfo->reg,ainfo->regtype));
+
+ if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (i == sig->sentinelpos)) {
+ MonoInst *sigArg;
+
+ cfg->disable_aot = TRUE;
+ MONO_INST_NEW (cfg, sigArg, OP_ICONST);
+ sigArg->inst_p0 = call->signature;
+
+ MONO_INST_NEW (cfg, arg, OP_OUTARG);
+ arg->inst_imm = cinfo->sigCookie.offset;
+ arg->inst_left = sigArg;
+
+ arg->next = call->out_args;
+ call->out_args = arg;
+ }
+
if (is_virtual && i == 0) {
/* the argument will be attached to the call instrucion */
in = call->args [i];
arg->inst_imm = ainfo->offset;
call->used_fregs |= 1 << ainfo->reg;
} else if (ainfo->regtype == RegTypeFP) {
-// arg->opcode = OP_OUTARG_R8;
-// arg->unused = ainfo->reg;
-// call->used_fregs |= 1 << ainfo->reg;
-// if (ainfo->size == 4) {
-// /* we reduce the precision */
-// MonoInst *conv;
-// MONO_INST_NEW (cfg, conv, OP_FCONV_TO_R4);
-// conv->inst_left = arg->inst_left;
-// arg->inst_left = conv;
-// }
arg->unused = ainfo->reg;
call->used_fregs |= 1 << ainfo->reg;
if (ainfo->size == 4) {
int save_mode = SAVE_NONE,
saveOffset;
MonoMethod *method = cfg->method;
- int rtype = method->signature->ret->type;
+ int rtype = mono_type_get_underlying_type (method->signature->ret)->type;
saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
if (method->save_lmf)
while (ins) {
spec = ins_spec [ins->opcode];
DEBUG (print_ins (i, ins));
- if (spec [MONO_INST_CLOB] == 'c') {
- MonoCallInst * call = (MonoCallInst*)ins;
- int j;
- }
+// if (spec [MONO_INST_CLOB] == 'c') {
+// MonoCallInst * call = (MonoCallInst*)ins;
+// int j;
+// }
if (spec [MONO_INST_SRC1]) {
if (spec [MONO_INST_SRC1] == 'f')
reginfo1 = reginfof;
if (reginfod [ins->dreg].born_in == 0 || reginfod [ins->dreg].born_in > i)
reginfod [ins->dreg].born_in = i;
if (spec [MONO_INST_DEST] == 'l') {
- /* result in eax:edx, the virtual register is allocated sequentially */
+ /* result in R2/R3, the virtual register is allocated sequentially */
reginfod [ins->dreg + 1].prev_use = reginfod [ins->dreg + 1].last_use;
reginfod [ins->dreg + 1].last_use = i;
if (reginfod [ins->dreg + 1].born_in == 0 || reginfod [ins->dreg + 1].born_in > i)
create_copy_ins (cfg, ins->dreg, s390_r3, ins);
}
}
- if (reg_is_freeable (val) && hreg >= 0 && (reginfo [hreg].born_in >= i && !(cur_iregs & (1 << val)))) {
+ if (reg_is_freeable (val) &&
+ hreg >= 0 &&
+ (reginfo [hreg].born_in >= i &&
+ !(cur_iregs & (1 << val)))) {
DEBUG (g_print ("\tfreeable %s (R%d)\n", mono_arch_regname (val), hreg));
mono_regstate_free_int (rs, val);
}
/* the register gets spilled after this inst */
spill = -val -1;
}
- //g_assert (val == -1); /* source cannot be spilled */
val = mono_regstate_alloc_float (rs, src1_mask);
if (val < 0)
val = get_float_register_spilling (cfg, tmp, ins, src1_mask, ins->sreg1);
}
}
}
- /*if (reg_is_freeable (ins->sreg1) && prev_sreg1 >= 0 && reginfo [prev_sreg1].born_in >= i) {
- DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg1)));
- mono_regstate_free_int (rs, ins->sreg1);
- }
- if (reg_is_freeable (ins->sreg2) && prev_sreg2 >= 0 && reginfo [prev_sreg2].born_in >= i) {
- DEBUG (g_print ("freeable %s\n", mono_arch_regname (ins->sreg2)));
- mono_regstate_free_int (rs, ins->sreg2);
- }*/
-
- //DEBUG (print_ins (i, ins));
tmp = tmp->next;
}
}
} else {
s390_basr (code, s390_r13, 0);
s390_j (code, 10);
- s390_double (code, 0x41e0000000000000);
- s390_double (code, 0x41f0000000000000);
+ s390_llong (code, 0x41e0000000000000);
+ s390_llong (code, 0x41f0000000000000);
s390_ldr (code, s390_f15, sreg);
s390_cdb (code, s390_f15, 0, s390_r13, 0);
s390_jl (code, 10);
code = cfg->native_code + offset;
}
+ mono_debug_record_line_number (cfg, ins, offset);
+
switch (ins->opcode) {
case OP_STOREI1_MEMBASE_IMM: {
- s390_lhi (code, s390_r14, ins->inst_imm);
+ s390_lhi (code, s390_r0, ins->inst_imm);
if (s390_is_uimm12(ins->inst_offset))
- s390_stc (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
+ s390_stc (code, s390_r0, 0, ins->inst_destbasereg, ins->inst_offset);
else {
s390_basr (code, s390_r13, 0);
s390_j (code, 4);
s390_word (code, ins->inst_offset);
s390_l (code, s390_r13, 0, s390_r13, 4);
- s390_stc (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
+ s390_stc (code, s390_r0, s390_r13, ins->inst_destbasereg, 0);
}
}
break;
case OP_STOREI2_MEMBASE_IMM: {
- s390_lhi (code, s390_r14, ins->inst_imm);
+ s390_lhi (code, s390_r0, ins->inst_imm);
if (s390_is_uimm12(ins->inst_offset)) {
- s390_sth (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
+ s390_sth (code, s390_r0, 0, ins->inst_destbasereg, ins->inst_offset);
} else {
- s390_basr (code, s390_r14, 0);
+ s390_basr (code, s390_r13, 0);
s390_j (code, 4);
s390_word (code, ins->inst_offset);
s390_l (code, s390_r13, 0, s390_r13, 4);
- s390_sth (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
+ s390_sth (code, s390_r0, s390_r13, ins->inst_destbasereg, 0);
}
}
break;
case OP_STORE_MEMBASE_IMM:
case OP_STOREI4_MEMBASE_IMM: {
- if (s390_is_imm16(ins->inst_imm)) {
- s390_lhi (code, s390_r14, ins->inst_imm);
+ if (s390_is_uimm16(ins->inst_imm)) {
+ s390_lhi (code, s390_r0, ins->inst_imm);
} else {
s390_basr (code, s390_r13, 0);
s390_j (code, 4);
s390_word (code, ins->inst_imm);
- s390_l (code, s390_r14, 0, s390_r13, 4);
+ s390_l (code, s390_r0, 0, s390_r13, 4);
}
if (s390_is_uimm12(ins->inst_offset)) {
- s390_st (code, s390_r14, 0, ins->inst_destbasereg, ins->inst_offset);
+ s390_st (code, s390_r0, 0, ins->inst_destbasereg, ins->inst_offset);
} else {
s390_basr (code, s390_r13, 0);
s390_j (code, 4);
s390_word (code, ins->inst_offset);
s390_l (code, s390_r13, 0, s390_r13, 4);
- s390_st (code, s390_r14, s390_r13, ins->inst_destbasereg, 0);
+ s390_st (code, s390_r0, s390_r13, ins->inst_destbasereg, 0);
}
}
break;
if (s390_is_uimm12(ins->inst_offset))
s390_l (code, ins->dreg, 0, ins->inst_basereg, ins->inst_offset);
else {
- if (s390_is_imm16(ins->inst_offset)) {
+ if (s390_is_uimm16(ins->inst_offset)) {
s390_lhi (code, s390_r13, ins->inst_offset);
s390_l (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
} else {
}
break;
case OP_COMPARE_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r0, ins->inst_imm);
if ((ins->next) &&
((ins->next->opcode >= CEE_BNE_UN) &&
s390_alcr (code, ins->dreg, ins->sreg2);
}
break;
+ case OP_ADDCC_IMM:
case OP_ADD_IMM: {
if ((ins->next) &&
(ins->next->opcode == OP_ADC_IMM)) {
}
s390_al (code, ins->dreg, 0, s390_r13, 4);
} else {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
}
break;
case OP_ADC_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
s390_slbr (code, ins->dreg, ins->sreg2);
}
break;
+ case OP_SUBCC_IMM: {
+ if (s390_is_uimm16 (-ins->inst_imm)) {
+ if (ins->dreg != ins->sreg1) {
+ s390_lr (code, ins->dreg, ins->sreg1);
+ }
+ s390_ahi (code, ins->dreg, -ins->inst_imm);
+ } else {
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 4);
+ s390_word (code, ins->inst_imm);
+ if (ins->dreg != ins->sreg1) {
+ s390_lr (code, ins->dreg, ins->sreg1);
+ }
+ s390_sl (code, ins->dreg, 0, s390_r13, 4);
+ }
+ }
+ break;
case OP_SUB_IMM: {
- if (s390_is_imm16 (-ins->inst_imm)) {
+ if (s390_is_uimm16 (-ins->inst_imm)) {
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
}
break;
case OP_SBB_IMM: {
- s390_basr (code, s390_r13, 0);
- s390_j (code, 4);
- s390_word (code, ins->inst_imm);
- s390_sl (code, ins->dreg, 0, s390_r13, 4);
+ if (ins->dreg != ins->sreg1) {
+ s390_lr (code, ins->dreg, ins->sreg1);
+ }
+ if (s390_is_uimm16 (-ins->inst_imm)) {
+ s390_lhi (code, s390_r0, ins->inst_imm);
+ s390_slbr (code, ins->dreg, s390_r0);
+ } else {
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 4);
+ s390_word (code, ins->inst_imm);
+ s390_slb (code, ins->dreg, 0, s390_r13, 4);
+ }
}
break;
case CEE_SUB_OVF: {
}
break;
case OP_AND_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r0, ins->inst_imm);
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
break;
case OP_DIV_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r13, ins->inst_imm);
s390_lr (code, s390_r0, ins->sreg1);
} else {
s390_l (code, s390_r13, 0, s390_r13, 4);
}
s390_srda (code, s390_r0, 0, 32);
- s390_dr (code, s390_r0, ins->sreg2);
+ s390_dr (code, s390_r0, s390_r13);
s390_lr (code, ins->dreg, s390_r1);
}
break;
}
break;
case OP_REM_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r13, ins->inst_imm);
s390_lr (code, s390_r0, ins->sreg1);
} else {
s390_l (code, s390_r13, 0, s390_r13, 4);
}
s390_srda (code, s390_r0, 0, 32);
- s390_dr (code, s390_r0, ins->sreg2);
+ s390_dr (code, s390_r0, s390_r13);
s390_lr (code, ins->dreg, s390_r0);
}
break;
}
break;
case OP_OR_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r0, ins->inst_imm);
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
s390_or (code, ins->dreg, s390_r0);
} else {
- s390_bras (code, s390_r13, 4);
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 4);
s390_word (code, ins->inst_imm);
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
- s390_o (code, ins->dreg, 0, s390_r13, 0);
+ s390_o (code, ins->dreg, 0, s390_r13, 4);
}
}
break;
}
break;
case OP_XOR_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r0, ins->inst_imm);
if (ins->dreg != ins->sreg1) {
s390_lr (code, ins->dreg, ins->sreg1);
}
break;
case OP_MUL_IMM: {
- if (s390_is_imm16 (ins->inst_imm)) {
+ if (s390_is_uimm16 (ins->inst_imm)) {
s390_lhi (code, s390_r13, ins->inst_imm);
} else {
s390_basr (code, s390_r13, 0);
break;
case OP_LMUL: {
s390_l (code, s390_r0, 0, ins->sreg1, 4);
- s390_lr (code, s390_r14, s390_r0);
s390_srda (code, s390_r0, 0, 32);
s390_m (code, s390_r0, 0, ins->sreg2, 4);
- s390_srl (code, s390_r14, 0, 31);
- s390_a (code, s390_r14, 0, ins->sreg1, 0);
+ s390_l (code, s390_r0, 0, ins->sreg1, 4);
+ s390_srl (code, s390_r0, 0, 31);
+ s390_a (code, s390_r0, 0, ins->sreg1, 0);
s390_l (code, s390_r13, 0, ins->sreg2, 0);
s390_srl (code, s390_r13, 0, 31);
s390_ms (code, s390_r13, 0, ins->sreg1, 4);
- s390_ar (code, s390_r14, s390_r13);
- s390_st (code, s390_r14, 0, ins->dreg, 0);
+ s390_ar (code, s390_r0, s390_r13);
+ s390_st (code, s390_r0, 0, ins->dreg, 0);
s390_st (code, s390_r1, 0, ins->dreg, 4);
}
break;
case OP_ICONST:
case OP_SETREGIMM: {
- if (s390_is_imm16(ins->inst_c0)) {
+ if (s390_is_uimm16(ins->inst_c0)) {
s390_lhi (code, ins->dreg, ins->inst_c0);
} else {
s390_basr (code, s390_r13, 0);
s390_ledbr (code, ins->dreg, ins->sreg1);
}
break;
+ case OP_TLS_GET: {
+ if (s390_is_uimm16 (ins->inst_offset)) {
+ s390_lhi (code, s390_r13, ins->inst_offset);
+ } else {
+ s390_bras (code, s390_r13, 0);
+ s390_j (code, 4);
+ s390_word (code, ins->inst_offset);
+ s390_l (code, s390_r13, 0, s390_r13, 4);
+ }
+ s390_ear (code, s390_r1, 0);
+ s390_l (code, ins->dreg, s390_r13, s390_r1, 0);
+ }
+ break;
case OP_FCONV_TO_R4: {
if ((ins->next) &&
(ins->next->opcode != OP_STORER4_MEMBASE_REG))
}
break;
case CEE_JMP: {
+ int iParm, fParm, pOffset;
if (cfg->method->save_lmf)
- code = restoreLMF(cfg, code);
+ restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
+
+ if (cfg->flags & MONO_CFG_HAS_TAIL) {
+ pOffset = S390_PARM_SAVE_OFFSET;
+ s390_l (code, s390_r13, 0, STK_BASE, 0);
+ for (iParm = s390_r2;
+ iParm <= s390_r5;
+ iParm++, pOffset+sizeof(gint32)) {
+ if (cfg->used_int_regs & (1 << iParm))
+ s390_l (code, iParm, 0, s390_r13, pOffset);
+ }
+ pOffset = S390_FLOAT_SAVE_OFFSET;
+ for (fParm = 0;
+ fParm < 4;
+ fParm++, pOffset+sizeof(double))
+ s390_ld (code, fParm, 0, s390_r13, pOffset);
+ }
code = backUpStackPtr(cfg, code);
s390_l (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
s390_icm (code, s390_r0, 15, ins->sreg1, 0);
}
break;
+ case OP_ARGLIST: {
+ int offset = cfg->sig_cookie + cfg->stack_usage;
+
+ if (s390_is_uimm16 (offset))
+ s390_lhi (code, s390_r0, offset);
+ else {
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 4);
+ s390_word (code, offset);
+ s390_l (code, s390_r0, 0, s390_r13, 0);
+ }
+ s390_ar (code, s390_r0, cfg->frame_reg);
+ s390_st (code, s390_r0, 0, ins->sreg1, 0);
+ }
+ break;
case OP_FCALL: {
call = (MonoCallInst*)ins;
if (ins->flags & MONO_INST_HAS_METHOD)
S390_STACK_ALIGNMENT - 1;
int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
s390_lr (code, s390_r1, ins->sreg1);
+ if (ins->flags & MONO_INST_INIT)
+ s390_lr (code, s390_r0, ins->sreg1);
s390_ahi (code, s390_r1, 14);
s390_srl (code, s390_r1, 0, 3);
s390_sll (code, s390_r1, 0, 3);
s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
s390_srl (code, ins->dreg, 0, 3);
s390_sll (code, ins->dreg, 0, 3);
+ if (ins->flags & MONO_INST_INIT) {
+ s390_lr (code, s390_r1, s390_r0);
+ s390_lr (code, s390_r0, ins->dreg);
+ s390_lr (code, s390_r14, s390_r12);
+ s390_lhi (code, s390_r13, 0);
+ s390_mvcle(code, s390_r0, s390_r12, 0, 0);
+ s390_jo (code, -2);
+ s390_lr (code, s390_r12, s390_r14);
+ }
}
break;
case CEE_RET: {
s390_brasl (code, s390_r14, 0);
}
break;
+ case OP_RETHROW: {
+ s390_lr (code, s390_r2, ins->sreg1);
+ mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
+ (gpointer)"mono_arch_rethrow_exception");
+ s390_brasl (code, s390_r14, 0);
+ }
+ break;
case OP_START_HANDLER: {
if (s390_is_uimm12 (ins->inst_left->inst_offset)) {
s390_st (code, s390_r14, 0,
s390_l (code, s390_r14, s390_r13,
ins->inst_left->inst_basereg, 0);
}
-// s390_l (code, STK_BASE, 0, STK_BASE, 0);
-// s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
s390_br (code, s390_r14);
}
break;
s390_l (code, s390_r14, s390_r13,
ins->inst_left->inst_basereg, 0);
}
-// s390_l (code, s390_r14, 0, ins->inst_left->inst_basereg, ins->inst_left->inst_offset);
s390_br (code, s390_r14);
}
break;
s390_word (code, ins->inst_p0);
s390_l (code, s390_r13, 0, s390_r13, 4);
s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
-// s390_ldebr(code, ins->dreg, ins->dreg);
}
}
break;
s390_l (code, s390_r13, 0, s390_r13, 4);
s390_ldeb (code, ins->dreg, s390_r13, ins->inst_basereg, 0);
}
-// s390_ldebr (code, ins->dreg, ins->dreg);
}
break;
case CEE_CONV_R_UN: {
case OP_LCONV_TO_OVF_I: {
/* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
short int *o[5];
- s390_ltr (code, ins->sreg2, ins->sreg2);
- s390_jnl (code, 0); CODEPTR(code, o[0]);
s390_ltr (code, ins->sreg1, ins->sreg1);
+ s390_jnl (code, 0); CODEPTR(code, o[0]);
+ s390_ltr (code, ins->sreg2, ins->sreg2);
s390_jnl (code, 0); CODEPTR(code, o[1]);
s390_lhi (code, s390_r13, -1);
- s390_cr (code, ins->sreg1, s390_r13);
+ s390_cr (code, ins->sreg2, s390_r13);
s390_jnz (code, 0); CODEPTR(code, o[2]);
- if (ins->dreg != ins->sreg2)
- s390_lr (code, ins->dreg, ins->sreg2);
+ if (ins->dreg != ins->sreg1)
+ s390_lr (code, ins->dreg, ins->sreg1);
s390_j (code, 0); CODEPTR(code, o[3]);
PTRSLOT(code, o[0]);
+ s390_ltr (code, ins->sreg2, ins->sreg2);
s390_jz (code, 0); CODEPTR(code, o[4]);
PTRSLOT(code, o[1]);
PTRSLOT(code, o[2]);
ins->inst_offset, ins->sreg1, ins->inst_imm);
} else {
s390_lr (code, s390_r0, ins->dreg);
- if (s390_is_imm16 (ins->inst_offset)) {
+ if (s390_is_uimm16 (ins->inst_offset)) {
s390_ahi (code, s390_r0, ins->inst_offset);
} else {
s390_basr (code, s390_r13, 0);
s390_word (code, ins->inst_offset);
s390_a (code, s390_r0, 0, s390_r13, 4);
}
- s390_lr (code, s390_r1, ins->sreg2);
- if (s390_is_imm16 (ins->inst_imm)) {
- s390_ahi (code, s390_r1, ins->inst_imm);
+ s390_lr (code, s390_r14, s390_r12);
+ s390_lr (code, s390_r12, ins->sreg1);
+ if (s390_is_uimm16 (ins->inst_imm)) {
+ s390_ahi (code, s390_r12, ins->inst_imm);
} else {
s390_basr (code, s390_r13, 0);
s390_j (code, 4);
s390_word (code, ins->inst_imm);
- s390_a (code, s390_r1, 0, s390_r13, 4);
+ s390_a (code, s390_r12, 0, s390_r13, 4);
}
- s390_lr (code, s390_r12, ins->sreg1);
+ s390_lr (code, s390_r1, ins->sreg1);
s390_lr (code, s390_r13, s390_r1);
s390_mvcle(code, s390_r0, s390_r12, 0, 0);
s390_jo (code, -2);
+ s390_lr (code, s390_r12, s390_r14);
}
}
}
break;
+ case OP_ATOMIC_ADD_I4: {
+ s390_lr (code, s390_r1, ins->sreg2);
+ s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
+ s390_a (code, s390_r1, 0, ins->inst_basereg, ins->inst_offset);
+ s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
+ s390_jnz (code, -7);
+ s390_lr (code, ins->dreg, s390_r1);
+ }
+ break;
+ case OP_ATOMIC_ADD_NEW_I4: {
+ s390_lr (code, s390_r1, ins->sreg2);
+ s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
+ s390_a (code, s390_r1, 0, ins->inst_basereg, ins->inst_offset);
+ s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
+ s390_jnz (code, -7);
+ s390_lr (code, ins->dreg, s390_r1);
+ }
+ break;
+ case OP_ATOMIC_EXCHANGE_I4: {
+ s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
+ s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
+ s390_jnz (code, -4);
+ s390_lr (code, ins->dreg, s390_r0);
+ }
+ break;
default:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
/*------------------------------------------------------------------*/
void
-mono_arch_patch_code (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
+mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
+ guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
{
MonoJumpInfo *patch_info;
for (patch_info = ji; patch_info; patch_info = patch_info->next) {
unsigned char *ip = patch_info->ip.i + code;
- gint32 target = 0;
+ gconstpointer target = NULL;
+
+ target = mono_resolve_patch_target (method, domain, code,
+ patch_info, run_cctors);
switch (patch_info->type) {
- case MONO_PATCH_INFO_BB:
- target = S390_RELATIVE((patch_info->data.bb->native_offset+code),
- ip);
- ip += 2; /* Skip over op-code */
- break;
- case MONO_PATCH_INFO_ABS:
- target = S390_RELATIVE(patch_info->data.target, ip);
- ip += 2; /* Skip over op-code */
- break;
- case MONO_PATCH_INFO_LABEL:
- target = S390_RELATIVE((patch_info->data.inst->inst_c0+code),ip);
- ip += 2; /* Skip over op-code */
- break;
- case MONO_PATCH_INFO_IP:
- target = ip;
- continue;
- case MONO_PATCH_INFO_METHOD_REL:
- g_assert_not_reached ();
- *((gpointer *)(ip)) = code + patch_info->data.offset;
- continue;
- case MONO_PATCH_INFO_INTERNAL_METHOD: {
- MonoJitICallInfo *mi = mono_find_jit_icall_by_name (patch_info->data.name);
- if (!mi) {
- g_warning ("unknown MONO_PATCH_INFO_INTERNAL_METHOD %s", patch_info->data.name);
+ case MONO_PATCH_INFO_IP:
+ case MONO_PATCH_INFO_EXC_NAME:
+ case MONO_PATCH_INFO_LDSTR:
+ case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
+ case MONO_PATCH_INFO_LDTOKEN:
+ case MONO_PATCH_INFO_EXC:
+ continue;
+ case MONO_PATCH_INFO_SWITCH:
+ /*----------------------------------*/
+ /* ip points at the basr r13,0/j +4 */
+ /* instruction the vtable value */
+ /* follows this (i.e. ip+6) */
+ /*----------------------------------*/
+ *((gconstpointer *)(ip+6)) = target;
+ target = NULL;
+ continue;
+ case MONO_PATCH_INFO_METHODCONST:
+ case MONO_PATCH_INFO_CLASS:
+ case MONO_PATCH_INFO_IMAGE:
+ case MONO_PATCH_INFO_FIELD:
+ case MONO_PATCH_INFO_IID:
+ target = S390_RELATIVE(target, ip);
+ continue;
+ case MONO_PATCH_INFO_R4:
+ case MONO_PATCH_INFO_R8:
+ case MONO_PATCH_INFO_METHOD_REL:
g_assert_not_reached ();
- }
- target = S390_RELATIVE(mono_icall_get_wrapper (mi), ip);
- ip += 2; /* Skip over op-code */
- break;
- }
- case MONO_PATCH_INFO_METHOD_JUMP: {
- GSList *list;
-
- /*------------------------------------------------------*/
- /* get the trampoline to the method from the domain */
- /*------------------------------------------------------*/
- target = mono_create_jump_trampoline (domain,
- patch_info->data.method,
- TRUE);
- target = S390_RELATIVE(target, ip);
- if (!domain->jump_target_hash)
- domain->jump_target_hash = g_hash_table_new (NULL, NULL);
- list = g_hash_table_lookup (domain->jump_target_hash,
- patch_info->data.method);
- list = g_slist_prepend (list, ip);
- g_hash_table_insert (domain->jump_target_hash,
- patch_info->data.method, list);
- ip +=2;
- break;
- }
- case MONO_PATCH_INFO_METHOD:
- if (patch_info->data.method == method) {
- target = S390_RELATIVE(code, ip);
- } else {
- /* get the trampoline to the method from the domain */
- target = S390_RELATIVE(mono_arch_create_jit_trampoline (patch_info->data.method), ip);
- target = mono_arch_create_jit_trampoline(patch_info->data.method);
+ continue;
+ default:
target = S390_RELATIVE(target, ip);
- }
- ip += 2; /* Skip over op-code */
- break;
- case MONO_PATCH_INFO_SWITCH: {
- gpointer *table = (gpointer *)patch_info->data.target;
- int i;
- /*------------------------------------------------------*/
- /* ip is pointing at the basr r13,0/j +4 instruction */
- /* the vtable value follows this (i.e. ip+6) */
- /*------------------------------------------------------*/
- *((gconstpointer *)(ip+6)) = table;
-
- for (i = 0; i < patch_info->table_size; i++) {
- table [i] = (int)patch_info->data.table [i] + code;
- }
- continue;
- }
- case MONO_PATCH_INFO_METHODCONST:
- case MONO_PATCH_INFO_CLASS:
- case MONO_PATCH_INFO_IMAGE:
- case MONO_PATCH_INFO_FIELD:
- target = S390_RELATIVE(patch_info->data.target, ip);
- continue;
- case MONO_PATCH_INFO_R4:
- case MONO_PATCH_INFO_R8:
- g_assert_not_reached ();
- *((gconstpointer *)(ip + 2)) = patch_info->data.target;
- continue;
- case MONO_PATCH_INFO_IID:
- mono_class_init (patch_info->data.klass);
- target = S390_RELATIVE(patch_info->data.klass->interface_id, ip);
- continue;
- case MONO_PATCH_INFO_VTABLE:
- target = S390_RELATIVE(mono_class_vtable (domain, patch_info->data.klass),ip);
- ip += 2;
- continue;
- case MONO_PATCH_INFO_CLASS_INIT:
- target = S390_RELATIVE(mono_create_class_init_trampoline (mono_class_vtable (domain, patch_info->data.klass)), ip);
- ip += 2;
- break;
- case MONO_PATCH_INFO_SFLDA: {
- MonoVTable *vtable = mono_class_vtable (domain, patch_info->data.field->parent);
- if (!vtable->initialized && !(vtable->klass->flags & TYPE_ATTRIBUTE_BEFORE_FIELD_INIT) && mono_class_needs_cctor_run (vtable->klass, method))
- /* Done by the generated code */
- ;
- else {
- if (run_cctors)
- mono_runtime_class_init (vtable);
- }
- target = S390_RELATIVE((char*)vtable->data + patch_info->data.field->offset, ip);
- ip += 2;
- continue;
- }
- case MONO_PATCH_INFO_EXC_NAME:
- *((gconstpointer *)(ip)) = patch_info->data.name;
- continue;
- case MONO_PATCH_INFO_LDSTR:
- target = mono_ldstr (domain, patch_info->data.token->image,
- mono_metadata_token_index (patch_info->data.token->token));
- continue;
- case MONO_PATCH_INFO_TYPE_FROM_HANDLE: {
- gpointer handle;
- MonoClass *handle_class;
-
- handle = mono_ldtoken (patch_info->data.token->image,
- patch_info->data.token->token,
- &handle_class, NULL);
- mono_class_init (handle_class);
- mono_class_init (mono_class_from_mono_type (handle));
-
- target = handle;
- continue;
- }
- case MONO_PATCH_INFO_LDTOKEN: {
- gpointer handle;
- MonoClass *handle_class;
-
- handle = mono_ldtoken (patch_info->data.token->image,
- patch_info->data.token->token,
- &handle_class, NULL);
- mono_class_init (handle_class);
-
- target = handle;
- continue;
- }
- case MONO_PATCH_INFO_EXC:
- /* everything is dealt with at epilog output time */
- continue;
- default:
- g_assert_not_reached ();
+ ip += 2;
}
s390_patch (ip, target);
}
/*========================= End of Function ========================*/
-/*------------------------------------------------------------------*/
-/* */
-/* Name - mono_arch_max_epilog_size */
-/* */
-/* Function - Determine the maximum size of the epilog code. */
-/* */
-/*------------------------------------------------------------------*/
-
-int
-mono_arch_max_epilog_size (MonoCompile *cfg)
-{
- int max_epilog_size = 96;
- MonoJumpInfo *patch_info;
-
- if (cfg->method->save_lmf)
- max_epilog_size += 128;
-
- if (mono_jit_trace_calls != NULL)
- max_epilog_size += 128;
-
- if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
- max_epilog_size += 128;
-
- /* count the number of exception infos */
-
- for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
- if (patch_info->type == MONO_PATCH_INFO_EXC)
- max_epilog_size += 26;
- }
-
- return max_epilog_size;
-}
-
-/*========================= End of Function ========================*/
-
/*------------------------------------------------------------------*/
/* */
/* Name - mono_arch_emit_prolog */
MonoBasicBlock *bb;
MonoMethodSignature *sig;
MonoInst *inst;
- int alloc_size, pos, max_offset, i, lmfOffset;
+ int alloc_size, pos, max_offset, i;
guint8 *code;
CallInfo *cinfo;
size_data sz;
int tracing = 0;
+ int lmfOffset; \
if (mono_jit_trace_calls != NULL && mono_trace_eval (method))
tracing = 1;
- cfg->code_size = 256;
+ cfg->code_size = 512;
cfg->native_code = code = g_malloc (cfg->code_size);
- s390_stm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
+ if (cfg->flags & MONO_CFG_HAS_TAIL) {
+ s390_stm (code, s390_r2, s390_r14, STK_BASE, S390_PARM_SAVE_OFFSET);
+ for (pos = 0; pos < 4; pos++)
+ s390_std (code, pos, 0, STK_BASE,
+ S390_FLOAT_SAVE_OFFSET+pos*sizeof(double));
+ } else {
+ s390_stm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
+ }
if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
cfg->used_int_regs |= 1 << 11;
}
alloc_size = cfg->stack_offset;
-// if (tracing)
-// alloc_size += S390_TRACE_STACK_SIZE;
-// pos = 0;
- /* reserve room to save return value */
-// if (tracing)
-// pos += 8;
-
-// alloc_size += pos;
-
-// if (method->save_lmf)
-// alloc_size += sizeof(MonoLMF);
-
-// alloc_size = S390_ALIGN(alloc_size, S390_STACK_ALIGNMENT);
cfg->stack_usage = alloc_size;
s390_lr (code, s390_r11, STK_BASE);
- if (s390_is_imm16 (-alloc_size)) {
+ if (s390_is_uimm16 (alloc_size)) {
s390_ahi (code, STK_BASE, -alloc_size);
} else {
int stackSize = alloc_size;
}
s390_st (code, s390_r11, 0, STK_BASE, 0);
-// if (cfg->flags & MONO_CFG_HAS_ALLOCA)
if (cfg->frame_reg != STK_BASE)
s390_lr (code, s390_r11, STK_BASE);
if (inst->dreg != ainfo->reg) {
if (ainfo->size == 4) {
s390_ledbr (code, inst->dreg, ainfo->reg);
-// s390_ler (code, inst->dreg, ainfo->reg);
} else {
s390_ldr (code, inst->dreg, ainfo->reg);
}
/*---------------------------------------------------------------*/
/* we build the MonoLMF structure on the stack - see mini-s390.h */
/*---------------------------------------------------------------*/
- lmfOffset = alloc_size - sizeof(MonoLMF);
-
- s390_lr (code, s390_r13, cfg->frame_reg);
- s390_ahi (code, s390_r13, lmfOffset);
-
- /*---------------------------------------------------------------*/
- /* Set lmf.lmf_addr = jit_tls->lmf */
- /*---------------------------------------------------------------*/
- s390_st (code, s390_r2, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, lmf_addr));
-
- /*---------------------------------------------------------------*/
- /* Get current lmf */
- /*---------------------------------------------------------------*/
- s390_l (code, s390_r0, 0, s390_r2, 0);
-
- /*---------------------------------------------------------------*/
- /* Set our lmf as the current lmf */
- /*---------------------------------------------------------------*/
- s390_st (code, s390_r13, 0, s390_r2, 0);
-
- /*---------------------------------------------------------------*/
- /* Have our lmf.previous_lmf point to the last lmf */
- /*---------------------------------------------------------------*/
- s390_st (code, s390_r0, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, previous_lmf));
-
- /*---------------------------------------------------------------*/
- /* save method info */
- /*---------------------------------------------------------------*/
- s390_basr (code, s390_r1, 0);
- s390_j (code, 4);
- s390_word (code, method);
- s390_l (code, s390_r1, 0, s390_r1, 4);
- s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, method));
-
- /*---------------------------------------------------------------*/
- /* save the current IP */
- /*---------------------------------------------------------------*/
+ lmfOffset = alloc_size - sizeof(MonoLMF);
+
+ s390_lr (code, s390_r13, cfg->frame_reg);
+ s390_ahi (code, s390_r13, lmfOffset);
+
+ /*---------------------------------------------------------------*/
+ /* Set lmf.lmf_addr = jit_tls->lmf */
+ /*---------------------------------------------------------------*/
+ s390_st (code, s390_r2, 0, s390_r13,
+ G_STRUCT_OFFSET(MonoLMF, lmf_addr));
+
+ /*---------------------------------------------------------------*/
+ /* Get current lmf */
+ /*---------------------------------------------------------------*/
+ s390_l (code, s390_r0, 0, s390_r2, 0);
+
+ /*---------------------------------------------------------------*/
+ /* Set our lmf as the current lmf */
+ /*---------------------------------------------------------------*/
+ s390_st (code, s390_r13, 0, s390_r2, 0);
+
+ /*---------------------------------------------------------------*/
+ /* Have our lmf.previous_lmf point to the last lmf */
+ /*---------------------------------------------------------------*/
+ s390_st (code, s390_r0, 0, s390_r13,
+ G_STRUCT_OFFSET(MonoLMF, previous_lmf));
+
+ /*---------------------------------------------------------------*/
+ /* save method info */
+ /*---------------------------------------------------------------*/
+ s390_basr (code, s390_r1, 0);
+ s390_j (code, 4);
+ s390_word (code, method);
+ s390_l (code, s390_r1, 0, s390_r1, 4);
+ s390_st (code, s390_r1, 0, s390_r13,
+ G_STRUCT_OFFSET(MonoLMF, method));
+
+ /*---------------------------------------------------------------*/
+ /* save the current IP */
+ /*---------------------------------------------------------------*/
s390_lr (code, s390_r1, cfg->frame_reg);
-// s390_ahi (code, s390_r1, alloc_size);
- s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
- s390_l (code, s390_r1, 0, s390_r1, S390_RET_ADDR_OFFSET);
- s390_la (code, s390_r1, 0, s390_r1, 0);
- s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
-
- /*---------------------------------------------------------------*/
- /* Save general and floating point registers */
- /*---------------------------------------------------------------*/
- s390_stm (code, s390_r2, s390_r12, s390_r13, G_STRUCT_OFFSET(MonoLMF, gregs[2]));
- for (i = 0; i < 16; i++) {
- s390_std (code, i, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, fregs[i]));
- }
+ s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
+ s390_basr (code, s390_r1, 0);
+ s390_la (code, s390_r1, 0, s390_r1, 0);
+ s390_st (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
+
+ /*---------------------------------------------------------------*/
+ /* Save general and floating point registers */
+ /*---------------------------------------------------------------*/
+ s390_stm (code, s390_r2, s390_r12, s390_r13,
+ G_STRUCT_OFFSET(MonoLMF, gregs[2]));
+ for (i = 0; i < 16; i++) {
+ s390_std (code, i, 0, s390_r13,
+ G_STRUCT_OFFSET(MonoLMF, fregs[i]));
+ }
/*---------------------------------------------------------------*/
/* Restore the parameter registers now that we've set up the lmf */
{
MonoJumpInfo *patch_info;
MonoMethod *method = cfg->method;
- MonoMethodSignature *sig = method->signature;
- MonoInst *inst;
- int i, tracing = 0;
+ int tracing = 0;
guint8 *code;
+ int max_epilog_size = 96;
+
+ if (cfg->method->save_lmf)
+ max_epilog_size += 128;
+
+ if (mono_jit_trace_calls != NULL)
+ max_epilog_size += 128;
+
+ if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
+ max_epilog_size += 128;
+
+ while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
+ cfg->code_size *= 2;
+ cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
+ mono_jit_stats.code_reallocs++;
+ }
code = cfg->native_code + cfg->code_len;
}
if (method->save_lmf)
- code = restoreLMF(cfg, code);
+ restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
if (cfg->flags & MONO_CFG_HAS_ALLOCA)
s390_l (code, STK_BASE, 0, STK_BASE, 0);
s390_lm (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
s390_br (code, s390_r14);
- /* add code to raise exceptions */
+ cfg->code_len = code - cfg->native_code;
+
+ g_assert (cfg->code_len < cfg->code_size);
+
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_emit_exceptions */
+/* */
+/* Function - Emit the blocks to handle exception conditions. */
+/* */
+/*------------------------------------------------------------------*/
+
+void
+mono_arch_emit_exceptions (MonoCompile *cfg)
+{
+ MonoJumpInfo *patch_info;
+ guint8 *code;
+ int nThrows = 0,
+ exc_count = 0,
+ iExc;
+ guint32 code_size;
+ MonoClass *exc_classes [MAX_EXC];
+ guint8 *exc_throw_start [MAX_EXC],
+ *exc_throw_end [MAX_EXC];
+
+ for (patch_info = cfg->patch_info;
+ patch_info;
+ patch_info = patch_info->next) {
+ if (patch_info->type == MONO_PATCH_INFO_EXC)
+ exc_count++;
+ }
+
+ code_size = exc_count * 26;
+
+ while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
+ cfg->code_size *= 2;
+ cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
+ mono_jit_stats.code_reallocs++;
+ }
+
+ code = cfg->native_code + cfg->code_len;
+
+ /*---------------------------------------------------------------------*/
+ /* Add code to raise exceptions */
+ /*---------------------------------------------------------------------*/
for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
switch (patch_info->type) {
case MONO_PATCH_INFO_EXC: {
+ guint8 *ip = patch_info->ip.i + cfg->native_code,
+ *buf, buf2;
+ MonoClass *exc_class;
+ guint32 throw_ip;
+
/*-----------------------------------------------------*/
/* Patch the branch in epilog to come here */
/*-----------------------------------------------------*/
- s390_patch (patch_info->ip.i+cfg->native_code+2,
- S390_RELATIVE(code,patch_info->ip.i+cfg->native_code));
- /*-----------------------------------------------------*/
- /* Patch the parameter passed to the handler */
- /*-----------------------------------------------------*/
- s390_basr (code, s390_r13, 0);
- s390_j (code, 4);
- mono_add_patch_info (cfg, code - cfg->native_code,
- MONO_PATCH_INFO_EXC_NAME,
- patch_info->data.target);
- s390_word (code, 0);
- /*-----------------------------------------------------*/
- /* Load the return address and the parameter register */
- /*-----------------------------------------------------*/
- s390_larl (code, s390_r14, S390_RELATIVE((patch_info->ip.i +
- cfg->native_code + 8), code));
- s390_l (code, s390_r2, 0, s390_r13, 4);
- /*-----------------------------------------------------*/
- /* Reuse the current patch to set the jump */
- /*-----------------------------------------------------*/
- patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
- patch_info->data.name = "mono_arch_throw_exception_by_name";
- patch_info->ip.i = code - cfg->native_code;
- s390_jcl (code, S390_CC_UN, 0);
+ s390_patch (ip + 2, S390_RELATIVE(code,ip));
+
+ exc_class = mono_class_from_name (mono_defaults.corlib,
+ "System",
+ patch_info->data.name);
+ g_assert (exc_class);
+ throw_ip = patch_info->ip.i;
+
+ for (iExc = 0; iExc < nThrows; ++iExc)
+ if (exc_classes [iExc] == exc_class)
+ break;
+
+ if (iExc < nThrows) {
+ s390_jcl (code, S390_CC_UN, exc_throw_start [iExc]);
+ patch_info->type = MONO_PATCH_INFO_NONE;
+ } else {
+
+ if (nThrows < MAX_EXC) {
+ exc_classes [nThrows] = exc_class;
+ exc_throw_start [nThrows] = code;
+ }
+
+ /*---------------------------------------------*/
+ /* Patch the parameter passed to the handler */
+ /*---------------------------------------------*/
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 4);
+ s390_word (code, patch_info->data.target);
+ /*---------------------------------------------*/
+ /* Load return address & parameter register */
+ /*---------------------------------------------*/
+ s390_larl (code, s390_r14, S390_RELATIVE((patch_info->ip.i +
+ cfg->native_code + 8), code));
+ s390_l (code, s390_r2, 0, s390_r13, 4);
+ /*---------------------------------------------*/
+ /* Reuse the current patch to set the jump */
+ /*---------------------------------------------*/
+ patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
+ patch_info->data.name = "mono_arch_throw_exception_by_name";
+ patch_info->ip.i = code - cfg->native_code;
+ s390_jcl (code, S390_CC_UN, 0);
+ }
break;
}
default:
void
mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
{
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ pthread_t self = pthread_self();
+ pthread_attr_t attr;
+ void *stAddr = NULL;
+ size_t stSize = 0;
+ struct sigaltstack sa;
+#endif
+
+ if (!tls_offset_inited) {
+ tls_offset_inited = TRUE;
+
+#if HAVE_KW_THREAD
+# if 0
+ __asm__ ("\tear\t%r1,0\n"
+ "\tlr\t%0,%3\n"
+ "\tsr\t%0,%r1\n"
+ "\tlr\t%1,%4\n"
+ "\tsr\t%1,%r1\n"
+ "\tlr\t%2,%5\n"
+ "\tsr\t%2,%r1\n"
+ : "=r" (appdomain_tls_offset),
+ "=r" (thread_tls_offset),
+ "=r" (lmf_tls_offset)
+ : "r" (&tls_appdomain),
+ "r" (&tls_current_object),
+ "r" (&mono_lmf_addr)
+ : "1", "cc");
+# endif
+#endif
+ }
+
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+
+ /*----------------------------------------------------------*/
+ /* Determine stack boundaries */
+ /*----------------------------------------------------------*/
+ if (!mono_running_on_valgrind ()) {
+#ifdef HAVE_PTHREAD_GETATTR_NP
+ pthread_getattr_np( self, &attr );
+#elif HAVE_PTHREAD_ATTR_GET_NP
+ pthread_attr_get_np( self, &attr );
+#endif
+ pthread_attr_getstack( &attr, &stAddr, &stSize );
+ }
+
+
+ /*----------------------------------------------------------*/
+ /* Setup an alternate signal stack */
+ /*----------------------------------------------------------*/
+ tls->stack_size = stSize;
+ tls->signal_stack = g_malloc (SIGNAL_STACK_SIZE);
+ tls->signal_stack_size = SIGNAL_STACK_SIZE;
+
+ sa.ss_sp = tls->signal_stack;
+ sa.ss_size = SIGNAL_STACK_SIZE;
+ sa.ss_flags = SS_ONSTACK;
+ sigaltstack (&sa, NULL);
+#endif
+
}
/*========================= End of Function ========================*/
void
mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
{
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ struct sigaltstack sa;
+
+ sa.ss_sp = tls->signal_stack;
+ sa.ss_size = SIGNAL_STACK_SIZE;
+ sa.ss_flags = SS_DISABLE;
+ sigaltstack (&sa, NULL);
+
+ if (tls->signal_stack)
+ g_free (tls->signal_stack);
+#endif
+
}
/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_get_opcode_for_method */
+/* Name - mono_arch_get_inst_for_method */
/* */
/* Function - Check for opcodes we can handle directly in */
/* hardware. */
/* */
/*------------------------------------------------------------------*/
-gint
-mono_arch_get_opcode_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
+MonoInst*
+mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod,
+ MonoMethodSignature *fsig, MonoInst **args)
{
+ MonoInst *ins = NULL;
+
if (cmethod->klass == mono_defaults.math_class) {
- if (strcmp (cmethod->name, "Sqrt") == 0)
- return OP_SQRT;
+ if (strcmp (cmethod->name, "Sqrt") == 0) {
+ MONO_INST_NEW (cfg, ins, OP_SQRT);
+ ins->inst_i0 = args [0];
+ }
+ } else if(cmethod->klass->image == mono_defaults.corlib &&
+ (strcmp (cmethod->klass->name_space, "System.Threading") == 0) &&
+ (strcmp (cmethod->klass->name, "Interlocked") == 0)) {
+
+ if (strcmp (cmethod->name, "Increment") == 0 &&
+ fsig->params [0]->type == MONO_TYPE_I4) {
+ MonoInst *ins_iconst;
+
+ MONO_INST_NEW (cfg, ins, OP_ATOMIC_ADD_NEW_I4);
+ MONO_INST_NEW (cfg, ins_iconst, OP_ICONST);
+ ins_iconst->inst_c0 = 1;
+
+ ins->inst_i0 = args [0];
+ ins->inst_i1 = ins_iconst;
+ } else if (strcmp (cmethod->name, "Decrement") == 0 &&
+ fsig->params [0]->type == MONO_TYPE_I4) {
+ MonoInst *ins_iconst;
+
+ MONO_INST_NEW (cfg, ins, OP_ATOMIC_ADD_NEW_I4);
+ MONO_INST_NEW (cfg, ins_iconst, OP_ICONST);
+ ins_iconst->inst_c0 = -1;
+
+ ins->inst_i0 = args [0];
+ ins->inst_i1 = ins_iconst;
+ } else if (strcmp (cmethod->name, "Exchange") == 0 &&
+ fsig->params [0]->type == MONO_TYPE_I4) {
+ MONO_INST_NEW (cfg, ins, OP_ATOMIC_EXCHANGE_I4);
+
+ ins->inst_i0 = args [0];
+ ins->inst_i1 = args [1];
+ } else if (strcmp (cmethod->name, "Add") == 0 &&
+ fsig->params [0]->type == MONO_TYPE_I4) {
+ MONO_INST_NEW (cfg, ins, OP_ATOMIC_ADD_I4);
+
+ ins->inst_i0 = args [0];
+ ins->inst_i1 = args [1];
+ }
}
- return -1;
+ return ins;
}
/*========================= End of Function ========================*/
switch (tree->opcode) {
case OP_S390_LOADARG:
case OP_S390_ARGPTR:
- case OP_S390_STKARG:
printf ("[0x%x(%s)]", tree->inst_offset,
mono_arch_regname (tree->inst_basereg));
done = 1;
break;
+ case OP_S390_STKARG:
+ printf ("[0x%x(previous_frame)]",
+ tree->inst_offset);
+ done = 1;
+ break;
case OP_S390_MOVE:
printf ("[0x%x(%d,%s),0x%x(%s)]",
tree->inst_offset, tree->unused,
printf ("[f%d,f%d]",
mono_arch_regname (tree->dreg),
mono_arch_regname (tree->sreg1));
+ done = 1;
+ break;
+ case OP_TLS_GET:
+ printf ("[0x%x(0x%x,%s)]", tree->inst_offset,
+ tree->inst_imm,
+ mono_arch_regname (tree->sreg1));
+ done = 1;
default:
done = 0;
}
mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
{
/* FIXME: */
- return 3;
+ return 2;
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_get_domain_intrinsic */
+/* */
+/* Function - */
+/* */
+/* Returns - */
+/* */
+/*------------------------------------------------------------------*/
+
+MonoInst *
+mono_arch_get_domain_intrinsic (MonoCompile* cfg)
+{
+ MonoInst *ins;
+
+ if (appdomain_tls_offset == -1)
+ return NULL;
+
+ MONO_INST_NEW (cfg, ins, OP_TLS_GET);
+ ins->inst_offset = appdomain_tls_offset;
+ return (ins);
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_get_thread_intrinsic */
+/* */
+/* Function - */
+/* */
+/* Returns - */
+/* */
+/*------------------------------------------------------------------*/
+
+MonoInst *
+mono_arch_get_thread_intrinsic (MonoCompile* cfg)
+{
+ MonoInst *ins;
+
+ if (thread_tls_offset == -1)
+ return NULL;
+
+ MONO_INST_NEW (cfg, ins, OP_TLS_GET);
+ ins->inst_offset = thread_tls_offset;
+ return (ins);
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_flush_register_windows */
+/* */
+/* Function - */
+/* */
+/* Returns - */
+/* */
+/*------------------------------------------------------------------*/
+
+void
+mono_arch_flush_register_windows (void)
+{
}
/*========================= End of Function ========================*/