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 EMIT_COND_BRANCH(ins,cond) \
23 if (ins->flags & MONO_INST_BRLABEL) { \
24 if (ins->inst_i0->inst_c0) { \
26 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
27 if (s390_is_imm16(displace)) { \
28 s390_brc (code, cond, displace); \
30 s390_jcl (code, cond, displace); \
33 mono_add_patch_info (cfg, code - cfg->native_code, \
34 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
35 s390_jcl (code, cond, 0); \
38 if (ins->inst_true_bb->native_offset) { \
40 displace = ((cfg->native_code + \
41 ins->inst_true_bb->native_offset) - code) / 2; \
42 if (s390_is_imm16(displace)) { \
43 s390_brc (code, cond, displace); \
45 s390_jcl (code, cond, displace); \
48 mono_add_patch_info (cfg, code - cfg->native_code, \
49 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
50 s390_jcl (code, cond, 0); \
55 #define EMIT_UNCOND_BRANCH(ins) \
57 if (ins->flags & MONO_INST_BRLABEL) { \
58 if (ins->inst_i0->inst_c0) { \
60 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
61 if (s390_is_imm16(displace)) { \
62 s390_brc (code, S390_CC_UN, displace); \
64 s390_jcl (code, S390_CC_UN, displace); \
67 mono_add_patch_info (cfg, code - cfg->native_code, \
68 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
69 s390_jcl (code, S390_CC_UN, 0); \
72 if (ins->inst_target_bb->native_offset) { \
74 displace = ((cfg->native_code + \
75 ins->inst_target_bb->native_offset) - code) / 2; \
76 if (s390_is_imm16(displace)) { \
77 s390_brc (code, S390_CC_UN, displace); \
79 s390_jcl (code, S390_CC_UN, displace); \
82 mono_add_patch_info (cfg, code - cfg->native_code, \
83 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
84 s390_jcl (code, S390_CC_UN, 0); \
89 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
91 mono_add_patch_info (cfg, code - cfg->native_code, \
92 MONO_PATCH_INFO_EXC, exc_name); \
93 s390_jcl (code, cond, 0); \
96 #define CHECK_SRCDST_COM \
97 if (ins->dreg == ins->sreg2) { \
101 if (ins->dreg != ins->sreg1) { \
102 s390_lgr (code, ins->dreg, ins->sreg1); \
106 #define CHECK_SRCDST_NCOM \
107 if (ins->dreg == ins->sreg2) { \
109 s390_lgr (code, s390_r13, ins->sreg2); \
113 if (ins->dreg != ins->sreg1) { \
114 s390_lgr (code, ins->dreg, ins->sreg1); \
117 #define CHECK_SRCDST_COM_I \
118 if (ins->dreg == ins->sreg2) { \
122 if (ins->dreg != ins->sreg1) { \
123 s390_lgfr (code, ins->dreg, ins->sreg1); \
127 #define CHECK_SRCDST_NCOM_I \
128 if (ins->dreg == ins->sreg2) { \
130 s390_lgfr (code, s390_r13, ins->sreg2); \
134 if (ins->dreg != ins->sreg1) { \
135 s390_lgfr (code, ins->dreg, ins->sreg1); \
138 #define CHECK_SRCDST_COM_F \
139 if (ins->dreg == ins->sreg2) { \
143 if (ins->dreg != ins->sreg1) { \
144 s390_ldr (code, ins->dreg, ins->sreg1); \
148 #define CHECK_SRCDST_NCOM_F \
149 if (ins->dreg == ins->sreg2) { \
151 s390_ldr (code, s390_r13, ins->sreg2); \
155 if (ins->dreg != ins->sreg1) { \
156 s390_ldr (code, ins->dreg, ins->sreg1); \
159 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
163 MONO_INST_NEW (cfg, inst, OP_NOP); \
165 tmpr = mono_alloc_preg (cfg); \
166 MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
168 inst->inst_offset = offset; \
170 inst->inst_imm = imm; \
171 inst->sreg2 = tmpr; \
173 if (s390_is_uimm12(offset)) { \
175 inst->inst_offset = offset; \
177 dReg = mono_alloc_preg (cfg); \
178 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
179 dReg, dest, offset); \
181 inst->inst_offset = 0; \
183 if (s390_is_uimm12(imm)) { \
185 inst->inst_imm = imm; \
187 sReg = mono_alloc_preg (cfg); \
188 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
190 inst->sreg1 = sReg; \
191 inst->inst_imm = 0; \
194 inst->opcode = OP_S390_MOVE; \
195 inst->backend.size = size; \
196 MONO_ADD_INS (cfg->cbb, inst); \
199 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
200 int reg = mono_alloc_preg (cfg); \
203 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
206 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
210 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
214 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
218 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
222 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
225 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
229 tmpr = mono_alloc_preg (cfg); \
230 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
231 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
235 tmpr = mono_alloc_preg (cfg); \
236 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
238 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
242 tmpr = mono_alloc_preg (cfg); \
243 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
245 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
249 tmpr = mono_alloc_preg (cfg); \
250 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
252 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
256 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
262 #define DEBUG(a) if (cfg->verbose_level > 1) a
266 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
268 #define MAX(a, b) ((a) > (b) ? (a) : (b))
270 /*========================= End of Defines =========================*/
272 /*------------------------------------------------------------------*/
273 /* I n c l u d e s */
274 /*------------------------------------------------------------------*/
279 #include <mono/metadata/appdomain.h>
280 #include <mono/metadata/debug-helpers.h>
281 #include <mono/metadata/profiler-private.h>
282 #include <mono/utils/mono-math.h>
284 #include "mini-s390x.h"
285 #include "cpu-s390x.h"
286 #include "jit-icalls.h"
289 /*========================= End of Includes ========================*/
291 /*------------------------------------------------------------------*/
292 /* T y p e d e f s */
293 /*------------------------------------------------------------------*/
305 /*------------------------------------------------------------------*/
306 /* Used by the instrument_emit_epilog */
307 /*------------------------------------------------------------------*/
318 typedef struct InstList InstList;
332 RegTypeStructByValInFP,
337 gint32 offset; /* offset from caller's stack */
338 gint32 offparm; /* offset from callee's stack */
339 guint16 vtsize; /* in param area */
342 guint32 size; /* Size of structure used by RegTypeStructByVal */
343 gint32 type; /* Data type of argument */
358 gint64 gr[5]; /* R2-R6 */
359 gdouble fp[3]; /* F0-F2 */
360 } __attribute__ ((packed)) RegParm;
362 /*========================= End of Typedefs ========================*/
364 /*------------------------------------------------------------------*/
365 /* P r o t o t y p e s */
366 /*------------------------------------------------------------------*/
368 static void indent (int);
369 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
370 static void decodeParm (MonoType *, void *, int);
371 static void enter_method (MonoMethod *, RegParm *, char *);
372 static void leave_method (MonoMethod *, ...);
373 static gboolean is_regsize_var (MonoType *);
374 static inline void add_general (guint *, size_data *, ArgInfo *);
375 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
376 static inline void add_float (guint *, size_data *, ArgInfo *);
377 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
378 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
379 gpointer mono_arch_get_lmf_addr (void);
380 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
381 static void catch_SIGILL(int, siginfo_t *, void *);
382 static void emit_sig_cookie (MonoCompile *, MonoCallInst *, CallInfo *, int);
384 /*========================= End of Prototypes ======================*/
386 /*------------------------------------------------------------------*/
387 /* G l o b a l V a r i a b l e s */
388 /*------------------------------------------------------------------*/
390 int mono_exc_esp_offset = 0;
392 static int indent_level = 0;
396 static gboolean tls_offset_inited = FALSE;
398 static int appdomain_tls_offset = -1,
399 thread_tls_offset = -1;
401 pthread_key_t lmf_addr_key;
403 gboolean lmf_addr_key_inited = FALSE;
407 extern __thread MonoDomain *tls_appdomain;
408 extern __thread MonoThread *tls_current_object;
409 extern __thread gpointer mono_lmf_addr;
413 /*====================== End of Global Variables ===================*/
415 /*------------------------------------------------------------------*/
417 /* Name - mono_arch_regname */
419 /* Function - Returns the name of the register specified by */
420 /* the input parameter. */
422 /*------------------------------------------------------------------*/
425 mono_arch_regname (int reg) {
426 static const char * rnames[] = {
427 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
428 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
429 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
433 if (reg >= 0 && reg < 16)
439 /*========================= End of Function ========================*/
441 /*------------------------------------------------------------------*/
443 /* Name - mono_arch_fregname */
445 /* Function - Returns the name of the register specified by */
446 /* the input parameter. */
448 /*------------------------------------------------------------------*/
451 mono_arch_fregname (int reg) {
452 static const char * rnames[] = {
453 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
454 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
455 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
459 if (reg >= 0 && reg < 16)
465 /*========================= End of Function ========================*/
467 /*------------------------------------------------------------------*/
469 /* Name - arch_get_argument_info */
471 /* Function - Gathers information on parameters such as size, */
472 /* alignment, and padding. arg_info should be large */
473 /* enough to hold param_count + 1 entries. */
475 /* Parameters - @csig - Method signature */
476 /* @param_count - No. of parameters to consider */
477 /* @arg_info - An array to store the result info */
479 /* Returns - Size of the activation frame */
481 /*------------------------------------------------------------------*/
484 mono_arch_get_argument_info (MonoMethodSignature *csig,
486 MonoJitArgumentInfo *arg_info)
488 int k, frame_size = 0;
489 int size, align, pad;
492 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
493 frame_size += sizeof (gpointer);
497 arg_info [0].offset = offset;
500 frame_size += sizeof (gpointer);
504 arg_info [0].size = frame_size;
506 for (k = 0; k < param_count; k++) {
509 size = mono_type_native_stack_size (csig->params [k], &align);
511 size = mini_type_stack_size (NULL, csig->params [k], &align);
513 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
514 arg_info [k].pad = pad;
516 arg_info [k + 1].pad = 0;
517 arg_info [k + 1].size = size;
519 arg_info [k + 1].offset = offset;
523 align = MONO_ARCH_FRAME_ALIGNMENT;
524 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
525 arg_info [k].pad = pad;
530 /*========================= End of Function ========================*/
532 /*------------------------------------------------------------------*/
534 /* Name - retFitsInReg. */
536 /* Function - Determines if a value can be returned in one or */
539 /*------------------------------------------------------------------*/
541 static inline gboolean
542 retFitsInReg(guint32 size)
557 /*========================= End of Function ========================*/
559 /*------------------------------------------------------------------*/
561 /* Name - backStackPtr. */
563 /* Function - Restore Stack Pointer to previous frame. */
565 /*------------------------------------------------------------------*/
567 static inline guint8 *
568 backUpStackPtr(MonoCompile *cfg, guint8 *code)
570 int stackSize = cfg->stack_usage;
572 if (s390_is_imm16 (stackSize)) {
573 s390_aghi (code, STK_BASE, stackSize);
575 while (stackSize > 32767) {
576 s390_aghi (code, STK_BASE, 32767);
579 s390_aghi (code, STK_BASE, stackSize);
584 /*========================= End of Function ========================*/
586 /*------------------------------------------------------------------*/
590 /* Function - Perform nice indenting to current level */
592 /*------------------------------------------------------------------*/
598 indent_level += diff;
605 indent_level += diff;
608 /*========================= End of Function ========================*/
610 /*------------------------------------------------------------------*/
612 /* Name - decodeParm */
614 /* Function - Decode a parameter for the trace. */
616 /*------------------------------------------------------------------*/
619 decodeParm(MonoType *type, void *curParm, int size)
624 printf("[BYREF:%p], ", *((char **) curParm));
626 simpleType = mono_type_get_underlying_type(type)->type;
628 switch (simpleType) {
630 printf ("[INTPTR:%p], ", *((int **) curParm));
633 printf ("[UINTPTR:%p], ", *((int **) curParm));
635 case MONO_TYPE_BOOLEAN :
636 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
638 case MONO_TYPE_CHAR :
639 printf ("[CHAR:%c], ", *((int *) curParm));
642 printf ("[INT1:%ld], ", *((gint64 *) curParm));
645 printf ("[INT2:%ld], ", *((gint64 *) curParm));
648 printf ("[INT4:%ld], ", *((gint64 *) curParm));
651 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
654 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
657 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
660 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
662 case MONO_TYPE_STRING : {
663 MonoString *s = *((MonoString **) curParm);
665 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
666 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
668 printf("[STRING:null], ");
672 case MONO_TYPE_CLASS :
673 case MONO_TYPE_OBJECT : {
674 MonoObject *obj = *((MonoObject **) curParm);
676 if ((obj) && (obj->vtable)) {
677 printf("[CLASS/OBJ:");
678 class = obj->vtable->klass;
679 printf("%p [%p] ",obj,curParm);
680 if (class == mono_defaults.string_class) {
681 printf("[STRING:%p:%s]",
682 obj, mono_string_to_utf8 ((MonoString *) obj));
683 } else if (class == mono_defaults.int32_class) {
684 printf("[INT32:%p:%d]",
685 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
688 class->name_space, class->name, obj);
691 printf("[OBJECT:null], ");
696 printf("[PTR:%p], ", *((gpointer **) (curParm)));
698 case MONO_TYPE_FNPTR :
699 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
701 case MONO_TYPE_ARRAY :
702 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
704 case MONO_TYPE_SZARRAY :
705 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
708 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
711 printf("[FLOAT4:%g], ", *((float *) (curParm)));
714 printf("[FLOAT8:%g], ", *((double *) (curParm)));
716 case MONO_TYPE_VALUETYPE : {
718 MonoMarshalType *info;
720 if (type->data.klass->enumtype) {
721 simpleType = type->data.klass->enum_basetype->type;
722 printf("{VALUETYPE} - ");
726 info = mono_marshal_load_type_info (type->data.klass);
728 if ((info->native_size == sizeof(float)) &&
729 (info->num_fields == 1) &&
730 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
731 printf("[FLOAT4:%f], ", *((float *) (curParm)));
735 if ((info->native_size == sizeof(double)) &&
736 (info->num_fields == 1) &&
737 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
738 printf("[FLOAT8:%g], ", *((double *) (curParm)));
742 printf("[VALUETYPE:");
743 for (i = 0; i < size; i++)
744 printf("%02x,", *((guint8 *)curParm+i));
748 case MONO_TYPE_TYPEDBYREF: {
750 printf("[TYPEDBYREF:");
751 for (i = 0; i < size; i++)
752 printf("%02x,", *((guint8 *)curParm+i));
757 printf("[?? - %d], ",simpleType);
762 /*========================= End of Function ========================*/
764 /*------------------------------------------------------------------*/
766 /* Name - enter_method */
768 /* Function - Perform tracing of the entry to the current */
771 /*------------------------------------------------------------------*/
774 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
776 int i, oParm = 0, iParm = 0;
779 MonoMethodSignature *sig;
786 fname = mono_method_full_name (method, TRUE);
788 printf ("ENTER: %s ", fname);
791 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
792 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
797 sig = mono_method_signature (method);
799 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
801 if (cinfo->struct_ret) {
802 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
807 gpointer *this = (gpointer *) rParm->gr[iParm];
808 obj = (MonoObject *) this;
809 if (method->klass->valuetype) {
811 printf("this:[value:%p:%016lx], ",
812 this, *((guint64 *)(this+sizeof(MonoObject))));
814 printf ("this:[NULL], ");
817 class = obj->vtable->klass;
818 if (class == mono_defaults.string_class) {
819 printf ("this:[STRING:%p:%s], ",
820 obj, mono_string_to_utf8 ((MonoString *)obj));
822 printf ("this:%p[%s.%s], ",
823 obj, class->name_space, class->name);
826 printf ("this:NULL, ");
831 for (i = 0; i < sig->param_count; ++i) {
832 ainfo = &cinfo->args[i + oParm];
833 switch (ainfo->regtype) {
834 case RegTypeGeneral :
835 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
838 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
841 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
843 case RegTypeStructByVal :
844 if (ainfo->reg != STK_BASE) {
845 int offset = sizeof(glong) - ainfo->size;
846 curParm = &(rParm->gr[ainfo->reg-2])+offset;
849 curParm = sp+ainfo->offset;
851 if (retFitsInReg (ainfo->vtsize))
852 decodeParm(sig->params[i],
856 decodeParm(sig->params[i],
857 *((char **) curParm),
860 case RegTypeStructByAddr :
861 if (ainfo->reg != STK_BASE)
862 curParm = &(rParm->gr[ainfo->reg-2]);
864 curParm = sp+ainfo->offset;
866 decodeParm(sig->params[i],
867 *((char **) curParm),
879 /*========================= End of Function ========================*/
881 /*------------------------------------------------------------------*/
883 /* Name - leave_method */
887 /*------------------------------------------------------------------*/
890 leave_method (MonoMethod *method, ...)
897 va_start(ap, method);
899 fname = mono_method_full_name (method, TRUE);
901 printf ("LEAVE: %s", fname);
904 type = mono_method_signature (method)->ret;
907 switch (type->type) {
910 case MONO_TYPE_BOOLEAN: {
911 int val = va_arg (ap, int);
913 printf ("[TRUE:%d]", val);
919 case MONO_TYPE_CHAR: {
920 int val = va_arg (ap, int);
921 printf ("[CHAR:%d]", val);
925 int val = va_arg (ap, int);
926 printf ("[INT1:%d]", val);
930 int val = va_arg (ap, int);
931 printf ("[UINT1:%d]", val);
935 int val = va_arg (ap, int);
936 printf ("[INT2:%d]", val);
940 int val = va_arg (ap, int);
941 printf ("[UINT2:%d]", val);
945 int val = va_arg (ap, int);
946 printf ("[INT4:%d]", val);
950 int val = va_arg (ap, int);
951 printf ("[UINT4:%d]", val);
955 gint64 val = va_arg (ap, gint64);
956 printf ("[INT:%ld]", val);
961 gint64 val = va_arg (ap, gint64);
962 printf ("[UINT:%lu]", val);
966 case MONO_TYPE_STRING: {
967 MonoString *s = va_arg (ap, MonoString *);
970 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
971 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
973 printf ("[STRING:null], ");
976 case MONO_TYPE_CLASS:
977 case MONO_TYPE_OBJECT: {
978 MonoObject *o = va_arg (ap, MonoObject *);
980 if ((o) && (o->vtable)) {
981 if (o->vtable->klass == mono_defaults.boolean_class) {
982 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
983 } else if (o->vtable->klass == mono_defaults.int32_class) {
984 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
985 } else if (o->vtable->klass == mono_defaults.int64_class) {
986 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
988 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
990 printf ("[OBJECT:%p]", o);
995 case MONO_TYPE_FNPTR:
996 case MONO_TYPE_ARRAY:
997 case MONO_TYPE_SZARRAY: {
998 gpointer p = va_arg (ap, gpointer);
999 printf ("[result=%p]", p);
1002 case MONO_TYPE_I8: {
1003 gint64 l = va_arg (ap, gint64);
1004 printf ("[LONG:%ld]", l);
1007 case MONO_TYPE_U8: {
1008 guint64 l = va_arg (ap, guint64);
1009 printf ("[ULONG:%lu]", l);
1012 case MONO_TYPE_R4: {
1013 double f = va_arg (ap, double);
1014 printf ("[FLOAT4:%g]\n", f);
1017 case MONO_TYPE_R8: {
1018 double f = va_arg (ap, double);
1019 printf ("[FLOAT8:%g]\n", f);
1022 case MONO_TYPE_VALUETYPE: {
1023 MonoMarshalType *info;
1024 if (type->data.klass->enumtype) {
1025 type = type->data.klass->enum_basetype;
1028 guint8 *p = va_arg (ap, gpointer);
1031 info = mono_marshal_load_type_info (type->data.klass);
1033 if ((info->native_size == sizeof(float)) &&
1034 (info->num_fields == 1) &&
1035 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1036 double f = va_arg (ap, double);
1037 printf("[FLOAT4:%g]\n", (double) f);
1041 if ((info->native_size == sizeof(double)) &&
1042 (info->num_fields == 1) &&
1043 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1044 double f = va_arg (ap, double);
1045 printf("[FLOAT8:%g]\n", f);
1049 size = mono_type_size (type, &align);
1056 for (j = 0; p && j < size; j++)
1057 printf ("%02x,", p [j]);
1061 printf ("[VALUETYPE]\n");
1066 case MONO_TYPE_TYPEDBYREF: {
1067 guint8 *p = va_arg (ap, gpointer);
1069 size = mono_type_size (type, &align);
1076 for (j = 0; p && j < size; j++)
1077 printf ("%02x,", p [j]);
1081 printf ("[TYPEDBYREF]\n");
1086 printf ("(unknown return type %x)",
1087 mono_method_signature (method)->ret->type);
1090 ip = ((gint64) __builtin_return_address (0));
1091 printf (" ip: %p\n", (gpointer) ip);
1094 /*========================= End of Function ========================*/
1096 /*------------------------------------------------------------------*/
1098 /* Name - catch_SIGILL */
1100 /* Function - Catch SIGILL as a result of testing for long */
1101 /* displacement facility. */
1103 /*------------------------------------------------------------------*/
1106 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1112 /*========================= End of Function ========================*/
1114 /*------------------------------------------------------------------*/
1116 /* Name - mono_arch_cpu_init */
1118 /* Function - Perform CPU specific initialization to execute */
1121 /*------------------------------------------------------------------*/
1124 mono_arch_cpu_init (void)
1126 struct sigaction sa,
1130 /*--------------------------------------*/
1131 /* Set default rounding mode for FP */
1132 /*--------------------------------------*/
1133 __asm__ ("SRNM\t%0\n\t"
1136 /*--------------------------------------*/
1137 /* Determine if we have long displace- */
1138 /* ment facility on this processor */
1139 /*--------------------------------------*/
1140 sa.sa_sigaction = catch_SIGILL;
1141 sigemptyset (&sa.sa_mask);
1142 sa.sa_flags = SA_SIGINFO;
1144 sigaction (SIGILL, &sa, oldSa);
1146 /*--------------------------------------*/
1147 /* We test by executing the STY inst */
1148 /*--------------------------------------*/
1149 __asm__ ("LGHI\t0,1\n\t"
1151 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1152 : "=m" (has_ld) : : "0", "1");
1154 sigaction (SIGILL, oldSa, NULL);
1157 /*========================= End of Function ========================*/
1161 * Initialize architecture specific code.
1164 mono_arch_init (void)
1169 * Cleanup architecture specific code.
1172 mono_arch_cleanup (void)
1176 /*------------------------------------------------------------------*/
1178 /* Name - mono_arch_cpu_optimizazions */
1180 /* Function - Returns the optimizations supported on this CPU */
1182 /*------------------------------------------------------------------*/
1185 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1189 /*----------------------------------------------------------*/
1190 /* No s390-specific optimizations yet */
1191 /*----------------------------------------------------------*/
1192 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1193 // *exclude_mask = MONO_OPT_INLINE;
1197 /*========================= End of Function ========================*/
1199 /*------------------------------------------------------------------*/
1205 /*------------------------------------------------------------------*/
1208 is_regsize_var (MonoType *t) {
1211 switch (mono_type_get_underlying_type (t)->type) {
1219 case MONO_TYPE_FNPTR:
1221 case MONO_TYPE_OBJECT:
1222 case MONO_TYPE_STRING:
1223 case MONO_TYPE_CLASS:
1224 case MONO_TYPE_SZARRAY:
1225 case MONO_TYPE_ARRAY:
1227 case MONO_TYPE_VALUETYPE:
1228 if (t->data.klass->enumtype)
1229 return is_regsize_var (t->data.klass->enum_basetype);
1235 /*========================= End of Function ========================*/
1237 /*------------------------------------------------------------------*/
1239 /* Name - mono_arch_get_allocatable_int_vars */
1243 /*------------------------------------------------------------------*/
1246 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1251 for (i = 0; i < cfg->num_varinfo; i++) {
1252 MonoInst *ins = cfg->varinfo [i];
1253 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1256 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1259 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1260 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1263 /* we can only allocate 32 bit values */
1264 if (is_regsize_var (ins->inst_vtype)) {
1265 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1266 g_assert (i == vmv->idx);
1267 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1274 /*========================= End of Function ========================*/
1276 /*------------------------------------------------------------------*/
1278 /* Name - mono_arch_global_int_regs */
1280 /* Function - Return a list of usable integer registers. */
1282 /*------------------------------------------------------------------*/
1285 mono_arch_get_global_int_regs (MonoCompile *cfg)
1288 MonoMethodHeader *header;
1291 header = mono_method_get_header (cfg->method);
1292 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1293 cfg->frame_reg = s390_r11;
1296 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1298 for (i = 8; i < top; ++i) {
1299 if (cfg->frame_reg != i)
1300 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1306 /*========================= End of Function ========================*/
1308 /*------------------------------------------------------------------*/
1310 /* Name - mono_arch_flush_icache */
1312 /* Function - Flush the CPU icache. */
1314 /*------------------------------------------------------------------*/
1317 mono_arch_flush_icache (guint8 *code, gint size)
1321 /*========================= End of Function ========================*/
1323 /*------------------------------------------------------------------*/
1325 /* Name - add_general */
1327 /* Function - Determine code and stack size incremements for a */
1330 /*------------------------------------------------------------------*/
1333 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1335 if (*gr > S390_LAST_ARG_REG) {
1336 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1337 ainfo->offset = sz->stack_size;
1338 ainfo->reg = STK_BASE;
1339 ainfo->regtype = RegTypeBase;
1340 sz->stack_size += sizeof(long);
1341 sz->local_size += sizeof(long);
1342 sz->offStruct += sizeof(long);
1343 sz->code_size += 12;
1351 /*========================= End of Function ========================*/
1353 /*------------------------------------------------------------------*/
1355 /* Name - add_stackParm */
1357 /* Function - Determine code and stack size incremements for a */
1360 /*------------------------------------------------------------------*/
1363 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1365 if (*gr > S390_LAST_ARG_REG) {
1366 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1367 ainfo->reg = STK_BASE;
1368 ainfo->offset = sz->stack_size;
1369 sz->stack_size += sizeof (gpointer);
1370 sz->parm_size += sizeof(gpointer);
1371 sz->offStruct += sizeof(gpointer);
1374 ainfo->offset = sz->stack_size;
1377 ainfo->offparm = sz->offset;
1378 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1380 ainfo->regtype = RegTypeStructByAddr;
1381 ainfo->vtsize = size;
1382 sz->parm_size += size;
1385 /*========================= End of Function ========================*/
1387 /*------------------------------------------------------------------*/
1389 /* Name - add_float */
1391 /* Function - Determine code and stack size incremements for a */
1392 /* float parameter. */
1394 /*------------------------------------------------------------------*/
1397 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1399 if ((*fr) <= S390_LAST_FPARG_REG) {
1400 ainfo->regtype = RegTypeFP;
1406 ainfo->offset = sz->stack_size;
1407 ainfo->reg = STK_BASE;
1408 ainfo->regtype = RegTypeBase;
1410 sz->stack_size += sizeof(double);
1411 sz->local_size += sizeof(double);
1412 sz->offStruct += sizeof(double);
1416 /*========================= End of Function ========================*/
1418 /*------------------------------------------------------------------*/
1420 /* Name - get_call_info */
1422 /* Function - Determine the amount of space required for code */
1423 /* and stack. In addition determine starting points */
1424 /* for stack-based parameters, and area for struct- */
1425 /* ures being returned on the stack. */
1427 /*------------------------------------------------------------------*/
1430 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1432 guint i, fr, gr, size;
1433 int nParm = sig->hasthis + sig->param_count;
1435 guint32 simpletype, align;
1438 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1441 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1443 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1448 cinfo->struct_ret = 0;
1452 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1453 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1458 /*----------------------------------------------------------*/
1459 /* We determine the size of the return code/stack in case we*/
1460 /* need to reserve a register to be used to address a stack */
1461 /* area that the callee will use. */
1462 /*----------------------------------------------------------*/
1464 ret_type = mono_type_get_underlying_type (sig->ret);
1465 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1466 simpletype = ret_type->type;
1468 switch (simpletype) {
1469 case MONO_TYPE_BOOLEAN:
1474 case MONO_TYPE_CHAR:
1479 case MONO_TYPE_CLASS:
1480 case MONO_TYPE_OBJECT:
1481 case MONO_TYPE_SZARRAY:
1482 case MONO_TYPE_ARRAY:
1484 case MONO_TYPE_FNPTR:
1485 case MONO_TYPE_STRING:
1486 cinfo->ret.reg = s390_r2;
1491 cinfo->ret.reg = s390_f0;
1496 cinfo->ret.reg = s390_r2;
1499 case MONO_TYPE_GENERICINST:
1500 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1501 cinfo->ret.reg = s390_r2;
1506 case MONO_TYPE_VALUETYPE: {
1507 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1508 if (klass->enumtype) {
1509 simpletype = klass->enum_basetype->type;
1513 size = mono_class_native_size (klass, &align);
1515 size = mono_class_value_size (klass, &align);
1517 cinfo->ret.reg = s390_r2;
1518 cinfo->struct_ret = 1;
1519 cinfo->ret.size = size;
1520 cinfo->ret.vtsize = size;
1524 case MONO_TYPE_TYPEDBYREF:
1525 size = sizeof (MonoTypedRef);
1526 cinfo->ret.reg = s390_r2;
1527 cinfo->struct_ret = 1;
1528 cinfo->ret.size = size;
1529 cinfo->ret.vtsize = size;
1532 case MONO_TYPE_VOID:
1535 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1539 cinfo->args[nParm].size = sizeof(gpointer);
1540 add_general (&gr, sz, cinfo->args+nParm);
1544 /*----------------------------------------------------------*/
1545 /* We determine the size of the parameter code and stack */
1546 /* requirements by checking the types and sizes of the */
1548 /*----------------------------------------------------------*/
1550 for (i = 0; i < sig->param_count; ++i) {
1553 /*--------------------------------------------------*/
1554 /* Handle vararg type calls. All args are put on */
1556 /*--------------------------------------------------*/
1557 if ((sig->call_convention == MONO_CALL_VARARG) &&
1558 (i == sig->sentinelpos)) {
1559 gr = S390_LAST_ARG_REG + 1;
1560 add_general (&gr, sz, &cinfo->sigCookie);
1563 if (sig->params [i]->byref) {
1564 add_general (&gr, sz, cinfo->args+nParm);
1565 cinfo->args[nParm].size = sizeof(gpointer);
1570 ptype = mono_type_get_underlying_type (sig->params [i]);
1571 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1572 simpletype = ptype->type;
1573 cinfo->args[nParm].type = simpletype;
1574 switch (simpletype) {
1575 case MONO_TYPE_BOOLEAN:
1578 cinfo->args[nParm].size = sizeof(char);
1579 add_general (&gr, sz, cinfo->args+nParm);
1584 case MONO_TYPE_CHAR:
1585 cinfo->args[nParm].size = sizeof(short);
1586 add_general (&gr, sz, cinfo->args+nParm);
1591 cinfo->args[nParm].size = sizeof(int);
1592 add_general (&gr, sz, cinfo->args+nParm);
1598 case MONO_TYPE_FNPTR:
1599 case MONO_TYPE_CLASS:
1600 case MONO_TYPE_OBJECT:
1601 case MONO_TYPE_STRING:
1602 case MONO_TYPE_SZARRAY:
1603 case MONO_TYPE_ARRAY:
1604 cinfo->args[nParm].size = sizeof(gpointer);
1605 add_general (&gr, sz, cinfo->args+nParm);
1610 cinfo->args[nParm].size = sizeof(long long);
1611 add_general (&gr, sz, cinfo->args+nParm);
1615 cinfo->args[nParm].size = sizeof(float);
1616 add_float (&fr, sz, cinfo->args+nParm);
1620 cinfo->args[nParm].size = sizeof(double);
1621 add_float (&fr, sz, cinfo->args+nParm);
1624 case MONO_TYPE_GENERICINST:
1625 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1626 cinfo->args[nParm].size = sizeof(gpointer);
1627 add_general (&gr, sz, cinfo->args+nParm);
1632 case MONO_TYPE_VALUETYPE: {
1633 MonoMarshalType *info;
1634 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1636 size = mono_class_native_size (klass, &align);
1638 size = mono_class_value_size (klass, &align);
1640 info = mono_marshal_load_type_info (klass);
1642 if ((info->native_size == sizeof(float)) &&
1643 (info->num_fields == 1) &&
1644 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1645 cinfo->args[nParm].size = sizeof(float);
1646 add_float(&fr, sz, cinfo->args+nParm);
1651 if ((info->native_size == sizeof(double)) &&
1652 (info->num_fields == 1) &&
1653 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1654 cinfo->args[nParm].size = sizeof(double);
1655 add_float(&fr, sz, cinfo->args+nParm);
1660 cinfo->args[nParm].vtsize = 0;
1661 cinfo->args[nParm].size = 0;
1664 /*----------------------------------*/
1665 /* On S/390, structures of size 1, */
1666 /* 2, 4, and 8 bytes are passed in */
1667 /* (a) register(s). */
1668 /*----------------------------------*/
1674 add_general(&gr, sz, cinfo->args+nParm);
1675 cinfo->args[nParm].size = size;
1676 cinfo->args[nParm].regtype = RegTypeStructByVal;
1678 sz->local_size += sizeof(long);
1681 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1686 case MONO_TYPE_TYPEDBYREF: {
1687 int size = sizeof (MonoTypedRef);
1689 cinfo->args[nParm].vtsize = 0;
1690 cinfo->args[nParm].size = 0;
1693 /*----------------------------------*/
1694 /* On S/390, structures of size 1, */
1695 /* 2, 4, and 8 bytes are passed in */
1696 /* (a) register(s). */
1697 /*----------------------------------*/
1703 add_general(&gr, sz, cinfo->args+nParm);
1704 cinfo->args[nParm].size = size;
1705 cinfo->args[nParm].regtype = RegTypeStructByVal;
1707 sz->local_size += sizeof(long);
1710 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1716 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1720 /*----------------------------------------------------------*/
1721 /* Handle the case where there are no implicit arguments */
1722 /*----------------------------------------------------------*/
1723 if ((sig->call_convention == MONO_CALL_VARARG) &&
1724 (sig->param_count == sig->sentinelpos)) {
1725 gr = S390_LAST_ARG_REG + 1;
1726 add_general (&gr, sz, &cinfo->sigCookie);
1729 /*----------------------------------------------------------*/
1730 /* If we are passing a structure back then if it won't be */
1731 /* in a register(s) then we make room at the end of the */
1732 /* parameters that may have been placed on the stack */
1733 /*----------------------------------------------------------*/
1734 if (cinfo->struct_ret) {
1735 cinfo->ret.offset = sz->stack_size;
1736 switch (cinfo->ret.size) {
1744 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1749 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1751 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1756 /*========================= End of Function ========================*/
1758 /*------------------------------------------------------------------*/
1760 /* Name - mono_arch_allocate_vars */
1762 /* Function - Set var information according to the calling */
1763 /* convention for S/390. The local var stuff should */
1764 /* most likely be split in another method. */
1766 /* Parameter - @m - Compile unit. */
1768 /*------------------------------------------------------------------*/
1771 mono_arch_allocate_vars (MonoCompile *cfg)
1773 MonoMethodSignature *sig;
1774 MonoMethodHeader *header;
1777 int iParm, iVar, offset, size, align, curinst;
1778 int frame_reg = STK_BASE;
1781 header = mono_method_get_header (cfg->method);
1783 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1785 /*---------------------------------------------------------*/
1786 /* We use the frame register also for any method that has */
1787 /* filter clauses. This way, when the handlers are called, */
1788 /* the code will reference local variables using the frame */
1789 /* reg instead of the stack pointer: if we had to restore */
1790 /* the stack pointer, we'd corrupt the method frames that */
1791 /* are already on the stack (since filters get called */
1792 /* before stack unwinding happens) when the filter code */
1793 /* would call any method. */
1794 /*---------------------------------------------------------*/
1795 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1796 frame_reg = s390_r11;
1798 cfg->frame_reg = frame_reg;
1800 cfg->arch.bkchain_reg = -1;
1802 if (frame_reg != STK_BASE)
1803 cfg->used_int_regs |= 1 << frame_reg;
1805 sig = mono_method_signature (cfg->method);
1807 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1809 if (!cinfo->struct_ret) {
1810 switch (mono_type_get_underlying_type (sig->ret)->type) {
1811 case MONO_TYPE_VOID:
1814 cfg->ret->opcode = OP_REGVAR;
1815 cfg->ret->dreg = s390_r2;
1820 /*--------------------------------------------------------------*/
1821 /* local vars are at a positive offset from the stack pointer */
1822 /* also note that if the function uses alloca, we use s390_r11 */
1823 /* to point at the local variables. */
1824 /* add parameter area size for called functions */
1825 /*--------------------------------------------------------------*/
1826 offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
1827 cfg->sig_cookie = 0;
1829 if (cinfo->struct_ret) {
1830 inst = cfg->vret_addr;
1831 offset = S390_ALIGN(offset, sizeof(gpointer));
1832 inst->inst_offset = offset;
1833 inst->opcode = OP_REGOFFSET;
1834 inst->inst_basereg = frame_reg;
1835 offset += sizeof(gpointer);
1836 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1837 printf ("vret_addr =");
1838 mono_print_ins (cfg->vret_addr);
1843 inst = cfg->args [0];
1844 if (inst->opcode != OP_REGVAR) {
1845 inst->opcode = OP_REGOFFSET;
1846 inst->inst_basereg = frame_reg;
1847 offset = S390_ALIGN(offset, sizeof(gpointer));
1848 inst->inst_offset = offset;
1849 offset += sizeof (gpointer);
1856 eArg = sig->param_count + sArg;
1858 if (sig->call_convention == MONO_CALL_VARARG)
1859 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1861 for (iParm = sArg; iParm < eArg; ++iParm) {
1862 inst = cfg->args [curinst];
1863 if (inst->opcode != OP_REGVAR) {
1864 switch (cinfo->args[iParm].regtype) {
1865 case RegTypeStructByAddr : {
1868 size = sizeof (gpointer);
1870 inst->opcode = OP_REGOFFSET;
1871 inst->inst_basereg = frame_reg;
1872 offset = S390_ALIGN (offset, sizeof (gpointer));
1873 inst->inst_offset = offset;
1875 /* Add a level of indirection */
1876 MONO_INST_NEW (cfg, indir, 0);
1878 inst->opcode = OP_VTARG_ADDR;
1879 inst->inst_left = indir;
1882 case RegTypeStructByVal :
1883 size = cinfo->args[iParm].size;
1884 offset = S390_ALIGN(offset, size);
1885 inst->opcode = OP_REGOFFSET;
1886 inst->inst_basereg = frame_reg;
1887 inst->inst_offset = offset;
1890 if (cinfo->args [iParm].reg == STK_BASE) {
1892 * These arguments are in the previous frame, so we can't
1893 * compute their offset from the current frame pointer right
1894 * now, since cfg->stack_offset is not yet known, so dedicate a
1895 * register holding the previous frame pointer.
1897 cfg->arch.bkchain_reg = s390_r12;
1898 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1900 inst->opcode = OP_REGOFFSET;
1901 inst->inst_basereg = cfg->arch.bkchain_reg;
1902 size = (cinfo->args[iParm].size < 8
1903 ? 8 - cinfo->args[iParm].size
1905 inst->inst_offset = cinfo->args [iParm].offset + size;
1906 size = sizeof (long);
1908 inst->opcode = OP_REGOFFSET;
1909 inst->inst_basereg = frame_reg;
1910 size = (cinfo->args[iParm].size < 8
1913 offset = S390_ALIGN(offset, size);
1914 inst->inst_offset = offset;
1918 if ((sig->call_convention == MONO_CALL_VARARG) &&
1919 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1920 (iParm < sig->sentinelpos))
1921 cfg->sig_cookie += size;
1928 curinst = cfg->locals_start;
1929 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1930 inst = cfg->varinfo [iVar];
1931 if ((inst->flags & MONO_INST_IS_DEAD) ||
1932 (inst->opcode == OP_REGVAR))
1935 /*--------------------------------------------------*/
1936 /* inst->backend.is_pinvoke indicates native sized value types, */
1937 /* this is used by the pinvoke wrappers when they */
1938 /* call functions returning structure */
1939 /*--------------------------------------------------*/
1940 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1941 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype), &align);
1943 size = mono_type_size (inst->inst_vtype, &align);
1945 offset = S390_ALIGN(offset, align);
1946 inst->inst_offset = offset;
1947 inst->opcode = OP_REGOFFSET;
1948 inst->inst_basereg = frame_reg;
1950 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
1951 iVar, inst->inst_offset, size));
1954 /*------------------------------------------------------*/
1955 /* Allow space for the trace method stack area if needed*/
1956 /*------------------------------------------------------*/
1957 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
1958 offset += S390_TRACE_STACK_SIZE;
1960 /*------------------------------------------------------*/
1961 /* Reserve space to save LMF and caller saved registers */
1962 /*------------------------------------------------------*/
1963 if (cfg->method->save_lmf)
1964 offset += sizeof (MonoLMF);
1966 /*------------------------------------------------------*/
1967 /* align the offset */
1968 /*------------------------------------------------------*/
1969 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1973 /*========================= End of Function ========================*/
1975 /*------------------------------------------------------------------*/
1977 /* Name - mono_arch_create_vars */
1978 /*------------------------------------------------------------------*/
1981 mono_arch_create_vars (MonoCompile *cfg)
1983 MonoMethodSignature *sig;
1986 sig = mono_method_signature (cfg->method);
1988 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1990 if (cinfo->struct_ret) {
1991 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
1992 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1993 printf ("vret_addr = ");
1994 mono_print_ins (cfg->vret_addr);
1999 /*========================= End of Function ========================*/
2002 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2007 case RegTypeGeneral:
2008 MONO_INST_NEW (cfg, ins, OP_MOVE);
2009 ins->dreg = mono_alloc_ireg (cfg);
2010 ins->sreg1 = tree->dreg;
2011 MONO_ADD_INS (cfg->cbb, ins);
2012 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2015 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2016 ins->dreg = mono_alloc_freg (cfg);
2017 ins->sreg1 = tree->dreg;
2018 MONO_ADD_INS (cfg->cbb, ins);
2019 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2022 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2023 ins->dreg = mono_alloc_freg (cfg);
2024 ins->sreg1 = tree->dreg;
2025 MONO_ADD_INS (cfg->cbb, ins);
2026 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2029 g_assert_not_reached ();
2034 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2036 MonoMethodSignature *tmpSig;
2039 cfg->disable_aot = TRUE;
2041 /*----------------------------------------------------------*/
2042 /* mono_ArgIterator_Setup assumes the signature cookie is */
2043 /* passed first and all the arguments which were before it */
2044 /* passed on the stack after the signature. So compensate */
2045 /* by passing a different signature. */
2046 /*----------------------------------------------------------*/
2047 tmpSig = mono_metadata_signature_dup (call->signature);
2048 tmpSig->param_count -= call->signature->sentinelpos;
2049 tmpSig->sentinelpos = 0;
2050 if (tmpSig->param_count > 0)
2051 memcpy (tmpSig->params,
2052 call->signature->params + call->signature->sentinelpos,
2053 tmpSig->param_count * sizeof(MonoType *));
2055 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2056 sig_arg->dreg = mono_alloc_ireg (cfg);
2057 sig_arg->inst_p0 = tmpSig;
2058 MONO_ADD_INS (cfg->cbb, sig_arg);
2060 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2061 cinfo->sigCookie.offset, sig_arg->dreg);
2064 /*------------------------------------------------------------------*/
2066 /* Name - mono_arch_emit_call */
2068 /*------------------------------------------------------------------*/
2071 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2074 MonoMethodSignature *sig;
2076 int i, n, lParamArea;
2078 ArgInfo *ainfo = NULL;
2081 sig = call->signature;
2082 n = sig->param_count + sig->hasthis;
2083 DEBUG (g_print ("Call requires: %d parameters\n",n));
2085 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2087 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size + cinfo->sz.parm_size + cinfo->sz.offset;
2088 call->stack_usage = MAX(stackSize, call->stack_usage);
2089 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2090 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2091 cfg->flags |= MONO_CFG_HAS_CALLS;
2093 if (cinfo->struct_ret) {
2094 MONO_INST_NEW (cfg, ins, OP_MOVE);
2095 ins->sreg1 = call->vret_var->dreg;
2096 ins->dreg = mono_alloc_preg (cfg);
2097 MONO_ADD_INS (cfg->cbb, ins);
2098 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2101 for (i = 0; i < n; ++i) {
2102 ainfo = cinfo->args + i;
2105 if (i >= sig->hasthis)
2106 t = sig->params [i - sig->hasthis];
2108 t = &mono_defaults.int_class->byval_arg;
2109 t = mono_type_get_underlying_type (t);
2111 in = call->args [i];
2113 if ((sig->call_convention == MONO_CALL_VARARG) &&
2114 (i == sig->sentinelpos)) {
2115 emit_sig_cookie (cfg, call, cinfo);
2118 switch (ainfo->regtype) {
2119 case RegTypeGeneral:
2120 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2123 if (MONO_TYPE_ISSTRUCT (t)) {
2124 /* Valuetype passed in one fp register */
2125 ainfo->regtype = RegTypeStructByValInFP;
2128 if (ainfo->size == 4)
2129 ainfo->regtype = RegTypeFPR4;
2130 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2133 case RegTypeStructByVal:
2134 case RegTypeStructByAddr: {
2138 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2139 size = sizeof (MonoTypedRef);
2140 align = sizeof (gpointer);
2144 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2147 * Other backends use mono_type_stack_size (), but that
2148 * aligns the size to 8, which is larger than the size of
2149 * the source, leading to reads of invalid memory if the
2150 * source is at the end of address space.
2152 size = mono_class_value_size (in->klass, &align);
2155 g_assert (in->klass);
2157 ainfo->offparm += cinfo->sz.offStruct;
2159 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2160 ins->sreg1 = in->dreg;
2161 ins->klass = in->klass;
2162 ins->backend.size = ainfo->size;
2163 ins->inst_p0 = call;
2164 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2165 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2167 MONO_ADD_INS (cfg->cbb, ins);
2169 if (ainfo->regtype == RegTypeStructByAddr) {
2171 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2172 * use the normal OUTARG opcodes to pass the address of the location to
2175 int treg = mono_alloc_preg (cfg);
2176 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2177 STK_BASE, ainfo->offparm);
2178 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2183 if (!t->byref && t->type == MONO_TYPE_R4) {
2184 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2185 STK_BASE, ainfo->offset + 4,
2187 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2188 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2189 STK_BASE, ainfo->offset,
2192 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2193 ins->inst_destbasereg = STK_BASE;
2194 ins->inst_offset = ainfo->offset;
2195 ins->sreg1 = in->dreg;
2197 /* This is needed by MonoTypedRef->value to point to the correct data */
2198 if ((sig->call_convention == MONO_CALL_VARARG) &&
2199 (i >= sig->sentinelpos)) {
2200 switch (ainfo->size) {
2202 ins->opcode = OP_STOREI1_MEMBASE_REG;
2205 ins->opcode = OP_STOREI2_MEMBASE_REG;
2208 ins->opcode = OP_STOREI4_MEMBASE_REG;
2215 MONO_ADD_INS (cfg->cbb, ins);
2219 g_assert_not_reached ();
2225 * Handle the case where there are no implicit arguments
2227 if ((sig->call_convention == MONO_CALL_VARARG) &&
2228 (i == sig->sentinelpos)) {
2229 emit_sig_cookie (cfg, call, cinfo);
2233 /*========================= End of Function ========================*/
2235 /*------------------------------------------------------------------*/
2237 /* Name - mono_arch_emit_outarg_vt */
2239 /*------------------------------------------------------------------*/
2242 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2244 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2245 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2246 int size = ins->backend.size;
2248 if (ainfo->regtype == RegTypeStructByVal) {
2250 arg->ins.sreg1 = ainfo->reg;
2251 arg->ins.opcode = OP_OUTARG_VT;
2252 arg->size = ainfo->size;
2253 arg->offset = ainfo->offset;
2254 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2256 if (ainfo->reg != STK_BASE) {
2257 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2259 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2262 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2263 int dreg = mono_alloc_freg (cfg);
2265 if (ainfo->size == 4) {
2266 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2267 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2269 g_assert (ainfo->size == 8);
2271 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2274 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2276 MONO_EMIT_NEW_MOVE (cfg, STK_BASE, ainfo->offparm,
2277 src->dreg, 0, size);
2281 /*------------------------------------------------------------------*/
2283 /* Name - mono_arch_emit_setret */
2285 /*------------------------------------------------------------------*/
2288 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2290 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2293 if (ret->type == MONO_TYPE_R4) {
2294 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2296 } else if (ret->type == MONO_TYPE_R8) {
2297 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2302 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2305 /*========================= End of Function ========================*/
2307 /*------------------------------------------------------------------*/
2309 /* Name - mono_arch_instrument_mem_needs */
2311 /* Function - Allow tracing to work with this interface (with */
2312 /* an optional argument). */
2314 /*------------------------------------------------------------------*/
2317 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2319 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2321 /* split prolog-epilog requirements? */
2322 *code = 50; /* max bytes needed: check this number */
2325 /*========================= End of Function ========================*/
2327 /*------------------------------------------------------------------*/
2329 /* Name - mono_arch_instrument_prolog */
2331 /* Function - Create an "instrumented" prolog. */
2333 /*------------------------------------------------------------------*/
2336 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2337 gboolean enable_arguments)
2344 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2345 if (cfg->method->save_lmf)
2346 parmOffset -= sizeof(MonoLMF);
2347 fpOffset = parmOffset + (5*sizeof(gpointer));
2348 if ((!has_ld) && (fpOffset > 4096)) {
2349 s390_lgr (code, s390_r12, STK_BASE);
2351 while (fpOffset > 4096) {
2352 s390_aghi (code, baseReg, 4096);
2360 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2362 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2363 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2364 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2365 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2367 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2368 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2369 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2370 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2372 s390_basr (code, s390_r13, 0);
2374 s390_llong(code, cfg->method);
2375 s390_llong(code, func);
2376 s390_lg (code, s390_r2, 0, s390_r13, 4);
2378 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2380 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2381 s390_lgr (code, s390_r4, STK_BASE);
2382 s390_aghi (code, s390_r4, cfg->stack_usage);
2383 s390_lg (code, s390_r1, 0, s390_r13, 12);
2384 s390_basr (code, s390_r14, s390_r1);
2386 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2387 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2388 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2389 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2391 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2392 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2393 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2394 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2396 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2401 /*========================= End of Function ========================*/
2403 /*------------------------------------------------------------------*/
2405 /* Name - mono_arch_instrument_epilog */
2407 /* Function - Create an epilog that will handle the returned */
2408 /* values used in instrumentation. */
2410 /*------------------------------------------------------------------*/
2413 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
2416 int save_mode = SAVE_NONE,
2418 MonoMethod *method = cfg->method;
2419 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2421 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2422 if (method->save_lmf)
2423 saveOffset -= sizeof(MonoLMF);
2427 case MONO_TYPE_VOID:
2428 /* special case string .ctor icall */
2429 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2430 save_mode = SAVE_ONE;
2432 save_mode = SAVE_NONE;
2436 save_mode = SAVE_ONE;
2439 save_mode = SAVE_R4;
2442 save_mode = SAVE_R8;
2444 case MONO_TYPE_VALUETYPE:
2445 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2446 rtype = mono_method_signature (method)->ret->data.klass->enum_basetype->type;
2449 save_mode = SAVE_STRUCT;
2452 save_mode = SAVE_ONE;
2456 switch (save_mode) {
2458 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2459 if (enable_arguments) {
2460 s390_lgr (code, s390_r3, s390_r2);
2464 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2465 if (enable_arguments) {
2466 s390_ldebr (code, s390_f0, s390_f0);
2470 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2473 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2474 if (enable_arguments) {
2475 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2476 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2484 s390_basr (code, s390_r13, 0);
2486 s390_llong(code, cfg->method);
2487 s390_llong(code, func);
2488 s390_lg (code, s390_r2, 0, s390_r13, 4);
2489 s390_lg (code, s390_r1, 0, s390_r13, 12);
2490 s390_basr (code, s390_r14, s390_r1);
2492 switch (save_mode) {
2494 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2498 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2501 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2511 /*========================= End of Function ========================*/
2514 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2518 /*------------------------------------------------------------------*/
2520 /* Name - mono_arch_peephole_pass */
2522 /* Function - Form a peephole pass at the code looking for */
2523 /* simple optimizations. */
2525 /*------------------------------------------------------------------*/
2528 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2532 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2533 mono_peephole_ins (bb, ins);
2537 /*========================= End of Function ========================*/
2540 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2542 MonoInst *ins, *next;
2544 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2545 switch (ins->opcode) {
2550 case OP_IDIV_UN_IMM:
2551 case OP_IREM_UN_IMM:
2555 case OP_LOCALLOC_IMM:
2556 mono_decompose_op_imm (cfg, bb, ins);
2559 if (!s390_is_imm16 (ins->inst_imm))
2560 /* This is created by the memcpy code which ignores is_inst_imm */
2561 mono_decompose_op_imm (cfg, bb, ins);
2568 bb->max_vreg = cfg->next_vreg;
2571 /*========================= End of Function ========================*/
2573 /*------------------------------------------------------------------*/
2575 /* Name - emit_float_to_int */
2577 /* Function - Create instructions which will convert a floating */
2578 /* point value to integer. */
2580 /*------------------------------------------------------------------*/
2583 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2585 /* sreg is a float, dreg is an integer reg. */
2587 s390_cfdbr (code, dreg, 5, sreg);
2590 s390_lghi (code, s390_r0, 0);
2591 s390_lghi (code, s390_r13, 0xff);
2592 s390_ltgr (code, dreg, dreg);
2594 s390_lghi (code, s390_r0, 0x80);
2595 s390_ngr (code, dreg, s390_r13);
2596 s390_ogr (code, dreg, s390_r0);
2601 s390_basr (code, s390_r13, 0);
2603 s390_llong (code, 0x41e0000000000000);
2604 s390_llong (code, 0x41f0000000000000);
2605 s390_ldr (code, s390_f15, sreg);
2606 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2607 s390_jl (code, 0); CODEPTR (code, o[0]);
2608 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2609 s390_cfdbr (code, dreg, 7, s390_f15);
2611 PTRSLOT (code, o[0]);
2612 s390_cfdbr (code, dreg, 5, sreg);
2615 s390_lghi (code, s390_r0, 0xff);
2616 s390_ngr (code, dreg, s390_r0);
2619 s390_lghi (code, s390_r0, -1);
2620 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2621 s390_ngr (code, dreg, s390_r0);
2628 /*========================= End of Function ========================*/
2630 static gboolean is_unsigned (MonoInst *next)
2633 (((next->opcode >= OP_IBNE_UN) &&
2634 (next->opcode <= OP_IBLT_UN)) ||
2635 ((next->opcode >= OP_LBNE_UN) &&
2636 (next->opcode <= OP_LBLT_UN)) ||
2637 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2638 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2639 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2640 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2641 ((next->opcode == OP_CLT_UN) ||
2642 (next->opcode == OP_CGT_UN)) ||
2643 ((next->opcode == OP_ICLT_UN) ||
2644 (next->opcode == OP_ICGT_UN) ||
2645 (next->opcode == OP_LCLT_UN) ||
2646 (next->opcode == OP_LCGT_UN))))
2652 /*------------------------------------------------------------------*/
2654 /* Name - mono_arch_output_basic_block */
2656 /* Function - Perform the "real" work of emitting instructions */
2657 /* that will do the work of in the basic block. */
2659 /*------------------------------------------------------------------*/
2662 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2667 guint8 *code = cfg->native_code + cfg->code_len;
2668 guint last_offset = 0;
2669 int max_len, cpos, src2;
2671 /* we don't align basic blocks of loops on s390 */
2673 if (cfg->verbose_level > 2)
2674 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2676 cpos = bb->max_offset;
2678 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2679 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2680 //g_assert (!mono_compile_aot);
2683 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2684 /* this is not thread save, but good enough */
2685 /* fixme: howto handle overflows? */
2686 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2689 MONO_BB_FOR_EACH_INS (bb, ins) {
2690 offset = code - cfg->native_code;
2692 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2694 if (offset > (cfg->code_size - max_len - 16)) {
2695 cfg->code_size *= 2;
2696 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2697 code = cfg->native_code + offset;
2700 mono_debug_record_line_number (cfg, ins, offset);
2702 switch (ins->opcode) {
2703 case OP_STOREI1_MEMBASE_IMM: {
2704 s390_lghi (code, s390_r0, ins->inst_imm);
2705 S390_LONG (code, stcy, stc, s390_r0, 0,
2706 ins->inst_destbasereg, ins->inst_offset);
2709 case OP_STOREI2_MEMBASE_IMM: {
2710 s390_lghi (code, s390_r0, ins->inst_imm);
2711 S390_LONG (code, sthy, sth, s390_r0, 0,
2712 ins->inst_destbasereg, ins->inst_offset);
2715 case OP_STOREI4_MEMBASE_IMM: {
2716 if (s390_is_imm16(ins->inst_imm)) {
2717 s390_lghi (code, s390_r0, ins->inst_imm);
2719 s390_basr (code, s390_r13, 0);
2721 s390_llong(code, ins->inst_imm);
2722 s390_lg (code, s390_r0, 0, s390_r13, 4);
2724 S390_LONG (code, sty, st, s390_r0, 0,
2725 ins->inst_destbasereg, ins->inst_offset);
2728 case OP_STORE_MEMBASE_IMM:
2729 case OP_STOREI8_MEMBASE_IMM: {
2730 if (s390_is_imm16(ins->inst_imm)) {
2731 s390_lghi (code, s390_r0, ins->inst_imm);
2733 s390_basr (code, s390_r13, 0);
2735 s390_llong(code, ins->inst_imm);
2736 s390_lg (code, s390_r0, 0, s390_r13, 4);
2738 S390_LONG (code, stg, stg, s390_r0, 0,
2739 ins->inst_destbasereg, ins->inst_offset);
2742 case OP_STOREI1_MEMBASE_REG: {
2743 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2744 ins->inst_destbasereg, ins->inst_offset);
2747 case OP_STOREI2_MEMBASE_REG: {
2748 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2749 ins->inst_destbasereg, ins->inst_offset);
2752 case OP_STOREI4_MEMBASE_REG: {
2753 S390_LONG (code, sty, st, ins->sreg1, 0,
2754 ins->inst_destbasereg, ins->inst_offset);
2757 case OP_STORE_MEMBASE_REG:
2758 case OP_STOREI8_MEMBASE_REG: {
2759 S390_LONG (code, stg, stg, ins->sreg1, 0,
2760 ins->inst_destbasereg, ins->inst_offset);
2764 g_assert_not_reached ();
2766 case OP_LOAD_MEMBASE:
2767 case OP_LOADI8_MEMBASE: {
2768 S390_LONG (code, lg, lg, ins->dreg, 0,
2769 ins->inst_basereg, ins->inst_offset);
2772 case OP_LOADI4_MEMBASE: {
2773 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2774 ins->inst_basereg, ins->inst_offset);
2777 case OP_LOADU4_MEMBASE: {
2778 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2779 ins->inst_basereg, ins->inst_offset);
2782 case OP_LOADU1_MEMBASE: {
2783 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2784 ins->inst_basereg, ins->inst_offset);
2787 case OP_LOADI1_MEMBASE: {
2788 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2789 ins->inst_basereg, ins->inst_offset);
2792 case OP_LOADU2_MEMBASE: {
2793 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2794 ins->inst_basereg, ins->inst_offset);
2797 case OP_LOADI2_MEMBASE: {
2798 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2799 ins->inst_basereg, ins->inst_offset);
2802 case OP_LCONV_TO_I1: {
2803 s390_lghi (code, s390_r0, 0x80);
2804 if (ins->dreg != ins->sreg1) {
2805 s390_lgr (code, ins->dreg, ins->sreg1);
2807 s390_ngr (code, s390_r0, ins->sreg1);
2809 s390_lghi (code, s390_r13, -1);
2810 s390_sllg (code, s390_r13, s390_r13, 0, 8);
2811 s390_ogr (code, ins->dreg, s390_r13);
2814 case OP_LCONV_TO_I2: {
2815 s390_lghi (code, s390_r0, 0x80);
2816 s390_sllg (code, s390_r0, s390_r0, 0, 8);
2817 if (ins->dreg != ins->sreg1) {
2818 s390_lgr (code, ins->dreg, ins->sreg1);
2820 s390_ngr (code, s390_r0, ins->sreg1);
2822 s390_lghi (code, s390_r13, -1);
2823 s390_sllg (code, s390_r13, s390_r13, 0, 16);
2824 s390_ogr (code, ins->dreg, s390_r13);
2827 case OP_LCONV_TO_U1: {
2828 s390_lghi (code, s390_r0, 0xff);
2829 if (ins->dreg != ins->sreg1) {
2830 s390_lgr (code, ins->dreg, ins->sreg1);
2832 s390_ngr (code, ins->dreg, s390_r0);
2835 case OP_LCONV_TO_U2: {
2836 s390_lghi (code, s390_r0, -1);
2837 s390_sllg (code, s390_r0, s390_r0, 0, 16);
2838 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2839 if (ins->dreg != ins->sreg1) {
2840 s390_lgr (code, ins->dreg, ins->sreg1);
2842 s390_ngr (code, ins->dreg, s390_r0);
2845 case OP_ICONV_TO_I1: {
2846 s390_lhi (code, s390_r0, 0x80);
2847 if (ins->dreg != ins->sreg1) {
2848 s390_lr (code, ins->dreg, ins->sreg1);
2850 s390_nr (code, s390_r0, ins->sreg1);
2852 s390_lhi (code, s390_r13, -1);
2853 s390_sll (code, s390_r13, 0, 8);
2854 s390_or (code, ins->dreg, s390_r13);
2857 case OP_ICONV_TO_I2: {
2858 s390_lhi (code, s390_r0, 0x80);
2859 s390_sll (code, s390_r0, 0, 8);
2860 if (ins->dreg != ins->sreg1) {
2861 s390_lr (code, ins->dreg, ins->sreg1);
2863 s390_nr (code, s390_r0, ins->sreg1);
2865 s390_lhi (code, s390_r13, -1);
2866 s390_sll (code, s390_r13, 0, 16);
2867 s390_or (code, ins->dreg, s390_r13);
2870 case OP_ICONV_TO_U1: {
2871 s390_lhi (code, s390_r0, 0xff);
2872 if (ins->dreg != ins->sreg1) {
2873 s390_lr (code, ins->dreg, ins->sreg1);
2875 s390_nr (code, ins->dreg, s390_r0);
2878 case OP_ICONV_TO_U2: {
2879 s390_lhi (code, s390_r0, -1);
2880 s390_sll (code, s390_r0, 0, 16);
2881 s390_srl (code, s390_r0, 0, 16);
2882 if (ins->dreg != ins->sreg1) {
2883 s390_lr (code, ins->dreg, ins->sreg1);
2885 s390_nr (code, ins->dreg, s390_r0);
2890 if (is_unsigned (ins->next))
2891 s390_clgr (code, ins->sreg1, ins->sreg2);
2893 s390_cgr (code, ins->sreg1, ins->sreg2);
2897 if (is_unsigned (ins->next))
2898 s390_clr (code, ins->sreg1, ins->sreg2);
2900 s390_cr (code, ins->sreg1, ins->sreg2);
2903 case OP_COMPARE_IMM:
2904 case OP_LCOMPARE_IMM: {
2905 if (s390_is_imm16 (ins->inst_imm)) {
2906 s390_lghi (code, s390_r0, ins->inst_imm);
2907 if (is_unsigned (ins->next))
2908 s390_clgr (code, ins->sreg1, s390_r0);
2910 s390_cgr (code, ins->sreg1, s390_r0);
2912 s390_basr (code, s390_r13, 0);
2914 s390_llong(code, ins->inst_imm);
2915 if (is_unsigned (ins->next))
2916 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
2918 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
2922 case OP_ICOMPARE_IMM: {
2923 if (s390_is_imm16 (ins->inst_imm)) {
2924 s390_lghi (code, s390_r0, ins->inst_imm);
2925 if (is_unsigned (ins->next))
2926 s390_clr (code, ins->sreg1, s390_r0);
2928 s390_cr (code, ins->sreg1, s390_r0);
2931 s390_basr (code, s390_r13, 0);
2933 s390_word (code, ins->inst_imm);
2934 if (is_unsigned (ins->next))
2935 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
2937 s390_c (code, ins->sreg1, 0, s390_r13, 4);
2942 s390_basr (code, s390_r13, 0);
2944 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
2946 s390_llong (code, mono_break);
2947 s390_lg (code, s390_r14, 0, s390_r13, 4);
2948 s390_basr (code, s390_r14, s390_r14);
2953 s390_agr (code, ins->dreg, src2);
2958 s390_agr (code, ins->dreg, src2);
2963 s390_alcgr (code, ins->dreg, src2);
2967 if (ins->dreg != ins->sreg1) {
2968 s390_lgr (code, ins->dreg, ins->sreg1);
2970 if (s390_is_imm16 (ins->inst_imm)) {
2971 s390_aghi (code, ins->dreg, ins->inst_imm);
2973 s390_basr (code, s390_r13, 0);
2975 s390_llong(code, ins->inst_imm);
2976 s390_ag (code, ins->dreg, 0, s390_r13, 4);
2981 if (ins->dreg != ins->sreg1) {
2982 s390_lgr (code, ins->dreg, ins->sreg1);
2984 g_assert (s390_is_imm16 (ins->inst_imm));
2985 s390_aghi (code, ins->dreg, ins->inst_imm);
2989 if (ins->dreg != ins->sreg1) {
2990 s390_lgr (code, ins->dreg, ins->sreg1);
2992 if (s390_is_imm16 (ins->inst_imm)) {
2993 s390_lghi (code, s390_r0, ins->inst_imm);
2994 s390_alcgr (code, ins->dreg, s390_r0);
2996 s390_basr (code, s390_r13, 0);
2998 s390_llong (code, ins->inst_imm);
2999 s390_lg (code, s390_r13, 0, s390_r13, 4);
3000 s390_alcgr (code, ins->dreg, s390_r13);
3005 case OP_S390_IADD_OVF: {
3007 s390_ar (code, ins->dreg, src2);
3008 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3009 s390_lgfr (code, ins->dreg, ins->dreg);
3012 case OP_IADD_OVF_UN:
3013 case OP_S390_IADD_OVF_UN: {
3015 s390_algr (code, ins->dreg, src2);
3016 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3017 s390_llgfr (code, ins->dreg, ins->dreg);
3020 case OP_ADD_OVF_CARRY: {
3022 s390_lghi (code, s390_r0, 0);
3023 s390_lgr (code, s390_r1, s390_r0);
3024 s390_alcgr (code, s390_r0, s390_r1);
3025 s390_agr (code, ins->dreg, src2);
3026 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3027 s390_agr (code, ins->dreg, s390_r0);
3028 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3031 case OP_ADD_OVF_UN_CARRY: {
3033 s390_alcgr (code, ins->dreg, src2);
3034 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3039 s390_sgr (code, ins->dreg, src2);
3044 s390_sgr (code, ins->dreg, src2);
3049 s390_slbgr(code, ins->dreg, src2);
3053 if (ins->dreg != ins->sreg1) {
3054 s390_lgr (code, ins->dreg, ins->sreg1);
3056 if (s390_is_imm16 (-ins->inst_imm)) {
3057 s390_lghi (code, s390_r0, ins->inst_imm);
3058 s390_slgr (code, ins->dreg, s390_r0);
3060 s390_basr (code, s390_r13, 0);
3062 s390_llong(code, ins->inst_imm);
3063 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3068 if (ins->dreg != ins->sreg1) {
3069 s390_lgr (code, ins->dreg, ins->sreg1);
3071 if (s390_is_imm16 (-ins->inst_imm)) {
3072 s390_lghi (code, s390_r0, ins->inst_imm);
3073 s390_slgr (code, ins->dreg, s390_r0);
3075 s390_basr (code, s390_r13, 0);
3077 s390_llong(code, ins->inst_imm);
3078 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3083 if (ins->dreg != ins->sreg1) {
3084 s390_lgr (code, ins->dreg, ins->sreg1);
3086 if (s390_is_imm16 (-ins->inst_imm)) {
3087 s390_lghi (code, s390_r0, ins->inst_imm);
3088 s390_slbgr (code, ins->dreg, s390_r0);
3090 s390_basr (code, s390_r13, 0);
3092 s390_llong(code, ins->inst_imm);
3093 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3097 case OP_SUB_OVF_CARRY: {
3099 s390_lghi (code, s390_r0, 0);
3100 s390_lgr (code, s390_r1, s390_r0);
3101 s390_slbgr (code, s390_r0, s390_r1);
3102 s390_sgr (code, ins->dreg, src2);
3103 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3104 s390_agr (code, ins->dreg, s390_r0);
3105 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3108 case OP_SUB_OVF_UN_CARRY: {
3110 s390_slbgr (code, ins->dreg, src2);
3111 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3115 if (ins->sreg1 == ins->dreg) {
3116 s390_ngr (code, ins->dreg, ins->sreg2);
3119 if (ins->sreg2 == ins->dreg) {
3120 s390_ngr (code, ins->dreg, ins->sreg1);
3123 s390_lgr (code, ins->dreg, ins->sreg1);
3124 s390_ngr (code, ins->dreg, ins->sreg2);
3130 if (ins->dreg != ins->sreg1) {
3131 s390_lgr (code, ins->dreg, ins->sreg1);
3133 if (s390_is_imm16 (ins->inst_imm)) {
3134 s390_lghi (code, s390_r0, ins->inst_imm);
3135 s390_ngr (code, ins->dreg, s390_r0);
3137 s390_basr (code, s390_r13, 0);
3139 s390_llong(code, ins->inst_imm);
3140 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3145 s390_lgr (code, s390_r1, ins->sreg1);
3146 s390_dsgr (code, s390_r0, ins->sreg2);
3147 s390_lgr (code, ins->dreg, s390_r1);
3151 s390_lgr (code, s390_r1, ins->sreg1);
3152 s390_lghi (code, s390_r0, 0);
3153 s390_dlgr (code, s390_r0, ins->sreg2);
3154 s390_lgr (code, ins->dreg, s390_r1);
3158 s390_lgr (code, s390_r1, ins->sreg1);
3159 s390_dsgr (code, s390_r0, ins->sreg2);
3160 s390_lgr (code, ins->dreg, s390_r0);
3164 s390_lgr (code, s390_r1, ins->sreg1);
3165 s390_lghi (code, s390_r0, 0);
3166 s390_dlgr (code, s390_r0, ins->sreg2);
3167 s390_lgr (code, ins->dreg, s390_r0);
3171 if (ins->sreg1 == ins->dreg) {
3172 s390_ogr (code, ins->dreg, ins->sreg2);
3175 if (ins->sreg2 == ins->dreg) {
3176 s390_ogr (code, ins->dreg, ins->sreg1);
3179 s390_lgr (code, ins->dreg, ins->sreg1);
3180 s390_ogr (code, ins->dreg, ins->sreg2);
3186 if (ins->dreg != ins->sreg1) {
3187 s390_lgr (code, ins->dreg, ins->sreg1);
3189 if (s390_is_imm16 (ins->inst_imm)) {
3190 s390_lghi (code, s390_r0, ins->inst_imm);
3191 s390_ogr (code, ins->dreg, s390_r0);
3193 s390_basr (code, s390_r13, 0);
3195 s390_llong(code, ins->inst_imm);
3196 s390_og (code, ins->dreg, 0, s390_r13, 4);
3201 if (ins->sreg1 == ins->dreg) {
3202 s390_xgr (code, ins->dreg, ins->sreg2);
3205 if (ins->sreg2 == ins->dreg) {
3206 s390_xgr (code, ins->dreg, ins->sreg1);
3209 s390_lgr (code, ins->dreg, ins->sreg1);
3210 s390_xgr (code, ins->dreg, ins->sreg2);
3216 if (ins->dreg != ins->sreg1) {
3217 s390_lgr (code, ins->dreg, ins->sreg1);
3219 if (s390_is_imm16 (ins->inst_imm)) {
3220 s390_lghi (code, s390_r0, ins->inst_imm);
3221 s390_xgr (code, ins->dreg, s390_r0);
3223 s390_basr (code, s390_r13, 0);
3225 s390_llong(code, ins->inst_imm);
3226 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3232 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3237 if (ins->sreg1 != ins->dreg) {
3238 s390_lgr (code, ins->dreg, ins->sreg1);
3240 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3245 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3250 if (ins->sreg1 != ins->dreg) {
3251 s390_lgr (code, ins->dreg, ins->sreg1);
3253 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3257 case OP_LSHR_UN_IMM: {
3258 if (ins->sreg1 != ins->dreg) {
3259 s390_lgr (code, ins->dreg, ins->sreg1);
3261 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3266 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3270 if (ins->sreg1 != ins->dreg) {
3271 s390_lgr (code, ins->dreg, ins->sreg1);
3273 s390_lghi (code, s390_r0, -1);
3274 s390_xgr (code, ins->dreg, s390_r0);
3278 s390_lcgr (code, ins->dreg, ins->sreg1);
3283 s390_msgr (code, ins->dreg, src2);
3288 if (ins->dreg != ins->sreg1) {
3289 s390_lgr (code, ins->dreg, ins->sreg1);
3291 if (s390_is_imm16 (ins->inst_imm)) {
3292 s390_lghi (code, s390_r13, ins->inst_imm);
3294 s390_basr (code, s390_r13, 0);
3296 s390_llong(code, ins->inst_imm);
3297 s390_lg (code, s390_r13, 0, s390_r13, 4);
3299 s390_msgr (code, ins->dreg, s390_r13);
3304 s390_ltgr (code, s390_r1, ins->sreg1);
3305 s390_jz (code, 0); CODEPTR(code, o[0]);
3306 s390_ltgr (code, s390_r0, ins->sreg2);
3308 s390_lghi (code, s390_r1, 0);
3309 s390_j (code, 0); CODEPTR(code, o[1]);
3310 s390_xgr (code, s390_r0, s390_r1);
3311 s390_msgr (code, s390_r1, ins->sreg2);
3312 s390_xgr (code, s390_r0, s390_r1);
3313 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3314 s390_ltgr (code, s390_r0, s390_r0);
3315 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3316 PTRSLOT (code, o[0]);
3317 PTRSLOT (code, o[1]);
3318 s390_lgr (code, ins->dreg, s390_r1);
3321 case OP_LMUL_OVF_UN: {
3322 s390_lghi (code, s390_r0, 0);
3323 s390_lgr (code, s390_r1, ins->sreg1);
3324 s390_mlgr (code, s390_r0, ins->sreg2);
3325 s390_ltgr (code, s390_r0, s390_r0);
3326 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3327 s390_lgr (code, ins->dreg, s390_r1);
3331 g_assert_not_reached ();
3333 s390_algr (code, ins->dreg, src2);
3338 s390_agr (code, ins->dreg, src2);
3342 g_assert_not_reached ();
3344 s390_alcgr (code, ins->dreg, src2);
3348 if (ins->dreg != ins->sreg1) {
3349 s390_lgfr (code, ins->dreg, ins->sreg1);
3351 if (s390_is_imm16 (ins->inst_imm)) {
3352 s390_aghi(code, ins->dreg, ins->inst_imm);
3354 s390_basr (code, s390_r13, 0);
3356 s390_word (code, ins->inst_imm);
3357 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3362 if (ins->dreg != ins->sreg1) {
3363 s390_lgfr (code, ins->dreg, ins->sreg1);
3365 if (s390_is_imm16 (ins->inst_imm)) {
3366 s390_lghi (code, s390_r0, ins->inst_imm);
3367 s390_alcgr (code, ins->dreg, s390_r0);
3369 s390_basr (code, s390_r13, 0);
3371 s390_word (code, ins->inst_imm);
3372 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3373 s390_alcgr (code, ins->dreg, s390_r13);
3378 case OP_S390_LADD_OVF: {
3380 s390_agr (code, ins->dreg, src2);
3381 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3384 case OP_LADD_OVF_UN:
3385 case OP_S390_LADD_OVF_UN: {
3387 s390_algr (code, ins->dreg, src2);
3388 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3392 CHECK_SRCDST_NCOM_I;
3393 s390_slgr (code, ins->dreg, src2);
3397 CHECK_SRCDST_NCOM_I;
3398 s390_sgr (code, ins->dreg, src2);
3402 CHECK_SRCDST_NCOM_I;
3403 s390_slbgr (code, ins->dreg, src2);
3407 if (ins->dreg != ins->sreg1) {
3408 s390_lgfr (code, ins->dreg, ins->sreg1);
3410 if (s390_is_imm16 (-ins->inst_imm)) {
3411 s390_aghi (code, ins->dreg, -ins->inst_imm);
3413 s390_basr (code, s390_r13, 0);
3415 s390_word (code, ins->inst_imm);
3416 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3421 s390_basr (code, s390_r13, 0);
3423 s390_word (code, ins->inst_imm);
3424 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3428 case OP_S390_ISUB_OVF: {
3430 s390_sr (code, ins->dreg, src2);
3431 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3432 s390_lgfr (code, ins->dreg, ins->dreg);
3435 case OP_ISUB_OVF_UN:
3436 case OP_S390_ISUB_OVF_UN: {
3438 s390_slr (code, ins->dreg, src2);
3439 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3440 s390_llgfr(code, ins->dreg, ins->dreg);
3444 case OP_S390_LSUB_OVF: {
3446 s390_sgr (code, ins->dreg, src2);
3447 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3450 case OP_LSUB_OVF_UN:
3451 case OP_S390_LSUB_OVF_UN: {
3453 s390_slgr (code, ins->dreg, src2);
3454 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3458 CHECK_SRCDST_NCOM_I;
3459 s390_ngr (code, ins->dreg, src2);
3463 if (ins->dreg != ins->sreg1) {
3464 s390_lgfr (code, ins->dreg, ins->sreg1);
3466 if (s390_is_imm16 (ins->inst_imm)) {
3467 s390_lghi (code, s390_r0, ins->inst_imm);
3468 s390_ngr (code, ins->dreg, s390_r0);
3470 s390_basr (code, s390_r13, 0);
3472 s390_llong(code, ins->inst_imm);
3473 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3478 s390_lgfr (code, s390_r0, ins->sreg1);
3479 s390_srda (code, s390_r0, 0, 32);
3480 s390_dr (code, s390_r0, ins->sreg2);
3481 s390_lgfr (code, ins->dreg, s390_r1);
3485 s390_lgfr (code, s390_r0, ins->sreg1);
3486 s390_srdl (code, s390_r0, 0, 32);
3487 s390_dlr (code, s390_r0, ins->sreg2);
3488 s390_lgfr (code, ins->dreg, s390_r1);
3492 if (s390_is_imm16 (ins->inst_imm)) {
3493 s390_lghi (code, s390_r13, ins->inst_imm);
3494 s390_lgfr (code, s390_r0, ins->sreg1);
3496 s390_basr (code, s390_r13, 0);
3498 s390_word (code, ins->inst_imm);
3499 s390_lgfr (code, s390_r0, ins->sreg1);
3500 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3502 s390_srda (code, s390_r0, 0, 32);
3503 s390_dr (code, s390_r0, ins->sreg2);
3504 s390_lgfr (code, ins->dreg, s390_r1);
3508 s390_lgfr (code, s390_r0, ins->sreg1);
3509 s390_srda (code, s390_r0, 0, 32);
3510 s390_dr (code, s390_r0, ins->sreg2);
3511 s390_lgfr (code, ins->dreg, s390_r0);
3514 s390_lgfr (code, s390_r0, ins->sreg1);
3515 s390_srdl (code, s390_r0, 0, 32);
3516 s390_dlr (code, s390_r0, ins->sreg2);
3517 s390_lgfr (code, ins->dreg, s390_r0);
3521 if (s390_is_imm16 (ins->inst_imm)) {
3522 s390_lghi (code, s390_r13, ins->inst_imm);
3523 s390_lgfr (code, s390_r0, ins->sreg1);
3525 s390_basr (code, s390_r13, 0);
3527 s390_word (code, ins->inst_imm);
3528 s390_lgfr (code, s390_r0, ins->sreg1);
3529 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3531 s390_srda (code, s390_r0, 0, 32);
3532 s390_dr (code, s390_r0, ins->sreg2);
3533 s390_lgfr (code, ins->dreg, s390_r0);
3538 s390_ogr (code, ins->dreg, src2);
3542 if (ins->dreg != ins->sreg1) {
3543 s390_lgfr (code, ins->dreg, ins->sreg1);
3545 if (s390_is_imm16 (ins->inst_imm)) {
3546 s390_lghi (code, s390_r0, ins->inst_imm);
3547 s390_ogr (code, ins->dreg, s390_r0);
3549 s390_basr (code, s390_r13, 0);
3551 s390_llong(code, ins->inst_imm);
3552 s390_og (code, ins->dreg, 0, s390_r13, 4);
3558 s390_xgr (code, ins->dreg, src2);
3562 if (ins->dreg != ins->sreg1) {
3563 s390_lgfr (code, ins->dreg, ins->sreg1);
3565 if (s390_is_imm16 (ins->inst_imm)) {
3566 s390_lghi (code, s390_r0, ins->inst_imm);
3567 s390_xgr (code, ins->dreg, s390_r0);
3569 s390_basr (code, s390_r13, 0);
3571 s390_llong(code, ins->inst_imm);
3572 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3578 s390_sll (code, ins->dreg, src2, 0);
3582 if (ins->sreg1 != ins->dreg) {
3583 s390_lgfr (code, ins->dreg, ins->sreg1);
3585 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3590 s390_sra (code, ins->dreg, src2, 0);
3594 if (ins->sreg1 != ins->dreg) {
3595 s390_lgfr (code, ins->dreg, ins->sreg1);
3597 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3600 case OP_ISHR_UN_IMM: {
3601 if (ins->sreg1 != ins->dreg) {
3602 s390_lgfr (code, ins->dreg, ins->sreg1);
3604 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3609 s390_srl (code, ins->dreg, src2, 0);
3613 if (ins->sreg1 != ins->dreg) {
3614 s390_lgfr (code, ins->dreg, ins->sreg1);
3616 s390_lghi (code, s390_r0, -1);
3617 s390_xgr (code, ins->dreg, s390_r0);
3621 s390_lcgr (code, ins->dreg, ins->sreg1);
3626 s390_msr (code, ins->dreg, src2);
3630 if (ins->dreg != ins->sreg1) {
3631 s390_lgfr (code, ins->dreg, ins->sreg1);
3633 if (s390_is_imm16 (ins->inst_imm)) {
3634 s390_lghi (code, s390_r13, ins->inst_imm);
3636 s390_basr (code, s390_r13, 0);
3638 s390_word (code, ins->inst_imm);
3639 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3641 s390_msr (code, ins->dreg, s390_r13);
3646 s390_ltr (code, s390_r1, ins->sreg1);
3647 s390_jz (code, 0); CODEPTR(code, o[0]);
3648 s390_ltr (code, s390_r0, ins->sreg2);
3650 s390_lhi (code, s390_r1, 0);
3651 s390_j (code, 0); CODEPTR(code, o[1]);
3652 s390_xr (code, s390_r0, s390_r1);
3653 s390_msr (code, s390_r1, ins->sreg2);
3654 s390_xr (code, s390_r0, s390_r1);
3655 s390_srl (code, s390_r0, 0, 31);
3656 s390_ltr (code, s390_r0, s390_r0);
3657 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3658 PTRSLOT (code, o[0]);
3659 PTRSLOT (code, o[1]);
3660 s390_lgfr (code, ins->dreg, s390_r1);
3663 case OP_IMUL_OVF_UN: {
3664 s390_lhi (code, s390_r0, 0);
3665 s390_lr (code, s390_r1, ins->sreg1);
3666 s390_mlr (code, s390_r0, ins->sreg2);
3667 s390_ltr (code, s390_r0, s390_r0);
3668 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3669 s390_lgfr (code, ins->dreg, s390_r1);
3674 if (s390_is_imm16(ins->inst_c0)) {
3675 s390_lghi (code, ins->dreg, ins->inst_c0);
3677 s390_basr (code, s390_r13, 0);
3679 s390_llong(code, ins->inst_c0);
3680 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3685 s390_basr (code, s390_r13, 0);
3687 mono_add_patch_info (cfg, code - cfg->native_code,
3688 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3689 s390_llong(code, 0);
3690 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3693 case OP_JUMP_TABLE: {
3694 mono_add_patch_info (cfg, code - cfg->native_code,
3695 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3696 s390_basr (code, s390_r13, 0);
3698 s390_llong (code, 0);
3699 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3703 if (ins->dreg != ins->sreg1) {
3704 s390_lgr (code, ins->dreg, ins->sreg1);
3708 case OP_LCONV_TO_I8:
3710 s390_lgfr (code, ins->dreg, ins->sreg1);
3712 case OP_LCONV_TO_I4:
3713 s390_lgfr (code, ins->dreg, ins->sreg1);
3716 case OP_LCONV_TO_U8:
3717 case OP_LCONV_TO_U4:
3719 s390_llgfr (code, ins->dreg, ins->sreg1);
3721 case OP_LCONV_TO_OVF_U4:
3722 s390_basr (code, s390_r13, 0);
3724 s390_llong(code, 4294967295);
3725 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3726 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3727 s390_ltgr (code, ins->sreg1, ins->sreg1);
3728 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3729 s390_llgfr(code, ins->dreg, ins->sreg1);
3731 case OP_LCONV_TO_OVF_I4_UN:
3732 s390_basr (code, s390_r13, 0);
3734 s390_llong(code, 2147483647);
3735 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3736 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3737 s390_ltgr (code, ins->sreg1, ins->sreg1);
3738 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3739 s390_lgfr (code, ins->dreg, ins->sreg1);
3742 case OP_FCONV_TO_R4: {
3743 if (ins->dreg != ins->sreg1) {
3744 s390_ldr (code, ins->dreg, ins->sreg1);
3748 case OP_S390_SETF4RET: {
3749 s390_ledbr (code, ins->dreg, ins->sreg1);
3753 if (cfg->method->save_lmf)
3754 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3756 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3757 code = emit_load_volatile_arguments (code, cfg);
3760 code = backUpStackPtr(cfg, code);
3761 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3762 mono_add_patch_info (cfg, code - cfg->native_code,
3763 MONO_PATCH_INFO_METHOD_JUMP,
3765 s390_jcl (code, S390_CC_UN, 0);
3768 case OP_CHECK_THIS: {
3769 /* ensure ins->sreg1 is not NULL */
3770 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3771 s390_ltgr (code, s390_r0, s390_r0);
3775 int offset = cfg->sig_cookie + cfg->stack_usage;
3777 if (s390_is_imm16 (offset))
3778 s390_lghi (code, s390_r0, offset);
3780 s390_basr (code, s390_r13, 0);
3782 s390_llong(code, offset);
3783 s390_lg (code, s390_r0, 0, s390_r13, 0);
3785 s390_agr (code, s390_r0, cfg->frame_reg);
3786 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3790 s390_basr (code, s390_r13, 0);
3792 call = (MonoCallInst*)ins;
3793 if (ins->flags & MONO_INST_HAS_METHOD)
3794 mono_add_patch_info (cfg, code-cfg->native_code,
3795 MONO_PATCH_INFO_METHOD,
3798 mono_add_patch_info (cfg, code-cfg->native_code,
3799 MONO_PATCH_INFO_ABS,
3801 s390_llong(code, 0);
3802 s390_lg (code, s390_r14, 0, s390_r13, 4);
3803 s390_basr (code, s390_r14, s390_r14);
3804 if (call->signature->ret->type == MONO_TYPE_R4)
3805 s390_ldebr (code, s390_f0, s390_f0);
3813 s390_basr (code, s390_r13, 0);
3815 call = (MonoCallInst*)ins;
3816 if (ins->flags & MONO_INST_HAS_METHOD)
3817 mono_add_patch_info (cfg, code-cfg->native_code,
3818 MONO_PATCH_INFO_METHOD,
3821 mono_add_patch_info (cfg, code-cfg->native_code,
3822 MONO_PATCH_INFO_ABS,
3824 s390_llong(code, 0);
3825 s390_lg (code, s390_r14, 0, s390_r13, 4);
3826 s390_basr (code, s390_r14, s390_r14);
3829 case OP_FCALL_REG: {
3830 call = (MonoCallInst*)ins;
3831 s390_lgr (code, s390_r1, ins->sreg1);
3832 s390_basr (code, s390_r14, s390_r1);
3833 if (call->signature->ret->type == MONO_TYPE_R4)
3834 s390_ldebr (code, s390_f0, s390_f0);
3840 case OP_VOIDCALL_REG:
3842 s390_lgr (code, s390_r1, ins->sreg1);
3843 s390_basr (code, s390_r14, s390_r1);
3846 case OP_FCALL_MEMBASE: {
3847 call = (MonoCallInst*)ins;
3848 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3849 s390_basr (code, s390_r14, s390_r1);
3850 if (call->signature->ret->type == MONO_TYPE_R4)
3851 s390_ldebr (code, s390_f0, s390_f0);
3854 case OP_LCALL_MEMBASE:
3855 case OP_VCALL_MEMBASE:
3856 case OP_VCALL2_MEMBASE:
3857 case OP_VOIDCALL_MEMBASE:
3858 case OP_CALL_MEMBASE: {
3859 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3860 s390_basr (code, s390_r14, s390_r1);
3864 int alloca_skip = S390_MINIMAL_STACK_SIZE + cfg->param_area;
3865 int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3866 s390_lgr (code, s390_r1, ins->sreg1);
3867 if (ins->flags & MONO_INST_INIT)
3868 s390_lgr (code, s390_r0, ins->sreg1);
3869 s390_aghi (code, s390_r1, 14);
3870 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3871 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3872 if (cfg->method->save_lmf) {
3873 /*----------------------------------*/
3874 /* we have to adjust lmf ebp value */
3875 /*----------------------------------*/
3876 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3878 s390_lgr (code, s390_r13, cfg->frame_reg);
3879 if (s390_is_imm16(lmfOffset))
3880 s390_aghi (code, s390_r13, lmfOffset);
3882 s390_basr (code, s390_r14, 0);
3884 s390_word (code, lmfOffset);
3885 s390_agf (code, s390_r13, 0, s390_r14, 4);
3887 s390_lgr (code, s390_r14, STK_BASE);
3888 s390_sgr (code, s390_r14, s390_r1);
3889 s390_stg (code, s390_r14, 0, s390_r13,
3890 G_STRUCT_OFFSET(MonoLMF, ebp));
3892 s390_lg (code, s390_r13, 0, STK_BASE, 0);
3893 s390_sgr (code, STK_BASE, s390_r1);
3894 s390_stg (code, s390_r13, 0, STK_BASE, 0);
3895 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
3896 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
3897 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
3898 if (ins->flags & MONO_INST_INIT) {
3899 s390_lgr (code, s390_r1, s390_r0);
3900 s390_lgr (code, s390_r0, ins->dreg);
3901 s390_lgr (code, s390_r14, s390_r12);
3902 s390_lghi (code, s390_r13, 0);
3903 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
3905 s390_lgr (code, s390_r12, s390_r14);
3910 s390_lgr (code, s390_r2, ins->sreg1);
3911 s390_basr (code, s390_r13, 0);
3913 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3914 (gpointer) "mono_arch_throw_exception");
3915 s390_llong(code, 0);
3916 s390_lg (code, s390_r14, 0, s390_r13, 4);
3917 s390_basr (code, s390_r14, s390_r14);
3921 s390_lgr (code, s390_r2, ins->sreg1);
3922 s390_basr (code, s390_r13, 0);
3924 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3925 (gpointer) "mono_arch_rethrow_exception");
3926 s390_llong(code, 0);
3927 s390_lg (code, s390_r14, 0, s390_r13, 4);
3928 s390_basr (code, s390_r14, s390_r14);
3931 case OP_START_HANDLER: {
3932 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3934 S390_LONG (code, stg, stg, s390_r14, 0,
3935 spvar->inst_basereg,
3936 spvar->inst_offset);
3939 case OP_ENDFILTER: {
3940 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3942 if (ins->sreg1 != s390_r2)
3943 s390_lgr(code, s390_r2, ins->sreg1);
3944 S390_LONG (code, lg, lg, s390_r14, 0,
3945 spvar->inst_basereg,
3946 spvar->inst_offset);
3947 s390_br (code, s390_r14);
3950 case OP_ENDFINALLY: {
3951 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3953 S390_LONG (code, lg, lg, s390_r14, 0,
3954 spvar->inst_basereg,
3955 spvar->inst_offset);
3956 s390_br (code, s390_r14);
3959 case OP_CALL_HANDLER: {
3960 mono_add_patch_info (cfg, code-cfg->native_code,
3961 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3962 s390_brasl (code, s390_r14, 0);
3966 ins->inst_c0 = code - cfg->native_code;
3969 case OP_RELAXED_NOP:
3972 case OP_DUMMY_STORE:
3973 case OP_NOT_REACHED:
3978 EMIT_UNCOND_BRANCH(ins);
3981 s390_br (code, ins->sreg1);
3987 s390_lghi(code, ins->dreg, 1);
3989 s390_lghi(code, ins->dreg, 0);
3995 s390_lghi(code, ins->dreg, 1);
3997 s390_lghi(code, ins->dreg, 0);
4003 s390_lghi(code, ins->dreg, 1);
4005 s390_lghi(code, ins->dreg, 0);
4011 s390_lghi(code, ins->dreg, 1);
4013 s390_lghi(code, ins->dreg, 0);
4019 s390_lghi(code, ins->dreg, 1);
4021 s390_lghi(code, ins->dreg, 0);
4024 case OP_COND_EXC_EQ:
4025 case OP_COND_EXC_IEQ:
4026 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4028 case OP_COND_EXC_NE_UN:
4029 case OP_COND_EXC_INE_UN:
4030 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4032 case OP_COND_EXC_LT:
4033 case OP_COND_EXC_ILT:
4034 case OP_COND_EXC_LT_UN:
4035 case OP_COND_EXC_ILT_UN:
4036 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4038 case OP_COND_EXC_GT:
4039 case OP_COND_EXC_IGT:
4040 case OP_COND_EXC_GT_UN:
4041 case OP_COND_EXC_IGT_UN:
4042 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4044 case OP_COND_EXC_GE:
4045 case OP_COND_EXC_IGE:
4046 case OP_COND_EXC_GE_UN:
4047 case OP_COND_EXC_IGE_UN:
4048 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4050 case OP_COND_EXC_LE:
4051 case OP_COND_EXC_ILE:
4052 case OP_COND_EXC_LE_UN:
4053 case OP_COND_EXC_ILE_UN:
4054 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4056 case OP_COND_EXC_OV:
4057 case OP_COND_EXC_IOV:
4058 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4060 case OP_COND_EXC_NO:
4061 case OP_COND_EXC_INO:
4062 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4065 case OP_COND_EXC_IC:
4066 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4068 case OP_COND_EXC_NC:
4069 case OP_COND_EXC_INC:
4070 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4074 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4078 EMIT_COND_BRANCH (ins, S390_CC_NE);
4084 EMIT_COND_BRANCH (ins, S390_CC_LT);
4090 EMIT_COND_BRANCH (ins, S390_CC_GT);
4096 EMIT_COND_BRANCH (ins, S390_CC_GE);
4102 EMIT_COND_BRANCH (ins, S390_CC_LE);
4105 /* floating point opcodes */
4107 if (*((float *) ins->inst_p0) == 0) {
4108 s390_lzdr (code, ins->dreg);
4110 s390_basr (code, s390_r13, 0);
4112 s390_llong (code, ins->inst_p0);
4113 s390_lg (code, s390_r13, 0, s390_r13, 4);
4114 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4119 if (*((float *) ins->inst_p0) == 0) {
4120 s390_lzdr (code, ins->dreg);
4122 s390_basr (code, s390_r13, 0);
4124 s390_llong(code, ins->inst_p0);
4125 s390_lg (code, s390_r13, 0, s390_r13, 4);
4126 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4130 case OP_STORER8_MEMBASE_REG: {
4131 S390_LONG (code, stdy, std, ins->sreg1, 0,
4132 ins->inst_destbasereg, ins->inst_offset);
4135 case OP_LOADR8_MEMBASE: {
4136 S390_LONG (code, ldy, ld, ins->dreg, 0,
4137 ins->inst_basereg, ins->inst_offset);
4140 case OP_STORER4_MEMBASE_REG: {
4141 s390_ledbr (code, s390_f15, ins->sreg1);
4142 S390_LONG (code, stey, ste, s390_f15, 0,
4143 ins->inst_destbasereg, ins->inst_offset);
4146 case OP_LOADR4_MEMBASE: {
4147 S390_LONG (code, ldy, ld, s390_f15, 0,
4148 ins->inst_basereg, ins->inst_offset);
4149 s390_ldebr (code, ins->dreg, s390_f15);
4152 case OP_ICONV_TO_R_UN: {
4153 s390_cdfbr (code, ins->dreg, ins->sreg1);
4154 s390_ltr (code, ins->sreg1, ins->sreg1);
4155 s390_jnl (code, 12);
4156 s390_basr (code, s390_r13, 0);
4158 s390_word (code, 0x41f00000);
4159 s390_word (code, 0);
4160 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4163 case OP_LCONV_TO_R_UN: {
4164 s390_cdgbr (code, ins->dreg, ins->sreg1);
4165 s390_ltgr (code, ins->sreg1, ins->sreg1);
4166 s390_jnl (code, 12);
4167 s390_basr (code, s390_r13, 0);
4169 s390_word (code, 0x41f00000);
4170 s390_word (code, 0);
4171 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4174 case OP_LCONV_TO_R4:
4175 case OP_ICONV_TO_R4: {
4176 s390_cdgbr (code, ins->dreg, ins->sreg1);
4179 case OP_LCONV_TO_R8:
4180 case OP_ICONV_TO_R8: {
4181 s390_cdgbr (code, ins->dreg, ins->sreg1);
4184 case OP_FCONV_TO_I1:
4185 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4187 case OP_FCONV_TO_U1:
4188 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4190 case OP_FCONV_TO_I2:
4191 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4193 case OP_FCONV_TO_U2:
4194 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4196 case OP_FCONV_TO_I4:
4198 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4200 case OP_FCONV_TO_U4:
4202 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4204 case OP_FCONV_TO_I8:
4205 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4207 case OP_LCONV_TO_OVF_I: {
4208 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4210 s390_ltgr (code, ins->sreg2, ins->sreg2);
4211 s390_jnl (code, 0); CODEPTR(code, o[0]);
4212 s390_ltgr (code, ins->sreg1, ins->sreg1);
4213 s390_jnl (code, 0); CODEPTR(code, o[1]);
4214 s390_lhi (code, s390_r13, -1);
4215 s390_cgr (code, ins->sreg1, s390_r13);
4216 s390_jnz (code, 0); CODEPTR(code, o[2]);
4217 if (ins->dreg != ins->sreg2)
4218 s390_lgr (code, ins->dreg, ins->sreg2);
4219 s390_j (code, 0); CODEPTR(code, o[3]);
4220 PTRSLOT(code, o[0]);
4221 s390_jz (code, 0); CODEPTR(code, o[4]);
4222 PTRSLOT(code, o[1]);
4223 PTRSLOT(code, o[2]);
4224 mono_add_patch_info (cfg, code - cfg->native_code,
4225 MONO_PATCH_INFO_EXC, "OverflowException");
4226 s390_brasl (code, s390_r14, 0);
4227 PTRSLOT(code, o[3]);
4228 PTRSLOT(code, o[4]);
4232 s390_lpdbr (code, ins->dreg, ins->sreg1);
4236 s390_sqdbr (code, ins->dreg, ins->sreg1);
4241 s390_adbr (code, ins->dreg, src2);
4245 CHECK_SRCDST_NCOM_F;
4246 s390_sdbr (code, ins->dreg, src2);
4251 s390_mdbr (code, ins->dreg, src2);
4255 CHECK_SRCDST_NCOM_F;
4256 s390_ddbr (code, ins->dreg, src2);
4260 s390_lcdbr (code, ins->dreg, ins->sreg1);
4264 CHECK_SRCDST_NCOM_F;
4265 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4269 s390_cdbr (code, ins->sreg1, ins->sreg2);
4273 s390_cdbr (code, ins->sreg1, ins->sreg2);
4274 s390_lghi (code, ins->dreg, 1);
4276 s390_lghi (code, ins->dreg, 0);
4280 s390_cdbr (code, ins->sreg1, ins->sreg2);
4281 s390_lghi (code, ins->dreg, 1);
4283 s390_lghi (code, ins->dreg, 0);
4287 s390_cdbr (code, ins->sreg1, ins->sreg2);
4288 s390_lghi (code, ins->dreg, 1);
4290 s390_lghi (code, ins->dreg, 0);
4294 s390_cdbr (code, ins->sreg1, ins->sreg2);
4295 s390_lghi (code, ins->dreg, 1);
4297 s390_lghi (code, ins->dreg, 0);
4301 s390_cdbr (code, ins->sreg1, ins->sreg2);
4302 s390_lghi (code, ins->dreg, 1);
4304 s390_lghi (code, ins->dreg, 0);
4309 s390_jo (code, 0); CODEPTR(code, o);
4310 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4315 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4319 s390_jo (code, 0); CODEPTR(code, o);
4320 EMIT_COND_BRANCH (ins, S390_CC_LT);
4325 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4329 s390_jo (code, 0); CODEPTR(code, o);
4330 EMIT_COND_BRANCH (ins, S390_CC_GT);
4335 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4339 s390_jo (code, 0); CODEPTR(code, o);
4340 EMIT_COND_BRANCH (ins, S390_CC_GE);
4345 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4349 s390_jo (code, 0); CODEPTR(code, o);
4350 EMIT_COND_BRANCH (ins, S390_CC_LE);
4355 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4359 s390_lhi (code, s390_r13, 0x7f);
4360 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4361 s390_jz (code, 0); CODEPTR(code, o);
4362 mono_add_patch_info (cfg, code - cfg->native_code,
4363 MONO_PATCH_INFO_EXC, "ArithmeticException");
4364 s390_brasl (code, s390_r14,0);
4368 case OP_S390_MOVE: {
4369 if (ins->backend.size > 0) {
4370 if (ins->backend.size <= 256) {
4371 s390_mvc (code, ins->backend.size, ins->dreg,
4372 ins->inst_offset, ins->sreg1, ins->inst_imm);
4374 s390_lgr (code, s390_r0, ins->dreg);
4375 if (s390_is_imm16 (ins->inst_offset)) {
4376 s390_aghi (code, s390_r0, ins->inst_offset);
4378 s390_basr (code, s390_r13, 0);
4380 s390_llong(code, ins->inst_offset);
4381 s390_a (code, s390_r0, 0, s390_r13, 4);
4383 s390_lgr (code, s390_r12, ins->sreg1);
4384 if (s390_is_imm16 (ins->inst_imm)) {
4385 s390_aghi (code, s390_r12, ins->inst_imm);
4387 s390_basr (code, s390_r13, 0);
4389 s390_llong(code, ins->inst_imm);
4390 s390_ag (code, s390_r12, 0, s390_r13, 4);
4392 s390_lgr (code, s390_r1, ins->sreg1);
4393 s390_lgr (code, s390_r13, s390_r1);
4394 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4400 case OP_ATOMIC_ADD_I8: {
4401 s390_lgr (code, s390_r1, ins->sreg2);
4402 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4403 s390_agr (code, s390_r1, s390_r0);
4404 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4405 s390_jnz (code, -10);
4406 s390_lgr (code, ins->dreg, s390_r1);
4409 case OP_ATOMIC_ADD_NEW_I8: {
4410 s390_lgr (code, s390_r1, ins->sreg2);
4411 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4412 s390_agr (code, s390_r1, s390_r0);
4413 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4414 s390_jnz (code, -10);
4415 s390_lgr (code, ins->dreg, s390_r1);
4418 case OP_ATOMIC_EXCHANGE_I8: {
4419 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4420 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4421 s390_jnz (code, -6);
4422 s390_lgr (code, ins->dreg, s390_r0);
4425 case OP_ATOMIC_ADD_I4: {
4426 s390_lgfr(code, s390_r1, ins->sreg2);
4427 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4428 s390_agr (code, s390_r1, s390_r0);
4429 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4430 s390_jnz (code, -9);
4431 s390_lgfr(code, ins->dreg, s390_r1);
4434 case OP_ATOMIC_ADD_NEW_I4: {
4435 s390_lgfr(code, s390_r1, ins->sreg2);
4436 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4437 s390_agr (code, s390_r1, s390_r0);
4438 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4439 s390_jnz (code, -9);
4440 s390_lgfr(code, ins->dreg, s390_r1);
4443 case OP_ATOMIC_EXCHANGE_I4: {
4444 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4445 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4446 s390_jnz (code, -4);
4447 s390_lgfr(code, ins->dreg, s390_r0);
4450 case OP_S390_BKCHAIN: {
4451 s390_lgr (code, ins->dreg, ins->sreg1);
4452 if (s390_is_imm16 (cfg->stack_offset)) {
4453 s390_aghi (code, ins->dreg, cfg->stack_offset);
4455 s390_basr (code, s390_r13, 0);
4457 s390_llong(code, cfg->stack_offset);
4458 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4462 case OP_MEMORY_BARRIER: {
4466 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4467 g_assert_not_reached ();
4470 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4471 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4472 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4473 g_assert_not_reached ();
4478 last_offset = offset;
4481 cfg->code_len = code - cfg->native_code;
4484 /*========================= End of Function ========================*/
4486 /*------------------------------------------------------------------*/
4488 /* Name - mono_arch_register_lowlevel_calls */
4490 /* Function - Register routines to help with --trace operation. */
4492 /*------------------------------------------------------------------*/
4495 mono_arch_register_lowlevel_calls (void)
4497 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4500 /*========================= End of Function ========================*/
4502 /*------------------------------------------------------------------*/
4504 /* Name - mono_arch_patch_code */
4506 /* Function - Process the patch data created during the */
4507 /* instruction build process. This resolves jumps, */
4508 /* calls, variables etc. */
4510 /*------------------------------------------------------------------*/
4513 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4514 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4516 MonoJumpInfo *patch_info;
4518 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4519 unsigned char *ip = patch_info->ip.i + code;
4520 gconstpointer target = NULL;
4522 target = mono_resolve_patch_target (method, domain, code,
4523 patch_info, run_cctors);
4525 switch (patch_info->type) {
4526 case MONO_PATCH_INFO_IP:
4527 case MONO_PATCH_INFO_EXC_NAME:
4528 case MONO_PATCH_INFO_LDSTR:
4529 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4530 case MONO_PATCH_INFO_LDTOKEN:
4531 case MONO_PATCH_INFO_EXC:
4532 case MONO_PATCH_INFO_ABS:
4533 case MONO_PATCH_INFO_METHOD:
4534 case MONO_PATCH_INFO_INTERNAL_METHOD:
4535 case MONO_PATCH_INFO_CLASS_INIT:
4536 s390_patch_addr (ip, (guint64) target);
4538 case MONO_PATCH_INFO_SWITCH:
4539 /*----------------------------------*/
4540 /* ip points at the basr r13,0/j +4 */
4541 /* instruction the vtable value */
4542 /* follows this (i.e. ip+6) */
4543 /*----------------------------------*/
4544 *((gconstpointer *)(ip+6)) = target;
4546 case MONO_PATCH_INFO_METHODCONST:
4547 case MONO_PATCH_INFO_CLASS:
4548 case MONO_PATCH_INFO_IMAGE:
4549 case MONO_PATCH_INFO_FIELD:
4550 case MONO_PATCH_INFO_IID:
4551 target = S390_RELATIVE(target, ip);
4552 s390_patch_rel (ip, (guint64) target);
4554 case MONO_PATCH_INFO_R4:
4555 case MONO_PATCH_INFO_R8:
4556 case MONO_PATCH_INFO_METHOD_REL:
4557 g_assert_not_reached ();
4560 target = S390_RELATIVE(target, ip);
4562 s390_patch_rel (ip, (guint64) target);
4567 /*========================= End of Function ========================*/
4569 /*------------------------------------------------------------------*/
4571 /* Name - emit_load_volatile_arguments */
4573 /* Function - Emit the instructions to reload parameter regist- */
4574 /* registers for use with "tail" operations. */
4576 /* The register loading operations performed here */
4577 /* are the mirror of the store operations performed */
4578 /* in mono_arch_emit_prolog and need to be kept in */
4579 /* synchronization with it. */
4581 /*------------------------------------------------------------------*/
4584 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4587 MonoMethod *method = cfg->method;
4588 MonoMethodSignature *sig = mono_method_signature(method);
4592 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4594 if (cinfo->struct_ret) {
4595 ArgInfo *ainfo = &cinfo->ret;
4596 inst = cfg->vret_addr;
4597 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4600 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4601 ArgInfo *ainfo = cinfo->args + i;
4602 inst = cfg->args [pos];
4604 if (inst->opcode == OP_REGVAR) {
4605 if (ainfo->regtype == RegTypeGeneral)
4606 s390_lgr (code, ainfo->reg, inst->dreg);
4607 else if (ainfo->regtype == RegTypeFP) {
4608 if (inst->dreg != ainfo->reg) {
4609 if (ainfo->size == 4) {
4610 s390_ldebr (code, ainfo->reg, inst->dreg);
4612 s390_ldr (code, ainfo->reg, inst->dreg);
4616 else if (ainfo->regtype == RegTypeBase) {
4618 g_assert_not_reached ();
4620 if (ainfo->regtype == RegTypeGeneral) {
4621 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4622 g_assert_not_reached();
4623 switch (ainfo->size) {
4625 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4628 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4631 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4634 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4637 } else if (ainfo->regtype == RegTypeBase) {
4638 } else if (ainfo->regtype == RegTypeFP) {
4639 if (ainfo->size == 8)
4640 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4641 else if (ainfo->size == 4)
4642 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4644 g_assert_not_reached ();
4645 } else if (ainfo->regtype == RegTypeStructByVal) {
4646 if (ainfo->reg != STK_BASE) {
4647 switch (ainfo->size) {
4649 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4652 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4655 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4658 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4662 } else if (ainfo->regtype == RegTypeStructByAddr) {
4663 if (ainfo->reg != STK_BASE) {
4664 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4667 g_assert_not_reached ();
4675 /*========================= End of Function ========================*/
4677 /*------------------------------------------------------------------*/
4679 /* Name - mono_arch_emit_prolog */
4681 /* Function - Create the instruction sequence for a function */
4684 /*------------------------------------------------------------------*/
4687 mono_arch_emit_prolog (MonoCompile *cfg)
4689 MonoMethod *method = cfg->method;
4691 MonoMethodSignature *sig;
4693 int alloc_size, pos, max_offset, i;
4699 cfg->code_size = 512;
4701 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4703 cfg->code_size += 256;
4706 if (method->save_lmf)
4707 cfg->code_size += 200;
4709 cfg->native_code = code = g_malloc (cfg->code_size);
4711 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4713 if (cfg->arch.bkchain_reg != -1)
4714 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4716 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4717 cfg->used_int_regs |= 1 << 11;
4720 alloc_size = cfg->stack_offset;
4722 cfg->stack_usage = alloc_size;
4723 s390_lgr (code, s390_r11, STK_BASE);
4724 if (s390_is_imm16 (alloc_size)) {
4725 s390_aghi (code, STK_BASE, -alloc_size);
4727 int stackSize = alloc_size;
4728 while (stackSize > 32767) {
4729 s390_aghi (code, STK_BASE, -32767);
4732 s390_aghi (code, STK_BASE, -stackSize);
4734 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4736 if (cfg->frame_reg != STK_BASE)
4737 s390_lgr (code, s390_r11, STK_BASE);
4739 /* compute max_offset in order to use short forward jumps
4740 * we always do it on s390 because the immediate displacement
4741 * for jumps is too small
4744 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4746 bb->max_offset = max_offset;
4748 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4751 MONO_BB_FOR_EACH_INS (bb, ins)
4752 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4755 /* load arguments allocated to register from the stack */
4756 sig = mono_method_signature (method);
4759 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4761 if (cinfo->struct_ret) {
4762 ArgInfo *ainfo = &cinfo->ret;
4763 inst = cfg->vret_addr;
4764 inst->backend.size = ainfo->vtsize;
4765 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4768 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4769 ArgInfo *ainfo = cinfo->args + i;
4770 inst = cfg->args [pos];
4772 if (inst->opcode == OP_VTARG_ADDR)
4773 inst = inst->inst_left;
4775 if (inst->opcode == OP_REGVAR) {
4776 if (ainfo->regtype == RegTypeGeneral)
4777 s390_lgr (code, inst->dreg, ainfo->reg);
4778 else if (ainfo->regtype == RegTypeFP) {
4779 if (inst->dreg != ainfo->reg) {
4780 if (ainfo->size == 4) {
4781 s390_ledbr (code, inst->dreg, ainfo->reg);
4783 s390_ldr (code, inst->dreg, ainfo->reg);
4787 else if (ainfo->regtype == RegTypeBase) {
4788 s390_lgr (code, s390_r13, STK_BASE);
4789 s390_aghi (code, s390_r13, alloc_size);
4790 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4792 g_assert_not_reached ();
4794 if (cfg->verbose_level > 2)
4795 g_print ("Argument %d assigned to register %s\n",
4796 pos, mono_arch_regname (inst->dreg));
4798 if (ainfo->regtype == RegTypeGeneral) {
4799 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4800 g_assert_not_reached();
4801 switch (ainfo->size) {
4803 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4806 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4809 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4812 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4815 } else if (ainfo->regtype == RegTypeBase) {
4816 } else if (ainfo->regtype == RegTypeFP) {
4817 if (ainfo->size == 8)
4818 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4819 else if (ainfo->size == 4)
4820 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4822 g_assert_not_reached ();
4823 } else if (ainfo->regtype == RegTypeStructByVal) {
4824 int doffset = inst->inst_offset;
4826 if (ainfo->reg != STK_BASE)
4830 s390_lgr (code, s390_r13, STK_BASE);
4831 s390_aghi (code, s390_r13, alloc_size);
4833 switch (ainfo->size) {
4835 if (ainfo->reg == STK_BASE)
4836 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
4837 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4840 if (ainfo->reg == STK_BASE)
4841 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
4842 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4845 if (ainfo->reg == STK_BASE)
4846 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
4847 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4850 if (ainfo->reg == STK_BASE)
4851 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
4852 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
4855 } else if (ainfo->regtype == RegTypeStructByAddr) {
4856 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4858 g_assert_not_reached ();
4863 if (method->save_lmf) {
4864 /*---------------------------------------------------------------*/
4865 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4866 /*---------------------------------------------------------------*/
4867 lmfOffset = alloc_size - sizeof(MonoLMF);
4869 s390_lgr (code, s390_r13, cfg->frame_reg);
4870 s390_aghi (code, s390_r13, lmfOffset);
4872 /*---------------------------------------------------------------*/
4873 /* Preserve the parameter registers while we fix up the lmf */
4874 /*---------------------------------------------------------------*/
4875 s390_stmg (code, s390_r2, s390_r6, s390_r13,
4876 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4878 /*---------------------------------------------------------------*/
4879 /* On return from this call r2 have the address of the &lmf */
4880 /*---------------------------------------------------------------*/
4881 s390_basr(code, s390_r10, 0);
4883 mono_add_patch_info (cfg, code - cfg->native_code,
4884 MONO_PATCH_INFO_INTERNAL_METHOD,
4885 (gpointer)"mono_get_lmf_addr");
4886 s390_llong(code, 0);
4887 s390_lg (code, s390_r1, 0, s390_r10, 4);
4888 s390_basr (code, s390_r14, s390_r1);
4890 /*---------------------------------------------------------------*/
4891 /* Set lmf.lmf_addr = jit_tls->lmf */
4892 /*---------------------------------------------------------------*/
4893 s390_stg (code, s390_r2, 0, s390_r13,
4894 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4896 /*---------------------------------------------------------------*/
4897 /* Get current lmf */
4898 /*---------------------------------------------------------------*/
4899 s390_lg (code, s390_r0, 0, s390_r2, 0);
4901 /*---------------------------------------------------------------*/
4902 /* Set our lmf as the current lmf */
4903 /*---------------------------------------------------------------*/
4904 s390_stg (code, s390_r13, 0, s390_r2, 0);
4906 /*---------------------------------------------------------------*/
4907 /* Have our lmf.previous_lmf point to the last lmf */
4908 /*---------------------------------------------------------------*/
4909 s390_stg (code, s390_r0, 0, s390_r13,
4910 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4912 /*---------------------------------------------------------------*/
4913 /* save method info */
4914 /*---------------------------------------------------------------*/
4915 s390_basr (code, s390_r1, 0);
4917 s390_llong (code, method);
4918 s390_lg (code, s390_r1, 0, s390_r1, 4);
4919 s390_stg (code, s390_r1, 0, s390_r13,
4920 G_STRUCT_OFFSET(MonoLMF, method));
4922 /*---------------------------------------------------------------*/
4923 /* save the current IP */
4924 /*---------------------------------------------------------------*/
4925 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4926 s390_basr (code, s390_r1, 0);
4927 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4929 /*---------------------------------------------------------------*/
4930 /* Save general and floating point registers */
4931 /*---------------------------------------------------------------*/
4932 s390_stmg (code, s390_r2, s390_r12, s390_r13,
4933 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
4934 for (i = 0; i < 16; i++) {
4935 s390_std (code, i, 0, s390_r13,
4936 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
4939 /*---------------------------------------------------------------*/
4940 /* Restore the parameter registers now that we've set up the lmf */
4941 /*---------------------------------------------------------------*/
4942 s390_lmg (code, s390_r2, s390_r6, s390_r13,
4943 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4947 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
4949 cfg->code_len = code - cfg->native_code;
4950 g_assert (cfg->code_len < cfg->code_size);
4955 /*========================= End of Function ========================*/
4957 /*------------------------------------------------------------------*/
4959 /* Name - mono_arch_emit_epilog */
4961 /* Function - Emit the instructions for a function epilog. */
4963 /*------------------------------------------------------------------*/
4966 mono_arch_emit_epilog (MonoCompile *cfg)
4968 MonoMethod *method = cfg->method;
4971 int max_epilog_size = 96;
4973 if (cfg->method->save_lmf)
4974 max_epilog_size += 128;
4976 if (mono_jit_trace_calls != NULL)
4977 max_epilog_size += 128;
4979 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4980 max_epilog_size += 128;
4982 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
4983 cfg->code_size *= 2;
4984 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
4985 mono_jit_stats.code_reallocs++;
4988 code = cfg->native_code + cfg->code_len;
4990 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4991 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
4995 if (method->save_lmf)
4996 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4998 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
4999 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5001 code = backUpStackPtr(cfg, code);
5003 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5004 s390_br (code, s390_r14);
5006 cfg->code_len = code - cfg->native_code;
5008 g_assert (cfg->code_len < cfg->code_size);
5012 /*========================= End of Function ========================*/
5014 /*------------------------------------------------------------------*/
5016 /* Name - mono_arch_emit_exceptions */
5018 /* Function - Emit the blocks to handle exception conditions. */
5020 /*------------------------------------------------------------------*/
5023 mono_arch_emit_exceptions (MonoCompile *cfg)
5025 MonoJumpInfo *patch_info;
5031 MonoClass *exc_classes [MAX_EXC];
5032 guint8 *exc_throw_start [MAX_EXC];
5034 for (patch_info = cfg->patch_info;
5036 patch_info = patch_info->next) {
5037 if (patch_info->type == MONO_PATCH_INFO_EXC)
5041 code_size = exc_count * 48;
5043 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5044 cfg->code_size *= 2;
5045 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5046 mono_jit_stats.code_reallocs++;
5049 code = cfg->native_code + cfg->code_len;
5051 /*---------------------------------------------------------------------*/
5052 /* Add code to raise exceptions */
5053 /*---------------------------------------------------------------------*/
5054 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5055 switch (patch_info->type) {
5056 case MONO_PATCH_INFO_EXC: {
5057 guint8 *ip = patch_info->ip.i + cfg->native_code;
5058 MonoClass *exc_class;
5061 /*-----------------------------------------------------*/
5062 /* Patch the branch in epilog to come here */
5063 /*-----------------------------------------------------*/
5064 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5066 exc_class = mono_class_from_name (mono_defaults.corlib,
5068 patch_info->data.name);
5069 g_assert (exc_class);
5070 throw_ip = patch_info->ip.i;
5072 for (iExc = 0; iExc < nThrows; ++iExc)
5073 if (exc_classes [iExc] == exc_class)
5076 if (iExc < nThrows) {
5077 s390_jcl (code, S390_CC_UN,
5078 (guint64) exc_throw_start [iExc]);
5079 patch_info->type = MONO_PATCH_INFO_NONE;
5082 if (nThrows < MAX_EXC) {
5083 exc_classes [nThrows] = exc_class;
5084 exc_throw_start [nThrows] = code;
5087 /*---------------------------------------------*/
5088 /* Patch the parameter passed to the handler */
5089 /*---------------------------------------------*/
5090 s390_basr (code, s390_r13, 0);
5092 s390_llong(code, patch_info->data.target);
5093 /*---------------------------------------------*/
5094 /* Load return address & parameter register */
5095 /*---------------------------------------------*/
5096 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5097 cfg->native_code + 8), code));
5098 s390_lg (code, s390_r2, 0, s390_r13, 4);
5099 /*---------------------------------------------*/
5100 /* Reuse the current patch to set the jump */
5101 /*---------------------------------------------*/
5102 s390_basr (code, s390_r13, 0);
5104 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5105 patch_info->data.name = "mono_arch_throw_exception_by_name";
5106 patch_info->ip.i = code - cfg->native_code;
5107 s390_llong(code, 0);
5108 s390_lg (code, s390_r1, 0, s390_r13, 4);
5109 s390_br (code, s390_r1);
5119 cfg->code_len = code - cfg->native_code;
5121 g_assert (cfg->code_len < cfg->code_size);
5125 /*========================= End of Function ========================*/
5127 /*------------------------------------------------------------------*/
5129 /* Name - mono_arch_setup_jit_tls_data */
5131 /* Function - Setup the JIT's Thread Level Specific Data. */
5133 /*------------------------------------------------------------------*/
5136 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5138 if (!tls_offset_inited) {
5139 tls_offset_inited = TRUE;
5143 __asm__ ("\tear\t%r1,0\n"
5150 : "=r" (appdomain_tls_offset),
5151 "=r" (thread_tls_offset),
5152 "=r" (lmf_tls_offset)
5153 : "r" (&tls_appdomain),
5154 "r" (&tls_current_object),
5155 "r" (&mono_lmf_addr)
5161 if (!lmf_addr_key_inited) {
5162 lmf_addr_key_inited = TRUE;
5163 pthread_key_create (&lmf_addr_key, NULL);
5165 pthread_setspecific (lmf_addr_key, &tls->lmf);
5169 /*========================= End of Function ========================*/
5171 /*------------------------------------------------------------------*/
5173 /* Name - mono_arch_free_jit_tls_data */
5175 /* Function - Free tls data. */
5177 /*------------------------------------------------------------------*/
5180 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5184 /*========================= End of Function ========================*/
5186 /*------------------------------------------------------------------*/
5188 /* Name - mono_arch_emit_inst_for_method */
5190 /*------------------------------------------------------------------*/
5193 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5198 /*========================= End of Function ========================*/
5201 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5204 * Have to rename these to avoid being decomposed normally, since the normal
5205 * decomposition does not work on S390.
5207 switch (ins->opcode) {
5209 ins->opcode = OP_S390_ISUB_OVF;
5211 case OP_ISUB_OVF_UN:
5212 ins->opcode = OP_S390_ISUB_OVF_UN;
5215 ins->opcode = OP_S390_IADD_OVF;
5217 case OP_IADD_OVF_UN:
5218 ins->opcode = OP_S390_IADD_OVF_UN;
5221 ins->opcode = OP_S390_LADD_OVF;
5223 case OP_LADD_OVF_UN:
5224 ins->opcode = OP_S390_LADD_OVF_UN;
5227 ins->opcode = OP_S390_LSUB_OVF;
5229 case OP_LSUB_OVF_UN:
5230 ins->opcode = OP_S390_LSUB_OVF_UN;
5237 /*========================= End of Function ========================*/
5239 /*------------------------------------------------------------------*/
5241 /* Name - mono_arch_print_tree */
5243 /* Function - Print platform-specific opcode details. */
5245 /* Returns - 1 - opcode details have been printed */
5246 /* 0 - opcode details have not been printed */
5248 /*------------------------------------------------------------------*/
5251 mono_arch_print_tree (MonoInst *tree, int arity)
5255 switch (tree->opcode) {
5256 case OP_S390_LOADARG:
5257 case OP_S390_ARGREG:
5258 case OP_S390_ARGPTR:
5259 printf ("[0x%lx(%s)]", tree->inst_offset,
5260 mono_arch_regname (tree->inst_basereg));
5263 case OP_S390_STKARG:
5264 printf ("[0x%lx(previous_frame)]",
5269 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5270 tree->inst_offset, tree->backend.size,
5271 mono_arch_regname(tree->dreg),
5273 mono_arch_regname(tree->sreg1));
5276 case OP_S390_SETF4RET:
5277 printf ("[f%s,f%s]",
5278 mono_arch_regname (tree->dreg),
5279 mono_arch_regname (tree->sreg1));
5283 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5285 mono_arch_regname (tree->sreg1));
5288 case OP_S390_BKCHAIN:
5289 printf ("[previous_frame(%s)]",
5290 mono_arch_regname (tree->sreg1));
5298 /*========================= End of Function ========================*/
5300 /*------------------------------------------------------------------*/
5302 /* Name - mono_arch_regalloc_cost */
5304 /* Function - Determine the cost, in the number of memory */
5305 /* references, of the action of allocating the var- */
5306 /* iable VMV into a register during global register */
5309 /* Returns - Cost */
5311 /*------------------------------------------------------------------*/
5314 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5320 /*========================= End of Function ========================*/
5322 /*------------------------------------------------------------------*/
5324 /* Name - mono_arch_get_domain_intrinsic */
5330 /*------------------------------------------------------------------*/
5333 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5337 if (appdomain_tls_offset == -1)
5340 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5341 ins->inst_offset = appdomain_tls_offset;
5345 /*========================= End of Function ========================*/
5347 /*------------------------------------------------------------------*/
5349 /* Name - mono_arch_get_thread_intrinsic */
5355 /*------------------------------------------------------------------*/
5358 mono_arch_get_thread_intrinsic (MonoCompile* cfg)
5362 if (thread_tls_offset == -1)
5365 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5366 ins->inst_offset = thread_tls_offset;
5370 /*========================= End of Function ========================*/
5372 /*------------------------------------------------------------------*/
5374 /* Name - mono_arch_flush_register_windows */
5380 /*------------------------------------------------------------------*/
5383 mono_arch_flush_register_windows (void)
5387 /*========================= End of Function ========================*/
5389 /*------------------------------------------------------------------*/
5391 /* Name - mono_arch_get_lmf_addr */
5397 /*------------------------------------------------------------------*/
5400 mono_arch_get_lmf_addr (void)
5402 return pthread_getspecific (lmf_addr_key);
5405 /*========================= End of Function ========================*/
5407 /*------------------------------------------------------------------*/
5409 /* Name - mono_arch_is_inst_imm */
5411 /* Function - Determine if operand qualifies as an immediate */
5412 /* value. For s390 this is a value -32768-32768 */
5414 /* Returns - True|False - is [not] immediate value. */
5416 /*------------------------------------------------------------------*/
5419 mono_arch_is_inst_imm (gint64 imm)
5421 return s390_is_imm16 (imm);
5424 /*========================= End of Function ========================*/
5426 /*------------------------------------------------------------------*/
5428 /* Name - mono_arch_get_patch_offset */
5430 /* Function - Dummy entry point until s390x supports aot. */
5432 /* Returns - Offset for patch. */
5434 /*------------------------------------------------------------------*/
5437 mono_arch_get_patch_offset (guint8 *code)
5442 /*========================= End of Function ========================*/
5445 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5447 /* FIXME: implement */
5448 g_assert_not_reached ();