#define S390_THROWSTACK_ACCPRM S390_MINIMAL_STACK_SIZE
#define S390_THROWSTACK_FPCPRM (S390_THROWSTACK_ACCPRM+sizeof(gpointer))
-#define S390_THROWSTACK_RETHROW (S390_THROWSTACK_FPCPRM+sizeof(gint32))
+#define S390_THROWSTACK_RETHROW (S390_THROWSTACK_FPCPRM+sizeof(gulong))
#define S390_THROWSTACK_INTREGS (S390_THROWSTACK_RETHROW+sizeof(gboolean))
#define S390_THROWSTACK_FLTREGS (S390_THROWSTACK_INTREGS+(16*sizeof(gulong)))
#define S390_THROWSTACK_ACCREGS (S390_THROWSTACK_FLTREGS+(16*sizeof(gdouble)))
/* G l o b a l V a r i a b l e s */
/*------------------------------------------------------------------*/
+typedef enum {
+ by_none,
+ by_name,
+ by_token
+} throwType;
+
/*====================== End of Global Variables ===================*/
/*------------------------------------------------------------------*/
/*------------------------------------------------------*/
/* save general registers on stack */
/*------------------------------------------------------*/
- s390_stmg (code, s390_r0, s390_r13, STK_BASE, S390_CALLFILTER_INTREGS);
+ s390_stmg (code, s390_r0, STK_BASE, STK_BASE, S390_CALLFILTER_INTREGS);
/*------------------------------------------------------*/
/* save floating point registers on stack */
/*------------------------------------------------------*/
-// pos = S390_CALLFILTER_FLTREGS;
-// for (i = 0; i < 16; ++i) {
-// s390_std (code, i, 0, STK_BASE, pos);
-// pos += sizeof (gdouble);
-// }
+ pos = S390_CALLFILTER_FLTREGS;
+ for (i = 0; i < 16; ++i) {
+ s390_std (code, i, 0, STK_BASE, pos);
+ pos += sizeof (gdouble);
+ }
/*------------------------------------------------------*/
/* save access registers on stack */
/*------------------------------------------------------*/
-// s390_stam (code, s390_a0, s390_a15, STK_BASE, S390_CALLFILTER_ACCREGS);
+ s390_stam (code, s390_a0, s390_a15, STK_BASE, S390_CALLFILTER_ACCREGS);
/*------------------------------------------------------*/
/* Get A(Context) */
}
/*------------------------------------------------------*/
- /* Point at the copied stack frame and call the filter */
+ /* Go call filter */
/*------------------------------------------------------*/
s390_lgr (code, s390_r1, s390_r0);
s390_basr (code, s390_r14, s390_r1);
/* Restore all the regs from the stack */
/*------------------------------------------------------*/
s390_lmg (code, s390_r0, s390_r13, STK_BASE, S390_CALLFILTER_INTREGS);
-// pos = S390_CALLFILTER_FLTREGS;
-// for (i = 0; i < 16; ++i) {
-// s390_ld (code, i, 0, STK_BASE, pos);
-// pos += sizeof (gdouble);
-// }
+ pos = S390_CALLFILTER_FLTREGS;
+ for (i = 0; i < 16; ++i) {
+ s390_ld (code, i, 0, STK_BASE, pos);
+ pos += sizeof (gdouble);
+ }
s390_lgr (code, s390_r2, s390_r14);
-// s390_lam (code, s390_a0, s390_a15, STK_BASE, S390_CALLFILTER_ACCREGS);
+ s390_lam (code, s390_a0, s390_a15, STK_BASE, S390_CALLFILTER_ACCREGS);
s390_aghi (code, s390_r15, alloc_size);
s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
s390_br (code, s390_r14);
{
MonoContext ctx;
int iReg;
+ static void (*restore_context) (MonoContext *);
+
+ if (!restore_context)
+ restore_context = mono_arch_get_restore_context();
memset(&ctx, 0, sizeof(ctx));
getcontext(&ctx);
/* adjust eip so that it point into the call instruction */
- ip -= 6;
+ ip -= 2;
for (iReg = 0; iReg < 16; iReg++) {
ctx.uc_mcontext.gregs[iReg] = int_regs[iReg];
mono_ex->stack_trace = NULL;
}
mono_arch_handle_exception (&ctx, exc, FALSE);
- setcontext(&ctx);
+ restore_context(&ctx);
g_assert_not_reached ();
}
static gpointer
get_throw_exception_generic (guint8 *start, int size,
- int by_name, gboolean rethrow)
+ throwType type, gboolean rethrow)
{
guint8 *code;
int alloc_size, pos, i;
s390_lgr (code, s390_r14, STK_BASE);
s390_aghi (code, STK_BASE, -alloc_size);
s390_stg (code, s390_r14, 0, STK_BASE, 0);
- if (by_name) {
+ switch (type) {
+ case by_name :
s390_lgr (code, s390_r4, s390_r2);
+ s390_lg (code, s390_r3, 0, s390_r2, G_STRUCT_OFFSET(MonoException, object));
s390_basr (code, s390_r13, 0);
- s390_j (code, 14);
+ s390_j (code, 10);
s390_llong(code, mono_defaults.corlib);
- s390_llong(code, "System");
s390_llong(code, mono_exception_from_name);
+ s390_lg (code, s390_r3, 0, s390_r3, G_STRUCT_OFFSET(MonoVTable, klass));
+ s390_lg (code, s390_r2, 0, s390_r13, 4);
+ s390_lg (code, s390_r1, 0, s390_r13, 12);
+ s390_lg (code, s390_r4, 0, s390_r3, G_STRUCT_OFFSET(MonoClass, name));
+ s390_lg (code, s390_r3, 0, s390_r3, G_STRUCT_OFFSET(MonoClass, name_space));
+ s390_basr (code, s390_r14, s390_r1);
+ break;
+ case by_token :
+ s390_lgr (code, s390_r3, s390_r2);
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 10);
+ s390_llong(code, mono_defaults.exception_class->image);
+ s390_llong(code, mono_exception_from_token);
s390_lg (code, s390_r2, 0, s390_r13, 4);
- s390_lg (code, s390_r3, 0, s390_r13, 12);
- s390_lg (code, s390_r1, 0, s390_r13, 20);
+ s390_lg (code, s390_r1, 0, s390_r13, 12);
s390_basr (code, s390_r14, s390_r1);
+ break;
+ case by_none :
+ break;
}
/*------------------------------------------------------*/
/* save the general registers on the stack */
s390_stam (code, s390_r0, s390_r15, STK_BASE, S390_THROWSTACK_ACCREGS);
/*------------------------------------------------------*/
- /* call throw_exception (exc, ip, sp, gr, fr, ar) */
- /* exc is already in place in r2 */
+ /* call throw_exception (tkn, ip, sp, gr, fr, ar, re) */
+ /* - r2 already contains *exc */
/*------------------------------------------------------*/
s390_lgr (code, s390_r4, s390_r1); /* caller sp */
+
/*------------------------------------------------------*/
/* pointer to the saved int regs */
/*------------------------------------------------------*/
s390_la (code, s390_r6, 0, STK_BASE, S390_THROWSTACK_FLTREGS);
s390_la (code, s390_r7, 0, STK_BASE, S390_THROWSTACK_ACCREGS);
s390_stg (code, s390_r7, 0, STK_BASE, S390_THROWSTACK_ACCPRM);
- s390_stfpc(code, STK_BASE, S390_THROWSTACK_FPCPRM);
+ s390_stfpc(code, STK_BASE, S390_THROWSTACK_FPCPRM+4);
s390_lghi (code, s390_r7, rethrow);
s390_stg (code, s390_r7, 0, STK_BASE, S390_THROWSTACK_RETHROW);
s390_basr (code, s390_r13, 0);
if (inited)
return start;
start = mono_global_codeman_reserve (SZ_THROW);
- get_throw_exception_generic (start, SZ_THROW, FALSE, FALSE);
+ get_throw_exception_generic (start, SZ_THROW, by_none, FALSE);
inited = 1;
return start;
}
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - arch_get_corlib_exception */
+/* */
+/* Function - Return a function pointer which can be used to */
+/* raise corlib exceptions. The return function has */
+/* the following signature: */
+/* void (*func) (guint32 token, guint32 offset) */
+/* */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_get_throw_corlib_exception(void)
+{
+ static guint8 *start;
+ static int inited = 0;
+
+ if (inited)
+ return start;
+ start = mono_global_codeman_reserve (SZ_THROW);
+ get_throw_exception_generic (start, SZ_THROW, by_token, FALSE);
+ inited = 1;
+ return start;
+}
+
+/*========================= End of Function ========================*/
+
/*------------------------------------------------------------------*/
/* */
/* Name - arch_get_throw_exception_by_name */
if (inited)
return start;
start = mono_global_codeman_reserve (SZ_THROW);
- get_throw_exception_generic (start, SZ_THROW, TRUE, FALSE);
+ get_throw_exception_generic (start, SZ_THROW, by_name, FALSE);
inited = 1;
return start;
}
/* D e f i n e s */
/*------------------------------------------------------------------*/
-#define EMIT_COND_BRANCH(ins,cond) \
-{ \
+#define MAX_ARCH_DELEGATE_PARAMS 7
+
+#define EMIT_COND_BRANCH(ins,cond) \
+{ \
if (ins->inst_true_bb->native_offset) { \
int displace; \
displace = ((cfg->native_code + \
} \
}
-#define EMIT_UNCOND_BRANCH(ins) \
-{ \
+#define EMIT_UNCOND_BRANCH(ins) \
+{ \
if (ins->inst_target_bb->native_offset) { \
int displace; \
displace = ((cfg->native_code + \
#define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
MonoInst *inst; \
- int tmpr = 0; \
int sReg, dReg; \
- MONO_INST_NEW (cfg, inst, OP_NOP); \
+ MONO_INST_NEW (cfg, inst, OP_NOP); \
if (size > 256) { \
- tmpr = mono_alloc_preg (cfg); \
- MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
inst->dreg = dest; \
inst->inst_offset = offset; \
inst->sreg1 = src; \
inst->inst_imm = imm; \
- inst->sreg2 = tmpr; \
} else { \
if (s390_is_uimm12(offset)) { \
inst->dreg = dest; \
inst->inst_offset = offset; \
} else { \
- dReg = mono_alloc_preg (cfg); \
+ dReg = mono_alloc_preg (cfg); \
MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
dReg, dest, offset); \
inst->dreg = dReg; \
inst->sreg1 = src; \
inst->inst_imm = imm; \
} else { \
- sReg = mono_alloc_preg (cfg); \
+ sReg = mono_alloc_preg (cfg); \
MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
sReg, src, imm); \
inst->sreg1 = sReg; \
inst->inst_imm = 0; \
} \
} \
- inst->opcode = OP_S390_MOVE; \
- inst->backend.size = size; \
- MONO_ADD_INS (cfg->cbb, inst); \
+ inst->opcode = OP_S390_MOVE; \
+ inst->backend.size = size; \
+ MONO_ADD_INS (cfg->cbb, inst); \
} while (0)
#define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
reg, sr, so); \
break; \
} \
- mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
+ mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
} while (0)
#define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
dr, dx, tmpr); \
break; \
case 2: \
- tmpr = mono_alloc_preg (cfg); \
+ tmpr = mono_alloc_preg (cfg); \
MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
tmpr, sr, so); \
MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
dr, dx, tmpr); \
break; \
case 4: \
- tmpr = mono_alloc_preg (cfg); \
+ tmpr = mono_alloc_preg (cfg); \
MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
tmpr, sr, so); \
MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
#define MAX(a, b) ((a) > (b) ? (a) : (b))
+/*
+ * imt thunking size values
+ */
+#define CMP_SIZE 24
+#define LOADCON_SIZE 20
+#define LOAD_SIZE 6
+#define BR_SIZE 2
+#define JUMP_SIZE 6
+#define ENABLE_WRONG_METHOD_CHECK 0
+
/*========================= End of Defines =========================*/
/*------------------------------------------------------------------*/
gboolean lmf_addr_key_inited = FALSE;
+facilityList_t facs;
+
#if 0
extern __thread MonoDomain *tls_appdomain;
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_init. */
+/* */
+/* Function - Initialize architecture specific code. */
+/* */
+/*------------------------------------------------------------------*/
-/*
- * Initialize architecture specific code.
- */
void
mono_arch_init (void)
{
+#if 0
+ /*
+ * When we do an architectural level set at z9 or better
+ * we can use the STFLE instruction to show us
+ * what hardware facilities are available
+ */
+ int lFacility = sizeof(facs) % 8;
+
+ memset((char *) &facs, 0, sizeof(facs));
+
+ __asm__ (" lgfr 0,%1\n"
+ " stfle %0\n"
+ : "=m" (facs) : "r" (lFacility) : "0", "cc");
+#endif
+
}
-/*
- * Cleanup architecture specific code.
- */
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_cleanup. */
+/* */
+/* Function - Cleanup architecture specific code . */
+/* */
+/*------------------------------------------------------------------*/
+
void
mono_arch_cleanup (void)
{
}
+/*========================= End of Function ========================*/
+
/*------------------------------------------------------------------*/
/* */
/* Name - mono_arch_cpu_optimizazions */
/* */
/*------------------------------------------------------------------*/
-static void inline
+// static void inline
+static void
add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
{
if (*gr > S390_LAST_ARG_REG) {
/*------------------------------------------------------------------*/
/* */
-/* Name - get_call_info */
+/* Name - get_call_info */
/* */
/* Function - Determine the amount of space required for code */
/* and stack. In addition determine starting points */
nParm++;
}
+ if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
+ gr = S390_LAST_ARG_REG + 1;
+
+ /* Emit the signature cookie just before the implicit arguments */
+ add_general (&gr, sz, &cinfo->sigCookie);
+ }
+
/*----------------------------------------------------------*/
/* We determine the size of the parameter code and stack */
/* requirements by checking the types and sizes of the */
/* Handle the case where there are no implicit arguments */
/*----------------------------------------------------------*/
if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (nParm > 0) &&
+ (!sig->pinvoke) &&
(sig->param_count == sig->sentinelpos)) {
gr = S390_LAST_ARG_REG + 1;
add_general (&gr, sz, &cinfo->sigCookie);
/* to point at the local variables. */
/* add parameter area size for called functions */
/*--------------------------------------------------------------*/
- offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
+ if (cfg->param_area == 0)
+ offset = S390_MINIMAL_STACK_SIZE;
+ else
+ offset = cfg->param_area;
+
cfg->sig_cookie = 0;
if (cinfo->struct_ret) {
continue;
/*--------------------------------------------------*/
- /* inst->backend.is_pinvoke indicates native sized value types, */
- /* this is used by the pinvoke wrappers when they */
- /* call functions returning structure */
+ /* inst->backend.is_pinvoke indicates native sized */
+ /* value typs this is used by the pinvoke wrappers */
+ /* when they call functions returning structure */
/*--------------------------------------------------*/
if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
/*------------------------------------------------------*/
cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
+ /*------------------------------------------------------*/
+ /* Fix offsets for args whose value is in parent frame */
+ /*------------------------------------------------------*/
+ for (iParm = sArg; iParm < eArg; ++iParm) {
+ inst = cfg->args [iParm];
+
+ if (inst->opcode == OP_S390_STKARG) {
+ inst->opcode = OP_REGOFFSET;
+ inst->inst_offset += cfg->stack_offset;
+ }
+ }
}
/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_create_vars */
+/* Name - mono_arch_create_vars */
+/* */
/*------------------------------------------------------------------*/
void
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - add_outarg_reg2. */
+/* */
+/*------------------------------------------------------------------*/
+
static void
add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
{
}
}
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - emit_sig_cookie. */
+/* */
+/*------------------------------------------------------------------*/
+
static void
emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
{
MONO_ADD_INS (cfg->cbb, sig_arg);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
- cinfo->sigCookie.offset, sig_arg->dreg);
+ cinfo->sigCookie.offset, sig_arg->dreg);
}
+/*========================= End of Function ========================*/
+
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_emit_call */
+/* Name - mono_arch_emit_call */
/* */
/*------------------------------------------------------------------*/
int i, n, lParamArea;
CallInfo *cinfo;
ArgInfo *ainfo = NULL;
- int stackSize;
+ int stackSize;
+ MonoMethodHeader *header;
+ int frmReg;
sig = call->signature;
n = sig->param_count + sig->hasthis;
cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
- stackSize = cinfo->sz.stack_size + cinfo->sz.local_size + cinfo->sz.parm_size + cinfo->sz.offset;
+ stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
+ cinfo->sz.parm_size + cinfo->sz.offset;
call->stack_usage = MAX(stackSize, call->stack_usage);
lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
}
+ header = mono_method_get_header (cfg->method);
+ if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
+ frmReg = s390_r11;
+ else
+ frmReg = STK_BASE;
+
for (i = 0; i < n; ++i) {
MonoType *t;
in = call->args [i];
if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (!sig->pinvoke) &&
(i == sig->sentinelpos)) {
emit_sig_cookie (cfg, call, cinfo);
}
*/
int treg = mono_alloc_preg (cfg);
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
- STK_BASE, ainfo->offparm);
+ frmReg, ainfo->offparm);
mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
} else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
/* The address of the valuetype is passed on the stack */
int treg = mono_alloc_preg (cfg);
MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
- STK_BASE, ainfo->offparm);
+ frmReg, ainfo->offparm);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
- ainfo->reg, ainfo->offset, treg);
+ ainfo->reg, ainfo->offset, treg);
}
break;
}
case RegTypeBase:
if (!t->byref && t->type == MONO_TYPE_R4) {
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
- STK_BASE, ainfo->offset + 4,
- in->dreg);
+ STK_BASE, ainfo->offset + 4,
+ in->dreg);
} else if (!t->byref && (t->type == MONO_TYPE_R8)) {
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
- STK_BASE, ainfo->offset,
- in->dreg);
+ STK_BASE, ainfo->offset,
+ in->dreg);
} else {
MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
ins->inst_destbasereg = STK_BASE;
ins->inst_offset = ainfo->offset;
ins->sreg1 = in->dreg;
+#if 0
/* This is needed by MonoTypedRef->value to point to the correct data */
if ((sig->call_convention == MONO_CALL_VARARG) &&
(i >= sig->sentinelpos)) {
break;
}
}
+#endif
MONO_ADD_INS (cfg->cbb, ins);
}
* Handle the case where there are no implicit arguments
*/
if ((sig->call_convention == MONO_CALL_VARARG) &&
+ (!sig->pinvoke) &&
(i == sig->sentinelpos)) {
emit_sig_cookie (cfg, call, cinfo);
}
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_emit_outarg_vt */
+/* Name - mono_arch_emit_outarg_vt */
/* */
/*------------------------------------------------------------------*/
mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
} else {
- MONO_EMIT_NEW_MOVE (cfg, STK_BASE, ainfo->offparm,
+ MonoMethodHeader *header;
+ int srcReg;
+
+ header = mono_method_get_header (cfg->method);
+ if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
+ srcReg = s390_r11;
+ else
+ srcReg = STK_BASE;
+
+ MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
src->dreg, 0, size);
}
}
+/*========================= End of Function ========================*/
+
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_emit_setret */
+/* Name - mono_arch_emit_setret */
/* */
/*------------------------------------------------------------------*/
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_peephole_pass_1 */
+/* */
+/* Function - Form a peephole pass at the code looking for */
+/* simple optimizations. */
+/* */
+/*------------------------------------------------------------------*/
+
void
mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
{
}
+/*========================= End of Function ========================*/
+
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_peephole_pass */
+/* Name - mono_arch_peephole_pass_2 */
/* */
/* Function - Form a peephole pass at the code looking for */
/* simple optimizations. */
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_lowering_pass. */
+/* */
+/*------------------------------------------------------------------*/
+
void
mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
{
}
break;
case OP_LOCALLOC: {
- int alloca_skip = S390_MINIMAL_STACK_SIZE + cfg->param_area;
- int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
+ int alloca_skip;
+ int area_offset;
+
+ if (cfg->param_area == 0)
+ alloca_skip = S390_MINIMAL_STACK_SIZE;
+ else
+ alloca_skip = cfg->param_area;
+
+ area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
s390_lgr (code, s390_r1, ins->sreg1);
if (ins->flags & MONO_INST_INIT)
s390_lgr (code, s390_r0, ins->sreg1);
ins->inst_offset, ins->sreg1, ins->inst_imm);
} else {
s390_lgr (code, s390_r0, ins->dreg);
- if (s390_is_imm16 (ins->inst_offset)) {
- s390_aghi (code, s390_r0, ins->inst_offset);
- } else {
- s390_basr (code, s390_r13, 0);
- s390_j (code, 6);
- s390_llong(code, ins->inst_offset);
- s390_a (code, s390_r0, 0, s390_r13, 4);
+ if (ins->inst_offset > 0) {
+ if (s390_is_imm16 (ins->inst_offset)) {
+ s390_aghi (code, s390_r0, ins->inst_offset);
+ } else {
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 6);
+ s390_llong(code, ins->inst_offset);
+ s390_ag (code, s390_r0, 0, s390_r13, 4);
+ }
}
s390_lgr (code, s390_r12, ins->sreg1);
- if (s390_is_imm16 (ins->inst_imm)) {
- s390_aghi (code, s390_r12, ins->inst_imm);
+ if (ins->inst_imm > 0) {
+ if (s390_is_imm16 (ins->inst_imm)) {
+ s390_aghi (code, s390_r12, ins->inst_imm);
+ } else {
+ s390_basr (code, s390_r13, 0);
+ s390_j (code, 6);
+ s390_llong(code, ins->inst_imm);
+ s390_ag (code, s390_r12, 0, s390_r13, 4);
+ }
+ }
+ if (s390_is_imm16 (ins->backend.size)) {
+ s390_lghi (code, s390_r1, ins->backend.size);
} else {
s390_basr (code, s390_r13, 0);
s390_j (code, 6);
- s390_llong(code, ins->inst_imm);
- s390_ag (code, s390_r12, 0, s390_r13, 4);
+ s390_llong(code, ins->backend.size);
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
}
- s390_lgr (code, s390_r1, ins->sreg1);
s390_lgr (code, s390_r13, s390_r1);
s390_mvcle(code, s390_r0, s390_r12, 0, 0);
s390_jo (code, -2);
/*---------------------------------------------------------------*/
/* On return from this call r2 have the address of the &lmf */
/*---------------------------------------------------------------*/
- s390_basr(code, s390_r10, 0);
+ s390_basr(code, s390_r14, 0);
s390_j (code, 6);
mono_add_patch_info (cfg, code - cfg->native_code,
MONO_PATCH_INFO_INTERNAL_METHOD,
(gpointer)"mono_get_lmf_addr");
s390_llong(code, 0);
- s390_lg (code, s390_r1, 0, s390_r10, 4);
+ s390_lg (code, s390_r1, 0, s390_r14, 4);
s390_basr (code, s390_r14, s390_r1);
/*---------------------------------------------------------------*/
/*---------------------------------------------*/
s390_basr (code, s390_r13, 0);
s390_j (code, 6);
- s390_llong(code, patch_info->data.target);
+// s390_llong(code, patch_info->data.target);
+ s390_llong(code, exc_class->type_token);
/*---------------------------------------------*/
/* Load return address & parameter register */
/*---------------------------------------------*/
s390_basr (code, s390_r13, 0);
s390_j (code, 6);
patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
- patch_info->data.name = "mono_arch_throw_exception_by_name";
+ patch_info->data.name = "mono_arch_throw_corlib_exception";
patch_info->ip.i = code - cfg->native_code;
s390_llong(code, 0);
s390_lg (code, s390_r1, 0, s390_r13, 4);
}
/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_get_this_arg_from_call. */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_get_this_arg_from_call (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, mgreg_t *regs, guint8 *code)
+{
+ MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
+
+ /* FIXME: handle returning a struct */
+ if (MONO_TYPE_ISSTRUCT (sig->ret))
+ return (gpointer) lmf->gregs [s390_r3];
+ return (gpointer) lmf->gregs [s390_r2];
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - get_delegate_invoke_impl. */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+static gpointer
+get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
+{
+ guint8 *code, *start;
+
+ if (has_target) {
+ int size = 32;
+
+ start = code = mono_global_codeman_reserve (size);
+
+ /* Replace the this argument with the target */
+ s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
+ s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
+ s390_br (code, s390_r1);
+ g_assert ((code - start) <= size);
+
+ mono_arch_flush_icache (start, size);
+ } else {
+ int size, i;
+
+ size = 32 + param_count * 8;
+ start = code = mono_global_codeman_reserve (size);
+
+ s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
+ /* slide down the arguments */
+ for (i = 0; i < param_count; ++i) {
+ s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
+ }
+ s390_br (code, s390_r1);
+
+ g_assert ((code - start) <= size);
+
+ mono_arch_flush_icache (start, size);
+ }
+
+ if (code_len)
+ *code_len = code - start;
+
+ return start;
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_get_delegate_invoke_impls. */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+GSList*
+mono_arch_get_delegate_invoke_impls (void)
+{
+ GSList *res = NULL;
+ guint8 *code;
+ guint32 code_len;
+ int i;
+
+ code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
+ res = g_slist_prepend (res, mono_aot_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len));
+
+ for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
+ code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
+ res = g_slist_prepend (res, mono_aot_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len));
+ }
+
+ return res;
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_get_delegate_invoke_impl. */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
+{
+ guint8 *code, *start;
+
+ /* FIXME: Support more cases */
+ if (MONO_TYPE_ISSTRUCT (sig->ret))
+ return NULL;
+
+ if (has_target) {
+ static guint8* cached = NULL;
+
+ if (cached)
+ return cached;
+
+ if (mono_aot_only)
+ start = mono_aot_get_named_code ("delegate_invoke_impl_has_target");
+ else
+ start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
+
+ mono_memory_barrier ();
+
+ cached = start;
+ } else {
+ static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
+ int i;
+
+ if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
+ return NULL;
+ for (i = 0; i < sig->param_count; ++i)
+ if (!mono_is_regsize_var (sig->params [i]))
+ return NULL;
+
+
+ code = cache [sig->param_count];
+ if (code)
+ return code;
+
+ if (mono_aot_only) {
+ char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
+ start = mono_aot_get_named_code (name);
+ g_free (name);
+ } else {
+ start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
+ }
+
+ mono_memory_barrier ();
+
+ cache [sig->param_count] = start;
+ }
+ return start;
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_build_imt_thunk. */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
+ MonoIMTCheckItem **imt_entries, int count,
+ gpointer fail_tramp)
+{
+ int i;
+ int size = 0;
+ guchar *code, *start;
+
+ for (i = 0; i < count; ++i) {
+ MonoIMTCheckItem *item = imt_entries [i];
+ if (item->is_equals) {
+ if (item->check_target_idx) {
+ if (!item->compare_done)
+ item->chunk_size += CMP_SIZE + JUMP_SIZE;
+ if (item->has_target_code)
+ item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
+ else
+ item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
+ LOAD_SIZE;
+ } else {
+ if (fail_tramp) {
+ item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
+ 2 * LOADCON_SIZE;
+ if (!item->has_target_code)
+ item->chunk_size += LOAD_SIZE;
+ } else {
+ item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
+#if ENABLE_WRONG_METHOD_CHECK
+ item->chunk_size += CMP_SIZE + JUMP_SIZE;
+#endif
+ }
+ }
+ } else {
+ item->chunk_size += CMP_SIZE + JUMP_SIZE;
+ imt_entries [item->check_target_idx]->compare_done = TRUE;
+ }
+ size += item->chunk_size;
+ }
+
+ if (fail_tramp)
+ code = mono_method_alloc_generic_virtual_thunk (domain, size);
+ else
+ code = mono_domain_code_reserve (domain, size);
+
+ start = code;
+
+ for (i = 0; i < count; ++i) {
+ MonoIMTCheckItem *item = imt_entries [i];
+ item->code_target = (guint8 *) code;
+ if (item->is_equals) {
+ if (item->check_target_idx) {
+ if (!item->compare_done) {
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ s390_llong(code, item->key);
+ s390_lg (code, s390_r0, 0, s390_r13, 4);
+ s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
+ }
+ item->jmp_code = (guint8*) code;
+ s390_jcl (code, S390_CC_NE, 0);
+
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ if (item->has_target_code) {
+ s390_llong(code, item->value.target_code);
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
+ } else {
+ s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
+ s390_lg (code, s390_r1, 0, s390_r1, 0);
+ }
+ s390_br (code, s390_r1);
+ } else {
+ if (fail_tramp) {
+ gint64 target;
+
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ s390_llong(code, item->key);
+ s390_lg (code, s390_r0, 0, s390_r13, 4);
+ s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
+ item->jmp_code = (guint8*) code;
+ s390_jcl (code, S390_CC_NE, 0);
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ if (item->has_target_code) {
+ s390_llong(code, item->value.target_code);
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
+ } else {
+ g_assert (vtable);
+ s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
+ s390_lg (code, s390_r1, 0, s390_r1, 0);
+ }
+ s390_br (code, s390_r1);
+ target = S390_RELATIVE(item->jmp_code, code);
+ s390_patch_rel(item->jmp_code+2, target);
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ s390_llong(code, fail_tramp);
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
+ s390_br (code, s390_r1);
+ item->jmp_code = NULL;
+ } else {
+ /* enable the commented code to assert on wrong method */
+#if ENABLE_WRONG_METHOD_CHECK
+ g_assert_not_reached ();
+#endif
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
+ s390_lg (code, s390_r1, 0, s390_r13, 4);
+ s390_lg (code, s390_r1, 0, s390_r1, 0);
+ s390_br (code, s390_r1);
+#if ENABLE_WRONG_METHOD_CHECK
+ g_assert_not_reached ();
+#endif
+ }
+ }
+ } else {
+ s390_basr (code, s390_r13, s390_r0);
+ s390_j (code, 6);
+ s390_llong(code, item->key);
+ s390_lg (code, s390_r0, 0, s390_r13, 4);
+ s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
+ item->jmp_code = (guint8 *) code;
+ s390_jcl (code, S390_CC_GE, 0);
+ }
+ }
+ /* patch the branches to get to the target items */
+ for (i = 0; i < count; ++i) {
+ MonoIMTCheckItem *item = imt_entries [i];
+ if (item->jmp_code) {
+ if (item->check_target_idx) {
+ gint64 offset;
+ offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
+ item->jmp_code);
+ s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
+ }
+ }
+ }
+
+ mono_arch_flush_icache ((guint8*)start, (code - start));
+
+ if (!fail_tramp)
+ mono_stats.imt_thunks_size += (code - start);
+
+ g_assert (code - start <= size);
+
+ return (start);
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_find_imt_method. */
+/* */
+/* Function - Get the method address from MONO_ARCH_IMT_REG */
+/* found in the save area. */
+/* */
+/*------------------------------------------------------------------*/
+
+MonoMethod*
+mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
+{
+ MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
+
+ return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_find_this_argument. */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+MonoObject *
+mono_arch_find_this_argument (mgreg_t *regs, MonoMethod *method,
+ MonoGenericSharingContext *gsctx)
+{
+ return mono_arch_get_this_arg_from_call (gsctx, mono_method_signature (method), regs, NULL);
+}
+
+/*========================= End of Function ========================*/
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_get_unbox_trampoline */
+/* Name - mono_arch_get_unbox_trampoline */
/* */
/* Function - Return a pointer to a trampoline which does the */
/* unboxing before calling the method. */
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_patch_callsite */
+/* Name - mono_arch_patch_callsite */
/* */
-/* Function - Patch a non-virtual callsite so it calls @addr. */
+/* Function - Patch a non-virtual callsite so it calls @addr. */
/* */
/*------------------------------------------------------------------*/
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_patch_plt_entry. */
+/* */
+/* Function - Patch a PLT entry - unused as yet. */
+/* */
+/*------------------------------------------------------------------*/
+
void
mono_arch_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr)
{
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_nullify_class_init_trampoline */
+/* Name - mono_arch_nullify_class_init_trampoline */
/* */
-/* Function - Nullify a call which calls a class init trampoline */
+/* Function - Nullify a call which calls a class init trampoline*/
/* */
/*------------------------------------------------------------------*/
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_nullify_plt_entry */
+/* */
+/* Function - Nullify a PLT entry call. */
+/* */
+/*------------------------------------------------------------------*/
+
void
mono_arch_nullify_plt_entry (guint8 *code, mgreg_t *regs)
{
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_get_vcall_slot */
+/* Name - mono_arch_get_vcall_slot */
/* */
-/* Function - This method is called by the arch independent */
+/* Function - This method is called by the arch independent */
/* trampoline code to determine the vtable slot used by */
/* the call which invoked the trampoline. */
/* */
guchar* base;
unsigned short opcode;
char *sp;
+ MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
// We are passed sp instead of the register array
- sp = (char*)regs;
+#if 0
+ sp = (char *) regs;
+#endif
+ sp = (char *) lmf->gregs[s390_r15];
*displacement = 0;
return NULL;
/*-----------------------------------*/
- /* This is a bras r14,Rz instruction */
+ /* This is a basr r14,Rz instruction */
/* If it's preceded by a LG Rx,d(Ry) */
/* If Rz == 1 then this is virtual */
/* call. */
/* If call is preceded by LGR then */
/* there's nothing to patch */
/*-----------------------------------*/
- if ((code[0] == 0xb9) &&
- (code[1] == 0x04))
+ if ((code[0] == 0xb9) && (code[1] == 0x04))
return NULL;
/*-----------------------------------*/
/* hh = high 8 bits of displacement */
/*-----------------------------------*/
reg = code[0] >> 4;
- *displacement = (code[2] << 12) +
- ((code[0] & 0x0f) << 8) +
- code[1];
+ *displacement = (code[2] << 12) |
+ ((code[0] & 0x0f) << 8) |
+ code[1];
+ if (code[2] & 0x80)
+ *displacement |= 0xfff00000;
+
+ base = ((guchar *) lmf->gregs[reg]);
+#if 0
if (reg > 5)
base = *((guchar **) (sp + S390_REG_SAVE_OFFSET +
sizeof(long)*(reg-6)));
base = *((guchar **) ((sp - CREATE_STACK_SIZE) +
CREATE_GR_OFFSET +
sizeof(long)*(reg-2)));
+#endif
if (lkReg != 1)
/* Non virtual call */
return NULL;
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_create_trampoline_code */
+/* Name - mono_arch_create_trampoline_code */
/* */
/* Function - Create the designated type of trampoline according*/
/* to the 'tramp_type' parameter. */
stack size big enough to save our registers.
-----------------------------------------------------------*/
- s390_stmg (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
+ s390_stmg (buf, s390_r6, s390_r15, STK_BASE, S390_REG_SAVE_OFFSET);
s390_lgr (buf, s390_r11, s390_r15);
s390_aghi (buf, STK_BASE, -CREATE_STACK_SIZE);
s390_stg (buf, s390_r11, 0, STK_BASE, 0);
/*---------------------------------------------------------------*/
/* Save general and floating point registers */
/*---------------------------------------------------------------*/
- s390_stmg (buf, s390_r2, s390_r12, s390_r13,
- G_STRUCT_OFFSET(MonoLMF, gregs[2]));
- for (i = 0; i < 16; i++) {
- s390_std (buf, i, 0, s390_r13,
- G_STRUCT_OFFSET(MonoLMF, fregs[i]));
- }
+ s390_mvc (buf, 4*sizeof(gulong), s390_r13, G_STRUCT_OFFSET(MonoLMF, gregs[2]),
+ STK_BASE, CREATE_GR_OFFSET);
+ s390_mvc (buf, 10*sizeof(gulong), s390_r13, G_STRUCT_OFFSET(MonoLMF, gregs[6]),
+ s390_r11, S390_REG_SAVE_OFFSET);
+
+ /* Simply copy fpregs already saved above */
+ s390_mvc (buf, 16*sizeof(double), s390_r13, G_STRUCT_OFFSET(MonoLMF, fregs[0]),
+ STK_BASE, CREATE_FP_OFFSET);
/*---------------------------------------------------------------*/
/* STEP 2: call the C trampoline function */
/* Set arguments */
/* Arg 1: mgreg_t *regs. We pass sp instead */
- s390_lgr (buf, s390_r2, STK_BASE);
- s390_ahi (buf, s390_r2, CREATE_STACK_SIZE);
+ s390_la (buf, s390_r2, 0, STK_BASE, CREATE_STACK_SIZE);
/* Arg 2: code (next address to the instruction that called us) */
if (tramp_type == MONO_TRAMPOLINE_JUMP) {
/*------------------------------------------------------------------*/
/* */
-/* Name - mono_arch_create_specific_trampoline */
+/* Name - mono_arch_create_specific_trampoline */
/* */
-/* Function - Creates the given kind of specific trampoline */
+/* Function - Creates the given kind of specific trampoline */
/* */
/*------------------------------------------------------------------*/
/*========================= End of Function ========================*/
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_create_rgctx_lazy_fetch_trampoline */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
gpointer
mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 encoded_offset)
{
/* FIXME: implement! */
g_assert_not_reached ();
return NULL;
-}
+}
+
+/*========================= End of Function ========================*/