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 /*------------------------------------------------------------------*/
1350 // static void inline
1352 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1354 if (*gr > S390_LAST_ARG_REG) {
1355 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1356 ainfo->offset = sz->stack_size;
1357 ainfo->reg = STK_BASE;
1358 ainfo->regtype = RegTypeBase;
1359 sz->stack_size += sizeof(long);
1360 sz->local_size += sizeof(long);
1361 sz->offStruct += sizeof(long);
1362 sz->code_size += 12;
1370 /*========================= End of Function ========================*/
1372 /*------------------------------------------------------------------*/
1374 /* Name - add_stackParm */
1376 /* Function - Determine code and stack size incremements for a */
1379 /*------------------------------------------------------------------*/
1382 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1384 if (*gr > S390_LAST_ARG_REG) {
1385 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1386 ainfo->reg = STK_BASE;
1387 ainfo->offset = sz->stack_size;
1388 ainfo->regtype = RegTypeStructByAddrOnStack;
1389 sz->stack_size += sizeof (gpointer);
1390 sz->parm_size += sizeof(gpointer);
1391 sz->offStruct += sizeof(gpointer);
1394 ainfo->offset = sz->stack_size;
1395 ainfo->regtype = RegTypeStructByAddr;
1398 ainfo->offparm = sz->offset;
1399 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1401 ainfo->vtsize = size;
1402 sz->parm_size += size;
1405 /*========================= End of Function ========================*/
1407 /*------------------------------------------------------------------*/
1409 /* Name - add_float */
1411 /* Function - Determine code and stack size incremements for a */
1412 /* float parameter. */
1414 /*------------------------------------------------------------------*/
1417 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1419 if ((*fr) <= S390_LAST_FPARG_REG) {
1420 ainfo->regtype = RegTypeFP;
1426 ainfo->offset = sz->stack_size;
1427 ainfo->reg = STK_BASE;
1428 ainfo->regtype = RegTypeBase;
1430 sz->stack_size += sizeof(double);
1431 sz->local_size += sizeof(double);
1432 sz->offStruct += sizeof(double);
1436 /*========================= End of Function ========================*/
1438 /*------------------------------------------------------------------*/
1440 /* Name - get_call_info */
1442 /* Function - Determine the amount of space required for code */
1443 /* and stack. In addition determine starting points */
1444 /* for stack-based parameters, and area for struct- */
1445 /* ures being returned on the stack. */
1447 /*------------------------------------------------------------------*/
1450 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1452 guint i, fr, gr, size;
1453 int nParm = sig->hasthis + sig->param_count;
1455 guint32 simpletype, align;
1458 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1461 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1463 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1468 cinfo->struct_ret = 0;
1472 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1473 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1478 /*----------------------------------------------------------*/
1479 /* We determine the size of the return code/stack in case we*/
1480 /* need to reserve a register to be used to address a stack */
1481 /* area that the callee will use. */
1482 /*----------------------------------------------------------*/
1484 ret_type = mono_type_get_underlying_type (sig->ret);
1485 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1486 simpletype = ret_type->type;
1488 switch (simpletype) {
1489 case MONO_TYPE_BOOLEAN:
1494 case MONO_TYPE_CHAR:
1499 case MONO_TYPE_CLASS:
1500 case MONO_TYPE_OBJECT:
1501 case MONO_TYPE_SZARRAY:
1502 case MONO_TYPE_ARRAY:
1504 case MONO_TYPE_FNPTR:
1505 case MONO_TYPE_STRING:
1506 cinfo->ret.reg = s390_r2;
1511 cinfo->ret.reg = s390_f0;
1516 cinfo->ret.reg = s390_r2;
1519 case MONO_TYPE_GENERICINST:
1520 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1521 cinfo->ret.reg = s390_r2;
1526 case MONO_TYPE_VALUETYPE: {
1527 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1528 if (klass->enumtype) {
1529 simpletype = mono_class_enum_basetype (klass)->type;
1533 size = mono_class_native_size (klass, &align);
1535 size = mono_class_value_size (klass, &align);
1537 cinfo->ret.reg = s390_r2;
1538 cinfo->struct_ret = 1;
1539 cinfo->ret.size = size;
1540 cinfo->ret.vtsize = size;
1544 case MONO_TYPE_TYPEDBYREF:
1545 size = sizeof (MonoTypedRef);
1546 cinfo->ret.reg = s390_r2;
1547 cinfo->struct_ret = 1;
1548 cinfo->ret.size = size;
1549 cinfo->ret.vtsize = size;
1552 case MONO_TYPE_VOID:
1555 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1559 cinfo->args[nParm].size = sizeof(gpointer);
1560 add_general (&gr, sz, cinfo->args+nParm);
1564 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1565 gr = S390_LAST_ARG_REG + 1;
1567 /* Emit the signature cookie just before the implicit arguments */
1568 add_general (&gr, sz, &cinfo->sigCookie);
1571 /*----------------------------------------------------------*/
1572 /* We determine the size of the parameter code and stack */
1573 /* requirements by checking the types and sizes of the */
1575 /*----------------------------------------------------------*/
1577 for (i = 0; i < sig->param_count; ++i) {
1580 /*--------------------------------------------------*/
1581 /* Handle vararg type calls. All args are put on */
1583 /*--------------------------------------------------*/
1584 if ((sig->call_convention == MONO_CALL_VARARG) &&
1585 (i == sig->sentinelpos)) {
1586 gr = S390_LAST_ARG_REG + 1;
1587 add_general (&gr, sz, &cinfo->sigCookie);
1590 if (sig->params [i]->byref) {
1591 add_general (&gr, sz, cinfo->args+nParm);
1592 cinfo->args[nParm].size = sizeof(gpointer);
1597 ptype = mono_type_get_underlying_type (sig->params [i]);
1598 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1599 simpletype = ptype->type;
1600 cinfo->args[nParm].type = simpletype;
1601 switch (simpletype) {
1602 case MONO_TYPE_BOOLEAN:
1605 cinfo->args[nParm].size = sizeof(char);
1606 add_general (&gr, sz, cinfo->args+nParm);
1611 case MONO_TYPE_CHAR:
1612 cinfo->args[nParm].size = sizeof(short);
1613 add_general (&gr, sz, cinfo->args+nParm);
1618 cinfo->args[nParm].size = sizeof(int);
1619 add_general (&gr, sz, cinfo->args+nParm);
1625 case MONO_TYPE_FNPTR:
1626 case MONO_TYPE_CLASS:
1627 case MONO_TYPE_OBJECT:
1628 case MONO_TYPE_STRING:
1629 case MONO_TYPE_SZARRAY:
1630 case MONO_TYPE_ARRAY:
1631 cinfo->args[nParm].size = sizeof(gpointer);
1632 add_general (&gr, sz, cinfo->args+nParm);
1637 cinfo->args[nParm].size = sizeof(long long);
1638 add_general (&gr, sz, cinfo->args+nParm);
1642 cinfo->args[nParm].size = sizeof(float);
1643 add_float (&fr, sz, cinfo->args+nParm);
1647 cinfo->args[nParm].size = sizeof(double);
1648 add_float (&fr, sz, cinfo->args+nParm);
1651 case MONO_TYPE_GENERICINST:
1652 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1653 cinfo->args[nParm].size = sizeof(gpointer);
1654 add_general (&gr, sz, cinfo->args+nParm);
1659 case MONO_TYPE_VALUETYPE: {
1660 MonoMarshalType *info;
1661 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1663 size = mono_class_native_size (klass, &align);
1665 size = mono_class_value_size (klass, &align);
1667 info = mono_marshal_load_type_info (klass);
1669 if ((info->native_size == sizeof(float)) &&
1670 (info->num_fields == 1) &&
1671 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1672 cinfo->args[nParm].size = sizeof(float);
1673 add_float(&fr, sz, cinfo->args+nParm);
1678 if ((info->native_size == sizeof(double)) &&
1679 (info->num_fields == 1) &&
1680 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1681 cinfo->args[nParm].size = sizeof(double);
1682 add_float(&fr, sz, cinfo->args+nParm);
1687 cinfo->args[nParm].vtsize = 0;
1688 cinfo->args[nParm].size = 0;
1691 /*----------------------------------*/
1692 /* On S/390, structures of size 1, */
1693 /* 2, 4, and 8 bytes are passed in */
1694 /* (a) register(s). */
1695 /*----------------------------------*/
1701 add_general(&gr, sz, cinfo->args+nParm);
1702 cinfo->args[nParm].size = size;
1703 cinfo->args[nParm].regtype = RegTypeStructByVal;
1705 sz->local_size += sizeof(long);
1708 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1713 case MONO_TYPE_TYPEDBYREF: {
1714 int size = sizeof (MonoTypedRef);
1716 cinfo->args[nParm].vtsize = 0;
1717 cinfo->args[nParm].size = 0;
1720 /*----------------------------------*/
1721 /* On S/390, structures of size 1, */
1722 /* 2, 4, and 8 bytes are passed in */
1723 /* (a) register(s). */
1724 /*----------------------------------*/
1730 add_general(&gr, sz, cinfo->args+nParm);
1731 cinfo->args[nParm].size = size;
1732 cinfo->args[nParm].regtype = RegTypeStructByVal;
1734 sz->local_size += sizeof(long);
1737 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1743 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1747 /*----------------------------------------------------------*/
1748 /* Handle the case where there are no implicit arguments */
1749 /*----------------------------------------------------------*/
1750 if ((sig->call_convention == MONO_CALL_VARARG) &&
1753 (sig->param_count == sig->sentinelpos)) {
1754 gr = S390_LAST_ARG_REG + 1;
1755 add_general (&gr, sz, &cinfo->sigCookie);
1758 /*----------------------------------------------------------*/
1759 /* If we are passing a structure back then if it won't be */
1760 /* in a register(s) then we make room at the end of the */
1761 /* parameters that may have been placed on the stack */
1762 /*----------------------------------------------------------*/
1763 if (cinfo->struct_ret) {
1764 cinfo->ret.offset = sz->stack_size;
1765 switch (cinfo->ret.size) {
1773 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1778 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1780 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1785 /*========================= End of Function ========================*/
1787 /*------------------------------------------------------------------*/
1789 /* Name - mono_arch_allocate_vars */
1791 /* Function - Set var information according to the calling */
1792 /* convention for S/390. The local var stuff should */
1793 /* most likely be split in another method. */
1795 /* Parameter - @m - Compile unit. */
1797 /*------------------------------------------------------------------*/
1800 mono_arch_allocate_vars (MonoCompile *cfg)
1802 MonoMethodSignature *sig;
1803 MonoMethodHeader *header;
1806 int iParm, iVar, offset, align, size, curinst;
1807 int frame_reg = STK_BASE;
1810 header = cfg->header;
1812 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1814 /*---------------------------------------------------------*/
1815 /* We use the frame register also for any method that has */
1816 /* filter clauses. This way, when the handlers are called, */
1817 /* the code will reference local variables using the frame */
1818 /* reg instead of the stack pointer: if we had to restore */
1819 /* the stack pointer, we'd corrupt the method frames that */
1820 /* are already on the stack (since filters get called */
1821 /* before stack unwinding happens) when the filter code */
1822 /* would call any method. */
1823 /*---------------------------------------------------------*/
1824 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1825 frame_reg = s390_r11;
1827 cfg->frame_reg = frame_reg;
1829 cfg->arch.bkchain_reg = -1;
1831 if (frame_reg != STK_BASE)
1832 cfg->used_int_regs |= 1 << frame_reg;
1834 sig = mono_method_signature (cfg->method);
1836 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1838 if (!cinfo->struct_ret) {
1839 switch (mono_type_get_underlying_type (sig->ret)->type) {
1840 case MONO_TYPE_VOID:
1843 cfg->ret->opcode = OP_REGVAR;
1844 cfg->ret->dreg = s390_r2;
1849 /*--------------------------------------------------------------*/
1850 /* local vars are at a positive offset from the stack pointer */
1851 /* also note that if the function uses alloca, we use s390_r11 */
1852 /* to point at the local variables. */
1853 /* add parameter area size for called functions */
1854 /*--------------------------------------------------------------*/
1855 if (cfg->param_area == 0)
1856 offset = S390_MINIMAL_STACK_SIZE;
1858 offset = cfg->param_area;
1860 cfg->sig_cookie = 0;
1862 if (cinfo->struct_ret) {
1863 inst = cfg->vret_addr;
1864 offset = S390_ALIGN(offset, sizeof(gpointer));
1865 inst->inst_offset = offset;
1866 inst->opcode = OP_REGOFFSET;
1867 inst->inst_basereg = frame_reg;
1868 offset += sizeof(gpointer);
1869 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1870 printf ("vret_addr =");
1871 mono_print_ins (cfg->vret_addr);
1876 inst = cfg->args [0];
1877 if (inst->opcode != OP_REGVAR) {
1878 inst->opcode = OP_REGOFFSET;
1879 inst->inst_basereg = frame_reg;
1880 offset = S390_ALIGN(offset, sizeof(gpointer));
1881 inst->inst_offset = offset;
1882 offset += sizeof (gpointer);
1889 eArg = sig->param_count + sArg;
1891 if (sig->call_convention == MONO_CALL_VARARG)
1892 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1894 for (iParm = sArg; iParm < eArg; ++iParm) {
1895 inst = cfg->args [curinst];
1896 if (inst->opcode != OP_REGVAR) {
1897 switch (cinfo->args[iParm].regtype) {
1898 case RegTypeStructByAddr : {
1901 size = sizeof (gpointer);
1903 inst->opcode = OP_REGOFFSET;
1904 inst->inst_basereg = frame_reg;
1905 offset = S390_ALIGN (offset, sizeof (gpointer));
1906 inst->inst_offset = offset;
1908 /* Add a level of indirection */
1909 MONO_INST_NEW (cfg, indir, 0);
1911 inst->opcode = OP_VTARG_ADDR;
1912 inst->inst_left = indir;
1915 case RegTypeStructByAddrOnStack : {
1918 size = sizeof (gpointer);
1920 /* Similar to the == STK_BASE case below */
1921 cfg->arch.bkchain_reg = s390_r12;
1922 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1924 inst->opcode = OP_REGOFFSET;
1925 inst->dreg = mono_alloc_preg (cfg);
1926 inst->inst_basereg = cfg->arch.bkchain_reg;
1927 inst->inst_offset = cinfo->args [iParm].offset;
1929 /* Add a level of indirection */
1930 MONO_INST_NEW (cfg, indir, 0);
1932 inst->opcode = OP_VTARG_ADDR;
1933 inst->inst_left = indir;
1936 case RegTypeStructByVal :
1937 size = cinfo->args[iParm].size;
1938 offset = S390_ALIGN(offset, size);
1939 inst->opcode = OP_REGOFFSET;
1940 inst->inst_basereg = frame_reg;
1941 inst->inst_offset = offset;
1944 if (cinfo->args [iParm].reg == STK_BASE) {
1946 * These arguments are in the previous frame, so we can't
1947 * compute their offset from the current frame pointer right
1948 * now, since cfg->stack_offset is not yet known, so dedicate a
1949 * register holding the previous frame pointer.
1951 cfg->arch.bkchain_reg = s390_r12;
1952 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1954 inst->opcode = OP_REGOFFSET;
1955 inst->inst_basereg = cfg->arch.bkchain_reg;
1956 size = (cinfo->args[iParm].size < 8
1957 ? 8 - cinfo->args[iParm].size
1959 inst->inst_offset = cinfo->args [iParm].offset + size;
1960 size = sizeof (long);
1962 inst->opcode = OP_REGOFFSET;
1963 inst->inst_basereg = frame_reg;
1964 size = (cinfo->args[iParm].size < 8
1967 offset = S390_ALIGN(offset, size);
1968 inst->inst_offset = offset;
1972 if ((sig->call_convention == MONO_CALL_VARARG) &&
1973 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1974 (iParm < sig->sentinelpos))
1975 cfg->sig_cookie += size;
1982 curinst = cfg->locals_start;
1983 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1984 inst = cfg->varinfo [iVar];
1985 if ((inst->flags & MONO_INST_IS_DEAD) ||
1986 (inst->opcode == OP_REGVAR))
1989 /*--------------------------------------------------*/
1990 /* inst->backend.is_pinvoke indicates native sized */
1991 /* value typs this is used by the pinvoke wrappers */
1992 /* when they call functions returning structure */
1993 /*--------------------------------------------------*/
1994 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1995 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
1996 (guint32 *) &align);
1998 size = mono_type_size (inst->inst_vtype, &align);
2000 offset = S390_ALIGN(offset, align);
2001 inst->inst_offset = offset;
2002 inst->opcode = OP_REGOFFSET;
2003 inst->inst_basereg = frame_reg;
2005 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2006 iVar, inst->inst_offset, size));
2009 /*------------------------------------------------------*/
2010 /* Allow space for the trace method stack area if needed*/
2011 /*------------------------------------------------------*/
2012 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2013 offset += S390_TRACE_STACK_SIZE;
2015 /*------------------------------------------------------*/
2016 /* Reserve space to save LMF and caller saved registers */
2017 /*------------------------------------------------------*/
2018 if (cfg->method->save_lmf)
2019 offset += sizeof (MonoLMF);
2021 /*------------------------------------------------------*/
2022 /* align the offset */
2023 /*------------------------------------------------------*/
2024 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2026 /*------------------------------------------------------*/
2027 /* Fix offsets for args whose value is in parent frame */
2028 /*------------------------------------------------------*/
2029 for (iParm = sArg; iParm < eArg; ++iParm) {
2030 inst = cfg->args [iParm];
2032 if (inst->opcode == OP_S390_STKARG) {
2033 inst->opcode = OP_REGOFFSET;
2034 inst->inst_offset += cfg->stack_offset;
2039 /*========================= End of Function ========================*/
2041 /*------------------------------------------------------------------*/
2043 /* Name - mono_arch_create_vars */
2045 /*------------------------------------------------------------------*/
2048 mono_arch_create_vars (MonoCompile *cfg)
2050 MonoMethodSignature *sig;
2053 sig = mono_method_signature (cfg->method);
2055 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2057 if (cinfo->struct_ret) {
2058 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2059 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2060 printf ("vret_addr = ");
2061 mono_print_ins (cfg->vret_addr);
2066 /*========================= End of Function ========================*/
2068 /*------------------------------------------------------------------*/
2070 /* Name - add_outarg_reg2. */
2072 /*------------------------------------------------------------------*/
2075 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2080 case RegTypeGeneral:
2081 MONO_INST_NEW (cfg, ins, OP_MOVE);
2082 ins->dreg = mono_alloc_ireg (cfg);
2083 ins->sreg1 = tree->dreg;
2084 MONO_ADD_INS (cfg->cbb, ins);
2085 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2088 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2089 ins->dreg = mono_alloc_freg (cfg);
2090 ins->sreg1 = tree->dreg;
2091 MONO_ADD_INS (cfg->cbb, ins);
2092 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2095 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2096 ins->dreg = mono_alloc_freg (cfg);
2097 ins->sreg1 = tree->dreg;
2098 MONO_ADD_INS (cfg->cbb, ins);
2099 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2102 g_assert_not_reached ();
2106 /*========================= End of Function ========================*/
2108 /*------------------------------------------------------------------*/
2110 /* Name - emit_sig_cookie. */
2112 /*------------------------------------------------------------------*/
2115 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2117 MonoMethodSignature *tmpSig;
2120 cfg->disable_aot = TRUE;
2122 /*----------------------------------------------------------*/
2123 /* mono_ArgIterator_Setup assumes the signature cookie is */
2124 /* passed first and all the arguments which were before it */
2125 /* passed on the stack after the signature. So compensate */
2126 /* by passing a different signature. */
2127 /*----------------------------------------------------------*/
2128 tmpSig = mono_metadata_signature_dup (call->signature);
2129 tmpSig->param_count -= call->signature->sentinelpos;
2130 tmpSig->sentinelpos = 0;
2131 if (tmpSig->param_count > 0)
2132 memcpy (tmpSig->params,
2133 call->signature->params + call->signature->sentinelpos,
2134 tmpSig->param_count * sizeof(MonoType *));
2136 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2137 sig_arg->dreg = mono_alloc_ireg (cfg);
2138 sig_arg->inst_p0 = tmpSig;
2139 MONO_ADD_INS (cfg->cbb, sig_arg);
2141 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2142 cinfo->sigCookie.offset, sig_arg->dreg);
2145 /*========================= End of Function ========================*/
2147 /*------------------------------------------------------------------*/
2149 /* Name - mono_arch_emit_call */
2151 /*------------------------------------------------------------------*/
2154 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2157 MonoMethodSignature *sig;
2159 int i, n, lParamArea;
2161 ArgInfo *ainfo = NULL;
2163 MonoMethodHeader *header;
2166 sig = call->signature;
2167 n = sig->param_count + sig->hasthis;
2168 DEBUG (g_print ("Call requires: %d parameters\n",n));
2170 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2172 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2173 cinfo->sz.parm_size + cinfo->sz.offset;
2174 call->stack_usage = MAX(stackSize, call->stack_usage);
2175 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2176 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2177 cfg->flags |= MONO_CFG_HAS_CALLS;
2179 if (cinfo->struct_ret) {
2180 MONO_INST_NEW (cfg, ins, OP_MOVE);
2181 ins->sreg1 = call->vret_var->dreg;
2182 ins->dreg = mono_alloc_preg (cfg);
2183 MONO_ADD_INS (cfg->cbb, ins);
2184 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2187 header = mono_method_get_header (cfg->method);
2188 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2193 for (i = 0; i < n; ++i) {
2196 ainfo = cinfo->args + i;
2197 if (i >= sig->hasthis)
2198 t = sig->params [i - sig->hasthis];
2200 t = &mono_defaults.int_class->byval_arg;
2201 t = mono_type_get_underlying_type (t);
2203 in = call->args [i];
2205 if ((sig->call_convention == MONO_CALL_VARARG) &&
2207 (i == sig->sentinelpos)) {
2208 emit_sig_cookie (cfg, call, cinfo);
2211 switch (ainfo->regtype) {
2212 case RegTypeGeneral:
2213 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2216 if (MONO_TYPE_ISSTRUCT (t)) {
2217 /* Valuetype passed in one fp register */
2218 ainfo->regtype = RegTypeStructByValInFP;
2221 if (ainfo->size == 4)
2222 ainfo->regtype = RegTypeFPR4;
2223 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2226 case RegTypeStructByVal:
2227 case RegTypeStructByAddr:
2228 case RegTypeStructByAddrOnStack: {
2232 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2233 size = sizeof (MonoTypedRef);
2234 align = sizeof (gpointer);
2238 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2241 * Other backends use mono_type_stack_size (), but that
2242 * aligns the size to 8, which is larger than the size of
2243 * the source, leading to reads of invalid memory if the
2244 * source is at the end of address space.
2246 size = mono_class_value_size (in->klass, &align);
2249 g_assert (in->klass);
2251 ainfo->offparm += cinfo->sz.offStruct;
2253 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2254 ins->sreg1 = in->dreg;
2255 ins->klass = in->klass;
2256 ins->backend.size = ainfo->size;
2257 ins->inst_p0 = call;
2258 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2259 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2261 MONO_ADD_INS (cfg->cbb, ins);
2263 if (ainfo->regtype == RegTypeStructByAddr) {
2265 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2266 * use the normal OUTARG opcodes to pass the address of the location to
2269 int treg = mono_alloc_preg (cfg);
2270 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2271 frmReg, ainfo->offparm);
2272 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2273 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2274 /* The address of the valuetype is passed on the stack */
2275 int treg = mono_alloc_preg (cfg);
2276 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2277 frmReg, ainfo->offparm);
2278 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2279 ainfo->reg, ainfo->offset, treg);
2284 if (!t->byref && t->type == MONO_TYPE_R4) {
2285 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2286 STK_BASE, ainfo->offset + 4,
2288 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2289 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2290 STK_BASE, ainfo->offset,
2293 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2294 ins->inst_destbasereg = STK_BASE;
2295 ins->inst_offset = ainfo->offset;
2296 ins->sreg1 = in->dreg;
2299 /* This is needed by MonoTypedRef->value to point to the correct data */
2300 if ((sig->call_convention == MONO_CALL_VARARG) &&
2301 (i >= sig->sentinelpos)) {
2302 switch (ainfo->size) {
2304 ins->opcode = OP_STOREI1_MEMBASE_REG;
2307 ins->opcode = OP_STOREI2_MEMBASE_REG;
2310 ins->opcode = OP_STOREI4_MEMBASE_REG;
2318 MONO_ADD_INS (cfg->cbb, ins);
2322 g_assert_not_reached ();
2328 * Handle the case where there are no implicit arguments
2330 if ((sig->call_convention == MONO_CALL_VARARG) &&
2332 (i == sig->sentinelpos)) {
2333 emit_sig_cookie (cfg, call, cinfo);
2337 /*========================= End of Function ========================*/
2339 /*------------------------------------------------------------------*/
2341 /* Name - mono_arch_emit_outarg_vt */
2343 /*------------------------------------------------------------------*/
2346 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2348 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2349 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2350 int size = ins->backend.size;
2352 if (ainfo->regtype == RegTypeStructByVal) {
2354 arg->ins.sreg1 = ainfo->reg;
2355 arg->ins.opcode = OP_OUTARG_VT;
2356 arg->size = ainfo->size;
2357 arg->offset = ainfo->offset;
2358 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2360 if (ainfo->reg != STK_BASE) {
2361 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2363 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2366 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2367 int dreg = mono_alloc_freg (cfg);
2369 if (ainfo->size == 4) {
2370 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2371 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2373 g_assert (ainfo->size == 8);
2375 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2378 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2380 MonoMethodHeader *header;
2383 header = mono_method_get_header (cfg->method);
2384 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2389 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2390 src->dreg, 0, size);
2394 /*========================= End of Function ========================*/
2396 /*------------------------------------------------------------------*/
2398 /* Name - mono_arch_emit_setret */
2400 /*------------------------------------------------------------------*/
2403 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2405 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2408 if (ret->type == MONO_TYPE_R4) {
2409 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2411 } else if (ret->type == MONO_TYPE_R8) {
2412 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2417 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2420 /*========================= End of Function ========================*/
2422 /*------------------------------------------------------------------*/
2424 /* Name - mono_arch_instrument_mem_needs */
2426 /* Function - Allow tracing to work with this interface (with */
2427 /* an optional argument). */
2429 /*------------------------------------------------------------------*/
2432 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2434 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2436 /* split prolog-epilog requirements? */
2437 *code = 50; /* max bytes needed: check this number */
2440 /*========================= End of Function ========================*/
2442 /*------------------------------------------------------------------*/
2444 /* Name - mono_arch_instrument_prolog */
2446 /* Function - Create an "instrumented" prolog. */
2448 /*------------------------------------------------------------------*/
2451 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2452 gboolean enable_arguments)
2459 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2460 if (cfg->method->save_lmf)
2461 parmOffset -= sizeof(MonoLMF);
2462 fpOffset = parmOffset + (5*sizeof(gpointer));
2463 if ((!has_ld) && (fpOffset > 4096)) {
2464 s390_lgr (code, s390_r12, STK_BASE);
2466 while (fpOffset > 4096) {
2467 s390_aghi (code, baseReg, 4096);
2475 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2477 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2478 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2479 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2480 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2482 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2483 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2484 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2485 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2487 s390_basr (code, s390_r13, 0);
2489 s390_llong(code, cfg->method);
2490 s390_llong(code, func);
2491 s390_lg (code, s390_r2, 0, s390_r13, 4);
2493 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2495 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2496 s390_lgr (code, s390_r4, STK_BASE);
2497 s390_aghi (code, s390_r4, cfg->stack_usage);
2498 s390_lg (code, s390_r1, 0, s390_r13, 12);
2499 s390_basr (code, s390_r14, s390_r1);
2501 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2502 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2503 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2504 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2506 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2507 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2508 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2509 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2511 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2516 /*========================= End of Function ========================*/
2518 /*------------------------------------------------------------------*/
2520 /* Name - mono_arch_instrument_epilog */
2522 /* Function - Create an epilog that will handle the returned */
2523 /* values used in instrumentation. */
2525 /*------------------------------------------------------------------*/
2528 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2531 int save_mode = SAVE_NONE,
2533 MonoMethod *method = cfg->method;
2534 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2536 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2537 if (method->save_lmf)
2538 saveOffset -= sizeof(MonoLMF);
2542 case MONO_TYPE_VOID:
2543 /* special case string .ctor icall */
2544 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2545 save_mode = SAVE_ONE;
2547 save_mode = SAVE_NONE;
2551 save_mode = SAVE_ONE;
2554 save_mode = SAVE_R4;
2557 save_mode = SAVE_R8;
2559 case MONO_TYPE_VALUETYPE:
2560 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2561 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2564 save_mode = SAVE_STRUCT;
2567 save_mode = SAVE_ONE;
2571 switch (save_mode) {
2573 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2574 if (enable_arguments) {
2575 s390_lgr (code, s390_r3, s390_r2);
2579 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2580 if (enable_arguments) {
2581 s390_ldebr (code, s390_f0, s390_f0);
2585 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2588 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2589 if (enable_arguments) {
2590 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2591 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2599 s390_basr (code, s390_r13, 0);
2601 s390_llong(code, cfg->method);
2602 s390_llong(code, func);
2603 s390_lg (code, s390_r2, 0, s390_r13, 4);
2604 s390_lg (code, s390_r1, 0, s390_r13, 12);
2605 s390_basr (code, s390_r14, s390_r1);
2607 switch (save_mode) {
2609 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2613 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2616 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2626 /*========================= End of Function ========================*/
2628 /*------------------------------------------------------------------*/
2630 /* Name - mono_arch_peephole_pass_1 */
2632 /* Function - Form a peephole pass at the code looking for */
2633 /* simple optimizations. */
2635 /*------------------------------------------------------------------*/
2638 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2642 /*========================= End of Function ========================*/
2644 /*------------------------------------------------------------------*/
2646 /* Name - mono_arch_peephole_pass_2 */
2648 /* Function - Form a peephole pass at the code looking for */
2649 /* simple optimizations. */
2651 /*------------------------------------------------------------------*/
2654 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2658 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2659 mono_peephole_ins (bb, ins);
2663 /*========================= End of Function ========================*/
2665 /*------------------------------------------------------------------*/
2667 /* Name - mono_arch_lowering_pass. */
2669 /*------------------------------------------------------------------*/
2672 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2674 MonoInst *ins, *next;
2676 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2677 switch (ins->opcode) {
2682 case OP_IDIV_UN_IMM:
2683 case OP_IREM_UN_IMM:
2687 case OP_LOCALLOC_IMM:
2688 mono_decompose_op_imm (cfg, bb, ins);
2691 if (!s390_is_imm16 (ins->inst_imm))
2692 /* This is created by the memcpy code which ignores is_inst_imm */
2693 mono_decompose_op_imm (cfg, bb, ins);
2700 bb->max_vreg = cfg->next_vreg;
2703 /*========================= End of Function ========================*/
2705 /*------------------------------------------------------------------*/
2707 /* Name - emit_float_to_int */
2709 /* Function - Create instructions which will convert a floating */
2710 /* point value to integer. */
2712 /*------------------------------------------------------------------*/
2715 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2717 /* sreg is a float, dreg is an integer reg. */
2719 s390_cgdbr (code, dreg, 5, sreg);
2722 s390_lghi (code, s390_r0, 0);
2723 s390_lghi (code, s390_r13, 0xff);
2724 s390_ltgr (code, dreg, dreg);
2726 s390_lghi (code, s390_r0, 0x80);
2727 s390_ngr (code, dreg, s390_r13);
2728 s390_ogr (code, dreg, s390_r0);
2733 s390_basr (code, s390_r13, 0);
2735 s390_llong (code, 0x41e0000000000000);
2736 s390_llong (code, 0x41f0000000000000);
2737 s390_ldr (code, s390_f15, sreg);
2738 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2739 s390_jl (code, 0); CODEPTR (code, o[0]);
2740 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2741 s390_cfdbr (code, dreg, 7, s390_f15);
2743 PTRSLOT (code, o[0]);
2744 s390_cfdbr (code, dreg, 5, sreg);
2747 s390_lghi (code, s390_r0, 0xff);
2748 s390_ngr (code, dreg, s390_r0);
2751 s390_lghi (code, s390_r0, -1);
2752 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2753 s390_ngr (code, dreg, s390_r0);
2760 /*========================= End of Function ========================*/
2762 /*------------------------------------------------------------------*/
2764 /* Name - gboolean_is_unsigned. */
2766 /* Function - Return TRUE if next opcode is checking for un- */
2769 /*------------------------------------------------------------------*/
2772 gboolean is_unsigned (MonoInst *next)
2775 (((next->opcode >= OP_IBNE_UN) &&
2776 (next->opcode <= OP_IBLT_UN)) ||
2777 ((next->opcode >= OP_LBNE_UN) &&
2778 (next->opcode <= OP_LBLT_UN)) ||
2779 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2780 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2781 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2782 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2783 ((next->opcode == OP_CLT_UN) ||
2784 (next->opcode == OP_CGT_UN)) ||
2785 ((next->opcode == OP_ICLT_UN) ||
2786 (next->opcode == OP_ICGT_UN) ||
2787 (next->opcode == OP_LCLT_UN) ||
2788 (next->opcode == OP_LCGT_UN))))
2794 /*========================= End of Function ========================*/
2796 /*------------------------------------------------------------------*/
2798 /* Name - mono_arch_output_basic_block */
2800 /* Function - Perform the "real" work of emitting instructions */
2801 /* that will do the work of in the basic block. */
2803 /*------------------------------------------------------------------*/
2806 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2811 guint8 *code = cfg->native_code + cfg->code_len;
2812 guint last_offset = 0;
2813 int max_len, cpos, src2;
2815 /* we don't align basic blocks of loops on s390 */
2817 if (cfg->verbose_level > 2)
2818 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2820 cpos = bb->max_offset;
2822 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2823 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2824 //g_assert (!mono_compile_aot);
2827 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2828 /* this is not thread save, but good enough */
2829 /* fixme: howto handle overflows? */
2830 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2833 MONO_BB_FOR_EACH_INS (bb, ins) {
2834 offset = code - cfg->native_code;
2836 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2838 if (offset > (cfg->code_size - max_len - 16)) {
2839 cfg->code_size *= 2;
2840 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2841 code = cfg->native_code + offset;
2844 mono_debug_record_line_number (cfg, ins, offset);
2846 switch (ins->opcode) {
2847 case OP_STOREI1_MEMBASE_IMM: {
2848 s390_lghi (code, s390_r0, ins->inst_imm);
2849 S390_LONG (code, stcy, stc, s390_r0, 0,
2850 ins->inst_destbasereg, ins->inst_offset);
2853 case OP_STOREI2_MEMBASE_IMM: {
2854 s390_lghi (code, s390_r0, ins->inst_imm);
2855 S390_LONG (code, sthy, sth, s390_r0, 0,
2856 ins->inst_destbasereg, ins->inst_offset);
2859 case OP_STOREI4_MEMBASE_IMM: {
2860 if (s390_is_imm16(ins->inst_imm)) {
2861 s390_lghi (code, s390_r0, ins->inst_imm);
2863 s390_basr (code, s390_r13, 0);
2865 s390_llong(code, ins->inst_imm);
2866 s390_lg (code, s390_r0, 0, s390_r13, 4);
2868 S390_LONG (code, sty, st, s390_r0, 0,
2869 ins->inst_destbasereg, ins->inst_offset);
2872 case OP_STORE_MEMBASE_IMM:
2873 case OP_STOREI8_MEMBASE_IMM: {
2874 if (s390_is_imm16(ins->inst_imm)) {
2875 s390_lghi (code, s390_r0, ins->inst_imm);
2877 s390_basr (code, s390_r13, 0);
2879 s390_llong(code, ins->inst_imm);
2880 s390_lg (code, s390_r0, 0, s390_r13, 4);
2882 S390_LONG (code, stg, stg, s390_r0, 0,
2883 ins->inst_destbasereg, ins->inst_offset);
2886 case OP_STOREI1_MEMBASE_REG: {
2887 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2888 ins->inst_destbasereg, ins->inst_offset);
2891 case OP_STOREI2_MEMBASE_REG: {
2892 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2893 ins->inst_destbasereg, ins->inst_offset);
2896 case OP_STOREI4_MEMBASE_REG: {
2897 S390_LONG (code, sty, st, ins->sreg1, 0,
2898 ins->inst_destbasereg, ins->inst_offset);
2901 case OP_STORE_MEMBASE_REG:
2902 case OP_STOREI8_MEMBASE_REG: {
2903 S390_LONG (code, stg, stg, ins->sreg1, 0,
2904 ins->inst_destbasereg, ins->inst_offset);
2908 g_assert_not_reached ();
2910 case OP_LOAD_MEMBASE:
2911 case OP_LOADI8_MEMBASE: {
2912 S390_LONG (code, lg, lg, ins->dreg, 0,
2913 ins->inst_basereg, ins->inst_offset);
2916 case OP_LOADI4_MEMBASE: {
2917 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2918 ins->inst_basereg, ins->inst_offset);
2921 case OP_LOADU4_MEMBASE: {
2922 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2923 ins->inst_basereg, ins->inst_offset);
2926 case OP_LOADU1_MEMBASE: {
2927 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2928 ins->inst_basereg, ins->inst_offset);
2931 case OP_LOADI1_MEMBASE: {
2932 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2933 ins->inst_basereg, ins->inst_offset);
2936 case OP_LOADU2_MEMBASE: {
2937 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2938 ins->inst_basereg, ins->inst_offset);
2941 case OP_LOADI2_MEMBASE: {
2942 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2943 ins->inst_basereg, ins->inst_offset);
2946 case OP_LCONV_TO_I1: {
2948 s390_lgbr (code, ins->dreg, ins->sreg1);
2950 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
2951 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
2955 case OP_LCONV_TO_I2: {
2957 s390_lghr (code, ins->dreg, ins->sreg1);
2959 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
2960 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
2964 case OP_LCONV_TO_U1: {
2966 s390_llghr (code, ins->dreg, ins->sreg1);
2968 if (ins->dreg != ins->sreg1)
2969 s390_lgr (code, ins->dreg, ins->sreg1);
2970 s390_lghi (code, s390_r0, 0xff);
2971 s390_ngr (code, ins->dreg, s390_r0);
2975 case OP_LCONV_TO_U2: {
2977 s390_llghr (code, ins->dreg, ins->sreg1);
2979 if (ins->dreg != ins->sreg1)
2980 s390_lgr (code, ins->dreg, ins->sreg1);
2981 s390_lghi (code, s390_r0, -1);
2982 s390_srlg (code, s390_r0, s390_r0, 0, 48);
2983 s390_ngr (code, ins->dreg, s390_r0);
2987 case OP_ICONV_TO_I1: {
2989 s390_lbr (code, ins->dreg, ins->sreg1);
2991 if (ins->dreg != ins->sreg1)
2992 s390_lr (code, ins->dreg, ins->sreg1);
2993 s390_sll (code, ins->dreg, 0, 24);
2994 s390_sra (code, ins->dreg, 0, 24);
2999 case OP_ICONV_TO_I2: {
3001 s390_lhr (code, ins->dreg, ins->sreg1);
3003 if (ins->dreg != ins->sreg1)
3004 s390_lr (code, ins->dreg, ins->sreg1);
3005 s390_sll (code, ins->dreg, 0, 16);
3006 s390_sra (code, ins->dreg, 0, 16);
3010 case OP_ICONV_TO_U1: {
3012 s390_llcr (code, ins->dreg, ins->sreg1);
3014 if (ins->dreg != ins->sreg1)
3015 s390_lr (code, ins->dreg, ins->sreg1);
3016 s390_lhi (code, s390_r0, 0xff);
3017 s390_nr (code, ins->dreg, s390_r0);
3021 case OP_ICONV_TO_U2: {
3023 s390_llhr (code, ins->dreg, ins->sreg1);
3025 if (ins->dreg != ins->sreg1)
3026 s390_lr (code, ins->dreg, ins->sreg1);
3027 s390_lhi (code, s390_r0, -1);
3028 s390_srl (code, s390_r0, 0, 16);
3029 s390_nr (code, ins->dreg, s390_r0);
3035 if (is_unsigned (ins->next))
3036 s390_clgr (code, ins->sreg1, ins->sreg2);
3038 s390_cgr (code, ins->sreg1, ins->sreg2);
3042 if (is_unsigned (ins->next))
3043 s390_clr (code, ins->sreg1, ins->sreg2);
3045 s390_cr (code, ins->sreg1, ins->sreg2);
3048 case OP_COMPARE_IMM:
3049 case OP_LCOMPARE_IMM: {
3050 if (s390_is_imm16 (ins->inst_imm)) {
3051 s390_lghi (code, s390_r0, ins->inst_imm);
3052 if (is_unsigned (ins->next))
3053 s390_clgr (code, ins->sreg1, s390_r0);
3055 s390_cgr (code, ins->sreg1, s390_r0);
3057 s390_basr (code, s390_r13, 0);
3059 s390_llong(code, ins->inst_imm);
3060 if (is_unsigned (ins->next))
3061 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3063 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3067 case OP_ICOMPARE_IMM: {
3068 if (s390_is_imm16 (ins->inst_imm)) {
3069 s390_lghi (code, s390_r0, ins->inst_imm);
3070 if (is_unsigned (ins->next))
3071 s390_clr (code, ins->sreg1, s390_r0);
3073 s390_cr (code, ins->sreg1, s390_r0);
3076 s390_basr (code, s390_r13, 0);
3078 s390_word (code, ins->inst_imm);
3079 if (is_unsigned (ins->next))
3080 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3082 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3087 s390_basr (code, s390_r13, 0);
3089 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3091 s390_llong (code, mono_break);
3092 s390_lg (code, s390_r14, 0, s390_r13, 4);
3093 s390_basr (code, s390_r14, s390_r14);
3098 s390_agr (code, ins->dreg, src2);
3103 s390_agr (code, ins->dreg, src2);
3108 s390_alcgr (code, ins->dreg, src2);
3112 if (ins->dreg != ins->sreg1) {
3113 s390_lgr (code, ins->dreg, ins->sreg1);
3115 if (s390_is_imm16 (ins->inst_imm)) {
3116 s390_aghi (code, ins->dreg, ins->inst_imm);
3118 s390_basr (code, s390_r13, 0);
3120 s390_llong(code, ins->inst_imm);
3121 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3126 if (ins->dreg != ins->sreg1) {
3127 s390_lgr (code, ins->dreg, ins->sreg1);
3129 g_assert (s390_is_imm16 (ins->inst_imm));
3130 s390_aghi (code, ins->dreg, ins->inst_imm);
3134 if (ins->dreg != ins->sreg1) {
3135 s390_lgr (code, ins->dreg, ins->sreg1);
3137 if (s390_is_imm16 (ins->inst_imm)) {
3138 s390_lghi (code, s390_r0, ins->inst_imm);
3139 s390_alcgr (code, ins->dreg, s390_r0);
3141 s390_basr (code, s390_r13, 0);
3143 s390_llong (code, ins->inst_imm);
3144 s390_lg (code, s390_r13, 0, s390_r13, 4);
3145 s390_alcgr (code, ins->dreg, s390_r13);
3150 case OP_S390_IADD_OVF: {
3152 s390_ar (code, ins->dreg, src2);
3153 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3154 s390_lgfr (code, ins->dreg, ins->dreg);
3157 case OP_IADD_OVF_UN:
3158 case OP_S390_IADD_OVF_UN: {
3160 s390_algr (code, ins->dreg, src2);
3161 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3162 s390_llgfr (code, ins->dreg, ins->dreg);
3165 case OP_ADD_OVF_CARRY: {
3167 s390_lghi (code, s390_r0, 0);
3168 s390_lgr (code, s390_r1, s390_r0);
3169 s390_alcgr (code, s390_r0, s390_r1);
3170 s390_agr (code, ins->dreg, src2);
3171 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3172 s390_agr (code, ins->dreg, s390_r0);
3173 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3176 case OP_ADD_OVF_UN_CARRY: {
3178 s390_alcgr (code, ins->dreg, src2);
3179 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3184 s390_sgr (code, ins->dreg, src2);
3189 s390_sgr (code, ins->dreg, src2);
3194 s390_slbgr(code, ins->dreg, src2);
3198 if (ins->dreg != ins->sreg1) {
3199 s390_lgr (code, ins->dreg, ins->sreg1);
3201 if (s390_is_imm16 (-ins->inst_imm)) {
3202 s390_lghi (code, s390_r0, ins->inst_imm);
3203 s390_slgr (code, ins->dreg, s390_r0);
3205 s390_basr (code, s390_r13, 0);
3207 s390_llong(code, ins->inst_imm);
3208 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3213 if (ins->dreg != ins->sreg1) {
3214 s390_lgr (code, ins->dreg, ins->sreg1);
3216 if (s390_is_imm16 (-ins->inst_imm)) {
3217 s390_lghi (code, s390_r0, ins->inst_imm);
3218 s390_slgr (code, ins->dreg, s390_r0);
3220 s390_basr (code, s390_r13, 0);
3222 s390_llong(code, ins->inst_imm);
3223 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3228 if (ins->dreg != ins->sreg1) {
3229 s390_lgr (code, ins->dreg, ins->sreg1);
3231 if (s390_is_imm16 (-ins->inst_imm)) {
3232 s390_lghi (code, s390_r0, ins->inst_imm);
3233 s390_slbgr (code, ins->dreg, s390_r0);
3235 s390_basr (code, s390_r13, 0);
3237 s390_llong(code, ins->inst_imm);
3238 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3242 case OP_SUB_OVF_CARRY: {
3244 s390_lghi (code, s390_r0, 0);
3245 s390_lgr (code, s390_r1, s390_r0);
3246 s390_slbgr (code, s390_r0, s390_r1);
3247 s390_sgr (code, ins->dreg, src2);
3248 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3249 s390_agr (code, ins->dreg, s390_r0);
3250 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3253 case OP_SUB_OVF_UN_CARRY: {
3255 s390_slbgr (code, ins->dreg, src2);
3256 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3260 if (ins->sreg1 == ins->dreg) {
3261 s390_ngr (code, ins->dreg, ins->sreg2);
3264 if (ins->sreg2 == ins->dreg) {
3265 s390_ngr (code, ins->dreg, ins->sreg1);
3268 s390_lgr (code, ins->dreg, ins->sreg1);
3269 s390_ngr (code, ins->dreg, ins->sreg2);
3275 if (ins->dreg != ins->sreg1) {
3276 s390_lgr (code, ins->dreg, ins->sreg1);
3278 if (s390_is_imm16 (ins->inst_imm)) {
3279 s390_lghi (code, s390_r0, ins->inst_imm);
3280 s390_ngr (code, ins->dreg, s390_r0);
3282 s390_basr (code, s390_r13, 0);
3284 s390_llong(code, ins->inst_imm);
3285 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3290 s390_lgr (code, s390_r1, ins->sreg1);
3291 s390_dsgr (code, s390_r0, ins->sreg2);
3292 s390_lgr (code, ins->dreg, s390_r1);
3296 s390_lgr (code, s390_r1, ins->sreg1);
3297 s390_lghi (code, s390_r0, 0);
3298 s390_dlgr (code, s390_r0, ins->sreg2);
3299 s390_lgr (code, ins->dreg, s390_r1);
3303 s390_lgr (code, s390_r1, ins->sreg1);
3304 s390_dsgr (code, s390_r0, ins->sreg2);
3305 s390_lgr (code, ins->dreg, s390_r0);
3309 s390_lgr (code, s390_r1, ins->sreg1);
3310 s390_lghi (code, s390_r0, 0);
3311 s390_dlgr (code, s390_r0, ins->sreg2);
3312 s390_lgr (code, ins->dreg, s390_r0);
3316 if (ins->sreg1 == ins->dreg) {
3317 s390_ogr (code, ins->dreg, ins->sreg2);
3320 if (ins->sreg2 == ins->dreg) {
3321 s390_ogr (code, ins->dreg, ins->sreg1);
3324 s390_lgr (code, ins->dreg, ins->sreg1);
3325 s390_ogr (code, ins->dreg, ins->sreg2);
3331 if (ins->dreg != ins->sreg1) {
3332 s390_lgr (code, ins->dreg, ins->sreg1);
3334 if (s390_is_imm16 (ins->inst_imm)) {
3335 s390_lghi (code, s390_r0, ins->inst_imm);
3336 s390_ogr (code, ins->dreg, s390_r0);
3338 s390_basr (code, s390_r13, 0);
3340 s390_llong(code, ins->inst_imm);
3341 s390_og (code, ins->dreg, 0, s390_r13, 4);
3346 if (ins->sreg1 == ins->dreg) {
3347 s390_xgr (code, ins->dreg, ins->sreg2);
3350 if (ins->sreg2 == ins->dreg) {
3351 s390_xgr (code, ins->dreg, ins->sreg1);
3354 s390_lgr (code, ins->dreg, ins->sreg1);
3355 s390_xgr (code, ins->dreg, ins->sreg2);
3361 if (ins->dreg != ins->sreg1) {
3362 s390_lgr (code, ins->dreg, ins->sreg1);
3364 if (s390_is_imm16 (ins->inst_imm)) {
3365 s390_lghi (code, s390_r0, ins->inst_imm);
3366 s390_xgr (code, ins->dreg, s390_r0);
3368 s390_basr (code, s390_r13, 0);
3370 s390_llong(code, ins->inst_imm);
3371 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3377 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3382 if (ins->sreg1 != ins->dreg) {
3383 s390_lgr (code, ins->dreg, ins->sreg1);
3385 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3390 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3395 if (ins->sreg1 != ins->dreg) {
3396 s390_lgr (code, ins->dreg, ins->sreg1);
3398 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3402 case OP_LSHR_UN_IMM: {
3403 if (ins->sreg1 != ins->dreg) {
3404 s390_lgr (code, ins->dreg, ins->sreg1);
3406 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3411 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3415 if (ins->sreg1 != ins->dreg) {
3416 s390_lgr (code, ins->dreg, ins->sreg1);
3418 s390_lghi (code, s390_r0, -1);
3419 s390_xgr (code, ins->dreg, s390_r0);
3423 s390_lcgr (code, ins->dreg, ins->sreg1);
3428 s390_msgr (code, ins->dreg, src2);
3433 if (ins->dreg != ins->sreg1) {
3434 s390_lgr (code, ins->dreg, ins->sreg1);
3436 if (s390_is_imm16 (ins->inst_imm)) {
3437 s390_lghi (code, s390_r13, ins->inst_imm);
3439 s390_basr (code, s390_r13, 0);
3441 s390_llong(code, ins->inst_imm);
3442 s390_lg (code, s390_r13, 0, s390_r13, 4);
3444 s390_msgr (code, ins->dreg, s390_r13);
3449 s390_ltgr (code, s390_r1, ins->sreg1);
3450 s390_jz (code, 0); CODEPTR(code, o[0]);
3451 s390_ltgr (code, s390_r0, ins->sreg2);
3453 s390_lghi (code, s390_r1, 0);
3454 s390_j (code, 0); CODEPTR(code, o[1]);
3455 s390_xgr (code, s390_r0, s390_r1);
3456 s390_msgr (code, s390_r1, ins->sreg2);
3457 s390_xgr (code, s390_r0, s390_r1);
3458 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3459 s390_ltgr (code, s390_r0, s390_r0);
3460 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3461 PTRSLOT (code, o[0]);
3462 PTRSLOT (code, o[1]);
3463 s390_lgr (code, ins->dreg, s390_r1);
3466 case OP_LMUL_OVF_UN: {
3467 s390_lghi (code, s390_r0, 0);
3468 s390_lgr (code, s390_r1, ins->sreg1);
3469 s390_mlgr (code, s390_r0, ins->sreg2);
3470 s390_ltgr (code, s390_r0, s390_r0);
3471 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3472 s390_lgr (code, ins->dreg, s390_r1);
3476 g_assert_not_reached ();
3478 s390_algr (code, ins->dreg, src2);
3483 s390_agr (code, ins->dreg, src2);
3487 g_assert_not_reached ();
3489 s390_alcgr (code, ins->dreg, src2);
3493 if (ins->dreg != ins->sreg1) {
3494 s390_lgfr (code, ins->dreg, ins->sreg1);
3496 if (s390_is_imm16 (ins->inst_imm)) {
3497 s390_aghi(code, ins->dreg, ins->inst_imm);
3499 s390_basr (code, s390_r13, 0);
3501 s390_word (code, ins->inst_imm);
3502 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3507 if (ins->dreg != ins->sreg1) {
3508 s390_lgfr (code, ins->dreg, ins->sreg1);
3510 if (s390_is_imm16 (ins->inst_imm)) {
3511 s390_lghi (code, s390_r0, ins->inst_imm);
3512 s390_alcgr (code, ins->dreg, s390_r0);
3514 s390_basr (code, s390_r13, 0);
3516 s390_word (code, ins->inst_imm);
3517 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3518 s390_alcgr (code, ins->dreg, s390_r13);
3523 case OP_S390_LADD_OVF: {
3525 s390_agr (code, ins->dreg, src2);
3526 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3529 case OP_LADD_OVF_UN:
3530 case OP_S390_LADD_OVF_UN: {
3532 s390_algr (code, ins->dreg, src2);
3533 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3537 CHECK_SRCDST_NCOM_I;
3538 s390_slgr (code, ins->dreg, src2);
3542 CHECK_SRCDST_NCOM_I;
3543 s390_sgr (code, ins->dreg, src2);
3547 CHECK_SRCDST_NCOM_I;
3548 s390_slbgr (code, ins->dreg, src2);
3552 if (ins->dreg != ins->sreg1) {
3553 s390_lgfr (code, ins->dreg, ins->sreg1);
3555 if (s390_is_imm16 (-ins->inst_imm)) {
3556 s390_aghi (code, ins->dreg, -ins->inst_imm);
3558 s390_basr (code, s390_r13, 0);
3560 s390_word (code, ins->inst_imm);
3561 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3566 s390_basr (code, s390_r13, 0);
3568 s390_word (code, ins->inst_imm);
3569 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3573 case OP_S390_ISUB_OVF: {
3575 s390_sr (code, ins->dreg, src2);
3576 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3577 s390_lgfr (code, ins->dreg, ins->dreg);
3580 case OP_ISUB_OVF_UN:
3581 case OP_S390_ISUB_OVF_UN: {
3583 s390_slr (code, ins->dreg, src2);
3584 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3585 s390_llgfr(code, ins->dreg, ins->dreg);
3589 case OP_S390_LSUB_OVF: {
3591 s390_sgr (code, ins->dreg, src2);
3592 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3595 case OP_LSUB_OVF_UN:
3596 case OP_S390_LSUB_OVF_UN: {
3598 s390_slgr (code, ins->dreg, src2);
3599 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3603 CHECK_SRCDST_NCOM_I;
3604 s390_ngr (code, ins->dreg, src2);
3608 if (ins->dreg != ins->sreg1) {
3609 s390_lgfr (code, ins->dreg, ins->sreg1);
3611 if (s390_is_imm16 (ins->inst_imm)) {
3612 s390_lghi (code, s390_r0, ins->inst_imm);
3613 s390_ngr (code, ins->dreg, s390_r0);
3615 s390_basr (code, s390_r13, 0);
3617 s390_llong(code, ins->inst_imm);
3618 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3623 s390_lgfr (code, s390_r0, ins->sreg1);
3624 s390_srda (code, s390_r0, 0, 32);
3625 s390_dr (code, s390_r0, ins->sreg2);
3626 s390_lgfr (code, ins->dreg, s390_r1);
3630 s390_lgfr (code, s390_r0, ins->sreg1);
3631 s390_srdl (code, s390_r0, 0, 32);
3632 s390_dlr (code, s390_r0, ins->sreg2);
3633 s390_lgfr (code, ins->dreg, s390_r1);
3637 if (s390_is_imm16 (ins->inst_imm)) {
3638 s390_lghi (code, s390_r13, ins->inst_imm);
3639 s390_lgfr (code, s390_r0, ins->sreg1);
3641 s390_basr (code, s390_r13, 0);
3643 s390_word (code, ins->inst_imm);
3644 s390_lgfr (code, s390_r0, ins->sreg1);
3645 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3647 s390_srda (code, s390_r0, 0, 32);
3648 s390_dr (code, s390_r0, ins->sreg2);
3649 s390_lgfr (code, ins->dreg, s390_r1);
3653 s390_lgfr (code, s390_r0, ins->sreg1);
3654 s390_srda (code, s390_r0, 0, 32);
3655 s390_dr (code, s390_r0, ins->sreg2);
3656 s390_lgfr (code, ins->dreg, s390_r0);
3659 s390_lgfr (code, s390_r0, ins->sreg1);
3660 s390_srdl (code, s390_r0, 0, 32);
3661 s390_dlr (code, s390_r0, ins->sreg2);
3662 s390_lgfr (code, ins->dreg, s390_r0);
3666 if (s390_is_imm16 (ins->inst_imm)) {
3667 s390_lghi (code, s390_r13, ins->inst_imm);
3668 s390_lgfr (code, s390_r0, ins->sreg1);
3670 s390_basr (code, s390_r13, 0);
3672 s390_word (code, ins->inst_imm);
3673 s390_lgfr (code, s390_r0, ins->sreg1);
3674 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3676 s390_srda (code, s390_r0, 0, 32);
3677 s390_dr (code, s390_r0, ins->sreg2);
3678 s390_lgfr (code, ins->dreg, s390_r0);
3683 s390_ogr (code, ins->dreg, src2);
3687 if (ins->dreg != ins->sreg1) {
3688 s390_lgfr (code, ins->dreg, ins->sreg1);
3690 if (s390_is_imm16 (ins->inst_imm)) {
3691 s390_lghi (code, s390_r0, ins->inst_imm);
3692 s390_ogr (code, ins->dreg, s390_r0);
3694 s390_basr (code, s390_r13, 0);
3696 s390_llong(code, ins->inst_imm);
3697 s390_og (code, ins->dreg, 0, s390_r13, 4);
3703 s390_xgr (code, ins->dreg, src2);
3707 if (ins->dreg != ins->sreg1) {
3708 s390_lgfr (code, ins->dreg, ins->sreg1);
3710 if (s390_is_imm16 (ins->inst_imm)) {
3711 s390_lghi (code, s390_r0, ins->inst_imm);
3712 s390_xgr (code, ins->dreg, s390_r0);
3714 s390_basr (code, s390_r13, 0);
3716 s390_llong(code, ins->inst_imm);
3717 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3723 s390_sll (code, ins->dreg, src2, 0);
3727 if (ins->sreg1 != ins->dreg) {
3728 s390_lgfr (code, ins->dreg, ins->sreg1);
3730 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3735 s390_sra (code, ins->dreg, src2, 0);
3739 if (ins->sreg1 != ins->dreg) {
3740 s390_lgfr (code, ins->dreg, ins->sreg1);
3742 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3745 case OP_ISHR_UN_IMM: {
3746 if (ins->sreg1 != ins->dreg) {
3747 s390_lgfr (code, ins->dreg, ins->sreg1);
3749 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3754 s390_srl (code, ins->dreg, src2, 0);
3758 if (ins->sreg1 != ins->dreg) {
3759 s390_lgfr (code, ins->dreg, ins->sreg1);
3761 s390_lghi (code, s390_r0, -1);
3762 s390_xgr (code, ins->dreg, s390_r0);
3766 s390_lcgr (code, ins->dreg, ins->sreg1);
3771 s390_msr (code, ins->dreg, src2);
3775 if (ins->dreg != ins->sreg1) {
3776 s390_lgfr (code, ins->dreg, ins->sreg1);
3778 if (s390_is_imm16 (ins->inst_imm)) {
3779 s390_lghi (code, s390_r13, ins->inst_imm);
3781 s390_basr (code, s390_r13, 0);
3783 s390_word (code, ins->inst_imm);
3784 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3786 s390_msr (code, ins->dreg, s390_r13);
3791 s390_ltr (code, s390_r1, ins->sreg1);
3792 s390_jz (code, 0); CODEPTR(code, o[0]);
3793 s390_ltr (code, s390_r0, ins->sreg2);
3795 s390_lhi (code, s390_r1, 0);
3796 s390_j (code, 0); CODEPTR(code, o[1]);
3797 s390_xr (code, s390_r0, s390_r1);
3798 s390_msr (code, s390_r1, ins->sreg2);
3799 s390_xr (code, s390_r0, s390_r1);
3800 s390_srl (code, s390_r0, 0, 31);
3801 s390_ltr (code, s390_r0, s390_r0);
3802 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3803 PTRSLOT (code, o[0]);
3804 PTRSLOT (code, o[1]);
3805 s390_lgfr (code, ins->dreg, s390_r1);
3808 case OP_IMUL_OVF_UN: {
3809 s390_lhi (code, s390_r0, 0);
3810 s390_lr (code, s390_r1, ins->sreg1);
3811 s390_mlr (code, s390_r0, ins->sreg2);
3812 s390_ltr (code, s390_r0, s390_r0);
3813 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3814 s390_lgfr (code, ins->dreg, s390_r1);
3819 if (s390_is_imm16(ins->inst_c0)) {
3820 s390_lghi (code, ins->dreg, ins->inst_c0);
3822 s390_basr (code, s390_r13, 0);
3824 s390_llong(code, ins->inst_c0);
3825 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3830 s390_basr (code, s390_r13, 0);
3832 mono_add_patch_info (cfg, code - cfg->native_code,
3833 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3834 s390_llong(code, 0);
3835 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3838 case OP_JUMP_TABLE: {
3839 mono_add_patch_info (cfg, code - cfg->native_code,
3840 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3841 s390_basr (code, s390_r13, 0);
3843 s390_llong (code, 0);
3844 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3848 if (ins->dreg != ins->sreg1) {
3849 s390_lgr (code, ins->dreg, ins->sreg1);
3853 case OP_LCONV_TO_I8:
3855 s390_lgfr (code, ins->dreg, ins->sreg1);
3857 case OP_LCONV_TO_I4:
3858 s390_lgfr (code, ins->dreg, ins->sreg1);
3861 case OP_LCONV_TO_U8:
3862 case OP_LCONV_TO_U4:
3864 s390_llgfr (code, ins->dreg, ins->sreg1);
3866 case OP_LCONV_TO_OVF_U4:
3867 s390_basr (code, s390_r13, 0);
3869 s390_llong(code, 4294967295);
3870 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3871 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3872 s390_ltgr (code, ins->sreg1, ins->sreg1);
3873 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3874 s390_llgfr(code, ins->dreg, ins->sreg1);
3876 case OP_LCONV_TO_OVF_I4_UN:
3877 s390_basr (code, s390_r13, 0);
3879 s390_llong(code, 2147483647);
3880 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3881 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3882 s390_ltgr (code, ins->sreg1, ins->sreg1);
3883 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3884 s390_lgfr (code, ins->dreg, ins->sreg1);
3887 case OP_FCONV_TO_R4: {
3888 if (ins->dreg != ins->sreg1) {
3889 s390_ldr (code, ins->dreg, ins->sreg1);
3893 case OP_S390_SETF4RET: {
3894 s390_ledbr (code, ins->dreg, ins->sreg1);
3898 if (cfg->method->save_lmf)
3899 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3901 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3902 code = emit_load_volatile_arguments (code, cfg);
3905 code = backUpStackPtr(cfg, code);
3906 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3907 mono_add_patch_info (cfg, code - cfg->native_code,
3908 MONO_PATCH_INFO_METHOD_JUMP,
3910 s390_jcl (code, S390_CC_UN, 0);
3913 case OP_CHECK_THIS: {
3914 /* ensure ins->sreg1 is not NULL */
3915 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3916 s390_ltgr (code, s390_r0, s390_r0);
3920 int offset = cfg->sig_cookie + cfg->stack_usage;
3922 if (s390_is_imm16 (offset))
3923 s390_lghi (code, s390_r0, offset);
3925 s390_basr (code, s390_r13, 0);
3927 s390_llong(code, offset);
3928 s390_lg (code, s390_r0, 0, s390_r13, 0);
3930 s390_agr (code, s390_r0, cfg->frame_reg);
3931 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3935 s390_basr (code, s390_r13, 0);
3937 call = (MonoCallInst*)ins;
3938 if (ins->flags & MONO_INST_HAS_METHOD)
3939 mono_add_patch_info (cfg, code-cfg->native_code,
3940 MONO_PATCH_INFO_METHOD,
3943 mono_add_patch_info (cfg, code-cfg->native_code,
3944 MONO_PATCH_INFO_ABS,
3946 s390_llong(code, 0);
3947 s390_lg (code, s390_r14, 0, s390_r13, 4);
3948 s390_basr (code, s390_r14, s390_r14);
3949 if (call->signature->ret->type == MONO_TYPE_R4)
3950 s390_ldebr (code, s390_f0, s390_f0);
3958 s390_basr (code, s390_r13, 0);
3960 call = (MonoCallInst*)ins;
3961 if (ins->flags & MONO_INST_HAS_METHOD)
3962 mono_add_patch_info (cfg, code-cfg->native_code,
3963 MONO_PATCH_INFO_METHOD,
3966 mono_add_patch_info (cfg, code-cfg->native_code,
3967 MONO_PATCH_INFO_ABS,
3969 s390_llong(code, 0);
3970 s390_lg (code, s390_r14, 0, s390_r13, 4);
3971 s390_basr (code, s390_r14, s390_r14);
3974 case OP_FCALL_REG: {
3975 call = (MonoCallInst*)ins;
3976 s390_lgr (code, s390_r1, ins->sreg1);
3977 s390_basr (code, s390_r14, s390_r1);
3978 if (call->signature->ret->type == MONO_TYPE_R4)
3979 s390_ldebr (code, s390_f0, s390_f0);
3985 case OP_VOIDCALL_REG:
3987 s390_lgr (code, s390_r1, ins->sreg1);
3988 s390_basr (code, s390_r14, s390_r1);
3991 case OP_FCALL_MEMBASE: {
3992 call = (MonoCallInst*)ins;
3993 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3994 s390_basr (code, s390_r14, s390_r1);
3995 if (call->signature->ret->type == MONO_TYPE_R4)
3996 s390_ldebr (code, s390_f0, s390_f0);
3999 case OP_LCALL_MEMBASE:
4000 case OP_VCALL_MEMBASE:
4001 case OP_VCALL2_MEMBASE:
4002 case OP_VOIDCALL_MEMBASE:
4003 case OP_CALL_MEMBASE: {
4004 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4005 s390_basr (code, s390_r14, s390_r1);
4012 if (cfg->param_area == 0)
4013 alloca_skip = S390_MINIMAL_STACK_SIZE;
4015 alloca_skip = cfg->param_area;
4017 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4018 s390_lgr (code, s390_r1, ins->sreg1);
4019 if (ins->flags & MONO_INST_INIT)
4020 s390_lgr (code, s390_r0, ins->sreg1);
4021 s390_aghi (code, s390_r1, 14);
4022 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4023 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4024 if (cfg->method->save_lmf) {
4025 /*----------------------------------*/
4026 /* we have to adjust lmf ebp value */
4027 /*----------------------------------*/
4028 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4030 s390_lgr (code, s390_r13, cfg->frame_reg);
4031 if (s390_is_imm16(lmfOffset))
4032 s390_aghi (code, s390_r13, lmfOffset);
4034 s390_basr (code, s390_r14, 0);
4036 s390_word (code, lmfOffset);
4037 s390_agf (code, s390_r13, 0, s390_r14, 4);
4039 s390_lgr (code, s390_r14, STK_BASE);
4040 s390_sgr (code, s390_r14, s390_r1);
4041 s390_stg (code, s390_r14, 0, s390_r13,
4042 G_STRUCT_OFFSET(MonoLMF, ebp));
4044 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4045 s390_sgr (code, STK_BASE, s390_r1);
4046 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4047 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4048 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4049 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4050 if (ins->flags & MONO_INST_INIT) {
4051 s390_lgr (code, s390_r1, s390_r0);
4052 s390_lgr (code, s390_r0, ins->dreg);
4053 s390_lgr (code, s390_r14, s390_r12);
4054 s390_lghi (code, s390_r13, 0);
4055 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4057 s390_lgr (code, s390_r12, s390_r14);
4062 s390_lgr (code, s390_r2, ins->sreg1);
4063 s390_basr (code, s390_r13, 0);
4065 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4066 (gpointer) "mono_arch_throw_exception");
4067 s390_llong(code, 0);
4068 s390_lg (code, s390_r14, 0, s390_r13, 4);
4069 s390_basr (code, s390_r14, s390_r14);
4073 s390_lgr (code, s390_r2, ins->sreg1);
4074 s390_basr (code, s390_r13, 0);
4076 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4077 (gpointer) "mono_arch_rethrow_exception");
4078 s390_llong(code, 0);
4079 s390_lg (code, s390_r14, 0, s390_r13, 4);
4080 s390_basr (code, s390_r14, s390_r14);
4083 case OP_START_HANDLER: {
4084 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4086 S390_LONG (code, stg, stg, s390_r14, 0,
4087 spvar->inst_basereg,
4088 spvar->inst_offset);
4091 case OP_ENDFILTER: {
4092 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4094 if (ins->sreg1 != s390_r2)
4095 s390_lgr(code, s390_r2, ins->sreg1);
4096 S390_LONG (code, lg, lg, s390_r14, 0,
4097 spvar->inst_basereg,
4098 spvar->inst_offset);
4099 s390_br (code, s390_r14);
4102 case OP_ENDFINALLY: {
4103 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4105 S390_LONG (code, lg, lg, s390_r14, 0,
4106 spvar->inst_basereg,
4107 spvar->inst_offset);
4108 s390_br (code, s390_r14);
4111 case OP_CALL_HANDLER: {
4112 mono_add_patch_info (cfg, code-cfg->native_code,
4113 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4114 s390_brasl (code, s390_r14, 0);
4115 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4119 ins->inst_c0 = code - cfg->native_code;
4122 case OP_RELAXED_NOP:
4125 case OP_DUMMY_STORE:
4126 case OP_NOT_REACHED:
4131 EMIT_UNCOND_BRANCH(ins);
4134 s390_br (code, ins->sreg1);
4140 s390_lghi(code, ins->dreg, 1);
4142 s390_lghi(code, ins->dreg, 0);
4148 s390_lghi(code, ins->dreg, 1);
4150 s390_lghi(code, ins->dreg, 0);
4156 s390_lghi(code, ins->dreg, 1);
4158 s390_lghi(code, ins->dreg, 0);
4164 s390_lghi(code, ins->dreg, 1);
4166 s390_lghi(code, ins->dreg, 0);
4172 s390_lghi(code, ins->dreg, 1);
4174 s390_lghi(code, ins->dreg, 0);
4177 case OP_COND_EXC_EQ:
4178 case OP_COND_EXC_IEQ:
4179 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4181 case OP_COND_EXC_NE_UN:
4182 case OP_COND_EXC_INE_UN:
4183 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4185 case OP_COND_EXC_LT:
4186 case OP_COND_EXC_ILT:
4187 case OP_COND_EXC_LT_UN:
4188 case OP_COND_EXC_ILT_UN:
4189 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4191 case OP_COND_EXC_GT:
4192 case OP_COND_EXC_IGT:
4193 case OP_COND_EXC_GT_UN:
4194 case OP_COND_EXC_IGT_UN:
4195 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4197 case OP_COND_EXC_GE:
4198 case OP_COND_EXC_IGE:
4199 case OP_COND_EXC_GE_UN:
4200 case OP_COND_EXC_IGE_UN:
4201 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4203 case OP_COND_EXC_LE:
4204 case OP_COND_EXC_ILE:
4205 case OP_COND_EXC_LE_UN:
4206 case OP_COND_EXC_ILE_UN:
4207 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4209 case OP_COND_EXC_OV:
4210 case OP_COND_EXC_IOV:
4211 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4213 case OP_COND_EXC_NO:
4214 case OP_COND_EXC_INO:
4215 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4218 case OP_COND_EXC_IC:
4219 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4221 case OP_COND_EXC_NC:
4222 case OP_COND_EXC_INC:
4223 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4227 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4231 EMIT_COND_BRANCH (ins, S390_CC_NE);
4237 EMIT_COND_BRANCH (ins, S390_CC_LT);
4243 EMIT_COND_BRANCH (ins, S390_CC_GT);
4249 EMIT_COND_BRANCH (ins, S390_CC_GE);
4255 EMIT_COND_BRANCH (ins, S390_CC_LE);
4258 /* floating point opcodes */
4260 if (*((float *) ins->inst_p0) == 0) {
4261 s390_lzdr (code, ins->dreg);
4263 s390_basr (code, s390_r13, 0);
4265 s390_llong (code, ins->inst_p0);
4266 s390_lg (code, s390_r13, 0, s390_r13, 4);
4267 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4272 if (*((float *) ins->inst_p0) == 0) {
4273 s390_lzdr (code, ins->dreg);
4275 s390_basr (code, s390_r13, 0);
4277 s390_llong(code, ins->inst_p0);
4278 s390_lg (code, s390_r13, 0, s390_r13, 4);
4279 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4283 case OP_STORER8_MEMBASE_REG: {
4284 S390_LONG (code, stdy, std, ins->sreg1, 0,
4285 ins->inst_destbasereg, ins->inst_offset);
4288 case OP_LOADR8_MEMBASE: {
4289 S390_LONG (code, ldy, ld, ins->dreg, 0,
4290 ins->inst_basereg, ins->inst_offset);
4293 case OP_STORER4_MEMBASE_REG: {
4294 s390_ledbr (code, s390_f15, ins->sreg1);
4295 S390_LONG (code, stey, ste, s390_f15, 0,
4296 ins->inst_destbasereg, ins->inst_offset);
4299 case OP_LOADR4_MEMBASE: {
4300 S390_LONG (code, ldy, ld, s390_f15, 0,
4301 ins->inst_basereg, ins->inst_offset);
4302 s390_ldebr (code, ins->dreg, s390_f15);
4305 case OP_ICONV_TO_R_UN: {
4306 s390_cdfbr (code, ins->dreg, ins->sreg1);
4307 s390_ltr (code, ins->sreg1, ins->sreg1);
4308 s390_jnl (code, 12);
4309 s390_basr (code, s390_r13, 0);
4311 s390_word (code, 0x41f00000);
4312 s390_word (code, 0);
4313 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4316 case OP_LCONV_TO_R_UN: {
4317 s390_cdgbr (code, ins->dreg, ins->sreg1);
4318 s390_ltgr (code, ins->sreg1, ins->sreg1);
4319 s390_jnl (code, 12);
4320 s390_basr (code, s390_r13, 0);
4322 s390_word (code, 0x41f00000);
4323 s390_word (code, 0);
4324 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4327 case OP_LCONV_TO_R4:
4328 case OP_ICONV_TO_R4: {
4329 s390_cdgbr (code, ins->dreg, ins->sreg1);
4332 case OP_LCONV_TO_R8:
4333 case OP_ICONV_TO_R8: {
4334 s390_cdgbr (code, ins->dreg, ins->sreg1);
4337 case OP_FCONV_TO_I1:
4338 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4340 case OP_FCONV_TO_U1:
4341 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4343 case OP_FCONV_TO_I2:
4344 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4346 case OP_FCONV_TO_U2:
4347 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4349 case OP_FCONV_TO_I4:
4351 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4353 case OP_FCONV_TO_U4:
4355 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4357 case OP_FCONV_TO_I8:
4358 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4360 case OP_LCONV_TO_OVF_I: {
4361 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4363 s390_ltgr (code, ins->sreg2, ins->sreg2);
4364 s390_jnl (code, 0); CODEPTR(code, o[0]);
4365 s390_ltgr (code, ins->sreg1, ins->sreg1);
4366 s390_jnl (code, 0); CODEPTR(code, o[1]);
4367 s390_lhi (code, s390_r13, -1);
4368 s390_cgr (code, ins->sreg1, s390_r13);
4369 s390_jnz (code, 0); CODEPTR(code, o[2]);
4370 if (ins->dreg != ins->sreg2)
4371 s390_lgr (code, ins->dreg, ins->sreg2);
4372 s390_j (code, 0); CODEPTR(code, o[3]);
4373 PTRSLOT(code, o[0]);
4374 s390_jz (code, 0); CODEPTR(code, o[4]);
4375 PTRSLOT(code, o[1]);
4376 PTRSLOT(code, o[2]);
4377 mono_add_patch_info (cfg, code - cfg->native_code,
4378 MONO_PATCH_INFO_EXC, "OverflowException");
4379 s390_brasl (code, s390_r14, 0);
4380 PTRSLOT(code, o[3]);
4381 PTRSLOT(code, o[4]);
4385 s390_lpdbr (code, ins->dreg, ins->sreg1);
4389 s390_sqdbr (code, ins->dreg, ins->sreg1);
4394 s390_adbr (code, ins->dreg, src2);
4398 CHECK_SRCDST_NCOM_F;
4399 s390_sdbr (code, ins->dreg, src2);
4404 s390_mdbr (code, ins->dreg, src2);
4408 CHECK_SRCDST_NCOM_F;
4409 s390_ddbr (code, ins->dreg, src2);
4413 s390_lcdbr (code, ins->dreg, ins->sreg1);
4417 CHECK_SRCDST_NCOM_F;
4418 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4422 s390_cdbr (code, ins->sreg1, ins->sreg2);
4426 s390_cdbr (code, ins->sreg1, ins->sreg2);
4427 s390_lghi (code, ins->dreg, 1);
4429 s390_lghi (code, ins->dreg, 0);
4433 s390_cdbr (code, ins->sreg1, ins->sreg2);
4434 s390_lghi (code, ins->dreg, 1);
4436 s390_lghi (code, ins->dreg, 0);
4440 s390_cdbr (code, ins->sreg1, ins->sreg2);
4441 s390_lghi (code, ins->dreg, 1);
4443 s390_lghi (code, ins->dreg, 0);
4447 s390_cdbr (code, ins->sreg1, ins->sreg2);
4448 s390_lghi (code, ins->dreg, 1);
4450 s390_lghi (code, ins->dreg, 0);
4454 s390_cdbr (code, ins->sreg1, ins->sreg2);
4455 s390_lghi (code, ins->dreg, 1);
4457 s390_lghi (code, ins->dreg, 0);
4462 s390_jo (code, 0); CODEPTR(code, o);
4463 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4468 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4472 s390_jo (code, 0); CODEPTR(code, o);
4473 EMIT_COND_BRANCH (ins, S390_CC_LT);
4478 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4482 s390_jo (code, 0); CODEPTR(code, o);
4483 EMIT_COND_BRANCH (ins, S390_CC_GT);
4488 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4492 s390_jo (code, 0); CODEPTR(code, o);
4493 EMIT_COND_BRANCH (ins, S390_CC_GE);
4498 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4502 s390_jo (code, 0); CODEPTR(code, o);
4503 EMIT_COND_BRANCH (ins, S390_CC_LE);
4508 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4512 s390_lhi (code, s390_r13, 0x7f);
4513 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4514 s390_jz (code, 0); CODEPTR(code, o);
4515 mono_add_patch_info (cfg, code - cfg->native_code,
4516 MONO_PATCH_INFO_EXC, "ArithmeticException");
4517 s390_brasl (code, s390_r14,0);
4521 case OP_S390_MOVE: {
4522 if (ins->backend.size > 0) {
4523 if (ins->backend.size <= 256) {
4524 s390_mvc (code, ins->backend.size, ins->dreg,
4525 ins->inst_offset, ins->sreg1, ins->inst_imm);
4527 s390_lgr (code, s390_r0, ins->dreg);
4528 if (ins->inst_offset > 0) {
4529 if (s390_is_imm16 (ins->inst_offset)) {
4530 s390_aghi (code, s390_r0, ins->inst_offset);
4532 s390_basr (code, s390_r13, 0);
4534 s390_llong(code, ins->inst_offset);
4535 s390_ag (code, s390_r0, 0, s390_r13, 4);
4538 s390_lgr (code, s390_r12, ins->sreg1);
4539 if (ins->inst_imm > 0) {
4540 if (s390_is_imm16 (ins->inst_imm)) {
4541 s390_aghi (code, s390_r12, ins->inst_imm);
4543 s390_basr (code, s390_r13, 0);
4545 s390_llong(code, ins->inst_imm);
4546 s390_ag (code, s390_r12, 0, s390_r13, 4);
4549 if (s390_is_imm16 (ins->backend.size)) {
4550 s390_lghi (code, s390_r1, ins->backend.size);
4552 s390_basr (code, s390_r13, 0);
4554 s390_llong(code, ins->backend.size);
4555 s390_lg (code, s390_r1, 0, s390_r13, 4);
4557 s390_lgr (code, s390_r13, s390_r1);
4558 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4564 case OP_ATOMIC_ADD_I8: {
4565 s390_lgr (code, s390_r1, ins->sreg2);
4566 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4567 s390_agr (code, s390_r1, s390_r0);
4568 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4569 s390_jnz (code, -10);
4570 s390_lgr (code, ins->dreg, s390_r1);
4573 case OP_ATOMIC_ADD_NEW_I8: {
4574 s390_lgr (code, s390_r1, ins->sreg2);
4575 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4576 s390_agr (code, s390_r1, s390_r0);
4577 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4578 s390_jnz (code, -10);
4579 s390_lgr (code, ins->dreg, s390_r1);
4582 case OP_ATOMIC_EXCHANGE_I8: {
4583 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4584 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4585 s390_jnz (code, -6);
4586 s390_lgr (code, ins->dreg, s390_r0);
4589 case OP_ATOMIC_ADD_I4: {
4590 s390_lgfr(code, s390_r1, ins->sreg2);
4591 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4592 s390_agr (code, s390_r1, s390_r0);
4593 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4594 s390_jnz (code, -9);
4595 s390_lgfr(code, ins->dreg, s390_r1);
4598 case OP_ATOMIC_ADD_NEW_I4: {
4599 s390_lgfr(code, s390_r1, ins->sreg2);
4600 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4601 s390_agr (code, s390_r1, s390_r0);
4602 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4603 s390_jnz (code, -9);
4604 s390_lgfr(code, ins->dreg, s390_r1);
4607 case OP_ATOMIC_EXCHANGE_I4: {
4608 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4609 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4610 s390_jnz (code, -4);
4611 s390_lgfr(code, ins->dreg, s390_r0);
4614 case OP_S390_BKCHAIN: {
4615 s390_lgr (code, ins->dreg, ins->sreg1);
4616 if (s390_is_imm16 (cfg->stack_offset)) {
4617 s390_aghi (code, ins->dreg, cfg->stack_offset);
4619 s390_basr (code, s390_r13, 0);
4621 s390_llong(code, cfg->stack_offset);
4622 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4626 case OP_MEMORY_BARRIER: {
4630 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4631 g_assert_not_reached ();
4634 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4635 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4636 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4637 g_assert_not_reached ();
4642 last_offset = offset;
4645 cfg->code_len = code - cfg->native_code;
4648 /*========================= End of Function ========================*/
4650 /*------------------------------------------------------------------*/
4652 /* Name - mono_arch_register_lowlevel_calls */
4654 /* Function - Register routines to help with --trace operation. */
4656 /*------------------------------------------------------------------*/
4659 mono_arch_register_lowlevel_calls (void)
4661 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4664 /*========================= End of Function ========================*/
4666 /*------------------------------------------------------------------*/
4668 /* Name - mono_arch_patch_code */
4670 /* Function - Process the patch data created during the */
4671 /* instruction build process. This resolves jumps, */
4672 /* calls, variables etc. */
4674 /*------------------------------------------------------------------*/
4677 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4678 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4680 MonoJumpInfo *patch_info;
4682 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4683 unsigned char *ip = patch_info->ip.i + code;
4684 gconstpointer target = NULL;
4686 target = mono_resolve_patch_target (method, domain, code,
4687 patch_info, run_cctors);
4689 switch (patch_info->type) {
4690 case MONO_PATCH_INFO_IP:
4691 case MONO_PATCH_INFO_EXC_NAME:
4692 case MONO_PATCH_INFO_LDSTR:
4693 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4694 case MONO_PATCH_INFO_LDTOKEN:
4695 case MONO_PATCH_INFO_EXC:
4696 case MONO_PATCH_INFO_ABS:
4697 case MONO_PATCH_INFO_METHOD:
4698 case MONO_PATCH_INFO_INTERNAL_METHOD:
4699 case MONO_PATCH_INFO_CLASS_INIT:
4700 s390_patch_addr (ip, (guint64) target);
4702 case MONO_PATCH_INFO_SWITCH:
4703 /*----------------------------------*/
4704 /* ip points at the basr r13,0/j +4 */
4705 /* instruction the vtable value */
4706 /* follows this (i.e. ip+6) */
4707 /*----------------------------------*/
4708 *((gconstpointer *)(ip+6)) = target;
4710 case MONO_PATCH_INFO_METHODCONST:
4711 case MONO_PATCH_INFO_CLASS:
4712 case MONO_PATCH_INFO_IMAGE:
4713 case MONO_PATCH_INFO_FIELD:
4714 case MONO_PATCH_INFO_IID:
4715 target = S390_RELATIVE(target, ip);
4716 s390_patch_rel (ip, (guint64) target);
4718 case MONO_PATCH_INFO_R4:
4719 case MONO_PATCH_INFO_R8:
4720 case MONO_PATCH_INFO_METHOD_REL:
4721 g_assert_not_reached ();
4724 target = S390_RELATIVE(target, ip);
4726 s390_patch_rel (ip, (guint64) target);
4731 /*========================= End of Function ========================*/
4733 /*------------------------------------------------------------------*/
4735 /* Name - emit_load_volatile_arguments */
4737 /* Function - Emit the instructions to reload parameter regist- */
4738 /* registers for use with "tail" operations. */
4740 /* The register loading operations performed here */
4741 /* are the mirror of the store operations performed */
4742 /* in mono_arch_emit_prolog and need to be kept in */
4743 /* synchronization with it. */
4745 /*------------------------------------------------------------------*/
4748 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4751 MonoMethod *method = cfg->method;
4752 MonoMethodSignature *sig = mono_method_signature(method);
4756 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4758 if (cinfo->struct_ret) {
4759 ArgInfo *ainfo = &cinfo->ret;
4760 inst = cfg->vret_addr;
4761 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4764 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4765 ArgInfo *ainfo = cinfo->args + i;
4766 inst = cfg->args [pos];
4768 if (inst->opcode == OP_REGVAR) {
4769 if (ainfo->regtype == RegTypeGeneral)
4770 s390_lgr (code, ainfo->reg, inst->dreg);
4771 else if (ainfo->regtype == RegTypeFP) {
4772 if (inst->dreg != ainfo->reg) {
4773 if (ainfo->size == 4) {
4774 s390_ldebr (code, ainfo->reg, inst->dreg);
4776 s390_ldr (code, ainfo->reg, inst->dreg);
4780 else if (ainfo->regtype == RegTypeBase) {
4782 g_assert_not_reached ();
4784 if (ainfo->regtype == RegTypeGeneral) {
4785 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4786 g_assert_not_reached();
4787 switch (ainfo->size) {
4789 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4792 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4795 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4798 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4801 } else if (ainfo->regtype == RegTypeBase) {
4802 } else if (ainfo->regtype == RegTypeFP) {
4803 if (ainfo->size == 8)
4804 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4805 else if (ainfo->size == 4)
4806 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4808 g_assert_not_reached ();
4809 } else if (ainfo->regtype == RegTypeStructByVal) {
4810 if (ainfo->reg != STK_BASE) {
4811 switch (ainfo->size) {
4813 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4816 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4819 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4822 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4826 } else if (ainfo->regtype == RegTypeStructByAddr) {
4827 if (ainfo->reg != STK_BASE) {
4828 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4831 g_assert_not_reached ();
4839 /*========================= End of Function ========================*/
4841 /*------------------------------------------------------------------*/
4843 /* Name - mono_arch_emit_prolog */
4845 /* Function - Create the instruction sequence for a function */
4848 /*------------------------------------------------------------------*/
4851 mono_arch_emit_prolog (MonoCompile *cfg)
4853 MonoMethod *method = cfg->method;
4855 MonoMethodSignature *sig;
4857 int alloc_size, pos, max_offset, i;
4863 cfg->code_size = 512;
4865 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4867 cfg->code_size += 256;
4870 if (method->save_lmf)
4871 cfg->code_size += 200;
4873 cfg->native_code = code = g_malloc (cfg->code_size);
4875 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4877 if (cfg->arch.bkchain_reg != -1)
4878 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4880 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4881 cfg->used_int_regs |= 1 << 11;
4884 alloc_size = cfg->stack_offset;
4886 cfg->stack_usage = alloc_size;
4887 s390_lgr (code, s390_r11, STK_BASE);
4888 if (s390_is_imm16 (alloc_size)) {
4889 s390_aghi (code, STK_BASE, -alloc_size);
4891 int stackSize = alloc_size;
4892 while (stackSize > 32767) {
4893 s390_aghi (code, STK_BASE, -32767);
4896 s390_aghi (code, STK_BASE, -stackSize);
4898 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4900 if (cfg->frame_reg != STK_BASE)
4901 s390_lgr (code, s390_r11, STK_BASE);
4903 /* compute max_offset in order to use short forward jumps
4904 * we always do it on s390 because the immediate displacement
4905 * for jumps is too small
4908 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4910 bb->max_offset = max_offset;
4912 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4915 MONO_BB_FOR_EACH_INS (bb, ins)
4916 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4919 /* load arguments allocated to register from the stack */
4920 sig = mono_method_signature (method);
4923 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4925 if (cinfo->struct_ret) {
4926 ArgInfo *ainfo = &cinfo->ret;
4927 inst = cfg->vret_addr;
4928 inst->backend.size = ainfo->vtsize;
4929 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4932 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4933 ArgInfo *ainfo = cinfo->args + i;
4934 inst = cfg->args [pos];
4936 if (inst->opcode == OP_VTARG_ADDR)
4937 inst = inst->inst_left;
4939 if (inst->opcode == OP_REGVAR) {
4940 if (ainfo->regtype == RegTypeGeneral)
4941 s390_lgr (code, inst->dreg, ainfo->reg);
4942 else if (ainfo->regtype == RegTypeFP) {
4943 if (inst->dreg != ainfo->reg) {
4944 if (ainfo->size == 4) {
4945 s390_ledbr (code, inst->dreg, ainfo->reg);
4947 s390_ldr (code, inst->dreg, ainfo->reg);
4951 else if (ainfo->regtype == RegTypeBase) {
4952 s390_lgr (code, s390_r13, STK_BASE);
4953 s390_aghi (code, s390_r13, alloc_size);
4954 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4956 g_assert_not_reached ();
4958 if (cfg->verbose_level > 2)
4959 g_print ("Argument %d assigned to register %s\n",
4960 pos, mono_arch_regname (inst->dreg));
4962 if (ainfo->regtype == RegTypeGeneral) {
4963 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4964 g_assert_not_reached();
4965 switch (ainfo->size) {
4967 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4970 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4973 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4976 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4979 } else if (ainfo->regtype == RegTypeBase) {
4980 } else if (ainfo->regtype == RegTypeFP) {
4981 if (ainfo->size == 8)
4982 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4983 else if (ainfo->size == 4)
4984 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4986 g_assert_not_reached ();
4987 } else if (ainfo->regtype == RegTypeStructByVal) {
4988 int doffset = inst->inst_offset;
4990 if (ainfo->reg != STK_BASE)
4994 s390_lgr (code, s390_r13, STK_BASE);
4995 s390_aghi (code, s390_r13, alloc_size);
4997 switch (ainfo->size) {
4999 if (ainfo->reg == STK_BASE)
5000 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5001 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5004 if (ainfo->reg == STK_BASE)
5005 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5006 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5009 if (ainfo->reg == STK_BASE)
5010 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5011 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5014 if (ainfo->reg == STK_BASE)
5015 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5016 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5019 } else if (ainfo->regtype == RegTypeStructByAddr) {
5020 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5021 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5023 g_assert_not_reached ();
5028 if (method->save_lmf) {
5029 /*---------------------------------------------------------------*/
5030 /* we build the MonoLMF structure on the stack - see mini-s390.h */
5031 /*---------------------------------------------------------------*/
5032 lmfOffset = alloc_size - sizeof(MonoLMF);
5034 s390_lgr (code, s390_r13, cfg->frame_reg);
5035 s390_aghi (code, s390_r13, lmfOffset);
5037 /*---------------------------------------------------------------*/
5038 /* Preserve the parameter registers while we fix up the lmf */
5039 /*---------------------------------------------------------------*/
5040 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5041 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5043 /*---------------------------------------------------------------*/
5044 /* On return from this call r2 have the address of the &lmf */
5045 /*---------------------------------------------------------------*/
5046 s390_basr(code, s390_r14, 0);
5048 mono_add_patch_info (cfg, code - cfg->native_code,
5049 MONO_PATCH_INFO_INTERNAL_METHOD,
5050 (gpointer)"mono_get_lmf_addr");
5051 s390_llong(code, 0);
5052 s390_lg (code, s390_r1, 0, s390_r14, 4);
5053 s390_basr (code, s390_r14, s390_r1);
5055 /*---------------------------------------------------------------*/
5056 /* Set lmf.lmf_addr = jit_tls->lmf */
5057 /*---------------------------------------------------------------*/
5058 s390_stg (code, s390_r2, 0, s390_r13,
5059 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5061 /*---------------------------------------------------------------*/
5062 /* Get current lmf */
5063 /*---------------------------------------------------------------*/
5064 s390_lg (code, s390_r0, 0, s390_r2, 0);
5066 /*---------------------------------------------------------------*/
5067 /* Set our lmf as the current lmf */
5068 /*---------------------------------------------------------------*/
5069 s390_stg (code, s390_r13, 0, s390_r2, 0);
5071 /*---------------------------------------------------------------*/
5072 /* Have our lmf.previous_lmf point to the last lmf */
5073 /*---------------------------------------------------------------*/
5074 s390_stg (code, s390_r0, 0, s390_r13,
5075 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5077 /*---------------------------------------------------------------*/
5078 /* save method info */
5079 /*---------------------------------------------------------------*/
5080 s390_basr (code, s390_r1, 0);
5082 s390_llong (code, method);
5083 s390_lg (code, s390_r1, 0, s390_r1, 4);
5084 s390_stg (code, s390_r1, 0, s390_r13,
5085 G_STRUCT_OFFSET(MonoLMF, method));
5087 /*---------------------------------------------------------------*/
5088 /* save the current IP */
5089 /*---------------------------------------------------------------*/
5090 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5091 s390_basr (code, s390_r1, 0);
5092 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5094 /*---------------------------------------------------------------*/
5095 /* Save general and floating point registers */
5096 /*---------------------------------------------------------------*/
5097 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5098 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5099 for (i = 0; i < 16; i++) {
5100 s390_std (code, i, 0, s390_r13,
5101 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5104 /*---------------------------------------------------------------*/
5105 /* Restore the parameter registers now that we've set up the lmf */
5106 /*---------------------------------------------------------------*/
5107 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5108 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5112 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5114 cfg->code_len = code - cfg->native_code;
5115 g_assert (cfg->code_len < cfg->code_size);
5120 /*========================= End of Function ========================*/
5122 /*------------------------------------------------------------------*/
5124 /* Name - mono_arch_emit_epilog */
5126 /* Function - Emit the instructions for a function epilog. */
5128 /*------------------------------------------------------------------*/
5131 mono_arch_emit_epilog (MonoCompile *cfg)
5133 MonoMethod *method = cfg->method;
5136 int max_epilog_size = 96;
5138 if (cfg->method->save_lmf)
5139 max_epilog_size += 128;
5141 if (mono_jit_trace_calls != NULL)
5142 max_epilog_size += 128;
5144 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5145 max_epilog_size += 128;
5147 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5148 cfg->code_size *= 2;
5149 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5150 mono_jit_stats.code_reallocs++;
5153 code = cfg->native_code + cfg->code_len;
5155 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5156 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5160 if (method->save_lmf)
5161 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5163 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
5164 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5166 code = backUpStackPtr(cfg, code);
5168 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5169 s390_br (code, s390_r14);
5171 cfg->code_len = code - cfg->native_code;
5173 g_assert (cfg->code_len < cfg->code_size);
5177 /*========================= End of Function ========================*/
5179 /*------------------------------------------------------------------*/
5181 /* Name - mono_arch_emit_exceptions */
5183 /* Function - Emit the blocks to handle exception conditions. */
5185 /*------------------------------------------------------------------*/
5188 mono_arch_emit_exceptions (MonoCompile *cfg)
5190 MonoJumpInfo *patch_info;
5196 MonoClass *exc_classes [MAX_EXC];
5197 guint8 *exc_throw_start [MAX_EXC];
5199 for (patch_info = cfg->patch_info;
5201 patch_info = patch_info->next) {
5202 if (patch_info->type == MONO_PATCH_INFO_EXC)
5206 code_size = exc_count * 48;
5208 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5209 cfg->code_size *= 2;
5210 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5211 mono_jit_stats.code_reallocs++;
5214 code = cfg->native_code + cfg->code_len;
5216 /*---------------------------------------------------------------------*/
5217 /* Add code to raise exceptions */
5218 /*---------------------------------------------------------------------*/
5219 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5220 switch (patch_info->type) {
5221 case MONO_PATCH_INFO_EXC: {
5222 guint8 *ip = patch_info->ip.i + cfg->native_code;
5223 MonoClass *exc_class;
5226 /*-----------------------------------------------------*/
5227 /* Patch the branch in epilog to come here */
5228 /*-----------------------------------------------------*/
5229 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5231 exc_class = mono_class_from_name (mono_defaults.corlib,
5233 patch_info->data.name);
5234 g_assert (exc_class);
5235 throw_ip = patch_info->ip.i;
5237 for (iExc = 0; iExc < nThrows; ++iExc)
5238 if (exc_classes [iExc] == exc_class)
5241 if (iExc < nThrows) {
5242 s390_jcl (code, S390_CC_UN,
5243 (guint64) exc_throw_start [iExc]);
5244 patch_info->type = MONO_PATCH_INFO_NONE;
5247 if (nThrows < MAX_EXC) {
5248 exc_classes [nThrows] = exc_class;
5249 exc_throw_start [nThrows] = code;
5252 /*---------------------------------------------*/
5253 /* Patch the parameter passed to the handler */
5254 /*---------------------------------------------*/
5255 s390_basr (code, s390_r13, 0);
5257 // s390_llong(code, patch_info->data.target);
5258 s390_llong(code, exc_class->type_token);
5259 /*---------------------------------------------*/
5260 /* Load return address & parameter register */
5261 /*---------------------------------------------*/
5262 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5263 cfg->native_code + 8), code));
5264 s390_lg (code, s390_r2, 0, s390_r13, 4);
5265 /*---------------------------------------------*/
5266 /* Reuse the current patch to set the jump */
5267 /*---------------------------------------------*/
5268 s390_basr (code, s390_r13, 0);
5270 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5271 patch_info->data.name = "mono_arch_throw_corlib_exception";
5272 patch_info->ip.i = code - cfg->native_code;
5273 s390_llong(code, 0);
5274 s390_lg (code, s390_r1, 0, s390_r13, 4);
5275 s390_br (code, s390_r1);
5285 cfg->code_len = code - cfg->native_code;
5287 g_assert (cfg->code_len < cfg->code_size);
5291 /*========================= End of Function ========================*/
5293 /*------------------------------------------------------------------*/
5295 /* Name - mono_arch_setup_jit_tls_data */
5297 /* Function - Setup the JIT's Thread Level Specific Data. */
5299 /*------------------------------------------------------------------*/
5302 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5304 if (!tls_offset_inited) {
5305 tls_offset_inited = TRUE;
5309 __asm__ ("\tear\t%r1,0\n"
5316 : "=r" (appdomain_tls_offset),
5317 "=r" (thread_tls_offset),
5318 "=r" (lmf_tls_offset)
5319 : "r" (&tls_appdomain),
5320 "r" (&tls_current_object),
5321 "r" (&mono_lmf_addr)
5327 if (!lmf_addr_key_inited) {
5328 lmf_addr_key_inited = TRUE;
5329 pthread_key_create (&lmf_addr_key, NULL);
5331 pthread_setspecific (lmf_addr_key, &tls->lmf);
5335 /*========================= End of Function ========================*/
5337 /*------------------------------------------------------------------*/
5339 /* Name - mono_arch_free_jit_tls_data */
5341 /* Function - Free tls data. */
5343 /*------------------------------------------------------------------*/
5346 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5350 /*========================= End of Function ========================*/
5352 /*------------------------------------------------------------------*/
5354 /* Name - mono_arch_emit_inst_for_method */
5356 /*------------------------------------------------------------------*/
5359 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5364 /*========================= End of Function ========================*/
5366 /*------------------------------------------------------------------*/
5368 /* Name - mono_arch_decompose_opts */
5370 /* Function - Decompose opcode into a System z opcode. */
5372 /*------------------------------------------------------------------*/
5375 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5378 * Have to rename these to avoid being decomposed normally, since the normal
5379 * decomposition does not work on S390.
5381 switch (ins->opcode) {
5383 ins->opcode = OP_S390_ISUB_OVF;
5385 case OP_ISUB_OVF_UN:
5386 ins->opcode = OP_S390_ISUB_OVF_UN;
5389 ins->opcode = OP_S390_IADD_OVF;
5391 case OP_IADD_OVF_UN:
5392 ins->opcode = OP_S390_IADD_OVF_UN;
5395 ins->opcode = OP_S390_LADD_OVF;
5397 case OP_LADD_OVF_UN:
5398 ins->opcode = OP_S390_LADD_OVF_UN;
5401 ins->opcode = OP_S390_LSUB_OVF;
5403 case OP_LSUB_OVF_UN:
5404 ins->opcode = OP_S390_LSUB_OVF_UN;
5411 /*========================= End of Function ========================*/
5413 /*------------------------------------------------------------------*/
5415 /* Name - mono_arch_print_tree */
5417 /* Function - Print platform-specific opcode details. */
5419 /* Returns - 1 - opcode details have been printed */
5420 /* 0 - opcode details have not been printed */
5422 /*------------------------------------------------------------------*/
5425 mono_arch_print_tree (MonoInst *tree, int arity)
5429 switch (tree->opcode) {
5430 case OP_S390_LOADARG:
5431 case OP_S390_ARGREG:
5432 case OP_S390_ARGPTR:
5433 printf ("[0x%lx(%s)]", tree->inst_offset,
5434 mono_arch_regname (tree->inst_basereg));
5437 case OP_S390_STKARG:
5438 printf ("[0x%lx(previous_frame)]",
5443 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5444 tree->inst_offset, tree->backend.size,
5445 mono_arch_regname(tree->dreg),
5447 mono_arch_regname(tree->sreg1));
5450 case OP_S390_SETF4RET:
5451 printf ("[f%s,f%s]",
5452 mono_arch_regname (tree->dreg),
5453 mono_arch_regname (tree->sreg1));
5457 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5459 mono_arch_regname (tree->sreg1));
5462 case OP_S390_BKCHAIN:
5463 printf ("[previous_frame(%s)]",
5464 mono_arch_regname (tree->sreg1));
5472 /*========================= End of Function ========================*/
5474 /*------------------------------------------------------------------*/
5476 /* Name - mono_arch_regalloc_cost */
5478 /* Function - Determine the cost, in the number of memory */
5479 /* references, of the action of allocating the var- */
5480 /* iable VMV into a register during global register */
5483 /* Returns - Cost */
5485 /*------------------------------------------------------------------*/
5488 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5494 /*========================= End of Function ========================*/
5496 /*------------------------------------------------------------------*/
5498 /* Name - mono_arch_get_domain_intrinsic */
5504 /*------------------------------------------------------------------*/
5507 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5511 if (appdomain_tls_offset == -1)
5514 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5515 ins->inst_offset = appdomain_tls_offset;
5519 /*========================= End of Function ========================*/
5521 /*------------------------------------------------------------------*/
5523 /* Name - mono_arch_flush_register_windows */
5529 /*------------------------------------------------------------------*/
5532 mono_arch_flush_register_windows (void)
5536 /*========================= End of Function ========================*/
5538 /*------------------------------------------------------------------*/
5540 /* Name - mono_arch_get_lmf_addr */
5546 /*------------------------------------------------------------------*/
5549 mono_arch_get_lmf_addr (void)
5551 return pthread_getspecific (lmf_addr_key);
5554 /*========================= End of Function ========================*/
5556 /*------------------------------------------------------------------*/
5558 /* Name - mono_arch_is_inst_imm */
5560 /* Function - Determine if operand qualifies as an immediate */
5561 /* value. For s390 this is a value -32768-32768 */
5563 /* Returns - True|False - is [not] immediate value. */
5565 /*------------------------------------------------------------------*/
5568 mono_arch_is_inst_imm (gint64 imm)
5570 return s390_is_imm16 (imm);
5573 /*========================= End of Function ========================*/
5575 /*------------------------------------------------------------------*/
5577 /* Name - mono_arch_get_patch_offset */
5579 /* Function - Dummy entry point until s390x supports aot. */
5581 /* Returns - Offset for patch. */
5583 /*------------------------------------------------------------------*/
5586 mono_arch_get_patch_offset (guint8 *code)
5591 /*========================= End of Function ========================*/
5593 /*------------------------------------------------------------------*/
5595 /* Name - mono_arch_context_get_int_reg. */
5599 /* Returns - Offset for patch. */
5601 /*------------------------------------------------------------------*/
5604 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5606 /* FIXME: implement */
5607 g_assert_not_reached ();
5611 /*========================= End of Function ========================*/
5613 /*------------------------------------------------------------------*/
5615 /* Name - mono_arch_get_this_arg_from_call. */
5619 /*------------------------------------------------------------------*/
5622 mono_arch_get_this_arg_from_call (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, mgreg_t *regs, guint8 *code)
5624 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5626 /* FIXME: handle returning a struct */
5627 if (MONO_TYPE_ISSTRUCT (sig->ret))
5628 return (gpointer) lmf->gregs [s390_r3];
5629 return (gpointer) lmf->gregs [s390_r2];
5632 /*========================= End of Function ========================*/
5634 /*------------------------------------------------------------------*/
5636 /* Name - get_delegate_invoke_impl. */
5640 /*------------------------------------------------------------------*/
5643 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5645 guint8 *code, *start;
5650 start = code = mono_global_codeman_reserve (size);
5652 /* Replace the this argument with the target */
5653 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5654 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5655 s390_br (code, s390_r1);
5656 g_assert ((code - start) <= size);
5658 mono_arch_flush_icache (start, size);
5662 size = 32 + param_count * 8;
5663 start = code = mono_global_codeman_reserve (size);
5665 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5666 /* slide down the arguments */
5667 for (i = 0; i < param_count; ++i) {
5668 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5670 s390_br (code, s390_r1);
5672 g_assert ((code - start) <= size);
5674 mono_arch_flush_icache (start, size);
5678 *code_len = code - start;
5683 /*========================= End of Function ========================*/
5685 /*------------------------------------------------------------------*/
5687 /* Name - mono_arch_get_delegate_invoke_impls. */
5691 /*------------------------------------------------------------------*/
5694 mono_arch_get_delegate_invoke_impls (void)
5701 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5702 res = g_slist_prepend (res, mono_aot_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len));
5704 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5705 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5706 res = g_slist_prepend (res, mono_aot_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len));
5712 /*========================= End of Function ========================*/
5714 /*------------------------------------------------------------------*/
5716 /* Name - mono_arch_get_delegate_invoke_impl. */
5720 /*------------------------------------------------------------------*/
5723 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5725 guint8 *code, *start;
5727 /* FIXME: Support more cases */
5728 if (MONO_TYPE_ISSTRUCT (sig->ret))
5732 static guint8* cached = NULL;
5738 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5740 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5742 mono_memory_barrier ();
5746 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5749 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5751 for (i = 0; i < sig->param_count; ++i)
5752 if (!mono_is_regsize_var (sig->params [i]))
5756 code = cache [sig->param_count];
5760 if (mono_aot_only) {
5761 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5762 start = mono_aot_get_trampoline (name);
5765 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5768 mono_memory_barrier ();
5770 cache [sig->param_count] = start;
5775 /*========================= End of Function ========================*/
5777 /*------------------------------------------------------------------*/
5779 /* Name - mono_arch_build_imt_thunk. */
5783 /*------------------------------------------------------------------*/
5786 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5787 MonoIMTCheckItem **imt_entries, int count,
5788 gpointer fail_tramp)
5792 guchar *code, *start;
5794 for (i = 0; i < count; ++i) {
5795 MonoIMTCheckItem *item = imt_entries [i];
5796 if (item->is_equals) {
5797 if (item->check_target_idx) {
5798 if (!item->compare_done)
5799 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5800 if (item->has_target_code)
5801 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5803 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5807 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5809 if (!item->has_target_code)
5810 item->chunk_size += LOAD_SIZE;
5812 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5813 #if ENABLE_WRONG_METHOD_CHECK
5814 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5819 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5820 imt_entries [item->check_target_idx]->compare_done = TRUE;
5822 size += item->chunk_size;
5826 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5828 code = mono_domain_code_reserve (domain, size);
5832 for (i = 0; i < count; ++i) {
5833 MonoIMTCheckItem *item = imt_entries [i];
5834 item->code_target = (guint8 *) code;
5835 if (item->is_equals) {
5836 if (item->check_target_idx) {
5837 if (!item->compare_done) {
5838 s390_basr (code, s390_r13, s390_r0);
5840 s390_llong(code, item->key);
5841 s390_lg (code, s390_r0, 0, s390_r13, 4);
5842 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5844 item->jmp_code = (guint8*) code;
5845 s390_jcl (code, S390_CC_NE, 0);
5847 s390_basr (code, s390_r13, s390_r0);
5849 if (item->has_target_code) {
5850 s390_llong(code, item->value.target_code);
5851 s390_lg (code, s390_r1, 0, s390_r13, 4);
5853 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5854 s390_lg (code, s390_r1, 0, s390_r13, 4);
5855 s390_lg (code, s390_r1, 0, s390_r1, 0);
5857 s390_br (code, s390_r1);
5862 s390_basr (code, s390_r13, s390_r0);
5864 s390_llong(code, item->key);
5865 s390_lg (code, s390_r0, 0, s390_r13, 4);
5866 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5867 item->jmp_code = (guint8*) code;
5868 s390_jcl (code, S390_CC_NE, 0);
5869 s390_basr (code, s390_r13, s390_r0);
5871 if (item->has_target_code) {
5872 s390_llong(code, item->value.target_code);
5873 s390_lg (code, s390_r1, 0, s390_r13, 4);
5876 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5877 s390_lg (code, s390_r1, 0, s390_r13, 4);
5878 s390_lg (code, s390_r1, 0, s390_r1, 0);
5880 s390_br (code, s390_r1);
5881 target = S390_RELATIVE(item->jmp_code, code);
5882 s390_patch_rel(item->jmp_code+2, target);
5883 s390_basr (code, s390_r13, s390_r0);
5885 s390_llong(code, fail_tramp);
5886 s390_lg (code, s390_r1, 0, s390_r13, 4);
5887 s390_br (code, s390_r1);
5888 item->jmp_code = NULL;
5890 /* enable the commented code to assert on wrong method */
5891 #if ENABLE_WRONG_METHOD_CHECK
5892 g_assert_not_reached ();
5894 s390_basr (code, s390_r13, s390_r0);
5896 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
5897 s390_lg (code, s390_r1, 0, s390_r13, 4);
5898 s390_lg (code, s390_r1, 0, s390_r1, 0);
5899 s390_br (code, s390_r1);
5900 #if ENABLE_WRONG_METHOD_CHECK
5901 g_assert_not_reached ();
5906 s390_basr (code, s390_r13, s390_r0);
5908 s390_llong(code, item->key);
5909 s390_lg (code, s390_r0, 0, s390_r13, 4);
5910 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5911 item->jmp_code = (guint8 *) code;
5912 s390_jcl (code, S390_CC_GE, 0);
5915 /* patch the branches to get to the target items */
5916 for (i = 0; i < count; ++i) {
5917 MonoIMTCheckItem *item = imt_entries [i];
5918 if (item->jmp_code) {
5919 if (item->check_target_idx) {
5921 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5923 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5928 mono_arch_flush_icache ((guint8*)start, (code - start));
5931 mono_stats.imt_thunks_size += (code - start);
5933 g_assert (code - start <= size);
5938 /*========================= End of Function ========================*/
5940 /*------------------------------------------------------------------*/
5942 /* Name - mono_arch_find_imt_method. */
5944 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5945 /* found in the save area. */
5947 /*------------------------------------------------------------------*/
5950 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5952 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5954 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
5957 /*========================= End of Function ========================*/
5959 /*------------------------------------------------------------------*/
5961 /* Name - mono_arch_find_this_argument. */
5965 /*------------------------------------------------------------------*/
5968 mono_arch_find_this_argument (mgreg_t *regs, MonoMethod *method,
5969 MonoGenericSharingContext *gsctx)
5971 return mono_arch_get_this_arg_from_call (gsctx, mono_method_signature (method), regs, NULL);
5974 /*========================= End of Function ========================*/