1 /*------------------------------------------------------------------*/
3 /* Name - mini-s390.c */
5 /* Function - S/390 backend for the Mono code generator. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 #define MAX_ARCH_DELEGATE_PARAMS 7
23 #define EMIT_COND_BRANCH(ins,cond) \
25 if (ins->inst_true_bb->native_offset) { \
27 displace = ((cfg->native_code + \
28 ins->inst_true_bb->native_offset) - code) / 2; \
29 if (s390_is_imm16(displace)) { \
30 s390_brc (code, cond, displace); \
32 s390_jcl (code, cond, displace); \
35 mono_add_patch_info (cfg, code - cfg->native_code, \
36 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
37 s390_jcl (code, cond, 0); \
41 #define EMIT_UNCOND_BRANCH(ins) \
43 if (ins->inst_target_bb->native_offset) { \
45 displace = ((cfg->native_code + \
46 ins->inst_target_bb->native_offset) - code) / 2; \
47 if (s390_is_imm16(displace)) { \
48 s390_brc (code, S390_CC_UN, displace); \
50 s390_jcl (code, S390_CC_UN, displace); \
53 mono_add_patch_info (cfg, code - cfg->native_code, \
54 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
55 s390_jcl (code, S390_CC_UN, 0); \
59 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
61 mono_add_patch_info (cfg, code - cfg->native_code, \
62 MONO_PATCH_INFO_EXC, exc_name); \
63 s390_jcl (code, cond, 0); \
66 #define CHECK_SRCDST_COM \
67 if (ins->dreg == ins->sreg2) { \
71 if (ins->dreg != ins->sreg1) { \
72 s390_lgr (code, ins->dreg, ins->sreg1); \
76 #define CHECK_SRCDST_NCOM \
77 if (ins->dreg == ins->sreg2) { \
79 s390_lgr (code, s390_r13, ins->sreg2); \
83 if (ins->dreg != ins->sreg1) { \
84 s390_lgr (code, ins->dreg, ins->sreg1); \
87 #define CHECK_SRCDST_COM_I \
88 if (ins->dreg == ins->sreg2) { \
92 if (ins->dreg != ins->sreg1) { \
93 s390_lgfr (code, ins->dreg, ins->sreg1); \
97 #define CHECK_SRCDST_NCOM_I \
98 if (ins->dreg == ins->sreg2) { \
100 s390_lgfr (code, s390_r13, ins->sreg2); \
104 if (ins->dreg != ins->sreg1) { \
105 s390_lgfr (code, ins->dreg, ins->sreg1); \
108 #define CHECK_SRCDST_COM_F \
109 if (ins->dreg == ins->sreg2) { \
113 if (ins->dreg != ins->sreg1) { \
114 s390_ldr (code, ins->dreg, ins->sreg1); \
118 #define CHECK_SRCDST_NCOM_F \
119 if (ins->dreg == ins->sreg2) { \
121 s390_ldr (code, s390_r13, ins->sreg2); \
125 if (ins->dreg != ins->sreg1) { \
126 s390_ldr (code, ins->dreg, ins->sreg1); \
129 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
132 MONO_INST_NEW (cfg, inst, OP_NOP); \
135 inst->inst_offset = offset; \
137 inst->inst_imm = imm; \
139 if (s390_is_uimm12(offset)) { \
141 inst->inst_offset = offset; \
143 dReg = mono_alloc_preg (cfg); \
144 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
145 dReg, dest, offset); \
147 inst->inst_offset = 0; \
149 if (s390_is_uimm12(imm)) { \
151 inst->inst_imm = imm; \
153 sReg = mono_alloc_preg (cfg); \
154 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
156 inst->sreg1 = sReg; \
157 inst->inst_imm = 0; \
160 inst->opcode = OP_S390_MOVE; \
161 inst->backend.size = size; \
162 MONO_ADD_INS (cfg->cbb, inst); \
165 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
166 int reg = mono_alloc_preg (cfg); \
169 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
172 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
176 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
180 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
184 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
188 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
191 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
195 tmpr = mono_alloc_preg (cfg); \
196 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
197 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
201 tmpr = mono_alloc_preg (cfg); \
202 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
204 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
208 tmpr = mono_alloc_preg (cfg); \
209 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
211 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
215 tmpr = mono_alloc_preg (cfg); \
216 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
218 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
222 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
228 #define DEBUG(a) if (cfg->verbose_level > 1) a
232 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
234 #define MAX(a, b) ((a) > (b) ? (a) : (b))
237 * imt thunking size values
240 #define LOADCON_SIZE 20
244 #define ENABLE_WRONG_METHOD_CHECK 0
246 /*========================= End of Defines =========================*/
248 /*------------------------------------------------------------------*/
249 /* I n c l u d e s */
250 /*------------------------------------------------------------------*/
255 #include <mono/metadata/appdomain.h>
256 #include <mono/metadata/debug-helpers.h>
257 #include <mono/metadata/profiler-private.h>
258 #include <mono/utils/mono-math.h>
260 #include "mini-s390x.h"
261 #include "cpu-s390x.h"
262 #include "jit-icalls.h"
265 /*========================= End of Includes ========================*/
267 /*------------------------------------------------------------------*/
268 /* T y p e d e f s */
269 /*------------------------------------------------------------------*/
281 /*------------------------------------------------------------------*/
282 /* Used by the instrument_emit_epilog */
283 /*------------------------------------------------------------------*/
294 typedef struct InstList InstList;
308 RegTypeStructByValInFP,
310 RegTypeStructByAddrOnStack
314 gint32 offset; /* offset from caller's stack */
315 gint32 offparm; /* offset from callee's stack */
316 guint16 vtsize; /* in param area */
319 guint32 size; /* Size of structure used by RegTypeStructByVal */
320 gint32 type; /* Data type of argument */
336 gint64 gr[5]; /* R2-R6 */
337 gdouble fp[3]; /* F0-F2 */
338 } __attribute__ ((packed)) RegParm;
340 /*========================= End of Typedefs ========================*/
342 /*------------------------------------------------------------------*/
343 /* P r o t o t y p e s */
344 /*------------------------------------------------------------------*/
346 static void indent (int);
347 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
348 static void decodeParm (MonoType *, void *, int);
349 static void enter_method (MonoMethod *, RegParm *, char *);
350 static void leave_method (MonoMethod *, ...);
351 static gboolean is_regsize_var (MonoType *);
352 static inline void add_general (guint *, size_data *, ArgInfo *);
353 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
354 static inline void add_float (guint *, size_data *, ArgInfo *);
355 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
356 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
357 gpointer mono_arch_get_lmf_addr (void);
358 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
359 static void catch_SIGILL(int, siginfo_t *, void *);
361 /*========================= End of Prototypes ======================*/
363 /*------------------------------------------------------------------*/
364 /* G l o b a l V a r i a b l e s */
365 /*------------------------------------------------------------------*/
367 int mono_exc_esp_offset = 0;
369 static int indent_level = 0;
373 static gboolean tls_offset_inited = FALSE;
375 static int appdomain_tls_offset = -1,
376 thread_tls_offset = -1;
378 pthread_key_t lmf_addr_key;
380 gboolean lmf_addr_key_inited = FALSE;
386 extern __thread MonoDomain *tls_appdomain;
387 extern __thread MonoThread *tls_current_object;
388 extern __thread gpointer mono_lmf_addr;
392 /*====================== End of Global Variables ===================*/
394 /*------------------------------------------------------------------*/
396 /* Name - mono_arch_regname */
398 /* Function - Returns the name of the register specified by */
399 /* the input parameter. */
401 /*------------------------------------------------------------------*/
404 mono_arch_regname (int reg) {
405 static const char * rnames[] = {
406 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
407 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
408 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
412 if (reg >= 0 && reg < 16)
418 /*========================= End of Function ========================*/
420 /*------------------------------------------------------------------*/
422 /* Name - mono_arch_fregname */
424 /* Function - Returns the name of the register specified by */
425 /* the input parameter. */
427 /*------------------------------------------------------------------*/
430 mono_arch_fregname (int reg) {
431 static const char * rnames[] = {
432 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
433 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
434 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
438 if (reg >= 0 && reg < 16)
444 /*========================= End of Function ========================*/
446 /*------------------------------------------------------------------*/
448 /* Name - arch_get_argument_info */
450 /* Function - Gathers information on parameters such as size, */
451 /* alignment, and padding. arg_info should be large */
452 /* enough to hold param_count + 1 entries. */
454 /* Parameters - @csig - Method signature */
455 /* @param_count - No. of parameters to consider */
456 /* @arg_info - An array to store the result info */
458 /* Returns - Size of the activation frame */
460 /*------------------------------------------------------------------*/
463 mono_arch_get_argument_info (MonoMethodSignature *csig,
465 MonoJitArgumentInfo *arg_info)
467 int k, frame_size = 0;
468 int size, align, pad;
471 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
472 frame_size += sizeof (gpointer);
476 arg_info [0].offset = offset;
479 frame_size += sizeof (gpointer);
483 arg_info [0].size = frame_size;
485 for (k = 0; k < param_count; k++) {
488 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
490 size = mini_type_stack_size (NULL, csig->params [k], &align);
492 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
493 arg_info [k].pad = pad;
495 arg_info [k + 1].pad = 0;
496 arg_info [k + 1].size = size;
498 arg_info [k + 1].offset = offset;
502 align = MONO_ARCH_FRAME_ALIGNMENT;
503 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
504 arg_info [k].pad = pad;
509 /*========================= End of Function ========================*/
511 /*------------------------------------------------------------------*/
513 /* Name - retFitsInReg. */
515 /* Function - Determines if a value can be returned in one or */
518 /*------------------------------------------------------------------*/
520 static inline gboolean
521 retFitsInReg(guint32 size)
536 /*========================= End of Function ========================*/
538 /*------------------------------------------------------------------*/
540 /* Name - backStackPtr. */
542 /* Function - Restore Stack Pointer to previous frame. */
544 /*------------------------------------------------------------------*/
546 static inline guint8 *
547 backUpStackPtr(MonoCompile *cfg, guint8 *code)
549 int stackSize = cfg->stack_usage;
551 if (s390_is_imm16 (stackSize)) {
552 s390_aghi (code, STK_BASE, stackSize);
554 while (stackSize > 32767) {
555 s390_aghi (code, STK_BASE, 32767);
558 s390_aghi (code, STK_BASE, stackSize);
563 /*========================= End of Function ========================*/
565 /*------------------------------------------------------------------*/
569 /* Function - Perform nice indenting to current level */
571 /*------------------------------------------------------------------*/
577 indent_level += diff;
584 indent_level += diff;
587 /*========================= End of Function ========================*/
589 /*------------------------------------------------------------------*/
591 /* Name - decodeParm */
593 /* Function - Decode a parameter for the trace. */
595 /*------------------------------------------------------------------*/
598 decodeParm(MonoType *type, void *curParm, int size)
603 printf("[BYREF:%p], ", *((char **) curParm));
605 simpleType = mono_type_get_underlying_type(type)->type;
607 switch (simpleType) {
609 printf ("[INTPTR:%p], ", *((int **) curParm));
612 printf ("[UINTPTR:%p], ", *((int **) curParm));
614 case MONO_TYPE_BOOLEAN :
615 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
617 case MONO_TYPE_CHAR :
618 printf ("[CHAR:%c], ", *((int *) curParm));
621 printf ("[INT1:%ld], ", *((gint64 *) curParm));
624 printf ("[INT2:%ld], ", *((gint64 *) curParm));
627 printf ("[INT4:%ld], ", *((gint64 *) curParm));
630 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
633 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
636 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
639 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
641 case MONO_TYPE_STRING : {
642 MonoString *s = *((MonoString **) curParm);
644 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
645 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
647 printf("[STRING:null], ");
651 case MONO_TYPE_CLASS :
652 case MONO_TYPE_OBJECT : {
653 MonoObject *obj = *((MonoObject **) curParm);
655 if ((obj) && (obj->vtable)) {
656 printf("[CLASS/OBJ:");
657 class = obj->vtable->klass;
658 printf("%p [%p] ",obj,curParm);
659 if (class == mono_defaults.string_class) {
660 printf("[STRING:%p:%s]",
661 obj, mono_string_to_utf8 ((MonoString *) obj));
662 } else if (class == mono_defaults.int32_class) {
663 printf("[INT32:%p:%d]",
664 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
667 class->name_space, class->name, obj);
670 printf("[OBJECT:null], ");
675 printf("[PTR:%p], ", *((gpointer **) (curParm)));
677 case MONO_TYPE_FNPTR :
678 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
680 case MONO_TYPE_ARRAY :
681 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
683 case MONO_TYPE_SZARRAY :
684 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
687 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
690 printf("[FLOAT4:%g], ", *((float *) (curParm)));
693 printf("[FLOAT8:%g], ", *((double *) (curParm)));
695 case MONO_TYPE_VALUETYPE : {
697 MonoMarshalType *info;
699 if (type->data.klass->enumtype) {
700 simpleType = mono_class_enum_basetype (type->data.klass)->type;
701 printf("{VALUETYPE} - ");
705 info = mono_marshal_load_type_info (type->data.klass);
707 if ((info->native_size == sizeof(float)) &&
708 (info->num_fields == 1) &&
709 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
710 printf("[FLOAT4:%f], ", *((float *) (curParm)));
714 if ((info->native_size == sizeof(double)) &&
715 (info->num_fields == 1) &&
716 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
717 printf("[FLOAT8:%g], ", *((double *) (curParm)));
721 printf("[VALUETYPE:");
722 for (i = 0; i < size; i++)
723 printf("%02x,", *((guint8 *)curParm+i));
727 case MONO_TYPE_TYPEDBYREF: {
729 printf("[TYPEDBYREF:");
730 for (i = 0; i < size; i++)
731 printf("%02x,", *((guint8 *)curParm+i));
736 printf("[?? - %d], ",simpleType);
741 /*========================= End of Function ========================*/
743 /*------------------------------------------------------------------*/
745 /* Name - enter_method */
747 /* Function - Perform tracing of the entry to the current */
750 /*------------------------------------------------------------------*/
753 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
755 int i, oParm = 0, iParm = 0;
758 MonoMethodSignature *sig;
765 fname = mono_method_full_name (method, TRUE);
767 printf ("ENTER: %s ", fname);
770 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
771 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
776 sig = mono_method_signature (method);
778 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
780 if (cinfo->struct_ret) {
781 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
786 gpointer *this = (gpointer *) rParm->gr[iParm];
787 obj = (MonoObject *) this;
788 if (method->klass->valuetype) {
790 printf("this:[value:%p:%016lx], ",
791 this, *((guint64 *)(this+sizeof(MonoObject))));
793 printf ("this:[NULL], ");
796 class = obj->vtable->klass;
797 if (class == mono_defaults.string_class) {
798 printf ("this:[STRING:%p:%s], ",
799 obj, mono_string_to_utf8 ((MonoString *)obj));
801 printf ("this:%p[%s.%s], ",
802 obj, class->name_space, class->name);
805 printf ("this:NULL, ");
810 for (i = 0; i < sig->param_count; ++i) {
811 ainfo = &cinfo->args[i + oParm];
812 switch (ainfo->regtype) {
813 case RegTypeGeneral :
814 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
817 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
820 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
822 case RegTypeStructByVal :
823 if (ainfo->reg != STK_BASE) {
824 int offset = sizeof(glong) - ainfo->size;
825 curParm = &(rParm->gr[ainfo->reg-2])+offset;
828 curParm = sp+ainfo->offset;
830 if (retFitsInReg (ainfo->vtsize))
831 decodeParm(sig->params[i],
835 decodeParm(sig->params[i],
836 *((char **) curParm),
839 case RegTypeStructByAddr :
840 if (ainfo->reg != STK_BASE)
841 curParm = &(rParm->gr[ainfo->reg-2]);
843 curParm = sp+ainfo->offset;
845 decodeParm(sig->params[i],
846 *((char **) curParm),
858 /*========================= End of Function ========================*/
860 /*------------------------------------------------------------------*/
862 /* Name - leave_method */
866 /*------------------------------------------------------------------*/
869 leave_method (MonoMethod *method, ...)
876 va_start(ap, method);
878 fname = mono_method_full_name (method, TRUE);
880 printf ("LEAVE: %s", fname);
883 type = mono_method_signature (method)->ret;
886 switch (type->type) {
889 case MONO_TYPE_BOOLEAN: {
890 int val = va_arg (ap, int);
892 printf ("[TRUE:%d]", val);
898 case MONO_TYPE_CHAR: {
899 int val = va_arg (ap, int);
900 printf ("[CHAR:%d]", val);
904 int val = va_arg (ap, int);
905 printf ("[INT1:%d]", val);
909 int val = va_arg (ap, int);
910 printf ("[UINT1:%d]", val);
914 int val = va_arg (ap, int);
915 printf ("[INT2:%d]", val);
919 int val = va_arg (ap, int);
920 printf ("[UINT2:%d]", val);
924 int val = va_arg (ap, int);
925 printf ("[INT4:%d]", val);
929 int val = va_arg (ap, int);
930 printf ("[UINT4:%d]", val);
934 gint64 val = va_arg (ap, gint64);
935 printf ("[INT:%ld]", val);
940 gint64 val = va_arg (ap, gint64);
941 printf ("[UINT:%lu]", val);
945 case MONO_TYPE_STRING: {
946 MonoString *s = va_arg (ap, MonoString *);
949 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
950 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
952 printf ("[STRING:null], ");
955 case MONO_TYPE_CLASS:
956 case MONO_TYPE_OBJECT: {
957 MonoObject *o = va_arg (ap, MonoObject *);
959 if ((o) && (o->vtable)) {
960 if (o->vtable->klass == mono_defaults.boolean_class) {
961 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
962 } else if (o->vtable->klass == mono_defaults.int32_class) {
963 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
964 } else if (o->vtable->klass == mono_defaults.int64_class) {
965 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
967 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
969 printf ("[OBJECT:%p]", o);
974 case MONO_TYPE_FNPTR:
975 case MONO_TYPE_ARRAY:
976 case MONO_TYPE_SZARRAY: {
977 gpointer p = va_arg (ap, gpointer);
978 printf ("[result=%p]", p);
982 gint64 l = va_arg (ap, gint64);
983 printf ("[LONG:%ld]", l);
987 guint64 l = va_arg (ap, guint64);
988 printf ("[ULONG:%lu]", l);
992 double f = va_arg (ap, double);
993 printf ("[FLOAT4:%g]\n", f);
997 double f = va_arg (ap, double);
998 printf ("[FLOAT8:%g]\n", f);
1001 case MONO_TYPE_VALUETYPE: {
1002 MonoMarshalType *info;
1003 if (type->data.klass->enumtype) {
1004 type = mono_class_enum_basetype (type->data.klass);
1009 info = mono_marshal_load_type_info (type->data.klass);
1011 if ((info->native_size == sizeof(float)) &&
1012 (info->num_fields == 1) &&
1013 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1014 double f = va_arg (ap, double);
1015 printf("[FLOAT4:%g]\n", (double) f);
1019 if ((info->native_size == sizeof(double)) &&
1020 (info->num_fields == 1) &&
1021 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1022 double f = va_arg (ap, double);
1023 printf("[FLOAT8:%g]\n", f);
1027 size = mono_type_size (type, &align);
1030 guint32 p = va_arg (ap, guint32);
1031 printf ("[%02x]\n",p);
1035 guint32 p = va_arg (ap, guint32);
1036 printf ("[%04x]\n",p);
1040 guint32 p = va_arg (ap, guint32);
1041 printf ("[%08x]\n",p);
1045 guint64 p = va_arg (ap, guint64);
1046 printf ("[%016lx]\n",p);
1050 gpointer p = va_arg (ap, gpointer);
1051 printf ("[VALUETYPE] %p\n",p);
1057 case MONO_TYPE_TYPEDBYREF: {
1058 guint8 *p = va_arg (ap, gpointer);
1060 size = mono_type_size (type, &align);
1067 for (j = 0; p && j < size; j++)
1068 printf ("%02x,", p [j]);
1072 printf ("[TYPEDBYREF]\n");
1077 printf ("(unknown return type %x)",
1078 mono_method_signature (method)->ret->type);
1081 ip = ((gint64) __builtin_return_address (0));
1082 printf (" ip: %p\n", (gpointer) ip);
1085 /*========================= End of Function ========================*/
1087 /*------------------------------------------------------------------*/
1089 /* Name - catch_SIGILL */
1091 /* Function - Catch SIGILL as a result of testing for long */
1092 /* displacement facility. */
1094 /*------------------------------------------------------------------*/
1097 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1103 /*========================= End of Function ========================*/
1105 /*------------------------------------------------------------------*/
1107 /* Name - mono_arch_cpu_init */
1109 /* Function - Perform CPU specific initialization to execute */
1112 /*------------------------------------------------------------------*/
1115 mono_arch_cpu_init (void)
1117 struct sigaction sa,
1121 /*--------------------------------------*/
1122 /* Set default rounding mode for FP */
1123 /*--------------------------------------*/
1124 __asm__ ("SRNM\t%0\n\t"
1127 /*--------------------------------------*/
1128 /* Determine if we have long displace- */
1129 /* ment facility on this processor */
1130 /*--------------------------------------*/
1131 sa.sa_sigaction = catch_SIGILL;
1132 sigemptyset (&sa.sa_mask);
1133 sa.sa_flags = SA_SIGINFO;
1135 sigaction (SIGILL, &sa, oldSa);
1137 /*--------------------------------------*/
1138 /* We test by executing the STY inst */
1139 /*--------------------------------------*/
1140 __asm__ ("LGHI\t0,1\n\t"
1142 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1143 : "=m" (has_ld) : : "0", "1");
1145 sigaction (SIGILL, oldSa, NULL);
1148 /*========================= End of Function ========================*/
1150 /*------------------------------------------------------------------*/
1152 /* Name - mono_arch_init. */
1154 /* Function - Initialize architecture specific code. */
1156 /*------------------------------------------------------------------*/
1159 mono_arch_init (void)
1163 * When we do an architectural level set at z9 or better
1164 * we can use the STFLE instruction to show us
1165 * what hardware facilities are available
1167 int lFacility = sizeof(facs) % 8;
1169 memset((char *) &facs, 0, sizeof(facs));
1171 __asm__ (" lgfr 0,%1\n"
1173 : "=m" (facs) : "r" (lFacility) : "0", "cc");
1178 /*========================= End of Function ========================*/
1180 /*------------------------------------------------------------------*/
1182 /* Name - mono_arch_cleanup. */
1184 /* Function - Cleanup architecture specific code . */
1186 /*------------------------------------------------------------------*/
1189 mono_arch_cleanup (void)
1193 /*========================= End of Function ========================*/
1195 /*------------------------------------------------------------------*/
1197 /* Name - mono_arch_cpu_optimizazions */
1199 /* Function - Returns the optimizations supported on this CPU */
1201 /*------------------------------------------------------------------*/
1204 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1208 /*----------------------------------------------------------*/
1209 /* No s390-specific optimizations yet */
1210 /*----------------------------------------------------------*/
1211 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1212 // *exclude_mask = MONO_OPT_INLINE;
1216 /*========================= End of Function ========================*/
1218 /*------------------------------------------------------------------*/
1224 /*------------------------------------------------------------------*/
1227 is_regsize_var (MonoType *t) {
1230 switch (mono_type_get_underlying_type (t)->type) {
1238 case MONO_TYPE_FNPTR:
1240 case MONO_TYPE_OBJECT:
1241 case MONO_TYPE_STRING:
1242 case MONO_TYPE_CLASS:
1243 case MONO_TYPE_SZARRAY:
1244 case MONO_TYPE_ARRAY:
1246 case MONO_TYPE_VALUETYPE:
1247 if (t->data.klass->enumtype)
1248 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1254 /*========================= End of Function ========================*/
1256 /*------------------------------------------------------------------*/
1258 /* Name - mono_arch_get_allocatable_int_vars */
1262 /*------------------------------------------------------------------*/
1265 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1270 for (i = 0; i < cfg->num_varinfo; i++) {
1271 MonoInst *ins = cfg->varinfo [i];
1272 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1275 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1278 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1279 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1282 /* we can only allocate 32 bit values */
1283 if (is_regsize_var (ins->inst_vtype)) {
1284 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1285 g_assert (i == vmv->idx);
1286 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1293 /*========================= End of Function ========================*/
1295 /*------------------------------------------------------------------*/
1297 /* Name - mono_arch_global_int_regs */
1299 /* Function - Return a list of usable integer registers. */
1301 /*------------------------------------------------------------------*/
1304 mono_arch_get_global_int_regs (MonoCompile *cfg)
1307 MonoMethodHeader *header;
1310 header = cfg->header;
1311 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1312 cfg->frame_reg = s390_r11;
1315 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1317 for (i = 8; i < top; ++i) {
1318 if (cfg->frame_reg != i)
1319 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1325 /*========================= End of Function ========================*/
1327 /*------------------------------------------------------------------*/
1329 /* Name - mono_arch_flush_icache */
1331 /* Function - Flush the CPU icache. */
1333 /*------------------------------------------------------------------*/
1336 mono_arch_flush_icache (guint8 *code, gint size)
1340 /*========================= End of Function ========================*/
1342 /*------------------------------------------------------------------*/
1344 /* Name - add_general */
1346 /* Function - Determine code and stack size incremements for a */
1349 /*------------------------------------------------------------------*/
1352 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1354 if (*gr > S390_LAST_ARG_REG) {
1355 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1356 ainfo->offset = sz->stack_size;
1357 ainfo->reg = STK_BASE;
1358 ainfo->regtype = RegTypeBase;
1359 sz->stack_size += sizeof(long);
1360 sz->local_size += sizeof(long);
1361 sz->offStruct += sizeof(long);
1362 sz->code_size += 12;
1370 /*========================= End of Function ========================*/
1372 /*------------------------------------------------------------------*/
1374 /* Name - add_stackParm */
1376 /* Function - Determine code and stack size incremements for a */
1379 /*------------------------------------------------------------------*/
1382 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1384 if (*gr > S390_LAST_ARG_REG) {
1385 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1386 ainfo->reg = STK_BASE;
1387 ainfo->offset = sz->stack_size;
1388 ainfo->regtype = RegTypeStructByAddrOnStack;
1389 sz->stack_size += sizeof (gpointer);
1390 sz->parm_size += sizeof(gpointer);
1391 sz->offStruct += sizeof(gpointer);
1394 ainfo->offset = sz->stack_size;
1395 ainfo->regtype = RegTypeStructByAddr;
1398 ainfo->offparm = sz->offset;
1399 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1401 ainfo->vtsize = size;
1402 sz->parm_size += size;
1405 /*========================= End of Function ========================*/
1407 /*------------------------------------------------------------------*/
1409 /* Name - add_float */
1411 /* Function - Determine code and stack size incremements for a */
1412 /* float parameter. */
1414 /*------------------------------------------------------------------*/
1417 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1419 if ((*fr) <= S390_LAST_FPARG_REG) {
1420 ainfo->regtype = RegTypeFP;
1426 ainfo->offset = sz->stack_size;
1427 ainfo->reg = STK_BASE;
1428 ainfo->regtype = RegTypeBase;
1430 sz->stack_size += sizeof(double);
1431 sz->local_size += sizeof(double);
1432 sz->offStruct += sizeof(double);
1436 /*========================= End of Function ========================*/
1438 /*------------------------------------------------------------------*/
1440 /* Name - get_call_info */
1442 /* Function - Determine the amount of space required for code */
1443 /* and stack. In addition determine starting points */
1444 /* for stack-based parameters, and area for struct- */
1445 /* ures being returned on the stack. */
1447 /*------------------------------------------------------------------*/
1450 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1452 guint i, fr, gr, size, pstart;
1453 int nParm = sig->hasthis + sig->param_count;
1455 guint32 simpletype, align;
1458 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1461 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1463 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1468 cinfo->struct_ret = 0;
1472 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1473 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1478 /*----------------------------------------------------------*/
1479 /* We determine the size of the return code/stack in case we*/
1480 /* need to reserve a register to be used to address a stack */
1481 /* area that the callee will use. */
1482 /*----------------------------------------------------------*/
1484 ret_type = mono_type_get_underlying_type (sig->ret);
1485 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1486 simpletype = ret_type->type;
1488 switch (simpletype) {
1489 case MONO_TYPE_BOOLEAN:
1494 case MONO_TYPE_CHAR:
1499 case MONO_TYPE_CLASS:
1500 case MONO_TYPE_OBJECT:
1501 case MONO_TYPE_SZARRAY:
1502 case MONO_TYPE_ARRAY:
1504 case MONO_TYPE_FNPTR:
1505 case MONO_TYPE_STRING:
1506 cinfo->ret.reg = s390_r2;
1511 cinfo->ret.reg = s390_f0;
1516 cinfo->ret.reg = s390_r2;
1519 case MONO_TYPE_GENERICINST:
1520 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1521 cinfo->ret.reg = s390_r2;
1526 case MONO_TYPE_VALUETYPE: {
1527 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1528 if (klass->enumtype) {
1529 simpletype = mono_class_enum_basetype (klass)->type;
1533 size = mono_class_native_size (klass, &align);
1535 size = mono_class_value_size (klass, &align);
1537 cinfo->struct_ret = 1;
1538 cinfo->ret.size = size;
1539 cinfo->ret.vtsize = size;
1542 case MONO_TYPE_TYPEDBYREF:
1543 size = sizeof (MonoTypedRef);
1544 cinfo->struct_ret = 1;
1545 cinfo->ret.size = size;
1546 cinfo->ret.vtsize = size;
1548 case MONO_TYPE_VOID:
1551 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1557 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1558 * the first argument, allowing 'this' to be always passed in the first arg reg.
1559 * Also do this if the first argument is a reference type, since virtual calls
1560 * are sometimes made using calli without sig->hasthis set, like in the delegate
1563 if (cinfo->struct_ret && !is_pinvoke &&
1565 (sig->param_count > 0 &&
1566 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1568 cinfo->args[nParm].size = sizeof (gpointer);
1569 add_general (&gr, sz, cinfo->args + nParm);
1571 cinfo->args[nParm].size = sizeof (gpointer);
1572 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1576 cinfo->vret_arg_index = 1;
1577 cinfo->ret.reg = gr;
1582 cinfo->args[nParm].size = sizeof (gpointer);
1583 add_general (&gr, sz, cinfo->args + nParm);
1587 if (cinfo->struct_ret) {
1588 cinfo->ret.reg = gr;
1593 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1594 gr = S390_LAST_ARG_REG + 1;
1596 /* Emit the signature cookie just before the implicit arguments */
1597 add_general (&gr, sz, &cinfo->sigCookie);
1600 /*----------------------------------------------------------*/
1601 /* We determine the size of the parameter code and stack */
1602 /* requirements by checking the types and sizes of the */
1604 /*----------------------------------------------------------*/
1606 for (i = pstart; i < sig->param_count; ++i) {
1609 /*--------------------------------------------------*/
1610 /* Handle vararg type calls. All args are put on */
1612 /*--------------------------------------------------*/
1613 if ((sig->call_convention == MONO_CALL_VARARG) &&
1614 (i == sig->sentinelpos)) {
1615 gr = S390_LAST_ARG_REG + 1;
1616 add_general (&gr, sz, &cinfo->sigCookie);
1619 if (sig->params [i]->byref) {
1620 add_general (&gr, sz, cinfo->args+nParm);
1621 cinfo->args[nParm].size = sizeof(gpointer);
1626 ptype = mono_type_get_underlying_type (sig->params [i]);
1627 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1628 simpletype = ptype->type;
1629 cinfo->args[nParm].type = simpletype;
1630 switch (simpletype) {
1631 case MONO_TYPE_BOOLEAN:
1634 cinfo->args[nParm].size = sizeof(char);
1635 add_general (&gr, sz, cinfo->args+nParm);
1640 case MONO_TYPE_CHAR:
1641 cinfo->args[nParm].size = sizeof(short);
1642 add_general (&gr, sz, cinfo->args+nParm);
1647 cinfo->args[nParm].size = sizeof(int);
1648 add_general (&gr, sz, cinfo->args+nParm);
1654 case MONO_TYPE_FNPTR:
1655 case MONO_TYPE_CLASS:
1656 case MONO_TYPE_OBJECT:
1657 case MONO_TYPE_STRING:
1658 case MONO_TYPE_SZARRAY:
1659 case MONO_TYPE_ARRAY:
1660 cinfo->args[nParm].size = sizeof(gpointer);
1661 add_general (&gr, sz, cinfo->args+nParm);
1666 cinfo->args[nParm].size = sizeof(long long);
1667 add_general (&gr, sz, cinfo->args+nParm);
1671 cinfo->args[nParm].size = sizeof(float);
1672 add_float (&fr, sz, cinfo->args+nParm);
1676 cinfo->args[nParm].size = sizeof(double);
1677 add_float (&fr, sz, cinfo->args+nParm);
1680 case MONO_TYPE_GENERICINST:
1681 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1682 cinfo->args[nParm].size = sizeof(gpointer);
1683 add_general (&gr, sz, cinfo->args+nParm);
1688 case MONO_TYPE_VALUETYPE: {
1689 MonoMarshalType *info;
1690 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1692 size = mono_class_native_size (klass, &align);
1694 size = mono_class_value_size (klass, &align);
1696 info = mono_marshal_load_type_info (klass);
1698 if ((info->native_size == sizeof(float)) &&
1699 (info->num_fields == 1) &&
1700 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1701 cinfo->args[nParm].size = sizeof(float);
1702 add_float(&fr, sz, cinfo->args+nParm);
1707 if ((info->native_size == sizeof(double)) &&
1708 (info->num_fields == 1) &&
1709 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1710 cinfo->args[nParm].size = sizeof(double);
1711 add_float(&fr, sz, cinfo->args+nParm);
1716 cinfo->args[nParm].vtsize = 0;
1717 cinfo->args[nParm].size = 0;
1720 /*----------------------------------*/
1721 /* On S/390, structures of size 1, */
1722 /* 2, 4, and 8 bytes are passed in */
1723 /* (a) register(s). */
1724 /*----------------------------------*/
1730 add_general(&gr, sz, cinfo->args+nParm);
1731 cinfo->args[nParm].size = size;
1732 cinfo->args[nParm].regtype = RegTypeStructByVal;
1734 sz->local_size += sizeof(long);
1737 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1742 case MONO_TYPE_TYPEDBYREF: {
1743 int size = sizeof (MonoTypedRef);
1745 cinfo->args[nParm].vtsize = 0;
1746 cinfo->args[nParm].size = 0;
1749 /*----------------------------------*/
1750 /* On S/390, structures of size 1, */
1751 /* 2, 4, and 8 bytes are passed in */
1752 /* (a) register(s). */
1753 /*----------------------------------*/
1759 add_general(&gr, sz, cinfo->args+nParm);
1760 cinfo->args[nParm].size = size;
1761 cinfo->args[nParm].regtype = RegTypeStructByVal;
1763 sz->local_size += sizeof(long);
1766 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1772 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1776 /*----------------------------------------------------------*/
1777 /* Handle the case where there are no implicit arguments */
1778 /*----------------------------------------------------------*/
1779 if ((sig->call_convention == MONO_CALL_VARARG) &&
1782 (sig->param_count == sig->sentinelpos)) {
1783 gr = S390_LAST_ARG_REG + 1;
1784 add_general (&gr, sz, &cinfo->sigCookie);
1787 /*----------------------------------------------------------*/
1788 /* If we are passing a structure back then if it won't be */
1789 /* in a register(s) then we make room at the end of the */
1790 /* parameters that may have been placed on the stack */
1791 /*----------------------------------------------------------*/
1792 if (cinfo->struct_ret) {
1793 cinfo->ret.offset = sz->stack_size;
1794 switch (cinfo->ret.size) {
1802 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1807 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1809 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1814 /*========================= End of Function ========================*/
1816 /*------------------------------------------------------------------*/
1818 /* Name - mono_arch_allocate_vars */
1820 /* Function - Set var information according to the calling */
1821 /* convention for S/390. The local var stuff should */
1822 /* most likely be split in another method. */
1824 /* Parameter - @m - Compile unit. */
1826 /*------------------------------------------------------------------*/
1829 mono_arch_allocate_vars (MonoCompile *cfg)
1831 MonoMethodSignature *sig;
1832 MonoMethodHeader *header;
1835 int iParm, iVar, offset, align, size, curinst;
1836 int frame_reg = STK_BASE;
1839 header = cfg->header;
1841 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1843 /*---------------------------------------------------------*/
1844 /* We use the frame register also for any method that has */
1845 /* filter clauses. This way, when the handlers are called, */
1846 /* the code will reference local variables using the frame */
1847 /* reg instead of the stack pointer: if we had to restore */
1848 /* the stack pointer, we'd corrupt the method frames that */
1849 /* are already on the stack (since filters get called */
1850 /* before stack unwinding happens) when the filter code */
1851 /* would call any method. */
1852 /*---------------------------------------------------------*/
1853 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1854 frame_reg = s390_r11;
1856 cfg->frame_reg = frame_reg;
1858 cfg->arch.bkchain_reg = -1;
1860 if (frame_reg != STK_BASE)
1861 cfg->used_int_regs |= 1 << frame_reg;
1863 sig = mono_method_signature (cfg->method);
1865 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1867 if (!cinfo->struct_ret) {
1868 switch (mono_type_get_underlying_type (sig->ret)->type) {
1869 case MONO_TYPE_VOID:
1872 cfg->ret->opcode = OP_REGVAR;
1873 cfg->ret->dreg = s390_r2;
1878 /*--------------------------------------------------------------*/
1879 /* local vars are at a positive offset from the stack pointer */
1880 /* also note that if the function uses alloca, we use s390_r11 */
1881 /* to point at the local variables. */
1882 /* add parameter area size for called functions */
1883 /*--------------------------------------------------------------*/
1884 if (cfg->param_area == 0)
1885 offset = S390_MINIMAL_STACK_SIZE;
1887 offset = cfg->param_area;
1889 cfg->sig_cookie = 0;
1891 if (cinfo->struct_ret) {
1892 inst = cfg->vret_addr;
1893 offset = S390_ALIGN(offset, sizeof(gpointer));
1894 inst->inst_offset = offset;
1895 inst->opcode = OP_REGOFFSET;
1896 inst->inst_basereg = frame_reg;
1897 offset += sizeof(gpointer);
1898 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1899 printf ("vret_addr =");
1900 mono_print_ins (cfg->vret_addr);
1905 inst = cfg->args [0];
1906 if (inst->opcode != OP_REGVAR) {
1907 inst->opcode = OP_REGOFFSET;
1908 inst->inst_basereg = frame_reg;
1909 offset = S390_ALIGN(offset, sizeof(gpointer));
1910 inst->inst_offset = offset;
1911 offset += sizeof (gpointer);
1918 eArg = sig->param_count + sArg;
1920 if (sig->call_convention == MONO_CALL_VARARG)
1921 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1923 for (iParm = sArg; iParm < eArg; ++iParm) {
1924 inst = cfg->args [curinst];
1925 if (inst->opcode != OP_REGVAR) {
1926 switch (cinfo->args[iParm].regtype) {
1927 case RegTypeStructByAddr : {
1930 size = sizeof (gpointer);
1932 inst->opcode = OP_REGOFFSET;
1933 inst->inst_basereg = frame_reg;
1934 offset = S390_ALIGN (offset, sizeof (gpointer));
1935 inst->inst_offset = offset;
1937 /* Add a level of indirection */
1938 MONO_INST_NEW (cfg, indir, 0);
1940 inst->opcode = OP_VTARG_ADDR;
1941 inst->inst_left = indir;
1944 case RegTypeStructByAddrOnStack : {
1947 size = sizeof (gpointer);
1949 /* Similar to the == STK_BASE case below */
1950 cfg->arch.bkchain_reg = s390_r12;
1951 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1953 inst->opcode = OP_REGOFFSET;
1954 inst->dreg = mono_alloc_preg (cfg);
1955 inst->inst_basereg = cfg->arch.bkchain_reg;
1956 inst->inst_offset = cinfo->args [iParm].offset;
1958 /* Add a level of indirection */
1959 MONO_INST_NEW (cfg, indir, 0);
1961 inst->opcode = OP_VTARG_ADDR;
1962 inst->inst_left = indir;
1965 case RegTypeStructByVal :
1966 size = cinfo->args[iParm].size;
1967 offset = S390_ALIGN(offset, size);
1968 inst->opcode = OP_REGOFFSET;
1969 inst->inst_basereg = frame_reg;
1970 inst->inst_offset = offset;
1973 if (cinfo->args [iParm].reg == STK_BASE) {
1975 * These arguments are in the previous frame, so we can't
1976 * compute their offset from the current frame pointer right
1977 * now, since cfg->stack_offset is not yet known, so dedicate a
1978 * register holding the previous frame pointer.
1980 cfg->arch.bkchain_reg = s390_r12;
1981 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1983 inst->opcode = OP_REGOFFSET;
1984 inst->inst_basereg = cfg->arch.bkchain_reg;
1985 size = (cinfo->args[iParm].size < 8
1986 ? 8 - cinfo->args[iParm].size
1988 inst->inst_offset = cinfo->args [iParm].offset + size;
1989 size = sizeof (long);
1991 inst->opcode = OP_REGOFFSET;
1992 inst->inst_basereg = frame_reg;
1993 size = (cinfo->args[iParm].size < 8
1996 offset = S390_ALIGN(offset, size);
1997 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
1998 inst->inst_offset = offset;
2000 inst->inst_offset = offset + (8 - size);
2004 if ((sig->call_convention == MONO_CALL_VARARG) &&
2005 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2006 (iParm < sig->sentinelpos))
2007 cfg->sig_cookie += size;
2009 offset += MAX(size, 8);
2014 curinst = cfg->locals_start;
2015 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2016 inst = cfg->varinfo [iVar];
2017 if ((inst->flags & MONO_INST_IS_DEAD) ||
2018 (inst->opcode == OP_REGVAR))
2021 /*--------------------------------------------------*/
2022 /* inst->backend.is_pinvoke indicates native sized */
2023 /* value typs this is used by the pinvoke wrappers */
2024 /* when they call functions returning structure */
2025 /*--------------------------------------------------*/
2026 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2027 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2028 (guint32 *) &align);
2030 size = mono_type_size (inst->inst_vtype, &align);
2032 offset = S390_ALIGN(offset, align);
2033 inst->inst_offset = offset;
2034 inst->opcode = OP_REGOFFSET;
2035 inst->inst_basereg = frame_reg;
2037 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2038 iVar, inst->inst_offset, size));
2041 /*------------------------------------------------------*/
2042 /* Allow space for the trace method stack area if needed*/
2043 /*------------------------------------------------------*/
2044 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2045 offset += S390_TRACE_STACK_SIZE;
2047 /*------------------------------------------------------*/
2048 /* Reserve space to save LMF and caller saved registers */
2049 /*------------------------------------------------------*/
2050 if (cfg->method->save_lmf)
2051 offset += sizeof (MonoLMF);
2053 /*------------------------------------------------------*/
2054 /* align the offset */
2055 /*------------------------------------------------------*/
2056 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2058 /*------------------------------------------------------*/
2059 /* Fix offsets for args whose value is in parent frame */
2060 /*------------------------------------------------------*/
2061 for (iParm = sArg; iParm < eArg; ++iParm) {
2062 inst = cfg->args [iParm];
2064 if (inst->opcode == OP_S390_STKARG) {
2065 inst->opcode = OP_REGOFFSET;
2066 inst->inst_offset += cfg->stack_offset;
2071 /*========================= End of Function ========================*/
2073 /*------------------------------------------------------------------*/
2075 /* Name - mono_arch_create_vars */
2077 /*------------------------------------------------------------------*/
2080 mono_arch_create_vars (MonoCompile *cfg)
2082 MonoMethodSignature *sig;
2085 sig = mono_method_signature (cfg->method);
2087 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2089 if (cinfo->struct_ret) {
2090 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2091 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2092 printf ("vret_addr = ");
2093 mono_print_ins (cfg->vret_addr);
2098 /*========================= End of Function ========================*/
2100 /*------------------------------------------------------------------*/
2102 /* Name - add_outarg_reg2. */
2104 /*------------------------------------------------------------------*/
2107 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2112 case RegTypeGeneral:
2113 MONO_INST_NEW (cfg, ins, OP_MOVE);
2114 ins->dreg = mono_alloc_ireg (cfg);
2115 ins->sreg1 = tree->dreg;
2116 MONO_ADD_INS (cfg->cbb, ins);
2117 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2120 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2121 ins->dreg = mono_alloc_freg (cfg);
2122 ins->sreg1 = tree->dreg;
2123 MONO_ADD_INS (cfg->cbb, ins);
2124 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2127 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2128 ins->dreg = mono_alloc_freg (cfg);
2129 ins->sreg1 = tree->dreg;
2130 MONO_ADD_INS (cfg->cbb, ins);
2131 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2134 g_assert_not_reached ();
2138 /*========================= End of Function ========================*/
2140 /*------------------------------------------------------------------*/
2142 /* Name - emit_sig_cookie. */
2144 /*------------------------------------------------------------------*/
2147 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2149 MonoMethodSignature *tmpSig;
2152 cfg->disable_aot = TRUE;
2154 /*----------------------------------------------------------*/
2155 /* mono_ArgIterator_Setup assumes the signature cookie is */
2156 /* passed first and all the arguments which were before it */
2157 /* passed on the stack after the signature. So compensate */
2158 /* by passing a different signature. */
2159 /*----------------------------------------------------------*/
2160 tmpSig = mono_metadata_signature_dup (call->signature);
2161 tmpSig->param_count -= call->signature->sentinelpos;
2162 tmpSig->sentinelpos = 0;
2163 if (tmpSig->param_count > 0)
2164 memcpy (tmpSig->params,
2165 call->signature->params + call->signature->sentinelpos,
2166 tmpSig->param_count * sizeof(MonoType *));
2168 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2169 sig_arg->dreg = mono_alloc_ireg (cfg);
2170 sig_arg->inst_p0 = tmpSig;
2171 MONO_ADD_INS (cfg->cbb, sig_arg);
2173 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2174 cinfo->sigCookie.offset, sig_arg->dreg);
2177 /*========================= End of Function ========================*/
2179 /*------------------------------------------------------------------*/
2181 /* Name - mono_arch_emit_call */
2183 /*------------------------------------------------------------------*/
2186 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2189 MonoMethodSignature *sig;
2191 int i, n, lParamArea;
2193 ArgInfo *ainfo = NULL;
2195 MonoMethodHeader *header;
2198 sig = call->signature;
2199 n = sig->param_count + sig->hasthis;
2200 DEBUG (g_print ("Call requires: %d parameters\n",n));
2202 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2204 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2205 cinfo->sz.parm_size + cinfo->sz.offset;
2206 call->stack_usage = MAX(stackSize, call->stack_usage);
2207 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2208 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2209 cfg->flags |= MONO_CFG_HAS_CALLS;
2211 if (cinfo->struct_ret) {
2212 MONO_INST_NEW (cfg, ins, OP_MOVE);
2213 ins->sreg1 = call->vret_var->dreg;
2214 ins->dreg = mono_alloc_preg (cfg);
2215 MONO_ADD_INS (cfg->cbb, ins);
2216 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2219 header = cfg->header;
2220 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2225 for (i = 0; i < n; ++i) {
2228 ainfo = cinfo->args + i;
2229 if (i >= sig->hasthis)
2230 t = sig->params [i - sig->hasthis];
2232 t = &mono_defaults.int_class->byval_arg;
2233 t = mono_type_get_underlying_type (t);
2235 in = call->args [i];
2237 if ((sig->call_convention == MONO_CALL_VARARG) &&
2239 (i == sig->sentinelpos)) {
2240 emit_sig_cookie (cfg, call, cinfo);
2243 switch (ainfo->regtype) {
2244 case RegTypeGeneral:
2245 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2248 if (MONO_TYPE_ISSTRUCT (t)) {
2249 /* Valuetype passed in one fp register */
2250 ainfo->regtype = RegTypeStructByValInFP;
2253 if (ainfo->size == 4)
2254 ainfo->regtype = RegTypeFPR4;
2255 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2258 case RegTypeStructByVal:
2259 case RegTypeStructByAddr:
2260 case RegTypeStructByAddrOnStack: {
2264 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2265 size = sizeof (MonoTypedRef);
2266 align = sizeof (gpointer);
2270 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2273 * Other backends use mono_type_stack_size (), but that
2274 * aligns the size to 8, which is larger than the size of
2275 * the source, leading to reads of invalid memory if the
2276 * source is at the end of address space.
2278 size = mono_class_value_size (in->klass, &align);
2281 g_assert (in->klass);
2283 ainfo->offparm += cinfo->sz.offStruct;
2285 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2286 ins->sreg1 = in->dreg;
2287 ins->klass = in->klass;
2288 ins->backend.size = ainfo->size;
2289 ins->inst_p0 = call;
2290 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2291 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2293 MONO_ADD_INS (cfg->cbb, ins);
2295 if (ainfo->regtype == RegTypeStructByAddr) {
2297 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2298 * use the normal OUTARG opcodes to pass the address of the location to
2301 int treg = mono_alloc_preg (cfg);
2302 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2303 frmReg, ainfo->offparm);
2304 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2305 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2306 /* The address of the valuetype is passed on the stack */
2307 int treg = mono_alloc_preg (cfg);
2308 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2309 frmReg, ainfo->offparm);
2310 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2311 ainfo->reg, ainfo->offset, treg);
2316 if (!t->byref && t->type == MONO_TYPE_R4) {
2317 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2318 STK_BASE, ainfo->offset + 4,
2320 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2321 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2322 STK_BASE, ainfo->offset,
2325 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2326 ins->inst_destbasereg = STK_BASE;
2327 ins->inst_offset = ainfo->offset;
2328 ins->sreg1 = in->dreg;
2331 /* This is needed by MonoTypedRef->value to point to the correct data */
2332 if ((sig->call_convention == MONO_CALL_VARARG) &&
2333 (i >= sig->sentinelpos)) {
2334 switch (ainfo->size) {
2336 ins->opcode = OP_STOREI1_MEMBASE_REG;
2339 ins->opcode = OP_STOREI2_MEMBASE_REG;
2342 ins->opcode = OP_STOREI4_MEMBASE_REG;
2350 MONO_ADD_INS (cfg->cbb, ins);
2354 g_assert_not_reached ();
2360 * Handle the case where there are no implicit arguments
2362 if ((sig->call_convention == MONO_CALL_VARARG) &&
2364 (i == sig->sentinelpos)) {
2365 emit_sig_cookie (cfg, call, cinfo);
2369 /*========================= End of Function ========================*/
2371 /*------------------------------------------------------------------*/
2373 /* Name - mono_arch_emit_outarg_vt */
2375 /*------------------------------------------------------------------*/
2378 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2380 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2381 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2382 int size = ins->backend.size;
2384 if (ainfo->regtype == RegTypeStructByVal) {
2386 arg->ins.sreg1 = ainfo->reg;
2387 arg->ins.opcode = OP_OUTARG_VT;
2388 arg->size = ainfo->size;
2389 arg->offset = ainfo->offset;
2390 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2392 if (ainfo->reg != STK_BASE) {
2393 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2395 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2398 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2399 int dreg = mono_alloc_freg (cfg);
2401 if (ainfo->size == 4) {
2402 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2403 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2405 g_assert (ainfo->size == 8);
2407 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2410 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2412 MonoMethodHeader *header;
2415 header = mono_method_get_header (cfg->method);
2416 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2421 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2422 src->dreg, 0, size);
2426 /*========================= End of Function ========================*/
2428 /*------------------------------------------------------------------*/
2430 /* Name - mono_arch_emit_setret */
2432 /*------------------------------------------------------------------*/
2435 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2437 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2440 if (ret->type == MONO_TYPE_R4) {
2441 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2443 } else if (ret->type == MONO_TYPE_R8) {
2444 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2449 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2452 /*========================= End of Function ========================*/
2454 /*------------------------------------------------------------------*/
2456 /* Name - mono_arch_instrument_mem_needs */
2458 /* Function - Allow tracing to work with this interface (with */
2459 /* an optional argument). */
2461 /*------------------------------------------------------------------*/
2464 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2466 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2468 /* split prolog-epilog requirements? */
2469 *code = 50; /* max bytes needed: check this number */
2472 /*========================= End of Function ========================*/
2474 /*------------------------------------------------------------------*/
2476 /* Name - mono_arch_instrument_prolog */
2478 /* Function - Create an "instrumented" prolog. */
2480 /*------------------------------------------------------------------*/
2483 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2484 gboolean enable_arguments)
2491 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2492 if (cfg->method->save_lmf)
2493 parmOffset -= sizeof(MonoLMF);
2494 fpOffset = parmOffset + (5*sizeof(gpointer));
2495 if ((!has_ld) && (fpOffset > 4096)) {
2496 s390_lgr (code, s390_r12, STK_BASE);
2498 while (fpOffset > 4096) {
2499 s390_aghi (code, baseReg, 4096);
2507 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2509 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2510 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2511 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2512 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2514 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2515 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2516 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2517 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2519 s390_basr (code, s390_r13, 0);
2521 s390_llong(code, cfg->method);
2522 s390_llong(code, func);
2523 s390_lg (code, s390_r2, 0, s390_r13, 4);
2525 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2527 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2528 s390_lgr (code, s390_r4, STK_BASE);
2529 s390_aghi (code, s390_r4, cfg->stack_usage);
2530 s390_lg (code, s390_r1, 0, s390_r13, 12);
2531 s390_basr (code, s390_r14, s390_r1);
2533 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2534 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2535 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2536 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2538 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2539 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2540 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2541 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2543 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2548 /*========================= End of Function ========================*/
2550 /*------------------------------------------------------------------*/
2552 /* Name - mono_arch_instrument_epilog */
2554 /* Function - Create an epilog that will handle the returned */
2555 /* values used in instrumentation. */
2557 /*------------------------------------------------------------------*/
2560 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2563 int save_mode = SAVE_NONE,
2565 MonoMethod *method = cfg->method;
2566 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2568 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2569 if (method->save_lmf)
2570 saveOffset -= sizeof(MonoLMF);
2574 case MONO_TYPE_VOID:
2575 /* special case string .ctor icall */
2576 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2577 save_mode = SAVE_ONE;
2579 save_mode = SAVE_NONE;
2583 save_mode = SAVE_ONE;
2586 save_mode = SAVE_R4;
2589 save_mode = SAVE_R8;
2591 case MONO_TYPE_VALUETYPE:
2592 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2593 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2596 save_mode = SAVE_STRUCT;
2599 save_mode = SAVE_ONE;
2603 switch (save_mode) {
2605 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2606 if (enable_arguments) {
2607 s390_lgr (code, s390_r3, s390_r2);
2611 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2612 if (enable_arguments) {
2613 s390_ldebr (code, s390_f0, s390_f0);
2617 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2620 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2621 if (enable_arguments) {
2622 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2623 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2631 s390_basr (code, s390_r13, 0);
2633 s390_llong(code, cfg->method);
2634 s390_llong(code, func);
2635 s390_lg (code, s390_r2, 0, s390_r13, 4);
2636 s390_lg (code, s390_r1, 0, s390_r13, 12);
2637 s390_basr (code, s390_r14, s390_r1);
2639 switch (save_mode) {
2641 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2645 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2648 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2658 /*========================= End of Function ========================*/
2660 /*------------------------------------------------------------------*/
2662 /* Name - mono_arch_peephole_pass_1 */
2664 /* Function - Form a peephole pass at the code looking for */
2665 /* simple optimizations. */
2667 /*------------------------------------------------------------------*/
2670 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2674 /*========================= End of Function ========================*/
2676 /*------------------------------------------------------------------*/
2678 /* Name - mono_arch_peephole_pass_2 */
2680 /* Function - Form a peephole pass at the code looking for */
2681 /* simple optimizations. */
2683 /*------------------------------------------------------------------*/
2686 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2690 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2691 mono_peephole_ins (bb, ins);
2695 /*========================= End of Function ========================*/
2697 /*------------------------------------------------------------------*/
2699 /* Name - mono_arch_lowering_pass. */
2701 /*------------------------------------------------------------------*/
2704 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2706 MonoInst *ins, *next;
2708 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2709 switch (ins->opcode) {
2714 case OP_IDIV_UN_IMM:
2715 case OP_IREM_UN_IMM:
2719 case OP_LOCALLOC_IMM:
2720 mono_decompose_op_imm (cfg, bb, ins);
2723 if (!s390_is_imm16 (ins->inst_imm))
2724 /* This is created by the memcpy code which ignores is_inst_imm */
2725 mono_decompose_op_imm (cfg, bb, ins);
2732 bb->max_vreg = cfg->next_vreg;
2735 /*========================= End of Function ========================*/
2737 /*------------------------------------------------------------------*/
2739 /* Name - emit_float_to_int */
2741 /* Function - Create instructions which will convert a floating */
2742 /* point value to integer. */
2744 /*------------------------------------------------------------------*/
2747 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2749 /* sreg is a float, dreg is an integer reg. */
2751 s390_cgdbr (code, dreg, 5, sreg);
2754 s390_lghi (code, s390_r0, 0);
2755 s390_lghi (code, s390_r13, 0xff);
2756 s390_ltgr (code, dreg, dreg);
2758 s390_lghi (code, s390_r0, 0x80);
2759 s390_ngr (code, dreg, s390_r13);
2760 s390_ogr (code, dreg, s390_r0);
2765 s390_basr (code, s390_r13, 0);
2767 s390_llong (code, 0x41e0000000000000llu);
2768 s390_llong (code, 0x41f0000000000000llu);
2769 s390_ldr (code, s390_f15, sreg);
2770 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2771 s390_jl (code, 0); CODEPTR (code, o[0]);
2772 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2773 s390_cfdbr (code, dreg, 7, s390_f15);
2775 PTRSLOT (code, o[0]);
2776 s390_cfdbr (code, dreg, 5, sreg);
2779 s390_lghi (code, s390_r0, 0xff);
2780 s390_ngr (code, dreg, s390_r0);
2783 s390_lghi (code, s390_r0, -1);
2784 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2785 s390_ngr (code, dreg, s390_r0);
2792 /*========================= End of Function ========================*/
2794 /*------------------------------------------------------------------*/
2796 /* Name - gboolean_is_unsigned. */
2798 /* Function - Return TRUE if next opcode is checking for un- */
2801 /*------------------------------------------------------------------*/
2804 gboolean is_unsigned (MonoInst *next)
2807 (((next->opcode >= OP_IBNE_UN) &&
2808 (next->opcode <= OP_IBLT_UN)) ||
2809 ((next->opcode >= OP_LBNE_UN) &&
2810 (next->opcode <= OP_LBLT_UN)) ||
2811 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2812 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2813 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2814 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2815 ((next->opcode == OP_CLT_UN) ||
2816 (next->opcode == OP_CGT_UN)) ||
2817 ((next->opcode == OP_ICLT_UN) ||
2818 (next->opcode == OP_ICGT_UN) ||
2819 (next->opcode == OP_LCLT_UN) ||
2820 (next->opcode == OP_LCGT_UN))))
2826 /*========================= End of Function ========================*/
2828 /*------------------------------------------------------------------*/
2830 /* Name - mono_arch_output_basic_block */
2832 /* Function - Perform the "real" work of emitting instructions */
2833 /* that will do the work of in the basic block. */
2835 /*------------------------------------------------------------------*/
2838 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2843 guint8 *code = cfg->native_code + cfg->code_len;
2844 guint last_offset = 0;
2845 int max_len, cpos, src2;
2847 /* we don't align basic blocks of loops on s390 */
2849 if (cfg->verbose_level > 2)
2850 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2852 cpos = bb->max_offset;
2854 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2855 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2856 //g_assert (!mono_compile_aot);
2859 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2860 /* this is not thread save, but good enough */
2861 /* fixme: howto handle overflows? */
2862 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2865 MONO_BB_FOR_EACH_INS (bb, ins) {
2866 offset = code - cfg->native_code;
2868 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2870 if (offset > (cfg->code_size - max_len - 16)) {
2871 cfg->code_size *= 2;
2872 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2873 code = cfg->native_code + offset;
2876 mono_debug_record_line_number (cfg, ins, offset);
2878 switch (ins->opcode) {
2879 case OP_STOREI1_MEMBASE_IMM: {
2880 s390_lghi (code, s390_r0, ins->inst_imm);
2881 S390_LONG (code, stcy, stc, s390_r0, 0,
2882 ins->inst_destbasereg, ins->inst_offset);
2885 case OP_STOREI2_MEMBASE_IMM: {
2886 s390_lghi (code, s390_r0, ins->inst_imm);
2887 S390_LONG (code, sthy, sth, s390_r0, 0,
2888 ins->inst_destbasereg, ins->inst_offset);
2891 case OP_STOREI4_MEMBASE_IMM: {
2892 if (s390_is_imm16(ins->inst_imm)) {
2893 s390_lghi (code, s390_r0, ins->inst_imm);
2895 s390_basr (code, s390_r13, 0);
2897 s390_llong(code, ins->inst_imm);
2898 s390_lg (code, s390_r0, 0, s390_r13, 4);
2900 S390_LONG (code, sty, st, s390_r0, 0,
2901 ins->inst_destbasereg, ins->inst_offset);
2904 case OP_STORE_MEMBASE_IMM:
2905 case OP_STOREI8_MEMBASE_IMM: {
2906 if (s390_is_imm16(ins->inst_imm)) {
2907 s390_lghi (code, s390_r0, ins->inst_imm);
2909 s390_basr (code, s390_r13, 0);
2911 s390_llong(code, ins->inst_imm);
2912 s390_lg (code, s390_r0, 0, s390_r13, 4);
2914 S390_LONG (code, stg, stg, s390_r0, 0,
2915 ins->inst_destbasereg, ins->inst_offset);
2918 case OP_STOREI1_MEMBASE_REG: {
2919 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2920 ins->inst_destbasereg, ins->inst_offset);
2923 case OP_STOREI2_MEMBASE_REG: {
2924 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2925 ins->inst_destbasereg, ins->inst_offset);
2928 case OP_STOREI4_MEMBASE_REG: {
2929 S390_LONG (code, sty, st, ins->sreg1, 0,
2930 ins->inst_destbasereg, ins->inst_offset);
2933 case OP_STORE_MEMBASE_REG:
2934 case OP_STOREI8_MEMBASE_REG: {
2935 S390_LONG (code, stg, stg, ins->sreg1, 0,
2936 ins->inst_destbasereg, ins->inst_offset);
2940 g_assert_not_reached ();
2942 case OP_LOAD_MEMBASE:
2943 case OP_LOADI8_MEMBASE: {
2944 S390_LONG (code, lg, lg, ins->dreg, 0,
2945 ins->inst_basereg, ins->inst_offset);
2948 case OP_LOADI4_MEMBASE: {
2949 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2950 ins->inst_basereg, ins->inst_offset);
2953 case OP_LOADU4_MEMBASE: {
2954 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2955 ins->inst_basereg, ins->inst_offset);
2958 case OP_LOADU1_MEMBASE: {
2959 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2960 ins->inst_basereg, ins->inst_offset);
2963 case OP_LOADI1_MEMBASE: {
2964 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2965 ins->inst_basereg, ins->inst_offset);
2968 case OP_LOADU2_MEMBASE: {
2969 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2970 ins->inst_basereg, ins->inst_offset);
2973 case OP_LOADI2_MEMBASE: {
2974 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2975 ins->inst_basereg, ins->inst_offset);
2978 case OP_LCONV_TO_I1: {
2980 s390_lgbr (code, ins->dreg, ins->sreg1);
2982 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
2983 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
2987 case OP_LCONV_TO_I2: {
2989 s390_lghr (code, ins->dreg, ins->sreg1);
2991 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
2992 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
2996 case OP_LCONV_TO_U1: {
2998 s390_llghr (code, ins->dreg, ins->sreg1);
3000 if (ins->dreg != ins->sreg1)
3001 s390_lgr (code, ins->dreg, ins->sreg1);
3002 s390_lghi (code, s390_r0, 0xff);
3003 s390_ngr (code, ins->dreg, s390_r0);
3007 case OP_LCONV_TO_U2: {
3009 s390_llghr (code, ins->dreg, ins->sreg1);
3011 if (ins->dreg != ins->sreg1)
3012 s390_lgr (code, ins->dreg, ins->sreg1);
3013 s390_lghi (code, s390_r0, -1);
3014 s390_srlg (code, s390_r0, s390_r0, 0, 48);
3015 s390_ngr (code, ins->dreg, s390_r0);
3019 case OP_ICONV_TO_I1: {
3021 s390_lbr (code, ins->dreg, ins->sreg1);
3023 if (ins->dreg != ins->sreg1)
3024 s390_lr (code, ins->dreg, ins->sreg1);
3025 s390_sll (code, ins->dreg, 0, 24);
3026 s390_sra (code, ins->dreg, 0, 24);
3031 case OP_ICONV_TO_I2: {
3033 s390_lhr (code, ins->dreg, ins->sreg1);
3035 if (ins->dreg != ins->sreg1)
3036 s390_lr (code, ins->dreg, ins->sreg1);
3037 s390_sll (code, ins->dreg, 0, 16);
3038 s390_sra (code, ins->dreg, 0, 16);
3042 case OP_ICONV_TO_U1: {
3044 s390_llcr (code, ins->dreg, ins->sreg1);
3046 if (ins->dreg != ins->sreg1)
3047 s390_lr (code, ins->dreg, ins->sreg1);
3048 s390_lhi (code, s390_r0, 0xff);
3049 s390_nr (code, ins->dreg, s390_r0);
3053 case OP_ICONV_TO_U2: {
3055 s390_llhr (code, ins->dreg, ins->sreg1);
3057 if (ins->dreg != ins->sreg1)
3058 s390_lr (code, ins->dreg, ins->sreg1);
3059 s390_lhi (code, s390_r0, -1);
3060 s390_srl (code, s390_r0, 0, 16);
3061 s390_nr (code, ins->dreg, s390_r0);
3067 if (is_unsigned (ins->next))
3068 s390_clgr (code, ins->sreg1, ins->sreg2);
3070 s390_cgr (code, ins->sreg1, ins->sreg2);
3074 if (is_unsigned (ins->next))
3075 s390_clr (code, ins->sreg1, ins->sreg2);
3077 s390_cr (code, ins->sreg1, ins->sreg2);
3080 case OP_COMPARE_IMM:
3081 case OP_LCOMPARE_IMM: {
3082 if (s390_is_imm16 (ins->inst_imm)) {
3083 s390_lghi (code, s390_r0, ins->inst_imm);
3084 if (is_unsigned (ins->next))
3085 s390_clgr (code, ins->sreg1, s390_r0);
3087 s390_cgr (code, ins->sreg1, s390_r0);
3089 s390_basr (code, s390_r13, 0);
3091 s390_llong(code, ins->inst_imm);
3092 if (is_unsigned (ins->next))
3093 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3095 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3099 case OP_ICOMPARE_IMM: {
3100 if (s390_is_imm16 (ins->inst_imm)) {
3101 s390_lghi (code, s390_r0, ins->inst_imm);
3102 if (is_unsigned (ins->next))
3103 s390_clr (code, ins->sreg1, s390_r0);
3105 s390_cr (code, ins->sreg1, s390_r0);
3108 s390_basr (code, s390_r13, 0);
3110 s390_word (code, ins->inst_imm);
3111 if (is_unsigned (ins->next))
3112 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3114 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3119 s390_basr (code, s390_r13, 0);
3121 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3123 s390_llong (code, mono_break);
3124 s390_lg (code, s390_r14, 0, s390_r13, 4);
3125 s390_basr (code, s390_r14, s390_r14);
3130 s390_agr (code, ins->dreg, src2);
3135 s390_agr (code, ins->dreg, src2);
3140 s390_alcgr (code, ins->dreg, src2);
3144 if (ins->dreg != ins->sreg1) {
3145 s390_lgr (code, ins->dreg, ins->sreg1);
3147 if (s390_is_imm16 (ins->inst_imm)) {
3148 s390_aghi (code, ins->dreg, ins->inst_imm);
3150 s390_basr (code, s390_r13, 0);
3152 s390_llong(code, ins->inst_imm);
3153 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3158 if (ins->dreg != ins->sreg1) {
3159 s390_lgr (code, ins->dreg, ins->sreg1);
3161 g_assert (s390_is_imm16 (ins->inst_imm));
3162 s390_aghi (code, ins->dreg, ins->inst_imm);
3166 if (ins->dreg != ins->sreg1) {
3167 s390_lgr (code, ins->dreg, ins->sreg1);
3169 if (s390_is_imm16 (ins->inst_imm)) {
3170 s390_lghi (code, s390_r0, ins->inst_imm);
3171 s390_alcgr (code, ins->dreg, s390_r0);
3173 s390_basr (code, s390_r13, 0);
3175 s390_llong (code, ins->inst_imm);
3176 s390_lg (code, s390_r13, 0, s390_r13, 4);
3177 s390_alcgr (code, ins->dreg, s390_r13);
3182 case OP_S390_IADD_OVF: {
3184 s390_ar (code, ins->dreg, src2);
3185 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3186 s390_lgfr (code, ins->dreg, ins->dreg);
3189 case OP_IADD_OVF_UN:
3190 case OP_S390_IADD_OVF_UN: {
3192 s390_algr (code, ins->dreg, src2);
3193 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3194 s390_llgfr (code, ins->dreg, ins->dreg);
3197 case OP_ADD_OVF_CARRY: {
3199 s390_lghi (code, s390_r0, 0);
3200 s390_lgr (code, s390_r1, s390_r0);
3201 s390_alcgr (code, s390_r0, s390_r1);
3202 s390_agr (code, ins->dreg, src2);
3203 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3204 s390_agr (code, ins->dreg, s390_r0);
3205 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3208 case OP_ADD_OVF_UN_CARRY: {
3210 s390_alcgr (code, ins->dreg, src2);
3211 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3216 s390_sgr (code, ins->dreg, src2);
3221 s390_sgr (code, ins->dreg, src2);
3226 s390_slbgr(code, ins->dreg, src2);
3230 if (ins->dreg != ins->sreg1) {
3231 s390_lgr (code, ins->dreg, ins->sreg1);
3233 if (s390_is_imm16 (-ins->inst_imm)) {
3234 s390_lghi (code, s390_r0, ins->inst_imm);
3235 s390_slgr (code, ins->dreg, s390_r0);
3237 s390_basr (code, s390_r13, 0);
3239 s390_llong(code, ins->inst_imm);
3240 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3245 if (ins->dreg != ins->sreg1) {
3246 s390_lgr (code, ins->dreg, ins->sreg1);
3248 if (s390_is_imm16 (-ins->inst_imm)) {
3249 s390_lghi (code, s390_r0, ins->inst_imm);
3250 s390_slgr (code, ins->dreg, s390_r0);
3252 s390_basr (code, s390_r13, 0);
3254 s390_llong(code, ins->inst_imm);
3255 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3260 if (ins->dreg != ins->sreg1) {
3261 s390_lgr (code, ins->dreg, ins->sreg1);
3263 if (s390_is_imm16 (-ins->inst_imm)) {
3264 s390_lghi (code, s390_r0, ins->inst_imm);
3265 s390_slbgr (code, ins->dreg, s390_r0);
3267 s390_basr (code, s390_r13, 0);
3269 s390_llong(code, ins->inst_imm);
3270 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3274 case OP_SUB_OVF_CARRY: {
3276 s390_lghi (code, s390_r0, 0);
3277 s390_lgr (code, s390_r1, s390_r0);
3278 s390_slbgr (code, s390_r0, s390_r1);
3279 s390_sgr (code, ins->dreg, src2);
3280 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3281 s390_agr (code, ins->dreg, s390_r0);
3282 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3285 case OP_SUB_OVF_UN_CARRY: {
3287 s390_slbgr (code, ins->dreg, src2);
3288 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3292 if (ins->sreg1 == ins->dreg) {
3293 s390_ngr (code, ins->dreg, ins->sreg2);
3296 if (ins->sreg2 == ins->dreg) {
3297 s390_ngr (code, ins->dreg, ins->sreg1);
3300 s390_lgr (code, ins->dreg, ins->sreg1);
3301 s390_ngr (code, ins->dreg, ins->sreg2);
3307 if (ins->dreg != ins->sreg1) {
3308 s390_lgr (code, ins->dreg, ins->sreg1);
3310 if (s390_is_imm16 (ins->inst_imm)) {
3311 s390_lghi (code, s390_r0, ins->inst_imm);
3312 s390_ngr (code, ins->dreg, s390_r0);
3314 s390_basr (code, s390_r13, 0);
3316 s390_llong(code, ins->inst_imm);
3317 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3322 s390_lgr (code, s390_r1, ins->sreg1);
3323 s390_dsgr (code, s390_r0, ins->sreg2);
3324 s390_lgr (code, ins->dreg, s390_r1);
3328 s390_lgr (code, s390_r1, ins->sreg1);
3329 s390_lghi (code, s390_r0, 0);
3330 s390_dlgr (code, s390_r0, ins->sreg2);
3331 s390_lgr (code, ins->dreg, s390_r1);
3335 s390_lgr (code, s390_r1, ins->sreg1);
3336 s390_dsgr (code, s390_r0, ins->sreg2);
3337 s390_lgr (code, ins->dreg, s390_r0);
3341 s390_lgr (code, s390_r1, ins->sreg1);
3342 s390_lghi (code, s390_r0, 0);
3343 s390_dlgr (code, s390_r0, ins->sreg2);
3344 s390_lgr (code, ins->dreg, s390_r0);
3348 if (ins->sreg1 == ins->dreg) {
3349 s390_ogr (code, ins->dreg, ins->sreg2);
3352 if (ins->sreg2 == ins->dreg) {
3353 s390_ogr (code, ins->dreg, ins->sreg1);
3356 s390_lgr (code, ins->dreg, ins->sreg1);
3357 s390_ogr (code, ins->dreg, ins->sreg2);
3363 if (ins->dreg != ins->sreg1) {
3364 s390_lgr (code, ins->dreg, ins->sreg1);
3366 if (s390_is_imm16 (ins->inst_imm)) {
3367 s390_lghi (code, s390_r0, ins->inst_imm);
3368 s390_ogr (code, ins->dreg, s390_r0);
3370 s390_basr (code, s390_r13, 0);
3372 s390_llong(code, ins->inst_imm);
3373 s390_og (code, ins->dreg, 0, s390_r13, 4);
3378 if (ins->sreg1 == ins->dreg) {
3379 s390_xgr (code, ins->dreg, ins->sreg2);
3382 if (ins->sreg2 == ins->dreg) {
3383 s390_xgr (code, ins->dreg, ins->sreg1);
3386 s390_lgr (code, ins->dreg, ins->sreg1);
3387 s390_xgr (code, ins->dreg, ins->sreg2);
3393 if (ins->dreg != ins->sreg1) {
3394 s390_lgr (code, ins->dreg, ins->sreg1);
3396 if (s390_is_imm16 (ins->inst_imm)) {
3397 s390_lghi (code, s390_r0, ins->inst_imm);
3398 s390_xgr (code, ins->dreg, s390_r0);
3400 s390_basr (code, s390_r13, 0);
3402 s390_llong(code, ins->inst_imm);
3403 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3409 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3414 if (ins->sreg1 != ins->dreg) {
3415 s390_lgr (code, ins->dreg, ins->sreg1);
3417 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3422 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3427 if (ins->sreg1 != ins->dreg) {
3428 s390_lgr (code, ins->dreg, ins->sreg1);
3430 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3434 case OP_LSHR_UN_IMM: {
3435 if (ins->sreg1 != ins->dreg) {
3436 s390_lgr (code, ins->dreg, ins->sreg1);
3438 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3443 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3447 if (ins->sreg1 != ins->dreg) {
3448 s390_lgr (code, ins->dreg, ins->sreg1);
3450 s390_lghi (code, s390_r0, -1);
3451 s390_xgr (code, ins->dreg, s390_r0);
3455 s390_lcgr (code, ins->dreg, ins->sreg1);
3460 s390_msgr (code, ins->dreg, src2);
3465 if (ins->dreg != ins->sreg1) {
3466 s390_lgr (code, ins->dreg, ins->sreg1);
3468 if (s390_is_imm16 (ins->inst_imm)) {
3469 s390_lghi (code, s390_r13, ins->inst_imm);
3471 s390_basr (code, s390_r13, 0);
3473 s390_llong(code, ins->inst_imm);
3474 s390_lg (code, s390_r13, 0, s390_r13, 4);
3476 s390_msgr (code, ins->dreg, s390_r13);
3481 s390_ltgr (code, s390_r1, ins->sreg1);
3482 s390_jz (code, 0); CODEPTR(code, o[0]);
3483 s390_ltgr (code, s390_r0, ins->sreg2);
3485 s390_lghi (code, s390_r1, 0);
3486 s390_j (code, 0); CODEPTR(code, o[1]);
3487 s390_xgr (code, s390_r0, s390_r1);
3488 s390_msgr (code, s390_r1, ins->sreg2);
3489 s390_xgr (code, s390_r0, s390_r1);
3490 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3491 s390_ltgr (code, s390_r0, s390_r0);
3492 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3493 PTRSLOT (code, o[0]);
3494 PTRSLOT (code, o[1]);
3495 s390_lgr (code, ins->dreg, s390_r1);
3498 case OP_LMUL_OVF_UN: {
3499 s390_lghi (code, s390_r0, 0);
3500 s390_lgr (code, s390_r1, ins->sreg1);
3501 s390_mlgr (code, s390_r0, ins->sreg2);
3502 s390_ltgr (code, s390_r0, s390_r0);
3503 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3504 s390_lgr (code, ins->dreg, s390_r1);
3508 g_assert_not_reached ();
3510 s390_algr (code, ins->dreg, src2);
3515 s390_agr (code, ins->dreg, src2);
3519 g_assert_not_reached ();
3521 s390_alcgr (code, ins->dreg, src2);
3525 if (ins->dreg != ins->sreg1) {
3526 s390_lgfr (code, ins->dreg, ins->sreg1);
3528 if (s390_is_imm16 (ins->inst_imm)) {
3529 s390_aghi(code, ins->dreg, ins->inst_imm);
3531 s390_basr (code, s390_r13, 0);
3533 s390_word (code, ins->inst_imm);
3534 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3539 if (ins->dreg != ins->sreg1) {
3540 s390_lgfr (code, ins->dreg, ins->sreg1);
3542 if (s390_is_imm16 (ins->inst_imm)) {
3543 s390_lghi (code, s390_r0, ins->inst_imm);
3544 s390_alcgr (code, ins->dreg, s390_r0);
3546 s390_basr (code, s390_r13, 0);
3548 s390_word (code, ins->inst_imm);
3549 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3550 s390_alcgr (code, ins->dreg, s390_r13);
3555 case OP_S390_LADD_OVF: {
3557 s390_agr (code, ins->dreg, src2);
3558 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3561 case OP_LADD_OVF_UN:
3562 case OP_S390_LADD_OVF_UN: {
3564 s390_algr (code, ins->dreg, src2);
3565 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3569 CHECK_SRCDST_NCOM_I;
3570 s390_slgr (code, ins->dreg, src2);
3574 CHECK_SRCDST_NCOM_I;
3575 s390_sgr (code, ins->dreg, src2);
3579 CHECK_SRCDST_NCOM_I;
3580 s390_slbgr (code, ins->dreg, src2);
3584 if (ins->dreg != ins->sreg1) {
3585 s390_lgfr (code, ins->dreg, ins->sreg1);
3587 if (s390_is_imm16 (-ins->inst_imm)) {
3588 s390_aghi (code, ins->dreg, -ins->inst_imm);
3590 s390_basr (code, s390_r13, 0);
3592 s390_word (code, ins->inst_imm);
3593 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3598 s390_basr (code, s390_r13, 0);
3600 s390_word (code, ins->inst_imm);
3601 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3605 case OP_S390_ISUB_OVF: {
3607 s390_sr (code, ins->dreg, src2);
3608 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3609 s390_lgfr (code, ins->dreg, ins->dreg);
3612 case OP_ISUB_OVF_UN:
3613 case OP_S390_ISUB_OVF_UN: {
3615 s390_slr (code, ins->dreg, src2);
3616 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3617 s390_llgfr(code, ins->dreg, ins->dreg);
3621 case OP_S390_LSUB_OVF: {
3623 s390_sgr (code, ins->dreg, src2);
3624 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3627 case OP_LSUB_OVF_UN:
3628 case OP_S390_LSUB_OVF_UN: {
3630 s390_slgr (code, ins->dreg, src2);
3631 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3635 CHECK_SRCDST_NCOM_I;
3636 s390_ngr (code, ins->dreg, src2);
3640 if (ins->dreg != ins->sreg1) {
3641 s390_lgfr (code, ins->dreg, ins->sreg1);
3643 if (s390_is_imm16 (ins->inst_imm)) {
3644 s390_lghi (code, s390_r0, ins->inst_imm);
3645 s390_ngr (code, ins->dreg, s390_r0);
3647 s390_basr (code, s390_r13, 0);
3649 s390_llong(code, ins->inst_imm);
3650 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3655 s390_lgfr (code, s390_r0, ins->sreg1);
3656 s390_srda (code, s390_r0, 0, 32);
3657 s390_dr (code, s390_r0, ins->sreg2);
3658 s390_lgfr (code, ins->dreg, s390_r1);
3662 s390_lgfr (code, s390_r0, ins->sreg1);
3663 s390_srdl (code, s390_r0, 0, 32);
3664 s390_dlr (code, s390_r0, ins->sreg2);
3665 s390_lgfr (code, ins->dreg, s390_r1);
3669 if (s390_is_imm16 (ins->inst_imm)) {
3670 s390_lghi (code, s390_r13, ins->inst_imm);
3671 s390_lgfr (code, s390_r0, ins->sreg1);
3673 s390_basr (code, s390_r13, 0);
3675 s390_word (code, ins->inst_imm);
3676 s390_lgfr (code, s390_r0, ins->sreg1);
3677 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3679 s390_srda (code, s390_r0, 0, 32);
3680 s390_dr (code, s390_r0, ins->sreg2);
3681 s390_lgfr (code, ins->dreg, s390_r1);
3685 s390_lgfr (code, s390_r0, ins->sreg1);
3686 s390_srda (code, s390_r0, 0, 32);
3687 s390_dr (code, s390_r0, ins->sreg2);
3688 s390_lgfr (code, ins->dreg, s390_r0);
3691 s390_lgfr (code, s390_r0, ins->sreg1);
3692 s390_srdl (code, s390_r0, 0, 32);
3693 s390_dlr (code, s390_r0, ins->sreg2);
3694 s390_lgfr (code, ins->dreg, s390_r0);
3698 if (s390_is_imm16 (ins->inst_imm)) {
3699 s390_lghi (code, s390_r13, ins->inst_imm);
3700 s390_lgfr (code, s390_r0, ins->sreg1);
3702 s390_basr (code, s390_r13, 0);
3704 s390_word (code, ins->inst_imm);
3705 s390_lgfr (code, s390_r0, ins->sreg1);
3706 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3708 s390_srda (code, s390_r0, 0, 32);
3709 s390_dr (code, s390_r0, ins->sreg2);
3710 s390_lgfr (code, ins->dreg, s390_r0);
3715 s390_ogr (code, ins->dreg, src2);
3719 if (ins->dreg != ins->sreg1) {
3720 s390_lgfr (code, ins->dreg, ins->sreg1);
3722 if (s390_is_imm16 (ins->inst_imm)) {
3723 s390_lghi (code, s390_r0, ins->inst_imm);
3724 s390_ogr (code, ins->dreg, s390_r0);
3726 s390_basr (code, s390_r13, 0);
3728 s390_llong(code, ins->inst_imm);
3729 s390_og (code, ins->dreg, 0, s390_r13, 4);
3735 s390_xgr (code, ins->dreg, src2);
3739 if (ins->dreg != ins->sreg1) {
3740 s390_lgfr (code, ins->dreg, ins->sreg1);
3742 if (s390_is_imm16 (ins->inst_imm)) {
3743 s390_lghi (code, s390_r0, ins->inst_imm);
3744 s390_xgr (code, ins->dreg, s390_r0);
3746 s390_basr (code, s390_r13, 0);
3748 s390_llong(code, ins->inst_imm);
3749 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3755 s390_sll (code, ins->dreg, src2, 0);
3759 if (ins->sreg1 != ins->dreg) {
3760 s390_lgfr (code, ins->dreg, ins->sreg1);
3762 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3767 s390_sra (code, ins->dreg, src2, 0);
3771 if (ins->sreg1 != ins->dreg) {
3772 s390_lgfr (code, ins->dreg, ins->sreg1);
3774 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3777 case OP_ISHR_UN_IMM: {
3778 if (ins->sreg1 != ins->dreg) {
3779 s390_lgfr (code, ins->dreg, ins->sreg1);
3781 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3786 s390_srl (code, ins->dreg, src2, 0);
3790 if (ins->sreg1 != ins->dreg) {
3791 s390_lgfr (code, ins->dreg, ins->sreg1);
3793 s390_lghi (code, s390_r0, -1);
3794 s390_xgr (code, ins->dreg, s390_r0);
3798 s390_lcgr (code, ins->dreg, ins->sreg1);
3803 s390_msr (code, ins->dreg, src2);
3807 if (ins->dreg != ins->sreg1) {
3808 s390_lgfr (code, ins->dreg, ins->sreg1);
3810 if (s390_is_imm16 (ins->inst_imm)) {
3811 s390_lghi (code, s390_r13, ins->inst_imm);
3813 s390_basr (code, s390_r13, 0);
3815 s390_word (code, ins->inst_imm);
3816 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3818 s390_msr (code, ins->dreg, s390_r13);
3823 s390_ltr (code, s390_r1, ins->sreg1);
3824 s390_jz (code, 0); CODEPTR(code, o[0]);
3825 s390_ltr (code, s390_r0, ins->sreg2);
3827 s390_lhi (code, s390_r1, 0);
3828 s390_j (code, 0); CODEPTR(code, o[1]);
3829 s390_xr (code, s390_r0, s390_r1);
3830 s390_msr (code, s390_r1, ins->sreg2);
3831 s390_xr (code, s390_r0, s390_r1);
3832 s390_srl (code, s390_r0, 0, 31);
3833 s390_ltr (code, s390_r0, s390_r0);
3834 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3835 PTRSLOT (code, o[0]);
3836 PTRSLOT (code, o[1]);
3837 s390_lgfr (code, ins->dreg, s390_r1);
3840 case OP_IMUL_OVF_UN: {
3841 s390_lhi (code, s390_r0, 0);
3842 s390_lr (code, s390_r1, ins->sreg1);
3843 s390_mlr (code, s390_r0, ins->sreg2);
3844 s390_ltr (code, s390_r0, s390_r0);
3845 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3846 s390_lgfr (code, ins->dreg, s390_r1);
3851 if (s390_is_imm16(ins->inst_c0)) {
3852 s390_lghi (code, ins->dreg, ins->inst_c0);
3854 s390_basr (code, s390_r13, 0);
3856 s390_llong(code, ins->inst_c0);
3857 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3862 s390_basr (code, s390_r13, 0);
3864 mono_add_patch_info (cfg, code - cfg->native_code,
3865 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3866 s390_llong(code, 0);
3867 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3870 case OP_JUMP_TABLE: {
3871 mono_add_patch_info (cfg, code - cfg->native_code,
3872 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3873 s390_basr (code, s390_r13, 0);
3875 s390_llong (code, 0);
3876 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3880 if (ins->dreg != ins->sreg1) {
3881 s390_lgr (code, ins->dreg, ins->sreg1);
3885 case OP_LCONV_TO_I8:
3887 s390_lgfr (code, ins->dreg, ins->sreg1);
3889 case OP_LCONV_TO_I4:
3890 s390_lgfr (code, ins->dreg, ins->sreg1);
3893 case OP_LCONV_TO_U8:
3894 case OP_LCONV_TO_U4:
3896 s390_llgfr (code, ins->dreg, ins->sreg1);
3898 case OP_LCONV_TO_OVF_U4:
3899 s390_basr (code, s390_r13, 0);
3901 s390_llong(code, 4294967295);
3902 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3903 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3904 s390_ltgr (code, ins->sreg1, ins->sreg1);
3905 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3906 s390_llgfr(code, ins->dreg, ins->sreg1);
3908 case OP_LCONV_TO_OVF_I4_UN:
3909 s390_basr (code, s390_r13, 0);
3911 s390_llong(code, 2147483647);
3912 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3913 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3914 s390_ltgr (code, ins->sreg1, ins->sreg1);
3915 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3916 s390_lgfr (code, ins->dreg, ins->sreg1);
3919 case OP_FCONV_TO_R4: {
3920 if (ins->dreg != ins->sreg1) {
3921 s390_ldr (code, ins->dreg, ins->sreg1);
3925 case OP_S390_SETF4RET: {
3926 s390_ledbr (code, ins->dreg, ins->sreg1);
3930 if (cfg->method->save_lmf)
3931 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3933 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3934 code = emit_load_volatile_arguments (code, cfg);
3937 code = backUpStackPtr(cfg, code);
3938 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3939 mono_add_patch_info (cfg, code - cfg->native_code,
3940 MONO_PATCH_INFO_METHOD_JUMP,
3942 s390_jcl (code, S390_CC_UN, 0);
3945 case OP_CHECK_THIS: {
3946 /* ensure ins->sreg1 is not NULL */
3947 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3948 s390_ltgr (code, s390_r0, s390_r0);
3952 int offset = cfg->sig_cookie + cfg->stack_usage;
3954 if (s390_is_imm16 (offset))
3955 s390_lghi (code, s390_r0, offset);
3957 s390_basr (code, s390_r13, 0);
3959 s390_llong(code, offset);
3960 s390_lg (code, s390_r0, 0, s390_r13, 0);
3962 s390_agr (code, s390_r0, cfg->frame_reg);
3963 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3967 s390_basr (code, s390_r13, 0);
3969 call = (MonoCallInst*)ins;
3970 if (ins->flags & MONO_INST_HAS_METHOD)
3971 mono_add_patch_info (cfg, code-cfg->native_code,
3972 MONO_PATCH_INFO_METHOD,
3975 mono_add_patch_info (cfg, code-cfg->native_code,
3976 MONO_PATCH_INFO_ABS,
3978 s390_llong(code, 0);
3979 s390_lg (code, s390_r14, 0, s390_r13, 4);
3980 s390_basr (code, s390_r14, s390_r14);
3981 if (call->signature->ret->type == MONO_TYPE_R4)
3982 s390_ldebr (code, s390_f0, s390_f0);
3990 s390_basr (code, s390_r13, 0);
3992 call = (MonoCallInst*)ins;
3993 if (ins->flags & MONO_INST_HAS_METHOD)
3994 mono_add_patch_info (cfg, code-cfg->native_code,
3995 MONO_PATCH_INFO_METHOD,
3998 mono_add_patch_info (cfg, code-cfg->native_code,
3999 MONO_PATCH_INFO_ABS,
4001 s390_llong(code, 0);
4002 s390_lg (code, s390_r14, 0, s390_r13, 4);
4003 s390_basr (code, s390_r14, s390_r14);
4006 case OP_FCALL_REG: {
4007 call = (MonoCallInst*)ins;
4008 s390_lgr (code, s390_r1, ins->sreg1);
4009 s390_basr (code, s390_r14, s390_r1);
4010 if (call->signature->ret->type == MONO_TYPE_R4)
4011 s390_ldebr (code, s390_f0, s390_f0);
4017 case OP_VOIDCALL_REG:
4019 s390_lgr (code, s390_r1, ins->sreg1);
4020 s390_basr (code, s390_r14, s390_r1);
4023 case OP_FCALL_MEMBASE: {
4024 call = (MonoCallInst*)ins;
4025 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4026 s390_basr (code, s390_r14, s390_r1);
4027 if (call->signature->ret->type == MONO_TYPE_R4)
4028 s390_ldebr (code, s390_f0, s390_f0);
4031 case OP_LCALL_MEMBASE:
4032 case OP_VCALL_MEMBASE:
4033 case OP_VCALL2_MEMBASE:
4034 case OP_VOIDCALL_MEMBASE:
4035 case OP_CALL_MEMBASE: {
4036 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4037 s390_basr (code, s390_r14, s390_r1);
4044 if (cfg->param_area == 0)
4045 alloca_skip = S390_MINIMAL_STACK_SIZE;
4047 alloca_skip = cfg->param_area;
4049 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4050 s390_lgr (code, s390_r1, ins->sreg1);
4051 if (ins->flags & MONO_INST_INIT)
4052 s390_lgr (code, s390_r0, ins->sreg1);
4053 s390_aghi (code, s390_r1, 14);
4054 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4055 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4056 if (cfg->method->save_lmf) {
4057 /*----------------------------------*/
4058 /* we have to adjust lmf ebp value */
4059 /*----------------------------------*/
4060 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4062 s390_lgr (code, s390_r13, cfg->frame_reg);
4063 if (s390_is_imm16(lmfOffset))
4064 s390_aghi (code, s390_r13, lmfOffset);
4066 s390_basr (code, s390_r14, 0);
4068 s390_word (code, lmfOffset);
4069 s390_agf (code, s390_r13, 0, s390_r14, 4);
4071 s390_lgr (code, s390_r14, STK_BASE);
4072 s390_sgr (code, s390_r14, s390_r1);
4073 s390_stg (code, s390_r14, 0, s390_r13,
4074 G_STRUCT_OFFSET(MonoLMF, ebp));
4076 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4077 s390_sgr (code, STK_BASE, s390_r1);
4078 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4079 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4080 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4081 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4082 if (ins->flags & MONO_INST_INIT) {
4083 s390_lgr (code, s390_r1, s390_r0);
4084 s390_lgr (code, s390_r0, ins->dreg);
4085 s390_lgr (code, s390_r14, s390_r12);
4086 s390_lghi (code, s390_r13, 0);
4087 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4089 s390_lgr (code, s390_r12, s390_r14);
4094 s390_lgr (code, s390_r2, ins->sreg1);
4095 s390_basr (code, s390_r13, 0);
4097 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4098 (gpointer) "mono_arch_throw_exception");
4099 s390_llong(code, 0);
4100 s390_lg (code, s390_r14, 0, s390_r13, 4);
4101 s390_basr (code, s390_r14, s390_r14);
4105 s390_lgr (code, s390_r2, ins->sreg1);
4106 s390_basr (code, s390_r13, 0);
4108 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4109 (gpointer) "mono_arch_rethrow_exception");
4110 s390_llong(code, 0);
4111 s390_lg (code, s390_r14, 0, s390_r13, 4);
4112 s390_basr (code, s390_r14, s390_r14);
4115 case OP_START_HANDLER: {
4116 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4118 S390_LONG (code, stg, stg, s390_r14, 0,
4119 spvar->inst_basereg,
4120 spvar->inst_offset);
4123 case OP_ENDFILTER: {
4124 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4126 if (ins->sreg1 != s390_r2)
4127 s390_lgr(code, s390_r2, ins->sreg1);
4128 S390_LONG (code, lg, lg, s390_r14, 0,
4129 spvar->inst_basereg,
4130 spvar->inst_offset);
4131 s390_br (code, s390_r14);
4134 case OP_ENDFINALLY: {
4135 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4137 S390_LONG (code, lg, lg, s390_r14, 0,
4138 spvar->inst_basereg,
4139 spvar->inst_offset);
4140 s390_br (code, s390_r14);
4143 case OP_CALL_HANDLER: {
4144 mono_add_patch_info (cfg, code-cfg->native_code,
4145 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4146 s390_brasl (code, s390_r14, 0);
4147 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4151 ins->inst_c0 = code - cfg->native_code;
4154 case OP_RELAXED_NOP:
4157 case OP_DUMMY_STORE:
4158 case OP_NOT_REACHED:
4163 EMIT_UNCOND_BRANCH(ins);
4166 s390_br (code, ins->sreg1);
4172 s390_lghi(code, ins->dreg, 1);
4174 s390_lghi(code, ins->dreg, 0);
4180 s390_lghi(code, ins->dreg, 1);
4182 s390_lghi(code, ins->dreg, 0);
4188 s390_lghi(code, ins->dreg, 1);
4190 s390_lghi(code, ins->dreg, 0);
4196 s390_lghi(code, ins->dreg, 1);
4198 s390_lghi(code, ins->dreg, 0);
4204 s390_lghi(code, ins->dreg, 1);
4206 s390_lghi(code, ins->dreg, 0);
4209 case OP_COND_EXC_EQ:
4210 case OP_COND_EXC_IEQ:
4211 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4213 case OP_COND_EXC_NE_UN:
4214 case OP_COND_EXC_INE_UN:
4215 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4217 case OP_COND_EXC_LT:
4218 case OP_COND_EXC_ILT:
4219 case OP_COND_EXC_LT_UN:
4220 case OP_COND_EXC_ILT_UN:
4221 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4223 case OP_COND_EXC_GT:
4224 case OP_COND_EXC_IGT:
4225 case OP_COND_EXC_GT_UN:
4226 case OP_COND_EXC_IGT_UN:
4227 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4229 case OP_COND_EXC_GE:
4230 case OP_COND_EXC_IGE:
4231 case OP_COND_EXC_GE_UN:
4232 case OP_COND_EXC_IGE_UN:
4233 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4235 case OP_COND_EXC_LE:
4236 case OP_COND_EXC_ILE:
4237 case OP_COND_EXC_LE_UN:
4238 case OP_COND_EXC_ILE_UN:
4239 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4241 case OP_COND_EXC_OV:
4242 case OP_COND_EXC_IOV:
4243 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4245 case OP_COND_EXC_NO:
4246 case OP_COND_EXC_INO:
4247 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4250 case OP_COND_EXC_IC:
4251 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4253 case OP_COND_EXC_NC:
4254 case OP_COND_EXC_INC:
4255 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4259 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4263 EMIT_COND_BRANCH (ins, S390_CC_NE);
4269 EMIT_COND_BRANCH (ins, S390_CC_LT);
4275 EMIT_COND_BRANCH (ins, S390_CC_GT);
4281 EMIT_COND_BRANCH (ins, S390_CC_GE);
4287 EMIT_COND_BRANCH (ins, S390_CC_LE);
4290 /* floating point opcodes */
4292 if (*((float *) ins->inst_p0) == 0) {
4293 s390_lzdr (code, ins->dreg);
4295 s390_basr (code, s390_r13, 0);
4297 s390_llong (code, ins->inst_p0);
4298 s390_lg (code, s390_r13, 0, s390_r13, 4);
4299 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4304 if (*((float *) ins->inst_p0) == 0) {
4305 s390_lzdr (code, ins->dreg);
4307 s390_basr (code, s390_r13, 0);
4309 s390_llong(code, ins->inst_p0);
4310 s390_lg (code, s390_r13, 0, s390_r13, 4);
4311 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4315 case OP_STORER8_MEMBASE_REG: {
4316 S390_LONG (code, stdy, std, ins->sreg1, 0,
4317 ins->inst_destbasereg, ins->inst_offset);
4320 case OP_LOADR8_MEMBASE: {
4321 S390_LONG (code, ldy, ld, ins->dreg, 0,
4322 ins->inst_basereg, ins->inst_offset);
4325 case OP_STORER4_MEMBASE_REG: {
4326 s390_ledbr (code, s390_f15, ins->sreg1);
4327 S390_LONG (code, stey, ste, s390_f15, 0,
4328 ins->inst_destbasereg, ins->inst_offset);
4331 case OP_LOADR4_MEMBASE: {
4332 S390_LONG (code, ldy, ld, s390_f15, 0,
4333 ins->inst_basereg, ins->inst_offset);
4334 s390_ldebr (code, ins->dreg, s390_f15);
4337 case OP_ICONV_TO_R_UN: {
4338 s390_cdfbr (code, ins->dreg, ins->sreg1);
4339 s390_ltr (code, ins->sreg1, ins->sreg1);
4340 s390_jnl (code, 12);
4341 s390_basr (code, s390_r13, 0);
4343 s390_word (code, 0x41f00000);
4344 s390_word (code, 0);
4345 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4348 case OP_LCONV_TO_R_UN: {
4349 s390_cdgbr (code, ins->dreg, ins->sreg1);
4350 s390_ltgr (code, ins->sreg1, ins->sreg1);
4351 s390_jnl (code, 12);
4352 s390_basr (code, s390_r13, 0);
4354 s390_word (code, 0x41f00000);
4355 s390_word (code, 0);
4356 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4359 case OP_LCONV_TO_R4:
4360 case OP_ICONV_TO_R4: {
4361 s390_cdgbr (code, ins->dreg, ins->sreg1);
4364 case OP_LCONV_TO_R8:
4365 case OP_ICONV_TO_R8: {
4366 s390_cdgbr (code, ins->dreg, ins->sreg1);
4369 case OP_FCONV_TO_I1:
4370 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4372 case OP_FCONV_TO_U1:
4373 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4375 case OP_FCONV_TO_I2:
4376 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4378 case OP_FCONV_TO_U2:
4379 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4381 case OP_FCONV_TO_I4:
4383 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4385 case OP_FCONV_TO_U4:
4387 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4389 case OP_FCONV_TO_I8:
4390 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4392 case OP_LCONV_TO_OVF_I: {
4393 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4395 s390_ltgr (code, ins->sreg2, ins->sreg2);
4396 s390_jnl (code, 0); CODEPTR(code, o[0]);
4397 s390_ltgr (code, ins->sreg1, ins->sreg1);
4398 s390_jnl (code, 0); CODEPTR(code, o[1]);
4399 s390_lhi (code, s390_r13, -1);
4400 s390_cgr (code, ins->sreg1, s390_r13);
4401 s390_jnz (code, 0); CODEPTR(code, o[2]);
4402 if (ins->dreg != ins->sreg2)
4403 s390_lgr (code, ins->dreg, ins->sreg2);
4404 s390_j (code, 0); CODEPTR(code, o[3]);
4405 PTRSLOT(code, o[0]);
4406 s390_jz (code, 0); CODEPTR(code, o[4]);
4407 PTRSLOT(code, o[1]);
4408 PTRSLOT(code, o[2]);
4409 mono_add_patch_info (cfg, code - cfg->native_code,
4410 MONO_PATCH_INFO_EXC, "OverflowException");
4411 s390_brasl (code, s390_r14, 0);
4412 PTRSLOT(code, o[3]);
4413 PTRSLOT(code, o[4]);
4417 s390_lpdbr (code, ins->dreg, ins->sreg1);
4421 s390_sqdbr (code, ins->dreg, ins->sreg1);
4426 s390_adbr (code, ins->dreg, src2);
4430 CHECK_SRCDST_NCOM_F;
4431 s390_sdbr (code, ins->dreg, src2);
4436 s390_mdbr (code, ins->dreg, src2);
4440 CHECK_SRCDST_NCOM_F;
4441 s390_ddbr (code, ins->dreg, src2);
4445 s390_lcdbr (code, ins->dreg, ins->sreg1);
4449 CHECK_SRCDST_NCOM_F;
4450 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4454 s390_cdbr (code, ins->sreg1, ins->sreg2);
4458 s390_cdbr (code, ins->sreg1, ins->sreg2);
4459 s390_lghi (code, ins->dreg, 1);
4461 s390_lghi (code, ins->dreg, 0);
4465 s390_cdbr (code, ins->sreg1, ins->sreg2);
4466 s390_lghi (code, ins->dreg, 1);
4468 s390_lghi (code, ins->dreg, 0);
4472 s390_cdbr (code, ins->sreg1, ins->sreg2);
4473 s390_lghi (code, ins->dreg, 1);
4475 s390_lghi (code, ins->dreg, 0);
4479 s390_cdbr (code, ins->sreg1, ins->sreg2);
4480 s390_lghi (code, ins->dreg, 1);
4482 s390_lghi (code, ins->dreg, 0);
4486 s390_cdbr (code, ins->sreg1, ins->sreg2);
4487 s390_lghi (code, ins->dreg, 1);
4489 s390_lghi (code, ins->dreg, 0);
4494 s390_jo (code, 0); CODEPTR(code, o);
4495 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4500 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4504 s390_jo (code, 0); CODEPTR(code, o);
4505 EMIT_COND_BRANCH (ins, S390_CC_LT);
4510 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4514 s390_jo (code, 0); CODEPTR(code, o);
4515 EMIT_COND_BRANCH (ins, S390_CC_GT);
4520 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4524 s390_jo (code, 0); CODEPTR(code, o);
4525 EMIT_COND_BRANCH (ins, S390_CC_GE);
4530 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4534 s390_jo (code, 0); CODEPTR(code, o);
4535 EMIT_COND_BRANCH (ins, S390_CC_LE);
4540 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4544 s390_lhi (code, s390_r13, 0x7f);
4545 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4546 s390_jz (code, 0); CODEPTR(code, o);
4547 mono_add_patch_info (cfg, code - cfg->native_code,
4548 MONO_PATCH_INFO_EXC, "ArithmeticException");
4549 s390_brasl (code, s390_r14,0);
4553 case OP_S390_MOVE: {
4554 if (ins->backend.size > 0) {
4555 if (ins->backend.size <= 256) {
4556 s390_mvc (code, ins->backend.size, ins->dreg,
4557 ins->inst_offset, ins->sreg1, ins->inst_imm);
4559 s390_lgr (code, s390_r0, ins->dreg);
4560 if (ins->inst_offset > 0) {
4561 if (s390_is_imm16 (ins->inst_offset)) {
4562 s390_aghi (code, s390_r0, ins->inst_offset);
4564 s390_basr (code, s390_r13, 0);
4566 s390_llong(code, ins->inst_offset);
4567 s390_ag (code, s390_r0, 0, s390_r13, 4);
4570 s390_lgr (code, s390_r12, ins->sreg1);
4571 if (ins->inst_imm > 0) {
4572 if (s390_is_imm16 (ins->inst_imm)) {
4573 s390_aghi (code, s390_r12, ins->inst_imm);
4575 s390_basr (code, s390_r13, 0);
4577 s390_llong(code, ins->inst_imm);
4578 s390_ag (code, s390_r12, 0, s390_r13, 4);
4581 if (s390_is_imm16 (ins->backend.size)) {
4582 s390_lghi (code, s390_r1, ins->backend.size);
4584 s390_basr (code, s390_r13, 0);
4586 s390_llong(code, ins->backend.size);
4587 s390_lg (code, s390_r1, 0, s390_r13, 4);
4589 s390_lgr (code, s390_r13, s390_r1);
4590 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4596 case OP_ATOMIC_ADD_I8: {
4597 s390_lgr (code, s390_r1, ins->sreg2);
4598 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4599 s390_agr (code, s390_r1, s390_r0);
4600 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4601 s390_jnz (code, -10);
4602 s390_lgr (code, ins->dreg, s390_r1);
4605 case OP_ATOMIC_ADD_NEW_I8: {
4606 s390_lgr (code, s390_r1, ins->sreg2);
4607 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4608 s390_agr (code, s390_r1, s390_r0);
4609 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4610 s390_jnz (code, -10);
4611 s390_lgr (code, ins->dreg, s390_r1);
4614 case OP_ATOMIC_EXCHANGE_I8: {
4615 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4616 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4617 s390_jnz (code, -6);
4618 s390_lgr (code, ins->dreg, s390_r0);
4621 case OP_ATOMIC_ADD_I4: {
4622 s390_lgfr(code, s390_r1, ins->sreg2);
4623 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4624 s390_agr (code, s390_r1, s390_r0);
4625 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4626 s390_jnz (code, -9);
4627 s390_lgfr(code, ins->dreg, s390_r1);
4630 case OP_ATOMIC_ADD_NEW_I4: {
4631 s390_lgfr(code, s390_r1, ins->sreg2);
4632 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4633 s390_agr (code, s390_r1, s390_r0);
4634 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4635 s390_jnz (code, -9);
4636 s390_lgfr(code, ins->dreg, s390_r1);
4639 case OP_ATOMIC_EXCHANGE_I4: {
4640 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4641 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4642 s390_jnz (code, -4);
4643 s390_lgfr(code, ins->dreg, s390_r0);
4646 case OP_S390_BKCHAIN: {
4647 s390_lgr (code, ins->dreg, ins->sreg1);
4648 if (s390_is_imm16 (cfg->stack_offset)) {
4649 s390_aghi (code, ins->dreg, cfg->stack_offset);
4651 s390_basr (code, s390_r13, 0);
4653 s390_llong(code, cfg->stack_offset);
4654 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4658 case OP_MEMORY_BARRIER: {
4662 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4663 g_assert_not_reached ();
4666 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4667 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4668 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4669 g_assert_not_reached ();
4674 last_offset = offset;
4677 cfg->code_len = code - cfg->native_code;
4680 /*========================= End of Function ========================*/
4682 /*------------------------------------------------------------------*/
4684 /* Name - mono_arch_register_lowlevel_calls */
4686 /* Function - Register routines to help with --trace operation. */
4688 /*------------------------------------------------------------------*/
4691 mono_arch_register_lowlevel_calls (void)
4693 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4696 /*========================= End of Function ========================*/
4698 /*------------------------------------------------------------------*/
4700 /* Name - mono_arch_patch_code */
4702 /* Function - Process the patch data created during the */
4703 /* instruction build process. This resolves jumps, */
4704 /* calls, variables etc. */
4706 /*------------------------------------------------------------------*/
4709 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4710 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4712 MonoJumpInfo *patch_info;
4714 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4715 unsigned char *ip = patch_info->ip.i + code;
4716 gconstpointer target = NULL;
4718 target = mono_resolve_patch_target (method, domain, code,
4719 patch_info, run_cctors);
4721 switch (patch_info->type) {
4722 case MONO_PATCH_INFO_IP:
4723 case MONO_PATCH_INFO_EXC_NAME:
4724 case MONO_PATCH_INFO_LDSTR:
4725 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4726 case MONO_PATCH_INFO_LDTOKEN:
4727 case MONO_PATCH_INFO_EXC:
4728 case MONO_PATCH_INFO_ABS:
4729 case MONO_PATCH_INFO_METHOD:
4730 case MONO_PATCH_INFO_INTERNAL_METHOD:
4731 case MONO_PATCH_INFO_CLASS_INIT:
4732 s390_patch_addr (ip, (guint64) target);
4734 case MONO_PATCH_INFO_SWITCH:
4735 /*----------------------------------*/
4736 /* ip points at the basr r13,0/j +4 */
4737 /* instruction the vtable value */
4738 /* follows this (i.e. ip+6) */
4739 /*----------------------------------*/
4740 *((gconstpointer *)(ip+6)) = target;
4742 case MONO_PATCH_INFO_METHODCONST:
4743 case MONO_PATCH_INFO_CLASS:
4744 case MONO_PATCH_INFO_IMAGE:
4745 case MONO_PATCH_INFO_FIELD:
4746 case MONO_PATCH_INFO_IID:
4747 target = S390_RELATIVE(target, ip);
4748 s390_patch_rel (ip, (guint64) target);
4750 case MONO_PATCH_INFO_R4:
4751 case MONO_PATCH_INFO_R8:
4752 case MONO_PATCH_INFO_METHOD_REL:
4753 g_assert_not_reached ();
4756 target = S390_RELATIVE(target, ip);
4758 s390_patch_rel (ip, (guint64) target);
4763 /*========================= End of Function ========================*/
4765 /*------------------------------------------------------------------*/
4767 /* Name - emit_load_volatile_arguments */
4769 /* Function - Emit the instructions to reload parameter regist- */
4770 /* registers for use with "tail" operations. */
4772 /* The register loading operations performed here */
4773 /* are the mirror of the store operations performed */
4774 /* in mono_arch_emit_prolog and need to be kept in */
4775 /* synchronization with it. */
4777 /*------------------------------------------------------------------*/
4780 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4783 MonoMethod *method = cfg->method;
4784 MonoMethodSignature *sig = mono_method_signature(method);
4788 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4790 if (cinfo->struct_ret) {
4791 ArgInfo *ainfo = &cinfo->ret;
4792 inst = cfg->vret_addr;
4793 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4796 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4797 ArgInfo *ainfo = cinfo->args + i;
4798 inst = cfg->args [pos];
4800 if (inst->opcode == OP_REGVAR) {
4801 if (ainfo->regtype == RegTypeGeneral)
4802 s390_lgr (code, ainfo->reg, inst->dreg);
4803 else if (ainfo->regtype == RegTypeFP) {
4804 if (inst->dreg != ainfo->reg) {
4805 if (ainfo->size == 4) {
4806 s390_ldebr (code, ainfo->reg, inst->dreg);
4808 s390_ldr (code, ainfo->reg, inst->dreg);
4812 else if (ainfo->regtype == RegTypeBase) {
4814 g_assert_not_reached ();
4816 if (ainfo->regtype == RegTypeGeneral) {
4817 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4818 g_assert_not_reached();
4819 switch (ainfo->size) {
4821 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4824 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4827 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4830 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4833 } else if (ainfo->regtype == RegTypeBase) {
4834 } else if (ainfo->regtype == RegTypeFP) {
4835 if (ainfo->size == 8)
4836 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4837 else if (ainfo->size == 4)
4838 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4840 g_assert_not_reached ();
4841 } else if (ainfo->regtype == RegTypeStructByVal) {
4842 if (ainfo->reg != STK_BASE) {
4843 switch (ainfo->size) {
4845 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4848 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4851 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4854 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4858 } else if (ainfo->regtype == RegTypeStructByAddr) {
4859 if (ainfo->reg != STK_BASE) {
4860 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4863 g_assert_not_reached ();
4871 /*========================= End of Function ========================*/
4873 /*------------------------------------------------------------------*/
4875 /* Name - mono_arch_emit_prolog */
4877 /* Function - Create the instruction sequence for a function */
4880 /*------------------------------------------------------------------*/
4883 mono_arch_emit_prolog (MonoCompile *cfg)
4885 MonoMethod *method = cfg->method;
4887 MonoMethodSignature *sig;
4889 int alloc_size, pos, max_offset, i;
4896 cfg->code_size = 512;
4898 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4900 cfg->code_size += 256;
4903 if (method->save_lmf)
4904 cfg->code_size += 200;
4906 cfg->native_code = code = g_malloc (cfg->code_size);
4908 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4910 if (cfg->arch.bkchain_reg != -1)
4911 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4913 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4914 cfg->used_int_regs |= 1 << 11;
4917 alloc_size = cfg->stack_offset;
4919 cfg->stack_usage = alloc_size;
4920 s390_lgr (code, s390_r11, STK_BASE);
4921 if (s390_is_imm16 (alloc_size)) {
4922 s390_aghi (code, STK_BASE, -alloc_size);
4924 int stackSize = alloc_size;
4925 while (stackSize > 32767) {
4926 s390_aghi (code, STK_BASE, -32767);
4929 s390_aghi (code, STK_BASE, -stackSize);
4931 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4933 if (cfg->frame_reg != STK_BASE)
4934 s390_lgr (code, s390_r11, STK_BASE);
4936 /* compute max_offset in order to use short forward jumps
4937 * we always do it on s390 because the immediate displacement
4938 * for jumps is too small
4941 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4943 bb->max_offset = max_offset;
4945 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4948 MONO_BB_FOR_EACH_INS (bb, ins)
4949 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4952 /* load arguments allocated to register from the stack */
4953 sig = mono_method_signature (method);
4956 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4958 if (cinfo->struct_ret) {
4959 ArgInfo *ainfo = &cinfo->ret;
4960 inst = cfg->vret_addr;
4961 inst->backend.size = ainfo->vtsize;
4962 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4965 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4966 ArgInfo *ainfo = cinfo->args + i;
4967 inst = cfg->args [pos];
4969 if (inst->opcode == OP_VTARG_ADDR)
4970 inst = inst->inst_left;
4972 if (inst->opcode == OP_REGVAR) {
4973 if (ainfo->regtype == RegTypeGeneral)
4974 s390_lgr (code, inst->dreg, ainfo->reg);
4975 else if (ainfo->regtype == RegTypeFP) {
4976 if (inst->dreg != ainfo->reg) {
4977 if (ainfo->size == 4) {
4978 s390_ledbr (code, inst->dreg, ainfo->reg);
4980 s390_ldr (code, inst->dreg, ainfo->reg);
4984 else if (ainfo->regtype == RegTypeBase) {
4985 s390_lgr (code, s390_r13, STK_BASE);
4986 s390_aghi (code, s390_r13, alloc_size);
4987 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4989 g_assert_not_reached ();
4991 if (cfg->verbose_level > 2)
4992 g_print ("Argument %d assigned to register %s\n",
4993 pos, mono_arch_regname (inst->dreg));
4995 if (ainfo->regtype == RegTypeGeneral) {
4996 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4997 g_assert_not_reached();
4998 switch (ainfo->size) {
5000 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5003 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5006 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5009 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5012 } else if (ainfo->regtype == RegTypeBase) {
5013 } else if (ainfo->regtype == RegTypeFP) {
5014 if (ainfo->size == 8)
5015 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5016 else if (ainfo->size == 4)
5017 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5019 g_assert_not_reached ();
5020 } else if (ainfo->regtype == RegTypeStructByVal) {
5021 int doffset = inst->inst_offset;
5023 if (ainfo->reg != STK_BASE)
5027 s390_lgr (code, s390_r13, STK_BASE);
5028 s390_aghi (code, s390_r13, alloc_size);
5031 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5032 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5037 if (ainfo->reg == STK_BASE)
5038 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5039 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5042 if (ainfo->reg == STK_BASE)
5043 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5044 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5047 if (ainfo->reg == STK_BASE)
5048 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5049 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5052 if (ainfo->reg == STK_BASE)
5053 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5054 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5057 } else if (ainfo->regtype == RegTypeStructByAddr) {
5058 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5059 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5061 g_assert_not_reached ();
5066 if (method->save_lmf) {
5067 /*---------------------------------------------------------------*/
5068 /* we build the MonoLMF structure on the stack - see mini-s390.h */
5069 /*---------------------------------------------------------------*/
5070 lmfOffset = alloc_size - sizeof(MonoLMF);
5072 s390_lgr (code, s390_r13, cfg->frame_reg);
5073 s390_aghi (code, s390_r13, lmfOffset);
5075 /*---------------------------------------------------------------*/
5076 /* Preserve the parameter registers while we fix up the lmf */
5077 /*---------------------------------------------------------------*/
5078 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5079 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5081 /*---------------------------------------------------------------*/
5082 /* On return from this call r2 have the address of the &lmf */
5083 /*---------------------------------------------------------------*/
5084 s390_basr(code, s390_r14, 0);
5086 mono_add_patch_info (cfg, code - cfg->native_code,
5087 MONO_PATCH_INFO_INTERNAL_METHOD,
5088 (gpointer)"mono_get_lmf_addr");
5089 s390_llong(code, 0);
5090 s390_lg (code, s390_r1, 0, s390_r14, 4);
5091 s390_basr (code, s390_r14, s390_r1);
5093 /*---------------------------------------------------------------*/
5094 /* Set lmf.lmf_addr = jit_tls->lmf */
5095 /*---------------------------------------------------------------*/
5096 s390_stg (code, s390_r2, 0, s390_r13,
5097 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5099 /*---------------------------------------------------------------*/
5100 /* Get current lmf */
5101 /*---------------------------------------------------------------*/
5102 s390_lg (code, s390_r0, 0, s390_r2, 0);
5104 /*---------------------------------------------------------------*/
5105 /* Set our lmf as the current lmf */
5106 /*---------------------------------------------------------------*/
5107 s390_stg (code, s390_r13, 0, s390_r2, 0);
5109 /*---------------------------------------------------------------*/
5110 /* Have our lmf.previous_lmf point to the last lmf */
5111 /*---------------------------------------------------------------*/
5112 s390_stg (code, s390_r0, 0, s390_r13,
5113 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5115 /*---------------------------------------------------------------*/
5116 /* save method info */
5117 /*---------------------------------------------------------------*/
5118 s390_basr (code, s390_r1, 0);
5120 s390_llong (code, method);
5121 s390_lg (code, s390_r1, 0, s390_r1, 4);
5122 s390_stg (code, s390_r1, 0, s390_r13,
5123 G_STRUCT_OFFSET(MonoLMF, method));
5125 /*---------------------------------------------------------------*/
5126 /* save the current IP */
5127 /*---------------------------------------------------------------*/
5128 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5129 s390_basr (code, s390_r1, 0);
5130 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5132 /*---------------------------------------------------------------*/
5133 /* Save general and floating point registers */
5134 /*---------------------------------------------------------------*/
5135 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5136 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5137 for (i = 0; i < 16; i++) {
5138 s390_std (code, i, 0, s390_r13,
5139 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5142 /*---------------------------------------------------------------*/
5143 /* Restore the parameter registers now that we've set up the lmf */
5144 /*---------------------------------------------------------------*/
5145 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5146 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5150 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5152 cfg->code_len = code - cfg->native_code;
5153 g_assert (cfg->code_len < cfg->code_size);
5158 /*========================= End of Function ========================*/
5160 /*------------------------------------------------------------------*/
5162 /* Name - mono_arch_emit_epilog */
5164 /* Function - Emit the instructions for a function epilog. */
5166 /*------------------------------------------------------------------*/
5169 mono_arch_emit_epilog (MonoCompile *cfg)
5171 MonoMethod *method = cfg->method;
5174 int max_epilog_size = 96;
5176 if (cfg->method->save_lmf)
5177 max_epilog_size += 128;
5179 if (mono_jit_trace_calls != NULL)
5180 max_epilog_size += 128;
5182 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5183 max_epilog_size += 128;
5185 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5186 cfg->code_size *= 2;
5187 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5188 mono_jit_stats.code_reallocs++;
5191 code = cfg->native_code + cfg->code_len;
5193 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5194 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5198 if (method->save_lmf)
5199 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5201 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
5202 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5204 code = backUpStackPtr(cfg, code);
5206 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5207 s390_br (code, s390_r14);
5209 cfg->code_len = code - cfg->native_code;
5211 g_assert (cfg->code_len < cfg->code_size);
5215 /*========================= End of Function ========================*/
5217 /*------------------------------------------------------------------*/
5219 /* Name - mono_arch_emit_exceptions */
5221 /* Function - Emit the blocks to handle exception conditions. */
5223 /*------------------------------------------------------------------*/
5226 mono_arch_emit_exceptions (MonoCompile *cfg)
5228 MonoJumpInfo *patch_info;
5234 MonoClass *exc_classes [MAX_EXC];
5235 guint8 *exc_throw_start [MAX_EXC];
5237 for (patch_info = cfg->patch_info;
5239 patch_info = patch_info->next) {
5240 if (patch_info->type == MONO_PATCH_INFO_EXC)
5244 code_size = exc_count * 48;
5246 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5247 cfg->code_size *= 2;
5248 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5249 mono_jit_stats.code_reallocs++;
5252 code = cfg->native_code + cfg->code_len;
5254 /*---------------------------------------------------------------------*/
5255 /* Add code to raise exceptions */
5256 /*---------------------------------------------------------------------*/
5257 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5258 switch (patch_info->type) {
5259 case MONO_PATCH_INFO_EXC: {
5260 guint8 *ip = patch_info->ip.i + cfg->native_code;
5261 MonoClass *exc_class;
5264 /*-----------------------------------------------------*/
5265 /* Patch the branch in epilog to come here */
5266 /*-----------------------------------------------------*/
5267 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5269 exc_class = mono_class_from_name (mono_defaults.corlib,
5271 patch_info->data.name);
5272 g_assert (exc_class);
5273 throw_ip = patch_info->ip.i;
5275 for (iExc = 0; iExc < nThrows; ++iExc)
5276 if (exc_classes [iExc] == exc_class)
5279 if (iExc < nThrows) {
5280 s390_jcl (code, S390_CC_UN,
5281 (guint64) exc_throw_start [iExc]);
5282 patch_info->type = MONO_PATCH_INFO_NONE;
5285 if (nThrows < MAX_EXC) {
5286 exc_classes [nThrows] = exc_class;
5287 exc_throw_start [nThrows] = code;
5290 /*---------------------------------------------*/
5291 /* Patch the parameter passed to the handler */
5292 /*---------------------------------------------*/
5293 s390_basr (code, s390_r13, 0);
5295 // s390_llong(code, patch_info->data.target);
5296 s390_llong(code, exc_class->type_token);
5297 /*---------------------------------------------*/
5298 /* Load return address & parameter register */
5299 /*---------------------------------------------*/
5300 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5301 cfg->native_code + 8), code));
5302 s390_lg (code, s390_r2, 0, s390_r13, 4);
5303 /*---------------------------------------------*/
5304 /* Reuse the current patch to set the jump */
5305 /*---------------------------------------------*/
5306 s390_basr (code, s390_r13, 0);
5308 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5309 patch_info->data.name = "mono_arch_throw_corlib_exception";
5310 patch_info->ip.i = code - cfg->native_code;
5311 s390_llong(code, 0);
5312 s390_lg (code, s390_r1, 0, s390_r13, 4);
5313 s390_br (code, s390_r1);
5323 cfg->code_len = code - cfg->native_code;
5325 g_assert (cfg->code_len < cfg->code_size);
5329 /*========================= End of Function ========================*/
5331 /*------------------------------------------------------------------*/
5333 /* Name - mono_arch_setup_jit_tls_data */
5335 /* Function - Setup the JIT's Thread Level Specific Data. */
5337 /*------------------------------------------------------------------*/
5340 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5342 if (!tls_offset_inited) {
5343 tls_offset_inited = TRUE;
5347 __asm__ ("\tear\t%r1,0\n"
5354 : "=r" (appdomain_tls_offset),
5355 "=r" (thread_tls_offset),
5356 "=r" (lmf_tls_offset)
5357 : "r" (&tls_appdomain),
5358 "r" (&tls_current_object),
5359 "r" (&mono_lmf_addr)
5365 if (!lmf_addr_key_inited) {
5366 lmf_addr_key_inited = TRUE;
5367 pthread_key_create (&lmf_addr_key, NULL);
5369 pthread_setspecific (lmf_addr_key, &tls->lmf);
5373 /*========================= End of Function ========================*/
5375 /*------------------------------------------------------------------*/
5377 /* Name - mono_arch_free_jit_tls_data */
5379 /* Function - Free tls data. */
5381 /*------------------------------------------------------------------*/
5384 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5388 /*========================= End of Function ========================*/
5390 /*------------------------------------------------------------------*/
5392 /* Name - mono_arch_emit_inst_for_method */
5394 /*------------------------------------------------------------------*/
5397 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5402 /*========================= End of Function ========================*/
5404 /*------------------------------------------------------------------*/
5406 /* Name - mono_arch_decompose_opts */
5408 /* Function - Decompose opcode into a System z opcode. */
5410 /*------------------------------------------------------------------*/
5413 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5416 * Have to rename these to avoid being decomposed normally, since the normal
5417 * decomposition does not work on S390.
5419 switch (ins->opcode) {
5421 ins->opcode = OP_S390_ISUB_OVF;
5423 case OP_ISUB_OVF_UN:
5424 ins->opcode = OP_S390_ISUB_OVF_UN;
5427 ins->opcode = OP_S390_IADD_OVF;
5429 case OP_IADD_OVF_UN:
5430 ins->opcode = OP_S390_IADD_OVF_UN;
5433 ins->opcode = OP_S390_LADD_OVF;
5435 case OP_LADD_OVF_UN:
5436 ins->opcode = OP_S390_LADD_OVF_UN;
5439 ins->opcode = OP_S390_LSUB_OVF;
5441 case OP_LSUB_OVF_UN:
5442 ins->opcode = OP_S390_LSUB_OVF_UN;
5449 /*========================= End of Function ========================*/
5451 /*------------------------------------------------------------------*/
5453 /* Name - mono_arch_print_tree */
5455 /* Function - Print platform-specific opcode details. */
5457 /* Returns - 1 - opcode details have been printed */
5458 /* 0 - opcode details have not been printed */
5460 /*------------------------------------------------------------------*/
5463 mono_arch_print_tree (MonoInst *tree, int arity)
5467 switch (tree->opcode) {
5468 case OP_S390_LOADARG:
5469 case OP_S390_ARGREG:
5470 case OP_S390_ARGPTR:
5471 printf ("[0x%lx(%s)]", tree->inst_offset,
5472 mono_arch_regname (tree->inst_basereg));
5475 case OP_S390_STKARG:
5476 printf ("[0x%lx(previous_frame)]",
5481 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5482 tree->inst_offset, tree->backend.size,
5483 mono_arch_regname(tree->dreg),
5485 mono_arch_regname(tree->sreg1));
5488 case OP_S390_SETF4RET:
5489 printf ("[f%s,f%s]",
5490 mono_arch_regname (tree->dreg),
5491 mono_arch_regname (tree->sreg1));
5495 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5497 mono_arch_regname (tree->sreg1));
5500 case OP_S390_BKCHAIN:
5501 printf ("[previous_frame(%s)]",
5502 mono_arch_regname (tree->sreg1));
5510 /*========================= End of Function ========================*/
5512 /*------------------------------------------------------------------*/
5514 /* Name - mono_arch_regalloc_cost */
5516 /* Function - Determine the cost, in the number of memory */
5517 /* references, of the action of allocating the var- */
5518 /* iable VMV into a register during global register */
5521 /* Returns - Cost */
5523 /*------------------------------------------------------------------*/
5526 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5532 /*========================= End of Function ========================*/
5534 /*------------------------------------------------------------------*/
5536 /* Name - mono_arch_get_domain_intrinsic */
5542 /*------------------------------------------------------------------*/
5545 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5549 if (appdomain_tls_offset == -1)
5552 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5553 ins->inst_offset = appdomain_tls_offset;
5557 /*========================= End of Function ========================*/
5559 /*------------------------------------------------------------------*/
5561 /* Name - mono_arch_flush_register_windows */
5567 /*------------------------------------------------------------------*/
5570 mono_arch_flush_register_windows (void)
5574 /*========================= End of Function ========================*/
5576 /*------------------------------------------------------------------*/
5578 /* Name - mono_arch_get_lmf_addr */
5584 /*------------------------------------------------------------------*/
5587 mono_arch_get_lmf_addr (void)
5589 return pthread_getspecific (lmf_addr_key);
5592 /*========================= End of Function ========================*/
5594 /*------------------------------------------------------------------*/
5596 /* Name - mono_arch_is_inst_imm */
5598 /* Function - Determine if operand qualifies as an immediate */
5599 /* value. For s390 this is a value -32768-32768 */
5601 /* Returns - True|False - is [not] immediate value. */
5603 /*------------------------------------------------------------------*/
5606 mono_arch_is_inst_imm (gint64 imm)
5608 return s390_is_imm16 (imm);
5611 /*========================= End of Function ========================*/
5613 /*------------------------------------------------------------------*/
5615 /* Name - mono_arch_get_patch_offset */
5617 /* Function - Dummy entry point until s390x supports aot. */
5619 /* Returns - Offset for patch. */
5621 /*------------------------------------------------------------------*/
5624 mono_arch_get_patch_offset (guint8 *code)
5629 /*========================= End of Function ========================*/
5631 /*------------------------------------------------------------------*/
5633 /* Name - mono_arch_context_get_int_reg. */
5637 /* Returns - Offset for patch. */
5639 /*------------------------------------------------------------------*/
5642 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5644 /* FIXME: implement */
5645 g_assert_not_reached ();
5649 /*========================= End of Function ========================*/
5651 /*------------------------------------------------------------------*/
5653 /* Name - mono_arch_get_this_arg_from_call. */
5657 /*------------------------------------------------------------------*/
5660 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5662 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5664 return (gpointer) lmf->gregs [s390_r2];
5667 /*========================= End of Function ========================*/
5669 /*------------------------------------------------------------------*/
5671 /* Name - get_delegate_invoke_impl. */
5675 /*------------------------------------------------------------------*/
5678 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5680 guint8 *code, *start;
5685 start = code = mono_global_codeman_reserve (size);
5687 /* Replace the this argument with the target */
5688 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5689 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5690 s390_br (code, s390_r1);
5691 g_assert ((code - start) <= size);
5693 mono_arch_flush_icache (start, size);
5697 size = 32 + param_count * 8;
5698 start = code = mono_global_codeman_reserve (size);
5700 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5701 /* slide down the arguments */
5702 for (i = 0; i < param_count; ++i) {
5703 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5705 s390_br (code, s390_r1);
5707 g_assert ((code - start) <= size);
5709 mono_arch_flush_icache (start, size);
5713 *code_len = code - start;
5718 /*========================= End of Function ========================*/
5720 /*------------------------------------------------------------------*/
5722 /* Name - mono_arch_get_delegate_invoke_impls. */
5726 /*------------------------------------------------------------------*/
5729 mono_arch_get_delegate_invoke_impls (void)
5736 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5737 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
5739 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5740 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5741 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
5747 /*========================= End of Function ========================*/
5749 /*------------------------------------------------------------------*/
5751 /* Name - mono_arch_get_delegate_invoke_impl. */
5755 /*------------------------------------------------------------------*/
5758 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5760 guint8 *code, *start;
5762 /* FIXME: Support more cases */
5763 if (MONO_TYPE_ISSTRUCT (sig->ret))
5767 static guint8* cached = NULL;
5773 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5775 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5777 mono_memory_barrier ();
5781 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5784 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5786 for (i = 0; i < sig->param_count; ++i)
5787 if (!mono_is_regsize_var (sig->params [i]))
5791 code = cache [sig->param_count];
5795 if (mono_aot_only) {
5796 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5797 start = mono_aot_get_trampoline (name);
5800 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5803 mono_memory_barrier ();
5805 cache [sig->param_count] = start;
5810 /*========================= End of Function ========================*/
5812 /*------------------------------------------------------------------*/
5814 /* Name - mono_arch_build_imt_thunk. */
5818 /*------------------------------------------------------------------*/
5821 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5822 MonoIMTCheckItem **imt_entries, int count,
5823 gpointer fail_tramp)
5827 guchar *code, *start;
5829 for (i = 0; i < count; ++i) {
5830 MonoIMTCheckItem *item = imt_entries [i];
5831 if (item->is_equals) {
5832 if (item->check_target_idx) {
5833 if (!item->compare_done)
5834 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5835 if (item->has_target_code)
5836 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5838 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5842 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5844 if (!item->has_target_code)
5845 item->chunk_size += LOAD_SIZE;
5847 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5848 #if ENABLE_WRONG_METHOD_CHECK
5849 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5854 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5855 imt_entries [item->check_target_idx]->compare_done = TRUE;
5857 size += item->chunk_size;
5861 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5863 code = mono_domain_code_reserve (domain, size);
5867 for (i = 0; i < count; ++i) {
5868 MonoIMTCheckItem *item = imt_entries [i];
5869 item->code_target = (guint8 *) code;
5870 if (item->is_equals) {
5871 if (item->check_target_idx) {
5872 if (!item->compare_done) {
5873 s390_basr (code, s390_r13, s390_r0);
5875 s390_llong(code, item->key);
5876 s390_lg (code, s390_r0, 0, s390_r13, 4);
5877 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5879 item->jmp_code = (guint8*) code;
5880 s390_jcl (code, S390_CC_NE, 0);
5882 s390_basr (code, s390_r13, s390_r0);
5884 if (item->has_target_code) {
5885 s390_llong(code, item->value.target_code);
5886 s390_lg (code, s390_r1, 0, s390_r13, 4);
5888 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5889 s390_lg (code, s390_r1, 0, s390_r13, 4);
5890 s390_lg (code, s390_r1, 0, s390_r1, 0);
5892 s390_br (code, s390_r1);
5897 s390_basr (code, s390_r13, s390_r0);
5899 s390_llong(code, item->key);
5900 s390_lg (code, s390_r0, 0, s390_r13, 4);
5901 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5902 item->jmp_code = (guint8*) code;
5903 s390_jcl (code, S390_CC_NE, 0);
5904 s390_basr (code, s390_r13, s390_r0);
5906 if (item->has_target_code) {
5907 s390_llong(code, item->value.target_code);
5908 s390_lg (code, s390_r1, 0, s390_r13, 4);
5911 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5912 s390_lg (code, s390_r1, 0, s390_r13, 4);
5913 s390_lg (code, s390_r1, 0, s390_r1, 0);
5915 s390_br (code, s390_r1);
5916 target = S390_RELATIVE(code, item->jmp_code);
5917 s390_patch_rel(item->jmp_code+2, target);
5918 s390_basr (code, s390_r13, s390_r0);
5920 s390_llong(code, fail_tramp);
5921 s390_lg (code, s390_r1, 0, s390_r13, 4);
5922 s390_br (code, s390_r1);
5923 item->jmp_code = NULL;
5925 /* enable the commented code to assert on wrong method */
5926 #if ENABLE_WRONG_METHOD_CHECK
5927 g_assert_not_reached ();
5929 s390_basr (code, s390_r13, s390_r0);
5931 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5932 s390_lg (code, s390_r1, 0, s390_r13, 4);
5933 s390_lg (code, s390_r1, 0, s390_r1, 0);
5934 s390_br (code, s390_r1);
5935 #if ENABLE_WRONG_METHOD_CHECK
5936 g_assert_not_reached ();
5941 s390_basr (code, s390_r13, s390_r0);
5943 s390_llong(code, item->key);
5944 s390_lg (code, s390_r0, 0, s390_r13, 4);
5945 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5946 item->jmp_code = (guint8 *) code;
5947 s390_jcl (code, S390_CC_GE, 0);
5950 /* patch the branches to get to the target items */
5951 for (i = 0; i < count; ++i) {
5952 MonoIMTCheckItem *item = imt_entries [i];
5953 if (item->jmp_code) {
5954 if (item->check_target_idx) {
5956 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5958 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5963 mono_arch_flush_icache ((guint8*)start, (code - start));
5966 mono_stats.imt_thunks_size += (code - start);
5968 g_assert (code - start <= size);
5973 /*========================= End of Function ========================*/
5975 /*------------------------------------------------------------------*/
5977 /* Name - mono_arch_find_imt_method. */
5979 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5980 /* found in the save area. */
5982 /*------------------------------------------------------------------*/
5985 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5987 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5989 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
5992 /*========================= End of Function ========================*/