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 NOT_IMPLEMENTED(x) \
22 g_error ("FIXME: %s is not yet implemented.", x);
24 #define EMIT_COND_BRANCH(ins,cond) \
26 if (ins->flags & MONO_INST_BRLABEL) { \
27 if (ins->inst_i0->inst_c0) { \
29 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
30 if (s390_is_imm16(displace)) { \
31 s390_brc (code, cond, displace); \
33 s390_jcl (code, cond, displace); \
36 mono_add_patch_info (cfg, code - cfg->native_code, \
37 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
38 s390_jcl (code, cond, 0); \
41 if (ins->inst_true_bb->native_offset) { \
43 displace = ((cfg->native_code + \
44 ins->inst_true_bb->native_offset) - code) / 2; \
45 if (s390_is_imm16(displace)) { \
46 s390_brc (code, cond, displace); \
48 s390_jcl (code, cond, displace); \
51 mono_add_patch_info (cfg, code - cfg->native_code, \
52 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
53 s390_jcl (code, cond, 0); \
58 #define EMIT_UNCOND_BRANCH(ins) \
60 if (ins->flags & MONO_INST_BRLABEL) { \
61 if (ins->inst_i0->inst_c0) { \
63 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
64 if (s390_is_imm16(displace)) { \
65 s390_brc (code, S390_CC_UN, displace); \
67 s390_jcl (code, S390_CC_UN, displace); \
70 mono_add_patch_info (cfg, code - cfg->native_code, \
71 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
72 s390_jcl (code, S390_CC_UN, 0); \
75 if (ins->inst_target_bb->native_offset) { \
77 displace = ((cfg->native_code + \
78 ins->inst_target_bb->native_offset) - code) / 2; \
79 if (s390_is_imm16(displace)) { \
80 s390_brc (code, S390_CC_UN, displace); \
82 s390_jcl (code, S390_CC_UN, displace); \
85 mono_add_patch_info (cfg, code - cfg->native_code, \
86 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
87 s390_jcl (code, S390_CC_UN, 0); \
92 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
94 mono_add_patch_info (cfg, code - cfg->native_code, \
95 MONO_PATCH_INFO_EXC, exc_name); \
96 s390_jcl (code, cond, 0); \
99 #define CHECK_SRCDST_COM \
100 if (ins->dreg == ins->sreg2) { \
104 if (ins->dreg != ins->sreg1) { \
105 s390_lgr (code, ins->dreg, ins->sreg1); \
109 #define CHECK_SRCDST_NCOM \
110 if (ins->dreg == ins->sreg2) { \
112 s390_lgr (code, s390_r13, ins->sreg2); \
116 if (ins->dreg != ins->sreg1) { \
117 s390_lgr (code, ins->dreg, ins->sreg1); \
120 #define CHECK_SRCDST_COM_I \
121 if (ins->dreg == ins->sreg2) { \
125 if (ins->dreg != ins->sreg1) { \
126 s390_lgfr (code, ins->dreg, ins->sreg1); \
130 #define CHECK_SRCDST_NCOM_I \
131 if (ins->dreg == ins->sreg2) { \
133 s390_lgfr (code, s390_r13, ins->sreg2); \
137 if (ins->dreg != ins->sreg1) { \
138 s390_lgfr (code, ins->dreg, ins->sreg1); \
141 #define CHECK_SRCDST_COM_F \
142 if (ins->dreg == ins->sreg2) { \
146 if (ins->dreg != ins->sreg1) { \
147 s390_ldr (code, ins->dreg, ins->sreg1); \
151 #define CHECK_SRCDST_NCOM_F \
152 if (ins->dreg == ins->sreg2) { \
154 s390_ldr (code, s390_r13, ins->sreg2); \
158 if (ins->dreg != ins->sreg1) { \
159 s390_ldr (code, ins->dreg, ins->sreg1); \
163 #define DEBUG(a) if (cfg->verbose_level > 1) a
167 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
169 #define MAX (a, b) ((a) > (b) ? (a) : (b))
171 /*========================= End of Defines =========================*/
173 /*------------------------------------------------------------------*/
174 /* I n c l u d e s */
175 /*------------------------------------------------------------------*/
180 #include <mono/metadata/appdomain.h>
181 #include <mono/metadata/debug-helpers.h>
182 #include <mono/metadata/profiler-private.h>
183 #include <mono/utils/mono-math.h>
185 #include "mini-s390x.h"
187 #include "cpu-s390x.h"
189 /*========================= End of Includes ========================*/
191 /*------------------------------------------------------------------*/
192 /* T y p e d e f s */
193 /*------------------------------------------------------------------*/
224 /*------------------------------------------------------------------*/
225 /* Used by the instrument_emit_epilog */
226 /*------------------------------------------------------------------*/
237 typedef struct InstList InstList;
254 gint32 offset; /* offset from caller's stack */
255 gint32 offparm; /* offset from callee's stack */
256 guint16 vtsize; /* in param area */
258 guint8 regtype; /* See RegType* */
259 guint32 size; /* Size of structure used by RegTypeStructByVal */
260 gint32 type; /* Data type of argument */
274 gint64 gr[5]; /* R2-R6 */
275 gdouble fp[3]; /* F0-F2 */
276 } __attribute__ ((packed)) RegParm;
278 /*========================= End of Typedefs ========================*/
280 /*------------------------------------------------------------------*/
281 /* P r o t o t y p e s */
282 /*------------------------------------------------------------------*/
284 static void indent (int);
285 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
286 static void decodeParm (MonoType *, void *, int);
287 static void enter_method (MonoMethod *, RegParm *, char *);
288 static void leave_method (MonoMethod *, ...);
289 static gboolean is_regsize_var (MonoType *);
290 static inline void add_general (guint *, size_data *, ArgInfo *);
291 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
292 static inline void add_float (guint *, size_data *, ArgInfo *);
293 static CallInfo * calculate_sizes (MonoMethodSignature *, size_data *, gboolean);
294 static void peephole_pass (MonoCompile *, MonoBasicBlock *);
295 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
296 static void mono_arch_break(void);
297 gpointer mono_arch_get_lmf_addr (void);
298 static guint8 * emit_load_volatile_registers (guint8 *, MonoCompile *);
299 static CompRelation opcode_to_cond (int);
300 static void catch_SIGILL(int, siginfo_t *, void *);
301 static void emit_sig_cookie (MonoCompile *, MonoCallInst *, CallInfo *, int);
303 /*========================= End of Prototypes ======================*/
305 /*------------------------------------------------------------------*/
306 /* G l o b a l V a r i a b l e s */
307 /*------------------------------------------------------------------*/
309 int mono_exc_esp_offset = 0;
311 static int indent_level = 0;
315 static gboolean tls_offset_inited = FALSE;
317 static int appdomain_tls_offset = -1,
319 thread_tls_offset = -1;
321 pthread_key_t lmf_addr_key;
323 gboolean lmf_addr_key_inited = FALSE;
327 extern __thread MonoDomain *tls_appdomain;
328 extern __thread MonoThread *tls_current_object;
329 extern __thread gpointer mono_lmf_addr;
333 /*====================== End of Global Variables ===================*/
335 /*------------------------------------------------------------------*/
337 /* Name - mono_arch_regname */
339 /* Function - Returns the name of the register specified by */
340 /* the input parameter. */
342 /*------------------------------------------------------------------*/
345 mono_arch_regname (int reg) {
346 static const char * rnames[] = {
347 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
348 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
349 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
353 if (reg >= 0 && reg < 16)
359 /*========================= End of Function ========================*/
361 /*------------------------------------------------------------------*/
363 /* Name - mono_arch_fregname */
365 /* Function - Returns the name of the register specified by */
366 /* the input parameter. */
368 /*------------------------------------------------------------------*/
371 mono_arch_fregname (int reg) {
372 static const char * rnames[] = {
373 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
374 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
375 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
379 if (reg >= 0 && reg < 16)
385 /*========================= End of Function ========================*/
387 /*------------------------------------------------------------------*/
389 /* Name - arch_get_argument_info */
391 /* Function - Gathers information on parameters such as size, */
392 /* alignment, and padding. arg_info should be large */
393 /* enough to hold param_count + 1 entries. */
395 /* Parameters - @csig - Method signature */
396 /* @param_count - No. of parameters to consider */
397 /* @arg_info - An array to store the result info */
399 /* Returns - Size of the activation frame */
401 /*------------------------------------------------------------------*/
404 mono_arch_get_argument_info (MonoMethodSignature *csig,
406 MonoJitArgumentInfo *arg_info)
408 int k, frame_size = 0;
409 int size, align, pad;
412 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
413 frame_size += sizeof (gpointer);
417 arg_info [0].offset = offset;
420 frame_size += sizeof (gpointer);
424 arg_info [0].size = frame_size;
426 for (k = 0; k < param_count; k++) {
429 size = mono_type_native_stack_size (csig->params [k], &align);
431 size = mono_type_stack_size (csig->params [k], &align);
433 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
434 arg_info [k].pad = pad;
436 arg_info [k + 1].pad = 0;
437 arg_info [k + 1].size = size;
439 arg_info [k + 1].offset = offset;
443 align = MONO_ARCH_FRAME_ALIGNMENT;
444 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
445 arg_info [k].pad = pad;
450 /*========================= End of Function ========================*/
452 /*------------------------------------------------------------------*/
454 /* Name - retFitsInReg. */
456 /* Function - Determines if a value can be returned in one or */
459 /*------------------------------------------------------------------*/
461 static inline gboolean
462 retFitsInReg(guint32 size)
477 /*========================= End of Function ========================*/
479 /*------------------------------------------------------------------*/
481 /* Name - backStackPtr. */
483 /* Function - Restore Stack Pointer to previous frame. */
485 /*------------------------------------------------------------------*/
487 static inline guint8 *
488 backUpStackPtr(MonoCompile *cfg, guint8 *code)
490 int stackSize = cfg->stack_usage;
492 if (s390_is_uimm16 (stackSize)) {
493 s390_aghi (code, STK_BASE, stackSize);
495 while (stackSize > 32767) {
496 s390_aghi (code, STK_BASE, 32767);
499 s390_aghi (code, STK_BASE, stackSize);
504 /*========================= End of Function ========================*/
506 /*------------------------------------------------------------------*/
510 /* Function - Perform nice indenting to current level */
512 /*------------------------------------------------------------------*/
518 indent_level += diff;
525 indent_level += diff;
528 /*========================= End of Function ========================*/
530 /*------------------------------------------------------------------*/
532 /* Name - decodeParm */
534 /* Function - Decode a parameter for the trace. */
536 /*------------------------------------------------------------------*/
539 decodeParm(MonoType *type, void *curParm, int size)
544 printf("[BYREF:%p], ", *((char **) curParm));
546 simpleType = mono_type_get_underlying_type(type)->type;
548 switch (simpleType) {
550 printf ("[INTPTR:%p], ", *((int **) curParm));
553 printf ("[UINTPTR:%p], ", *((int **) curParm));
555 case MONO_TYPE_BOOLEAN :
556 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
558 case MONO_TYPE_CHAR :
559 printf ("[CHAR:%c], ", *((int *) curParm));
562 printf ("[INT1:%ld], ", *((gint64 *) curParm));
565 printf ("[INT2:%ld], ", *((gint64 *) curParm));
568 printf ("[INT4:%ld], ", *((gint64 *) curParm));
571 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
574 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
577 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
580 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
582 case MONO_TYPE_STRING : {
583 MonoString *s = *((MonoString **) curParm);
585 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
586 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
588 printf("[STRING:null], ");
592 case MONO_TYPE_CLASS :
593 case MONO_TYPE_OBJECT : {
594 MonoObject *obj = *((MonoObject **) curParm);
596 if ((obj) && (obj->vtable)) {
597 printf("[CLASS/OBJ:");
598 class = obj->vtable->klass;
599 printf("%p [%p] ",obj,curParm);
600 if (class == mono_defaults.string_class) {
601 printf("[STRING:%p:%s]",
602 obj, mono_string_to_utf8 ((MonoString *) obj));
603 } else if (class == mono_defaults.int32_class) {
604 printf("[INT32:%p:%d]",
605 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
608 class->name_space, class->name, obj);
611 printf("[OBJECT:null], ");
616 printf("[PTR:%p], ", *((gpointer **) (curParm)));
618 case MONO_TYPE_FNPTR :
619 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
621 case MONO_TYPE_ARRAY :
622 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
624 case MONO_TYPE_SZARRAY :
625 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
628 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
631 printf("[FLOAT4:%g], ", *((float *) (curParm)));
634 printf("[FLOAT8:%g], ", *((double *) (curParm)));
636 case MONO_TYPE_VALUETYPE : {
638 MonoMarshalType *info;
640 if (type->data.klass->enumtype) {
641 simpleType = type->data.klass->enum_basetype->type;
642 printf("{VALUETYPE} - ");
646 info = mono_marshal_load_type_info (type->data.klass);
648 if ((info->native_size == sizeof(float)) &&
649 (info->num_fields == 1) &&
650 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
651 printf("[FLOAT4:%f], ", *((float *) (curParm)));
655 if ((info->native_size == sizeof(double)) &&
656 (info->num_fields == 1) &&
657 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
658 printf("[FLOAT8:%g], ", *((double *) (curParm)));
662 printf("[VALUETYPE:");
663 for (i = 0; i < size; i++)
664 printf("%02x,", *((guint8 *)curParm+i));
668 case MONO_TYPE_TYPEDBYREF: {
670 printf("[TYPEDBYREF:");
671 for (i = 0; i < size; i++)
672 printf("%02x,", *((guint8 *)curParm+i));
677 printf("[?? - %d], ",simpleType);
682 /*========================= End of Function ========================*/
684 /*------------------------------------------------------------------*/
686 /* Name - enter_method */
688 /* Function - Perform tracing of the entry to the current */
691 /*------------------------------------------------------------------*/
694 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
696 int i, oParm = 0, iParm = 0;
699 MonoMethodSignature *sig;
707 fname = mono_method_full_name (method, TRUE);
709 printf ("ENTER: %s ", fname);
712 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
713 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
718 sig = mono_method_signature (method);
720 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
722 if (cinfo->struct_ret) {
723 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
728 gpointer *this = (gpointer *) rParm->gr[iParm];
729 obj = (MonoObject *) this;
730 if (method->klass->valuetype) {
732 printf("this:[value:%p:%016lx], ",
733 this, *((guint64 *)(this+sizeof(MonoObject))));
735 printf ("this:[NULL], ");
738 class = obj->vtable->klass;
739 if (class == mono_defaults.string_class) {
740 printf ("this:[STRING:%p:%s], ",
741 obj, mono_string_to_utf8 ((MonoString *)obj));
743 printf ("this:%p[%s.%s], ",
744 obj, class->name_space, class->name);
747 printf ("this:NULL, ");
752 for (i = 0; i < sig->param_count; ++i) {
753 ainfo = &cinfo->args[i + oParm];
754 switch (ainfo->regtype) {
755 case RegTypeGeneral :
756 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
759 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
762 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
764 case RegTypeStructByVal :
765 if (ainfo->reg != STK_BASE) {
766 int offset = sizeof(glong) - ainfo->size;
767 curParm = &(rParm->gr[ainfo->reg-2])+offset;
770 curParm = sp+ainfo->offset;
772 if (retFitsInReg (ainfo->vtsize))
773 decodeParm(sig->params[i],
777 decodeParm(sig->params[i],
778 *((char **) curParm),
781 case RegTypeStructByAddr :
782 if (ainfo->reg != STK_BASE)
783 curParm = &(rParm->gr[ainfo->reg-2]);
785 curParm = sp+ainfo->offset;
787 decodeParm(sig->params[i],
788 *((char **) curParm),
800 /*========================= End of Function ========================*/
802 /*------------------------------------------------------------------*/
804 /* Name - leave_method */
808 /*------------------------------------------------------------------*/
811 leave_method (MonoMethod *method, ...)
818 va_start(ap, method);
820 fname = mono_method_full_name (method, TRUE);
822 printf ("LEAVE: %s", fname);
825 type = mono_method_signature (method)->ret;
828 switch (type->type) {
831 case MONO_TYPE_BOOLEAN: {
832 int val = va_arg (ap, int);
834 printf ("[TRUE:%d]", val);
840 case MONO_TYPE_CHAR: {
841 int val = va_arg (ap, int);
842 printf ("[CHAR:%d]", val);
846 int val = va_arg (ap, int);
847 printf ("[INT1:%d]", val);
851 int val = va_arg (ap, int);
852 printf ("[UINT1:%d]", val);
856 int val = va_arg (ap, int);
857 printf ("[INT2:%d]", val);
861 int val = va_arg (ap, int);
862 printf ("[UINT2:%d]", val);
866 int val = va_arg (ap, int);
867 printf ("[INT4:%d]", val);
871 int val = va_arg (ap, int);
872 printf ("[UINT4:%d]", val);
876 gint64 val = va_arg (ap, gint64);
877 printf ("[INT:%ld]", val);
882 gint64 val = va_arg (ap, gint64);
883 printf ("[UINT:%lu]", val);
887 case MONO_TYPE_STRING: {
888 MonoString *s = va_arg (ap, MonoString *);
891 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
892 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
894 printf ("[STRING:null], ");
897 case MONO_TYPE_CLASS:
898 case MONO_TYPE_OBJECT: {
899 MonoObject *o = va_arg (ap, MonoObject *);
901 if ((o) && (o->vtable)) {
902 if (o->vtable->klass == mono_defaults.boolean_class) {
903 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
904 } else if (o->vtable->klass == mono_defaults.int32_class) {
905 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
906 } else if (o->vtable->klass == mono_defaults.int64_class) {
907 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
909 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
911 printf ("[OBJECT:%p]", o);
916 case MONO_TYPE_FNPTR:
917 case MONO_TYPE_ARRAY:
918 case MONO_TYPE_SZARRAY: {
919 gpointer p = va_arg (ap, gpointer);
920 printf ("[result=%p]", p);
924 gint64 l = va_arg (ap, gint64);
925 printf ("[LONG:%ld]", l);
929 guint64 l = va_arg (ap, guint64);
930 printf ("[ULONG:%lu]", l);
934 double f = va_arg (ap, double);
935 printf ("[FLOAT4:%g]\n", f);
939 double f = va_arg (ap, double);
940 printf ("[FLOAT8:%g]\n", f);
943 case MONO_TYPE_VALUETYPE: {
944 MonoMarshalType *info;
945 if (type->data.klass->enumtype) {
946 type = type->data.klass->enum_basetype;
949 guint8 *p = va_arg (ap, gpointer);
952 info = mono_marshal_load_type_info (type->data.klass);
954 if ((info->native_size == sizeof(float)) &&
955 (info->num_fields == 1) &&
956 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
957 double f = va_arg (ap, double);
958 printf("[FLOAT4:%g]\n", (double) f);
962 if ((info->native_size == sizeof(double)) &&
963 (info->num_fields == 1) &&
964 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
965 double f = va_arg (ap, double);
966 printf("[FLOAT8:%g]\n", f);
970 size = mono_type_size (type, &align);
977 for (j = 0; p && j < size; j++)
978 printf ("%02x,", p [j]);
982 printf ("[VALUETYPE]\n");
987 case MONO_TYPE_TYPEDBYREF: {
988 guint8 *p = va_arg (ap, gpointer);
990 size = mono_type_size (type, &align);
997 for (j = 0; p && j < size; j++)
998 printf ("%02x,", p [j]);
1002 printf ("[TYPEDBYREF]\n");
1007 printf ("(unknown return type %x)",
1008 mono_method_signature (method)->ret->type);
1011 ip = ((gint64) __builtin_return_address (0));
1012 printf (" ip: %p\n", (gpointer) ip);
1015 /*========================= End of Function ========================*/
1017 /*------------------------------------------------------------------*/
1019 /* Name - catch_SIGILL */
1021 /* Function - Catch SIGILL as a result of testing for long */
1022 /* displacement facility. */
1024 /*------------------------------------------------------------------*/
1027 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1033 /*========================= End of Function ========================*/
1035 /*------------------------------------------------------------------*/
1037 /* Name - mono_arch_cpu_init */
1039 /* Function - Perform CPU specific initialization to execute */
1042 /*------------------------------------------------------------------*/
1045 mono_arch_cpu_init (void)
1047 struct sigaction sa,
1051 /*--------------------------------------*/
1052 /* Set default rounding mode for FP */
1053 /*--------------------------------------*/
1054 __asm__ ("SRNM\t%0\n\t"
1057 /*--------------------------------------*/
1058 /* Determine if we have long displace- */
1059 /* ment facility on this processor */
1060 /*--------------------------------------*/
1061 sa.sa_sigaction = catch_SIGILL;
1062 sigemptyset (&sa.sa_mask);
1063 sa.sa_flags = SA_SIGINFO;
1065 sigaction (SIGILL, &sa, oldSa);
1067 /*--------------------------------------*/
1068 /* We test by executing the STY inst */
1069 /*--------------------------------------*/
1070 __asm__ ("LGHI\t0,1\n\t"
1072 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1073 : "=m" (has_ld) : : "0", "1");
1075 sigaction (SIGILL, oldSa, NULL);
1078 /*========================= End of Function ========================*/
1080 /*------------------------------------------------------------------*/
1082 /* Name - mono_arch_cpu_optimizazions */
1084 /* Function - Returns the optimizations supported on this CPU */
1086 /*------------------------------------------------------------------*/
1089 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1093 /*----------------------------------------------------------*/
1094 /* No s390-specific optimizations yet */
1095 /*----------------------------------------------------------*/
1096 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1097 // *exclude_mask = MONO_OPT_INLINE;
1101 /*========================= End of Function ========================*/
1103 /*------------------------------------------------------------------*/
1109 /*------------------------------------------------------------------*/
1112 is_regsize_var (MonoType *t) {
1115 switch (mono_type_get_underlying_type (t)->type) {
1123 case MONO_TYPE_FNPTR:
1125 case MONO_TYPE_OBJECT:
1126 case MONO_TYPE_STRING:
1127 case MONO_TYPE_CLASS:
1128 case MONO_TYPE_SZARRAY:
1129 case MONO_TYPE_ARRAY:
1131 case MONO_TYPE_VALUETYPE:
1132 if (t->data.klass->enumtype)
1133 return is_regsize_var (t->data.klass->enum_basetype);
1139 /*========================= End of Function ========================*/
1141 /*------------------------------------------------------------------*/
1143 /* Name - mono_arch_get_allocatable_int_vars */
1147 /*------------------------------------------------------------------*/
1150 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1155 for (i = 0; i < cfg->num_varinfo; i++) {
1156 MonoInst *ins = cfg->varinfo [i];
1157 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1160 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1163 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1164 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1167 /* we can only allocate 32 bit values */
1168 if (is_regsize_var (ins->inst_vtype)) {
1169 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1170 g_assert (i == vmv->idx);
1171 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1178 /*========================= End of Function ========================*/
1180 /*------------------------------------------------------------------*/
1182 /* Name - mono_arch_global_int_regs */
1184 /* Function - Return a list of usable integer registers. */
1186 /*------------------------------------------------------------------*/
1189 mono_arch_get_global_int_regs (MonoCompile *cfg)
1192 MonoMethodHeader *header;
1195 header = mono_method_get_header (cfg->method);
1196 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1197 cfg->frame_reg = s390_r11;
1199 for (i = 8; i < top; ++i) {
1200 if (cfg->frame_reg != i)
1201 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1207 /*========================= End of Function ========================*/
1209 /*------------------------------------------------------------------*/
1211 /* Name - mono_arch_flush_icache */
1213 /* Function - Flush the CPU icache. */
1215 /*------------------------------------------------------------------*/
1218 mono_arch_flush_icache (guint8 *code, gint size)
1222 /*========================= End of Function ========================*/
1224 /*------------------------------------------------------------------*/
1226 /* Name - add_general */
1228 /* Function - Determine code and stack size incremements for a */
1231 /*------------------------------------------------------------------*/
1234 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1236 if (*gr > S390_LAST_ARG_REG) {
1237 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1238 ainfo->offset = sz->stack_size;
1239 ainfo->reg = STK_BASE;
1240 ainfo->regtype = RegTypeBase;
1241 sz->stack_size += sizeof(long);
1242 sz->local_size += sizeof(long);
1243 sz->offStruct += sizeof(long);
1244 sz->code_size += 12;
1252 /*========================= End of Function ========================*/
1254 /*------------------------------------------------------------------*/
1256 /* Name - add_stackParm */
1258 /* Function - Determine code and stack size incremements for a */
1261 /*------------------------------------------------------------------*/
1264 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1266 if (*gr > S390_LAST_ARG_REG) {
1267 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1268 ainfo->reg = STK_BASE;
1269 sz->stack_size += sizeof(gpointer);
1270 sz->offStruct += sizeof(gpointer);
1275 ainfo->offset = sz->stack_size;
1276 ainfo->offparm = sz->offset;
1277 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1279 ainfo->regtype = RegTypeStructByAddr;
1280 ainfo->vtsize = size;
1281 sz->parm_size += size;
1284 /*========================= End of Function ========================*/
1286 /*------------------------------------------------------------------*/
1288 /* Name - add_float */
1290 /* Function - Determine code and stack size incremements for a */
1291 /* float parameter. */
1293 /*------------------------------------------------------------------*/
1296 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1298 if ((*fr) <= S390_LAST_FPARG_REG) {
1299 ainfo->regtype = RegTypeFP;
1305 ainfo->offset = sz->stack_size;
1306 ainfo->reg = STK_BASE;
1307 ainfo->regtype = RegTypeBase;
1309 sz->stack_size += sizeof(double);
1310 sz->local_size += sizeof(double);
1311 sz->offStruct += sizeof(double);
1315 /*========================= End of Function ========================*/
1317 /*------------------------------------------------------------------*/
1319 /* Name - calculate_sizes */
1321 /* Function - Determine the amount of space required for code */
1322 /* and stack. In addition determine starting points */
1323 /* for stack-based parameters, and area for struct- */
1324 /* ures being returned on the stack. */
1326 /*------------------------------------------------------------------*/
1329 calculate_sizes (MonoMethodSignature *sig, size_data *sz,
1330 gboolean string_ctor)
1332 guint i, fr, gr, size;
1333 int nParm = sig->hasthis + sig->param_count;
1334 guint32 simpletype, align;
1335 CallInfo *cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1340 cinfo->struct_ret = 0;
1343 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1344 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1349 /*----------------------------------------------------------*/
1350 /* We determine the size of the return code/stack in case we*/
1351 /* need to reserve a register to be used to address a stack */
1352 /* area that the callee will use. */
1353 /*----------------------------------------------------------*/
1355 simpletype = mono_type_get_underlying_type (sig->ret)->type;
1357 switch (simpletype) {
1358 case MONO_TYPE_BOOLEAN:
1363 case MONO_TYPE_CHAR:
1368 case MONO_TYPE_CLASS:
1369 case MONO_TYPE_OBJECT:
1370 case MONO_TYPE_SZARRAY:
1371 case MONO_TYPE_ARRAY:
1373 case MONO_TYPE_FNPTR:
1374 case MONO_TYPE_STRING:
1375 cinfo->ret.reg = s390_r2;
1380 cinfo->ret.reg = s390_f0;
1385 cinfo->ret.reg = s390_r2;
1388 case MONO_TYPE_GENERICINST:
1389 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1390 cinfo->ret.reg = s390_r2;
1395 case MONO_TYPE_VALUETYPE: {
1396 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1397 if (sig->ret->data.klass->enumtype) {
1398 simpletype = sig->ret->data.klass->enum_basetype->type;
1402 size = mono_class_native_size (klass, &align);
1404 size = mono_class_value_size (klass, &align);
1406 cinfo->ret.reg = s390_r2;
1407 cinfo->struct_ret = 1;
1408 cinfo->ret.size = size;
1409 cinfo->ret.vtsize = size;
1413 case MONO_TYPE_TYPEDBYREF:
1414 size = sizeof (MonoTypedRef);
1415 cinfo->ret.reg = s390_r2;
1416 cinfo->struct_ret = 1;
1417 cinfo->ret.size = size;
1418 cinfo->ret.vtsize = size;
1421 case MONO_TYPE_VOID:
1424 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1428 cinfo->args[nParm].size = sizeof(gpointer);
1429 add_general (&gr, sz, cinfo->args+nParm);
1433 /*----------------------------------------------------------*/
1434 /* We determine the size of the parameter code and stack */
1435 /* requirements by checking the types and sizes of the */
1437 /*----------------------------------------------------------*/
1439 for (i = 0; i < sig->param_count; ++i) {
1440 /*--------------------------------------------------*/
1441 /* Handle vararg type calls. All args are put on */
1443 /*--------------------------------------------------*/
1444 if ((sig->call_convention == MONO_CALL_VARARG) &&
1445 (i == sig->sentinelpos)) {
1446 gr = S390_LAST_ARG_REG + 1;
1447 add_general (&gr, sz, &cinfo->sigCookie);
1450 if (sig->params [i]->byref) {
1451 add_general (&gr, sz, cinfo->args+nParm);
1452 cinfo->args[nParm].size = sizeof(gpointer);
1457 simpletype = mono_type_get_underlying_type(sig->params [i])->type;
1458 cinfo->args[nParm].type = simpletype;
1459 switch (simpletype) {
1460 case MONO_TYPE_BOOLEAN:
1463 cinfo->args[nParm].size = sizeof(char);
1464 add_general (&gr, sz, cinfo->args+nParm);
1469 case MONO_TYPE_CHAR:
1470 cinfo->args[nParm].size = sizeof(short);
1471 add_general (&gr, sz, cinfo->args+nParm);
1476 cinfo->args[nParm].size = sizeof(int);
1477 add_general (&gr, sz, cinfo->args+nParm);
1483 case MONO_TYPE_FNPTR:
1484 case MONO_TYPE_CLASS:
1485 case MONO_TYPE_OBJECT:
1486 case MONO_TYPE_STRING:
1487 case MONO_TYPE_SZARRAY:
1488 case MONO_TYPE_ARRAY:
1489 cinfo->args[nParm].size = sizeof(gpointer);
1490 add_general (&gr, sz, cinfo->args+nParm);
1495 cinfo->args[nParm].size = sizeof(long long);
1496 add_general (&gr, sz, cinfo->args+nParm);
1500 cinfo->args[nParm].size = sizeof(float);
1501 add_float (&fr, sz, cinfo->args+nParm);
1505 cinfo->args[nParm].size = sizeof(double);
1506 add_float (&fr, sz, cinfo->args+nParm);
1509 case MONO_TYPE_GENERICINST:
1510 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1511 cinfo->args[nParm].size = sizeof(gpointer);
1512 add_general (&gr, sz, cinfo->args+nParm);
1517 case MONO_TYPE_VALUETYPE: {
1518 MonoMarshalType *info;
1519 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1521 size = mono_class_native_size (klass, &align);
1523 size = mono_class_value_size (klass, &align);
1525 info = mono_marshal_load_type_info (klass);
1527 if ((info->native_size == sizeof(float)) &&
1528 (info->num_fields == 1) &&
1529 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1530 cinfo->args[nParm].size = sizeof(float);
1531 add_float(&fr, sz, cinfo->args+nParm);
1535 if ((info->native_size == sizeof(double)) &&
1536 (info->num_fields == 1) &&
1537 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1538 cinfo->args[nParm].size = sizeof(double);
1539 add_float(&fr, sz, cinfo->args+nParm);
1543 cinfo->args[nParm].vtsize = 0;
1544 cinfo->args[nParm].size = 0;
1547 /*----------------------------------*/
1548 /* On S/390, structures of size 1, */
1549 /* 2, 4, and 8 bytes are passed in */
1550 /* (a) register(s). */
1551 /*----------------------------------*/
1557 add_general(&gr, sz, cinfo->args+nParm);
1558 cinfo->args[nParm].size = size;
1559 cinfo->args[nParm].regtype = RegTypeStructByVal;
1561 sz->local_size += sizeof(long);
1564 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1569 case MONO_TYPE_TYPEDBYREF: {
1570 int size = sizeof (MonoTypedRef);
1572 cinfo->args[nParm].vtsize = 0;
1573 cinfo->args[nParm].size = 0;
1576 /*----------------------------------*/
1577 /* On S/390, structures of size 1, */
1578 /* 2, 4, and 8 bytes are passed in */
1579 /* (a) register(s). */
1580 /*----------------------------------*/
1586 add_general(&gr, sz, cinfo->args+nParm);
1587 cinfo->args[nParm].size = size;
1588 cinfo->args[nParm].regtype = RegTypeStructByVal;
1590 sz->local_size += sizeof(long);
1593 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1599 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1603 /*----------------------------------------------------------*/
1604 /* Handle the case where there are no implicit arguments */
1605 /*----------------------------------------------------------*/
1606 if ((sig->call_convention == MONO_CALL_VARARG) &&
1607 (sig->param_count == sig->sentinelpos)) {
1608 gr = S390_LAST_ARG_REG + 1;
1609 add_general (&gr, sz, &cinfo->sigCookie);
1612 /*----------------------------------------------------------*/
1613 /* If we are passing a structure back then if it won't be */
1614 /* in a register(s) then we make room at the end of the */
1615 /* parameters that may have been placed on the stack */
1616 /*----------------------------------------------------------*/
1617 if (cinfo->struct_ret) {
1618 cinfo->ret.offset = sz->stack_size;
1619 switch (cinfo->ret.size) {
1627 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1632 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1634 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1639 /*========================= End of Function ========================*/
1641 /*------------------------------------------------------------------*/
1643 /* Name - mono_arch_allocate_vars */
1645 /* Function - Set var information according to the calling */
1646 /* convention for S/390. The local var stuff should */
1647 /* most likely be split in another method. */
1649 /* Parameter - @m - Compile unit. */
1651 /*------------------------------------------------------------------*/
1654 mono_arch_allocate_vars (MonoCompile *cfg)
1656 MonoMethodSignature *sig;
1657 MonoMethodHeader *header;
1661 int iParm, iVar, offset, size, align, curinst;
1662 int frame_reg = STK_BASE;
1665 header = mono_method_get_header (cfg->method);
1667 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1669 /*---------------------------------------------------------*/
1670 /* We use the frame register also for any method that has */
1671 /* filter clauses. This way, when the handlers are called, */
1672 /* the code will reference local variables using the frame */
1673 /* reg instead of the stack pointer: if we had to restore */
1674 /* the stack pointer, we'd corrupt the method frames that */
1675 /* are already on the stack (since filters get called */
1676 /* before stack unwinding happens) when the filter code */
1677 /* would call any method. */
1678 /*---------------------------------------------------------*/
1679 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1680 frame_reg = s390_r11;
1682 cfg->frame_reg = frame_reg;
1684 if (frame_reg != STK_BASE)
1685 cfg->used_int_regs |= 1 << frame_reg;
1687 sig = mono_method_signature (cfg->method);
1689 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1691 if (cinfo->struct_ret) {
1692 cfg->ret->opcode = OP_REGVAR;
1693 cfg->ret->inst_c0 = s390_r2;
1695 switch (mono_type_get_underlying_type (sig->ret)->type) {
1696 case MONO_TYPE_VOID:
1699 cfg->ret->opcode = OP_REGVAR;
1700 cfg->ret->dreg = s390_r2;
1705 /*--------------------------------------------------------------*/
1706 /* local vars are at a positive offset from the stack pointer */
1707 /* also note that if the function uses alloca, we use s390_r11 */
1708 /* to point at the local variables. */
1709 /* add parameter area size for called functions */
1710 /*--------------------------------------------------------------*/
1711 offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
1712 cfg->sig_cookie = 0;
1714 if (cinfo->struct_ret) {
1716 offset = S390_ALIGN(offset, sizeof(gpointer));
1717 inst->inst_offset = offset;
1718 inst->opcode = OP_REGOFFSET;
1719 inst->inst_basereg = frame_reg;
1720 offset += sizeof(gpointer);
1721 if ((sig->call_convention == MONO_CALL_VARARG) &&
1722 (!retFitsInReg (cinfo->ret.size)))
1723 cfg->sig_cookie += cinfo->ret.size;
1727 inst = cfg->varinfo [0];
1728 if (inst->opcode != OP_REGVAR) {
1729 inst->opcode = OP_REGOFFSET;
1730 inst->inst_basereg = frame_reg;
1731 offset = S390_ALIGN(offset, sizeof(gpointer));
1732 inst->inst_offset = offset;
1733 offset += sizeof (gpointer);
1740 eArg = sig->param_count + sArg;
1742 if (sig->call_convention == MONO_CALL_VARARG)
1743 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1745 for (iParm = sArg; iParm < eArg; ++iParm) {
1746 inst = cfg->varinfo [curinst];
1747 if (inst->opcode != OP_REGVAR) {
1748 switch (cinfo->args[iParm].regtype) {
1749 case RegTypeStructByAddr :
1750 if (cinfo->args[iParm].reg == STK_BASE) {
1751 inst->opcode = OP_S390_LOADARG;
1752 inst->inst_basereg = frame_reg;
1753 offset = S390_ALIGN(offset, sizeof(long));
1754 inst->inst_offset = offset;
1755 size = abs(cinfo->args[iParm].vtsize);
1756 inst->backend.arg_info = cinfo->args[iParm].offset;
1758 inst->opcode = OP_S390_ARGREG;
1759 inst->inst_basereg = frame_reg;
1760 size = sizeof(gpointer);
1761 offset = S390_ALIGN(offset, size);
1762 inst->inst_offset = offset;
1763 inst->backend.arg_info = cinfo->args[iParm].offset;
1766 case RegTypeStructByVal :
1767 inst->opcode = OP_S390_ARGPTR;
1768 inst->inst_basereg = frame_reg;
1769 size = cinfo->args[iParm].size;
1770 offset = S390_ALIGN(offset, size);
1771 inst->inst_offset = offset;
1772 inst->backend.arg_info = cinfo->args[iParm].offset;
1775 if (cinfo->args[iParm].reg != STK_BASE) {
1776 inst->opcode = OP_REGOFFSET;
1777 inst->inst_basereg = frame_reg;
1778 size = (cinfo->args[iParm].size < 8
1781 offset = S390_ALIGN(offset, size);
1782 inst->inst_offset = offset;
1784 inst->opcode = OP_S390_STKARG;
1785 inst->inst_basereg = frame_reg;
1786 size = ((cinfo->args[iParm].size < 8)
1787 ? 8 - cinfo->args[iParm].size
1789 inst->inst_offset = cinfo->args[iParm].offset +
1791 inst->backend.arg_info = 0;
1792 size = sizeof(long);
1795 if ((sig->call_convention == MONO_CALL_VARARG) &&
1796 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1797 (iParm < sig->sentinelpos))
1798 cfg->sig_cookie += size;
1805 curinst = cfg->locals_start;
1806 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1807 inst = cfg->varinfo [iVar];
1808 if ((inst->flags & MONO_INST_IS_DEAD) ||
1809 (inst->opcode == OP_REGVAR))
1812 /*--------------------------------------------------*/
1813 /* inst->backend.is_pinvoke indicates native sized value types, */
1814 /* this is used by the pinvoke wrappers when they */
1815 /* call functions returning structure */
1816 /*--------------------------------------------------*/
1817 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1818 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype), &align);
1820 size = mono_type_size (inst->inst_vtype, &align);
1822 offset = S390_ALIGN(offset, align);
1823 inst->inst_offset = offset;
1824 inst->opcode = OP_REGOFFSET;
1825 inst->inst_basereg = frame_reg;
1827 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
1828 iVar, inst->inst_offset, size));
1831 /*------------------------------------------------------*/
1832 /* Allow space for the trace method stack area if needed*/
1833 /*------------------------------------------------------*/
1834 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
1835 offset += S390_TRACE_STACK_SIZE;
1837 /*------------------------------------------------------*/
1838 /* Reserve space to save LMF and caller saved registers */
1839 /*------------------------------------------------------*/
1840 if (cfg->method->save_lmf)
1841 offset += sizeof (MonoLMF);
1843 /*------------------------------------------------------*/
1844 /* align the offset */
1845 /*------------------------------------------------------*/
1846 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1850 /*========================= End of Function ========================*/
1852 /*------------------------------------------------------------------*/
1854 /* Name - mono_arch_call_opcode */
1856 /* Function - Take the arguments and generate the arch-specific */
1857 /* instructions to properly call the function. This */
1858 /* includes pushing, moving argments to the correct */
1861 /*------------------------------------------------------------------*/
1864 mono_arch_call_opcode (MonoCompile *cfg, MonoBasicBlock* bb,
1865 MonoCallInst *call, int is_virtual) {
1867 MonoCallArgParm *arg;
1868 MonoMethodSignature *sig;
1869 int i, n, lParamArea;
1874 sig = call->signature;
1875 n = sig->param_count + sig->hasthis;
1876 DEBUG (g_print ("Call requires: %d parameters\n",n));
1878 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
1880 call->stack_usage = MAX(sz.stack_size, call->stack_usage);
1881 lParamArea = MAX((call->stack_usage - S390_MINIMAL_STACK_SIZE - sz.parm_size), 0);
1882 cfg->param_area = MAX (((signed) cfg->param_area), lParamArea);
1883 cfg->flags |= MONO_CFG_HAS_CALLS;
1885 if (cinfo->struct_ret)
1886 call->used_iregs |= 1 << cinfo->ret.reg;
1888 for (i = 0; i < n; ++i) {
1889 ainfo = cinfo->args + i;
1891 if (!(sig->pinvoke) &&
1892 (sig->call_convention == MONO_CALL_VARARG) &&
1893 (i == sig->sentinelpos)) {
1894 emit_sig_cookie (cfg, call, cinfo, ainfo->size);
1897 if (is_virtual && i == 0) {
1898 /* the argument will be attached to the call instrucion */
1899 in = call->args [i];
1900 call->used_iregs |= 1 << ainfo->reg;
1902 MONO_INST_NEW_CALL_ARG (cfg, arg, OP_OUTARG);
1903 in = call->args [i];
1904 arg->ins.cil_code = in->cil_code;
1905 arg->ins.inst_left = in;
1906 arg->ins.type = in->type;
1908 /* prepend, we'll need to reverse them later */
1909 arg->ins.next = call->out_args;
1910 call->out_args = (MonoInst *) arg;
1911 arg->ins.inst_right = (MonoInst *) call;
1912 if (ainfo->regtype == RegTypeGeneral) {
1913 arg->ins.backend.reg3 = ainfo->reg;
1914 call->used_iregs |= 1 << ainfo->reg;
1915 } else if (ainfo->regtype == RegTypeStructByAddr) {
1916 call->used_iregs |= 1 << ainfo->reg;
1917 arg->ins.sreg1 = ainfo->reg;
1918 arg->ins.opcode = OP_OUTARG_VT;
1919 arg->size = -ainfo->vtsize;
1920 arg->offset = ainfo->offset;
1921 arg->offPrm = ainfo->offparm + sz.offStruct;
1922 } else if (ainfo->regtype == RegTypeStructByVal) {
1923 if (ainfo->reg != STK_BASE)
1924 call->used_iregs |= 1 << ainfo->reg;
1925 arg->ins.sreg1 = ainfo->reg;
1926 arg->ins.opcode = OP_OUTARG_VT;
1927 arg->size = ainfo->size;
1928 arg->offset = ainfo->offset;
1929 arg->offPrm = ainfo->offparm + sz.offStruct;
1930 } else if (ainfo->regtype == RegTypeBase) {
1931 arg->ins.opcode = OP_OUTARG_MEMBASE;
1932 arg->ins.sreg1 = ainfo->reg;
1933 arg->size = ainfo->size;
1934 arg->offset = ainfo->offset;
1935 call->used_iregs |= 1 << ainfo->reg;
1936 } else if (ainfo->regtype == RegTypeFP) {
1937 arg->ins.backend.reg3 = ainfo->reg;
1938 call->used_fregs |= 1 << ainfo->reg;
1939 if (ainfo->size == 4)
1940 arg->ins.opcode = OP_OUTARG_R4;
1942 arg->ins.opcode = OP_OUTARG_R8;
1944 g_assert_not_reached ();
1950 * Handle the case where there are no implicit arguments
1952 if (!(sig->pinvoke) &&
1953 (sig->call_convention == MONO_CALL_VARARG) &&
1954 (n == sig->sentinelpos)) {
1955 emit_sig_cookie (cfg, call, cinfo, sizeof(MonoType *));
1959 * Reverse the call->out_args list.
1962 MonoInst *prev = NULL, *list = call->out_args, *next;
1969 call->out_args = prev;
1976 /*========================= End of Function ========================*/
1978 /*------------------------------------------------------------------*/
1980 /* Name - emit_sig_cookie. */
1982 /* Function - For variable length parameter lists construct a */
1983 /* signature cookie and emit it. */
1985 /*------------------------------------------------------------------*/
1988 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call,
1989 CallInfo *cinfo, int argSize)
1991 MonoCallArgParm *arg;
1992 MonoMethodSignature *tmpSig;
1995 cfg->disable_aot = TRUE;
1997 /*----------------------------------------------------------*/
1998 /* mono_ArgIterator_Setup assumes the signature cookie is */
1999 /* passed first and all the arguments which were before it */
2000 /* passed on the stack after the signature. So compensate */
2001 /* by passing a different signature. */
2002 /*----------------------------------------------------------*/
2003 tmpSig = mono_metadata_signature_dup (call->signature);
2004 tmpSig->param_count -= call->signature->sentinelpos;
2005 tmpSig->sentinelpos = 0;
2006 if (tmpSig->param_count > 0)
2007 memcpy (tmpSig->params,
2008 call->signature->params + call->signature->sentinelpos,
2009 tmpSig->param_count * sizeof(MonoType *));
2011 MONO_INST_NEW (cfg, sigArg, OP_ICONST);
2012 sigArg->inst_p0 = tmpSig;
2014 MONO_INST_NEW_CALL_ARG (cfg, arg, OP_OUTARG_MEMBASE);
2015 arg->ins.inst_left = sigArg;
2016 arg->ins.inst_right = (MonoInst *) call;
2017 arg->size = argSize;
2018 arg->offset = cinfo->sigCookie.offset;
2020 /* prepend, we'll need to reverse them later */
2021 arg->ins.next = call->out_args;
2022 call->out_args = (MonoInst *) arg;
2025 /*========================= End of Function ========================*/
2027 /*------------------------------------------------------------------*/
2029 /* Name - mono_arch_instrument_mem_needs */
2031 /* Function - Allow tracing to work with this interface (with */
2032 /* an optional argument). */
2034 /*------------------------------------------------------------------*/
2037 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2039 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2041 /* split prolog-epilog requirements? */
2042 *code = 50; /* max bytes needed: check this number */
2045 /*========================= End of Function ========================*/
2047 /*------------------------------------------------------------------*/
2049 /* Name - mono_arch_instrument_prolog */
2051 /* Function - Create an "instrumented" prolog. */
2053 /*------------------------------------------------------------------*/
2056 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2057 gboolean enable_arguments)
2064 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2065 if (cfg->method->save_lmf)
2066 parmOffset -= sizeof(MonoLMF);
2067 fpOffset = parmOffset + (5*sizeof(gpointer));
2068 if ((!has_ld) && (fpOffset > 4096)) {
2069 s390_lgr (code, s390_r12, STK_BASE);
2071 while (fpOffset > 4096) {
2072 s390_aghi (code, baseReg, 4096);
2080 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2082 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2083 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2084 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2085 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2087 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2088 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2089 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2090 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2092 s390_basr (code, s390_r13, 0);
2094 s390_llong(code, cfg->method);
2095 s390_llong(code, func);
2096 s390_lg (code, s390_r2, 0, s390_r13, 4);
2098 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2100 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2101 s390_lgr (code, s390_r4, STK_BASE);
2102 s390_aghi (code, s390_r4, cfg->stack_usage);
2103 s390_lg (code, s390_r1, 0, s390_r13, 12);
2104 s390_basr (code, s390_r14, s390_r1);
2106 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2107 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2108 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2109 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2111 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2112 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2113 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2114 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2116 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2121 /*========================= End of Function ========================*/
2123 /*------------------------------------------------------------------*/
2125 /* Name - mono_arch_instrument_epilog */
2127 /* Function - Create an epilog that will handle the returned */
2128 /* values used in instrumentation. */
2130 /*------------------------------------------------------------------*/
2133 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
2136 int save_mode = SAVE_NONE,
2138 MonoMethod *method = cfg->method;
2139 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2141 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2142 if (method->save_lmf)
2143 saveOffset -= sizeof(MonoLMF);
2147 case MONO_TYPE_VOID:
2148 /* special case string .ctor icall */
2149 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2150 save_mode = SAVE_ONE;
2152 save_mode = SAVE_NONE;
2156 save_mode = SAVE_ONE;
2159 save_mode = SAVE_R4;
2162 save_mode = SAVE_R8;
2164 case MONO_TYPE_VALUETYPE:
2165 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2166 rtype = mono_method_signature (method)->ret->data.klass->enum_basetype->type;
2169 save_mode = SAVE_STRUCT;
2172 save_mode = SAVE_ONE;
2176 switch (save_mode) {
2178 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2179 if (enable_arguments) {
2180 s390_lgr (code, s390_r3, s390_r2);
2184 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2185 if (enable_arguments) {
2186 s390_ldebr (code, s390_f0, s390_f0);
2190 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2193 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2194 if (enable_arguments) {
2195 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2196 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2204 s390_basr (code, s390_r13, 0);
2206 s390_llong(code, cfg->method);
2207 s390_llong(code, func);
2208 s390_lg (code, s390_r2, 0, s390_r13, 4);
2209 s390_lg (code, s390_r1, 0, s390_r13, 12);
2210 s390_basr (code, s390_r14, s390_r1);
2212 switch (save_mode) {
2214 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2218 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2221 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2231 /*========================= End of Function ========================*/
2233 /*------------------------------------------------------------------*/
2235 /* Name - peephole_pass */
2237 /* Function - Form a peephole pass at the code looking for */
2238 /* simple optimizations. */
2240 /*------------------------------------------------------------------*/
2243 peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2245 MonoInst *ins, *last_ins = NULL;
2250 switch (ins->opcode) {
2252 /* remove unnecessary multiplication with 1 */
2253 if (ins->inst_imm == 1) {
2254 if (ins->dreg != ins->sreg1) {
2255 ins->opcode = OP_MOVE;
2257 last_ins->next = ins->next;
2263 case OP_LOAD_MEMBASE:
2264 case OP_LOADI4_MEMBASE:
2266 * OP_STORE_MEMBASE_REG reg, offset(basereg)
2267 * OP_LOAD_MEMBASE offset(basereg), reg
2269 if (last_ins && (last_ins->opcode == OP_STOREI4_MEMBASE_REG
2270 || last_ins->opcode == OP_STORE_MEMBASE_REG) &&
2271 ins->inst_basereg == last_ins->inst_destbasereg &&
2272 ins->inst_offset == last_ins->inst_offset) {
2273 if (ins->dreg == last_ins->sreg1) {
2274 last_ins->next = ins->next;
2278 ins->opcode = OP_MOVE;
2279 ins->sreg1 = last_ins->sreg1;
2283 * Note: reg1 must be different from the basereg in the second load
2284 * OP_LOAD_MEMBASE offset(basereg), reg1
2285 * OP_LOAD_MEMBASE offset(basereg), reg2
2287 * OP_LOAD_MEMBASE offset(basereg), reg1
2288 * OP_MOVE reg1, reg2
2290 } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE
2291 || last_ins->opcode == OP_LOAD_MEMBASE) &&
2292 ins->inst_basereg != last_ins->dreg &&
2293 ins->inst_basereg == last_ins->inst_basereg &&
2294 ins->inst_offset == last_ins->inst_offset) {
2296 if (ins->dreg == last_ins->dreg) {
2297 last_ins->next = ins->next;
2301 ins->opcode = OP_MOVE;
2302 ins->sreg1 = last_ins->dreg;
2307 case OP_LOADU1_MEMBASE:
2308 case OP_LOADI1_MEMBASE:
2309 if (last_ins && (last_ins->opcode == OP_STOREI1_MEMBASE_REG) &&
2310 ins->inst_basereg == last_ins->inst_destbasereg &&
2311 ins->inst_offset == last_ins->inst_offset) {
2312 if (ins->dreg == last_ins->sreg1) {
2313 last_ins->next = ins->next;
2317 ins->opcode = OP_MOVE;
2318 ins->sreg1 = last_ins->sreg1;
2322 case OP_LOADU2_MEMBASE:
2323 case OP_LOADI2_MEMBASE:
2324 if (last_ins && (last_ins->opcode == OP_STOREI2_MEMBASE_REG) &&
2325 ins->inst_basereg == last_ins->inst_destbasereg &&
2326 ins->inst_offset == last_ins->inst_offset) {
2327 if (ins->dreg == last_ins->sreg1) {
2328 last_ins->next = ins->next;
2332 ins->opcode = OP_MOVE;
2333 ins->sreg1 = last_ins->sreg1;
2343 if (ins->dreg == ins->sreg1) {
2345 last_ins->next = ins->next;
2350 * OP_MOVE sreg, dreg
2351 * OP_MOVE dreg, sreg
2353 if (last_ins && last_ins->opcode == OP_MOVE &&
2354 ins->sreg1 == last_ins->dreg &&
2355 ins->dreg == last_ins->sreg1) {
2356 last_ins->next = ins->next;
2365 bb->last_ins = last_ins;
2368 /*========================= End of Function ========================*/
2370 /*------------------------------------------------------------------*/
2372 /* Name - mono_arch_local_regalloc. */
2374 /* Function - We first scan the list of instructions and we */
2375 /* save the liveness information of each register */
2376 /* (when the register is first used, when its value */
2377 /* is set etc.). We also reverse the list of instr- */
2378 /* uctions (in the InstList list) because assigning */
2379 /* registers backwards allows for more tricks to be */
2382 /*------------------------------------------------------------------*/
2385 mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
2387 mono_local_regalloc(cfg, bb);
2390 /*========================= End of Function ========================*/
2392 /*------------------------------------------------------------------*/
2394 /* Name - emit_float_to_int */
2396 /* Function - Create instructions which will convert a floating */
2397 /* point value to integer. */
2399 /*------------------------------------------------------------------*/
2402 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2404 /* sreg is a float, dreg is an integer reg. */
2406 s390_cfdbr (code, dreg, 5, sreg);
2409 s390_lghi (code, s390_r0, 0);
2410 s390_lghi (code, s390_r13, 0xff);
2411 s390_ltgr (code, dreg, dreg);
2413 s390_lghi (code, s390_r0, 0x80);
2414 s390_ngr (code, dreg, s390_r13);
2415 s390_ogr (code, dreg, s390_r0);
2420 s390_basr (code, s390_r13, 0);
2422 s390_llong (code, 0x41e0000000000000);
2423 s390_llong (code, 0x41f0000000000000);
2424 s390_ldr (code, s390_f15, sreg);
2425 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2426 s390_jl (code, 0); CODEPTR (code, o[0]);
2427 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2428 s390_cfdbr (code, dreg, 7, s390_f15);
2430 PTRSLOT (code, o[0]);
2431 s390_cfdbr (code, dreg, 5, sreg);
2434 s390_lghi (code, s390_r0, 0xff);
2435 s390_ngr (code, dreg, s390_r0);
2438 s390_lghi (code, s390_r0, -1);
2439 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2440 s390_ngr (code, dreg, s390_r0);
2447 /*========================= End of Function ========================*/
2449 /*------------------------------------------------------------------*/
2451 /* Name - mono_arch_output_basic_block */
2453 /* Function - Perform the "real" work of emitting instructions */
2454 /* that will do the work of in the basic block. */
2456 /*------------------------------------------------------------------*/
2459 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2464 guint8 *code = cfg->native_code + cfg->code_len;
2465 MonoInst *last_ins = NULL;
2466 guint last_offset = 0;
2467 int max_len, cpos, src2;
2469 if (cfg->opt & MONO_OPT_PEEPHOLE)
2470 peephole_pass (cfg, bb);
2472 /* we don't align basic blocks of loops on s390 */
2474 if (cfg->verbose_level > 2)
2475 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2477 cpos = bb->max_offset;
2479 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2480 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2481 //g_assert (!mono_compile_aot);
2484 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2485 /* this is not thread save, but good enough */
2486 /* fixme: howto handle overflows? */
2487 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2492 offset = code - cfg->native_code;
2494 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2496 if (offset > (cfg->code_size - max_len - 16)) {
2497 cfg->code_size *= 2;
2498 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2499 code = cfg->native_code + offset;
2502 mono_debug_record_line_number (cfg, ins, offset);
2504 switch (ins->opcode) {
2505 case OP_STOREI1_MEMBASE_IMM: {
2506 s390_lghi (code, s390_r0, ins->inst_imm);
2507 S390_LONG (code, stcy, stc, s390_r0, 0,
2508 ins->inst_destbasereg, ins->inst_offset);
2511 case OP_STOREI2_MEMBASE_IMM: {
2512 s390_lghi (code, s390_r0, ins->inst_imm);
2513 S390_LONG (code, sthy, sth, s390_r0, 0,
2514 ins->inst_destbasereg, ins->inst_offset);
2517 case OP_STOREI4_MEMBASE_IMM: {
2518 if (s390_is_imm16(ins->inst_imm)) {
2519 s390_lghi (code, s390_r0, ins->inst_imm);
2521 s390_basr (code, s390_r13, 0);
2523 s390_llong(code, ins->inst_imm);
2524 s390_lg (code, s390_r0, 0, s390_r13, 4);
2526 S390_LONG (code, sty, st, s390_r0, 0,
2527 ins->inst_destbasereg, ins->inst_offset);
2530 case OP_STORE_MEMBASE_IMM:
2531 case OP_STOREI8_MEMBASE_IMM: {
2532 if (s390_is_imm16(ins->inst_imm)) {
2533 s390_lghi (code, s390_r0, ins->inst_imm);
2535 s390_basr (code, s390_r13, 0);
2537 s390_llong(code, ins->inst_imm);
2538 s390_lg (code, s390_r0, 0, s390_r13, 4);
2540 S390_LONG (code, stg, stg, s390_r0, 0,
2541 ins->inst_destbasereg, ins->inst_offset);
2544 case OP_STOREI1_MEMBASE_REG: {
2545 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2546 ins->inst_destbasereg, ins->inst_offset);
2549 case OP_STOREI2_MEMBASE_REG: {
2550 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2551 ins->inst_destbasereg, ins->inst_offset);
2554 case OP_STOREI4_MEMBASE_REG: {
2555 S390_LONG (code, sty, st, ins->sreg1, 0,
2556 ins->inst_destbasereg, ins->inst_offset);
2559 case OP_STORE_MEMBASE_REG:
2560 case OP_STOREI8_MEMBASE_REG: {
2561 S390_LONG (code, stg, stg, ins->sreg1, 0,
2562 ins->inst_destbasereg, ins->inst_offset);
2566 case CEE_LDIND_I4: {
2567 s390_basr (code, s390_r13, 0);
2569 s390_llong(code, ins->inst_p0);
2570 s390_lg (code, s390_r13, 0, s390_r13, 4);
2571 s390_lgf (code, ins->dreg, 0, s390_r13, 0);
2574 case CEE_LDIND_U4: {
2575 s390_basr (code, s390_r13, 0);
2577 s390_llong(code, ins->inst_p0);
2578 s390_lg (code, s390_r13, 0, s390_r13, 4);
2579 s390_llgf (code, ins->dreg, 0, s390_r13, 0);
2583 g_assert_not_reached ();
2585 case OP_LOAD_MEMBASE:
2586 case OP_LOADI8_MEMBASE: {
2587 S390_LONG (code, lg, lg, ins->dreg, 0,
2588 ins->inst_basereg, ins->inst_offset);
2591 case OP_LOADI4_MEMBASE: {
2592 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2593 ins->inst_basereg, ins->inst_offset);
2596 case OP_LOADU4_MEMBASE: {
2597 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2598 ins->inst_basereg, ins->inst_offset);
2601 case OP_LOADU1_MEMBASE: {
2602 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2603 ins->inst_basereg, ins->inst_offset);
2606 case OP_LOADI1_MEMBASE: {
2607 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2608 ins->inst_basereg, ins->inst_offset);
2611 case OP_LOADU2_MEMBASE: {
2612 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2613 ins->inst_basereg, ins->inst_offset);
2616 case OP_LOADI2_MEMBASE: {
2617 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2618 ins->inst_basereg, ins->inst_offset);
2622 s390_lghi (code, s390_r0, 0x80);
2623 if (ins->dreg != ins->sreg1) {
2624 s390_lgr (code, ins->dreg, ins->sreg1);
2626 s390_ngr (code, s390_r0, ins->sreg1);
2628 s390_lghi (code, s390_r13, -1);
2629 s390_sllg (code, s390_r13, s390_r13, 0, 8);
2630 s390_ogr (code, ins->dreg, s390_r13);
2634 s390_lghi (code, s390_r0, 0x80);
2635 s390_sllg (code, s390_r0, s390_r0, 0, 8);
2636 if (ins->dreg != ins->sreg1) {
2637 s390_lgr (code, ins->dreg, ins->sreg1);
2639 s390_ngr (code, s390_r0, ins->sreg1);
2641 s390_lghi (code, s390_r13, -1);
2642 s390_sllg (code, s390_r13, s390_r13, 0, 16);
2643 s390_ogr (code, ins->dreg, s390_r13);
2647 s390_lghi (code, s390_r0, 0xff);
2648 if (ins->dreg != ins->sreg1) {
2649 s390_lgr (code, ins->dreg, ins->sreg1);
2651 s390_ngr (code, ins->dreg, s390_r0);
2655 s390_lghi (code, s390_r0, -1);
2656 s390_sllg (code, s390_r0, s390_r0, 0, 16);
2657 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2658 if (ins->dreg != ins->sreg1) {
2659 s390_lgr (code, ins->dreg, ins->sreg1);
2661 s390_ngr (code, ins->dreg, s390_r0);
2667 (opcode_to_cond(ins->next->opcode) >= CMP_LE_UN))
2668 s390_clgr (code, ins->sreg1, ins->sreg2);
2670 s390_cgr (code, ins->sreg1, ins->sreg2);
2673 case OP_COMPARE_IMM: {
2674 if (s390_is_imm16 (ins->inst_imm)) {
2675 s390_lghi (code, s390_r0, ins->inst_imm);
2677 (opcode_to_cond(ins->next->opcode) >= CMP_LE_UN))
2678 s390_clgr (code, ins->sreg1, s390_r0);
2680 s390_cgr (code, ins->sreg1, s390_r0);
2683 s390_basr (code, s390_r13, 0);
2685 s390_llong(code, ins->inst_imm);
2687 (opcode_to_cond(ins->next->opcode) >= CMP_LE_UN))
2688 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
2690 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
2696 (opcode_to_cond(ins->next->opcode) >= CMP_LE_UN))
2697 s390_clr (code, ins->sreg1, ins->sreg2);
2699 s390_cr (code, ins->sreg1, ins->sreg2);
2702 case OP_ICOMPARE_IMM: {
2703 if (s390_is_imm16 (ins->inst_imm)) {
2704 s390_lghi (code, s390_r0, ins->inst_imm);
2706 (opcode_to_cond(ins->next->opcode) >= CMP_LE_UN))
2707 s390_clr (code, ins->sreg1, s390_r0);
2709 s390_cr (code, ins->sreg1, s390_r0);
2712 s390_basr (code, s390_r13, 0);
2714 s390_word (code, ins->inst_imm);
2716 (opcode_to_cond(ins->next->opcode) >= CMP_LE_UN))
2717 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
2719 s390_c (code, ins->sreg1, 0, s390_r13, 4);
2724 s390_basr (code, s390_r13, 0);
2726 mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS,
2728 s390_llong (code, mono_arch_break);
2729 s390_lg (code, s390_r14, 0, s390_r13, 4);
2730 s390_basr (code, s390_r14, s390_r14);
2735 s390_algr (code, ins->dreg, src2);
2740 s390_agr (code, ins->dreg, src2);
2745 s390_alcgr (code, ins->dreg, src2);
2749 if (ins->dreg != ins->sreg1) {
2750 s390_lgr (code, ins->dreg, ins->sreg1);
2752 if (s390_is_imm16 (ins->inst_imm)) {
2753 s390_aghi (code, ins->dreg, ins->inst_imm);
2755 s390_basr (code, s390_r13, 0);
2757 s390_llong(code, ins->inst_imm);
2758 s390_ag (code, ins->dreg, 0, s390_r13, 4);
2763 if (ins->dreg != ins->sreg1) {
2764 s390_lgr (code, ins->dreg, ins->sreg1);
2766 if (s390_is_imm16 (ins->inst_imm)) {
2767 s390_lghi (code, s390_r0, ins->inst_imm);
2768 s390_alcgr (code, ins->dreg, s390_r0);
2770 s390_basr (code, s390_r13, 0);
2772 s390_llong (code, ins->inst_imm);
2773 s390_lg (code, s390_r13, 0, s390_r13, 4);
2774 s390_alcgr (code, ins->dreg, s390_r13);
2780 s390_agr (code, ins->dreg, src2);
2781 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
2784 case OP_LADD_OVF_UN: {
2786 s390_algr (code, ins->dreg, src2);
2787 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
2790 case OP_ADD_OVF_CARRY: {
2792 s390_lghi (code, s390_r0, 0);
2793 s390_lgr (code, s390_r1, s390_r0);
2794 s390_alcgr (code, s390_r0, s390_r1);
2795 s390_agr (code, ins->dreg, src2);
2796 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
2797 s390_agr (code, ins->dreg, s390_r0);
2798 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
2801 case OP_ADD_OVF_UN_CARRY: {
2803 s390_alcgr (code, ins->dreg, src2);
2804 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
2809 s390_slgr (code, ins->dreg, src2);
2814 s390_sgr (code, ins->dreg, src2);
2819 s390_slbgr(code, ins->dreg, src2);
2823 if (ins->dreg != ins->sreg1) {
2824 s390_lgr (code, ins->dreg, ins->sreg1);
2826 if (s390_is_imm16 (-ins->inst_imm)) {
2827 s390_lghi (code, s390_r0, ins->inst_imm);
2828 s390_slgr (code, ins->dreg, s390_r0);
2830 s390_basr (code, s390_r13, 0);
2832 s390_llong(code, ins->inst_imm);
2833 s390_slg (code, ins->dreg, 0, s390_r13, 4);
2838 if (ins->dreg != ins->sreg1) {
2839 s390_lgr (code, ins->dreg, ins->sreg1);
2841 if (s390_is_imm16 (-ins->inst_imm)) {
2842 s390_lghi (code, s390_r0, ins->inst_imm);
2843 s390_slbgr (code, ins->dreg, s390_r0);
2845 s390_basr (code, s390_r13, 0);
2847 s390_llong(code, ins->inst_imm);
2848 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
2854 s390_sgr (code, ins->dreg, src2);
2855 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
2858 case OP_LSUB_OVF_UN: {
2860 s390_slgr (code, ins->dreg, src2);
2861 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
2864 case OP_SUB_OVF_CARRY: {
2866 s390_lghi (code, s390_r0, 0);
2867 s390_lgr (code, s390_r1, s390_r0);
2868 s390_slbgr (code, s390_r0, s390_r1);
2869 s390_sgr (code, ins->dreg, src2);
2870 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
2871 s390_agr (code, ins->dreg, s390_r0);
2872 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
2875 case OP_SUB_OVF_UN_CARRY: {
2877 s390_slbgr (code, ins->dreg, src2);
2878 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
2882 if (ins->sreg1 == ins->dreg) {
2883 s390_ngr (code, ins->dreg, ins->sreg2);
2886 if (ins->sreg2 == ins->dreg) {
2887 s390_ngr (code, ins->dreg, ins->sreg1);
2890 s390_lgr (code, ins->dreg, ins->sreg1);
2891 s390_ngr (code, ins->dreg, ins->sreg2);
2897 if (ins->dreg != ins->sreg1) {
2898 s390_lgr (code, ins->dreg, ins->sreg1);
2900 if (s390_is_imm16 (ins->inst_imm)) {
2901 s390_lghi (code, s390_r0, ins->inst_imm);
2902 s390_ngr (code, ins->dreg, s390_r0);
2904 s390_basr (code, s390_r13, 0);
2906 s390_llong(code, ins->inst_imm);
2907 s390_ng (code, ins->dreg, 0, s390_r13, 4);
2912 s390_lgr (code, s390_r1, ins->sreg1);
2913 s390_dsgr (code, s390_r0, ins->sreg2);
2914 s390_lgr (code, ins->dreg, s390_r1);
2918 s390_lgr (code, s390_r1, ins->sreg1);
2919 s390_lghi (code, s390_r0, 0);
2920 s390_dlgr (code, s390_r0, ins->sreg2);
2921 s390_lgr (code, ins->dreg, s390_r1);
2925 if (s390_is_imm16 (ins->inst_imm)) {
2926 s390_lghi (code, s390_r13, ins->inst_imm);
2927 s390_lgr (code, s390_r1, ins->sreg1);
2929 s390_basr (code, s390_r13, 0);
2931 s390_llong(code, ins->inst_imm);
2932 s390_lgr (code, s390_r1, ins->sreg1);
2933 s390_lg (code, s390_r13, 0, s390_r13, 4);
2935 s390_dsgr (code, s390_r0, s390_r13);
2936 s390_lgr (code, ins->dreg, s390_r1);
2940 s390_lgr (code, s390_r1, ins->sreg1);
2941 s390_dsgr (code, s390_r0, ins->sreg2);
2942 s390_lgr (code, ins->dreg, s390_r0);
2946 s390_lgr (code, s390_r1, ins->sreg1);
2947 s390_lghi (code, s390_r0, 0);
2948 s390_dlgr (code, s390_r0, ins->sreg2);
2949 s390_lgr (code, ins->dreg, s390_r0);
2953 if (s390_is_imm16 (ins->inst_imm)) {
2954 s390_lghi (code, s390_r13, ins->inst_imm);
2955 s390_lgr (code, s390_r0, ins->sreg1);
2957 s390_basr (code, s390_r13, 0);
2959 s390_llong(code, ins->inst_imm);
2960 s390_lgr (code, s390_r0, ins->sreg1);
2961 s390_lg (code, s390_r13, 0, s390_r13, 4);
2963 s390_dsgr(code, s390_r0, s390_r13);
2964 s390_lgr (code, ins->dreg, s390_r0);
2968 if (ins->sreg1 == ins->dreg) {
2969 s390_ogr (code, ins->dreg, ins->sreg2);
2972 if (ins->sreg2 == ins->dreg) {
2973 s390_ogr (code, ins->dreg, ins->sreg1);
2976 s390_lgr (code, ins->dreg, ins->sreg1);
2977 s390_ogr (code, ins->dreg, ins->sreg2);
2983 if (ins->dreg != ins->sreg1) {
2984 s390_lgr (code, ins->dreg, ins->sreg1);
2986 if (s390_is_imm16 (ins->inst_imm)) {
2987 s390_lghi (code, s390_r0, ins->inst_imm);
2988 s390_ogr (code, ins->dreg, s390_r0);
2990 s390_basr (code, s390_r13, 0);
2992 s390_llong(code, ins->inst_imm);
2993 s390_og (code, ins->dreg, 0, s390_r13, 4);
2998 if (ins->sreg1 == ins->dreg) {
2999 s390_xgr (code, ins->dreg, ins->sreg2);
3002 if (ins->sreg2 == ins->dreg) {
3003 s390_xgr (code, ins->dreg, ins->sreg1);
3006 s390_lgr (code, ins->dreg, ins->sreg1);
3007 s390_xgr (code, ins->dreg, ins->sreg2);
3013 if (ins->dreg != ins->sreg1) {
3014 s390_lgr (code, ins->dreg, ins->sreg1);
3016 if (s390_is_imm16 (ins->inst_imm)) {
3017 s390_lghi (code, s390_r0, ins->inst_imm);
3018 s390_xgr (code, ins->dreg, s390_r0);
3020 s390_basr (code, s390_r13, 0);
3022 s390_llong(code, ins->inst_imm);
3023 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3030 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3035 if (ins->sreg1 != ins->dreg) {
3036 s390_lgr (code, ins->dreg, ins->sreg1);
3038 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3044 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3049 if (ins->sreg1 != ins->dreg) {
3050 s390_lgr (code, ins->dreg, ins->sreg1);
3052 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3056 case OP_LSHR_UN_IMM: {
3057 if (ins->sreg1 != ins->dreg) {
3058 s390_lgr (code, ins->dreg, ins->sreg1);
3060 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3066 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3070 if (ins->sreg1 != ins->dreg) {
3071 s390_lgr (code, ins->dreg, ins->sreg1);
3073 s390_lghi (code, s390_r0, -1);
3074 s390_xgr (code, ins->dreg, s390_r0);
3078 s390_lcgr (code, ins->dreg, ins->sreg1);
3084 s390_msgr (code, ins->dreg, src2);
3089 if (ins->dreg != ins->sreg1) {
3090 s390_lgr (code, ins->dreg, ins->sreg1);
3092 if (s390_is_imm16 (ins->inst_imm)) {
3093 s390_lghi (code, s390_r13, ins->inst_imm);
3095 s390_basr (code, s390_r13, 0);
3097 s390_llong(code, ins->inst_imm);
3098 s390_lg (code, s390_r13, 0, s390_r13, 4);
3100 s390_msgr (code, ins->dreg, s390_r13);
3106 s390_ltgr (code, s390_r1, ins->sreg1);
3107 s390_jz (code, 0); CODEPTR(code, o[0]);
3108 s390_ltgr (code, s390_r0, ins->sreg2);
3110 s390_lghi (code, s390_r1, 0);
3111 s390_j (code, 0); CODEPTR(code, o[1]);
3112 s390_xgr (code, s390_r0, s390_r1);
3113 s390_msgr (code, s390_r1, ins->sreg2);
3114 s390_xgr (code, s390_r0, s390_r1);
3115 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3116 s390_ltgr (code, s390_r0, s390_r0);
3117 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3118 PTRSLOT (code, o[0]);
3119 PTRSLOT (code, o[1]);
3120 s390_lgr (code, ins->dreg, s390_r1);
3123 case OP_LMUL_OVF_UN:
3124 case CEE_MUL_OVF_UN: {
3125 s390_lghi (code, s390_r0, 0);
3126 s390_lgr (code, s390_r1, ins->sreg1);
3127 s390_mlgr (code, s390_r0, ins->sreg2);
3128 s390_ltgr (code, s390_r0, s390_r0);
3129 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3130 s390_lgr (code, ins->dreg, s390_r1);
3134 g_assert_not_reached ();
3136 s390_algr (code, ins->dreg, src2);
3141 s390_agr (code, ins->dreg, src2);
3145 g_assert_not_reached ();
3147 s390_alcgr (code, ins->dreg, src2);
3151 if (ins->dreg != ins->sreg1) {
3152 s390_lgfr (code, ins->dreg, ins->sreg1);
3154 if (s390_is_imm16 (ins->inst_imm)) {
3155 s390_aghi(code, ins->dreg, ins->inst_imm);
3157 s390_basr (code, s390_r13, 0);
3159 s390_word (code, ins->inst_imm);
3160 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3165 if (ins->dreg != ins->sreg1) {
3166 s390_lgfr (code, ins->dreg, ins->sreg1);
3168 if (s390_is_imm16 (ins->inst_imm)) {
3169 s390_lghi (code, s390_r0, ins->inst_imm);
3170 s390_alcgr (code, ins->dreg, s390_r0);
3172 s390_basr (code, s390_r13, 0);
3174 s390_word (code, ins->inst_imm);
3175 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3176 s390_alcgr (code, ins->dreg, s390_r13);
3182 s390_ar (code, ins->dreg, src2);
3183 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3184 s390_lgfr (code, ins->dreg, ins->dreg);
3187 case CEE_ADD_OVF_UN: {
3189 s390_algr (code, ins->dreg, src2);
3190 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3191 s390_llgfr (code, ins->dreg, ins->dreg);
3195 CHECK_SRCDST_NCOM_I;
3196 s390_slgr (code, ins->dreg, src2);
3200 CHECK_SRCDST_NCOM_I;
3201 s390_sgr (code, ins->dreg, src2);
3205 CHECK_SRCDST_NCOM_I;
3206 s390_slbgr (code, ins->dreg, src2);
3210 if (ins->dreg != ins->sreg1) {
3211 s390_lgfr (code, ins->dreg, ins->sreg1);
3213 if (s390_is_imm16 (-ins->inst_imm)) {
3214 s390_aghi (code, ins->dreg, -ins->inst_imm);
3216 s390_basr (code, s390_r13, 0);
3218 s390_word (code, ins->inst_imm);
3219 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3224 s390_basr (code, s390_r13, 0);
3226 s390_word (code, ins->inst_imm);
3227 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3232 s390_sr (code, ins->dreg, src2);
3233 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3234 s390_lgfr (code, ins->dreg, ins->dreg);
3237 case CEE_SUB_OVF_UN: {
3239 s390_slr (code, ins->dreg, src2);
3240 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3241 s390_llgfr(code, ins->dreg, ins->dreg);
3245 CHECK_SRCDST_NCOM_I;
3246 s390_ngr (code, ins->dreg, src2);
3250 if (ins->dreg != ins->sreg1) {
3251 s390_lgfr (code, ins->dreg, ins->sreg1);
3253 if (s390_is_imm16 (ins->inst_imm)) {
3254 s390_lghi (code, s390_r0, ins->inst_imm);
3255 s390_ngr (code, ins->dreg, s390_r0);
3257 s390_basr (code, s390_r13, 0);
3259 s390_llong(code, ins->inst_imm);
3260 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3265 s390_lgfr (code, s390_r0, ins->sreg1);
3266 s390_srda (code, s390_r0, 0, 32);
3267 s390_dr (code, s390_r0, ins->sreg2);
3268 s390_lgfr (code, ins->dreg, s390_r1);
3272 s390_lgfr (code, s390_r0, ins->sreg1);
3273 s390_srdl (code, s390_r0, 0, 32);
3274 s390_dlr (code, s390_r0, ins->sreg2);
3275 s390_lgfr (code, ins->dreg, s390_r1);
3279 if (s390_is_imm16 (ins->inst_imm)) {
3280 s390_lghi (code, s390_r13, ins->inst_imm);
3281 s390_lgfr (code, s390_r0, ins->sreg1);
3283 s390_basr (code, s390_r13, 0);
3285 s390_word (code, ins->inst_imm);
3286 s390_lgfr (code, s390_r0, ins->sreg1);
3287 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3289 s390_srda (code, s390_r0, 0, 32);
3290 s390_dr (code, s390_r0, ins->sreg2);
3291 s390_lgfr (code, ins->dreg, s390_r1);
3295 s390_lgfr (code, s390_r0, ins->sreg1);
3296 s390_srda (code, s390_r0, 0, 32);
3297 s390_dr (code, s390_r0, ins->sreg2);
3298 s390_lgfr (code, ins->dreg, s390_r0);
3301 s390_lgfr (code, s390_r0, ins->sreg1);
3302 s390_srdl (code, s390_r0, 0, 32);
3303 s390_dlr (code, s390_r0, ins->sreg2);
3304 s390_lgfr (code, ins->dreg, s390_r0);
3308 if (s390_is_imm16 (ins->inst_imm)) {
3309 s390_lghi (code, s390_r13, ins->inst_imm);
3310 s390_lgfr (code, s390_r0, ins->sreg1);
3312 s390_basr (code, s390_r13, 0);
3314 s390_word (code, ins->inst_imm);
3315 s390_lgfr (code, s390_r0, ins->sreg1);
3316 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3318 s390_srda (code, s390_r0, 0, 32);
3319 s390_dr (code, s390_r0, ins->sreg2);
3320 s390_lgfr (code, ins->dreg, s390_r0);
3325 s390_ogr (code, ins->dreg, src2);
3329 if (ins->dreg != ins->sreg1) {
3330 s390_lgfr (code, ins->dreg, ins->sreg1);
3332 if (s390_is_imm16 (ins->inst_imm)) {
3333 s390_lghi (code, s390_r0, ins->inst_imm);
3334 s390_ogr (code, ins->dreg, s390_r0);
3336 s390_basr (code, s390_r13, 0);
3338 s390_llong(code, ins->inst_imm);
3339 s390_og (code, ins->dreg, 0, s390_r13, 4);
3345 s390_xgr (code, ins->dreg, src2);
3349 if (ins->dreg != ins->sreg1) {
3350 s390_lgfr (code, ins->dreg, ins->sreg1);
3352 if (s390_is_imm16 (ins->inst_imm)) {
3353 s390_lghi (code, s390_r0, ins->inst_imm);
3354 s390_xgr (code, ins->dreg, s390_r0);
3356 s390_basr (code, s390_r13, 0);
3358 s390_llong(code, ins->inst_imm);
3359 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3364 if (ins->sreg1 != ins->dreg) {
3365 s390_lgfr (code, ins->dreg, ins->sreg1);
3367 s390_sll (code, ins->dreg, ins->sreg2, 0);
3371 if (ins->sreg1 != ins->dreg) {
3372 s390_lgfr (code, ins->dreg, ins->sreg1);
3374 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3378 if (ins->sreg1 != ins->dreg) {
3379 s390_lgfr (code, ins->dreg, ins->sreg1);
3381 s390_sra (code, ins->dreg, ins->sreg2, 0);
3385 if (ins->sreg1 != ins->dreg) {
3386 s390_lgfr (code, ins->dreg, ins->sreg1);
3388 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3391 case OP_ISHR_UN_IMM: {
3392 if (ins->sreg1 != ins->dreg) {
3393 s390_lgfr (code, ins->dreg, ins->sreg1);
3395 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3399 if (ins->sreg1 != ins->dreg) {
3400 s390_lgfr (code, ins->dreg, ins->sreg1);
3402 s390_srl (code, ins->dreg, ins->sreg2, 0);
3406 if (ins->sreg1 != ins->dreg) {
3407 s390_lgfr (code, ins->dreg, ins->sreg1);
3409 s390_lghi (code, s390_r0, -1);
3410 s390_xgr (code, ins->dreg, s390_r0);
3414 s390_lcgr (code, ins->dreg, ins->sreg1);
3419 s390_msr (code, ins->dreg, src2);
3423 if (ins->dreg != ins->sreg1) {
3424 s390_lgfr (code, ins->dreg, ins->sreg1);
3426 if (s390_is_imm16 (ins->inst_imm)) {
3427 s390_lghi (code, s390_r13, ins->inst_imm);
3429 s390_basr (code, s390_r13, 0);
3431 s390_word (code, ins->inst_imm);
3432 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3434 s390_msr (code, ins->dreg, s390_r13);
3439 s390_ltr (code, s390_r1, ins->sreg1);
3440 s390_jz (code, 0); CODEPTR(code, o[0]);
3441 s390_ltr (code, s390_r0, ins->sreg2);
3443 s390_lhi (code, s390_r1, 0);
3444 s390_j (code, 0); CODEPTR(code, o[1]);
3445 s390_xr (code, s390_r0, s390_r1);
3446 s390_msr (code, s390_r1, ins->sreg2);
3447 s390_xr (code, s390_r0, s390_r1);
3448 s390_srl (code, s390_r0, 0, 31);
3449 s390_ltr (code, s390_r0, s390_r0);
3450 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3451 PTRSLOT (code, o[0]);
3452 PTRSLOT (code, o[1]);
3453 s390_lgfr (code, ins->dreg, s390_r1);
3456 case OP_IMUL_OVF_UN: {
3457 s390_lhi (code, s390_r0, 0);
3458 s390_lr (code, s390_r1, ins->sreg1);
3459 s390_mlr (code, s390_r0, ins->sreg2);
3460 s390_ltr (code, s390_r0, s390_r0);
3461 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3462 s390_lgfr (code, ins->dreg, s390_r1);
3467 case OP_SETREGIMM: {
3468 if (s390_is_imm16(ins->inst_c0)) {
3469 s390_lghi (code, ins->dreg, ins->inst_c0);
3471 s390_basr (code, s390_r13, 0);
3473 s390_llong(code, ins->inst_c0);
3474 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3479 s390_basr (code, s390_r13, 0);
3481 mono_add_patch_info (cfg, code - cfg->native_code,
3482 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3483 s390_llong(code, 0);
3484 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3491 if (ins->dreg != ins->sreg1) {
3492 s390_lgr (code, ins->dreg, ins->sreg1);
3497 s390_lgfr (code, ins->dreg, ins->sreg1);
3502 s390_llgfr (code, ins->dreg, ins->sreg1);
3504 case CEE_CONV_OVF_U4:
3505 s390_basr (code, s390_r13, 0);
3507 s390_llong(code, 4294967295);
3508 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3509 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3510 s390_ltgr (code, ins->sreg1, ins->sreg1);
3511 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3512 s390_llgfr(code, ins->dreg, ins->sreg1);
3514 case CEE_CONV_OVF_I4_UN:
3515 s390_basr (code, s390_r13, 0);
3517 s390_llong(code, 2147483647);
3518 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3519 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3520 s390_ltgr (code, ins->sreg1, ins->sreg1);
3521 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3522 s390_lgfr (code, ins->dreg, ins->sreg1);
3526 if (ins->dreg != ins->sreg1) {
3527 s390_ldr (code, ins->dreg, ins->sreg1);
3531 case OP_S390_SETF4RET: {
3532 s390_ledbr (code, ins->dreg, ins->sreg1);
3535 case OP_FCONV_TO_R4: {
3536 g_error ("Shouldn't be reached");
3538 (ins->next->opcode != OP_FMOVE) &&
3539 (ins->next->opcode != OP_STORER4_MEMBASE_REG))
3540 s390_ledbr (code, ins->dreg, ins->sreg1);
3544 if (cfg->method->save_lmf)
3545 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3547 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3548 code = emit_load_volatile_registers(code, cfg);
3551 code = backUpStackPtr(cfg, code);
3552 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3553 mono_add_patch_info (cfg, code - cfg->native_code,
3554 MONO_PATCH_INFO_METHOD_JUMP,
3556 s390_jcl (code, S390_CC_UN, 0);
3559 case OP_CHECK_THIS: {
3560 /* ensure ins->sreg1 is not NULL */
3561 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3562 s390_ltgr (code, s390_r0, s390_r0);
3566 int offset = cfg->sig_cookie + cfg->stack_usage;
3568 if (s390_is_imm16 (offset))
3569 s390_lghi (code, s390_r0, offset);
3571 s390_basr (code, s390_r13, 0);
3573 s390_llong(code, offset);
3574 s390_lg (code, s390_r0, 0, s390_r13, 0);
3576 s390_agr (code, s390_r0, cfg->frame_reg);
3577 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3581 s390_basr (code, s390_r13, 0);
3583 call = (MonoCallInst*)ins;
3584 if (ins->flags & MONO_INST_HAS_METHOD)
3585 mono_add_patch_info (cfg, code-cfg->native_code,
3586 MONO_PATCH_INFO_METHOD,
3589 mono_add_patch_info (cfg, code-cfg->native_code,
3590 MONO_PATCH_INFO_ABS,
3592 s390_llong(code, 0);
3593 s390_lg (code, s390_r14, 0, s390_r13, 4);
3594 s390_basr (code, s390_r14, s390_r14);
3595 if (call->signature->ret->type == MONO_TYPE_R4)
3596 s390_ldebr (code, s390_f0, s390_f0);
3603 s390_basr (code, s390_r13, 0);
3605 call = (MonoCallInst*)ins;
3606 if (ins->flags & MONO_INST_HAS_METHOD)
3607 mono_add_patch_info (cfg, code-cfg->native_code,
3608 MONO_PATCH_INFO_METHOD,
3611 mono_add_patch_info (cfg, code-cfg->native_code,
3612 MONO_PATCH_INFO_ABS,
3614 s390_llong(code, 0);
3615 s390_lg (code, s390_r14, 0, s390_r13, 4);
3616 s390_basr (code, s390_r14, s390_r14);
3619 case OP_FCALL_REG: {
3620 call = (MonoCallInst*)ins;
3621 s390_lgr (code, s390_r1, ins->sreg1);
3622 s390_basr (code, s390_r14, s390_r1);
3623 if (call->signature->ret->type == MONO_TYPE_R4)
3624 s390_ldebr (code, s390_f0, s390_f0);
3629 case OP_VOIDCALL_REG:
3631 s390_lgr (code, s390_r1, ins->sreg1);
3632 s390_basr (code, s390_r14, s390_r1);
3635 case OP_FCALL_MEMBASE: {
3636 call = (MonoCallInst*)ins;
3637 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3638 s390_basr (code, s390_r14, s390_r1);
3639 if (call->signature->ret->type == MONO_TYPE_R4)
3640 s390_ldebr (code, s390_f0, s390_f0);
3643 case OP_LCALL_MEMBASE:
3644 case OP_VCALL_MEMBASE:
3645 case OP_VOIDCALL_MEMBASE:
3646 case OP_CALL_MEMBASE: {
3647 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3648 s390_basr (code, s390_r14, s390_r1);
3652 g_assert_not_reached ();
3655 int alloca_skip = S390_MINIMAL_STACK_SIZE + cfg->param_area;
3656 int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3657 s390_lgr (code, s390_r1, ins->sreg1);
3658 if (ins->flags & MONO_INST_INIT)
3659 s390_lgr (code, s390_r0, ins->sreg1);
3660 s390_aghi (code, s390_r1, 14);
3661 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3662 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3663 if (cfg->method->save_lmf) {
3664 /*----------------------------------*/
3665 /* we have to adjust lmf ebp value */
3666 /*----------------------------------*/
3667 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3669 s390_lgr (code, s390_r13, cfg->frame_reg);
3670 if (s390_is_uimm16(lmfOffset))
3671 s390_aghi (code, s390_r13, lmfOffset);
3673 s390_basr (code, s390_r14, 0);
3675 s390_word (code, lmfOffset);
3676 s390_agf (code, s390_r13, 0, s390_r14, 4);
3678 s390_lgr (code, s390_r14, STK_BASE);
3679 s390_sgr (code, s390_r14, s390_r1);
3680 s390_stg (code, s390_r14, 0, s390_r13,
3681 G_STRUCT_OFFSET(MonoLMF, ebp));
3683 s390_lg (code, s390_r13, 0, STK_BASE, 0);
3684 s390_sgr (code, STK_BASE, s390_r1);
3685 s390_stg (code, s390_r13, 0, STK_BASE, 0);
3686 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
3687 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
3688 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
3689 if (ins->flags & MONO_INST_INIT) {
3690 s390_lgr (code, s390_r1, s390_r0);
3691 s390_lgr (code, s390_r0, ins->dreg);
3692 s390_lgr (code, s390_r14, s390_r12);
3693 s390_lghi (code, s390_r13, 0);
3694 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
3696 s390_lgr (code, s390_r12, s390_r14);
3701 s390_br (code, s390_r14);
3705 s390_lgr (code, s390_r2, ins->sreg1);
3706 s390_basr (code, s390_r13, 0);
3708 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3709 (gpointer) "mono_arch_throw_exception");
3710 s390_llong(code, 0);
3711 s390_lg (code, s390_r14, 0, s390_r13, 4);
3712 s390_basr (code, s390_r14, s390_r14);
3716 s390_lgr (code, s390_r2, ins->sreg1);
3717 s390_basr (code, s390_r13, 0);
3719 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3720 (gpointer) "mono_arch_rethrow_exception");
3721 s390_llong(code, 0);
3722 s390_lg (code, s390_r14, 0, s390_r13, 4);
3723 s390_basr (code, s390_r14, s390_r14);
3726 case OP_START_HANDLER: {
3727 S390_LONG (code, stg, stg, s390_r14, 0,
3728 ins->inst_left->inst_basereg,
3729 ins->inst_left->inst_offset);
3732 case OP_ENDFILTER: {
3733 if (ins->sreg1 != s390_r2)
3734 s390_lgr(code, s390_r2, ins->sreg1);
3735 S390_LONG (code, lg, lg, s390_r14, 0,
3736 ins->inst_left->inst_basereg,
3737 ins->inst_left->inst_offset);
3738 s390_br (code, s390_r14);
3741 case CEE_ENDFINALLY: {
3742 S390_LONG (code, lg, lg, s390_r14, 0,
3743 ins->inst_left->inst_basereg,
3744 ins->inst_left->inst_offset);
3745 s390_br (code, s390_r14);
3748 case OP_CALL_HANDLER: {
3749 mono_add_patch_info (cfg, code-cfg->native_code,
3750 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3751 s390_brasl (code, s390_r14, 0);
3755 ins->inst_c0 = code - cfg->native_code;
3759 EMIT_UNCOND_BRANCH(ins);
3762 s390_br (code, ins->sreg1);
3767 s390_lghi(code, ins->dreg, 1);
3769 s390_lghi(code, ins->dreg, 0);
3774 s390_lghi(code, ins->dreg, 1);
3776 s390_lghi(code, ins->dreg, 0);
3781 s390_lghi(code, ins->dreg, 1);
3783 s390_lghi(code, ins->dreg, 0);
3788 s390_lghi(code, ins->dreg, 1);
3790 s390_lghi(code, ins->dreg, 0);
3795 s390_lghi(code, ins->dreg, 1);
3797 s390_lghi(code, ins->dreg, 0);
3800 case OP_COND_EXC_EQ:
3801 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
3803 case OP_COND_EXC_NE_UN:
3804 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
3806 case OP_COND_EXC_LT:
3807 case OP_COND_EXC_LT_UN:
3808 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
3810 case OP_COND_EXC_GT:
3811 case OP_COND_EXC_GT_UN:
3812 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
3814 case OP_COND_EXC_GE:
3815 case OP_COND_EXC_GE_UN:
3816 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
3818 case OP_COND_EXC_LE:
3819 case OP_COND_EXC_LE_UN:
3820 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
3822 case OP_COND_EXC_OV:
3823 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
3825 case OP_COND_EXC_NO:
3826 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
3829 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
3831 case OP_COND_EXC_NC:
3832 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
3836 EMIT_COND_BRANCH (ins, S390_CC_EQ);
3840 EMIT_COND_BRANCH (ins, S390_CC_NE);
3846 EMIT_COND_BRANCH (ins, S390_CC_LT);
3852 EMIT_COND_BRANCH (ins, S390_CC_GT);
3858 EMIT_COND_BRANCH (ins, S390_CC_GE);
3864 EMIT_COND_BRANCH (ins, S390_CC_LE);
3867 /* floating point opcodes */
3869 if (*((float *) ins->inst_p0) == 0) {
3870 s390_lzdr (code, ins->dreg);
3872 s390_basr (code, s390_r13, 0);
3874 s390_llong (code, ins->inst_p0);
3875 s390_lg (code, s390_r13, 0, s390_r13, 4);
3876 s390_ld (code, ins->dreg, 0, s390_r13, 0);
3881 if (*((float *) ins->inst_p0) == 0) {
3882 s390_lzdr (code, ins->dreg);
3884 s390_basr (code, s390_r13, 0);
3886 s390_llong(code, ins->inst_p0);
3887 s390_lg (code, s390_r13, 0, s390_r13, 4);
3888 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
3892 case OP_STORER8_MEMBASE_REG: {
3893 S390_LONG (code, stdy, std, ins->sreg1, 0,
3894 ins->inst_destbasereg, ins->inst_offset);
3897 case OP_LOADR8_MEMBASE: {
3898 S390_LONG (code, ldy, ld, ins->dreg, 0,
3899 ins->inst_basereg, ins->inst_offset);
3902 case OP_STORER4_MEMBASE_REG: {
3903 s390_ledbr (code, s390_f15, ins->sreg1);
3904 S390_LONG (code, stey, ste, s390_f15, 0,
3905 ins->inst_destbasereg, ins->inst_offset);
3908 case OP_LOADR4_MEMBASE: {
3909 S390_LONG (code, ldy, ld, s390_f15, 0,
3910 ins->inst_basereg, ins->inst_offset);
3911 s390_ldebr (code, ins->dreg, s390_f15);
3914 case CEE_CONV_R_UN: {
3915 s390_cdgbr (code, ins->dreg, ins->sreg1);
3916 s390_ltgr (code, ins->sreg1, ins->sreg1);
3917 s390_jnl (code, 12);
3918 s390_basr (code, s390_r13, 0);
3920 s390_word (code, 0x41f00000);
3921 s390_word (code, 0);
3922 s390_adb (code, ins->dreg, 0, s390_r13, 4);
3925 case OP_LCONV_TO_R4:
3927 s390_cdgbr (code, ins->dreg, ins->sreg1);
3930 case OP_LCONV_TO_R8:
3932 s390_cdgbr (code, ins->dreg, ins->sreg1);
3935 case OP_FCONV_TO_I1:
3936 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
3938 case OP_FCONV_TO_U1:
3939 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
3941 case OP_FCONV_TO_I2:
3942 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
3944 case OP_FCONV_TO_U2:
3945 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
3947 case OP_FCONV_TO_I4:
3949 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
3951 case OP_FCONV_TO_U4:
3953 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
3955 case OP_FCONV_TO_I8:
3956 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
3958 case OP_FCONV_TO_U8:
3959 g_assert_not_reached ();
3960 /* Implemented as helper calls */
3962 case OP_LCONV_TO_R_UN:
3963 g_assert_not_reached ();
3964 /* Implemented as helper calls */
3966 case OP_LCONV_TO_OVF_I: {
3967 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
3969 s390_ltgr (code, ins->sreg2, ins->sreg2);
3970 s390_jnl (code, 0); CODEPTR(code, o[0]);
3971 s390_ltgr (code, ins->sreg1, ins->sreg1);
3972 s390_jnl (code, 0); CODEPTR(code, o[1]);
3973 s390_lhi (code, s390_r13, -1);
3974 s390_cgr (code, ins->sreg1, s390_r13);
3975 s390_jnz (code, 0); CODEPTR(code, o[2]);
3976 if (ins->dreg != ins->sreg2)
3977 s390_lgr (code, ins->dreg, ins->sreg2);
3978 s390_j (code, 0); CODEPTR(code, o[3]);
3979 PTRSLOT(code, o[0]);
3980 s390_jz (code, 0); CODEPTR(code, o[4]);
3981 PTRSLOT(code, o[1]);
3982 PTRSLOT(code, o[2]);
3983 mono_add_patch_info (cfg, code - cfg->native_code,
3984 MONO_PATCH_INFO_EXC, "OverflowException");
3985 s390_brasl (code, s390_r14, 0);
3986 PTRSLOT(code, o[3]);
3987 PTRSLOT(code, o[4]);
3991 s390_lpdbr (code, ins->dreg, ins->sreg1);
3995 s390_sqdbr (code, ins->dreg, ins->sreg1);
4000 s390_adbr (code, ins->dreg, src2);
4004 CHECK_SRCDST_NCOM_F;
4005 s390_sdbr (code, ins->dreg, src2);
4010 s390_mdbr (code, ins->dreg, src2);
4014 CHECK_SRCDST_NCOM_F;
4015 s390_ddbr (code, ins->dreg, src2);
4019 s390_lcdbr (code, ins->dreg, ins->sreg1);
4023 CHECK_SRCDST_NCOM_F;
4024 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4028 s390_cdbr (code, ins->sreg1, ins->sreg2);
4032 s390_cdbr (code, ins->sreg1, ins->sreg2);
4033 s390_lghi (code, ins->dreg, 1);
4035 s390_lghi (code, ins->dreg, 0);
4039 s390_cdbr (code, ins->sreg1, ins->sreg2);
4040 s390_lghi (code, ins->dreg, 1);
4042 s390_lghi (code, ins->dreg, 0);
4046 s390_cdbr (code, ins->sreg1, ins->sreg2);
4047 s390_lghi (code, ins->dreg, 1);
4049 s390_lghi (code, ins->dreg, 0);
4053 s390_cdbr (code, ins->sreg1, ins->sreg2);
4054 s390_lghi (code, ins->dreg, 1);
4056 s390_lghi (code, ins->dreg, 0);
4060 s390_cdbr (code, ins->sreg1, ins->sreg2);
4061 s390_lghi (code, ins->dreg, 1);
4063 s390_lghi (code, ins->dreg, 0);
4067 EMIT_COND_BRANCH (ins, S390_CC_EQ|S390_CC_OV);
4070 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4073 EMIT_COND_BRANCH (ins, S390_CC_LT);
4076 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4079 EMIT_COND_BRANCH (ins, S390_CC_GT);
4082 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4085 EMIT_COND_BRANCH (ins, S390_CC_GE);
4088 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4091 EMIT_COND_BRANCH (ins, S390_CC_LE);
4094 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4096 case CEE_CKFINITE: {
4098 s390_lhi (code, s390_r13, 0x7f);
4099 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4100 s390_jz (code, 0); CODEPTR(code, o);
4101 mono_add_patch_info (cfg, code - cfg->native_code,
4102 MONO_PATCH_INFO_EXC, "ArithmeticException");
4103 s390_brasl (code, s390_r14,0);
4107 case OP_S390_MOVE: {
4108 if (ins->backend.size > 0) {
4109 if (ins->backend.size <= 256) {
4110 s390_mvc (code, ins->backend.size, ins->dreg,
4111 ins->inst_offset, ins->sreg1, ins->inst_imm);
4113 s390_lgr (code, s390_r0, ins->dreg);
4114 if (s390_is_imm16 (ins->inst_offset)) {
4115 s390_aghi (code, s390_r0, ins->inst_offset);
4117 s390_basr (code, s390_r13, 0);
4119 s390_llong(code, ins->inst_offset);
4120 s390_a (code, s390_r0, 0, s390_r13, 4);
4122 s390_lgr (code, s390_r12, ins->sreg1);
4123 if (s390_is_imm16 (ins->inst_imm)) {
4124 s390_aghi (code, s390_r12, ins->inst_imm);
4126 s390_basr (code, s390_r13, 0);
4128 s390_llong(code, ins->inst_imm);
4129 s390_ag (code, s390_r12, 0, s390_r13, 4);
4131 s390_lgr (code, s390_r1, ins->sreg1);
4132 s390_lgr (code, s390_r13, s390_r1);
4133 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4139 case OP_ATOMIC_ADD_I8: {
4140 s390_lgr (code, s390_r1, ins->sreg2);
4141 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4142 s390_agr (code, s390_r1, s390_r0);
4143 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4144 s390_jnz (code, -10);
4145 s390_lgr (code, ins->dreg, s390_r1);
4148 case OP_ATOMIC_ADD_NEW_I8: {
4149 s390_lgr (code, s390_r1, ins->sreg2);
4150 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4151 s390_agr (code, s390_r1, s390_r0);
4152 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4153 s390_jnz (code, -10);
4154 s390_lgr (code, ins->dreg, s390_r1);
4157 case OP_ATOMIC_EXCHANGE_I8: {
4158 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4159 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4160 s390_jnz (code, -6);
4161 s390_lgr (code, ins->dreg, s390_r0);
4164 case OP_ATOMIC_ADD_I4: {
4165 s390_lgfr(code, s390_r1, ins->sreg2);
4166 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4167 s390_agr (code, s390_r1, s390_r0);
4168 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4169 s390_jnz (code, -9);
4170 s390_lgfr(code, ins->dreg, s390_r1);
4173 case OP_ATOMIC_ADD_NEW_I4: {
4174 s390_lgfr(code, s390_r1, ins->sreg2);
4175 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4176 s390_agr (code, s390_r1, s390_r0);
4177 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4178 s390_jnz (code, -9);
4179 s390_lgfr(code, ins->dreg, s390_r1);
4182 case OP_ATOMIC_EXCHANGE_I4: {
4183 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4184 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4185 s390_jnz (code, -4);
4186 s390_lgfr(code, ins->dreg, s390_r0);
4189 case OP_S390_BKCHAIN: {
4190 s390_lgr (code, ins->dreg, ins->sreg1);
4191 if (s390_is_imm16 (cfg->stack_offset)) {
4192 s390_aghi (code, ins->dreg, cfg->stack_offset);
4194 s390_basr (code, s390_r13, 0);
4196 s390_llong(code, cfg->stack_offset);
4197 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4201 case OP_MEMORY_BARRIER: {
4205 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4206 g_assert_not_reached ();
4209 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4210 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4211 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4212 g_assert_not_reached ();
4218 last_offset = offset;
4223 cfg->code_len = code - cfg->native_code;
4226 /*========================= End of Function ========================*/
4228 /*------------------------------------------------------------------*/
4230 /* Name - mono_arch_register_lowlevel_calls */
4232 /* Function - Register routines to help with --trace operation. */
4234 /*------------------------------------------------------------------*/
4237 mono_arch_register_lowlevel_calls (void)
4239 mono_register_jit_icall (mono_arch_break, "mono_arch_break", NULL, TRUE);
4240 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4243 /*========================= End of Function ========================*/
4245 /*------------------------------------------------------------------*/
4247 /* Name - mono_arch_break */
4249 /* Function - Process a "break" operation for debugging. */
4251 /*------------------------------------------------------------------*/
4254 mono_arch_break(void) {
4257 /*========================= End of Function ========================*/
4259 /*------------------------------------------------------------------*/
4261 /* Name - mono_arch_patch_code */
4263 /* Function - Process the patch data created during the */
4264 /* instruction build process. This resolves jumps, */
4265 /* calls, variables etc. */
4267 /*------------------------------------------------------------------*/
4270 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4271 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4273 MonoJumpInfo *patch_info;
4275 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4276 unsigned char *ip = patch_info->ip.i + code;
4277 gconstpointer target = NULL;
4279 target = mono_resolve_patch_target (method, domain, code,
4280 patch_info, run_cctors);
4282 switch (patch_info->type) {
4283 case MONO_PATCH_INFO_IP:
4284 case MONO_PATCH_INFO_EXC_NAME:
4285 case MONO_PATCH_INFO_LDSTR:
4286 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4287 case MONO_PATCH_INFO_LDTOKEN:
4288 case MONO_PATCH_INFO_EXC:
4289 case MONO_PATCH_INFO_ABS:
4290 case MONO_PATCH_INFO_METHOD:
4291 case MONO_PATCH_INFO_INTERNAL_METHOD:
4292 case MONO_PATCH_INFO_CLASS_INIT:
4293 s390_patch_addr (ip, (guint64) target);
4295 case MONO_PATCH_INFO_SWITCH:
4296 /*----------------------------------*/
4297 /* ip points at the basr r13,0/j +4 */
4298 /* instruction the vtable value */
4299 /* follows this (i.e. ip+6) */
4300 /*----------------------------------*/
4301 *((gconstpointer *)(ip+6)) = target;
4303 case MONO_PATCH_INFO_METHODCONST:
4304 case MONO_PATCH_INFO_CLASS:
4305 case MONO_PATCH_INFO_IMAGE:
4306 case MONO_PATCH_INFO_FIELD:
4307 case MONO_PATCH_INFO_IID:
4308 target = S390_RELATIVE(target, ip);
4309 s390_patch_rel (ip, (guint64) target);
4311 case MONO_PATCH_INFO_R4:
4312 case MONO_PATCH_INFO_R8:
4313 case MONO_PATCH_INFO_METHOD_REL:
4314 g_assert_not_reached ();
4317 target = S390_RELATIVE(target, ip);
4319 s390_patch_rel (ip, (guint64) target);
4324 /*========================= End of Function ========================*/
4326 /*------------------------------------------------------------------*/
4328 /* Name - emit_load_volatile_registers */
4330 /* Function - Emit the instructions to reload parameter regist- */
4331 /* registers for use with "tail" operations. */
4333 /* The register loading operations performed here */
4334 /* are the mirror of the store operations performed */
4335 /* in mono_arch_emit_prolog and need to be kept in */
4336 /* synchronization with it. */
4338 /*------------------------------------------------------------------*/
4341 emit_load_volatile_registers (guint8 *code, MonoCompile *cfg)
4344 MonoMethod *method = cfg->method;
4345 MonoMethodSignature *sig = mono_method_signature(method);
4350 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
4352 if (cinfo->struct_ret) {
4353 ArgInfo *ainfo = &cinfo->ret;
4355 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4358 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4359 ArgInfo *ainfo = cinfo->args + i;
4360 inst = cfg->varinfo [pos];
4362 if (inst->opcode == OP_REGVAR) {
4363 if (ainfo->regtype == RegTypeGeneral)
4364 s390_lgr (code, ainfo->reg, inst->dreg);
4365 else if (ainfo->regtype == RegTypeFP) {
4366 if (inst->dreg != ainfo->reg) {
4367 if (ainfo->size == 4) {
4368 s390_ldebr (code, ainfo->reg, inst->dreg);
4370 s390_ldr (code, ainfo->reg, inst->dreg);
4374 else if (ainfo->regtype == RegTypeBase) {
4376 g_assert_not_reached ();
4378 if (ainfo->regtype == RegTypeGeneral) {
4379 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4380 g_assert_not_reached();
4381 switch (ainfo->size) {
4383 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4386 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4389 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4392 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4395 } else if (ainfo->regtype == RegTypeBase) {
4396 } else if (ainfo->regtype == RegTypeFP) {
4397 if (ainfo->size == 8)
4398 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4399 else if (ainfo->size == 4)
4400 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4402 g_assert_not_reached ();
4403 } else if (ainfo->regtype == RegTypeStructByVal) {
4404 if (ainfo->reg != STK_BASE) {
4405 switch (ainfo->size) {
4407 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4410 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4413 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4416 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4420 } else if (ainfo->regtype == RegTypeStructByAddr) {
4421 if (ainfo->reg != STK_BASE) {
4422 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4425 g_assert_not_reached ();
4435 /*========================= End of Function ========================*/
4437 /*------------------------------------------------------------------*/
4439 /* Name - mono_arch_emit_prolog */
4441 /* Function - Create the instruction sequence for a function */
4444 /*------------------------------------------------------------------*/
4447 mono_arch_emit_prolog (MonoCompile *cfg)
4449 MonoMethod *method = cfg->method;
4451 MonoMethodSignature *sig;
4453 int alloc_size, pos, max_offset, i;
4460 cfg->code_size = 512;
4462 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4464 cfg->code_size += 256;
4467 if (method->save_lmf)
4468 cfg->code_size += 200;
4470 cfg->native_code = code = g_malloc (cfg->code_size);
4472 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4474 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4475 cfg->used_int_regs |= 1 << 11;
4478 alloc_size = cfg->stack_offset;
4480 cfg->stack_usage = alloc_size;
4481 s390_lgr (code, s390_r11, STK_BASE);
4482 if (s390_is_uimm16 (alloc_size)) {
4483 s390_aghi (code, STK_BASE, -alloc_size);
4485 int stackSize = alloc_size;
4486 while (stackSize > 32767) {
4487 s390_aghi (code, STK_BASE, -32767);
4490 s390_aghi (code, STK_BASE, -stackSize);
4492 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4494 if (cfg->frame_reg != STK_BASE)
4495 s390_lgr (code, s390_r11, STK_BASE);
4497 /* compute max_offset in order to use short forward jumps
4498 * we always do it on s390 because the immediate displacement
4499 * for jumps is too small
4502 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4503 MonoInst *ins = bb->code;
4504 bb->max_offset = max_offset;
4506 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4510 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4515 /* load arguments allocated to register from the stack */
4516 sig = mono_method_signature (method);
4519 cinfo = calculate_sizes (sig, &sz, sig->pinvoke);
4521 if (cinfo->struct_ret) {
4522 ArgInfo *ainfo = &cinfo->ret;
4524 inst->backend.size = ainfo->vtsize;
4525 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4528 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4529 ArgInfo *ainfo = cinfo->args + i;
4530 inst = cfg->varinfo [pos];
4532 if (inst->opcode == OP_REGVAR) {
4533 if (ainfo->regtype == RegTypeGeneral)
4534 s390_lgr (code, inst->dreg, ainfo->reg);
4535 else if (ainfo->regtype == RegTypeFP) {
4536 if (inst->dreg != ainfo->reg) {
4537 if (ainfo->size == 4) {
4538 s390_ledbr (code, inst->dreg, ainfo->reg);
4540 s390_ldr (code, inst->dreg, ainfo->reg);
4544 else if (ainfo->regtype == RegTypeBase) {
4545 s390_lgr (code, s390_r13, STK_BASE);
4546 s390_aghi (code, s390_r13, alloc_size);
4547 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4549 g_assert_not_reached ();
4551 if (cfg->verbose_level > 2)
4552 g_print ("Argument %d assigned to register %s\n",
4553 pos, mono_arch_regname (inst->dreg));
4555 if (ainfo->regtype == RegTypeGeneral) {
4556 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4557 g_assert_not_reached();
4558 switch (ainfo->size) {
4560 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4563 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4566 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4569 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4572 } else if (ainfo->regtype == RegTypeBase) {
4573 } else if (ainfo->regtype == RegTypeFP) {
4574 if (ainfo->size == 8)
4575 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4576 else if (ainfo->size == 4)
4577 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4579 g_assert_not_reached ();
4580 } else if (ainfo->regtype == RegTypeStructByVal) {
4581 int doffset = inst->inst_offset;
4583 if (ainfo->reg != STK_BASE)
4587 s390_lgr (code, s390_r13, STK_BASE);
4588 s390_aghi (code, s390_r13, alloc_size);
4590 switch (ainfo->size) {
4592 if (ainfo->reg == STK_BASE)
4593 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
4594 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4597 if (ainfo->reg == STK_BASE)
4598 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
4599 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4602 if (ainfo->reg == STK_BASE)
4603 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
4604 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4607 if (ainfo->reg == STK_BASE)
4608 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
4609 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
4612 } else if (ainfo->regtype == RegTypeStructByAddr) {
4613 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4615 g_assert_not_reached ();
4620 if (method->save_lmf) {
4621 /*---------------------------------------------------------------*/
4622 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4623 /*---------------------------------------------------------------*/
4624 lmfOffset = alloc_size - sizeof(MonoLMF);
4626 s390_lgr (code, s390_r13, cfg->frame_reg);
4627 s390_aghi (code, s390_r13, lmfOffset);
4629 /*---------------------------------------------------------------*/
4630 /* Preserve the parameter registers while we fix up the lmf */
4631 /*---------------------------------------------------------------*/
4632 s390_stmg (code, s390_r2, s390_r6, s390_r13,
4633 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4635 /*---------------------------------------------------------------*/
4636 /* On return from this call r2 have the address of the &lmf */
4637 /*---------------------------------------------------------------*/
4638 s390_basr(code, s390_r10, 0);
4640 mono_add_patch_info (cfg, code - cfg->native_code,
4641 MONO_PATCH_INFO_INTERNAL_METHOD,
4642 (gpointer)"mono_get_lmf_addr");
4643 s390_llong(code, 0);
4644 s390_lg (code, s390_r1, 0, s390_r10, 4);
4645 s390_basr (code, s390_r14, s390_r1);
4647 /*---------------------------------------------------------------*/
4648 /* Set lmf.lmf_addr = jit_tls->lmf */
4649 /*---------------------------------------------------------------*/
4650 s390_stg (code, s390_r2, 0, s390_r13,
4651 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4653 /*---------------------------------------------------------------*/
4654 /* Get current lmf */
4655 /*---------------------------------------------------------------*/
4656 s390_lg (code, s390_r0, 0, s390_r2, 0);
4658 /*---------------------------------------------------------------*/
4659 /* Set our lmf as the current lmf */
4660 /*---------------------------------------------------------------*/
4661 s390_stg (code, s390_r13, 0, s390_r2, 0);
4663 /*---------------------------------------------------------------*/
4664 /* Have our lmf.previous_lmf point to the last lmf */
4665 /*---------------------------------------------------------------*/
4666 s390_stg (code, s390_r0, 0, s390_r13,
4667 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4669 /*---------------------------------------------------------------*/
4670 /* save method info */
4671 /*---------------------------------------------------------------*/
4672 s390_basr (code, s390_r1, 0);
4674 s390_llong (code, method);
4675 s390_lg (code, s390_r1, 0, s390_r1, 4);
4676 s390_stg (code, s390_r1, 0, s390_r13,
4677 G_STRUCT_OFFSET(MonoLMF, method));
4679 /*---------------------------------------------------------------*/
4680 /* save the current IP */
4681 /*---------------------------------------------------------------*/
4682 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4683 s390_basr (code, s390_r1, 0);
4684 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4686 /*---------------------------------------------------------------*/
4687 /* Save general and floating point registers */
4688 /*---------------------------------------------------------------*/
4689 s390_stmg (code, s390_r2, s390_r12, s390_r13,
4690 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
4691 for (i = 0; i < 16; i++) {
4692 s390_std (code, i, 0, s390_r13,
4693 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
4696 /*---------------------------------------------------------------*/
4697 /* Restore the parameter registers now that we've set up the lmf */
4698 /*---------------------------------------------------------------*/
4699 s390_lmg (code, s390_r2, s390_r6, s390_r13,
4700 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4704 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
4706 cfg->code_len = code - cfg->native_code;
4707 g_assert (cfg->code_len < cfg->code_size);
4714 /*========================= End of Function ========================*/
4716 /*------------------------------------------------------------------*/
4718 /* Name - mono_arch_emit_epilog */
4720 /* Function - Emit the instructions for a function epilog. */
4722 /*------------------------------------------------------------------*/
4725 mono_arch_emit_epilog (MonoCompile *cfg)
4727 MonoMethod *method = cfg->method;
4730 int max_epilog_size = 96;
4732 if (cfg->method->save_lmf)
4733 max_epilog_size += 128;
4735 if (mono_jit_trace_calls != NULL)
4736 max_epilog_size += 128;
4738 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4739 max_epilog_size += 128;
4741 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
4742 cfg->code_size *= 2;
4743 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
4744 mono_jit_stats.code_reallocs++;
4747 code = cfg->native_code + cfg->code_len;
4749 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4750 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
4754 if (method->save_lmf)
4755 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4757 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
4758 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
4760 code = backUpStackPtr(cfg, code);
4762 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4763 s390_br (code, s390_r14);
4765 cfg->code_len = code - cfg->native_code;
4767 g_assert (cfg->code_len < cfg->code_size);
4771 /*========================= End of Function ========================*/
4773 /*------------------------------------------------------------------*/
4775 /* Name - mono_arch_emit_exceptions */
4777 /* Function - Emit the blocks to handle exception conditions. */
4779 /*------------------------------------------------------------------*/
4782 mono_arch_emit_exceptions (MonoCompile *cfg)
4784 MonoJumpInfo *patch_info;
4790 MonoClass *exc_classes [MAX_EXC];
4791 guint8 *exc_throw_start [MAX_EXC],
4792 *exc_throw_end [MAX_EXC];
4794 for (patch_info = cfg->patch_info;
4796 patch_info = patch_info->next) {
4797 if (patch_info->type == MONO_PATCH_INFO_EXC)
4801 code_size = exc_count * 48;
4803 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
4804 cfg->code_size *= 2;
4805 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
4806 mono_jit_stats.code_reallocs++;
4809 code = cfg->native_code + cfg->code_len;
4811 /*---------------------------------------------------------------------*/
4812 /* Add code to raise exceptions */
4813 /*---------------------------------------------------------------------*/
4814 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
4815 switch (patch_info->type) {
4816 case MONO_PATCH_INFO_EXC: {
4817 guint8 *ip = patch_info->ip.i + cfg->native_code;
4818 MonoClass *exc_class;
4821 /*-----------------------------------------------------*/
4822 /* Patch the branch in epilog to come here */
4823 /*-----------------------------------------------------*/
4824 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
4826 exc_class = mono_class_from_name (mono_defaults.corlib,
4828 patch_info->data.name);
4829 g_assert (exc_class);
4830 throw_ip = patch_info->ip.i;
4832 for (iExc = 0; iExc < nThrows; ++iExc)
4833 if (exc_classes [iExc] == exc_class)
4836 if (iExc < nThrows) {
4837 s390_jcl (code, S390_CC_UN,
4838 (guint64) exc_throw_start [iExc]);
4839 patch_info->type = MONO_PATCH_INFO_NONE;
4842 if (nThrows < MAX_EXC) {
4843 exc_classes [nThrows] = exc_class;
4844 exc_throw_start [nThrows] = code;
4847 /*---------------------------------------------*/
4848 /* Patch the parameter passed to the handler */
4849 /*---------------------------------------------*/
4850 s390_basr (code, s390_r13, 0);
4852 s390_llong(code, patch_info->data.target);
4853 /*---------------------------------------------*/
4854 /* Load return address & parameter register */
4855 /*---------------------------------------------*/
4856 s390_larl (code, s390_r14, S390_RELATIVE((patch_info->ip.i +
4857 cfg->native_code + 8), code));
4858 s390_lg (code, s390_r2, 0, s390_r13, 4);
4859 /*---------------------------------------------*/
4860 /* Reuse the current patch to set the jump */
4861 /*---------------------------------------------*/
4862 s390_basr (code, s390_r13, 0);
4864 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
4865 patch_info->data.name = "mono_arch_throw_exception_by_name";
4866 patch_info->ip.i = code - cfg->native_code;
4867 s390_llong(code, 0);
4868 s390_lg (code, s390_r1, 0, s390_r13, 4);
4869 s390_br (code, s390_r1);
4879 cfg->code_len = code - cfg->native_code;
4881 g_assert (cfg->code_len < cfg->code_size);
4885 /*========================= End of Function ========================*/
4887 /*------------------------------------------------------------------*/
4889 /* Name - mono_arch_setup_jit_tls_data */
4891 /* Function - Setup the JIT's Thread Level Specific Data. */
4893 /*------------------------------------------------------------------*/
4896 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
4898 if (!tls_offset_inited) {
4899 tls_offset_inited = TRUE;
4903 __asm__ ("\tear\t%r1,0\n"
4910 : "=r" (appdomain_tls_offset),
4911 "=r" (thread_tls_offset),
4912 "=r" (lmf_tls_offset)
4913 : "r" (&tls_appdomain),
4914 "r" (&tls_current_object),
4915 "r" (&mono_lmf_addr)
4921 if (!lmf_addr_key_inited) {
4922 lmf_addr_key_inited = TRUE;
4923 pthread_key_create (&lmf_addr_key, NULL);
4925 pthread_setspecific (lmf_addr_key, &tls->lmf);
4929 /*========================= End of Function ========================*/
4931 /*------------------------------------------------------------------*/
4933 /* Name - mono_arch_free_jit_tls_data */
4935 /* Function - Free tls data. */
4937 /*------------------------------------------------------------------*/
4940 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
4945 /*========================= End of Function ========================*/
4947 /*------------------------------------------------------------------*/
4949 /* Name - mono_arch_emit_this_vret_args */
4953 /*------------------------------------------------------------------*/
4956 mono_arch_emit_this_vret_args (MonoCompile *cfg, MonoCallInst *inst, int this_reg, int this_type, int vt_reg)
4958 int this_dreg = s390_r2;
4961 this_dreg = s390_r3;
4963 /* add the this argument */
4964 if (this_reg != -1) {
4966 MONO_INST_NEW (cfg, this, OP_SETREG);
4967 this->type = this_type;
4968 this->sreg1 = this_reg;
4969 this->dreg = mono_regstate_next_int (cfg->rs);
4970 mono_bblock_add_inst (cfg->cbb, this);
4971 mono_call_inst_add_outarg_reg (cfg, inst, this->dreg, this_dreg, FALSE);
4976 MONO_INST_NEW (cfg, vtarg, OP_SETREG);
4977 vtarg->type = STACK_MP;
4978 vtarg->sreg1 = vt_reg;
4979 vtarg->dreg = mono_regstate_next_int (cfg->rs);
4980 mono_bblock_add_inst (cfg->cbb, vtarg);
4981 mono_call_inst_add_outarg_reg (cfg, inst, vtarg->dreg, s390_r2, FALSE);
4985 /*========================= End of Function ========================*/
4987 /*------------------------------------------------------------------*/
4989 /* Name - mono_arch_get_inst_for_method */
4991 /* Function - Check for opcodes we can handle directly in */
4994 /*------------------------------------------------------------------*/
4997 mono_arch_get_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod,
4998 MonoMethodSignature *fsig, MonoInst **args)
5000 MonoInst *ins = NULL;
5002 if (cmethod->klass == mono_defaults.math_class) {
5003 if (strcmp (cmethod->name, "Sqrt") == 0) {
5004 MONO_INST_NEW (cfg, ins, OP_SQRT);
5005 ins->inst_i0 = args [0];
5007 // if (strcmp (cmethod->name, "Abs") == 0) {
5008 // MONO_INST_NEW (cfg, ins, OP_ABS);
5009 // ins->inst_i0 = args [0];
5011 } else if (cmethod->klass == mono_defaults.thread_class &&
5012 strcmp (cmethod->name, "MemoryBarrier") == 0) {
5013 MONO_INST_NEW (cfg, ins, OP_MEMORY_BARRIER);
5014 } else if(cmethod->klass->image == mono_defaults.corlib &&
5015 (strcmp (cmethod->klass->name_space, "System.Threading") == 0) &&
5016 (strcmp (cmethod->klass->name, "Interlocked") == 0)) {
5018 if (strcmp (cmethod->name, "Increment") == 0) {
5019 MonoInst *ins_iconst;
5022 if (fsig->params [0]->type == MONO_TYPE_I4)
5023 opcode = OP_ATOMIC_ADD_NEW_I4;
5024 else if (fsig->params [0]->type == MONO_TYPE_I8)
5025 opcode = OP_ATOMIC_ADD_NEW_I8;
5027 g_assert_not_reached ();
5029 MONO_INST_NEW (cfg, ins, opcode);
5030 MONO_INST_NEW (cfg, ins_iconst, OP_ICONST);
5031 ins_iconst->inst_c0 = 1;
5033 ins->inst_i0 = args [0];
5034 ins->inst_i1 = ins_iconst;
5035 } else if (strcmp (cmethod->name, "Decrement") == 0) {
5036 MonoInst *ins_iconst;
5039 if (fsig->params [0]->type == MONO_TYPE_I4)
5040 opcode = OP_ATOMIC_ADD_NEW_I4;
5041 else if (fsig->params [0]->type == MONO_TYPE_I8)
5042 opcode = OP_ATOMIC_ADD_NEW_I8;
5044 g_assert_not_reached ();
5045 MONO_INST_NEW (cfg, ins, opcode);
5046 MONO_INST_NEW (cfg, ins_iconst, OP_ICONST);
5047 ins_iconst->inst_c0 = -1;
5049 ins->inst_i0 = args [0];
5050 ins->inst_i1 = ins_iconst;
5052 } else if (strcmp (cmethod->name, "Exchange") == 0) {
5055 if (fsig->params [0]->type == MONO_TYPE_I4)
5056 opcode = OP_ATOMIC_EXCHANGE_I4;
5057 else if ((fsig->params [0]->type == MONO_TYPE_I8) ||
5058 (fsig->params [0]->type == MONO_TYPE_I) ||
5059 (fsig->params [0]->type == MONO_TYPE_OBJECT))
5060 opcode = OP_ATOMIC_EXCHANGE_I8;
5064 MONO_INST_NEW (cfg, ins, opcode);
5066 ins->inst_i0 = args [0];
5067 ins->inst_i1 = args [1];
5068 } else if (strcmp (cmethod->name, "Add") == 0) {
5071 if (fsig->params [0]->type == MONO_TYPE_I4)
5072 opcode = OP_ATOMIC_ADD_I4;
5073 else if (fsig->params [0]->type == MONO_TYPE_I8)
5074 opcode = OP_ATOMIC_ADD_I8;
5076 g_assert_not_reached ();
5078 MONO_INST_NEW (cfg, ins, opcode);
5080 ins->inst_i0 = args [0];
5081 ins->inst_i1 = args [1];
5082 } else if ((strcmp (cmethod->name, "Read") == 0 &&
5083 (fsig->params [0]->type == MONO_TYPE_I8))) {
5084 MONO_INST_NEW (cfg, ins, CEE_LDIND_I8);
5085 ins->inst_i0 = args [0];
5091 /*========================= End of Function ========================*/
5093 /*------------------------------------------------------------------*/
5095 /* Name - mono_arch_print_tree */
5097 /* Function - Print platform-specific opcode details. */
5099 /* Returns - 1 - opcode details have been printed */
5100 /* 0 - opcode details have not been printed */
5102 /*------------------------------------------------------------------*/
5105 mono_arch_print_tree (MonoInst *tree, int arity)
5109 switch (tree->opcode) {
5110 case OP_S390_LOADARG:
5111 case OP_S390_ARGREG:
5112 case OP_S390_ARGPTR:
5113 printf ("[0x%lx(%s)]", tree->inst_offset,
5114 mono_arch_regname (tree->inst_basereg));
5117 case OP_S390_STKARG:
5118 printf ("[0x%lx(previous_frame)]",
5123 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5124 tree->inst_offset, tree->backend.size,
5125 mono_arch_regname(tree->dreg),
5127 mono_arch_regname(tree->sreg1));
5130 case OP_S390_SETF4RET:
5131 printf ("[f%s,f%s]",
5132 mono_arch_regname (tree->dreg),
5133 mono_arch_regname (tree->sreg1));
5137 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5139 mono_arch_regname (tree->sreg1));
5142 case OP_S390_BKCHAIN:
5143 printf ("[previous_frame(%s)]",
5144 mono_arch_regname (tree->sreg1));
5152 /*========================= End of Function ========================*/
5154 /*------------------------------------------------------------------*/
5156 /* Name - mono_arch_regalloc_cost */
5158 /* Function - Determine the cost, in the number of memory */
5159 /* references, of the action of allocating the var- */
5160 /* iable VMV into a register during global register */
5163 /* Returns - Cost */
5165 /*------------------------------------------------------------------*/
5168 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5174 /*========================= End of Function ========================*/
5176 /*------------------------------------------------------------------*/
5178 /* Name - mono_arch_get_domain_intrinsic */
5184 /*------------------------------------------------------------------*/
5187 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5191 if (appdomain_tls_offset == -1)
5194 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5195 ins->inst_offset = appdomain_tls_offset;
5199 /*========================= End of Function ========================*/
5201 /*------------------------------------------------------------------*/
5203 /* Name - mono_arch_get_thread_intrinsic */
5209 /*------------------------------------------------------------------*/
5212 mono_arch_get_thread_intrinsic (MonoCompile* cfg)
5216 if (thread_tls_offset == -1)
5219 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5220 ins->inst_offset = thread_tls_offset;
5224 /*========================= End of Function ========================*/
5226 /*------------------------------------------------------------------*/
5228 /* Name - mono_arch_flush_register_windows */
5234 /*------------------------------------------------------------------*/
5237 mono_arch_flush_register_windows (void)
5241 /*========================= End of Function ========================*/
5243 /*------------------------------------------------------------------*/
5245 /* Name - mono_arch_get_lmf_addr */
5251 /*------------------------------------------------------------------*/
5254 mono_arch_get_lmf_addr (void)
5256 return pthread_getspecific (lmf_addr_key);
5259 /*========================= End of Function ========================*/
5261 /*------------------------------------------------------------------*/
5263 /* Name - mono_arch_is_inst_imm */
5265 /* Function - Determine if operand qualifies as an immediate */
5266 /* value. For s390 this is a value -32768-32768 */
5268 /* Returns - True|False - is [not] immediate value. */
5270 /*------------------------------------------------------------------*/
5273 mono_arch_is_inst_imm (gint64 imm)
5275 return s390_is_imm16 (imm);
5278 /*========================= End of Function ========================*/
5280 /*------------------------------------------------------------------*/
5282 /* Name - opcode_to_cond */
5284 /* Function - Simplify the branch on condition opcode from */
5285 /* more than 20 to just a handful for easy manipu- */
5286 /* lation within the instruction emitting code. */
5288 /* Returns - CMP_xxx - this simplified condition type. */
5290 /*------------------------------------------------------------------*/
5293 opcode_to_cond (int opcode)
5302 case OP_COND_EXC_EQ:
5305 case OP_COND_EXC_NE_UN:
5318 case OP_COND_EXC_LT:
5326 case OP_COND_EXC_GT:
5335 case OP_COND_EXC_LE_UN:
5349 case OP_COND_EXC_LT_UN:
5352 case OP_COND_EXC_GT_UN:
5360 printf ("%s\n", mono_inst_name (opcode));
5361 g_error("Not implemented\n");
5366 /*========================= End of Function ========================*/
5368 /*------------------------------------------------------------------*/
5370 /* Name - mono_arch_get_patch_offset */
5372 /* Function - Dummy entry point until s390x supports aot. */
5374 /* Returns - Offset for patch. */
5376 /*------------------------------------------------------------------*/
5379 mono_arch_get_patch_offset (guint8 *code)
5384 /*========================= End of Function ========================*/