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,
334 RegTypeStructByAddrOnStack
338 gint32 offset; /* offset from caller's stack */
339 gint32 offparm; /* offset from callee's stack */
340 guint16 vtsize; /* in param area */
343 guint32 size; /* Size of structure used by RegTypeStructByVal */
344 gint32 type; /* Data type of argument */
359 gint64 gr[5]; /* R2-R6 */
360 gdouble fp[3]; /* F0-F2 */
361 } __attribute__ ((packed)) RegParm;
363 /*========================= End of Typedefs ========================*/
365 /*------------------------------------------------------------------*/
366 /* P r o t o t y p e s */
367 /*------------------------------------------------------------------*/
369 static void indent (int);
370 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
371 static void decodeParm (MonoType *, void *, int);
372 static void enter_method (MonoMethod *, RegParm *, char *);
373 static void leave_method (MonoMethod *, ...);
374 static gboolean is_regsize_var (MonoType *);
375 static inline void add_general (guint *, size_data *, ArgInfo *);
376 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
377 static inline void add_float (guint *, size_data *, ArgInfo *);
378 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
379 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
380 gpointer mono_arch_get_lmf_addr (void);
381 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
382 static void catch_SIGILL(int, siginfo_t *, void *);
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 = mono_class_enum_basetype (type->data.klass)->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 = mono_class_enum_basetype (type->data.klass);
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 (mono_class_enum_basetype (t->data.klass));
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 ainfo->regtype = RegTypeStructByAddrOnStack;
1370 sz->stack_size += sizeof (gpointer);
1371 sz->parm_size += sizeof(gpointer);
1372 sz->offStruct += sizeof(gpointer);
1375 ainfo->offset = sz->stack_size;
1376 ainfo->regtype = RegTypeStructByAddr;
1379 ainfo->offparm = sz->offset;
1380 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1382 ainfo->vtsize = size;
1383 sz->parm_size += size;
1386 /*========================= End of Function ========================*/
1388 /*------------------------------------------------------------------*/
1390 /* Name - add_float */
1392 /* Function - Determine code and stack size incremements for a */
1393 /* float parameter. */
1395 /*------------------------------------------------------------------*/
1398 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1400 if ((*fr) <= S390_LAST_FPARG_REG) {
1401 ainfo->regtype = RegTypeFP;
1407 ainfo->offset = sz->stack_size;
1408 ainfo->reg = STK_BASE;
1409 ainfo->regtype = RegTypeBase;
1411 sz->stack_size += sizeof(double);
1412 sz->local_size += sizeof(double);
1413 sz->offStruct += sizeof(double);
1417 /*========================= End of Function ========================*/
1419 /*------------------------------------------------------------------*/
1421 /* Name - get_call_info */
1423 /* Function - Determine the amount of space required for code */
1424 /* and stack. In addition determine starting points */
1425 /* for stack-based parameters, and area for struct- */
1426 /* ures being returned on the stack. */
1428 /*------------------------------------------------------------------*/
1431 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1433 guint i, fr, gr, size;
1434 int nParm = sig->hasthis + sig->param_count;
1436 guint32 simpletype, align;
1439 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1442 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1444 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1449 cinfo->struct_ret = 0;
1453 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1454 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1459 /*----------------------------------------------------------*/
1460 /* We determine the size of the return code/stack in case we*/
1461 /* need to reserve a register to be used to address a stack */
1462 /* area that the callee will use. */
1463 /*----------------------------------------------------------*/
1465 ret_type = mono_type_get_underlying_type (sig->ret);
1466 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1467 simpletype = ret_type->type;
1469 switch (simpletype) {
1470 case MONO_TYPE_BOOLEAN:
1475 case MONO_TYPE_CHAR:
1480 case MONO_TYPE_CLASS:
1481 case MONO_TYPE_OBJECT:
1482 case MONO_TYPE_SZARRAY:
1483 case MONO_TYPE_ARRAY:
1485 case MONO_TYPE_FNPTR:
1486 case MONO_TYPE_STRING:
1487 cinfo->ret.reg = s390_r2;
1492 cinfo->ret.reg = s390_f0;
1497 cinfo->ret.reg = s390_r2;
1500 case MONO_TYPE_GENERICINST:
1501 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1502 cinfo->ret.reg = s390_r2;
1507 case MONO_TYPE_VALUETYPE: {
1508 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1509 if (klass->enumtype) {
1510 simpletype = mono_class_enum_basetype (klass)->type;
1514 size = mono_class_native_size (klass, &align);
1516 size = mono_class_value_size (klass, &align);
1518 cinfo->ret.reg = s390_r2;
1519 cinfo->struct_ret = 1;
1520 cinfo->ret.size = size;
1521 cinfo->ret.vtsize = size;
1525 case MONO_TYPE_TYPEDBYREF:
1526 size = sizeof (MonoTypedRef);
1527 cinfo->ret.reg = s390_r2;
1528 cinfo->struct_ret = 1;
1529 cinfo->ret.size = size;
1530 cinfo->ret.vtsize = size;
1533 case MONO_TYPE_VOID:
1536 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1540 cinfo->args[nParm].size = sizeof(gpointer);
1541 add_general (&gr, sz, cinfo->args+nParm);
1545 /*----------------------------------------------------------*/
1546 /* We determine the size of the parameter code and stack */
1547 /* requirements by checking the types and sizes of the */
1549 /*----------------------------------------------------------*/
1551 for (i = 0; i < sig->param_count; ++i) {
1554 /*--------------------------------------------------*/
1555 /* Handle vararg type calls. All args are put on */
1557 /*--------------------------------------------------*/
1558 if ((sig->call_convention == MONO_CALL_VARARG) &&
1559 (i == sig->sentinelpos)) {
1560 gr = S390_LAST_ARG_REG + 1;
1561 add_general (&gr, sz, &cinfo->sigCookie);
1564 if (sig->params [i]->byref) {
1565 add_general (&gr, sz, cinfo->args+nParm);
1566 cinfo->args[nParm].size = sizeof(gpointer);
1571 ptype = mono_type_get_underlying_type (sig->params [i]);
1572 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1573 simpletype = ptype->type;
1574 cinfo->args[nParm].type = simpletype;
1575 switch (simpletype) {
1576 case MONO_TYPE_BOOLEAN:
1579 cinfo->args[nParm].size = sizeof(char);
1580 add_general (&gr, sz, cinfo->args+nParm);
1585 case MONO_TYPE_CHAR:
1586 cinfo->args[nParm].size = sizeof(short);
1587 add_general (&gr, sz, cinfo->args+nParm);
1592 cinfo->args[nParm].size = sizeof(int);
1593 add_general (&gr, sz, cinfo->args+nParm);
1599 case MONO_TYPE_FNPTR:
1600 case MONO_TYPE_CLASS:
1601 case MONO_TYPE_OBJECT:
1602 case MONO_TYPE_STRING:
1603 case MONO_TYPE_SZARRAY:
1604 case MONO_TYPE_ARRAY:
1605 cinfo->args[nParm].size = sizeof(gpointer);
1606 add_general (&gr, sz, cinfo->args+nParm);
1611 cinfo->args[nParm].size = sizeof(long long);
1612 add_general (&gr, sz, cinfo->args+nParm);
1616 cinfo->args[nParm].size = sizeof(float);
1617 add_float (&fr, sz, cinfo->args+nParm);
1621 cinfo->args[nParm].size = sizeof(double);
1622 add_float (&fr, sz, cinfo->args+nParm);
1625 case MONO_TYPE_GENERICINST:
1626 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1627 cinfo->args[nParm].size = sizeof(gpointer);
1628 add_general (&gr, sz, cinfo->args+nParm);
1633 case MONO_TYPE_VALUETYPE: {
1634 MonoMarshalType *info;
1635 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1637 size = mono_class_native_size (klass, &align);
1639 size = mono_class_value_size (klass, &align);
1641 info = mono_marshal_load_type_info (klass);
1643 if ((info->native_size == sizeof(float)) &&
1644 (info->num_fields == 1) &&
1645 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1646 cinfo->args[nParm].size = sizeof(float);
1647 add_float(&fr, sz, cinfo->args+nParm);
1652 if ((info->native_size == sizeof(double)) &&
1653 (info->num_fields == 1) &&
1654 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1655 cinfo->args[nParm].size = sizeof(double);
1656 add_float(&fr, sz, cinfo->args+nParm);
1661 cinfo->args[nParm].vtsize = 0;
1662 cinfo->args[nParm].size = 0;
1665 /*----------------------------------*/
1666 /* On S/390, structures of size 1, */
1667 /* 2, 4, and 8 bytes are passed in */
1668 /* (a) register(s). */
1669 /*----------------------------------*/
1675 add_general(&gr, sz, cinfo->args+nParm);
1676 cinfo->args[nParm].size = size;
1677 cinfo->args[nParm].regtype = RegTypeStructByVal;
1679 sz->local_size += sizeof(long);
1682 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1687 case MONO_TYPE_TYPEDBYREF: {
1688 int size = sizeof (MonoTypedRef);
1690 cinfo->args[nParm].vtsize = 0;
1691 cinfo->args[nParm].size = 0;
1694 /*----------------------------------*/
1695 /* On S/390, structures of size 1, */
1696 /* 2, 4, and 8 bytes are passed in */
1697 /* (a) register(s). */
1698 /*----------------------------------*/
1704 add_general(&gr, sz, cinfo->args+nParm);
1705 cinfo->args[nParm].size = size;
1706 cinfo->args[nParm].regtype = RegTypeStructByVal;
1708 sz->local_size += sizeof(long);
1711 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1717 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1721 /*----------------------------------------------------------*/
1722 /* Handle the case where there are no implicit arguments */
1723 /*----------------------------------------------------------*/
1724 if ((sig->call_convention == MONO_CALL_VARARG) &&
1725 (sig->param_count == sig->sentinelpos)) {
1726 gr = S390_LAST_ARG_REG + 1;
1727 add_general (&gr, sz, &cinfo->sigCookie);
1730 /*----------------------------------------------------------*/
1731 /* If we are passing a structure back then if it won't be */
1732 /* in a register(s) then we make room at the end of the */
1733 /* parameters that may have been placed on the stack */
1734 /*----------------------------------------------------------*/
1735 if (cinfo->struct_ret) {
1736 cinfo->ret.offset = sz->stack_size;
1737 switch (cinfo->ret.size) {
1745 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1750 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1752 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1757 /*========================= End of Function ========================*/
1759 /*------------------------------------------------------------------*/
1761 /* Name - mono_arch_allocate_vars */
1763 /* Function - Set var information according to the calling */
1764 /* convention for S/390. The local var stuff should */
1765 /* most likely be split in another method. */
1767 /* Parameter - @m - Compile unit. */
1769 /*------------------------------------------------------------------*/
1772 mono_arch_allocate_vars (MonoCompile *cfg)
1774 MonoMethodSignature *sig;
1775 MonoMethodHeader *header;
1778 int iParm, iVar, offset, size, align, curinst;
1779 int frame_reg = STK_BASE;
1782 header = mono_method_get_header (cfg->method);
1784 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1786 /*---------------------------------------------------------*/
1787 /* We use the frame register also for any method that has */
1788 /* filter clauses. This way, when the handlers are called, */
1789 /* the code will reference local variables using the frame */
1790 /* reg instead of the stack pointer: if we had to restore */
1791 /* the stack pointer, we'd corrupt the method frames that */
1792 /* are already on the stack (since filters get called */
1793 /* before stack unwinding happens) when the filter code */
1794 /* would call any method. */
1795 /*---------------------------------------------------------*/
1796 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1797 frame_reg = s390_r11;
1799 cfg->frame_reg = frame_reg;
1801 cfg->arch.bkchain_reg = -1;
1803 if (frame_reg != STK_BASE)
1804 cfg->used_int_regs |= 1 << frame_reg;
1806 sig = mono_method_signature (cfg->method);
1808 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1810 if (!cinfo->struct_ret) {
1811 switch (mono_type_get_underlying_type (sig->ret)->type) {
1812 case MONO_TYPE_VOID:
1815 cfg->ret->opcode = OP_REGVAR;
1816 cfg->ret->dreg = s390_r2;
1821 /*--------------------------------------------------------------*/
1822 /* local vars are at a positive offset from the stack pointer */
1823 /* also note that if the function uses alloca, we use s390_r11 */
1824 /* to point at the local variables. */
1825 /* add parameter area size for called functions */
1826 /*--------------------------------------------------------------*/
1827 offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
1828 cfg->sig_cookie = 0;
1830 if (cinfo->struct_ret) {
1831 inst = cfg->vret_addr;
1832 offset = S390_ALIGN(offset, sizeof(gpointer));
1833 inst->inst_offset = offset;
1834 inst->opcode = OP_REGOFFSET;
1835 inst->inst_basereg = frame_reg;
1836 offset += sizeof(gpointer);
1837 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1838 printf ("vret_addr =");
1839 mono_print_ins (cfg->vret_addr);
1844 inst = cfg->args [0];
1845 if (inst->opcode != OP_REGVAR) {
1846 inst->opcode = OP_REGOFFSET;
1847 inst->inst_basereg = frame_reg;
1848 offset = S390_ALIGN(offset, sizeof(gpointer));
1849 inst->inst_offset = offset;
1850 offset += sizeof (gpointer);
1857 eArg = sig->param_count + sArg;
1859 if (sig->call_convention == MONO_CALL_VARARG)
1860 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1862 for (iParm = sArg; iParm < eArg; ++iParm) {
1863 inst = cfg->args [curinst];
1864 if (inst->opcode != OP_REGVAR) {
1865 switch (cinfo->args[iParm].regtype) {
1866 case RegTypeStructByAddr : {
1869 size = sizeof (gpointer);
1871 inst->opcode = OP_REGOFFSET;
1872 inst->inst_basereg = frame_reg;
1873 offset = S390_ALIGN (offset, sizeof (gpointer));
1874 inst->inst_offset = offset;
1876 /* Add a level of indirection */
1877 MONO_INST_NEW (cfg, indir, 0);
1879 inst->opcode = OP_VTARG_ADDR;
1880 inst->inst_left = indir;
1883 case RegTypeStructByAddrOnStack : {
1886 size = sizeof (gpointer);
1888 /* Similar to the == STK_BASE case below */
1889 cfg->arch.bkchain_reg = s390_r12;
1890 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1892 inst->opcode = OP_REGOFFSET;
1893 inst->dreg = mono_alloc_preg (cfg);
1894 inst->inst_basereg = cfg->arch.bkchain_reg;
1895 inst->inst_offset = cinfo->args [iParm].offset;
1897 /* Add a level of indirection */
1898 MONO_INST_NEW (cfg, indir, 0);
1900 inst->opcode = OP_VTARG_ADDR;
1901 inst->inst_left = indir;
1904 case RegTypeStructByVal :
1905 size = cinfo->args[iParm].size;
1906 offset = S390_ALIGN(offset, size);
1907 inst->opcode = OP_REGOFFSET;
1908 inst->inst_basereg = frame_reg;
1909 inst->inst_offset = offset;
1912 if (cinfo->args [iParm].reg == STK_BASE) {
1914 * These arguments are in the previous frame, so we can't
1915 * compute their offset from the current frame pointer right
1916 * now, since cfg->stack_offset is not yet known, so dedicate a
1917 * register holding the previous frame pointer.
1919 cfg->arch.bkchain_reg = s390_r12;
1920 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1922 inst->opcode = OP_REGOFFSET;
1923 inst->inst_basereg = cfg->arch.bkchain_reg;
1924 size = (cinfo->args[iParm].size < 8
1925 ? 8 - cinfo->args[iParm].size
1927 inst->inst_offset = cinfo->args [iParm].offset + size;
1928 size = sizeof (long);
1930 inst->opcode = OP_REGOFFSET;
1931 inst->inst_basereg = frame_reg;
1932 size = (cinfo->args[iParm].size < 8
1935 offset = S390_ALIGN(offset, size);
1936 inst->inst_offset = offset;
1940 if ((sig->call_convention == MONO_CALL_VARARG) &&
1941 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1942 (iParm < sig->sentinelpos))
1943 cfg->sig_cookie += size;
1950 curinst = cfg->locals_start;
1951 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1952 inst = cfg->varinfo [iVar];
1953 if ((inst->flags & MONO_INST_IS_DEAD) ||
1954 (inst->opcode == OP_REGVAR))
1957 /*--------------------------------------------------*/
1958 /* inst->backend.is_pinvoke indicates native sized value types, */
1959 /* this is used by the pinvoke wrappers when they */
1960 /* call functions returning structure */
1961 /*--------------------------------------------------*/
1962 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1963 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype), &align);
1965 size = mono_type_size (inst->inst_vtype, &align);
1967 offset = S390_ALIGN(offset, align);
1968 inst->inst_offset = offset;
1969 inst->opcode = OP_REGOFFSET;
1970 inst->inst_basereg = frame_reg;
1972 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
1973 iVar, inst->inst_offset, size));
1976 /*------------------------------------------------------*/
1977 /* Allow space for the trace method stack area if needed*/
1978 /*------------------------------------------------------*/
1979 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
1980 offset += S390_TRACE_STACK_SIZE;
1982 /*------------------------------------------------------*/
1983 /* Reserve space to save LMF and caller saved registers */
1984 /*------------------------------------------------------*/
1985 if (cfg->method->save_lmf)
1986 offset += sizeof (MonoLMF);
1988 /*------------------------------------------------------*/
1989 /* align the offset */
1990 /*------------------------------------------------------*/
1991 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1995 /*========================= End of Function ========================*/
1997 /*------------------------------------------------------------------*/
1999 /* Name - mono_arch_create_vars */
2000 /*------------------------------------------------------------------*/
2003 mono_arch_create_vars (MonoCompile *cfg)
2005 MonoMethodSignature *sig;
2008 sig = mono_method_signature (cfg->method);
2010 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2012 if (cinfo->struct_ret) {
2013 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2014 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2015 printf ("vret_addr = ");
2016 mono_print_ins (cfg->vret_addr);
2021 /*========================= End of Function ========================*/
2024 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2029 case RegTypeGeneral:
2030 MONO_INST_NEW (cfg, ins, OP_MOVE);
2031 ins->dreg = mono_alloc_ireg (cfg);
2032 ins->sreg1 = tree->dreg;
2033 MONO_ADD_INS (cfg->cbb, ins);
2034 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2037 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2038 ins->dreg = mono_alloc_freg (cfg);
2039 ins->sreg1 = tree->dreg;
2040 MONO_ADD_INS (cfg->cbb, ins);
2041 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2044 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2045 ins->dreg = mono_alloc_freg (cfg);
2046 ins->sreg1 = tree->dreg;
2047 MONO_ADD_INS (cfg->cbb, ins);
2048 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2051 g_assert_not_reached ();
2056 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2058 MonoMethodSignature *tmpSig;
2061 cfg->disable_aot = TRUE;
2063 /*----------------------------------------------------------*/
2064 /* mono_ArgIterator_Setup assumes the signature cookie is */
2065 /* passed first and all the arguments which were before it */
2066 /* passed on the stack after the signature. So compensate */
2067 /* by passing a different signature. */
2068 /*----------------------------------------------------------*/
2069 tmpSig = mono_metadata_signature_dup (call->signature);
2070 tmpSig->param_count -= call->signature->sentinelpos;
2071 tmpSig->sentinelpos = 0;
2072 if (tmpSig->param_count > 0)
2073 memcpy (tmpSig->params,
2074 call->signature->params + call->signature->sentinelpos,
2075 tmpSig->param_count * sizeof(MonoType *));
2077 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2078 sig_arg->dreg = mono_alloc_ireg (cfg);
2079 sig_arg->inst_p0 = tmpSig;
2080 MONO_ADD_INS (cfg->cbb, sig_arg);
2082 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2083 cinfo->sigCookie.offset, sig_arg->dreg);
2086 /*------------------------------------------------------------------*/
2088 /* Name - mono_arch_emit_call */
2090 /*------------------------------------------------------------------*/
2093 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2096 MonoMethodSignature *sig;
2098 int i, n, lParamArea;
2100 ArgInfo *ainfo = NULL;
2103 sig = call->signature;
2104 n = sig->param_count + sig->hasthis;
2105 DEBUG (g_print ("Call requires: %d parameters\n",n));
2107 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2109 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size + cinfo->sz.parm_size + cinfo->sz.offset;
2110 call->stack_usage = MAX(stackSize, call->stack_usage);
2111 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2112 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2113 cfg->flags |= MONO_CFG_HAS_CALLS;
2115 if (cinfo->struct_ret) {
2116 MONO_INST_NEW (cfg, ins, OP_MOVE);
2117 ins->sreg1 = call->vret_var->dreg;
2118 ins->dreg = mono_alloc_preg (cfg);
2119 MONO_ADD_INS (cfg->cbb, ins);
2120 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2123 for (i = 0; i < n; ++i) {
2124 ainfo = cinfo->args + i;
2127 if (i >= sig->hasthis)
2128 t = sig->params [i - sig->hasthis];
2130 t = &mono_defaults.int_class->byval_arg;
2131 t = mono_type_get_underlying_type (t);
2133 in = call->args [i];
2135 if ((sig->call_convention == MONO_CALL_VARARG) &&
2136 (i == sig->sentinelpos)) {
2137 emit_sig_cookie (cfg, call, cinfo);
2140 switch (ainfo->regtype) {
2141 case RegTypeGeneral:
2142 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2145 if (MONO_TYPE_ISSTRUCT (t)) {
2146 /* Valuetype passed in one fp register */
2147 ainfo->regtype = RegTypeStructByValInFP;
2150 if (ainfo->size == 4)
2151 ainfo->regtype = RegTypeFPR4;
2152 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2155 case RegTypeStructByVal:
2156 case RegTypeStructByAddr:
2157 case RegTypeStructByAddrOnStack: {
2161 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2162 size = sizeof (MonoTypedRef);
2163 align = sizeof (gpointer);
2167 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2170 * Other backends use mono_type_stack_size (), but that
2171 * aligns the size to 8, which is larger than the size of
2172 * the source, leading to reads of invalid memory if the
2173 * source is at the end of address space.
2175 size = mono_class_value_size (in->klass, &align);
2178 g_assert (in->klass);
2180 ainfo->offparm += cinfo->sz.offStruct;
2182 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2183 ins->sreg1 = in->dreg;
2184 ins->klass = in->klass;
2185 ins->backend.size = ainfo->size;
2186 ins->inst_p0 = call;
2187 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2188 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2190 MONO_ADD_INS (cfg->cbb, ins);
2192 if (ainfo->regtype == RegTypeStructByAddr) {
2194 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2195 * use the normal OUTARG opcodes to pass the address of the location to
2198 int treg = mono_alloc_preg (cfg);
2199 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2200 STK_BASE, ainfo->offparm);
2201 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2202 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2203 /* The address of the valuetype is passed on the stack */
2204 int treg = mono_alloc_preg (cfg);
2205 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2206 STK_BASE, ainfo->offparm);
2207 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2208 ainfo->reg, ainfo->offset, treg);
2213 if (!t->byref && t->type == MONO_TYPE_R4) {
2214 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2215 STK_BASE, ainfo->offset + 4,
2217 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2218 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2219 STK_BASE, ainfo->offset,
2222 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2223 ins->inst_destbasereg = STK_BASE;
2224 ins->inst_offset = ainfo->offset;
2225 ins->sreg1 = in->dreg;
2227 /* This is needed by MonoTypedRef->value to point to the correct data */
2228 if ((sig->call_convention == MONO_CALL_VARARG) &&
2229 (i >= sig->sentinelpos)) {
2230 switch (ainfo->size) {
2232 ins->opcode = OP_STOREI1_MEMBASE_REG;
2235 ins->opcode = OP_STOREI2_MEMBASE_REG;
2238 ins->opcode = OP_STOREI4_MEMBASE_REG;
2245 MONO_ADD_INS (cfg->cbb, ins);
2249 g_assert_not_reached ();
2255 * Handle the case where there are no implicit arguments
2257 if ((sig->call_convention == MONO_CALL_VARARG) &&
2258 (i == sig->sentinelpos)) {
2259 emit_sig_cookie (cfg, call, cinfo);
2263 /*========================= End of Function ========================*/
2265 /*------------------------------------------------------------------*/
2267 /* Name - mono_arch_emit_outarg_vt */
2269 /*------------------------------------------------------------------*/
2272 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2274 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2275 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2276 int size = ins->backend.size;
2278 if (ainfo->regtype == RegTypeStructByVal) {
2280 arg->ins.sreg1 = ainfo->reg;
2281 arg->ins.opcode = OP_OUTARG_VT;
2282 arg->size = ainfo->size;
2283 arg->offset = ainfo->offset;
2284 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2286 if (ainfo->reg != STK_BASE) {
2287 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2289 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2292 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2293 int dreg = mono_alloc_freg (cfg);
2295 if (ainfo->size == 4) {
2296 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2297 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2299 g_assert (ainfo->size == 8);
2301 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2304 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2306 MONO_EMIT_NEW_MOVE (cfg, STK_BASE, ainfo->offparm,
2307 src->dreg, 0, size);
2311 /*------------------------------------------------------------------*/
2313 /* Name - mono_arch_emit_setret */
2315 /*------------------------------------------------------------------*/
2318 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2320 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2323 if (ret->type == MONO_TYPE_R4) {
2324 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2326 } else if (ret->type == MONO_TYPE_R8) {
2327 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2332 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2335 /*========================= End of Function ========================*/
2337 /*------------------------------------------------------------------*/
2339 /* Name - mono_arch_instrument_mem_needs */
2341 /* Function - Allow tracing to work with this interface (with */
2342 /* an optional argument). */
2344 /*------------------------------------------------------------------*/
2347 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2349 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2351 /* split prolog-epilog requirements? */
2352 *code = 50; /* max bytes needed: check this number */
2355 /*========================= End of Function ========================*/
2357 /*------------------------------------------------------------------*/
2359 /* Name - mono_arch_instrument_prolog */
2361 /* Function - Create an "instrumented" prolog. */
2363 /*------------------------------------------------------------------*/
2366 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2367 gboolean enable_arguments)
2374 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2375 if (cfg->method->save_lmf)
2376 parmOffset -= sizeof(MonoLMF);
2377 fpOffset = parmOffset + (5*sizeof(gpointer));
2378 if ((!has_ld) && (fpOffset > 4096)) {
2379 s390_lgr (code, s390_r12, STK_BASE);
2381 while (fpOffset > 4096) {
2382 s390_aghi (code, baseReg, 4096);
2390 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2392 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2393 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2394 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2395 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2397 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2398 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2399 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2400 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2402 s390_basr (code, s390_r13, 0);
2404 s390_llong(code, cfg->method);
2405 s390_llong(code, func);
2406 s390_lg (code, s390_r2, 0, s390_r13, 4);
2408 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2410 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2411 s390_lgr (code, s390_r4, STK_BASE);
2412 s390_aghi (code, s390_r4, cfg->stack_usage);
2413 s390_lg (code, s390_r1, 0, s390_r13, 12);
2414 s390_basr (code, s390_r14, s390_r1);
2416 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2417 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2418 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2419 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2421 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2422 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2423 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2424 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2426 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2431 /*========================= End of Function ========================*/
2433 /*------------------------------------------------------------------*/
2435 /* Name - mono_arch_instrument_epilog */
2437 /* Function - Create an epilog that will handle the returned */
2438 /* values used in instrumentation. */
2440 /*------------------------------------------------------------------*/
2443 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
2446 int save_mode = SAVE_NONE,
2448 MonoMethod *method = cfg->method;
2449 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2451 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2452 if (method->save_lmf)
2453 saveOffset -= sizeof(MonoLMF);
2457 case MONO_TYPE_VOID:
2458 /* special case string .ctor icall */
2459 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2460 save_mode = SAVE_ONE;
2462 save_mode = SAVE_NONE;
2466 save_mode = SAVE_ONE;
2469 save_mode = SAVE_R4;
2472 save_mode = SAVE_R8;
2474 case MONO_TYPE_VALUETYPE:
2475 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2476 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2479 save_mode = SAVE_STRUCT;
2482 save_mode = SAVE_ONE;
2486 switch (save_mode) {
2488 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2489 if (enable_arguments) {
2490 s390_lgr (code, s390_r3, s390_r2);
2494 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2495 if (enable_arguments) {
2496 s390_ldebr (code, s390_f0, s390_f0);
2500 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2503 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2504 if (enable_arguments) {
2505 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2506 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2514 s390_basr (code, s390_r13, 0);
2516 s390_llong(code, cfg->method);
2517 s390_llong(code, func);
2518 s390_lg (code, s390_r2, 0, s390_r13, 4);
2519 s390_lg (code, s390_r1, 0, s390_r13, 12);
2520 s390_basr (code, s390_r14, s390_r1);
2522 switch (save_mode) {
2524 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2528 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2531 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2541 /*========================= End of Function ========================*/
2544 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2548 /*------------------------------------------------------------------*/
2550 /* Name - mono_arch_peephole_pass */
2552 /* Function - Form a peephole pass at the code looking for */
2553 /* simple optimizations. */
2555 /*------------------------------------------------------------------*/
2558 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2562 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2563 mono_peephole_ins (bb, ins);
2567 /*========================= End of Function ========================*/
2570 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2572 MonoInst *ins, *next;
2574 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2575 switch (ins->opcode) {
2580 case OP_IDIV_UN_IMM:
2581 case OP_IREM_UN_IMM:
2585 case OP_LOCALLOC_IMM:
2586 mono_decompose_op_imm (cfg, bb, ins);
2589 if (!s390_is_imm16 (ins->inst_imm))
2590 /* This is created by the memcpy code which ignores is_inst_imm */
2591 mono_decompose_op_imm (cfg, bb, ins);
2598 bb->max_vreg = cfg->next_vreg;
2601 /*========================= End of Function ========================*/
2603 /*------------------------------------------------------------------*/
2605 /* Name - emit_float_to_int */
2607 /* Function - Create instructions which will convert a floating */
2608 /* point value to integer. */
2610 /*------------------------------------------------------------------*/
2613 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2615 /* sreg is a float, dreg is an integer reg. */
2617 s390_cfdbr (code, dreg, 5, sreg);
2620 s390_lghi (code, s390_r0, 0);
2621 s390_lghi (code, s390_r13, 0xff);
2622 s390_ltgr (code, dreg, dreg);
2624 s390_lghi (code, s390_r0, 0x80);
2625 s390_ngr (code, dreg, s390_r13);
2626 s390_ogr (code, dreg, s390_r0);
2631 s390_basr (code, s390_r13, 0);
2633 s390_llong (code, 0x41e0000000000000);
2634 s390_llong (code, 0x41f0000000000000);
2635 s390_ldr (code, s390_f15, sreg);
2636 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2637 s390_jl (code, 0); CODEPTR (code, o[0]);
2638 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2639 s390_cfdbr (code, dreg, 7, s390_f15);
2641 PTRSLOT (code, o[0]);
2642 s390_cfdbr (code, dreg, 5, sreg);
2645 s390_lghi (code, s390_r0, 0xff);
2646 s390_ngr (code, dreg, s390_r0);
2649 s390_lghi (code, s390_r0, -1);
2650 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2651 s390_ngr (code, dreg, s390_r0);
2658 /*========================= End of Function ========================*/
2660 static gboolean is_unsigned (MonoInst *next)
2663 (((next->opcode >= OP_IBNE_UN) &&
2664 (next->opcode <= OP_IBLT_UN)) ||
2665 ((next->opcode >= OP_LBNE_UN) &&
2666 (next->opcode <= OP_LBLT_UN)) ||
2667 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2668 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2669 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2670 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2671 ((next->opcode == OP_CLT_UN) ||
2672 (next->opcode == OP_CGT_UN)) ||
2673 ((next->opcode == OP_ICLT_UN) ||
2674 (next->opcode == OP_ICGT_UN) ||
2675 (next->opcode == OP_LCLT_UN) ||
2676 (next->opcode == OP_LCGT_UN))))
2682 /*------------------------------------------------------------------*/
2684 /* Name - mono_arch_output_basic_block */
2686 /* Function - Perform the "real" work of emitting instructions */
2687 /* that will do the work of in the basic block. */
2689 /*------------------------------------------------------------------*/
2692 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2697 guint8 *code = cfg->native_code + cfg->code_len;
2698 guint last_offset = 0;
2699 int max_len, cpos, src2;
2701 /* we don't align basic blocks of loops on s390 */
2703 if (cfg->verbose_level > 2)
2704 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2706 cpos = bb->max_offset;
2708 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2709 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2710 //g_assert (!mono_compile_aot);
2713 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2714 /* this is not thread save, but good enough */
2715 /* fixme: howto handle overflows? */
2716 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2719 MONO_BB_FOR_EACH_INS (bb, ins) {
2720 offset = code - cfg->native_code;
2722 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2724 if (offset > (cfg->code_size - max_len - 16)) {
2725 cfg->code_size *= 2;
2726 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2727 code = cfg->native_code + offset;
2730 mono_debug_record_line_number (cfg, ins, offset);
2732 switch (ins->opcode) {
2733 case OP_STOREI1_MEMBASE_IMM: {
2734 s390_lghi (code, s390_r0, ins->inst_imm);
2735 S390_LONG (code, stcy, stc, s390_r0, 0,
2736 ins->inst_destbasereg, ins->inst_offset);
2739 case OP_STOREI2_MEMBASE_IMM: {
2740 s390_lghi (code, s390_r0, ins->inst_imm);
2741 S390_LONG (code, sthy, sth, s390_r0, 0,
2742 ins->inst_destbasereg, ins->inst_offset);
2745 case OP_STOREI4_MEMBASE_IMM: {
2746 if (s390_is_imm16(ins->inst_imm)) {
2747 s390_lghi (code, s390_r0, ins->inst_imm);
2749 s390_basr (code, s390_r13, 0);
2751 s390_llong(code, ins->inst_imm);
2752 s390_lg (code, s390_r0, 0, s390_r13, 4);
2754 S390_LONG (code, sty, st, s390_r0, 0,
2755 ins->inst_destbasereg, ins->inst_offset);
2758 case OP_STORE_MEMBASE_IMM:
2759 case OP_STOREI8_MEMBASE_IMM: {
2760 if (s390_is_imm16(ins->inst_imm)) {
2761 s390_lghi (code, s390_r0, ins->inst_imm);
2763 s390_basr (code, s390_r13, 0);
2765 s390_llong(code, ins->inst_imm);
2766 s390_lg (code, s390_r0, 0, s390_r13, 4);
2768 S390_LONG (code, stg, stg, s390_r0, 0,
2769 ins->inst_destbasereg, ins->inst_offset);
2772 case OP_STOREI1_MEMBASE_REG: {
2773 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2774 ins->inst_destbasereg, ins->inst_offset);
2777 case OP_STOREI2_MEMBASE_REG: {
2778 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2779 ins->inst_destbasereg, ins->inst_offset);
2782 case OP_STOREI4_MEMBASE_REG: {
2783 S390_LONG (code, sty, st, ins->sreg1, 0,
2784 ins->inst_destbasereg, ins->inst_offset);
2787 case OP_STORE_MEMBASE_REG:
2788 case OP_STOREI8_MEMBASE_REG: {
2789 S390_LONG (code, stg, stg, ins->sreg1, 0,
2790 ins->inst_destbasereg, ins->inst_offset);
2794 g_assert_not_reached ();
2796 case OP_LOAD_MEMBASE:
2797 case OP_LOADI8_MEMBASE: {
2798 S390_LONG (code, lg, lg, ins->dreg, 0,
2799 ins->inst_basereg, ins->inst_offset);
2802 case OP_LOADI4_MEMBASE: {
2803 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2804 ins->inst_basereg, ins->inst_offset);
2807 case OP_LOADU4_MEMBASE: {
2808 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2809 ins->inst_basereg, ins->inst_offset);
2812 case OP_LOADU1_MEMBASE: {
2813 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2814 ins->inst_basereg, ins->inst_offset);
2817 case OP_LOADI1_MEMBASE: {
2818 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2819 ins->inst_basereg, ins->inst_offset);
2822 case OP_LOADU2_MEMBASE: {
2823 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2824 ins->inst_basereg, ins->inst_offset);
2827 case OP_LOADI2_MEMBASE: {
2828 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2829 ins->inst_basereg, ins->inst_offset);
2832 case OP_LCONV_TO_I1: {
2833 s390_lghi (code, s390_r0, 0x80);
2834 if (ins->dreg != ins->sreg1) {
2835 s390_lgr (code, ins->dreg, ins->sreg1);
2837 s390_ngr (code, s390_r0, ins->sreg1);
2839 s390_lghi (code, s390_r13, -1);
2840 s390_sllg (code, s390_r13, s390_r13, 0, 8);
2841 s390_ogr (code, ins->dreg, s390_r13);
2844 case OP_LCONV_TO_I2: {
2845 s390_lghi (code, s390_r0, 0x80);
2846 s390_sllg (code, s390_r0, s390_r0, 0, 8);
2847 if (ins->dreg != ins->sreg1) {
2848 s390_lgr (code, ins->dreg, ins->sreg1);
2850 s390_ngr (code, s390_r0, ins->sreg1);
2852 s390_lghi (code, s390_r13, -1);
2853 s390_sllg (code, s390_r13, s390_r13, 0, 16);
2854 s390_ogr (code, ins->dreg, s390_r13);
2857 case OP_LCONV_TO_U1: {
2858 s390_lghi (code, s390_r0, 0xff);
2859 if (ins->dreg != ins->sreg1) {
2860 s390_lgr (code, ins->dreg, ins->sreg1);
2862 s390_ngr (code, ins->dreg, s390_r0);
2865 case OP_LCONV_TO_U2: {
2866 s390_lghi (code, s390_r0, -1);
2867 s390_sllg (code, s390_r0, s390_r0, 0, 48);
2868 s390_srlg (code, s390_r0, s390_r0, 0, 48);
2869 if (ins->dreg != ins->sreg1) {
2870 s390_lgr (code, ins->dreg, ins->sreg1);
2872 s390_ngr (code, ins->dreg, s390_r0);
2875 case OP_ICONV_TO_I1: {
2876 s390_lhi (code, s390_r0, 0x80);
2877 if (ins->dreg != ins->sreg1) {
2878 s390_lr (code, ins->dreg, ins->sreg1);
2880 s390_nr (code, s390_r0, ins->sreg1);
2882 s390_lhi (code, s390_r13, -1);
2883 s390_sll (code, s390_r13, 0, 8);
2884 s390_or (code, ins->dreg, s390_r13);
2887 case OP_ICONV_TO_I2: {
2888 s390_lhi (code, s390_r0, 0x80);
2889 s390_sll (code, s390_r0, 0, 8);
2890 if (ins->dreg != ins->sreg1) {
2891 s390_lr (code, ins->dreg, ins->sreg1);
2893 s390_nr (code, s390_r0, ins->sreg1);
2895 s390_lhi (code, s390_r13, -1);
2896 s390_sll (code, s390_r13, 0, 16);
2897 s390_or (code, ins->dreg, s390_r13);
2900 case OP_ICONV_TO_U1: {
2901 s390_lhi (code, s390_r0, 0xff);
2902 if (ins->dreg != ins->sreg1) {
2903 s390_lr (code, ins->dreg, ins->sreg1);
2905 s390_nr (code, ins->dreg, s390_r0);
2908 case OP_ICONV_TO_U2: {
2909 s390_lhi (code, s390_r0, -1);
2910 s390_sll (code, s390_r0, 0, 16);
2911 s390_srl (code, s390_r0, 0, 16);
2912 if (ins->dreg != ins->sreg1) {
2913 s390_lr (code, ins->dreg, ins->sreg1);
2915 s390_nr (code, ins->dreg, s390_r0);
2920 if (is_unsigned (ins->next))
2921 s390_clgr (code, ins->sreg1, ins->sreg2);
2923 s390_cgr (code, ins->sreg1, ins->sreg2);
2927 if (is_unsigned (ins->next))
2928 s390_clr (code, ins->sreg1, ins->sreg2);
2930 s390_cr (code, ins->sreg1, ins->sreg2);
2933 case OP_COMPARE_IMM:
2934 case OP_LCOMPARE_IMM: {
2935 if (s390_is_imm16 (ins->inst_imm)) {
2936 s390_lghi (code, s390_r0, ins->inst_imm);
2937 if (is_unsigned (ins->next))
2938 s390_clgr (code, ins->sreg1, s390_r0);
2940 s390_cgr (code, ins->sreg1, s390_r0);
2942 s390_basr (code, s390_r13, 0);
2944 s390_llong(code, ins->inst_imm);
2945 if (is_unsigned (ins->next))
2946 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
2948 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
2952 case OP_ICOMPARE_IMM: {
2953 if (s390_is_imm16 (ins->inst_imm)) {
2954 s390_lghi (code, s390_r0, ins->inst_imm);
2955 if (is_unsigned (ins->next))
2956 s390_clr (code, ins->sreg1, s390_r0);
2958 s390_cr (code, ins->sreg1, s390_r0);
2961 s390_basr (code, s390_r13, 0);
2963 s390_word (code, ins->inst_imm);
2964 if (is_unsigned (ins->next))
2965 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
2967 s390_c (code, ins->sreg1, 0, s390_r13, 4);
2972 s390_basr (code, s390_r13, 0);
2974 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
2976 s390_llong (code, mono_break);
2977 s390_lg (code, s390_r14, 0, s390_r13, 4);
2978 s390_basr (code, s390_r14, s390_r14);
2983 s390_agr (code, ins->dreg, src2);
2988 s390_agr (code, ins->dreg, src2);
2993 s390_alcgr (code, ins->dreg, src2);
2997 if (ins->dreg != ins->sreg1) {
2998 s390_lgr (code, ins->dreg, ins->sreg1);
3000 if (s390_is_imm16 (ins->inst_imm)) {
3001 s390_aghi (code, ins->dreg, ins->inst_imm);
3003 s390_basr (code, s390_r13, 0);
3005 s390_llong(code, ins->inst_imm);
3006 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3011 if (ins->dreg != ins->sreg1) {
3012 s390_lgr (code, ins->dreg, ins->sreg1);
3014 g_assert (s390_is_imm16 (ins->inst_imm));
3015 s390_aghi (code, ins->dreg, ins->inst_imm);
3019 if (ins->dreg != ins->sreg1) {
3020 s390_lgr (code, ins->dreg, ins->sreg1);
3022 if (s390_is_imm16 (ins->inst_imm)) {
3023 s390_lghi (code, s390_r0, ins->inst_imm);
3024 s390_alcgr (code, ins->dreg, s390_r0);
3026 s390_basr (code, s390_r13, 0);
3028 s390_llong (code, ins->inst_imm);
3029 s390_lg (code, s390_r13, 0, s390_r13, 4);
3030 s390_alcgr (code, ins->dreg, s390_r13);
3035 case OP_S390_IADD_OVF: {
3037 s390_ar (code, ins->dreg, src2);
3038 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3039 s390_lgfr (code, ins->dreg, ins->dreg);
3042 case OP_IADD_OVF_UN:
3043 case OP_S390_IADD_OVF_UN: {
3045 s390_algr (code, ins->dreg, src2);
3046 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3047 s390_llgfr (code, ins->dreg, ins->dreg);
3050 case OP_ADD_OVF_CARRY: {
3052 s390_lghi (code, s390_r0, 0);
3053 s390_lgr (code, s390_r1, s390_r0);
3054 s390_alcgr (code, s390_r0, s390_r1);
3055 s390_agr (code, ins->dreg, src2);
3056 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3057 s390_agr (code, ins->dreg, s390_r0);
3058 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3061 case OP_ADD_OVF_UN_CARRY: {
3063 s390_alcgr (code, ins->dreg, src2);
3064 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3069 s390_sgr (code, ins->dreg, src2);
3074 s390_sgr (code, ins->dreg, src2);
3079 s390_slbgr(code, ins->dreg, src2);
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_slgr (code, ins->dreg, s390_r0);
3090 s390_basr (code, s390_r13, 0);
3092 s390_llong(code, ins->inst_imm);
3093 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3098 if (ins->dreg != ins->sreg1) {
3099 s390_lgr (code, ins->dreg, ins->sreg1);
3101 if (s390_is_imm16 (-ins->inst_imm)) {
3102 s390_lghi (code, s390_r0, ins->inst_imm);
3103 s390_slgr (code, ins->dreg, s390_r0);
3105 s390_basr (code, s390_r13, 0);
3107 s390_llong(code, ins->inst_imm);
3108 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3113 if (ins->dreg != ins->sreg1) {
3114 s390_lgr (code, ins->dreg, ins->sreg1);
3116 if (s390_is_imm16 (-ins->inst_imm)) {
3117 s390_lghi (code, s390_r0, ins->inst_imm);
3118 s390_slbgr (code, ins->dreg, s390_r0);
3120 s390_basr (code, s390_r13, 0);
3122 s390_llong(code, ins->inst_imm);
3123 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3127 case OP_SUB_OVF_CARRY: {
3129 s390_lghi (code, s390_r0, 0);
3130 s390_lgr (code, s390_r1, s390_r0);
3131 s390_slbgr (code, s390_r0, s390_r1);
3132 s390_sgr (code, ins->dreg, src2);
3133 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3134 s390_agr (code, ins->dreg, s390_r0);
3135 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3138 case OP_SUB_OVF_UN_CARRY: {
3140 s390_slbgr (code, ins->dreg, src2);
3141 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3145 if (ins->sreg1 == ins->dreg) {
3146 s390_ngr (code, ins->dreg, ins->sreg2);
3149 if (ins->sreg2 == ins->dreg) {
3150 s390_ngr (code, ins->dreg, ins->sreg1);
3153 s390_lgr (code, ins->dreg, ins->sreg1);
3154 s390_ngr (code, ins->dreg, ins->sreg2);
3160 if (ins->dreg != ins->sreg1) {
3161 s390_lgr (code, ins->dreg, ins->sreg1);
3163 if (s390_is_imm16 (ins->inst_imm)) {
3164 s390_lghi (code, s390_r0, ins->inst_imm);
3165 s390_ngr (code, ins->dreg, s390_r0);
3167 s390_basr (code, s390_r13, 0);
3169 s390_llong(code, ins->inst_imm);
3170 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3175 s390_lgr (code, s390_r1, ins->sreg1);
3176 s390_dsgr (code, s390_r0, ins->sreg2);
3177 s390_lgr (code, ins->dreg, s390_r1);
3181 s390_lgr (code, s390_r1, ins->sreg1);
3182 s390_lghi (code, s390_r0, 0);
3183 s390_dlgr (code, s390_r0, ins->sreg2);
3184 s390_lgr (code, ins->dreg, s390_r1);
3188 s390_lgr (code, s390_r1, ins->sreg1);
3189 s390_dsgr (code, s390_r0, ins->sreg2);
3190 s390_lgr (code, ins->dreg, s390_r0);
3194 s390_lgr (code, s390_r1, ins->sreg1);
3195 s390_lghi (code, s390_r0, 0);
3196 s390_dlgr (code, s390_r0, ins->sreg2);
3197 s390_lgr (code, ins->dreg, s390_r0);
3201 if (ins->sreg1 == ins->dreg) {
3202 s390_ogr (code, ins->dreg, ins->sreg2);
3205 if (ins->sreg2 == ins->dreg) {
3206 s390_ogr (code, ins->dreg, ins->sreg1);
3209 s390_lgr (code, ins->dreg, ins->sreg1);
3210 s390_ogr (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_ogr (code, ins->dreg, s390_r0);
3223 s390_basr (code, s390_r13, 0);
3225 s390_llong(code, ins->inst_imm);
3226 s390_og (code, ins->dreg, 0, s390_r13, 4);
3231 if (ins->sreg1 == ins->dreg) {
3232 s390_xgr (code, ins->dreg, ins->sreg2);
3235 if (ins->sreg2 == ins->dreg) {
3236 s390_xgr (code, ins->dreg, ins->sreg1);
3239 s390_lgr (code, ins->dreg, ins->sreg1);
3240 s390_xgr (code, ins->dreg, ins->sreg2);
3246 if (ins->dreg != ins->sreg1) {
3247 s390_lgr (code, ins->dreg, ins->sreg1);
3249 if (s390_is_imm16 (ins->inst_imm)) {
3250 s390_lghi (code, s390_r0, ins->inst_imm);
3251 s390_xgr (code, ins->dreg, s390_r0);
3253 s390_basr (code, s390_r13, 0);
3255 s390_llong(code, ins->inst_imm);
3256 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3262 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3267 if (ins->sreg1 != ins->dreg) {
3268 s390_lgr (code, ins->dreg, ins->sreg1);
3270 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3275 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3280 if (ins->sreg1 != ins->dreg) {
3281 s390_lgr (code, ins->dreg, ins->sreg1);
3283 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3287 case OP_LSHR_UN_IMM: {
3288 if (ins->sreg1 != ins->dreg) {
3289 s390_lgr (code, ins->dreg, ins->sreg1);
3291 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3296 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3300 if (ins->sreg1 != ins->dreg) {
3301 s390_lgr (code, ins->dreg, ins->sreg1);
3303 s390_lghi (code, s390_r0, -1);
3304 s390_xgr (code, ins->dreg, s390_r0);
3308 s390_lcgr (code, ins->dreg, ins->sreg1);
3313 s390_msgr (code, ins->dreg, src2);
3318 if (ins->dreg != ins->sreg1) {
3319 s390_lgr (code, ins->dreg, ins->sreg1);
3321 if (s390_is_imm16 (ins->inst_imm)) {
3322 s390_lghi (code, s390_r13, ins->inst_imm);
3324 s390_basr (code, s390_r13, 0);
3326 s390_llong(code, ins->inst_imm);
3327 s390_lg (code, s390_r13, 0, s390_r13, 4);
3329 s390_msgr (code, ins->dreg, s390_r13);
3334 s390_ltgr (code, s390_r1, ins->sreg1);
3335 s390_jz (code, 0); CODEPTR(code, o[0]);
3336 s390_ltgr (code, s390_r0, ins->sreg2);
3338 s390_lghi (code, s390_r1, 0);
3339 s390_j (code, 0); CODEPTR(code, o[1]);
3340 s390_xgr (code, s390_r0, s390_r1);
3341 s390_msgr (code, s390_r1, ins->sreg2);
3342 s390_xgr (code, s390_r0, s390_r1);
3343 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3344 s390_ltgr (code, s390_r0, s390_r0);
3345 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3346 PTRSLOT (code, o[0]);
3347 PTRSLOT (code, o[1]);
3348 s390_lgr (code, ins->dreg, s390_r1);
3351 case OP_LMUL_OVF_UN: {
3352 s390_lghi (code, s390_r0, 0);
3353 s390_lgr (code, s390_r1, ins->sreg1);
3354 s390_mlgr (code, s390_r0, ins->sreg2);
3355 s390_ltgr (code, s390_r0, s390_r0);
3356 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3357 s390_lgr (code, ins->dreg, s390_r1);
3361 g_assert_not_reached ();
3363 s390_algr (code, ins->dreg, src2);
3368 s390_agr (code, ins->dreg, src2);
3372 g_assert_not_reached ();
3374 s390_alcgr (code, ins->dreg, src2);
3378 if (ins->dreg != ins->sreg1) {
3379 s390_lgfr (code, ins->dreg, ins->sreg1);
3381 if (s390_is_imm16 (ins->inst_imm)) {
3382 s390_aghi(code, ins->dreg, ins->inst_imm);
3384 s390_basr (code, s390_r13, 0);
3386 s390_word (code, ins->inst_imm);
3387 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3392 if (ins->dreg != ins->sreg1) {
3393 s390_lgfr (code, ins->dreg, ins->sreg1);
3395 if (s390_is_imm16 (ins->inst_imm)) {
3396 s390_lghi (code, s390_r0, ins->inst_imm);
3397 s390_alcgr (code, ins->dreg, s390_r0);
3399 s390_basr (code, s390_r13, 0);
3401 s390_word (code, ins->inst_imm);
3402 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3403 s390_alcgr (code, ins->dreg, s390_r13);
3408 case OP_S390_LADD_OVF: {
3410 s390_agr (code, ins->dreg, src2);
3411 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3414 case OP_LADD_OVF_UN:
3415 case OP_S390_LADD_OVF_UN: {
3417 s390_algr (code, ins->dreg, src2);
3418 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3422 CHECK_SRCDST_NCOM_I;
3423 s390_slgr (code, ins->dreg, src2);
3427 CHECK_SRCDST_NCOM_I;
3428 s390_sgr (code, ins->dreg, src2);
3432 CHECK_SRCDST_NCOM_I;
3433 s390_slbgr (code, ins->dreg, src2);
3437 if (ins->dreg != ins->sreg1) {
3438 s390_lgfr (code, ins->dreg, ins->sreg1);
3440 if (s390_is_imm16 (-ins->inst_imm)) {
3441 s390_aghi (code, ins->dreg, -ins->inst_imm);
3443 s390_basr (code, s390_r13, 0);
3445 s390_word (code, ins->inst_imm);
3446 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3451 s390_basr (code, s390_r13, 0);
3453 s390_word (code, ins->inst_imm);
3454 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3458 case OP_S390_ISUB_OVF: {
3460 s390_sr (code, ins->dreg, src2);
3461 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3462 s390_lgfr (code, ins->dreg, ins->dreg);
3465 case OP_ISUB_OVF_UN:
3466 case OP_S390_ISUB_OVF_UN: {
3468 s390_slr (code, ins->dreg, src2);
3469 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3470 s390_llgfr(code, ins->dreg, ins->dreg);
3474 case OP_S390_LSUB_OVF: {
3476 s390_sgr (code, ins->dreg, src2);
3477 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3480 case OP_LSUB_OVF_UN:
3481 case OP_S390_LSUB_OVF_UN: {
3483 s390_slgr (code, ins->dreg, src2);
3484 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3488 CHECK_SRCDST_NCOM_I;
3489 s390_ngr (code, ins->dreg, src2);
3493 if (ins->dreg != ins->sreg1) {
3494 s390_lgfr (code, ins->dreg, ins->sreg1);
3496 if (s390_is_imm16 (ins->inst_imm)) {
3497 s390_lghi (code, s390_r0, ins->inst_imm);
3498 s390_ngr (code, ins->dreg, s390_r0);
3500 s390_basr (code, s390_r13, 0);
3502 s390_llong(code, ins->inst_imm);
3503 s390_ng (code, ins->dreg, 0, s390_r13, 4);
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_r1);
3515 s390_lgfr (code, s390_r0, ins->sreg1);
3516 s390_srdl (code, s390_r0, 0, 32);
3517 s390_dlr (code, s390_r0, ins->sreg2);
3518 s390_lgfr (code, ins->dreg, s390_r1);
3522 if (s390_is_imm16 (ins->inst_imm)) {
3523 s390_lghi (code, s390_r13, ins->inst_imm);
3524 s390_lgfr (code, s390_r0, ins->sreg1);
3526 s390_basr (code, s390_r13, 0);
3528 s390_word (code, ins->inst_imm);
3529 s390_lgfr (code, s390_r0, ins->sreg1);
3530 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3532 s390_srda (code, s390_r0, 0, 32);
3533 s390_dr (code, s390_r0, ins->sreg2);
3534 s390_lgfr (code, ins->dreg, s390_r1);
3538 s390_lgfr (code, s390_r0, ins->sreg1);
3539 s390_srda (code, s390_r0, 0, 32);
3540 s390_dr (code, s390_r0, ins->sreg2);
3541 s390_lgfr (code, ins->dreg, s390_r0);
3544 s390_lgfr (code, s390_r0, ins->sreg1);
3545 s390_srdl (code, s390_r0, 0, 32);
3546 s390_dlr (code, s390_r0, ins->sreg2);
3547 s390_lgfr (code, ins->dreg, s390_r0);
3551 if (s390_is_imm16 (ins->inst_imm)) {
3552 s390_lghi (code, s390_r13, ins->inst_imm);
3553 s390_lgfr (code, s390_r0, ins->sreg1);
3555 s390_basr (code, s390_r13, 0);
3557 s390_word (code, ins->inst_imm);
3558 s390_lgfr (code, s390_r0, ins->sreg1);
3559 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3561 s390_srda (code, s390_r0, 0, 32);
3562 s390_dr (code, s390_r0, ins->sreg2);
3563 s390_lgfr (code, ins->dreg, s390_r0);
3568 s390_ogr (code, ins->dreg, src2);
3572 if (ins->dreg != ins->sreg1) {
3573 s390_lgfr (code, ins->dreg, ins->sreg1);
3575 if (s390_is_imm16 (ins->inst_imm)) {
3576 s390_lghi (code, s390_r0, ins->inst_imm);
3577 s390_ogr (code, ins->dreg, s390_r0);
3579 s390_basr (code, s390_r13, 0);
3581 s390_llong(code, ins->inst_imm);
3582 s390_og (code, ins->dreg, 0, s390_r13, 4);
3588 s390_xgr (code, ins->dreg, src2);
3592 if (ins->dreg != ins->sreg1) {
3593 s390_lgfr (code, ins->dreg, ins->sreg1);
3595 if (s390_is_imm16 (ins->inst_imm)) {
3596 s390_lghi (code, s390_r0, ins->inst_imm);
3597 s390_xgr (code, ins->dreg, s390_r0);
3599 s390_basr (code, s390_r13, 0);
3601 s390_llong(code, ins->inst_imm);
3602 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3608 s390_sll (code, ins->dreg, src2, 0);
3612 if (ins->sreg1 != ins->dreg) {
3613 s390_lgfr (code, ins->dreg, ins->sreg1);
3615 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3620 s390_sra (code, ins->dreg, src2, 0);
3624 if (ins->sreg1 != ins->dreg) {
3625 s390_lgfr (code, ins->dreg, ins->sreg1);
3627 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3630 case OP_ISHR_UN_IMM: {
3631 if (ins->sreg1 != ins->dreg) {
3632 s390_lgfr (code, ins->dreg, ins->sreg1);
3634 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3639 s390_srl (code, ins->dreg, src2, 0);
3643 if (ins->sreg1 != ins->dreg) {
3644 s390_lgfr (code, ins->dreg, ins->sreg1);
3646 s390_lghi (code, s390_r0, -1);
3647 s390_xgr (code, ins->dreg, s390_r0);
3651 s390_lcgr (code, ins->dreg, ins->sreg1);
3656 s390_msr (code, ins->dreg, src2);
3660 if (ins->dreg != ins->sreg1) {
3661 s390_lgfr (code, ins->dreg, ins->sreg1);
3663 if (s390_is_imm16 (ins->inst_imm)) {
3664 s390_lghi (code, s390_r13, ins->inst_imm);
3666 s390_basr (code, s390_r13, 0);
3668 s390_word (code, ins->inst_imm);
3669 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3671 s390_msr (code, ins->dreg, s390_r13);
3676 s390_ltr (code, s390_r1, ins->sreg1);
3677 s390_jz (code, 0); CODEPTR(code, o[0]);
3678 s390_ltr (code, s390_r0, ins->sreg2);
3680 s390_lhi (code, s390_r1, 0);
3681 s390_j (code, 0); CODEPTR(code, o[1]);
3682 s390_xr (code, s390_r0, s390_r1);
3683 s390_msr (code, s390_r1, ins->sreg2);
3684 s390_xr (code, s390_r0, s390_r1);
3685 s390_srl (code, s390_r0, 0, 31);
3686 s390_ltr (code, s390_r0, s390_r0);
3687 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3688 PTRSLOT (code, o[0]);
3689 PTRSLOT (code, o[1]);
3690 s390_lgfr (code, ins->dreg, s390_r1);
3693 case OP_IMUL_OVF_UN: {
3694 s390_lhi (code, s390_r0, 0);
3695 s390_lr (code, s390_r1, ins->sreg1);
3696 s390_mlr (code, s390_r0, ins->sreg2);
3697 s390_ltr (code, s390_r0, s390_r0);
3698 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3699 s390_lgfr (code, ins->dreg, s390_r1);
3704 if (s390_is_imm16(ins->inst_c0)) {
3705 s390_lghi (code, ins->dreg, ins->inst_c0);
3707 s390_basr (code, s390_r13, 0);
3709 s390_llong(code, ins->inst_c0);
3710 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3715 s390_basr (code, s390_r13, 0);
3717 mono_add_patch_info (cfg, code - cfg->native_code,
3718 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3719 s390_llong(code, 0);
3720 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3723 case OP_JUMP_TABLE: {
3724 mono_add_patch_info (cfg, code - cfg->native_code,
3725 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3726 s390_basr (code, s390_r13, 0);
3728 s390_llong (code, 0);
3729 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3733 if (ins->dreg != ins->sreg1) {
3734 s390_lgr (code, ins->dreg, ins->sreg1);
3738 case OP_LCONV_TO_I8:
3740 s390_lgfr (code, ins->dreg, ins->sreg1);
3742 case OP_LCONV_TO_I4:
3743 s390_lgfr (code, ins->dreg, ins->sreg1);
3746 case OP_LCONV_TO_U8:
3747 case OP_LCONV_TO_U4:
3749 s390_llgfr (code, ins->dreg, ins->sreg1);
3751 case OP_LCONV_TO_OVF_U4:
3752 s390_basr (code, s390_r13, 0);
3754 s390_llong(code, 4294967295);
3755 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3756 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3757 s390_ltgr (code, ins->sreg1, ins->sreg1);
3758 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3759 s390_llgfr(code, ins->dreg, ins->sreg1);
3761 case OP_LCONV_TO_OVF_I4_UN:
3762 s390_basr (code, s390_r13, 0);
3764 s390_llong(code, 2147483647);
3765 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3766 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3767 s390_ltgr (code, ins->sreg1, ins->sreg1);
3768 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3769 s390_lgfr (code, ins->dreg, ins->sreg1);
3772 case OP_FCONV_TO_R4: {
3773 if (ins->dreg != ins->sreg1) {
3774 s390_ldr (code, ins->dreg, ins->sreg1);
3778 case OP_S390_SETF4RET: {
3779 s390_ledbr (code, ins->dreg, ins->sreg1);
3783 if (cfg->method->save_lmf)
3784 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3786 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3787 code = emit_load_volatile_arguments (code, cfg);
3790 code = backUpStackPtr(cfg, code);
3791 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3792 mono_add_patch_info (cfg, code - cfg->native_code,
3793 MONO_PATCH_INFO_METHOD_JUMP,
3795 s390_jcl (code, S390_CC_UN, 0);
3798 case OP_CHECK_THIS: {
3799 /* ensure ins->sreg1 is not NULL */
3800 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3801 s390_ltgr (code, s390_r0, s390_r0);
3805 int offset = cfg->sig_cookie + cfg->stack_usage;
3807 if (s390_is_imm16 (offset))
3808 s390_lghi (code, s390_r0, offset);
3810 s390_basr (code, s390_r13, 0);
3812 s390_llong(code, offset);
3813 s390_lg (code, s390_r0, 0, s390_r13, 0);
3815 s390_agr (code, s390_r0, cfg->frame_reg);
3816 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3820 s390_basr (code, s390_r13, 0);
3822 call = (MonoCallInst*)ins;
3823 if (ins->flags & MONO_INST_HAS_METHOD)
3824 mono_add_patch_info (cfg, code-cfg->native_code,
3825 MONO_PATCH_INFO_METHOD,
3828 mono_add_patch_info (cfg, code-cfg->native_code,
3829 MONO_PATCH_INFO_ABS,
3831 s390_llong(code, 0);
3832 s390_lg (code, s390_r14, 0, s390_r13, 4);
3833 s390_basr (code, s390_r14, s390_r14);
3834 if (call->signature->ret->type == MONO_TYPE_R4)
3835 s390_ldebr (code, s390_f0, s390_f0);
3843 s390_basr (code, s390_r13, 0);
3845 call = (MonoCallInst*)ins;
3846 if (ins->flags & MONO_INST_HAS_METHOD)
3847 mono_add_patch_info (cfg, code-cfg->native_code,
3848 MONO_PATCH_INFO_METHOD,
3851 mono_add_patch_info (cfg, code-cfg->native_code,
3852 MONO_PATCH_INFO_ABS,
3854 s390_llong(code, 0);
3855 s390_lg (code, s390_r14, 0, s390_r13, 4);
3856 s390_basr (code, s390_r14, s390_r14);
3859 case OP_FCALL_REG: {
3860 call = (MonoCallInst*)ins;
3861 s390_lgr (code, s390_r1, ins->sreg1);
3862 s390_basr (code, s390_r14, s390_r1);
3863 if (call->signature->ret->type == MONO_TYPE_R4)
3864 s390_ldebr (code, s390_f0, s390_f0);
3870 case OP_VOIDCALL_REG:
3872 s390_lgr (code, s390_r1, ins->sreg1);
3873 s390_basr (code, s390_r14, s390_r1);
3876 case OP_FCALL_MEMBASE: {
3877 call = (MonoCallInst*)ins;
3878 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3879 s390_basr (code, s390_r14, s390_r1);
3880 if (call->signature->ret->type == MONO_TYPE_R4)
3881 s390_ldebr (code, s390_f0, s390_f0);
3884 case OP_LCALL_MEMBASE:
3885 case OP_VCALL_MEMBASE:
3886 case OP_VCALL2_MEMBASE:
3887 case OP_VOIDCALL_MEMBASE:
3888 case OP_CALL_MEMBASE: {
3889 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3890 s390_basr (code, s390_r14, s390_r1);
3894 int alloca_skip = S390_MINIMAL_STACK_SIZE + cfg->param_area;
3895 int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3896 s390_lgr (code, s390_r1, ins->sreg1);
3897 if (ins->flags & MONO_INST_INIT)
3898 s390_lgr (code, s390_r0, ins->sreg1);
3899 s390_aghi (code, s390_r1, 14);
3900 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3901 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3902 if (cfg->method->save_lmf) {
3903 /*----------------------------------*/
3904 /* we have to adjust lmf ebp value */
3905 /*----------------------------------*/
3906 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3908 s390_lgr (code, s390_r13, cfg->frame_reg);
3909 if (s390_is_imm16(lmfOffset))
3910 s390_aghi (code, s390_r13, lmfOffset);
3912 s390_basr (code, s390_r14, 0);
3914 s390_word (code, lmfOffset);
3915 s390_agf (code, s390_r13, 0, s390_r14, 4);
3917 s390_lgr (code, s390_r14, STK_BASE);
3918 s390_sgr (code, s390_r14, s390_r1);
3919 s390_stg (code, s390_r14, 0, s390_r13,
3920 G_STRUCT_OFFSET(MonoLMF, ebp));
3922 s390_lg (code, s390_r13, 0, STK_BASE, 0);
3923 s390_sgr (code, STK_BASE, s390_r1);
3924 s390_stg (code, s390_r13, 0, STK_BASE, 0);
3925 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
3926 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
3927 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
3928 if (ins->flags & MONO_INST_INIT) {
3929 s390_lgr (code, s390_r1, s390_r0);
3930 s390_lgr (code, s390_r0, ins->dreg);
3931 s390_lgr (code, s390_r14, s390_r12);
3932 s390_lghi (code, s390_r13, 0);
3933 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
3935 s390_lgr (code, s390_r12, s390_r14);
3940 s390_lgr (code, s390_r2, ins->sreg1);
3941 s390_basr (code, s390_r13, 0);
3943 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3944 (gpointer) "mono_arch_throw_exception");
3945 s390_llong(code, 0);
3946 s390_lg (code, s390_r14, 0, s390_r13, 4);
3947 s390_basr (code, s390_r14, s390_r14);
3951 s390_lgr (code, s390_r2, ins->sreg1);
3952 s390_basr (code, s390_r13, 0);
3954 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3955 (gpointer) "mono_arch_rethrow_exception");
3956 s390_llong(code, 0);
3957 s390_lg (code, s390_r14, 0, s390_r13, 4);
3958 s390_basr (code, s390_r14, s390_r14);
3961 case OP_START_HANDLER: {
3962 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3964 S390_LONG (code, stg, stg, s390_r14, 0,
3965 spvar->inst_basereg,
3966 spvar->inst_offset);
3969 case OP_ENDFILTER: {
3970 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3972 if (ins->sreg1 != s390_r2)
3973 s390_lgr(code, s390_r2, ins->sreg1);
3974 S390_LONG (code, lg, lg, s390_r14, 0,
3975 spvar->inst_basereg,
3976 spvar->inst_offset);
3977 s390_br (code, s390_r14);
3980 case OP_ENDFINALLY: {
3981 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3983 S390_LONG (code, lg, lg, s390_r14, 0,
3984 spvar->inst_basereg,
3985 spvar->inst_offset);
3986 s390_br (code, s390_r14);
3989 case OP_CALL_HANDLER: {
3990 mono_add_patch_info (cfg, code-cfg->native_code,
3991 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3992 s390_brasl (code, s390_r14, 0);
3996 ins->inst_c0 = code - cfg->native_code;
3999 case OP_RELAXED_NOP:
4002 case OP_DUMMY_STORE:
4003 case OP_NOT_REACHED:
4008 EMIT_UNCOND_BRANCH(ins);
4011 s390_br (code, ins->sreg1);
4017 s390_lghi(code, ins->dreg, 1);
4019 s390_lghi(code, ins->dreg, 0);
4025 s390_lghi(code, ins->dreg, 1);
4027 s390_lghi(code, ins->dreg, 0);
4033 s390_lghi(code, ins->dreg, 1);
4035 s390_lghi(code, ins->dreg, 0);
4041 s390_lghi(code, ins->dreg, 1);
4043 s390_lghi(code, ins->dreg, 0);
4049 s390_lghi(code, ins->dreg, 1);
4051 s390_lghi(code, ins->dreg, 0);
4054 case OP_COND_EXC_EQ:
4055 case OP_COND_EXC_IEQ:
4056 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4058 case OP_COND_EXC_NE_UN:
4059 case OP_COND_EXC_INE_UN:
4060 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4062 case OP_COND_EXC_LT:
4063 case OP_COND_EXC_ILT:
4064 case OP_COND_EXC_LT_UN:
4065 case OP_COND_EXC_ILT_UN:
4066 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4068 case OP_COND_EXC_GT:
4069 case OP_COND_EXC_IGT:
4070 case OP_COND_EXC_GT_UN:
4071 case OP_COND_EXC_IGT_UN:
4072 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4074 case OP_COND_EXC_GE:
4075 case OP_COND_EXC_IGE:
4076 case OP_COND_EXC_GE_UN:
4077 case OP_COND_EXC_IGE_UN:
4078 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4080 case OP_COND_EXC_LE:
4081 case OP_COND_EXC_ILE:
4082 case OP_COND_EXC_LE_UN:
4083 case OP_COND_EXC_ILE_UN:
4084 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4086 case OP_COND_EXC_OV:
4087 case OP_COND_EXC_IOV:
4088 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4090 case OP_COND_EXC_NO:
4091 case OP_COND_EXC_INO:
4092 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4095 case OP_COND_EXC_IC:
4096 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4098 case OP_COND_EXC_NC:
4099 case OP_COND_EXC_INC:
4100 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4104 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4108 EMIT_COND_BRANCH (ins, S390_CC_NE);
4114 EMIT_COND_BRANCH (ins, S390_CC_LT);
4120 EMIT_COND_BRANCH (ins, S390_CC_GT);
4126 EMIT_COND_BRANCH (ins, S390_CC_GE);
4132 EMIT_COND_BRANCH (ins, S390_CC_LE);
4135 /* floating point opcodes */
4137 if (*((float *) ins->inst_p0) == 0) {
4138 s390_lzdr (code, ins->dreg);
4140 s390_basr (code, s390_r13, 0);
4142 s390_llong (code, ins->inst_p0);
4143 s390_lg (code, s390_r13, 0, s390_r13, 4);
4144 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4149 if (*((float *) ins->inst_p0) == 0) {
4150 s390_lzdr (code, ins->dreg);
4152 s390_basr (code, s390_r13, 0);
4154 s390_llong(code, ins->inst_p0);
4155 s390_lg (code, s390_r13, 0, s390_r13, 4);
4156 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4160 case OP_STORER8_MEMBASE_REG: {
4161 S390_LONG (code, stdy, std, ins->sreg1, 0,
4162 ins->inst_destbasereg, ins->inst_offset);
4165 case OP_LOADR8_MEMBASE: {
4166 S390_LONG (code, ldy, ld, ins->dreg, 0,
4167 ins->inst_basereg, ins->inst_offset);
4170 case OP_STORER4_MEMBASE_REG: {
4171 s390_ledbr (code, s390_f15, ins->sreg1);
4172 S390_LONG (code, stey, ste, s390_f15, 0,
4173 ins->inst_destbasereg, ins->inst_offset);
4176 case OP_LOADR4_MEMBASE: {
4177 S390_LONG (code, ldy, ld, s390_f15, 0,
4178 ins->inst_basereg, ins->inst_offset);
4179 s390_ldebr (code, ins->dreg, s390_f15);
4182 case OP_ICONV_TO_R_UN: {
4183 s390_cdfbr (code, ins->dreg, ins->sreg1);
4184 s390_ltr (code, ins->sreg1, ins->sreg1);
4185 s390_jnl (code, 12);
4186 s390_basr (code, s390_r13, 0);
4188 s390_word (code, 0x41f00000);
4189 s390_word (code, 0);
4190 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4193 case OP_LCONV_TO_R_UN: {
4194 s390_cdgbr (code, ins->dreg, ins->sreg1);
4195 s390_ltgr (code, ins->sreg1, ins->sreg1);
4196 s390_jnl (code, 12);
4197 s390_basr (code, s390_r13, 0);
4199 s390_word (code, 0x41f00000);
4200 s390_word (code, 0);
4201 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4204 case OP_LCONV_TO_R4:
4205 case OP_ICONV_TO_R4: {
4206 s390_cdgbr (code, ins->dreg, ins->sreg1);
4209 case OP_LCONV_TO_R8:
4210 case OP_ICONV_TO_R8: {
4211 s390_cdgbr (code, ins->dreg, ins->sreg1);
4214 case OP_FCONV_TO_I1:
4215 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4217 case OP_FCONV_TO_U1:
4218 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4220 case OP_FCONV_TO_I2:
4221 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4223 case OP_FCONV_TO_U2:
4224 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4226 case OP_FCONV_TO_I4:
4228 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4230 case OP_FCONV_TO_U4:
4232 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4234 case OP_FCONV_TO_I8:
4235 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4237 case OP_LCONV_TO_OVF_I: {
4238 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4240 s390_ltgr (code, ins->sreg2, ins->sreg2);
4241 s390_jnl (code, 0); CODEPTR(code, o[0]);
4242 s390_ltgr (code, ins->sreg1, ins->sreg1);
4243 s390_jnl (code, 0); CODEPTR(code, o[1]);
4244 s390_lhi (code, s390_r13, -1);
4245 s390_cgr (code, ins->sreg1, s390_r13);
4246 s390_jnz (code, 0); CODEPTR(code, o[2]);
4247 if (ins->dreg != ins->sreg2)
4248 s390_lgr (code, ins->dreg, ins->sreg2);
4249 s390_j (code, 0); CODEPTR(code, o[3]);
4250 PTRSLOT(code, o[0]);
4251 s390_jz (code, 0); CODEPTR(code, o[4]);
4252 PTRSLOT(code, o[1]);
4253 PTRSLOT(code, o[2]);
4254 mono_add_patch_info (cfg, code - cfg->native_code,
4255 MONO_PATCH_INFO_EXC, "OverflowException");
4256 s390_brasl (code, s390_r14, 0);
4257 PTRSLOT(code, o[3]);
4258 PTRSLOT(code, o[4]);
4262 s390_lpdbr (code, ins->dreg, ins->sreg1);
4266 s390_sqdbr (code, ins->dreg, ins->sreg1);
4271 s390_adbr (code, ins->dreg, src2);
4275 CHECK_SRCDST_NCOM_F;
4276 s390_sdbr (code, ins->dreg, src2);
4281 s390_mdbr (code, ins->dreg, src2);
4285 CHECK_SRCDST_NCOM_F;
4286 s390_ddbr (code, ins->dreg, src2);
4290 s390_lcdbr (code, ins->dreg, ins->sreg1);
4294 CHECK_SRCDST_NCOM_F;
4295 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4299 s390_cdbr (code, ins->sreg1, ins->sreg2);
4303 s390_cdbr (code, ins->sreg1, ins->sreg2);
4304 s390_lghi (code, ins->dreg, 1);
4306 s390_lghi (code, ins->dreg, 0);
4310 s390_cdbr (code, ins->sreg1, ins->sreg2);
4311 s390_lghi (code, ins->dreg, 1);
4313 s390_lghi (code, ins->dreg, 0);
4317 s390_cdbr (code, ins->sreg1, ins->sreg2);
4318 s390_lghi (code, ins->dreg, 1);
4320 s390_lghi (code, ins->dreg, 0);
4324 s390_cdbr (code, ins->sreg1, ins->sreg2);
4325 s390_lghi (code, ins->dreg, 1);
4327 s390_lghi (code, ins->dreg, 0);
4331 s390_cdbr (code, ins->sreg1, ins->sreg2);
4332 s390_lghi (code, ins->dreg, 1);
4334 s390_lghi (code, ins->dreg, 0);
4339 s390_jo (code, 0); CODEPTR(code, o);
4340 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4345 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4349 s390_jo (code, 0); CODEPTR(code, o);
4350 EMIT_COND_BRANCH (ins, S390_CC_LT);
4355 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4359 s390_jo (code, 0); CODEPTR(code, o);
4360 EMIT_COND_BRANCH (ins, S390_CC_GT);
4365 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4369 s390_jo (code, 0); CODEPTR(code, o);
4370 EMIT_COND_BRANCH (ins, S390_CC_GE);
4375 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4379 s390_jo (code, 0); CODEPTR(code, o);
4380 EMIT_COND_BRANCH (ins, S390_CC_LE);
4385 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4389 s390_lhi (code, s390_r13, 0x7f);
4390 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4391 s390_jz (code, 0); CODEPTR(code, o);
4392 mono_add_patch_info (cfg, code - cfg->native_code,
4393 MONO_PATCH_INFO_EXC, "ArithmeticException");
4394 s390_brasl (code, s390_r14,0);
4398 case OP_S390_MOVE: {
4399 if (ins->backend.size > 0) {
4400 if (ins->backend.size <= 256) {
4401 s390_mvc (code, ins->backend.size, ins->dreg,
4402 ins->inst_offset, ins->sreg1, ins->inst_imm);
4404 s390_lgr (code, s390_r0, ins->dreg);
4405 if (s390_is_imm16 (ins->inst_offset)) {
4406 s390_aghi (code, s390_r0, ins->inst_offset);
4408 s390_basr (code, s390_r13, 0);
4410 s390_llong(code, ins->inst_offset);
4411 s390_a (code, s390_r0, 0, s390_r13, 4);
4413 s390_lgr (code, s390_r12, ins->sreg1);
4414 if (s390_is_imm16 (ins->inst_imm)) {
4415 s390_aghi (code, s390_r12, ins->inst_imm);
4417 s390_basr (code, s390_r13, 0);
4419 s390_llong(code, ins->inst_imm);
4420 s390_ag (code, s390_r12, 0, s390_r13, 4);
4422 s390_lgr (code, s390_r1, ins->sreg1);
4423 s390_lgr (code, s390_r13, s390_r1);
4424 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4430 case OP_ATOMIC_ADD_I8: {
4431 s390_lgr (code, s390_r1, ins->sreg2);
4432 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4433 s390_agr (code, s390_r1, s390_r0);
4434 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4435 s390_jnz (code, -10);
4436 s390_lgr (code, ins->dreg, s390_r1);
4439 case OP_ATOMIC_ADD_NEW_I8: {
4440 s390_lgr (code, s390_r1, ins->sreg2);
4441 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4442 s390_agr (code, s390_r1, s390_r0);
4443 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4444 s390_jnz (code, -10);
4445 s390_lgr (code, ins->dreg, s390_r1);
4448 case OP_ATOMIC_EXCHANGE_I8: {
4449 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4450 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4451 s390_jnz (code, -6);
4452 s390_lgr (code, ins->dreg, s390_r0);
4455 case OP_ATOMIC_ADD_I4: {
4456 s390_lgfr(code, s390_r1, ins->sreg2);
4457 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4458 s390_agr (code, s390_r1, s390_r0);
4459 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4460 s390_jnz (code, -9);
4461 s390_lgfr(code, ins->dreg, s390_r1);
4464 case OP_ATOMIC_ADD_NEW_I4: {
4465 s390_lgfr(code, s390_r1, ins->sreg2);
4466 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4467 s390_agr (code, s390_r1, s390_r0);
4468 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4469 s390_jnz (code, -9);
4470 s390_lgfr(code, ins->dreg, s390_r1);
4473 case OP_ATOMIC_EXCHANGE_I4: {
4474 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4475 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4476 s390_jnz (code, -4);
4477 s390_lgfr(code, ins->dreg, s390_r0);
4480 case OP_S390_BKCHAIN: {
4481 s390_lgr (code, ins->dreg, ins->sreg1);
4482 if (s390_is_imm16 (cfg->stack_offset)) {
4483 s390_aghi (code, ins->dreg, cfg->stack_offset);
4485 s390_basr (code, s390_r13, 0);
4487 s390_llong(code, cfg->stack_offset);
4488 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4492 case OP_MEMORY_BARRIER: {
4496 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4497 g_assert_not_reached ();
4500 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4501 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4502 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4503 g_assert_not_reached ();
4508 last_offset = offset;
4511 cfg->code_len = code - cfg->native_code;
4514 /*========================= End of Function ========================*/
4516 /*------------------------------------------------------------------*/
4518 /* Name - mono_arch_register_lowlevel_calls */
4520 /* Function - Register routines to help with --trace operation. */
4522 /*------------------------------------------------------------------*/
4525 mono_arch_register_lowlevel_calls (void)
4527 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4530 /*========================= End of Function ========================*/
4532 /*------------------------------------------------------------------*/
4534 /* Name - mono_arch_patch_code */
4536 /* Function - Process the patch data created during the */
4537 /* instruction build process. This resolves jumps, */
4538 /* calls, variables etc. */
4540 /*------------------------------------------------------------------*/
4543 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4544 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4546 MonoJumpInfo *patch_info;
4548 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4549 unsigned char *ip = patch_info->ip.i + code;
4550 gconstpointer target = NULL;
4552 target = mono_resolve_patch_target (method, domain, code,
4553 patch_info, run_cctors);
4555 switch (patch_info->type) {
4556 case MONO_PATCH_INFO_IP:
4557 case MONO_PATCH_INFO_EXC_NAME:
4558 case MONO_PATCH_INFO_LDSTR:
4559 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4560 case MONO_PATCH_INFO_LDTOKEN:
4561 case MONO_PATCH_INFO_EXC:
4562 case MONO_PATCH_INFO_ABS:
4563 case MONO_PATCH_INFO_METHOD:
4564 case MONO_PATCH_INFO_INTERNAL_METHOD:
4565 case MONO_PATCH_INFO_CLASS_INIT:
4566 s390_patch_addr (ip, (guint64) target);
4568 case MONO_PATCH_INFO_SWITCH:
4569 /*----------------------------------*/
4570 /* ip points at the basr r13,0/j +4 */
4571 /* instruction the vtable value */
4572 /* follows this (i.e. ip+6) */
4573 /*----------------------------------*/
4574 *((gconstpointer *)(ip+6)) = target;
4576 case MONO_PATCH_INFO_METHODCONST:
4577 case MONO_PATCH_INFO_CLASS:
4578 case MONO_PATCH_INFO_IMAGE:
4579 case MONO_PATCH_INFO_FIELD:
4580 case MONO_PATCH_INFO_IID:
4581 target = S390_RELATIVE(target, ip);
4582 s390_patch_rel (ip, (guint64) target);
4584 case MONO_PATCH_INFO_R4:
4585 case MONO_PATCH_INFO_R8:
4586 case MONO_PATCH_INFO_METHOD_REL:
4587 g_assert_not_reached ();
4590 target = S390_RELATIVE(target, ip);
4592 s390_patch_rel (ip, (guint64) target);
4597 /*========================= End of Function ========================*/
4599 /*------------------------------------------------------------------*/
4601 /* Name - emit_load_volatile_arguments */
4603 /* Function - Emit the instructions to reload parameter regist- */
4604 /* registers for use with "tail" operations. */
4606 /* The register loading operations performed here */
4607 /* are the mirror of the store operations performed */
4608 /* in mono_arch_emit_prolog and need to be kept in */
4609 /* synchronization with it. */
4611 /*------------------------------------------------------------------*/
4614 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4617 MonoMethod *method = cfg->method;
4618 MonoMethodSignature *sig = mono_method_signature(method);
4622 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4624 if (cinfo->struct_ret) {
4625 ArgInfo *ainfo = &cinfo->ret;
4626 inst = cfg->vret_addr;
4627 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4630 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4631 ArgInfo *ainfo = cinfo->args + i;
4632 inst = cfg->args [pos];
4634 if (inst->opcode == OP_REGVAR) {
4635 if (ainfo->regtype == RegTypeGeneral)
4636 s390_lgr (code, ainfo->reg, inst->dreg);
4637 else if (ainfo->regtype == RegTypeFP) {
4638 if (inst->dreg != ainfo->reg) {
4639 if (ainfo->size == 4) {
4640 s390_ldebr (code, ainfo->reg, inst->dreg);
4642 s390_ldr (code, ainfo->reg, inst->dreg);
4646 else if (ainfo->regtype == RegTypeBase) {
4648 g_assert_not_reached ();
4650 if (ainfo->regtype == RegTypeGeneral) {
4651 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4652 g_assert_not_reached();
4653 switch (ainfo->size) {
4655 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4658 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4661 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4664 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4667 } else if (ainfo->regtype == RegTypeBase) {
4668 } else if (ainfo->regtype == RegTypeFP) {
4669 if (ainfo->size == 8)
4670 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4671 else if (ainfo->size == 4)
4672 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4674 g_assert_not_reached ();
4675 } else if (ainfo->regtype == RegTypeStructByVal) {
4676 if (ainfo->reg != STK_BASE) {
4677 switch (ainfo->size) {
4679 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4682 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4685 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4688 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4692 } else if (ainfo->regtype == RegTypeStructByAddr) {
4693 if (ainfo->reg != STK_BASE) {
4694 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4697 g_assert_not_reached ();
4705 /*========================= End of Function ========================*/
4707 /*------------------------------------------------------------------*/
4709 /* Name - mono_arch_emit_prolog */
4711 /* Function - Create the instruction sequence for a function */
4714 /*------------------------------------------------------------------*/
4717 mono_arch_emit_prolog (MonoCompile *cfg)
4719 MonoMethod *method = cfg->method;
4721 MonoMethodSignature *sig;
4723 int alloc_size, pos, max_offset, i;
4729 cfg->code_size = 512;
4731 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4733 cfg->code_size += 256;
4736 if (method->save_lmf)
4737 cfg->code_size += 200;
4739 cfg->native_code = code = g_malloc (cfg->code_size);
4741 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4743 if (cfg->arch.bkchain_reg != -1)
4744 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4746 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4747 cfg->used_int_regs |= 1 << 11;
4750 alloc_size = cfg->stack_offset;
4752 cfg->stack_usage = alloc_size;
4753 s390_lgr (code, s390_r11, STK_BASE);
4754 if (s390_is_imm16 (alloc_size)) {
4755 s390_aghi (code, STK_BASE, -alloc_size);
4757 int stackSize = alloc_size;
4758 while (stackSize > 32767) {
4759 s390_aghi (code, STK_BASE, -32767);
4762 s390_aghi (code, STK_BASE, -stackSize);
4764 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4766 if (cfg->frame_reg != STK_BASE)
4767 s390_lgr (code, s390_r11, STK_BASE);
4769 /* compute max_offset in order to use short forward jumps
4770 * we always do it on s390 because the immediate displacement
4771 * for jumps is too small
4774 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4776 bb->max_offset = max_offset;
4778 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4781 MONO_BB_FOR_EACH_INS (bb, ins)
4782 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4785 /* load arguments allocated to register from the stack */
4786 sig = mono_method_signature (method);
4789 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4791 if (cinfo->struct_ret) {
4792 ArgInfo *ainfo = &cinfo->ret;
4793 inst = cfg->vret_addr;
4794 inst->backend.size = ainfo->vtsize;
4795 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4798 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4799 ArgInfo *ainfo = cinfo->args + i;
4800 inst = cfg->args [pos];
4802 if (inst->opcode == OP_VTARG_ADDR)
4803 inst = inst->inst_left;
4805 if (inst->opcode == OP_REGVAR) {
4806 if (ainfo->regtype == RegTypeGeneral)
4807 s390_lgr (code, inst->dreg, ainfo->reg);
4808 else if (ainfo->regtype == RegTypeFP) {
4809 if (inst->dreg != ainfo->reg) {
4810 if (ainfo->size == 4) {
4811 s390_ledbr (code, inst->dreg, ainfo->reg);
4813 s390_ldr (code, inst->dreg, ainfo->reg);
4817 else if (ainfo->regtype == RegTypeBase) {
4818 s390_lgr (code, s390_r13, STK_BASE);
4819 s390_aghi (code, s390_r13, alloc_size);
4820 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4822 g_assert_not_reached ();
4824 if (cfg->verbose_level > 2)
4825 g_print ("Argument %d assigned to register %s\n",
4826 pos, mono_arch_regname (inst->dreg));
4828 if (ainfo->regtype == RegTypeGeneral) {
4829 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4830 g_assert_not_reached();
4831 switch (ainfo->size) {
4833 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4836 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4839 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4842 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4845 } else if (ainfo->regtype == RegTypeBase) {
4846 } else if (ainfo->regtype == RegTypeFP) {
4847 if (ainfo->size == 8)
4848 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4849 else if (ainfo->size == 4)
4850 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4852 g_assert_not_reached ();
4853 } else if (ainfo->regtype == RegTypeStructByVal) {
4854 int doffset = inst->inst_offset;
4856 if (ainfo->reg != STK_BASE)
4860 s390_lgr (code, s390_r13, STK_BASE);
4861 s390_aghi (code, s390_r13, alloc_size);
4863 switch (ainfo->size) {
4865 if (ainfo->reg == STK_BASE)
4866 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
4867 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4870 if (ainfo->reg == STK_BASE)
4871 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
4872 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4875 if (ainfo->reg == STK_BASE)
4876 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
4877 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4880 if (ainfo->reg == STK_BASE)
4881 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
4882 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
4885 } else if (ainfo->regtype == RegTypeStructByAddr) {
4886 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4887 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
4889 g_assert_not_reached ();
4894 if (method->save_lmf) {
4895 /*---------------------------------------------------------------*/
4896 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4897 /*---------------------------------------------------------------*/
4898 lmfOffset = alloc_size - sizeof(MonoLMF);
4900 s390_lgr (code, s390_r13, cfg->frame_reg);
4901 s390_aghi (code, s390_r13, lmfOffset);
4903 /*---------------------------------------------------------------*/
4904 /* Preserve the parameter registers while we fix up the lmf */
4905 /*---------------------------------------------------------------*/
4906 s390_stmg (code, s390_r2, s390_r6, s390_r13,
4907 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4909 /*---------------------------------------------------------------*/
4910 /* On return from this call r2 have the address of the &lmf */
4911 /*---------------------------------------------------------------*/
4912 s390_basr(code, s390_r10, 0);
4914 mono_add_patch_info (cfg, code - cfg->native_code,
4915 MONO_PATCH_INFO_INTERNAL_METHOD,
4916 (gpointer)"mono_get_lmf_addr");
4917 s390_llong(code, 0);
4918 s390_lg (code, s390_r1, 0, s390_r10, 4);
4919 s390_basr (code, s390_r14, s390_r1);
4921 /*---------------------------------------------------------------*/
4922 /* Set lmf.lmf_addr = jit_tls->lmf */
4923 /*---------------------------------------------------------------*/
4924 s390_stg (code, s390_r2, 0, s390_r13,
4925 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4927 /*---------------------------------------------------------------*/
4928 /* Get current lmf */
4929 /*---------------------------------------------------------------*/
4930 s390_lg (code, s390_r0, 0, s390_r2, 0);
4932 /*---------------------------------------------------------------*/
4933 /* Set our lmf as the current lmf */
4934 /*---------------------------------------------------------------*/
4935 s390_stg (code, s390_r13, 0, s390_r2, 0);
4937 /*---------------------------------------------------------------*/
4938 /* Have our lmf.previous_lmf point to the last lmf */
4939 /*---------------------------------------------------------------*/
4940 s390_stg (code, s390_r0, 0, s390_r13,
4941 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4943 /*---------------------------------------------------------------*/
4944 /* save method info */
4945 /*---------------------------------------------------------------*/
4946 s390_basr (code, s390_r1, 0);
4948 s390_llong (code, method);
4949 s390_lg (code, s390_r1, 0, s390_r1, 4);
4950 s390_stg (code, s390_r1, 0, s390_r13,
4951 G_STRUCT_OFFSET(MonoLMF, method));
4953 /*---------------------------------------------------------------*/
4954 /* save the current IP */
4955 /*---------------------------------------------------------------*/
4956 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4957 s390_basr (code, s390_r1, 0);
4958 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4960 /*---------------------------------------------------------------*/
4961 /* Save general and floating point registers */
4962 /*---------------------------------------------------------------*/
4963 s390_stmg (code, s390_r2, s390_r12, s390_r13,
4964 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
4965 for (i = 0; i < 16; i++) {
4966 s390_std (code, i, 0, s390_r13,
4967 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
4970 /*---------------------------------------------------------------*/
4971 /* Restore the parameter registers now that we've set up the lmf */
4972 /*---------------------------------------------------------------*/
4973 s390_lmg (code, s390_r2, s390_r6, s390_r13,
4974 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4978 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
4980 cfg->code_len = code - cfg->native_code;
4981 g_assert (cfg->code_len < cfg->code_size);
4986 /*========================= End of Function ========================*/
4988 /*------------------------------------------------------------------*/
4990 /* Name - mono_arch_emit_epilog */
4992 /* Function - Emit the instructions for a function epilog. */
4994 /*------------------------------------------------------------------*/
4997 mono_arch_emit_epilog (MonoCompile *cfg)
4999 MonoMethod *method = cfg->method;
5002 int max_epilog_size = 96;
5004 if (cfg->method->save_lmf)
5005 max_epilog_size += 128;
5007 if (mono_jit_trace_calls != NULL)
5008 max_epilog_size += 128;
5010 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5011 max_epilog_size += 128;
5013 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5014 cfg->code_size *= 2;
5015 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5016 mono_jit_stats.code_reallocs++;
5019 code = cfg->native_code + cfg->code_len;
5021 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5022 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5026 if (method->save_lmf)
5027 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5029 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
5030 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5032 code = backUpStackPtr(cfg, code);
5034 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5035 s390_br (code, s390_r14);
5037 cfg->code_len = code - cfg->native_code;
5039 g_assert (cfg->code_len < cfg->code_size);
5043 /*========================= End of Function ========================*/
5045 /*------------------------------------------------------------------*/
5047 /* Name - mono_arch_emit_exceptions */
5049 /* Function - Emit the blocks to handle exception conditions. */
5051 /*------------------------------------------------------------------*/
5054 mono_arch_emit_exceptions (MonoCompile *cfg)
5056 MonoJumpInfo *patch_info;
5062 MonoClass *exc_classes [MAX_EXC];
5063 guint8 *exc_throw_start [MAX_EXC];
5065 for (patch_info = cfg->patch_info;
5067 patch_info = patch_info->next) {
5068 if (patch_info->type == MONO_PATCH_INFO_EXC)
5072 code_size = exc_count * 48;
5074 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5075 cfg->code_size *= 2;
5076 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5077 mono_jit_stats.code_reallocs++;
5080 code = cfg->native_code + cfg->code_len;
5082 /*---------------------------------------------------------------------*/
5083 /* Add code to raise exceptions */
5084 /*---------------------------------------------------------------------*/
5085 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5086 switch (patch_info->type) {
5087 case MONO_PATCH_INFO_EXC: {
5088 guint8 *ip = patch_info->ip.i + cfg->native_code;
5089 MonoClass *exc_class;
5092 /*-----------------------------------------------------*/
5093 /* Patch the branch in epilog to come here */
5094 /*-----------------------------------------------------*/
5095 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5097 exc_class = mono_class_from_name (mono_defaults.corlib,
5099 patch_info->data.name);
5100 g_assert (exc_class);
5101 throw_ip = patch_info->ip.i;
5103 for (iExc = 0; iExc < nThrows; ++iExc)
5104 if (exc_classes [iExc] == exc_class)
5107 if (iExc < nThrows) {
5108 s390_jcl (code, S390_CC_UN,
5109 (guint64) exc_throw_start [iExc]);
5110 patch_info->type = MONO_PATCH_INFO_NONE;
5113 if (nThrows < MAX_EXC) {
5114 exc_classes [nThrows] = exc_class;
5115 exc_throw_start [nThrows] = code;
5118 /*---------------------------------------------*/
5119 /* Patch the parameter passed to the handler */
5120 /*---------------------------------------------*/
5121 s390_basr (code, s390_r13, 0);
5123 s390_llong(code, patch_info->data.target);
5124 /*---------------------------------------------*/
5125 /* Load return address & parameter register */
5126 /*---------------------------------------------*/
5127 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5128 cfg->native_code + 8), code));
5129 s390_lg (code, s390_r2, 0, s390_r13, 4);
5130 /*---------------------------------------------*/
5131 /* Reuse the current patch to set the jump */
5132 /*---------------------------------------------*/
5133 s390_basr (code, s390_r13, 0);
5135 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5136 patch_info->data.name = "mono_arch_throw_exception_by_name";
5137 patch_info->ip.i = code - cfg->native_code;
5138 s390_llong(code, 0);
5139 s390_lg (code, s390_r1, 0, s390_r13, 4);
5140 s390_br (code, s390_r1);
5150 cfg->code_len = code - cfg->native_code;
5152 g_assert (cfg->code_len < cfg->code_size);
5156 /*========================= End of Function ========================*/
5158 /*------------------------------------------------------------------*/
5160 /* Name - mono_arch_setup_jit_tls_data */
5162 /* Function - Setup the JIT's Thread Level Specific Data. */
5164 /*------------------------------------------------------------------*/
5167 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5169 if (!tls_offset_inited) {
5170 tls_offset_inited = TRUE;
5174 __asm__ ("\tear\t%r1,0\n"
5181 : "=r" (appdomain_tls_offset),
5182 "=r" (thread_tls_offset),
5183 "=r" (lmf_tls_offset)
5184 : "r" (&tls_appdomain),
5185 "r" (&tls_current_object),
5186 "r" (&mono_lmf_addr)
5192 if (!lmf_addr_key_inited) {
5193 lmf_addr_key_inited = TRUE;
5194 pthread_key_create (&lmf_addr_key, NULL);
5196 pthread_setspecific (lmf_addr_key, &tls->lmf);
5200 /*========================= End of Function ========================*/
5202 /*------------------------------------------------------------------*/
5204 /* Name - mono_arch_free_jit_tls_data */
5206 /* Function - Free tls data. */
5208 /*------------------------------------------------------------------*/
5211 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5215 /*========================= End of Function ========================*/
5217 /*------------------------------------------------------------------*/
5219 /* Name - mono_arch_emit_inst_for_method */
5221 /*------------------------------------------------------------------*/
5224 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5229 /*========================= End of Function ========================*/
5232 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5235 * Have to rename these to avoid being decomposed normally, since the normal
5236 * decomposition does not work on S390.
5238 switch (ins->opcode) {
5240 ins->opcode = OP_S390_ISUB_OVF;
5242 case OP_ISUB_OVF_UN:
5243 ins->opcode = OP_S390_ISUB_OVF_UN;
5246 ins->opcode = OP_S390_IADD_OVF;
5248 case OP_IADD_OVF_UN:
5249 ins->opcode = OP_S390_IADD_OVF_UN;
5252 ins->opcode = OP_S390_LADD_OVF;
5254 case OP_LADD_OVF_UN:
5255 ins->opcode = OP_S390_LADD_OVF_UN;
5258 ins->opcode = OP_S390_LSUB_OVF;
5260 case OP_LSUB_OVF_UN:
5261 ins->opcode = OP_S390_LSUB_OVF_UN;
5268 /*========================= End of Function ========================*/
5270 /*------------------------------------------------------------------*/
5272 /* Name - mono_arch_print_tree */
5274 /* Function - Print platform-specific opcode details. */
5276 /* Returns - 1 - opcode details have been printed */
5277 /* 0 - opcode details have not been printed */
5279 /*------------------------------------------------------------------*/
5282 mono_arch_print_tree (MonoInst *tree, int arity)
5286 switch (tree->opcode) {
5287 case OP_S390_LOADARG:
5288 case OP_S390_ARGREG:
5289 case OP_S390_ARGPTR:
5290 printf ("[0x%lx(%s)]", tree->inst_offset,
5291 mono_arch_regname (tree->inst_basereg));
5294 case OP_S390_STKARG:
5295 printf ("[0x%lx(previous_frame)]",
5300 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5301 tree->inst_offset, tree->backend.size,
5302 mono_arch_regname(tree->dreg),
5304 mono_arch_regname(tree->sreg1));
5307 case OP_S390_SETF4RET:
5308 printf ("[f%s,f%s]",
5309 mono_arch_regname (tree->dreg),
5310 mono_arch_regname (tree->sreg1));
5314 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5316 mono_arch_regname (tree->sreg1));
5319 case OP_S390_BKCHAIN:
5320 printf ("[previous_frame(%s)]",
5321 mono_arch_regname (tree->sreg1));
5329 /*========================= End of Function ========================*/
5331 /*------------------------------------------------------------------*/
5333 /* Name - mono_arch_regalloc_cost */
5335 /* Function - Determine the cost, in the number of memory */
5336 /* references, of the action of allocating the var- */
5337 /* iable VMV into a register during global register */
5340 /* Returns - Cost */
5342 /*------------------------------------------------------------------*/
5345 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5351 /*========================= End of Function ========================*/
5353 /*------------------------------------------------------------------*/
5355 /* Name - mono_arch_get_domain_intrinsic */
5361 /*------------------------------------------------------------------*/
5364 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5368 if (appdomain_tls_offset == -1)
5371 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5372 ins->inst_offset = appdomain_tls_offset;
5376 /*========================= End of Function ========================*/
5378 /*------------------------------------------------------------------*/
5380 /* Name - mono_arch_get_thread_intrinsic */
5386 /*------------------------------------------------------------------*/
5389 mono_arch_get_thread_intrinsic (MonoCompile* cfg)
5393 if (thread_tls_offset == -1)
5396 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5397 ins->inst_offset = thread_tls_offset;
5401 /*========================= End of Function ========================*/
5403 /*------------------------------------------------------------------*/
5405 /* Name - mono_arch_flush_register_windows */
5411 /*------------------------------------------------------------------*/
5414 mono_arch_flush_register_windows (void)
5418 /*========================= End of Function ========================*/
5420 /*------------------------------------------------------------------*/
5422 /* Name - mono_arch_get_lmf_addr */
5428 /*------------------------------------------------------------------*/
5431 mono_arch_get_lmf_addr (void)
5433 return pthread_getspecific (lmf_addr_key);
5436 /*========================= End of Function ========================*/
5438 /*------------------------------------------------------------------*/
5440 /* Name - mono_arch_is_inst_imm */
5442 /* Function - Determine if operand qualifies as an immediate */
5443 /* value. For s390 this is a value -32768-32768 */
5445 /* Returns - True|False - is [not] immediate value. */
5447 /*------------------------------------------------------------------*/
5450 mono_arch_is_inst_imm (gint64 imm)
5452 return s390_is_imm16 (imm);
5455 /*========================= End of Function ========================*/
5457 /*------------------------------------------------------------------*/
5459 /* Name - mono_arch_get_patch_offset */
5461 /* Function - Dummy entry point until s390x supports aot. */
5463 /* Returns - Offset for patch. */
5465 /*------------------------------------------------------------------*/
5468 mono_arch_get_patch_offset (guint8 *code)
5473 /*========================= End of Function ========================*/
5476 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5478 /* FIXME: implement */
5479 g_assert_not_reached ();