From f4d7a32173979ed14b1885cc5b22da5aa578ba09 Mon Sep 17 00:00:00 2001 From: neale Date: Tue, 29 Aug 2006 14:24:40 +0000 Subject: [PATCH] * mini-s390.c, mini-s390x.c: Fix VARARG case processing with 0 arguments. Add mono_arch_get_patch_offset as a dummy entry point to allow successful link. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mono@64511 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- mono/mini/ChangeLog | 6 +++ mono/mini/exceptions-s390x.c | 9 ++-- mono/mini/mini-s390.c | 101 ++++++++++++++++++++++++++++++++------ mono/mini/mini-s390x.c | 112 ++++++++++++++++++++++++++++++++++++------- 4 files changed, 193 insertions(+), 35 deletions(-) diff --git a/mono/mini/ChangeLog b/mono/mini/ChangeLog index fe8a17962..ee09a9114 100644 --- a/mono/mini/ChangeLog +++ b/mono/mini/ChangeLog @@ -1,3 +1,9 @@ +2006-08-29 Neale Ferguson + + * mini-s390.c, mini-s390x.c: Fix VARARG case processing with 0 arguments. Add + mono_arch_get_patch_offset as a dummy entry point to allow successful link. + + * exceptions-s390x.c: Cosmetic change. Wed Aug 23 19:24:00 CEST 2006 Paolo Molaro diff --git a/mono/mini/exceptions-s390x.c b/mono/mini/exceptions-s390x.c index 65dddc08a..b40b50ce8 100644 --- a/mono/mini/exceptions-s390x.c +++ b/mono/mini/exceptions-s390x.c @@ -426,7 +426,7 @@ mono_arch_get_throw_exception_by_name (void) /* */ /* Name - mono_arch_find_jit_info */ /* */ -/* Function - This function is used to gather informatoin from */ +/* Function - This function is used to gather information from */ /* @ctx. It returns the MonoJitInfo of the corres- */ /* ponding function, unwinds one stack frame and */ /* stores the resulting context into @new_ctx. It */ @@ -434,7 +434,7 @@ mono_arch_get_throw_exception_by_name (void) /* into @trace (if not NULL), and modifies the @lmf */ /* if necessary. @native_offset returns the IP off- */ /* set from the start of the function or -1 if that */ -/* informatoin is not available. */ +/* information is not available. */ /* */ /*------------------------------------------------------------------*/ @@ -458,8 +458,8 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, if (trace) *trace = NULL; - if (native_offset) - *native_offset = -1; +// if (native_offset) +// *native_offset = -1; if (managed) *managed = FALSE; @@ -489,6 +489,7 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, MONO_CONTEXT_SET_IP (new_ctx, sframe->return_address); memcpy (&new_ctx->uc_mcontext.gregs[6], sframe->regs, (8*sizeof(gint64))); return ji; + } else if (*lmf) { *new_ctx = *ctx; diff --git a/mono/mini/mini-s390.c b/mono/mini/mini-s390.c index 173870b96..d889f7119 100644 --- a/mono/mini/mini-s390.c +++ b/mono/mini/mini-s390.c @@ -221,6 +221,7 @@ typedef struct { typedef struct { int nargs; + int lastgr; guint32 stack_usage; guint32 struct_ret; ArgInfo ret; @@ -254,6 +255,7 @@ static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gbool static void mono_arch_break(void); gpointer mono_arch_get_lmf_addr (void); static guint8 * emit_load_volatile_registers(guint8 *, MonoCompile *); +static void emit_sig_cookie (MonoCompile *, MonoCallInst *, CallInfo *, int); /*========================= End of Prototypes ======================*/ @@ -1565,6 +1567,16 @@ enum_retvalue: } } + /*----------------------------------------------------------*/ + /* Handle the case where there are no implicit arguments */ + /*----------------------------------------------------------*/ + if ((sig->call_convention == MONO_CALL_VARARG) && + (sig->param_count == sig->sentinelpos)) { + gr = S390_LAST_ARG_REG + 1; + add_general (&gr, sz, &cinfo->sigCookie, TRUE); + } + + cinfo->lastgr = gr; sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size + sz->offset; sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long)); @@ -1828,20 +1840,7 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, 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_CALL_ARG (cfg, arg, OP_OUTARG_MEMBASE); - arg->ins.inst_left = sigArg; - arg->ins.inst_right = (MonoInst *) call; - arg->size = ainfo->size; - arg->offset = cinfo->sigCookie.offset; - call->used_iregs |= 1 << ainfo->reg; - arg->ins.next = call->out_args; - call->out_args = (MonoInst *) arg; + emit_sig_cookie (cfg, call, cinfo, ainfo->size); } if (is_virtual && i == 0) { @@ -1910,6 +1909,15 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, } } } + + /* + * Handle the case where there are no implicit arguments + */ + if ((sig->call_convention == MONO_CALL_VARARG) && + (i == sig->sentinelpos)) { + emit_sig_cookie (cfg, call, cinfo, ainfo->size); + } + /* * Reverse the call->out_args list. */ @@ -1932,6 +1940,53 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, /*------------------------------------------------------------------*/ /* */ +/* Name - emit_sig_cookie. */ +/* */ +/* Function - For variable length parameter lists construct a */ +/* signature cookie and emit it. */ +/* */ +/*------------------------------------------------------------------*/ + +static void +emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, + CallInfo *cinfo, int argSize) +{ + MonoCallArgParm *arg; + MonoMethodSignature *tmpSig; + MonoInst *sigArg; + + cfg->disable_aot = TRUE; + + /*----------------------------------------------------------*/ + /* mono_ArgIterator_Setup assumes the signature cookie is */ + /* passed first and all the arguments which were before it */ + /* passed on the stack after the signature. So compensate */ + /* by passing a different signature. */ + /*----------------------------------------------------------*/ + tmpSig = mono_metadata_signature_dup (call->signature); + tmpSig->param_count -= call->signature->sentinelpos; + tmpSig->sentinelpos = 0; + if (tmpSig->param_count > 0) + memcpy (tmpSig->params, + call->signature->params + call->signature->sentinelpos, + tmpSig->param_count * sizeof(MonoType *)); + + MONO_INST_NEW (cfg, sigArg, OP_ICONST); + sigArg->inst_p0 = tmpSig; + + MONO_INST_NEW_CALL_ARG (cfg, arg, OP_OUTARG_MEMBASE); + arg->ins.inst_left = sigArg; + arg->ins.inst_right = (MonoInst *) call; + arg->size = argSize; + arg->offset = cinfo->sigCookie.offset; + arg->ins.next = call->out_args; + call->out_args = (MonoInst *) arg; +} + +/*========================= End of Function ========================*/ + +/*------------------------------------------------------------------*/ +/* */ /* Name - mono_arch_instrument_mem_needs */ /* */ /* Function - Allow tracing to work with this interface (with */ @@ -4974,3 +5029,21 @@ mono_arch_get_lmf_addr (void) /*========================= End of Function ========================*/ + +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_get_patch_offset */ +/* */ +/* Function - Dummy entry point until s390x supports aot. */ +/* */ +/* Returns - Offset for patch. */ +/* */ +/*------------------------------------------------------------------*/ + +guint32 +mono_arch_get_patch_offset (guint8 *code) +{ + return 0; +} + +/*========================= End of Function ========================*/ diff --git a/mono/mini/mini-s390x.c b/mono/mini/mini-s390x.c index ea8084d42..7244e9aef 100644 --- a/mono/mini/mini-s390x.c +++ b/mono/mini/mini-s390x.c @@ -262,6 +262,7 @@ typedef struct { typedef struct { int nargs; + int lastgr; guint32 stack_usage; guint32 struct_ret; ArgInfo ret; @@ -297,6 +298,7 @@ gpointer mono_arch_get_lmf_addr (void); static guint8 * emit_load_volatile_registers (guint8 *, MonoCompile *); static CompRelation opcode_to_cond (int); static void catch_SIGILL(int, siginfo_t *, void *); +static void emit_sig_cookie (MonoCompile *, MonoCallInst *, CallInfo *, int); /*========================= End of Prototypes ======================*/ @@ -556,7 +558,7 @@ enum_parmtype: printf ("[BOOL:%ld], ", *((gint64 *) curParm)); break; case MONO_TYPE_CHAR : - printf ("[CHAR:%c], ", *((gint64 *) curParm)); + printf ("[CHAR:%c], ", *((int *) curParm)); break; case MONO_TYPE_I1 : printf ("[INT1:%ld], ", *((gint64 *) curParm)); @@ -599,7 +601,7 @@ enum_parmtype: printf("%p [%p] ",obj,curParm); if (class == mono_defaults.string_class) { printf("[STRING:%p:%s]", - obj, mono_string_to_utf8 (obj)); + obj, mono_string_to_utf8 ((MonoString *) obj)); } else if (class == mono_defaults.int32_class) { printf("[INT32:%p:%d]", obj, *(gint32 *)((char *)obj + sizeof (MonoObject))); @@ -1599,6 +1601,15 @@ enum_retvalue: } /*----------------------------------------------------------*/ + /* Handle the case where there are no implicit arguments */ + /*----------------------------------------------------------*/ + if ((sig->call_convention == MONO_CALL_VARARG) && + (sig->param_count == sig->sentinelpos)) { + gr = S390_LAST_ARG_REG + 1; + add_general (&gr, sz, &cinfo->sigCookie); + } + + /*----------------------------------------------------------*/ /* If we are passing a structure back then if it won't be */ /* in a register(s) then we make room at the end of the */ /* parameters that may have been placed on the stack */ @@ -1617,6 +1628,7 @@ enum_retvalue: } } + cinfo->lastgr = gr; sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size + sz->offset; sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long)); @@ -1876,22 +1888,10 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, for (i = 0; i < n; ++i) { ainfo = cinfo->args + i; - if ((sig->call_convention == MONO_CALL_VARARG) && + if (!(sig->pinvoke) && + (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_CALL_ARG (cfg, arg, OP_OUTARG_MEMBASE); - arg->ins.inst_left = sigArg; - arg->ins.inst_right = (MonoInst *) call; - arg->size = ainfo->size; - arg->offset = cinfo->sigCookie.offset; - call->used_iregs |= 1 << ainfo->reg; - arg->ins.next = call->out_args; - call->out_args = (MonoInst *) arg; + emit_sig_cookie (cfg, call, cinfo, ainfo->size); } if (is_virtual && i == 0) { @@ -1904,6 +1904,7 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, arg->ins.cil_code = in->cil_code; arg->ins.inst_left = in; arg->ins.type = in->type; + /* prepend, we'll need to reverse them later */ arg->ins.next = call->out_args; call->out_args = (MonoInst *) arg; @@ -1944,6 +1945,16 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, } } } + + /* + * Handle the case where there are no implicit arguments + */ + if (!(sig->pinvoke) && + (sig->call_convention == MONO_CALL_VARARG) && + (n == sig->sentinelpos)) { + emit_sig_cookie (cfg, call, cinfo, sizeof(MonoType *)); + } + /* * Reverse the call->out_args list. */ @@ -1966,6 +1977,55 @@ mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb, /*------------------------------------------------------------------*/ /* */ +/* Name - emit_sig_cookie. */ +/* */ +/* Function - For variable length parameter lists construct a */ +/* signature cookie and emit it. */ +/* */ +/*------------------------------------------------------------------*/ + +static void +emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, + CallInfo *cinfo, int argSize) +{ + MonoCallArgParm *arg; + MonoMethodSignature *tmpSig; + MonoInst *sigArg; + + cfg->disable_aot = TRUE; + + /*----------------------------------------------------------*/ + /* mono_ArgIterator_Setup assumes the signature cookie is */ + /* passed first and all the arguments which were before it */ + /* passed on the stack after the signature. So compensate */ + /* by passing a different signature. */ + /*----------------------------------------------------------*/ + tmpSig = mono_metadata_signature_dup (call->signature); + tmpSig->param_count -= call->signature->sentinelpos; + tmpSig->sentinelpos = 0; + if (tmpSig->param_count > 0) + memcpy (tmpSig->params, + call->signature->params + call->signature->sentinelpos, + tmpSig->param_count * sizeof(MonoType *)); + + MONO_INST_NEW (cfg, sigArg, OP_ICONST); + sigArg->inst_p0 = tmpSig; + + MONO_INST_NEW_CALL_ARG (cfg, arg, OP_OUTARG_MEMBASE); + arg->ins.inst_left = sigArg; + arg->ins.inst_right = (MonoInst *) call; + arg->size = argSize; + arg->offset = cinfo->sigCookie.offset; + + /* prepend, we'll need to reverse them later */ + arg->ins.next = call->out_args; + call->out_args = (MonoInst *) arg; +} + +/*========================= End of Function ========================*/ + +/*------------------------------------------------------------------*/ +/* */ /* Name - mono_arch_instrument_mem_needs */ /* */ /* Function - Allow tracing to work with this interface (with */ @@ -5332,3 +5392,21 @@ opcode_to_cond (int opcode) } /*========================= End of Function ========================*/ + +/*------------------------------------------------------------------*/ +/* */ +/* Name - mono_arch_get_patch_offset */ +/* */ +/* Function - Dummy entry point until s390x supports aot. */ +/* */ +/* Returns - Offset for patch. */ +/* */ +/*------------------------------------------------------------------*/ + +guint32 +mono_arch_get_patch_offset (guint8 *code) +{ + return 0; +} + +/*========================= End of Function ========================*/ -- 2.11.4.GIT