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 */
335 gint64 gr[5]; /* R2-R6 */
336 gdouble fp[3]; /* F0-F2 */
337 } __attribute__ ((packed)) RegParm;
339 /*========================= End of Typedefs ========================*/
341 /*------------------------------------------------------------------*/
342 /* P r o t o t y p e s */
343 /*------------------------------------------------------------------*/
345 static void indent (int);
346 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
347 static void decodeParm (MonoType *, void *, int);
348 static void enter_method (MonoMethod *, RegParm *, char *);
349 static void leave_method (MonoMethod *, ...);
350 static gboolean is_regsize_var (MonoType *);
351 static inline void add_general (guint *, size_data *, ArgInfo *);
352 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
353 static inline void add_float (guint *, size_data *, ArgInfo *);
354 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
355 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
356 gpointer mono_arch_get_lmf_addr (void);
357 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
358 static void catch_SIGILL(int, siginfo_t *, void *);
360 /*========================= End of Prototypes ======================*/
362 /*------------------------------------------------------------------*/
363 /* G l o b a l V a r i a b l e s */
364 /*------------------------------------------------------------------*/
366 int mono_exc_esp_offset = 0;
368 static int indent_level = 0;
372 static gboolean tls_offset_inited = FALSE;
374 static int appdomain_tls_offset = -1,
375 thread_tls_offset = -1;
377 pthread_key_t lmf_addr_key;
379 gboolean lmf_addr_key_inited = FALSE;
385 extern __thread MonoDomain *tls_appdomain;
386 extern __thread MonoThread *tls_current_object;
387 extern __thread gpointer mono_lmf_addr;
391 /*====================== End of Global Variables ===================*/
393 /*------------------------------------------------------------------*/
395 /* Name - mono_arch_regname */
397 /* Function - Returns the name of the register specified by */
398 /* the input parameter. */
400 /*------------------------------------------------------------------*/
403 mono_arch_regname (int reg) {
404 static const char * rnames[] = {
405 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
406 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
407 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
411 if (reg >= 0 && reg < 16)
417 /*========================= End of Function ========================*/
419 /*------------------------------------------------------------------*/
421 /* Name - mono_arch_fregname */
423 /* Function - Returns the name of the register specified by */
424 /* the input parameter. */
426 /*------------------------------------------------------------------*/
429 mono_arch_fregname (int reg) {
430 static const char * rnames[] = {
431 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
432 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
433 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
437 if (reg >= 0 && reg < 16)
443 /*========================= End of Function ========================*/
445 /*------------------------------------------------------------------*/
447 /* Name - arch_get_argument_info */
449 /* Function - Gathers information on parameters such as size, */
450 /* alignment, and padding. arg_info should be large */
451 /* enough to hold param_count + 1 entries. */
453 /* Parameters - @csig - Method signature */
454 /* @param_count - No. of parameters to consider */
455 /* @arg_info - An array to store the result info */
457 /* Returns - Size of the activation frame */
459 /*------------------------------------------------------------------*/
462 mono_arch_get_argument_info (MonoMethodSignature *csig,
464 MonoJitArgumentInfo *arg_info)
466 int k, frame_size = 0;
467 int size, align, pad;
470 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
471 frame_size += sizeof (gpointer);
475 arg_info [0].offset = offset;
478 frame_size += sizeof (gpointer);
482 arg_info [0].size = frame_size;
484 for (k = 0; k < param_count; k++) {
487 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
489 size = mini_type_stack_size (NULL, csig->params [k], &align);
491 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
492 arg_info [k].pad = pad;
494 arg_info [k + 1].pad = 0;
495 arg_info [k + 1].size = size;
497 arg_info [k + 1].offset = offset;
501 align = MONO_ARCH_FRAME_ALIGNMENT;
502 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
503 arg_info [k].pad = pad;
508 /*========================= End of Function ========================*/
510 /*------------------------------------------------------------------*/
512 /* Name - retFitsInReg. */
514 /* Function - Determines if a value can be returned in one or */
517 /*------------------------------------------------------------------*/
519 static inline gboolean
520 retFitsInReg(guint32 size)
535 /*========================= End of Function ========================*/
537 /*------------------------------------------------------------------*/
539 /* Name - backStackPtr. */
541 /* Function - Restore Stack Pointer to previous frame. */
543 /*------------------------------------------------------------------*/
545 static inline guint8 *
546 backUpStackPtr(MonoCompile *cfg, guint8 *code)
548 int stackSize = cfg->stack_usage;
550 if (s390_is_imm16 (stackSize)) {
551 s390_aghi (code, STK_BASE, stackSize);
553 while (stackSize > 32767) {
554 s390_aghi (code, STK_BASE, 32767);
557 s390_aghi (code, STK_BASE, stackSize);
562 /*========================= End of Function ========================*/
564 /*------------------------------------------------------------------*/
568 /* Function - Perform nice indenting to current level */
570 /*------------------------------------------------------------------*/
576 indent_level += diff;
583 indent_level += diff;
586 /*========================= End of Function ========================*/
588 /*------------------------------------------------------------------*/
590 /* Name - decodeParm */
592 /* Function - Decode a parameter for the trace. */
594 /*------------------------------------------------------------------*/
597 decodeParm(MonoType *type, void *curParm, int size)
602 printf("[BYREF:%p], ", *((char **) curParm));
604 simpleType = mono_type_get_underlying_type(type)->type;
606 switch (simpleType) {
608 printf ("[INTPTR:%p], ", *((int **) curParm));
611 printf ("[UINTPTR:%p], ", *((int **) curParm));
613 case MONO_TYPE_BOOLEAN :
614 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
616 case MONO_TYPE_CHAR :
617 printf ("[CHAR:%c], ", *((int *) curParm));
620 printf ("[INT1:%ld], ", *((gint64 *) curParm));
623 printf ("[INT2:%ld], ", *((gint64 *) curParm));
626 printf ("[INT4:%ld], ", *((gint64 *) curParm));
629 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
632 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
635 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
638 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
640 case MONO_TYPE_STRING : {
641 MonoString *s = *((MonoString **) curParm);
643 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
644 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
646 printf("[STRING:null], ");
650 case MONO_TYPE_CLASS :
651 case MONO_TYPE_OBJECT : {
652 MonoObject *obj = *((MonoObject **) curParm);
654 if ((obj) && (obj->vtable)) {
655 printf("[CLASS/OBJ:");
656 class = obj->vtable->klass;
657 printf("%p [%p] ",obj,curParm);
658 if (class == mono_defaults.string_class) {
659 printf("[STRING:%p:%s]",
660 obj, mono_string_to_utf8 ((MonoString *) obj));
661 } else if (class == mono_defaults.int32_class) {
662 printf("[INT32:%p:%d]",
663 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
666 class->name_space, class->name, obj);
669 printf("[OBJECT:null], ");
674 printf("[PTR:%p], ", *((gpointer **) (curParm)));
676 case MONO_TYPE_FNPTR :
677 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
679 case MONO_TYPE_ARRAY :
680 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
682 case MONO_TYPE_SZARRAY :
683 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
686 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
689 printf("[FLOAT4:%g], ", *((float *) (curParm)));
692 printf("[FLOAT8:%g], ", *((double *) (curParm)));
694 case MONO_TYPE_VALUETYPE : {
696 MonoMarshalType *info;
698 if (type->data.klass->enumtype) {
699 simpleType = mono_class_enum_basetype (type->data.klass)->type;
700 printf("{VALUETYPE} - ");
704 info = mono_marshal_load_type_info (type->data.klass);
706 if ((info->native_size == sizeof(float)) &&
707 (info->num_fields == 1) &&
708 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
709 printf("[FLOAT4:%f], ", *((float *) (curParm)));
713 if ((info->native_size == sizeof(double)) &&
714 (info->num_fields == 1) &&
715 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
716 printf("[FLOAT8:%g], ", *((double *) (curParm)));
720 printf("[VALUETYPE:");
721 for (i = 0; i < size; i++)
722 printf("%02x,", *((guint8 *)curParm+i));
726 case MONO_TYPE_TYPEDBYREF: {
728 printf("[TYPEDBYREF:");
729 for (i = 0; i < size; i++)
730 printf("%02x,", *((guint8 *)curParm+i));
735 printf("[?? - %d], ",simpleType);
740 /*========================= End of Function ========================*/
742 /*------------------------------------------------------------------*/
744 /* Name - enter_method */
746 /* Function - Perform tracing of the entry to the current */
749 /*------------------------------------------------------------------*/
752 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
754 int i, oParm = 0, iParm = 0;
757 MonoMethodSignature *sig;
764 fname = mono_method_full_name (method, TRUE);
766 printf ("ENTER: %s ", fname);
769 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
770 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
775 sig = mono_method_signature (method);
777 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
779 if (cinfo->struct_ret) {
780 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
785 gpointer *this = (gpointer *) rParm->gr[iParm];
786 obj = (MonoObject *) this;
787 if (method->klass->valuetype) {
789 printf("this:[value:%p:%016lx], ",
790 this, *((guint64 *)(this+sizeof(MonoObject))));
792 printf ("this:[NULL], ");
795 class = obj->vtable->klass;
796 if (class == mono_defaults.string_class) {
797 printf ("this:[STRING:%p:%s], ",
798 obj, mono_string_to_utf8 ((MonoString *)obj));
800 printf ("this:%p[%s.%s], ",
801 obj, class->name_space, class->name);
804 printf ("this:NULL, ");
809 for (i = 0; i < sig->param_count; ++i) {
810 ainfo = &cinfo->args[i + oParm];
811 switch (ainfo->regtype) {
812 case RegTypeGeneral :
813 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
816 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
819 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
821 case RegTypeStructByVal :
822 if (ainfo->reg != STK_BASE) {
823 int offset = sizeof(glong) - ainfo->size;
824 curParm = &(rParm->gr[ainfo->reg-2])+offset;
827 curParm = sp+ainfo->offset;
829 if (retFitsInReg (ainfo->vtsize))
830 decodeParm(sig->params[i],
834 decodeParm(sig->params[i],
835 *((char **) curParm),
838 case RegTypeStructByAddr :
839 if (ainfo->reg != STK_BASE)
840 curParm = &(rParm->gr[ainfo->reg-2]);
842 curParm = sp+ainfo->offset;
844 decodeParm(sig->params[i],
845 *((char **) curParm),
857 /*========================= End of Function ========================*/
859 /*------------------------------------------------------------------*/
861 /* Name - leave_method */
865 /*------------------------------------------------------------------*/
868 leave_method (MonoMethod *method, ...)
875 va_start(ap, method);
877 fname = mono_method_full_name (method, TRUE);
879 printf ("LEAVE: %s", fname);
882 type = mono_method_signature (method)->ret;
885 switch (type->type) {
888 case MONO_TYPE_BOOLEAN: {
889 int val = va_arg (ap, int);
891 printf ("[TRUE:%d]", val);
897 case MONO_TYPE_CHAR: {
898 int val = va_arg (ap, int);
899 printf ("[CHAR:%d]", val);
903 int val = va_arg (ap, int);
904 printf ("[INT1:%d]", val);
908 int val = va_arg (ap, int);
909 printf ("[UINT1:%d]", val);
913 int val = va_arg (ap, int);
914 printf ("[INT2:%d]", val);
918 int val = va_arg (ap, int);
919 printf ("[UINT2:%d]", val);
923 int val = va_arg (ap, int);
924 printf ("[INT4:%d]", val);
928 int val = va_arg (ap, int);
929 printf ("[UINT4:%d]", val);
933 gint64 val = va_arg (ap, gint64);
934 printf ("[INT:%ld]", val);
939 gint64 val = va_arg (ap, gint64);
940 printf ("[UINT:%lu]", val);
944 case MONO_TYPE_STRING: {
945 MonoString *s = va_arg (ap, MonoString *);
948 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
949 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
951 printf ("[STRING:null], ");
954 case MONO_TYPE_CLASS:
955 case MONO_TYPE_OBJECT: {
956 MonoObject *o = va_arg (ap, MonoObject *);
958 if ((o) && (o->vtable)) {
959 if (o->vtable->klass == mono_defaults.boolean_class) {
960 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
961 } else if (o->vtable->klass == mono_defaults.int32_class) {
962 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
963 } else if (o->vtable->klass == mono_defaults.int64_class) {
964 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
966 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
968 printf ("[OBJECT:%p]", o);
973 case MONO_TYPE_FNPTR:
974 case MONO_TYPE_ARRAY:
975 case MONO_TYPE_SZARRAY: {
976 gpointer p = va_arg (ap, gpointer);
977 printf ("[result=%p]", p);
981 gint64 l = va_arg (ap, gint64);
982 printf ("[LONG:%ld]", l);
986 guint64 l = va_arg (ap, guint64);
987 printf ("[ULONG:%lu]", l);
991 double f = va_arg (ap, double);
992 printf ("[FLOAT4:%g]\n", f);
996 double f = va_arg (ap, double);
997 printf ("[FLOAT8:%g]\n", f);
1000 case MONO_TYPE_VALUETYPE: {
1001 MonoMarshalType *info;
1002 if (type->data.klass->enumtype) {
1003 type = mono_class_enum_basetype (type->data.klass);
1008 info = mono_marshal_load_type_info (type->data.klass);
1010 if ((info->native_size == sizeof(float)) &&
1011 (info->num_fields == 1) &&
1012 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1013 double f = va_arg (ap, double);
1014 printf("[FLOAT4:%g]\n", (double) f);
1018 if ((info->native_size == sizeof(double)) &&
1019 (info->num_fields == 1) &&
1020 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1021 double f = va_arg (ap, double);
1022 printf("[FLOAT8:%g]\n", f);
1026 size = mono_type_size (type, &align);
1029 guint32 p = va_arg (ap, guint32);
1030 printf ("[%02x]\n",p);
1034 guint32 p = va_arg (ap, guint32);
1035 printf ("[%04x]\n",p);
1039 guint32 p = va_arg (ap, guint32);
1040 printf ("[%08x]\n",p);
1044 guint64 p = va_arg (ap, guint64);
1045 printf ("[%016lx]\n",p);
1049 gpointer p = va_arg (ap, gpointer);
1050 printf ("[VALUETYPE] %p\n",p);
1056 case MONO_TYPE_TYPEDBYREF: {
1057 guint8 *p = va_arg (ap, gpointer);
1059 size = mono_type_size (type, &align);
1066 for (j = 0; p && j < size; j++)
1067 printf ("%02x,", p [j]);
1071 printf ("[TYPEDBYREF]\n");
1076 printf ("(unknown return type %x)",
1077 mono_method_signature (method)->ret->type);
1080 ip = ((gint64) __builtin_return_address (0));
1081 printf (" ip: %p\n", (gpointer) ip);
1084 /*========================= End of Function ========================*/
1086 /*------------------------------------------------------------------*/
1088 /* Name - catch_SIGILL */
1090 /* Function - Catch SIGILL as a result of testing for long */
1091 /* displacement facility. */
1093 /*------------------------------------------------------------------*/
1096 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1102 /*========================= End of Function ========================*/
1104 /*------------------------------------------------------------------*/
1106 /* Name - mono_arch_cpu_init */
1108 /* Function - Perform CPU specific initialization to execute */
1111 /*------------------------------------------------------------------*/
1114 mono_arch_cpu_init (void)
1116 struct sigaction sa,
1120 /*--------------------------------------*/
1121 /* Set default rounding mode for FP */
1122 /*--------------------------------------*/
1123 __asm__ ("SRNM\t%0\n\t"
1126 /*--------------------------------------*/
1127 /* Determine if we have long displace- */
1128 /* ment facility on this processor */
1129 /*--------------------------------------*/
1130 sa.sa_sigaction = catch_SIGILL;
1131 sigemptyset (&sa.sa_mask);
1132 sa.sa_flags = SA_SIGINFO;
1134 sigaction (SIGILL, &sa, oldSa);
1136 /*--------------------------------------*/
1137 /* We test by executing the STY inst */
1138 /*--------------------------------------*/
1139 __asm__ ("LGHI\t0,1\n\t"
1141 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1142 : "=m" (has_ld) : : "0", "1");
1144 sigaction (SIGILL, oldSa, NULL);
1147 /*========================= End of Function ========================*/
1149 /*------------------------------------------------------------------*/
1151 /* Name - mono_arch_init. */
1153 /* Function - Initialize architecture specific code. */
1155 /*------------------------------------------------------------------*/
1158 mono_arch_init (void)
1162 * When we do an architectural level set at z9 or better
1163 * we can use the STFLE instruction to show us
1164 * what hardware facilities are available
1166 int lFacility = sizeof(facs) % 8;
1168 memset((char *) &facs, 0, sizeof(facs));
1170 __asm__ (" lgfr 0,%1\n"
1172 : "=m" (facs) : "r" (lFacility) : "0", "cc");
1177 /*========================= End of Function ========================*/
1179 /*------------------------------------------------------------------*/
1181 /* Name - mono_arch_cleanup. */
1183 /* Function - Cleanup architecture specific code . */
1185 /*------------------------------------------------------------------*/
1188 mono_arch_cleanup (void)
1192 /*========================= End of Function ========================*/
1194 /*------------------------------------------------------------------*/
1196 /* Name - mono_arch_cpu_optimizazions */
1198 /* Function - Returns the optimizations supported on this CPU */
1200 /*------------------------------------------------------------------*/
1203 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1207 /*----------------------------------------------------------*/
1208 /* No s390-specific optimizations yet */
1209 /*----------------------------------------------------------*/
1210 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1211 // *exclude_mask = MONO_OPT_INLINE;
1215 /*========================= End of Function ========================*/
1217 /*------------------------------------------------------------------*/
1223 /*------------------------------------------------------------------*/
1226 is_regsize_var (MonoType *t) {
1229 switch (mono_type_get_underlying_type (t)->type) {
1237 case MONO_TYPE_FNPTR:
1239 case MONO_TYPE_OBJECT:
1240 case MONO_TYPE_STRING:
1241 case MONO_TYPE_CLASS:
1242 case MONO_TYPE_SZARRAY:
1243 case MONO_TYPE_ARRAY:
1245 case MONO_TYPE_VALUETYPE:
1246 if (t->data.klass->enumtype)
1247 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1253 /*========================= End of Function ========================*/
1255 /*------------------------------------------------------------------*/
1257 /* Name - mono_arch_get_allocatable_int_vars */
1261 /*------------------------------------------------------------------*/
1264 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1269 for (i = 0; i < cfg->num_varinfo; i++) {
1270 MonoInst *ins = cfg->varinfo [i];
1271 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1274 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1277 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1278 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1281 /* we can only allocate 32 bit values */
1282 if (is_regsize_var (ins->inst_vtype)) {
1283 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1284 g_assert (i == vmv->idx);
1285 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1292 /*========================= End of Function ========================*/
1294 /*------------------------------------------------------------------*/
1296 /* Name - mono_arch_global_int_regs */
1298 /* Function - Return a list of usable integer registers. */
1300 /*------------------------------------------------------------------*/
1303 mono_arch_get_global_int_regs (MonoCompile *cfg)
1306 MonoMethodHeader *header;
1309 header = cfg->header;
1310 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1311 cfg->frame_reg = s390_r11;
1314 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1316 for (i = 8; i < top; ++i) {
1317 if (cfg->frame_reg != i)
1318 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1324 /*========================= End of Function ========================*/
1326 /*------------------------------------------------------------------*/
1328 /* Name - mono_arch_flush_icache */
1330 /* Function - Flush the CPU icache. */
1332 /*------------------------------------------------------------------*/
1335 mono_arch_flush_icache (guint8 *code, gint size)
1339 /*========================= End of Function ========================*/
1341 /*------------------------------------------------------------------*/
1343 /* Name - add_general */
1345 /* Function - Determine code and stack size incremements for a */
1348 /*------------------------------------------------------------------*/
1351 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1353 if (*gr > S390_LAST_ARG_REG) {
1354 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1355 ainfo->offset = sz->stack_size;
1356 ainfo->reg = STK_BASE;
1357 ainfo->regtype = RegTypeBase;
1358 sz->stack_size += sizeof(long);
1359 sz->local_size += sizeof(long);
1360 sz->offStruct += sizeof(long);
1361 sz->code_size += 12;
1369 /*========================= End of Function ========================*/
1371 /*------------------------------------------------------------------*/
1373 /* Name - add_stackParm */
1375 /* Function - Determine code and stack size incremements for a */
1378 /*------------------------------------------------------------------*/
1381 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1383 if (*gr > S390_LAST_ARG_REG) {
1384 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1385 ainfo->reg = STK_BASE;
1386 ainfo->offset = sz->stack_size;
1387 ainfo->regtype = RegTypeStructByAddrOnStack;
1388 sz->stack_size += sizeof (gpointer);
1389 sz->parm_size += sizeof(gpointer);
1390 sz->offStruct += sizeof(gpointer);
1393 ainfo->offset = sz->stack_size;
1394 ainfo->regtype = RegTypeStructByAddr;
1397 ainfo->offparm = sz->offset;
1398 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1400 ainfo->vtsize = size;
1401 sz->parm_size += size;
1404 /*========================= End of Function ========================*/
1406 /*------------------------------------------------------------------*/
1408 /* Name - add_float */
1410 /* Function - Determine code and stack size incremements for a */
1411 /* float parameter. */
1413 /*------------------------------------------------------------------*/
1416 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1418 if ((*fr) <= S390_LAST_FPARG_REG) {
1419 ainfo->regtype = RegTypeFP;
1425 ainfo->offset = sz->stack_size;
1426 ainfo->reg = STK_BASE;
1427 ainfo->regtype = RegTypeBase;
1429 sz->stack_size += sizeof(double);
1430 sz->local_size += sizeof(double);
1431 sz->offStruct += sizeof(double);
1435 /*========================= End of Function ========================*/
1437 /*------------------------------------------------------------------*/
1439 /* Name - get_call_info */
1441 /* Function - Determine the amount of space required for code */
1442 /* and stack. In addition determine starting points */
1443 /* for stack-based parameters, and area for struct- */
1444 /* ures being returned on the stack. */
1446 /*------------------------------------------------------------------*/
1449 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1451 guint i, fr, gr, size;
1452 int nParm = sig->hasthis + sig->param_count;
1454 guint32 simpletype, align;
1457 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1460 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1462 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1467 cinfo->struct_ret = 0;
1471 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1472 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1477 /*----------------------------------------------------------*/
1478 /* We determine the size of the return code/stack in case we*/
1479 /* need to reserve a register to be used to address a stack */
1480 /* area that the callee will use. */
1481 /*----------------------------------------------------------*/
1483 ret_type = mono_type_get_underlying_type (sig->ret);
1484 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1485 simpletype = ret_type->type;
1487 switch (simpletype) {
1488 case MONO_TYPE_BOOLEAN:
1493 case MONO_TYPE_CHAR:
1498 case MONO_TYPE_CLASS:
1499 case MONO_TYPE_OBJECT:
1500 case MONO_TYPE_SZARRAY:
1501 case MONO_TYPE_ARRAY:
1503 case MONO_TYPE_FNPTR:
1504 case MONO_TYPE_STRING:
1505 cinfo->ret.reg = s390_r2;
1510 cinfo->ret.reg = s390_f0;
1515 cinfo->ret.reg = s390_r2;
1518 case MONO_TYPE_GENERICINST:
1519 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1520 cinfo->ret.reg = s390_r2;
1525 case MONO_TYPE_VALUETYPE: {
1526 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1527 if (klass->enumtype) {
1528 simpletype = mono_class_enum_basetype (klass)->type;
1532 size = mono_class_native_size (klass, &align);
1534 size = mono_class_value_size (klass, &align);
1536 cinfo->ret.reg = s390_r2;
1537 cinfo->struct_ret = 1;
1538 cinfo->ret.size = size;
1539 cinfo->ret.vtsize = size;
1543 case MONO_TYPE_TYPEDBYREF:
1544 size = sizeof (MonoTypedRef);
1545 cinfo->ret.reg = s390_r2;
1546 cinfo->struct_ret = 1;
1547 cinfo->ret.size = size;
1548 cinfo->ret.vtsize = size;
1551 case MONO_TYPE_VOID:
1554 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1558 cinfo->args[nParm].size = sizeof(gpointer);
1559 add_general (&gr, sz, cinfo->args+nParm);
1563 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1564 gr = S390_LAST_ARG_REG + 1;
1566 /* Emit the signature cookie just before the implicit arguments */
1567 add_general (&gr, sz, &cinfo->sigCookie);
1570 /*----------------------------------------------------------*/
1571 /* We determine the size of the parameter code and stack */
1572 /* requirements by checking the types and sizes of the */
1574 /*----------------------------------------------------------*/
1576 for (i = 0; i < sig->param_count; ++i) {
1579 /*--------------------------------------------------*/
1580 /* Handle vararg type calls. All args are put on */
1582 /*--------------------------------------------------*/
1583 if ((sig->call_convention == MONO_CALL_VARARG) &&
1584 (i == sig->sentinelpos)) {
1585 gr = S390_LAST_ARG_REG + 1;
1586 add_general (&gr, sz, &cinfo->sigCookie);
1589 if (sig->params [i]->byref) {
1590 add_general (&gr, sz, cinfo->args+nParm);
1591 cinfo->args[nParm].size = sizeof(gpointer);
1596 ptype = mono_type_get_underlying_type (sig->params [i]);
1597 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1598 simpletype = ptype->type;
1599 cinfo->args[nParm].type = simpletype;
1600 switch (simpletype) {
1601 case MONO_TYPE_BOOLEAN:
1604 cinfo->args[nParm].size = sizeof(char);
1605 add_general (&gr, sz, cinfo->args+nParm);
1610 case MONO_TYPE_CHAR:
1611 cinfo->args[nParm].size = sizeof(short);
1612 add_general (&gr, sz, cinfo->args+nParm);
1617 cinfo->args[nParm].size = sizeof(int);
1618 add_general (&gr, sz, cinfo->args+nParm);
1624 case MONO_TYPE_FNPTR:
1625 case MONO_TYPE_CLASS:
1626 case MONO_TYPE_OBJECT:
1627 case MONO_TYPE_STRING:
1628 case MONO_TYPE_SZARRAY:
1629 case MONO_TYPE_ARRAY:
1630 cinfo->args[nParm].size = sizeof(gpointer);
1631 add_general (&gr, sz, cinfo->args+nParm);
1636 cinfo->args[nParm].size = sizeof(long long);
1637 add_general (&gr, sz, cinfo->args+nParm);
1641 cinfo->args[nParm].size = sizeof(float);
1642 add_float (&fr, sz, cinfo->args+nParm);
1646 cinfo->args[nParm].size = sizeof(double);
1647 add_float (&fr, sz, cinfo->args+nParm);
1650 case MONO_TYPE_GENERICINST:
1651 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1652 cinfo->args[nParm].size = sizeof(gpointer);
1653 add_general (&gr, sz, cinfo->args+nParm);
1658 case MONO_TYPE_VALUETYPE: {
1659 MonoMarshalType *info;
1660 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1662 size = mono_class_native_size (klass, &align);
1664 size = mono_class_value_size (klass, &align);
1666 info = mono_marshal_load_type_info (klass);
1668 if ((info->native_size == sizeof(float)) &&
1669 (info->num_fields == 1) &&
1670 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1671 cinfo->args[nParm].size = sizeof(float);
1672 add_float(&fr, sz, cinfo->args+nParm);
1677 if ((info->native_size == sizeof(double)) &&
1678 (info->num_fields == 1) &&
1679 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1680 cinfo->args[nParm].size = sizeof(double);
1681 add_float(&fr, sz, cinfo->args+nParm);
1686 cinfo->args[nParm].vtsize = 0;
1687 cinfo->args[nParm].size = 0;
1690 /*----------------------------------*/
1691 /* On S/390, structures of size 1, */
1692 /* 2, 4, and 8 bytes are passed in */
1693 /* (a) register(s). */
1694 /*----------------------------------*/
1700 add_general(&gr, sz, cinfo->args+nParm);
1701 cinfo->args[nParm].size = size;
1702 cinfo->args[nParm].regtype = RegTypeStructByVal;
1704 sz->local_size += sizeof(long);
1707 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1712 case MONO_TYPE_TYPEDBYREF: {
1713 int size = sizeof (MonoTypedRef);
1715 cinfo->args[nParm].vtsize = 0;
1716 cinfo->args[nParm].size = 0;
1719 /*----------------------------------*/
1720 /* On S/390, structures of size 1, */
1721 /* 2, 4, and 8 bytes are passed in */
1722 /* (a) register(s). */
1723 /*----------------------------------*/
1729 add_general(&gr, sz, cinfo->args+nParm);
1730 cinfo->args[nParm].size = size;
1731 cinfo->args[nParm].regtype = RegTypeStructByVal;
1733 sz->local_size += sizeof(long);
1736 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1742 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1746 /*----------------------------------------------------------*/
1747 /* Handle the case where there are no implicit arguments */
1748 /*----------------------------------------------------------*/
1749 if ((sig->call_convention == MONO_CALL_VARARG) &&
1752 (sig->param_count == sig->sentinelpos)) {
1753 gr = S390_LAST_ARG_REG + 1;
1754 add_general (&gr, sz, &cinfo->sigCookie);
1757 /*----------------------------------------------------------*/
1758 /* If we are passing a structure back then if it won't be */
1759 /* in a register(s) then we make room at the end of the */
1760 /* parameters that may have been placed on the stack */
1761 /*----------------------------------------------------------*/
1762 if (cinfo->struct_ret) {
1763 cinfo->ret.offset = sz->stack_size;
1764 switch (cinfo->ret.size) {
1772 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1777 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1779 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1784 /*========================= End of Function ========================*/
1786 /*------------------------------------------------------------------*/
1788 /* Name - mono_arch_allocate_vars */
1790 /* Function - Set var information according to the calling */
1791 /* convention for S/390. The local var stuff should */
1792 /* most likely be split in another method. */
1794 /* Parameter - @m - Compile unit. */
1796 /*------------------------------------------------------------------*/
1799 mono_arch_allocate_vars (MonoCompile *cfg)
1801 MonoMethodSignature *sig;
1802 MonoMethodHeader *header;
1805 int iParm, iVar, offset, align, size, curinst;
1806 int frame_reg = STK_BASE;
1809 header = cfg->header;
1811 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1813 /*---------------------------------------------------------*/
1814 /* We use the frame register also for any method that has */
1815 /* filter clauses. This way, when the handlers are called, */
1816 /* the code will reference local variables using the frame */
1817 /* reg instead of the stack pointer: if we had to restore */
1818 /* the stack pointer, we'd corrupt the method frames that */
1819 /* are already on the stack (since filters get called */
1820 /* before stack unwinding happens) when the filter code */
1821 /* would call any method. */
1822 /*---------------------------------------------------------*/
1823 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1824 frame_reg = s390_r11;
1826 cfg->frame_reg = frame_reg;
1828 cfg->arch.bkchain_reg = -1;
1830 if (frame_reg != STK_BASE)
1831 cfg->used_int_regs |= 1 << frame_reg;
1833 sig = mono_method_signature (cfg->method);
1835 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1837 if (!cinfo->struct_ret) {
1838 switch (mono_type_get_underlying_type (sig->ret)->type) {
1839 case MONO_TYPE_VOID:
1842 cfg->ret->opcode = OP_REGVAR;
1843 cfg->ret->dreg = s390_r2;
1848 /*--------------------------------------------------------------*/
1849 /* local vars are at a positive offset from the stack pointer */
1850 /* also note that if the function uses alloca, we use s390_r11 */
1851 /* to point at the local variables. */
1852 /* add parameter area size for called functions */
1853 /*--------------------------------------------------------------*/
1854 if (cfg->param_area == 0)
1855 offset = S390_MINIMAL_STACK_SIZE;
1857 offset = cfg->param_area;
1859 cfg->sig_cookie = 0;
1861 if (cinfo->struct_ret) {
1862 inst = cfg->vret_addr;
1863 offset = S390_ALIGN(offset, sizeof(gpointer));
1864 inst->inst_offset = offset;
1865 inst->opcode = OP_REGOFFSET;
1866 inst->inst_basereg = frame_reg;
1867 offset += sizeof(gpointer);
1868 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1869 printf ("vret_addr =");
1870 mono_print_ins (cfg->vret_addr);
1875 inst = cfg->args [0];
1876 if (inst->opcode != OP_REGVAR) {
1877 inst->opcode = OP_REGOFFSET;
1878 inst->inst_basereg = frame_reg;
1879 offset = S390_ALIGN(offset, sizeof(gpointer));
1880 inst->inst_offset = offset;
1881 offset += sizeof (gpointer);
1888 eArg = sig->param_count + sArg;
1890 if (sig->call_convention == MONO_CALL_VARARG)
1891 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1893 for (iParm = sArg; iParm < eArg; ++iParm) {
1894 inst = cfg->args [curinst];
1895 if (inst->opcode != OP_REGVAR) {
1896 switch (cinfo->args[iParm].regtype) {
1897 case RegTypeStructByAddr : {
1900 size = sizeof (gpointer);
1902 inst->opcode = OP_REGOFFSET;
1903 inst->inst_basereg = frame_reg;
1904 offset = S390_ALIGN (offset, sizeof (gpointer));
1905 inst->inst_offset = offset;
1907 /* Add a level of indirection */
1908 MONO_INST_NEW (cfg, indir, 0);
1910 inst->opcode = OP_VTARG_ADDR;
1911 inst->inst_left = indir;
1914 case RegTypeStructByAddrOnStack : {
1917 size = sizeof (gpointer);
1919 /* Similar to the == STK_BASE case below */
1920 cfg->arch.bkchain_reg = s390_r12;
1921 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1923 inst->opcode = OP_REGOFFSET;
1924 inst->dreg = mono_alloc_preg (cfg);
1925 inst->inst_basereg = cfg->arch.bkchain_reg;
1926 inst->inst_offset = cinfo->args [iParm].offset;
1928 /* Add a level of indirection */
1929 MONO_INST_NEW (cfg, indir, 0);
1931 inst->opcode = OP_VTARG_ADDR;
1932 inst->inst_left = indir;
1935 case RegTypeStructByVal :
1936 size = cinfo->args[iParm].size;
1937 offset = S390_ALIGN(offset, size);
1938 inst->opcode = OP_REGOFFSET;
1939 inst->inst_basereg = frame_reg;
1940 inst->inst_offset = offset;
1943 if (cinfo->args [iParm].reg == STK_BASE) {
1945 * These arguments are in the previous frame, so we can't
1946 * compute their offset from the current frame pointer right
1947 * now, since cfg->stack_offset is not yet known, so dedicate a
1948 * register holding the previous frame pointer.
1950 cfg->arch.bkchain_reg = s390_r12;
1951 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1953 inst->opcode = OP_REGOFFSET;
1954 inst->inst_basereg = cfg->arch.bkchain_reg;
1955 size = (cinfo->args[iParm].size < 8
1956 ? 8 - cinfo->args[iParm].size
1958 inst->inst_offset = cinfo->args [iParm].offset + size;
1959 size = sizeof (long);
1961 inst->opcode = OP_REGOFFSET;
1962 inst->inst_basereg = frame_reg;
1963 size = (cinfo->args[iParm].size < 8
1966 offset = S390_ALIGN(offset, size);
1967 inst->inst_offset = offset;
1971 if ((sig->call_convention == MONO_CALL_VARARG) &&
1972 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1973 (iParm < sig->sentinelpos))
1974 cfg->sig_cookie += size;
1981 curinst = cfg->locals_start;
1982 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1983 inst = cfg->varinfo [iVar];
1984 if ((inst->flags & MONO_INST_IS_DEAD) ||
1985 (inst->opcode == OP_REGVAR))
1988 /*--------------------------------------------------*/
1989 /* inst->backend.is_pinvoke indicates native sized */
1990 /* value typs this is used by the pinvoke wrappers */
1991 /* when they call functions returning structure */
1992 /*--------------------------------------------------*/
1993 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1994 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
1995 (guint32 *) &align);
1997 size = mono_type_size (inst->inst_vtype, &align);
1999 offset = S390_ALIGN(offset, align);
2000 inst->inst_offset = offset;
2001 inst->opcode = OP_REGOFFSET;
2002 inst->inst_basereg = frame_reg;
2004 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2005 iVar, inst->inst_offset, size));
2008 /*------------------------------------------------------*/
2009 /* Allow space for the trace method stack area if needed*/
2010 /*------------------------------------------------------*/
2011 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2012 offset += S390_TRACE_STACK_SIZE;
2014 /*------------------------------------------------------*/
2015 /* Reserve space to save LMF and caller saved registers */
2016 /*------------------------------------------------------*/
2017 if (cfg->method->save_lmf)
2018 offset += sizeof (MonoLMF);
2020 /*------------------------------------------------------*/
2021 /* align the offset */
2022 /*------------------------------------------------------*/
2023 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2025 /*------------------------------------------------------*/
2026 /* Fix offsets for args whose value is in parent frame */
2027 /*------------------------------------------------------*/
2028 for (iParm = sArg; iParm < eArg; ++iParm) {
2029 inst = cfg->args [iParm];
2031 if (inst->opcode == OP_S390_STKARG) {
2032 inst->opcode = OP_REGOFFSET;
2033 inst->inst_offset += cfg->stack_offset;
2038 /*========================= End of Function ========================*/
2040 /*------------------------------------------------------------------*/
2042 /* Name - mono_arch_create_vars */
2044 /*------------------------------------------------------------------*/
2047 mono_arch_create_vars (MonoCompile *cfg)
2049 MonoMethodSignature *sig;
2052 sig = mono_method_signature (cfg->method);
2054 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2056 if (cinfo->struct_ret) {
2057 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2058 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2059 printf ("vret_addr = ");
2060 mono_print_ins (cfg->vret_addr);
2065 /*========================= End of Function ========================*/
2067 /*------------------------------------------------------------------*/
2069 /* Name - add_outarg_reg2. */
2071 /*------------------------------------------------------------------*/
2074 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2079 case RegTypeGeneral:
2080 MONO_INST_NEW (cfg, ins, OP_MOVE);
2081 ins->dreg = mono_alloc_ireg (cfg);
2082 ins->sreg1 = tree->dreg;
2083 MONO_ADD_INS (cfg->cbb, ins);
2084 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2087 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2088 ins->dreg = mono_alloc_freg (cfg);
2089 ins->sreg1 = tree->dreg;
2090 MONO_ADD_INS (cfg->cbb, ins);
2091 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2094 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2095 ins->dreg = mono_alloc_freg (cfg);
2096 ins->sreg1 = tree->dreg;
2097 MONO_ADD_INS (cfg->cbb, ins);
2098 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2101 g_assert_not_reached ();
2105 /*========================= End of Function ========================*/
2107 /*------------------------------------------------------------------*/
2109 /* Name - emit_sig_cookie. */
2111 /*------------------------------------------------------------------*/
2114 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2116 MonoMethodSignature *tmpSig;
2119 cfg->disable_aot = TRUE;
2121 /*----------------------------------------------------------*/
2122 /* mono_ArgIterator_Setup assumes the signature cookie is */
2123 /* passed first and all the arguments which were before it */
2124 /* passed on the stack after the signature. So compensate */
2125 /* by passing a different signature. */
2126 /*----------------------------------------------------------*/
2127 tmpSig = mono_metadata_signature_dup (call->signature);
2128 tmpSig->param_count -= call->signature->sentinelpos;
2129 tmpSig->sentinelpos = 0;
2130 if (tmpSig->param_count > 0)
2131 memcpy (tmpSig->params,
2132 call->signature->params + call->signature->sentinelpos,
2133 tmpSig->param_count * sizeof(MonoType *));
2135 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2136 sig_arg->dreg = mono_alloc_ireg (cfg);
2137 sig_arg->inst_p0 = tmpSig;
2138 MONO_ADD_INS (cfg->cbb, sig_arg);
2140 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2141 cinfo->sigCookie.offset, sig_arg->dreg);
2144 /*========================= End of Function ========================*/
2146 /*------------------------------------------------------------------*/
2148 /* Name - mono_arch_emit_call */
2150 /*------------------------------------------------------------------*/
2153 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2156 MonoMethodSignature *sig;
2158 int i, n, lParamArea;
2160 ArgInfo *ainfo = NULL;
2162 MonoMethodHeader *header;
2165 sig = call->signature;
2166 n = sig->param_count + sig->hasthis;
2167 DEBUG (g_print ("Call requires: %d parameters\n",n));
2169 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2171 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2172 cinfo->sz.parm_size + cinfo->sz.offset;
2173 call->stack_usage = MAX(stackSize, call->stack_usage);
2174 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2175 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2176 cfg->flags |= MONO_CFG_HAS_CALLS;
2178 if (cinfo->struct_ret) {
2179 MONO_INST_NEW (cfg, ins, OP_MOVE);
2180 ins->sreg1 = call->vret_var->dreg;
2181 ins->dreg = mono_alloc_preg (cfg);
2182 MONO_ADD_INS (cfg->cbb, ins);
2183 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2186 header = cfg->header;
2187 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2192 for (i = 0; i < n; ++i) {
2195 ainfo = cinfo->args + i;
2196 if (i >= sig->hasthis)
2197 t = sig->params [i - sig->hasthis];
2199 t = &mono_defaults.int_class->byval_arg;
2200 t = mono_type_get_underlying_type (t);
2202 in = call->args [i];
2204 if ((sig->call_convention == MONO_CALL_VARARG) &&
2206 (i == sig->sentinelpos)) {
2207 emit_sig_cookie (cfg, call, cinfo);
2210 switch (ainfo->regtype) {
2211 case RegTypeGeneral:
2212 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2215 if (MONO_TYPE_ISSTRUCT (t)) {
2216 /* Valuetype passed in one fp register */
2217 ainfo->regtype = RegTypeStructByValInFP;
2220 if (ainfo->size == 4)
2221 ainfo->regtype = RegTypeFPR4;
2222 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2225 case RegTypeStructByVal:
2226 case RegTypeStructByAddr:
2227 case RegTypeStructByAddrOnStack: {
2231 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2232 size = sizeof (MonoTypedRef);
2233 align = sizeof (gpointer);
2237 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2240 * Other backends use mono_type_stack_size (), but that
2241 * aligns the size to 8, which is larger than the size of
2242 * the source, leading to reads of invalid memory if the
2243 * source is at the end of address space.
2245 size = mono_class_value_size (in->klass, &align);
2248 g_assert (in->klass);
2250 ainfo->offparm += cinfo->sz.offStruct;
2252 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2253 ins->sreg1 = in->dreg;
2254 ins->klass = in->klass;
2255 ins->backend.size = ainfo->size;
2256 ins->inst_p0 = call;
2257 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2258 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2260 MONO_ADD_INS (cfg->cbb, ins);
2262 if (ainfo->regtype == RegTypeStructByAddr) {
2264 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2265 * use the normal OUTARG opcodes to pass the address of the location to
2268 int treg = mono_alloc_preg (cfg);
2269 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2270 frmReg, ainfo->offparm);
2271 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2272 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2273 /* The address of the valuetype is passed on the stack */
2274 int treg = mono_alloc_preg (cfg);
2275 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2276 frmReg, ainfo->offparm);
2277 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2278 ainfo->reg, ainfo->offset, treg);
2283 if (!t->byref && t->type == MONO_TYPE_R4) {
2284 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2285 STK_BASE, ainfo->offset + 4,
2287 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2288 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2289 STK_BASE, ainfo->offset,
2292 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2293 ins->inst_destbasereg = STK_BASE;
2294 ins->inst_offset = ainfo->offset;
2295 ins->sreg1 = in->dreg;
2298 /* This is needed by MonoTypedRef->value to point to the correct data */
2299 if ((sig->call_convention == MONO_CALL_VARARG) &&
2300 (i >= sig->sentinelpos)) {
2301 switch (ainfo->size) {
2303 ins->opcode = OP_STOREI1_MEMBASE_REG;
2306 ins->opcode = OP_STOREI2_MEMBASE_REG;
2309 ins->opcode = OP_STOREI4_MEMBASE_REG;
2317 MONO_ADD_INS (cfg->cbb, ins);
2321 g_assert_not_reached ();
2327 * Handle the case where there are no implicit arguments
2329 if ((sig->call_convention == MONO_CALL_VARARG) &&
2331 (i == sig->sentinelpos)) {
2332 emit_sig_cookie (cfg, call, cinfo);
2336 /*========================= End of Function ========================*/
2338 /*------------------------------------------------------------------*/
2340 /* Name - mono_arch_emit_outarg_vt */
2342 /*------------------------------------------------------------------*/
2345 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2347 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2348 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2349 int size = ins->backend.size;
2351 if (ainfo->regtype == RegTypeStructByVal) {
2353 arg->ins.sreg1 = ainfo->reg;
2354 arg->ins.opcode = OP_OUTARG_VT;
2355 arg->size = ainfo->size;
2356 arg->offset = ainfo->offset;
2357 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2359 if (ainfo->reg != STK_BASE) {
2360 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2362 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2365 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2366 int dreg = mono_alloc_freg (cfg);
2368 if (ainfo->size == 4) {
2369 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2370 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2372 g_assert (ainfo->size == 8);
2374 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2377 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2379 MonoMethodHeader *header;
2382 header = mono_method_get_header (cfg->method);
2383 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2388 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2389 src->dreg, 0, size);
2393 /*========================= End of Function ========================*/
2395 /*------------------------------------------------------------------*/
2397 /* Name - mono_arch_emit_setret */
2399 /*------------------------------------------------------------------*/
2402 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2404 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2407 if (ret->type == MONO_TYPE_R4) {
2408 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2410 } else if (ret->type == MONO_TYPE_R8) {
2411 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2416 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2419 /*========================= End of Function ========================*/
2421 /*------------------------------------------------------------------*/
2423 /* Name - mono_arch_instrument_mem_needs */
2425 /* Function - Allow tracing to work with this interface (with */
2426 /* an optional argument). */
2428 /*------------------------------------------------------------------*/
2431 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2433 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2435 /* split prolog-epilog requirements? */
2436 *code = 50; /* max bytes needed: check this number */
2439 /*========================= End of Function ========================*/
2441 /*------------------------------------------------------------------*/
2443 /* Name - mono_arch_instrument_prolog */
2445 /* Function - Create an "instrumented" prolog. */
2447 /*------------------------------------------------------------------*/
2450 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2451 gboolean enable_arguments)
2458 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2459 if (cfg->method->save_lmf)
2460 parmOffset -= sizeof(MonoLMF);
2461 fpOffset = parmOffset + (5*sizeof(gpointer));
2462 if ((!has_ld) && (fpOffset > 4096)) {
2463 s390_lgr (code, s390_r12, STK_BASE);
2465 while (fpOffset > 4096) {
2466 s390_aghi (code, baseReg, 4096);
2474 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2476 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2477 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2478 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2479 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2481 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2482 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2483 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2484 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2486 s390_basr (code, s390_r13, 0);
2488 s390_llong(code, cfg->method);
2489 s390_llong(code, func);
2490 s390_lg (code, s390_r2, 0, s390_r13, 4);
2492 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2494 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2495 s390_lgr (code, s390_r4, STK_BASE);
2496 s390_aghi (code, s390_r4, cfg->stack_usage);
2497 s390_lg (code, s390_r1, 0, s390_r13, 12);
2498 s390_basr (code, s390_r14, s390_r1);
2500 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2501 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2502 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2503 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2505 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2506 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2507 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2508 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2510 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2515 /*========================= End of Function ========================*/
2517 /*------------------------------------------------------------------*/
2519 /* Name - mono_arch_instrument_epilog */
2521 /* Function - Create an epilog that will handle the returned */
2522 /* values used in instrumentation. */
2524 /*------------------------------------------------------------------*/
2527 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2530 int save_mode = SAVE_NONE,
2532 MonoMethod *method = cfg->method;
2533 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2535 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2536 if (method->save_lmf)
2537 saveOffset -= sizeof(MonoLMF);
2541 case MONO_TYPE_VOID:
2542 /* special case string .ctor icall */
2543 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2544 save_mode = SAVE_ONE;
2546 save_mode = SAVE_NONE;
2550 save_mode = SAVE_ONE;
2553 save_mode = SAVE_R4;
2556 save_mode = SAVE_R8;
2558 case MONO_TYPE_VALUETYPE:
2559 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2560 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2563 save_mode = SAVE_STRUCT;
2566 save_mode = SAVE_ONE;
2570 switch (save_mode) {
2572 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2573 if (enable_arguments) {
2574 s390_lgr (code, s390_r3, s390_r2);
2578 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2579 if (enable_arguments) {
2580 s390_ldebr (code, s390_f0, s390_f0);
2584 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2587 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2588 if (enable_arguments) {
2589 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2590 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2598 s390_basr (code, s390_r13, 0);
2600 s390_llong(code, cfg->method);
2601 s390_llong(code, func);
2602 s390_lg (code, s390_r2, 0, s390_r13, 4);
2603 s390_lg (code, s390_r1, 0, s390_r13, 12);
2604 s390_basr (code, s390_r14, s390_r1);
2606 switch (save_mode) {
2608 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2612 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2615 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2625 /*========================= End of Function ========================*/
2627 /*------------------------------------------------------------------*/
2629 /* Name - mono_arch_peephole_pass_1 */
2631 /* Function - Form a peephole pass at the code looking for */
2632 /* simple optimizations. */
2634 /*------------------------------------------------------------------*/
2637 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2641 /*========================= End of Function ========================*/
2643 /*------------------------------------------------------------------*/
2645 /* Name - mono_arch_peephole_pass_2 */
2647 /* Function - Form a peephole pass at the code looking for */
2648 /* simple optimizations. */
2650 /*------------------------------------------------------------------*/
2653 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2657 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2658 mono_peephole_ins (bb, ins);
2662 /*========================= End of Function ========================*/
2664 /*------------------------------------------------------------------*/
2666 /* Name - mono_arch_lowering_pass. */
2668 /*------------------------------------------------------------------*/
2671 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2673 MonoInst *ins, *next;
2675 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2676 switch (ins->opcode) {
2681 case OP_IDIV_UN_IMM:
2682 case OP_IREM_UN_IMM:
2686 case OP_LOCALLOC_IMM:
2687 mono_decompose_op_imm (cfg, bb, ins);
2690 if (!s390_is_imm16 (ins->inst_imm))
2691 /* This is created by the memcpy code which ignores is_inst_imm */
2692 mono_decompose_op_imm (cfg, bb, ins);
2699 bb->max_vreg = cfg->next_vreg;
2702 /*========================= End of Function ========================*/
2704 /*------------------------------------------------------------------*/
2706 /* Name - emit_float_to_int */
2708 /* Function - Create instructions which will convert a floating */
2709 /* point value to integer. */
2711 /*------------------------------------------------------------------*/
2714 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2716 /* sreg is a float, dreg is an integer reg. */
2718 s390_cgdbr (code, dreg, 5, sreg);
2721 s390_lghi (code, s390_r0, 0);
2722 s390_lghi (code, s390_r13, 0xff);
2723 s390_ltgr (code, dreg, dreg);
2725 s390_lghi (code, s390_r0, 0x80);
2726 s390_ngr (code, dreg, s390_r13);
2727 s390_ogr (code, dreg, s390_r0);
2732 s390_basr (code, s390_r13, 0);
2734 s390_llong (code, 0x41e0000000000000llu);
2735 s390_llong (code, 0x41f0000000000000llu);
2736 s390_ldr (code, s390_f15, sreg);
2737 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2738 s390_jl (code, 0); CODEPTR (code, o[0]);
2739 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2740 s390_cfdbr (code, dreg, 7, s390_f15);
2742 PTRSLOT (code, o[0]);
2743 s390_cfdbr (code, dreg, 5, sreg);
2746 s390_lghi (code, s390_r0, 0xff);
2747 s390_ngr (code, dreg, s390_r0);
2750 s390_lghi (code, s390_r0, -1);
2751 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2752 s390_ngr (code, dreg, s390_r0);
2759 /*========================= End of Function ========================*/
2761 /*------------------------------------------------------------------*/
2763 /* Name - gboolean_is_unsigned. */
2765 /* Function - Return TRUE if next opcode is checking for un- */
2768 /*------------------------------------------------------------------*/
2771 gboolean is_unsigned (MonoInst *next)
2774 (((next->opcode >= OP_IBNE_UN) &&
2775 (next->opcode <= OP_IBLT_UN)) ||
2776 ((next->opcode >= OP_LBNE_UN) &&
2777 (next->opcode <= OP_LBLT_UN)) ||
2778 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2779 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2780 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2781 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2782 ((next->opcode == OP_CLT_UN) ||
2783 (next->opcode == OP_CGT_UN)) ||
2784 ((next->opcode == OP_ICLT_UN) ||
2785 (next->opcode == OP_ICGT_UN) ||
2786 (next->opcode == OP_LCLT_UN) ||
2787 (next->opcode == OP_LCGT_UN))))
2793 /*========================= End of Function ========================*/
2795 /*------------------------------------------------------------------*/
2797 /* Name - mono_arch_output_basic_block */
2799 /* Function - Perform the "real" work of emitting instructions */
2800 /* that will do the work of in the basic block. */
2802 /*------------------------------------------------------------------*/
2805 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2810 guint8 *code = cfg->native_code + cfg->code_len;
2811 guint last_offset = 0;
2812 int max_len, cpos, src2;
2814 /* we don't align basic blocks of loops on s390 */
2816 if (cfg->verbose_level > 2)
2817 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2819 cpos = bb->max_offset;
2821 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2822 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2823 //g_assert (!mono_compile_aot);
2826 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2827 /* this is not thread save, but good enough */
2828 /* fixme: howto handle overflows? */
2829 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2832 MONO_BB_FOR_EACH_INS (bb, ins) {
2833 offset = code - cfg->native_code;
2835 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2837 if (offset > (cfg->code_size - max_len - 16)) {
2838 cfg->code_size *= 2;
2839 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2840 code = cfg->native_code + offset;
2843 mono_debug_record_line_number (cfg, ins, offset);
2845 switch (ins->opcode) {
2846 case OP_STOREI1_MEMBASE_IMM: {
2847 s390_lghi (code, s390_r0, ins->inst_imm);
2848 S390_LONG (code, stcy, stc, s390_r0, 0,
2849 ins->inst_destbasereg, ins->inst_offset);
2852 case OP_STOREI2_MEMBASE_IMM: {
2853 s390_lghi (code, s390_r0, ins->inst_imm);
2854 S390_LONG (code, sthy, sth, s390_r0, 0,
2855 ins->inst_destbasereg, ins->inst_offset);
2858 case OP_STOREI4_MEMBASE_IMM: {
2859 if (s390_is_imm16(ins->inst_imm)) {
2860 s390_lghi (code, s390_r0, ins->inst_imm);
2862 s390_basr (code, s390_r13, 0);
2864 s390_llong(code, ins->inst_imm);
2865 s390_lg (code, s390_r0, 0, s390_r13, 4);
2867 S390_LONG (code, sty, st, s390_r0, 0,
2868 ins->inst_destbasereg, ins->inst_offset);
2871 case OP_STORE_MEMBASE_IMM:
2872 case OP_STOREI8_MEMBASE_IMM: {
2873 if (s390_is_imm16(ins->inst_imm)) {
2874 s390_lghi (code, s390_r0, ins->inst_imm);
2876 s390_basr (code, s390_r13, 0);
2878 s390_llong(code, ins->inst_imm);
2879 s390_lg (code, s390_r0, 0, s390_r13, 4);
2881 S390_LONG (code, stg, stg, s390_r0, 0,
2882 ins->inst_destbasereg, ins->inst_offset);
2885 case OP_STOREI1_MEMBASE_REG: {
2886 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2887 ins->inst_destbasereg, ins->inst_offset);
2890 case OP_STOREI2_MEMBASE_REG: {
2891 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2892 ins->inst_destbasereg, ins->inst_offset);
2895 case OP_STOREI4_MEMBASE_REG: {
2896 S390_LONG (code, sty, st, ins->sreg1, 0,
2897 ins->inst_destbasereg, ins->inst_offset);
2900 case OP_STORE_MEMBASE_REG:
2901 case OP_STOREI8_MEMBASE_REG: {
2902 S390_LONG (code, stg, stg, ins->sreg1, 0,
2903 ins->inst_destbasereg, ins->inst_offset);
2907 g_assert_not_reached ();
2909 case OP_LOAD_MEMBASE:
2910 case OP_LOADI8_MEMBASE: {
2911 S390_LONG (code, lg, lg, ins->dreg, 0,
2912 ins->inst_basereg, ins->inst_offset);
2915 case OP_LOADI4_MEMBASE: {
2916 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2917 ins->inst_basereg, ins->inst_offset);
2920 case OP_LOADU4_MEMBASE: {
2921 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2922 ins->inst_basereg, ins->inst_offset);
2925 case OP_LOADU1_MEMBASE: {
2926 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2927 ins->inst_basereg, ins->inst_offset);
2930 case OP_LOADI1_MEMBASE: {
2931 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2932 ins->inst_basereg, ins->inst_offset);
2935 case OP_LOADU2_MEMBASE: {
2936 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2937 ins->inst_basereg, ins->inst_offset);
2940 case OP_LOADI2_MEMBASE: {
2941 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2942 ins->inst_basereg, ins->inst_offset);
2945 case OP_LCONV_TO_I1: {
2947 s390_lgbr (code, ins->dreg, ins->sreg1);
2949 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
2950 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
2954 case OP_LCONV_TO_I2: {
2956 s390_lghr (code, ins->dreg, ins->sreg1);
2958 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
2959 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
2963 case OP_LCONV_TO_U1: {
2965 s390_llghr (code, ins->dreg, ins->sreg1);
2967 if (ins->dreg != ins->sreg1)
2968 s390_lgr (code, ins->dreg, ins->sreg1);
2969 s390_lghi (code, s390_r0, 0xff);
2970 s390_ngr (code, ins->dreg, s390_r0);
2974 case OP_LCONV_TO_U2: {
2976 s390_llghr (code, ins->dreg, ins->sreg1);
2978 if (ins->dreg != ins->sreg1)
2979 s390_lgr (code, ins->dreg, ins->sreg1);
2980 s390_lghi (code, s390_r0, -1);
2981 s390_srlg (code, s390_r0, s390_r0, 0, 48);
2982 s390_ngr (code, ins->dreg, s390_r0);
2986 case OP_ICONV_TO_I1: {
2988 s390_lbr (code, ins->dreg, ins->sreg1);
2990 if (ins->dreg != ins->sreg1)
2991 s390_lr (code, ins->dreg, ins->sreg1);
2992 s390_sll (code, ins->dreg, 0, 24);
2993 s390_sra (code, ins->dreg, 0, 24);
2998 case OP_ICONV_TO_I2: {
3000 s390_lhr (code, ins->dreg, ins->sreg1);
3002 if (ins->dreg != ins->sreg1)
3003 s390_lr (code, ins->dreg, ins->sreg1);
3004 s390_sll (code, ins->dreg, 0, 16);
3005 s390_sra (code, ins->dreg, 0, 16);
3009 case OP_ICONV_TO_U1: {
3011 s390_llcr (code, ins->dreg, ins->sreg1);
3013 if (ins->dreg != ins->sreg1)
3014 s390_lr (code, ins->dreg, ins->sreg1);
3015 s390_lhi (code, s390_r0, 0xff);
3016 s390_nr (code, ins->dreg, s390_r0);
3020 case OP_ICONV_TO_U2: {
3022 s390_llhr (code, ins->dreg, ins->sreg1);
3024 if (ins->dreg != ins->sreg1)
3025 s390_lr (code, ins->dreg, ins->sreg1);
3026 s390_lhi (code, s390_r0, -1);
3027 s390_srl (code, s390_r0, 0, 16);
3028 s390_nr (code, ins->dreg, s390_r0);
3034 if (is_unsigned (ins->next))
3035 s390_clgr (code, ins->sreg1, ins->sreg2);
3037 s390_cgr (code, ins->sreg1, ins->sreg2);
3041 if (is_unsigned (ins->next))
3042 s390_clr (code, ins->sreg1, ins->sreg2);
3044 s390_cr (code, ins->sreg1, ins->sreg2);
3047 case OP_COMPARE_IMM:
3048 case OP_LCOMPARE_IMM: {
3049 if (s390_is_imm16 (ins->inst_imm)) {
3050 s390_lghi (code, s390_r0, ins->inst_imm);
3051 if (is_unsigned (ins->next))
3052 s390_clgr (code, ins->sreg1, s390_r0);
3054 s390_cgr (code, ins->sreg1, s390_r0);
3056 s390_basr (code, s390_r13, 0);
3058 s390_llong(code, ins->inst_imm);
3059 if (is_unsigned (ins->next))
3060 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3062 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3066 case OP_ICOMPARE_IMM: {
3067 if (s390_is_imm16 (ins->inst_imm)) {
3068 s390_lghi (code, s390_r0, ins->inst_imm);
3069 if (is_unsigned (ins->next))
3070 s390_clr (code, ins->sreg1, s390_r0);
3072 s390_cr (code, ins->sreg1, s390_r0);
3075 s390_basr (code, s390_r13, 0);
3077 s390_word (code, ins->inst_imm);
3078 if (is_unsigned (ins->next))
3079 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3081 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3086 s390_basr (code, s390_r13, 0);
3088 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3090 s390_llong (code, mono_break);
3091 s390_lg (code, s390_r14, 0, s390_r13, 4);
3092 s390_basr (code, s390_r14, s390_r14);
3097 s390_agr (code, ins->dreg, src2);
3102 s390_agr (code, ins->dreg, src2);
3107 s390_alcgr (code, ins->dreg, src2);
3111 if (ins->dreg != ins->sreg1) {
3112 s390_lgr (code, ins->dreg, ins->sreg1);
3114 if (s390_is_imm16 (ins->inst_imm)) {
3115 s390_aghi (code, ins->dreg, ins->inst_imm);
3117 s390_basr (code, s390_r13, 0);
3119 s390_llong(code, ins->inst_imm);
3120 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3125 if (ins->dreg != ins->sreg1) {
3126 s390_lgr (code, ins->dreg, ins->sreg1);
3128 g_assert (s390_is_imm16 (ins->inst_imm));
3129 s390_aghi (code, ins->dreg, ins->inst_imm);
3133 if (ins->dreg != ins->sreg1) {
3134 s390_lgr (code, ins->dreg, ins->sreg1);
3136 if (s390_is_imm16 (ins->inst_imm)) {
3137 s390_lghi (code, s390_r0, ins->inst_imm);
3138 s390_alcgr (code, ins->dreg, s390_r0);
3140 s390_basr (code, s390_r13, 0);
3142 s390_llong (code, ins->inst_imm);
3143 s390_lg (code, s390_r13, 0, s390_r13, 4);
3144 s390_alcgr (code, ins->dreg, s390_r13);
3149 case OP_S390_IADD_OVF: {
3151 s390_ar (code, ins->dreg, src2);
3152 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3153 s390_lgfr (code, ins->dreg, ins->dreg);
3156 case OP_IADD_OVF_UN:
3157 case OP_S390_IADD_OVF_UN: {
3159 s390_algr (code, ins->dreg, src2);
3160 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3161 s390_llgfr (code, ins->dreg, ins->dreg);
3164 case OP_ADD_OVF_CARRY: {
3166 s390_lghi (code, s390_r0, 0);
3167 s390_lgr (code, s390_r1, s390_r0);
3168 s390_alcgr (code, s390_r0, s390_r1);
3169 s390_agr (code, ins->dreg, src2);
3170 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3171 s390_agr (code, ins->dreg, s390_r0);
3172 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3175 case OP_ADD_OVF_UN_CARRY: {
3177 s390_alcgr (code, ins->dreg, src2);
3178 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3183 s390_sgr (code, ins->dreg, src2);
3188 s390_sgr (code, ins->dreg, src2);
3193 s390_slbgr(code, ins->dreg, src2);
3197 if (ins->dreg != ins->sreg1) {
3198 s390_lgr (code, ins->dreg, ins->sreg1);
3200 if (s390_is_imm16 (-ins->inst_imm)) {
3201 s390_lghi (code, s390_r0, ins->inst_imm);
3202 s390_slgr (code, ins->dreg, s390_r0);
3204 s390_basr (code, s390_r13, 0);
3206 s390_llong(code, ins->inst_imm);
3207 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3212 if (ins->dreg != ins->sreg1) {
3213 s390_lgr (code, ins->dreg, ins->sreg1);
3215 if (s390_is_imm16 (-ins->inst_imm)) {
3216 s390_lghi (code, s390_r0, ins->inst_imm);
3217 s390_slgr (code, ins->dreg, s390_r0);
3219 s390_basr (code, s390_r13, 0);
3221 s390_llong(code, ins->inst_imm);
3222 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3227 if (ins->dreg != ins->sreg1) {
3228 s390_lgr (code, ins->dreg, ins->sreg1);
3230 if (s390_is_imm16 (-ins->inst_imm)) {
3231 s390_lghi (code, s390_r0, ins->inst_imm);
3232 s390_slbgr (code, ins->dreg, s390_r0);
3234 s390_basr (code, s390_r13, 0);
3236 s390_llong(code, ins->inst_imm);
3237 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3241 case OP_SUB_OVF_CARRY: {
3243 s390_lghi (code, s390_r0, 0);
3244 s390_lgr (code, s390_r1, s390_r0);
3245 s390_slbgr (code, s390_r0, s390_r1);
3246 s390_sgr (code, ins->dreg, src2);
3247 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3248 s390_agr (code, ins->dreg, s390_r0);
3249 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3252 case OP_SUB_OVF_UN_CARRY: {
3254 s390_slbgr (code, ins->dreg, src2);
3255 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3259 if (ins->sreg1 == ins->dreg) {
3260 s390_ngr (code, ins->dreg, ins->sreg2);
3263 if (ins->sreg2 == ins->dreg) {
3264 s390_ngr (code, ins->dreg, ins->sreg1);
3267 s390_lgr (code, ins->dreg, ins->sreg1);
3268 s390_ngr (code, ins->dreg, ins->sreg2);
3274 if (ins->dreg != ins->sreg1) {
3275 s390_lgr (code, ins->dreg, ins->sreg1);
3277 if (s390_is_imm16 (ins->inst_imm)) {
3278 s390_lghi (code, s390_r0, ins->inst_imm);
3279 s390_ngr (code, ins->dreg, s390_r0);
3281 s390_basr (code, s390_r13, 0);
3283 s390_llong(code, ins->inst_imm);
3284 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3289 s390_lgr (code, s390_r1, ins->sreg1);
3290 s390_dsgr (code, s390_r0, ins->sreg2);
3291 s390_lgr (code, ins->dreg, s390_r1);
3295 s390_lgr (code, s390_r1, ins->sreg1);
3296 s390_lghi (code, s390_r0, 0);
3297 s390_dlgr (code, s390_r0, ins->sreg2);
3298 s390_lgr (code, ins->dreg, s390_r1);
3302 s390_lgr (code, s390_r1, ins->sreg1);
3303 s390_dsgr (code, s390_r0, ins->sreg2);
3304 s390_lgr (code, ins->dreg, s390_r0);
3308 s390_lgr (code, s390_r1, ins->sreg1);
3309 s390_lghi (code, s390_r0, 0);
3310 s390_dlgr (code, s390_r0, ins->sreg2);
3311 s390_lgr (code, ins->dreg, s390_r0);
3315 if (ins->sreg1 == ins->dreg) {
3316 s390_ogr (code, ins->dreg, ins->sreg2);
3319 if (ins->sreg2 == ins->dreg) {
3320 s390_ogr (code, ins->dreg, ins->sreg1);
3323 s390_lgr (code, ins->dreg, ins->sreg1);
3324 s390_ogr (code, ins->dreg, ins->sreg2);
3330 if (ins->dreg != ins->sreg1) {
3331 s390_lgr (code, ins->dreg, ins->sreg1);
3333 if (s390_is_imm16 (ins->inst_imm)) {
3334 s390_lghi (code, s390_r0, ins->inst_imm);
3335 s390_ogr (code, ins->dreg, s390_r0);
3337 s390_basr (code, s390_r13, 0);
3339 s390_llong(code, ins->inst_imm);
3340 s390_og (code, ins->dreg, 0, s390_r13, 4);
3345 if (ins->sreg1 == ins->dreg) {
3346 s390_xgr (code, ins->dreg, ins->sreg2);
3349 if (ins->sreg2 == ins->dreg) {
3350 s390_xgr (code, ins->dreg, ins->sreg1);
3353 s390_lgr (code, ins->dreg, ins->sreg1);
3354 s390_xgr (code, ins->dreg, ins->sreg2);
3360 if (ins->dreg != ins->sreg1) {
3361 s390_lgr (code, ins->dreg, ins->sreg1);
3363 if (s390_is_imm16 (ins->inst_imm)) {
3364 s390_lghi (code, s390_r0, ins->inst_imm);
3365 s390_xgr (code, ins->dreg, s390_r0);
3367 s390_basr (code, s390_r13, 0);
3369 s390_llong(code, ins->inst_imm);
3370 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3376 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3381 if (ins->sreg1 != ins->dreg) {
3382 s390_lgr (code, ins->dreg, ins->sreg1);
3384 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3389 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3394 if (ins->sreg1 != ins->dreg) {
3395 s390_lgr (code, ins->dreg, ins->sreg1);
3397 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3401 case OP_LSHR_UN_IMM: {
3402 if (ins->sreg1 != ins->dreg) {
3403 s390_lgr (code, ins->dreg, ins->sreg1);
3405 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3410 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3414 if (ins->sreg1 != ins->dreg) {
3415 s390_lgr (code, ins->dreg, ins->sreg1);
3417 s390_lghi (code, s390_r0, -1);
3418 s390_xgr (code, ins->dreg, s390_r0);
3422 s390_lcgr (code, ins->dreg, ins->sreg1);
3427 s390_msgr (code, ins->dreg, src2);
3432 if (ins->dreg != ins->sreg1) {
3433 s390_lgr (code, ins->dreg, ins->sreg1);
3435 if (s390_is_imm16 (ins->inst_imm)) {
3436 s390_lghi (code, s390_r13, ins->inst_imm);
3438 s390_basr (code, s390_r13, 0);
3440 s390_llong(code, ins->inst_imm);
3441 s390_lg (code, s390_r13, 0, s390_r13, 4);
3443 s390_msgr (code, ins->dreg, s390_r13);
3448 s390_ltgr (code, s390_r1, ins->sreg1);
3449 s390_jz (code, 0); CODEPTR(code, o[0]);
3450 s390_ltgr (code, s390_r0, ins->sreg2);
3452 s390_lghi (code, s390_r1, 0);
3453 s390_j (code, 0); CODEPTR(code, o[1]);
3454 s390_xgr (code, s390_r0, s390_r1);
3455 s390_msgr (code, s390_r1, ins->sreg2);
3456 s390_xgr (code, s390_r0, s390_r1);
3457 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3458 s390_ltgr (code, s390_r0, s390_r0);
3459 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3460 PTRSLOT (code, o[0]);
3461 PTRSLOT (code, o[1]);
3462 s390_lgr (code, ins->dreg, s390_r1);
3465 case OP_LMUL_OVF_UN: {
3466 s390_lghi (code, s390_r0, 0);
3467 s390_lgr (code, s390_r1, ins->sreg1);
3468 s390_mlgr (code, s390_r0, ins->sreg2);
3469 s390_ltgr (code, s390_r0, s390_r0);
3470 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3471 s390_lgr (code, ins->dreg, s390_r1);
3475 g_assert_not_reached ();
3477 s390_algr (code, ins->dreg, src2);
3482 s390_agr (code, ins->dreg, src2);
3486 g_assert_not_reached ();
3488 s390_alcgr (code, ins->dreg, src2);
3492 if (ins->dreg != ins->sreg1) {
3493 s390_lgfr (code, ins->dreg, ins->sreg1);
3495 if (s390_is_imm16 (ins->inst_imm)) {
3496 s390_aghi(code, ins->dreg, ins->inst_imm);
3498 s390_basr (code, s390_r13, 0);
3500 s390_word (code, ins->inst_imm);
3501 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3506 if (ins->dreg != ins->sreg1) {
3507 s390_lgfr (code, ins->dreg, ins->sreg1);
3509 if (s390_is_imm16 (ins->inst_imm)) {
3510 s390_lghi (code, s390_r0, ins->inst_imm);
3511 s390_alcgr (code, ins->dreg, s390_r0);
3513 s390_basr (code, s390_r13, 0);
3515 s390_word (code, ins->inst_imm);
3516 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3517 s390_alcgr (code, ins->dreg, s390_r13);
3522 case OP_S390_LADD_OVF: {
3524 s390_agr (code, ins->dreg, src2);
3525 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3528 case OP_LADD_OVF_UN:
3529 case OP_S390_LADD_OVF_UN: {
3531 s390_algr (code, ins->dreg, src2);
3532 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3536 CHECK_SRCDST_NCOM_I;
3537 s390_slgr (code, ins->dreg, src2);
3541 CHECK_SRCDST_NCOM_I;
3542 s390_sgr (code, ins->dreg, src2);
3546 CHECK_SRCDST_NCOM_I;
3547 s390_slbgr (code, ins->dreg, src2);
3551 if (ins->dreg != ins->sreg1) {
3552 s390_lgfr (code, ins->dreg, ins->sreg1);
3554 if (s390_is_imm16 (-ins->inst_imm)) {
3555 s390_aghi (code, ins->dreg, -ins->inst_imm);
3557 s390_basr (code, s390_r13, 0);
3559 s390_word (code, ins->inst_imm);
3560 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3565 s390_basr (code, s390_r13, 0);
3567 s390_word (code, ins->inst_imm);
3568 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3572 case OP_S390_ISUB_OVF: {
3574 s390_sr (code, ins->dreg, src2);
3575 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3576 s390_lgfr (code, ins->dreg, ins->dreg);
3579 case OP_ISUB_OVF_UN:
3580 case OP_S390_ISUB_OVF_UN: {
3582 s390_slr (code, ins->dreg, src2);
3583 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3584 s390_llgfr(code, ins->dreg, ins->dreg);
3588 case OP_S390_LSUB_OVF: {
3590 s390_sgr (code, ins->dreg, src2);
3591 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3594 case OP_LSUB_OVF_UN:
3595 case OP_S390_LSUB_OVF_UN: {
3597 s390_slgr (code, ins->dreg, src2);
3598 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3602 CHECK_SRCDST_NCOM_I;
3603 s390_ngr (code, ins->dreg, src2);
3607 if (ins->dreg != ins->sreg1) {
3608 s390_lgfr (code, ins->dreg, ins->sreg1);
3610 if (s390_is_imm16 (ins->inst_imm)) {
3611 s390_lghi (code, s390_r0, ins->inst_imm);
3612 s390_ngr (code, ins->dreg, s390_r0);
3614 s390_basr (code, s390_r13, 0);
3616 s390_llong(code, ins->inst_imm);
3617 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3622 s390_lgfr (code, s390_r0, ins->sreg1);
3623 s390_srda (code, s390_r0, 0, 32);
3624 s390_dr (code, s390_r0, ins->sreg2);
3625 s390_lgfr (code, ins->dreg, s390_r1);
3629 s390_lgfr (code, s390_r0, ins->sreg1);
3630 s390_srdl (code, s390_r0, 0, 32);
3631 s390_dlr (code, s390_r0, ins->sreg2);
3632 s390_lgfr (code, ins->dreg, s390_r1);
3636 if (s390_is_imm16 (ins->inst_imm)) {
3637 s390_lghi (code, s390_r13, ins->inst_imm);
3638 s390_lgfr (code, s390_r0, ins->sreg1);
3640 s390_basr (code, s390_r13, 0);
3642 s390_word (code, ins->inst_imm);
3643 s390_lgfr (code, s390_r0, ins->sreg1);
3644 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3646 s390_srda (code, s390_r0, 0, 32);
3647 s390_dr (code, s390_r0, ins->sreg2);
3648 s390_lgfr (code, ins->dreg, s390_r1);
3652 s390_lgfr (code, s390_r0, ins->sreg1);
3653 s390_srda (code, s390_r0, 0, 32);
3654 s390_dr (code, s390_r0, ins->sreg2);
3655 s390_lgfr (code, ins->dreg, s390_r0);
3658 s390_lgfr (code, s390_r0, ins->sreg1);
3659 s390_srdl (code, s390_r0, 0, 32);
3660 s390_dlr (code, s390_r0, ins->sreg2);
3661 s390_lgfr (code, ins->dreg, s390_r0);
3665 if (s390_is_imm16 (ins->inst_imm)) {
3666 s390_lghi (code, s390_r13, ins->inst_imm);
3667 s390_lgfr (code, s390_r0, ins->sreg1);
3669 s390_basr (code, s390_r13, 0);
3671 s390_word (code, ins->inst_imm);
3672 s390_lgfr (code, s390_r0, ins->sreg1);
3673 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3675 s390_srda (code, s390_r0, 0, 32);
3676 s390_dr (code, s390_r0, ins->sreg2);
3677 s390_lgfr (code, ins->dreg, s390_r0);
3682 s390_ogr (code, ins->dreg, src2);
3686 if (ins->dreg != ins->sreg1) {
3687 s390_lgfr (code, ins->dreg, ins->sreg1);
3689 if (s390_is_imm16 (ins->inst_imm)) {
3690 s390_lghi (code, s390_r0, ins->inst_imm);
3691 s390_ogr (code, ins->dreg, s390_r0);
3693 s390_basr (code, s390_r13, 0);
3695 s390_llong(code, ins->inst_imm);
3696 s390_og (code, ins->dreg, 0, s390_r13, 4);
3702 s390_xgr (code, ins->dreg, src2);
3706 if (ins->dreg != ins->sreg1) {
3707 s390_lgfr (code, ins->dreg, ins->sreg1);
3709 if (s390_is_imm16 (ins->inst_imm)) {
3710 s390_lghi (code, s390_r0, ins->inst_imm);
3711 s390_xgr (code, ins->dreg, s390_r0);
3713 s390_basr (code, s390_r13, 0);
3715 s390_llong(code, ins->inst_imm);
3716 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3722 s390_sll (code, ins->dreg, src2, 0);
3726 if (ins->sreg1 != ins->dreg) {
3727 s390_lgfr (code, ins->dreg, ins->sreg1);
3729 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3734 s390_sra (code, ins->dreg, src2, 0);
3738 if (ins->sreg1 != ins->dreg) {
3739 s390_lgfr (code, ins->dreg, ins->sreg1);
3741 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3744 case OP_ISHR_UN_IMM: {
3745 if (ins->sreg1 != ins->dreg) {
3746 s390_lgfr (code, ins->dreg, ins->sreg1);
3748 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3753 s390_srl (code, ins->dreg, src2, 0);
3757 if (ins->sreg1 != ins->dreg) {
3758 s390_lgfr (code, ins->dreg, ins->sreg1);
3760 s390_lghi (code, s390_r0, -1);
3761 s390_xgr (code, ins->dreg, s390_r0);
3765 s390_lcgr (code, ins->dreg, ins->sreg1);
3770 s390_msr (code, ins->dreg, src2);
3774 if (ins->dreg != ins->sreg1) {
3775 s390_lgfr (code, ins->dreg, ins->sreg1);
3777 if (s390_is_imm16 (ins->inst_imm)) {
3778 s390_lghi (code, s390_r13, ins->inst_imm);
3780 s390_basr (code, s390_r13, 0);
3782 s390_word (code, ins->inst_imm);
3783 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3785 s390_msr (code, ins->dreg, s390_r13);
3790 s390_ltr (code, s390_r1, ins->sreg1);
3791 s390_jz (code, 0); CODEPTR(code, o[0]);
3792 s390_ltr (code, s390_r0, ins->sreg2);
3794 s390_lhi (code, s390_r1, 0);
3795 s390_j (code, 0); CODEPTR(code, o[1]);
3796 s390_xr (code, s390_r0, s390_r1);
3797 s390_msr (code, s390_r1, ins->sreg2);
3798 s390_xr (code, s390_r0, s390_r1);
3799 s390_srl (code, s390_r0, 0, 31);
3800 s390_ltr (code, s390_r0, s390_r0);
3801 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3802 PTRSLOT (code, o[0]);
3803 PTRSLOT (code, o[1]);
3804 s390_lgfr (code, ins->dreg, s390_r1);
3807 case OP_IMUL_OVF_UN: {
3808 s390_lhi (code, s390_r0, 0);
3809 s390_lr (code, s390_r1, ins->sreg1);
3810 s390_mlr (code, s390_r0, ins->sreg2);
3811 s390_ltr (code, s390_r0, s390_r0);
3812 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3813 s390_lgfr (code, ins->dreg, s390_r1);
3818 if (s390_is_imm16(ins->inst_c0)) {
3819 s390_lghi (code, ins->dreg, ins->inst_c0);
3821 s390_basr (code, s390_r13, 0);
3823 s390_llong(code, ins->inst_c0);
3824 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3829 s390_basr (code, s390_r13, 0);
3831 mono_add_patch_info (cfg, code - cfg->native_code,
3832 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3833 s390_llong(code, 0);
3834 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3837 case OP_JUMP_TABLE: {
3838 mono_add_patch_info (cfg, code - cfg->native_code,
3839 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3840 s390_basr (code, s390_r13, 0);
3842 s390_llong (code, 0);
3843 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3847 if (ins->dreg != ins->sreg1) {
3848 s390_lgr (code, ins->dreg, ins->sreg1);
3852 case OP_LCONV_TO_I8:
3854 s390_lgfr (code, ins->dreg, ins->sreg1);
3856 case OP_LCONV_TO_I4:
3857 s390_lgfr (code, ins->dreg, ins->sreg1);
3860 case OP_LCONV_TO_U8:
3861 case OP_LCONV_TO_U4:
3863 s390_llgfr (code, ins->dreg, ins->sreg1);
3865 case OP_LCONV_TO_OVF_U4:
3866 s390_basr (code, s390_r13, 0);
3868 s390_llong(code, 4294967295);
3869 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3870 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3871 s390_ltgr (code, ins->sreg1, ins->sreg1);
3872 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3873 s390_llgfr(code, ins->dreg, ins->sreg1);
3875 case OP_LCONV_TO_OVF_I4_UN:
3876 s390_basr (code, s390_r13, 0);
3878 s390_llong(code, 2147483647);
3879 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3880 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3881 s390_ltgr (code, ins->sreg1, ins->sreg1);
3882 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3883 s390_lgfr (code, ins->dreg, ins->sreg1);
3886 case OP_FCONV_TO_R4: {
3887 if (ins->dreg != ins->sreg1) {
3888 s390_ldr (code, ins->dreg, ins->sreg1);
3892 case OP_S390_SETF4RET: {
3893 s390_ledbr (code, ins->dreg, ins->sreg1);
3897 if (cfg->method->save_lmf)
3898 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3900 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3901 code = emit_load_volatile_arguments (code, cfg);
3904 code = backUpStackPtr(cfg, code);
3905 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3906 mono_add_patch_info (cfg, code - cfg->native_code,
3907 MONO_PATCH_INFO_METHOD_JUMP,
3909 s390_jcl (code, S390_CC_UN, 0);
3912 case OP_CHECK_THIS: {
3913 /* ensure ins->sreg1 is not NULL */
3914 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3915 s390_ltgr (code, s390_r0, s390_r0);
3919 int offset = cfg->sig_cookie + cfg->stack_usage;
3921 if (s390_is_imm16 (offset))
3922 s390_lghi (code, s390_r0, offset);
3924 s390_basr (code, s390_r13, 0);
3926 s390_llong(code, offset);
3927 s390_lg (code, s390_r0, 0, s390_r13, 0);
3929 s390_agr (code, s390_r0, cfg->frame_reg);
3930 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3934 s390_basr (code, s390_r13, 0);
3936 call = (MonoCallInst*)ins;
3937 if (ins->flags & MONO_INST_HAS_METHOD)
3938 mono_add_patch_info (cfg, code-cfg->native_code,
3939 MONO_PATCH_INFO_METHOD,
3942 mono_add_patch_info (cfg, code-cfg->native_code,
3943 MONO_PATCH_INFO_ABS,
3945 s390_llong(code, 0);
3946 s390_lg (code, s390_r14, 0, s390_r13, 4);
3947 s390_basr (code, s390_r14, s390_r14);
3948 if (call->signature->ret->type == MONO_TYPE_R4)
3949 s390_ldebr (code, s390_f0, s390_f0);
3957 s390_basr (code, s390_r13, 0);
3959 call = (MonoCallInst*)ins;
3960 if (ins->flags & MONO_INST_HAS_METHOD)
3961 mono_add_patch_info (cfg, code-cfg->native_code,
3962 MONO_PATCH_INFO_METHOD,
3965 mono_add_patch_info (cfg, code-cfg->native_code,
3966 MONO_PATCH_INFO_ABS,
3968 s390_llong(code, 0);
3969 s390_lg (code, s390_r14, 0, s390_r13, 4);
3970 s390_basr (code, s390_r14, s390_r14);
3973 case OP_FCALL_REG: {
3974 call = (MonoCallInst*)ins;
3975 s390_lgr (code, s390_r1, ins->sreg1);
3976 s390_basr (code, s390_r14, s390_r1);
3977 if (call->signature->ret->type == MONO_TYPE_R4)
3978 s390_ldebr (code, s390_f0, s390_f0);
3984 case OP_VOIDCALL_REG:
3986 s390_lgr (code, s390_r1, ins->sreg1);
3987 s390_basr (code, s390_r14, s390_r1);
3990 case OP_FCALL_MEMBASE: {
3991 call = (MonoCallInst*)ins;
3992 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3993 s390_basr (code, s390_r14, s390_r1);
3994 if (call->signature->ret->type == MONO_TYPE_R4)
3995 s390_ldebr (code, s390_f0, s390_f0);
3998 case OP_LCALL_MEMBASE:
3999 case OP_VCALL_MEMBASE:
4000 case OP_VCALL2_MEMBASE:
4001 case OP_VOIDCALL_MEMBASE:
4002 case OP_CALL_MEMBASE: {
4003 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4004 s390_basr (code, s390_r14, s390_r1);
4011 if (cfg->param_area == 0)
4012 alloca_skip = S390_MINIMAL_STACK_SIZE;
4014 alloca_skip = cfg->param_area;
4016 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4017 s390_lgr (code, s390_r1, ins->sreg1);
4018 if (ins->flags & MONO_INST_INIT)
4019 s390_lgr (code, s390_r0, ins->sreg1);
4020 s390_aghi (code, s390_r1, 14);
4021 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4022 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4023 if (cfg->method->save_lmf) {
4024 /*----------------------------------*/
4025 /* we have to adjust lmf ebp value */
4026 /*----------------------------------*/
4027 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4029 s390_lgr (code, s390_r13, cfg->frame_reg);
4030 if (s390_is_imm16(lmfOffset))
4031 s390_aghi (code, s390_r13, lmfOffset);
4033 s390_basr (code, s390_r14, 0);
4035 s390_word (code, lmfOffset);
4036 s390_agf (code, s390_r13, 0, s390_r14, 4);
4038 s390_lgr (code, s390_r14, STK_BASE);
4039 s390_sgr (code, s390_r14, s390_r1);
4040 s390_stg (code, s390_r14, 0, s390_r13,
4041 G_STRUCT_OFFSET(MonoLMF, ebp));
4043 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4044 s390_sgr (code, STK_BASE, s390_r1);
4045 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4046 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4047 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4048 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4049 if (ins->flags & MONO_INST_INIT) {
4050 s390_lgr (code, s390_r1, s390_r0);
4051 s390_lgr (code, s390_r0, ins->dreg);
4052 s390_lgr (code, s390_r14, s390_r12);
4053 s390_lghi (code, s390_r13, 0);
4054 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4056 s390_lgr (code, s390_r12, s390_r14);
4061 s390_lgr (code, s390_r2, ins->sreg1);
4062 s390_basr (code, s390_r13, 0);
4064 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4065 (gpointer) "mono_arch_throw_exception");
4066 s390_llong(code, 0);
4067 s390_lg (code, s390_r14, 0, s390_r13, 4);
4068 s390_basr (code, s390_r14, s390_r14);
4072 s390_lgr (code, s390_r2, ins->sreg1);
4073 s390_basr (code, s390_r13, 0);
4075 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4076 (gpointer) "mono_arch_rethrow_exception");
4077 s390_llong(code, 0);
4078 s390_lg (code, s390_r14, 0, s390_r13, 4);
4079 s390_basr (code, s390_r14, s390_r14);
4082 case OP_START_HANDLER: {
4083 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4085 S390_LONG (code, stg, stg, s390_r14, 0,
4086 spvar->inst_basereg,
4087 spvar->inst_offset);
4090 case OP_ENDFILTER: {
4091 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4093 if (ins->sreg1 != s390_r2)
4094 s390_lgr(code, s390_r2, ins->sreg1);
4095 S390_LONG (code, lg, lg, s390_r14, 0,
4096 spvar->inst_basereg,
4097 spvar->inst_offset);
4098 s390_br (code, s390_r14);
4101 case OP_ENDFINALLY: {
4102 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4104 S390_LONG (code, lg, lg, s390_r14, 0,
4105 spvar->inst_basereg,
4106 spvar->inst_offset);
4107 s390_br (code, s390_r14);
4110 case OP_CALL_HANDLER: {
4111 mono_add_patch_info (cfg, code-cfg->native_code,
4112 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4113 s390_brasl (code, s390_r14, 0);
4114 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4118 ins->inst_c0 = code - cfg->native_code;
4121 case OP_RELAXED_NOP:
4124 case OP_DUMMY_STORE:
4125 case OP_NOT_REACHED:
4130 EMIT_UNCOND_BRANCH(ins);
4133 s390_br (code, ins->sreg1);
4139 s390_lghi(code, ins->dreg, 1);
4141 s390_lghi(code, ins->dreg, 0);
4147 s390_lghi(code, ins->dreg, 1);
4149 s390_lghi(code, ins->dreg, 0);
4155 s390_lghi(code, ins->dreg, 1);
4157 s390_lghi(code, ins->dreg, 0);
4163 s390_lghi(code, ins->dreg, 1);
4165 s390_lghi(code, ins->dreg, 0);
4171 s390_lghi(code, ins->dreg, 1);
4173 s390_lghi(code, ins->dreg, 0);
4176 case OP_COND_EXC_EQ:
4177 case OP_COND_EXC_IEQ:
4178 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4180 case OP_COND_EXC_NE_UN:
4181 case OP_COND_EXC_INE_UN:
4182 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4184 case OP_COND_EXC_LT:
4185 case OP_COND_EXC_ILT:
4186 case OP_COND_EXC_LT_UN:
4187 case OP_COND_EXC_ILT_UN:
4188 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4190 case OP_COND_EXC_GT:
4191 case OP_COND_EXC_IGT:
4192 case OP_COND_EXC_GT_UN:
4193 case OP_COND_EXC_IGT_UN:
4194 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4196 case OP_COND_EXC_GE:
4197 case OP_COND_EXC_IGE:
4198 case OP_COND_EXC_GE_UN:
4199 case OP_COND_EXC_IGE_UN:
4200 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4202 case OP_COND_EXC_LE:
4203 case OP_COND_EXC_ILE:
4204 case OP_COND_EXC_LE_UN:
4205 case OP_COND_EXC_ILE_UN:
4206 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4208 case OP_COND_EXC_OV:
4209 case OP_COND_EXC_IOV:
4210 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4212 case OP_COND_EXC_NO:
4213 case OP_COND_EXC_INO:
4214 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4217 case OP_COND_EXC_IC:
4218 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4220 case OP_COND_EXC_NC:
4221 case OP_COND_EXC_INC:
4222 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4226 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4230 EMIT_COND_BRANCH (ins, S390_CC_NE);
4236 EMIT_COND_BRANCH (ins, S390_CC_LT);
4242 EMIT_COND_BRANCH (ins, S390_CC_GT);
4248 EMIT_COND_BRANCH (ins, S390_CC_GE);
4254 EMIT_COND_BRANCH (ins, S390_CC_LE);
4257 /* floating point opcodes */
4259 if (*((float *) ins->inst_p0) == 0) {
4260 s390_lzdr (code, ins->dreg);
4262 s390_basr (code, s390_r13, 0);
4264 s390_llong (code, ins->inst_p0);
4265 s390_lg (code, s390_r13, 0, s390_r13, 4);
4266 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4271 if (*((float *) ins->inst_p0) == 0) {
4272 s390_lzdr (code, ins->dreg);
4274 s390_basr (code, s390_r13, 0);
4276 s390_llong(code, ins->inst_p0);
4277 s390_lg (code, s390_r13, 0, s390_r13, 4);
4278 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4282 case OP_STORER8_MEMBASE_REG: {
4283 S390_LONG (code, stdy, std, ins->sreg1, 0,
4284 ins->inst_destbasereg, ins->inst_offset);
4287 case OP_LOADR8_MEMBASE: {
4288 S390_LONG (code, ldy, ld, ins->dreg, 0,
4289 ins->inst_basereg, ins->inst_offset);
4292 case OP_STORER4_MEMBASE_REG: {
4293 s390_ledbr (code, s390_f15, ins->sreg1);
4294 S390_LONG (code, stey, ste, s390_f15, 0,
4295 ins->inst_destbasereg, ins->inst_offset);
4298 case OP_LOADR4_MEMBASE: {
4299 S390_LONG (code, ldy, ld, s390_f15, 0,
4300 ins->inst_basereg, ins->inst_offset);
4301 s390_ldebr (code, ins->dreg, s390_f15);
4304 case OP_ICONV_TO_R_UN: {
4305 s390_cdfbr (code, ins->dreg, ins->sreg1);
4306 s390_ltr (code, ins->sreg1, ins->sreg1);
4307 s390_jnl (code, 12);
4308 s390_basr (code, s390_r13, 0);
4310 s390_word (code, 0x41f00000);
4311 s390_word (code, 0);
4312 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4315 case OP_LCONV_TO_R_UN: {
4316 s390_cdgbr (code, ins->dreg, ins->sreg1);
4317 s390_ltgr (code, ins->sreg1, ins->sreg1);
4318 s390_jnl (code, 12);
4319 s390_basr (code, s390_r13, 0);
4321 s390_word (code, 0x41f00000);
4322 s390_word (code, 0);
4323 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4326 case OP_LCONV_TO_R4:
4327 case OP_ICONV_TO_R4: {
4328 s390_cdgbr (code, ins->dreg, ins->sreg1);
4331 case OP_LCONV_TO_R8:
4332 case OP_ICONV_TO_R8: {
4333 s390_cdgbr (code, ins->dreg, ins->sreg1);
4336 case OP_FCONV_TO_I1:
4337 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4339 case OP_FCONV_TO_U1:
4340 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4342 case OP_FCONV_TO_I2:
4343 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4345 case OP_FCONV_TO_U2:
4346 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4348 case OP_FCONV_TO_I4:
4350 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4352 case OP_FCONV_TO_U4:
4354 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4356 case OP_FCONV_TO_I8:
4357 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4359 case OP_LCONV_TO_OVF_I: {
4360 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4362 s390_ltgr (code, ins->sreg2, ins->sreg2);
4363 s390_jnl (code, 0); CODEPTR(code, o[0]);
4364 s390_ltgr (code, ins->sreg1, ins->sreg1);
4365 s390_jnl (code, 0); CODEPTR(code, o[1]);
4366 s390_lhi (code, s390_r13, -1);
4367 s390_cgr (code, ins->sreg1, s390_r13);
4368 s390_jnz (code, 0); CODEPTR(code, o[2]);
4369 if (ins->dreg != ins->sreg2)
4370 s390_lgr (code, ins->dreg, ins->sreg2);
4371 s390_j (code, 0); CODEPTR(code, o[3]);
4372 PTRSLOT(code, o[0]);
4373 s390_jz (code, 0); CODEPTR(code, o[4]);
4374 PTRSLOT(code, o[1]);
4375 PTRSLOT(code, o[2]);
4376 mono_add_patch_info (cfg, code - cfg->native_code,
4377 MONO_PATCH_INFO_EXC, "OverflowException");
4378 s390_brasl (code, s390_r14, 0);
4379 PTRSLOT(code, o[3]);
4380 PTRSLOT(code, o[4]);
4384 s390_lpdbr (code, ins->dreg, ins->sreg1);
4388 s390_sqdbr (code, ins->dreg, ins->sreg1);
4393 s390_adbr (code, ins->dreg, src2);
4397 CHECK_SRCDST_NCOM_F;
4398 s390_sdbr (code, ins->dreg, src2);
4403 s390_mdbr (code, ins->dreg, src2);
4407 CHECK_SRCDST_NCOM_F;
4408 s390_ddbr (code, ins->dreg, src2);
4412 s390_lcdbr (code, ins->dreg, ins->sreg1);
4416 CHECK_SRCDST_NCOM_F;
4417 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4421 s390_cdbr (code, ins->sreg1, ins->sreg2);
4425 s390_cdbr (code, ins->sreg1, ins->sreg2);
4426 s390_lghi (code, ins->dreg, 1);
4428 s390_lghi (code, ins->dreg, 0);
4432 s390_cdbr (code, ins->sreg1, ins->sreg2);
4433 s390_lghi (code, ins->dreg, 1);
4435 s390_lghi (code, ins->dreg, 0);
4439 s390_cdbr (code, ins->sreg1, ins->sreg2);
4440 s390_lghi (code, ins->dreg, 1);
4442 s390_lghi (code, ins->dreg, 0);
4446 s390_cdbr (code, ins->sreg1, ins->sreg2);
4447 s390_lghi (code, ins->dreg, 1);
4449 s390_lghi (code, ins->dreg, 0);
4453 s390_cdbr (code, ins->sreg1, ins->sreg2);
4454 s390_lghi (code, ins->dreg, 1);
4456 s390_lghi (code, ins->dreg, 0);
4461 s390_jo (code, 0); CODEPTR(code, o);
4462 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4467 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4471 s390_jo (code, 0); CODEPTR(code, o);
4472 EMIT_COND_BRANCH (ins, S390_CC_LT);
4477 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4481 s390_jo (code, 0); CODEPTR(code, o);
4482 EMIT_COND_BRANCH (ins, S390_CC_GT);
4487 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4491 s390_jo (code, 0); CODEPTR(code, o);
4492 EMIT_COND_BRANCH (ins, S390_CC_GE);
4497 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4501 s390_jo (code, 0); CODEPTR(code, o);
4502 EMIT_COND_BRANCH (ins, S390_CC_LE);
4507 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4511 s390_lhi (code, s390_r13, 0x7f);
4512 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4513 s390_jz (code, 0); CODEPTR(code, o);
4514 mono_add_patch_info (cfg, code - cfg->native_code,
4515 MONO_PATCH_INFO_EXC, "ArithmeticException");
4516 s390_brasl (code, s390_r14,0);
4520 case OP_S390_MOVE: {
4521 if (ins->backend.size > 0) {
4522 if (ins->backend.size <= 256) {
4523 s390_mvc (code, ins->backend.size, ins->dreg,
4524 ins->inst_offset, ins->sreg1, ins->inst_imm);
4526 s390_lgr (code, s390_r0, ins->dreg);
4527 if (ins->inst_offset > 0) {
4528 if (s390_is_imm16 (ins->inst_offset)) {
4529 s390_aghi (code, s390_r0, ins->inst_offset);
4531 s390_basr (code, s390_r13, 0);
4533 s390_llong(code, ins->inst_offset);
4534 s390_ag (code, s390_r0, 0, s390_r13, 4);
4537 s390_lgr (code, s390_r12, ins->sreg1);
4538 if (ins->inst_imm > 0) {
4539 if (s390_is_imm16 (ins->inst_imm)) {
4540 s390_aghi (code, s390_r12, ins->inst_imm);
4542 s390_basr (code, s390_r13, 0);
4544 s390_llong(code, ins->inst_imm);
4545 s390_ag (code, s390_r12, 0, s390_r13, 4);
4548 if (s390_is_imm16 (ins->backend.size)) {
4549 s390_lghi (code, s390_r1, ins->backend.size);
4551 s390_basr (code, s390_r13, 0);
4553 s390_llong(code, ins->backend.size);
4554 s390_lg (code, s390_r1, 0, s390_r13, 4);
4556 s390_lgr (code, s390_r13, s390_r1);
4557 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4563 case OP_ATOMIC_ADD_I8: {
4564 s390_lgr (code, s390_r1, ins->sreg2);
4565 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4566 s390_agr (code, s390_r1, s390_r0);
4567 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4568 s390_jnz (code, -10);
4569 s390_lgr (code, ins->dreg, s390_r1);
4572 case OP_ATOMIC_ADD_NEW_I8: {
4573 s390_lgr (code, s390_r1, ins->sreg2);
4574 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4575 s390_agr (code, s390_r1, s390_r0);
4576 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4577 s390_jnz (code, -10);
4578 s390_lgr (code, ins->dreg, s390_r1);
4581 case OP_ATOMIC_EXCHANGE_I8: {
4582 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4583 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4584 s390_jnz (code, -6);
4585 s390_lgr (code, ins->dreg, s390_r0);
4588 case OP_ATOMIC_ADD_I4: {
4589 s390_lgfr(code, s390_r1, ins->sreg2);
4590 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4591 s390_agr (code, s390_r1, s390_r0);
4592 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4593 s390_jnz (code, -9);
4594 s390_lgfr(code, ins->dreg, s390_r1);
4597 case OP_ATOMIC_ADD_NEW_I4: {
4598 s390_lgfr(code, s390_r1, ins->sreg2);
4599 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4600 s390_agr (code, s390_r1, s390_r0);
4601 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4602 s390_jnz (code, -9);
4603 s390_lgfr(code, ins->dreg, s390_r1);
4606 case OP_ATOMIC_EXCHANGE_I4: {
4607 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4608 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4609 s390_jnz (code, -4);
4610 s390_lgfr(code, ins->dreg, s390_r0);
4613 case OP_S390_BKCHAIN: {
4614 s390_lgr (code, ins->dreg, ins->sreg1);
4615 if (s390_is_imm16 (cfg->stack_offset)) {
4616 s390_aghi (code, ins->dreg, cfg->stack_offset);
4618 s390_basr (code, s390_r13, 0);
4620 s390_llong(code, cfg->stack_offset);
4621 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4625 case OP_MEMORY_BARRIER: {
4629 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4630 g_assert_not_reached ();
4633 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4634 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4635 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4636 g_assert_not_reached ();
4641 last_offset = offset;
4644 cfg->code_len = code - cfg->native_code;
4647 /*========================= End of Function ========================*/
4649 /*------------------------------------------------------------------*/
4651 /* Name - mono_arch_register_lowlevel_calls */
4653 /* Function - Register routines to help with --trace operation. */
4655 /*------------------------------------------------------------------*/
4658 mono_arch_register_lowlevel_calls (void)
4660 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4663 /*========================= End of Function ========================*/
4665 /*------------------------------------------------------------------*/
4667 /* Name - mono_arch_patch_code */
4669 /* Function - Process the patch data created during the */
4670 /* instruction build process. This resolves jumps, */
4671 /* calls, variables etc. */
4673 /*------------------------------------------------------------------*/
4676 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4677 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4679 MonoJumpInfo *patch_info;
4681 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4682 unsigned char *ip = patch_info->ip.i + code;
4683 gconstpointer target = NULL;
4685 target = mono_resolve_patch_target (method, domain, code,
4686 patch_info, run_cctors);
4688 switch (patch_info->type) {
4689 case MONO_PATCH_INFO_IP:
4690 case MONO_PATCH_INFO_EXC_NAME:
4691 case MONO_PATCH_INFO_LDSTR:
4692 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4693 case MONO_PATCH_INFO_LDTOKEN:
4694 case MONO_PATCH_INFO_EXC:
4695 case MONO_PATCH_INFO_ABS:
4696 case MONO_PATCH_INFO_METHOD:
4697 case MONO_PATCH_INFO_INTERNAL_METHOD:
4698 case MONO_PATCH_INFO_CLASS_INIT:
4699 s390_patch_addr (ip, (guint64) target);
4701 case MONO_PATCH_INFO_SWITCH:
4702 /*----------------------------------*/
4703 /* ip points at the basr r13,0/j +4 */
4704 /* instruction the vtable value */
4705 /* follows this (i.e. ip+6) */
4706 /*----------------------------------*/
4707 *((gconstpointer *)(ip+6)) = target;
4709 case MONO_PATCH_INFO_METHODCONST:
4710 case MONO_PATCH_INFO_CLASS:
4711 case MONO_PATCH_INFO_IMAGE:
4712 case MONO_PATCH_INFO_FIELD:
4713 case MONO_PATCH_INFO_IID:
4714 target = S390_RELATIVE(target, ip);
4715 s390_patch_rel (ip, (guint64) target);
4717 case MONO_PATCH_INFO_R4:
4718 case MONO_PATCH_INFO_R8:
4719 case MONO_PATCH_INFO_METHOD_REL:
4720 g_assert_not_reached ();
4723 target = S390_RELATIVE(target, ip);
4725 s390_patch_rel (ip, (guint64) target);
4730 /*========================= End of Function ========================*/
4732 /*------------------------------------------------------------------*/
4734 /* Name - emit_load_volatile_arguments */
4736 /* Function - Emit the instructions to reload parameter regist- */
4737 /* registers for use with "tail" operations. */
4739 /* The register loading operations performed here */
4740 /* are the mirror of the store operations performed */
4741 /* in mono_arch_emit_prolog and need to be kept in */
4742 /* synchronization with it. */
4744 /*------------------------------------------------------------------*/
4747 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4750 MonoMethod *method = cfg->method;
4751 MonoMethodSignature *sig = mono_method_signature(method);
4755 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4757 if (cinfo->struct_ret) {
4758 ArgInfo *ainfo = &cinfo->ret;
4759 inst = cfg->vret_addr;
4760 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4763 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4764 ArgInfo *ainfo = cinfo->args + i;
4765 inst = cfg->args [pos];
4767 if (inst->opcode == OP_REGVAR) {
4768 if (ainfo->regtype == RegTypeGeneral)
4769 s390_lgr (code, ainfo->reg, inst->dreg);
4770 else if (ainfo->regtype == RegTypeFP) {
4771 if (inst->dreg != ainfo->reg) {
4772 if (ainfo->size == 4) {
4773 s390_ldebr (code, ainfo->reg, inst->dreg);
4775 s390_ldr (code, ainfo->reg, inst->dreg);
4779 else if (ainfo->regtype == RegTypeBase) {
4781 g_assert_not_reached ();
4783 if (ainfo->regtype == RegTypeGeneral) {
4784 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4785 g_assert_not_reached();
4786 switch (ainfo->size) {
4788 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4791 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4794 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4797 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4800 } else if (ainfo->regtype == RegTypeBase) {
4801 } else if (ainfo->regtype == RegTypeFP) {
4802 if (ainfo->size == 8)
4803 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4804 else if (ainfo->size == 4)
4805 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4807 g_assert_not_reached ();
4808 } else if (ainfo->regtype == RegTypeStructByVal) {
4809 if (ainfo->reg != STK_BASE) {
4810 switch (ainfo->size) {
4812 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4815 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4818 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4821 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4825 } else if (ainfo->regtype == RegTypeStructByAddr) {
4826 if (ainfo->reg != STK_BASE) {
4827 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4830 g_assert_not_reached ();
4838 /*========================= End of Function ========================*/
4840 /*------------------------------------------------------------------*/
4842 /* Name - mono_arch_emit_prolog */
4844 /* Function - Create the instruction sequence for a function */
4847 /*------------------------------------------------------------------*/
4850 mono_arch_emit_prolog (MonoCompile *cfg)
4852 MonoMethod *method = cfg->method;
4854 MonoMethodSignature *sig;
4856 int alloc_size, pos, max_offset, i;
4862 cfg->code_size = 512;
4864 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4866 cfg->code_size += 256;
4869 if (method->save_lmf)
4870 cfg->code_size += 200;
4872 cfg->native_code = code = g_malloc (cfg->code_size);
4874 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4876 if (cfg->arch.bkchain_reg != -1)
4877 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4879 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4880 cfg->used_int_regs |= 1 << 11;
4883 alloc_size = cfg->stack_offset;
4885 cfg->stack_usage = alloc_size;
4886 s390_lgr (code, s390_r11, STK_BASE);
4887 if (s390_is_imm16 (alloc_size)) {
4888 s390_aghi (code, STK_BASE, -alloc_size);
4890 int stackSize = alloc_size;
4891 while (stackSize > 32767) {
4892 s390_aghi (code, STK_BASE, -32767);
4895 s390_aghi (code, STK_BASE, -stackSize);
4897 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4899 if (cfg->frame_reg != STK_BASE)
4900 s390_lgr (code, s390_r11, STK_BASE);
4902 /* compute max_offset in order to use short forward jumps
4903 * we always do it on s390 because the immediate displacement
4904 * for jumps is too small
4907 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4909 bb->max_offset = max_offset;
4911 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4914 MONO_BB_FOR_EACH_INS (bb, ins)
4915 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4918 /* load arguments allocated to register from the stack */
4919 sig = mono_method_signature (method);
4922 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4924 if (cinfo->struct_ret) {
4925 ArgInfo *ainfo = &cinfo->ret;
4926 inst = cfg->vret_addr;
4927 inst->backend.size = ainfo->vtsize;
4928 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4931 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4932 ArgInfo *ainfo = cinfo->args + i;
4933 inst = cfg->args [pos];
4935 if (inst->opcode == OP_VTARG_ADDR)
4936 inst = inst->inst_left;
4938 if (inst->opcode == OP_REGVAR) {
4939 if (ainfo->regtype == RegTypeGeneral)
4940 s390_lgr (code, inst->dreg, ainfo->reg);
4941 else if (ainfo->regtype == RegTypeFP) {
4942 if (inst->dreg != ainfo->reg) {
4943 if (ainfo->size == 4) {
4944 s390_ledbr (code, inst->dreg, ainfo->reg);
4946 s390_ldr (code, inst->dreg, ainfo->reg);
4950 else if (ainfo->regtype == RegTypeBase) {
4951 s390_lgr (code, s390_r13, STK_BASE);
4952 s390_aghi (code, s390_r13, alloc_size);
4953 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4955 g_assert_not_reached ();
4957 if (cfg->verbose_level > 2)
4958 g_print ("Argument %d assigned to register %s\n",
4959 pos, mono_arch_regname (inst->dreg));
4961 if (ainfo->regtype == RegTypeGeneral) {
4962 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4963 g_assert_not_reached();
4964 switch (ainfo->size) {
4966 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4969 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4972 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4975 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4978 } else if (ainfo->regtype == RegTypeBase) {
4979 } else if (ainfo->regtype == RegTypeFP) {
4980 if (ainfo->size == 8)
4981 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4982 else if (ainfo->size == 4)
4983 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4985 g_assert_not_reached ();
4986 } else if (ainfo->regtype == RegTypeStructByVal) {
4987 int doffset = inst->inst_offset;
4989 if (ainfo->reg != STK_BASE)
4993 s390_lgr (code, s390_r13, STK_BASE);
4994 s390_aghi (code, s390_r13, alloc_size);
4996 switch (ainfo->size) {
4998 if (ainfo->reg == STK_BASE)
4999 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5000 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5003 if (ainfo->reg == STK_BASE)
5004 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5005 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5008 if (ainfo->reg == STK_BASE)
5009 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5010 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5013 if (ainfo->reg == STK_BASE)
5014 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5015 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5018 } else if (ainfo->regtype == RegTypeStructByAddr) {
5019 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5020 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5022 g_assert_not_reached ();
5027 if (method->save_lmf) {
5028 /*---------------------------------------------------------------*/
5029 /* we build the MonoLMF structure on the stack - see mini-s390.h */
5030 /*---------------------------------------------------------------*/
5031 lmfOffset = alloc_size - sizeof(MonoLMF);
5033 s390_lgr (code, s390_r13, cfg->frame_reg);
5034 s390_aghi (code, s390_r13, lmfOffset);
5036 /*---------------------------------------------------------------*/
5037 /* Preserve the parameter registers while we fix up the lmf */
5038 /*---------------------------------------------------------------*/
5039 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5040 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5042 /*---------------------------------------------------------------*/
5043 /* On return from this call r2 have the address of the &lmf */
5044 /*---------------------------------------------------------------*/
5045 s390_basr(code, s390_r14, 0);
5047 mono_add_patch_info (cfg, code - cfg->native_code,
5048 MONO_PATCH_INFO_INTERNAL_METHOD,
5049 (gpointer)"mono_get_lmf_addr");
5050 s390_llong(code, 0);
5051 s390_lg (code, s390_r1, 0, s390_r14, 4);
5052 s390_basr (code, s390_r14, s390_r1);
5054 /*---------------------------------------------------------------*/
5055 /* Set lmf.lmf_addr = jit_tls->lmf */
5056 /*---------------------------------------------------------------*/
5057 s390_stg (code, s390_r2, 0, s390_r13,
5058 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5060 /*---------------------------------------------------------------*/
5061 /* Get current lmf */
5062 /*---------------------------------------------------------------*/
5063 s390_lg (code, s390_r0, 0, s390_r2, 0);
5065 /*---------------------------------------------------------------*/
5066 /* Set our lmf as the current lmf */
5067 /*---------------------------------------------------------------*/
5068 s390_stg (code, s390_r13, 0, s390_r2, 0);
5070 /*---------------------------------------------------------------*/
5071 /* Have our lmf.previous_lmf point to the last lmf */
5072 /*---------------------------------------------------------------*/
5073 s390_stg (code, s390_r0, 0, s390_r13,
5074 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5076 /*---------------------------------------------------------------*/
5077 /* save method info */
5078 /*---------------------------------------------------------------*/
5079 s390_basr (code, s390_r1, 0);
5081 s390_llong (code, method);
5082 s390_lg (code, s390_r1, 0, s390_r1, 4);
5083 s390_stg (code, s390_r1, 0, s390_r13,
5084 G_STRUCT_OFFSET(MonoLMF, method));
5086 /*---------------------------------------------------------------*/
5087 /* save the current IP */
5088 /*---------------------------------------------------------------*/
5089 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5090 s390_basr (code, s390_r1, 0);
5091 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5093 /*---------------------------------------------------------------*/
5094 /* Save general and floating point registers */
5095 /*---------------------------------------------------------------*/
5096 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5097 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5098 for (i = 0; i < 16; i++) {
5099 s390_std (code, i, 0, s390_r13,
5100 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5103 /*---------------------------------------------------------------*/
5104 /* Restore the parameter registers now that we've set up the lmf */
5105 /*---------------------------------------------------------------*/
5106 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5107 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5111 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5113 cfg->code_len = code - cfg->native_code;
5114 g_assert (cfg->code_len < cfg->code_size);
5119 /*========================= End of Function ========================*/
5121 /*------------------------------------------------------------------*/
5123 /* Name - mono_arch_emit_epilog */
5125 /* Function - Emit the instructions for a function epilog. */
5127 /*------------------------------------------------------------------*/
5130 mono_arch_emit_epilog (MonoCompile *cfg)
5132 MonoMethod *method = cfg->method;
5135 int max_epilog_size = 96;
5137 if (cfg->method->save_lmf)
5138 max_epilog_size += 128;
5140 if (mono_jit_trace_calls != NULL)
5141 max_epilog_size += 128;
5143 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5144 max_epilog_size += 128;
5146 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5147 cfg->code_size *= 2;
5148 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5149 mono_jit_stats.code_reallocs++;
5152 code = cfg->native_code + cfg->code_len;
5154 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5155 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5159 if (method->save_lmf)
5160 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5162 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
5163 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5165 code = backUpStackPtr(cfg, code);
5167 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5168 s390_br (code, s390_r14);
5170 cfg->code_len = code - cfg->native_code;
5172 g_assert (cfg->code_len < cfg->code_size);
5176 /*========================= End of Function ========================*/
5178 /*------------------------------------------------------------------*/
5180 /* Name - mono_arch_emit_exceptions */
5182 /* Function - Emit the blocks to handle exception conditions. */
5184 /*------------------------------------------------------------------*/
5187 mono_arch_emit_exceptions (MonoCompile *cfg)
5189 MonoJumpInfo *patch_info;
5195 MonoClass *exc_classes [MAX_EXC];
5196 guint8 *exc_throw_start [MAX_EXC];
5198 for (patch_info = cfg->patch_info;
5200 patch_info = patch_info->next) {
5201 if (patch_info->type == MONO_PATCH_INFO_EXC)
5205 code_size = exc_count * 48;
5207 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5208 cfg->code_size *= 2;
5209 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5210 mono_jit_stats.code_reallocs++;
5213 code = cfg->native_code + cfg->code_len;
5215 /*---------------------------------------------------------------------*/
5216 /* Add code to raise exceptions */
5217 /*---------------------------------------------------------------------*/
5218 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5219 switch (patch_info->type) {
5220 case MONO_PATCH_INFO_EXC: {
5221 guint8 *ip = patch_info->ip.i + cfg->native_code;
5222 MonoClass *exc_class;
5225 /*-----------------------------------------------------*/
5226 /* Patch the branch in epilog to come here */
5227 /*-----------------------------------------------------*/
5228 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5230 exc_class = mono_class_from_name (mono_defaults.corlib,
5232 patch_info->data.name);
5233 g_assert (exc_class);
5234 throw_ip = patch_info->ip.i;
5236 for (iExc = 0; iExc < nThrows; ++iExc)
5237 if (exc_classes [iExc] == exc_class)
5240 if (iExc < nThrows) {
5241 s390_jcl (code, S390_CC_UN,
5242 (guint64) exc_throw_start [iExc]);
5243 patch_info->type = MONO_PATCH_INFO_NONE;
5246 if (nThrows < MAX_EXC) {
5247 exc_classes [nThrows] = exc_class;
5248 exc_throw_start [nThrows] = code;
5251 /*---------------------------------------------*/
5252 /* Patch the parameter passed to the handler */
5253 /*---------------------------------------------*/
5254 s390_basr (code, s390_r13, 0);
5256 // s390_llong(code, patch_info->data.target);
5257 s390_llong(code, exc_class->type_token);
5258 /*---------------------------------------------*/
5259 /* Load return address & parameter register */
5260 /*---------------------------------------------*/
5261 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5262 cfg->native_code + 8), code));
5263 s390_lg (code, s390_r2, 0, s390_r13, 4);
5264 /*---------------------------------------------*/
5265 /* Reuse the current patch to set the jump */
5266 /*---------------------------------------------*/
5267 s390_basr (code, s390_r13, 0);
5269 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5270 patch_info->data.name = "mono_arch_throw_corlib_exception";
5271 patch_info->ip.i = code - cfg->native_code;
5272 s390_llong(code, 0);
5273 s390_lg (code, s390_r1, 0, s390_r13, 4);
5274 s390_br (code, s390_r1);
5284 cfg->code_len = code - cfg->native_code;
5286 g_assert (cfg->code_len < cfg->code_size);
5290 /*========================= End of Function ========================*/
5292 /*------------------------------------------------------------------*/
5294 /* Name - mono_arch_setup_jit_tls_data */
5296 /* Function - Setup the JIT's Thread Level Specific Data. */
5298 /*------------------------------------------------------------------*/
5301 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5303 if (!tls_offset_inited) {
5304 tls_offset_inited = TRUE;
5308 __asm__ ("\tear\t%r1,0\n"
5315 : "=r" (appdomain_tls_offset),
5316 "=r" (thread_tls_offset),
5317 "=r" (lmf_tls_offset)
5318 : "r" (&tls_appdomain),
5319 "r" (&tls_current_object),
5320 "r" (&mono_lmf_addr)
5326 if (!lmf_addr_key_inited) {
5327 lmf_addr_key_inited = TRUE;
5328 pthread_key_create (&lmf_addr_key, NULL);
5330 pthread_setspecific (lmf_addr_key, &tls->lmf);
5334 /*========================= End of Function ========================*/
5336 /*------------------------------------------------------------------*/
5338 /* Name - mono_arch_free_jit_tls_data */
5340 /* Function - Free tls data. */
5342 /*------------------------------------------------------------------*/
5345 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5349 /*========================= End of Function ========================*/
5351 /*------------------------------------------------------------------*/
5353 /* Name - mono_arch_emit_inst_for_method */
5355 /*------------------------------------------------------------------*/
5358 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5363 /*========================= End of Function ========================*/
5365 /*------------------------------------------------------------------*/
5367 /* Name - mono_arch_decompose_opts */
5369 /* Function - Decompose opcode into a System z opcode. */
5371 /*------------------------------------------------------------------*/
5374 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5377 * Have to rename these to avoid being decomposed normally, since the normal
5378 * decomposition does not work on S390.
5380 switch (ins->opcode) {
5382 ins->opcode = OP_S390_ISUB_OVF;
5384 case OP_ISUB_OVF_UN:
5385 ins->opcode = OP_S390_ISUB_OVF_UN;
5388 ins->opcode = OP_S390_IADD_OVF;
5390 case OP_IADD_OVF_UN:
5391 ins->opcode = OP_S390_IADD_OVF_UN;
5394 ins->opcode = OP_S390_LADD_OVF;
5396 case OP_LADD_OVF_UN:
5397 ins->opcode = OP_S390_LADD_OVF_UN;
5400 ins->opcode = OP_S390_LSUB_OVF;
5402 case OP_LSUB_OVF_UN:
5403 ins->opcode = OP_S390_LSUB_OVF_UN;
5410 /*========================= End of Function ========================*/
5412 /*------------------------------------------------------------------*/
5414 /* Name - mono_arch_print_tree */
5416 /* Function - Print platform-specific opcode details. */
5418 /* Returns - 1 - opcode details have been printed */
5419 /* 0 - opcode details have not been printed */
5421 /*------------------------------------------------------------------*/
5424 mono_arch_print_tree (MonoInst *tree, int arity)
5428 switch (tree->opcode) {
5429 case OP_S390_LOADARG:
5430 case OP_S390_ARGREG:
5431 case OP_S390_ARGPTR:
5432 printf ("[0x%lx(%s)]", tree->inst_offset,
5433 mono_arch_regname (tree->inst_basereg));
5436 case OP_S390_STKARG:
5437 printf ("[0x%lx(previous_frame)]",
5442 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5443 tree->inst_offset, tree->backend.size,
5444 mono_arch_regname(tree->dreg),
5446 mono_arch_regname(tree->sreg1));
5449 case OP_S390_SETF4RET:
5450 printf ("[f%s,f%s]",
5451 mono_arch_regname (tree->dreg),
5452 mono_arch_regname (tree->sreg1));
5456 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5458 mono_arch_regname (tree->sreg1));
5461 case OP_S390_BKCHAIN:
5462 printf ("[previous_frame(%s)]",
5463 mono_arch_regname (tree->sreg1));
5471 /*========================= End of Function ========================*/
5473 /*------------------------------------------------------------------*/
5475 /* Name - mono_arch_regalloc_cost */
5477 /* Function - Determine the cost, in the number of memory */
5478 /* references, of the action of allocating the var- */
5479 /* iable VMV into a register during global register */
5482 /* Returns - Cost */
5484 /*------------------------------------------------------------------*/
5487 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5493 /*========================= End of Function ========================*/
5495 /*------------------------------------------------------------------*/
5497 /* Name - mono_arch_get_domain_intrinsic */
5503 /*------------------------------------------------------------------*/
5506 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5510 if (appdomain_tls_offset == -1)
5513 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5514 ins->inst_offset = appdomain_tls_offset;
5518 /*========================= End of Function ========================*/
5520 /*------------------------------------------------------------------*/
5522 /* Name - mono_arch_flush_register_windows */
5528 /*------------------------------------------------------------------*/
5531 mono_arch_flush_register_windows (void)
5535 /*========================= End of Function ========================*/
5537 /*------------------------------------------------------------------*/
5539 /* Name - mono_arch_get_lmf_addr */
5545 /*------------------------------------------------------------------*/
5548 mono_arch_get_lmf_addr (void)
5550 return pthread_getspecific (lmf_addr_key);
5553 /*========================= End of Function ========================*/
5555 /*------------------------------------------------------------------*/
5557 /* Name - mono_arch_is_inst_imm */
5559 /* Function - Determine if operand qualifies as an immediate */
5560 /* value. For s390 this is a value -32768-32768 */
5562 /* Returns - True|False - is [not] immediate value. */
5564 /*------------------------------------------------------------------*/
5567 mono_arch_is_inst_imm (gint64 imm)
5569 return s390_is_imm16 (imm);
5572 /*========================= End of Function ========================*/
5574 /*------------------------------------------------------------------*/
5576 /* Name - mono_arch_get_patch_offset */
5578 /* Function - Dummy entry point until s390x supports aot. */
5580 /* Returns - Offset for patch. */
5582 /*------------------------------------------------------------------*/
5585 mono_arch_get_patch_offset (guint8 *code)
5590 /*========================= End of Function ========================*/
5592 /*------------------------------------------------------------------*/
5594 /* Name - mono_arch_context_get_int_reg. */
5598 /* Returns - Offset for patch. */
5600 /*------------------------------------------------------------------*/
5603 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5605 /* FIXME: implement */
5606 g_assert_not_reached ();
5610 /*========================= End of Function ========================*/
5612 /*------------------------------------------------------------------*/
5614 /* Name - mono_arch_get_this_arg_from_call. */
5618 /*------------------------------------------------------------------*/
5621 mono_arch_get_this_arg_from_call (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, mgreg_t *regs, guint8 *code)
5623 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5625 /* FIXME: handle returning a struct */
5626 if (MONO_TYPE_ISSTRUCT (sig->ret))
5627 return (gpointer) lmf->gregs [s390_r3];
5628 return (gpointer) lmf->gregs [s390_r2];
5631 /*========================= End of Function ========================*/
5633 /*------------------------------------------------------------------*/
5635 /* Name - get_delegate_invoke_impl. */
5639 /*------------------------------------------------------------------*/
5642 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5644 guint8 *code, *start;
5649 start = code = mono_global_codeman_reserve (size);
5651 /* Replace the this argument with the target */
5652 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5653 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5654 s390_br (code, s390_r1);
5655 g_assert ((code - start) <= size);
5657 mono_arch_flush_icache (start, size);
5661 size = 32 + param_count * 8;
5662 start = code = mono_global_codeman_reserve (size);
5664 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5665 /* slide down the arguments */
5666 for (i = 0; i < param_count; ++i) {
5667 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5669 s390_br (code, s390_r1);
5671 g_assert ((code - start) <= size);
5673 mono_arch_flush_icache (start, size);
5677 *code_len = code - start;
5682 /*========================= End of Function ========================*/
5684 /*------------------------------------------------------------------*/
5686 /* Name - mono_arch_get_delegate_invoke_impls. */
5690 /*------------------------------------------------------------------*/
5693 mono_arch_get_delegate_invoke_impls (void)
5700 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5701 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
5703 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5704 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5705 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
5711 /*========================= End of Function ========================*/
5713 /*------------------------------------------------------------------*/
5715 /* Name - mono_arch_get_delegate_invoke_impl. */
5719 /*------------------------------------------------------------------*/
5722 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5724 guint8 *code, *start;
5726 /* FIXME: Support more cases */
5727 if (MONO_TYPE_ISSTRUCT (sig->ret))
5731 static guint8* cached = NULL;
5737 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5739 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5741 mono_memory_barrier ();
5745 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5748 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5750 for (i = 0; i < sig->param_count; ++i)
5751 if (!mono_is_regsize_var (sig->params [i]))
5755 code = cache [sig->param_count];
5759 if (mono_aot_only) {
5760 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5761 start = mono_aot_get_trampoline (name);
5764 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5767 mono_memory_barrier ();
5769 cache [sig->param_count] = start;
5774 /*========================= End of Function ========================*/
5776 /*------------------------------------------------------------------*/
5778 /* Name - mono_arch_build_imt_thunk. */
5782 /*------------------------------------------------------------------*/
5785 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5786 MonoIMTCheckItem **imt_entries, int count,
5787 gpointer fail_tramp)
5791 guchar *code, *start;
5793 for (i = 0; i < count; ++i) {
5794 MonoIMTCheckItem *item = imt_entries [i];
5795 if (item->is_equals) {
5796 if (item->check_target_idx) {
5797 if (!item->compare_done)
5798 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5799 if (item->has_target_code)
5800 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5802 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5806 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5808 if (!item->has_target_code)
5809 item->chunk_size += LOAD_SIZE;
5811 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5812 #if ENABLE_WRONG_METHOD_CHECK
5813 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5818 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5819 imt_entries [item->check_target_idx]->compare_done = TRUE;
5821 size += item->chunk_size;
5825 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5827 code = mono_domain_code_reserve (domain, size);
5831 for (i = 0; i < count; ++i) {
5832 MonoIMTCheckItem *item = imt_entries [i];
5833 item->code_target = (guint8 *) code;
5834 if (item->is_equals) {
5835 if (item->check_target_idx) {
5836 if (!item->compare_done) {
5837 s390_basr (code, s390_r13, s390_r0);
5839 s390_llong(code, item->key);
5840 s390_lg (code, s390_r0, 0, s390_r13, 4);
5841 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5843 item->jmp_code = (guint8*) code;
5844 s390_jcl (code, S390_CC_NE, 0);
5846 s390_basr (code, s390_r13, s390_r0);
5848 if (item->has_target_code) {
5849 s390_llong(code, item->value.target_code);
5850 s390_lg (code, s390_r1, 0, s390_r13, 4);
5852 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5853 s390_lg (code, s390_r1, 0, s390_r13, 4);
5854 s390_lg (code, s390_r1, 0, s390_r1, 0);
5856 s390_br (code, s390_r1);
5861 s390_basr (code, s390_r13, s390_r0);
5863 s390_llong(code, item->key);
5864 s390_lg (code, s390_r0, 0, s390_r13, 4);
5865 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5866 item->jmp_code = (guint8*) code;
5867 s390_jcl (code, S390_CC_NE, 0);
5868 s390_basr (code, s390_r13, s390_r0);
5870 if (item->has_target_code) {
5871 s390_llong(code, item->value.target_code);
5872 s390_lg (code, s390_r1, 0, s390_r13, 4);
5875 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5876 s390_lg (code, s390_r1, 0, s390_r13, 4);
5877 s390_lg (code, s390_r1, 0, s390_r1, 0);
5879 s390_br (code, s390_r1);
5880 target = S390_RELATIVE(code, item->jmp_code);
5881 s390_patch_rel(item->jmp_code+2, target);
5882 s390_basr (code, s390_r13, s390_r0);
5884 s390_llong(code, fail_tramp);
5885 s390_lg (code, s390_r1, 0, s390_r13, 4);
5886 s390_br (code, s390_r1);
5887 item->jmp_code = NULL;
5889 /* enable the commented code to assert on wrong method */
5890 #if ENABLE_WRONG_METHOD_CHECK
5891 g_assert_not_reached ();
5893 s390_basr (code, s390_r13, s390_r0);
5895 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5896 s390_lg (code, s390_r1, 0, s390_r13, 4);
5897 s390_lg (code, s390_r1, 0, s390_r1, 0);
5898 s390_br (code, s390_r1);
5899 #if ENABLE_WRONG_METHOD_CHECK
5900 g_assert_not_reached ();
5905 s390_basr (code, s390_r13, s390_r0);
5907 s390_llong(code, item->key);
5908 s390_lg (code, s390_r0, 0, s390_r13, 4);
5909 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5910 item->jmp_code = (guint8 *) code;
5911 s390_jcl (code, S390_CC_GE, 0);
5914 /* patch the branches to get to the target items */
5915 for (i = 0; i < count; ++i) {
5916 MonoIMTCheckItem *item = imt_entries [i];
5917 if (item->jmp_code) {
5918 if (item->check_target_idx) {
5920 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5922 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5927 mono_arch_flush_icache ((guint8*)start, (code - start));
5930 mono_stats.imt_thunks_size += (code - start);
5932 g_assert (code - start <= size);
5937 /*========================= End of Function ========================*/
5939 /*------------------------------------------------------------------*/
5941 /* Name - mono_arch_find_imt_method. */
5943 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5944 /* found in the save area. */
5946 /*------------------------------------------------------------------*/
5949 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5951 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5953 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
5956 /*========================= End of Function ========================*/
5958 /*------------------------------------------------------------------*/
5960 /* Name - mono_arch_find_this_argument. */
5964 /*------------------------------------------------------------------*/
5967 mono_arch_find_this_argument (mgreg_t *regs, MonoMethod *method,
5968 MonoGenericSharingContext *gsctx)
5970 return mono_arch_get_this_arg_from_call (gsctx, mono_method_signature (method), regs, NULL);
5973 /*========================= End of Function ========================*/