1 /*------------------------------------------------------------------*/
3 /* Name - mini-s390.c */
5 /* Function - S/390 backend for the Mono code generator. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 #define MAX_ARCH_DELEGATE_PARAMS 7
23 #define EMIT_COND_BRANCH(ins,cond) \
25 if (ins->inst_true_bb->native_offset) { \
27 displace = ((cfg->native_code + \
28 ins->inst_true_bb->native_offset) - code) / 2; \
29 if (s390_is_imm16(displace)) { \
30 s390_brc (code, cond, displace); \
32 s390_jcl (code, cond, displace); \
35 mono_add_patch_info (cfg, code - cfg->native_code, \
36 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
37 s390_jcl (code, cond, 0); \
41 #define EMIT_UNCOND_BRANCH(ins) \
43 if (ins->inst_target_bb->native_offset) { \
45 displace = ((cfg->native_code + \
46 ins->inst_target_bb->native_offset) - code) / 2; \
47 if (s390_is_imm16(displace)) { \
48 s390_brc (code, S390_CC_UN, displace); \
50 s390_jcl (code, S390_CC_UN, displace); \
53 mono_add_patch_info (cfg, code - cfg->native_code, \
54 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
55 s390_jcl (code, S390_CC_UN, 0); \
59 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
61 mono_add_patch_info (cfg, code - cfg->native_code, \
62 MONO_PATCH_INFO_EXC, exc_name); \
63 s390_jcl (code, cond, 0); \
66 #define CHECK_SRCDST_COM \
67 if (ins->dreg == ins->sreg2) { \
71 if (ins->dreg != ins->sreg1) { \
72 s390_lgr (code, ins->dreg, ins->sreg1); \
76 #define CHECK_SRCDST_NCOM \
77 if (ins->dreg == ins->sreg2) { \
79 s390_lgr (code, s390_r13, ins->sreg2); \
83 if (ins->dreg != ins->sreg1) { \
84 s390_lgr (code, ins->dreg, ins->sreg1); \
87 #define CHECK_SRCDST_COM_I \
88 if (ins->dreg == ins->sreg2) { \
92 if (ins->dreg != ins->sreg1) { \
93 s390_lgfr (code, ins->dreg, ins->sreg1); \
97 #define CHECK_SRCDST_NCOM_I \
98 if (ins->dreg == ins->sreg2) { \
100 s390_lgfr (code, s390_r13, ins->sreg2); \
104 if (ins->dreg != ins->sreg1) { \
105 s390_lgfr (code, ins->dreg, ins->sreg1); \
108 #define CHECK_SRCDST_COM_F \
109 if (ins->dreg == ins->sreg2) { \
113 if (ins->dreg != ins->sreg1) { \
114 s390_ldr (code, ins->dreg, ins->sreg1); \
118 #define CHECK_SRCDST_NCOM_F \
119 if (ins->dreg == ins->sreg2) { \
121 s390_ldr (code, s390_r13, ins->sreg2); \
125 if (ins->dreg != ins->sreg1) { \
126 s390_ldr (code, ins->dreg, ins->sreg1); \
129 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
132 MONO_INST_NEW (cfg, inst, OP_NOP); \
135 inst->inst_offset = offset; \
137 inst->inst_imm = imm; \
139 if (s390_is_uimm12(offset)) { \
141 inst->inst_offset = offset; \
143 dReg = mono_alloc_preg (cfg); \
144 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
145 dReg, dest, offset); \
147 inst->inst_offset = 0; \
149 if (s390_is_uimm12(imm)) { \
151 inst->inst_imm = imm; \
153 sReg = mono_alloc_preg (cfg); \
154 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
156 inst->sreg1 = sReg; \
157 inst->inst_imm = 0; \
160 inst->opcode = OP_S390_MOVE; \
161 inst->backend.size = size; \
162 MONO_ADD_INS (cfg->cbb, inst); \
165 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
166 int reg = mono_alloc_preg (cfg); \
169 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
172 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
176 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
180 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
184 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
188 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
191 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
195 tmpr = mono_alloc_preg (cfg); \
196 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
197 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
201 tmpr = mono_alloc_preg (cfg); \
202 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
204 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
208 tmpr = mono_alloc_preg (cfg); \
209 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
211 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
215 tmpr = mono_alloc_preg (cfg); \
216 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
218 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
222 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
228 #define DEBUG(a) if (cfg->verbose_level > 1) a
232 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
234 #define BREAKPOINT_SIZE sizeof(breakpoint_t)
235 #define S390X_NOP_SIZE sizeof(I_Format)
237 #define MAX(a, b) ((a) > (b) ? (a) : (b))
240 * imt thunking size values
243 #define LOADCON_SIZE 20
247 #define ENABLE_WRONG_METHOD_CHECK 0
249 /*========================= End of Defines =========================*/
251 /*------------------------------------------------------------------*/
252 /* I n c l u d e s */
253 /*------------------------------------------------------------------*/
258 #include <mono/metadata/appdomain.h>
259 #include <mono/metadata/debug-helpers.h>
260 #include <mono/metadata/profiler-private.h>
261 #include <mono/utils/mono-math.h>
262 #include <mono/utils/mono-mmap.h>
264 #include "mini-s390x.h"
265 #include "cpu-s390x.h"
266 #include "jit-icalls.h"
270 /*========================= End of Includes ========================*/
272 /*------------------------------------------------------------------*/
273 /* T y p e d e f s */
274 /*------------------------------------------------------------------*/
286 /*------------------------------------------------------------------*/
287 /* Used by the instrument_emit_epilog */
288 /*------------------------------------------------------------------*/
299 typedef struct InstList InstList;
313 RegTypeStructByValInFP,
315 RegTypeStructByAddrOnStack
319 gint32 offset; /* offset from caller's stack */
320 gint32 offparm; /* offset from callee's stack */
321 guint16 vtsize; /* in param area */
324 guint32 size; /* Size of structure used by RegTypeStructByVal */
325 gint32 type; /* Data type of argument */
341 gint64 gr[5]; /* R2-R6 */
342 gdouble fp[3]; /* F0-F2 */
343 } __attribute__ ((packed)) RegParm;
351 } __attribute__ ((packed)) breakpoint_t;
353 /*========================= End of Typedefs ========================*/
355 /*------------------------------------------------------------------*/
356 /* P r o t o t y p e s */
357 /*------------------------------------------------------------------*/
359 static void indent (int);
360 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
361 static void decodeParm (MonoType *, void *, int);
362 static void enter_method (MonoMethod *, RegParm *, char *);
363 static void leave_method (MonoMethod *, ...);
364 static gboolean is_regsize_var (MonoType *);
365 static inline void add_general (guint *, size_data *, ArgInfo *);
366 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
367 static inline void add_float (guint *, size_data *, ArgInfo *);
368 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
369 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
370 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
371 static void catch_SIGILL(int, siginfo_t *, void *);
372 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
374 /*========================= End of Prototypes ======================*/
376 /*------------------------------------------------------------------*/
377 /* G l o b a l V a r i a b l e s */
378 /*------------------------------------------------------------------*/
380 int mono_exc_esp_offset = 0;
382 static int indent_level = 0;
386 static gint appdomain_tls_offset = -1,
388 lmf_addr_tls_offset = -1;
390 pthread_key_t lmf_addr_key;
392 gboolean lmf_addr_key_inited = FALSE;
398 extern __thread MonoDomain *tls_appdomain;
399 extern __thread MonoThread *tls_current_object;
400 extern __thread gpointer mono_lmf_addr;
405 * The code generated for sequence points reads from this location,
406 * which is made read-only when single stepping is enabled.
408 static gpointer ss_trigger_page;
411 * Enabled breakpoints read from this trigger page
413 static gpointer bp_trigger_page;
415 breakpoint_t breakpointCode;
417 /*====================== End of Global Variables ===================*/
419 /*------------------------------------------------------------------*/
421 /* Name - mono_arch_regname */
423 /* Function - Returns the name of the register specified by */
424 /* the input parameter. */
426 /*------------------------------------------------------------------*/
429 mono_arch_regname (int reg) {
430 static const char * rnames[] = {
431 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
432 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
433 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
437 if (reg >= 0 && reg < 16)
443 /*========================= End of Function ========================*/
445 /*------------------------------------------------------------------*/
447 /* Name - mono_arch_fregname */
449 /* Function - Returns the name of the register specified by */
450 /* the input parameter. */
452 /*------------------------------------------------------------------*/
455 mono_arch_fregname (int reg) {
456 static const char * rnames[] = {
457 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
458 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
459 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
463 if (reg >= 0 && reg < 16)
469 /*========================= End of Function ========================*/
471 /*------------------------------------------------------------------*/
473 /* Name - arch_get_argument_info */
475 /* Function - Gathers information on parameters such as size, */
476 /* alignment, and padding. arg_info should be large */
477 /* enough to hold param_count + 1 entries. */
479 /* Parameters - @csig - Method signature */
480 /* @param_count - No. of parameters to consider */
481 /* @arg_info - An array to store the result info */
483 /* Returns - Size of the activation frame */
485 /*------------------------------------------------------------------*/
488 mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig,
490 MonoJitArgumentInfo *arg_info)
492 int k, frame_size = 0;
493 int size, align, pad;
496 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
497 frame_size += sizeof (gpointer);
501 arg_info [0].offset = offset;
504 frame_size += sizeof (gpointer);
508 arg_info [0].size = frame_size;
510 for (k = 0; k < param_count; k++) {
513 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
515 size = mini_type_stack_size (NULL, csig->params [k], &align);
517 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
518 arg_info [k].pad = pad;
520 arg_info [k + 1].pad = 0;
521 arg_info [k + 1].size = size;
523 arg_info [k + 1].offset = offset;
527 align = MONO_ARCH_FRAME_ALIGNMENT;
528 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
529 arg_info [k].pad = pad;
534 /*========================= End of Function ========================*/
536 /*------------------------------------------------------------------*/
538 /* Name - emit_unwind_regs. */
540 /* Function - Determines if a value can be returned in one or */
543 /*------------------------------------------------------------------*/
545 static void __inline__
546 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
550 for (i = start; i < end; i++) {
551 mono_emit_unwind_op_offset (cfg, code, i, offset);
552 offset += sizeof(gulong);
556 /*========================= End of Function ========================*/
558 /*------------------------------------------------------------------*/
560 /* Name - retFitsInReg. */
562 /* Function - Determines if a value can be returned in one or */
565 /*------------------------------------------------------------------*/
567 static inline gboolean
568 retFitsInReg(guint32 size)
583 /*========================= End of Function ========================*/
585 /*------------------------------------------------------------------*/
587 /* Name - backStackPtr. */
589 /* Function - Restore Stack Pointer to previous frame. */
591 /*------------------------------------------------------------------*/
593 static inline guint8 *
594 backUpStackPtr(MonoCompile *cfg, guint8 *code)
596 int stackSize = cfg->stack_usage;
598 if (cfg->frame_reg != STK_BASE)
599 s390_lgr (code, STK_BASE, cfg->frame_reg);
601 if (s390_is_imm16 (stackSize)) {
602 s390_aghi (code, STK_BASE, stackSize);
604 while (stackSize > 32767) {
605 s390_aghi (code, STK_BASE, 32767);
608 s390_aghi (code, STK_BASE, stackSize);
613 /*========================= End of Function ========================*/
615 /*------------------------------------------------------------------*/
619 /* Function - Perform nice indenting to current level */
621 /*------------------------------------------------------------------*/
627 indent_level += diff;
634 indent_level += diff;
637 /*========================= End of Function ========================*/
639 /*------------------------------------------------------------------*/
641 /* Name - cvtMonoType */
643 /* Function - Convert a mono-type to a string. */
645 /*------------------------------------------------------------------*/
648 cvtMonoType(MonoTypeEnum t)
653 return "MONO_TYPE_END";
655 return "MONO_TYPE_VOID";
656 case MONO_TYPE_BOOLEAN:
657 return "MONO_TYPE_BOOLEAN";
659 return "MONO_TYPE_CHAR";
661 return "MONO_TYPE_I1";
663 return "MONO_TYPE_U1";
665 return "MONO_TYPE_I2";
667 return "MONO_TYPE_U2";
669 return "MONO_TYPE_I4";
671 return "MONO_TYPE_U4";
673 return "MONO_TYPE_I8";
675 return "MONO_TYPE_U8";
677 return "MONO_TYPE_R4";
679 return "MONO_TYPE_R8";
680 case MONO_TYPE_STRING:
681 return "MONO_TYPE_STRING";
683 return "MONO_TYPE_PTR";
684 case MONO_TYPE_BYREF:
685 return "MONO_TYPE_BYREF";
686 case MONO_TYPE_VALUETYPE:
687 return "MONO_TYPE_VALUETYPE";
688 case MONO_TYPE_CLASS:
689 return "MONO_TYPE_CLASS";
691 return "MONO_TYPE_VAR";
692 case MONO_TYPE_ARRAY:
693 return "MONO_TYPE_ARRAY";
694 case MONO_TYPE_GENERICINST:
695 return "MONO_TYPE_GENERICINST";
696 case MONO_TYPE_TYPEDBYREF:
697 return "MONO_TYPE_TYPEDBYREF";
699 return "MONO_TYPE_I";
701 return "MONO_TYPE_U";
702 case MONO_TYPE_FNPTR:
703 return "MONO_TYPE_FNPTR";
704 case MONO_TYPE_OBJECT:
705 return "MONO_TYPE_OBJECT";
706 case MONO_TYPE_SZARRAY:
707 return "MONO_TYPE_SZARRAY";
709 return "MONO_TYPE_MVAR";
710 case MONO_TYPE_CMOD_REQD:
711 return "MONO_TYPE_CMOD_REQD";
712 case MONO_TYPE_CMOD_OPT:
713 return "MONO_TYPE_CMOD_OPT";
714 case MONO_TYPE_INTERNAL:
715 return "MONO_TYPE_INTERNAL";
716 case MONO_TYPE_MODIFIER:
717 return "MONO_TYPE_MODIFIER";
718 case MONO_TYPE_SENTINEL:
719 return "MONO_TYPE_SENTINEL";
720 case MONO_TYPE_PINNED:
721 return "MONO_TYPE_PINNED";
728 /*========================= End of Function ========================*/
730 /*------------------------------------------------------------------*/
732 /* Name - decodeParm */
734 /* Function - Decode a parameter for the trace. */
736 /*------------------------------------------------------------------*/
739 decodeParm(MonoType *type, void *curParm, int size)
744 printf("[BYREF:%p], ", *((char **) curParm));
746 simpleType = mono_type_get_underlying_type(type)->type;
748 switch (simpleType) {
750 printf ("[INTPTR:%p], ", *((int **) curParm));
753 printf ("[UINTPTR:%p], ", *((int **) curParm));
755 case MONO_TYPE_BOOLEAN :
756 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
758 case MONO_TYPE_CHAR :
759 printf ("[CHAR:%c], ", *((int *) curParm));
762 printf ("[INT1:%ld], ", *((gint64 *) curParm));
765 printf ("[INT2:%ld], ", *((gint64 *) curParm));
768 printf ("[INT4:%ld], ", *((gint64 *) curParm));
771 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
774 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
777 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
780 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
782 case MONO_TYPE_STRING : {
783 MonoString *s = *((MonoString **) curParm);
785 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
786 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
788 printf("[STRING:null], ");
792 case MONO_TYPE_CLASS :
793 case MONO_TYPE_OBJECT : {
794 MonoObject *obj = *((MonoObject **) curParm);
796 if ((obj) && (obj->vtable)) {
797 printf("[CLASS/OBJ:");
798 class = obj->vtable->klass;
799 printf("%p [%p] ",obj,curParm);
800 if (class == mono_defaults.string_class) {
801 printf("[STRING:%p:%s]",
802 obj, mono_string_to_utf8 ((MonoString *) obj));
803 } else if (class == mono_defaults.int32_class) {
804 printf("[INT32:%p:%d]",
805 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
808 class->name_space, class->name, obj);
811 printf("[OBJECT:null], ");
816 printf("[PTR:%p], ", *((gpointer **) (curParm)));
818 case MONO_TYPE_FNPTR :
819 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
821 case MONO_TYPE_ARRAY :
822 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
824 case MONO_TYPE_SZARRAY :
825 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
828 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
831 printf("[FLOAT4:%g], ", *((float *) (curParm)));
834 printf("[FLOAT8:%g], ", *((double *) (curParm)));
836 case MONO_TYPE_VALUETYPE : {
838 MonoMarshalType *info;
840 if (type->data.klass->enumtype) {
841 simpleType = mono_class_enum_basetype (type->data.klass)->type;
842 printf("{VALUETYPE} - ");
846 info = mono_marshal_load_type_info (type->data.klass);
848 if ((info->native_size == sizeof(float)) &&
849 (info->num_fields == 1) &&
850 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
851 printf("[FLOAT4:%f], ", *((float *) (curParm)));
855 if ((info->native_size == sizeof(double)) &&
856 (info->num_fields == 1) &&
857 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
858 printf("[FLOAT8:%g], ", *((double *) (curParm)));
862 printf("[VALUETYPE:");
863 for (i = 0; i < size; i++)
864 printf("%02x,", *((guint8 *)curParm+i));
868 case MONO_TYPE_TYPEDBYREF: {
870 printf("[TYPEDBYREF:");
871 for (i = 0; i < size; i++)
872 printf("%02x,", *((guint8 *)curParm+i));
877 printf("[%s], ",cvtMonoType(simpleType));
882 /*========================= End of Function ========================*/
884 /*------------------------------------------------------------------*/
886 /* Name - enter_method */
888 /* Function - Perform tracing of the entry to the current */
891 /*------------------------------------------------------------------*/
894 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
896 int i, oParm = 0, iParm = 0;
899 MonoMethodSignature *sig;
906 fname = mono_method_full_name (method, TRUE);
908 printf ("ENTER: %s ", fname);
911 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
912 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
917 sig = mono_method_signature (method);
919 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
921 if (cinfo->struct_ret) {
922 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
927 gpointer *this = (gpointer *) rParm->gr[iParm];
928 obj = (MonoObject *) this;
929 switch(method->klass->this_arg.type) {
930 case MONO_TYPE_VALUETYPE:
932 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
933 printf("this:[value:%p:%016lx], ", this, *value);
935 printf ("this:[NULL], ");
937 case MONO_TYPE_STRING:
940 class = obj->vtable->klass;
941 if (class == mono_defaults.string_class) {
942 printf ("this:[STRING:%p:%s], ",
943 obj, mono_string_to_utf8 ((MonoString *)obj));
945 printf ("this:%p[%s.%s], ",
946 obj, class->name_space, class->name);
949 printf("vtable:[NULL], ");
951 printf ("this:[NULL], ");
954 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
959 for (i = 0; i < sig->param_count; ++i) {
960 ainfo = &cinfo->args[i + oParm];
961 switch (ainfo->regtype) {
962 case RegTypeGeneral :
963 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
966 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
969 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
971 case RegTypeStructByVal :
972 if (ainfo->reg != STK_BASE) {
973 int offset = sizeof(glong) - ainfo->size;
974 curParm = &(rParm->gr[ainfo->reg-2])+offset;
977 curParm = sp+ainfo->offset;
979 if (retFitsInReg (ainfo->vtsize))
980 decodeParm(sig->params[i],
984 decodeParm(sig->params[i],
985 *((char **) curParm),
988 case RegTypeStructByAddr :
989 if (ainfo->reg != STK_BASE)
990 curParm = &(rParm->gr[ainfo->reg-2]);
992 curParm = sp+ainfo->offset;
994 decodeParm(sig->params[i],
995 *((char **) curParm),
1007 /*========================= End of Function ========================*/
1009 /*------------------------------------------------------------------*/
1011 /* Name - leave_method */
1015 /*------------------------------------------------------------------*/
1018 leave_method (MonoMethod *method, ...)
1025 va_start(ap, method);
1027 fname = mono_method_full_name (method, TRUE);
1029 printf ("LEAVE: %s", fname);
1032 type = mono_method_signature (method)->ret;
1035 switch (type->type) {
1036 case MONO_TYPE_VOID:
1038 case MONO_TYPE_BOOLEAN: {
1039 int val = va_arg (ap, int);
1041 printf ("[TRUE:%d]", val);
1047 case MONO_TYPE_CHAR: {
1048 int val = va_arg (ap, int);
1049 printf ("[CHAR:%d]", val);
1052 case MONO_TYPE_I1: {
1053 int val = va_arg (ap, int);
1054 printf ("[INT1:%d]", val);
1057 case MONO_TYPE_U1: {
1058 int val = va_arg (ap, int);
1059 printf ("[UINT1:%d]", val);
1062 case MONO_TYPE_I2: {
1063 int val = va_arg (ap, int);
1064 printf ("[INT2:%d]", val);
1067 case MONO_TYPE_U2: {
1068 int val = va_arg (ap, int);
1069 printf ("[UINT2:%d]", val);
1072 case MONO_TYPE_I4: {
1073 int val = va_arg (ap, int);
1074 printf ("[INT4:%d]", val);
1077 case MONO_TYPE_U4: {
1078 int val = va_arg (ap, int);
1079 printf ("[UINT4:%d]", val);
1083 gint64 val = va_arg (ap, gint64);
1084 printf ("[INT:%ld]", val);
1089 gint64 val = va_arg (ap, gint64);
1090 printf ("[UINT:%lu]", val);
1094 case MONO_TYPE_STRING: {
1095 MonoString *s = va_arg (ap, MonoString *);
1098 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1099 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1101 printf ("[STRING:null], ");
1104 case MONO_TYPE_CLASS:
1105 case MONO_TYPE_OBJECT: {
1106 MonoObject *o = va_arg (ap, MonoObject *);
1108 if ((o) && (o->vtable)) {
1109 if (o->vtable->klass == mono_defaults.boolean_class) {
1110 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1111 } else if (o->vtable->klass == mono_defaults.int32_class) {
1112 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1113 } else if (o->vtable->klass == mono_defaults.int64_class) {
1114 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1116 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1118 printf ("[OBJECT:%p]", o);
1123 case MONO_TYPE_FNPTR:
1124 case MONO_TYPE_ARRAY:
1125 case MONO_TYPE_SZARRAY: {
1126 gpointer p = va_arg (ap, gpointer);
1127 printf ("[result=%p]", p);
1130 case MONO_TYPE_I8: {
1131 gint64 l = va_arg (ap, gint64);
1132 printf ("[LONG:%ld]", l);
1135 case MONO_TYPE_U8: {
1136 guint64 l = va_arg (ap, guint64);
1137 printf ("[ULONG:%lu]", l);
1140 case MONO_TYPE_R4: {
1141 double f = va_arg (ap, double);
1142 printf ("[FLOAT4:%g]\n", f);
1145 case MONO_TYPE_R8: {
1146 double f = va_arg (ap, double);
1147 printf ("[FLOAT8:%g]\n", f);
1150 case MONO_TYPE_VALUETYPE: {
1151 MonoMarshalType *info;
1152 if (type->data.klass->enumtype) {
1153 type = mono_class_enum_basetype (type->data.klass);
1158 info = mono_marshal_load_type_info (type->data.klass);
1160 if ((info->native_size == sizeof(float)) &&
1161 (info->num_fields == 1) &&
1162 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1163 double f = va_arg (ap, double);
1164 printf("[FLOAT4:%g]\n", (double) f);
1168 if ((info->native_size == sizeof(double)) &&
1169 (info->num_fields == 1) &&
1170 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1171 double f = va_arg (ap, double);
1172 printf("[FLOAT8:%g]\n", f);
1176 size = mono_type_size (type, &align);
1179 guint32 p = va_arg (ap, guint32);
1180 printf ("[%02x]\n",p);
1184 guint32 p = va_arg (ap, guint32);
1185 printf ("[%04x]\n",p);
1189 guint32 p = va_arg (ap, guint32);
1190 printf ("[%08x]\n",p);
1194 guint64 p = va_arg (ap, guint64);
1195 printf ("[%016lx]\n",p);
1199 gpointer p = va_arg (ap, gpointer);
1200 printf ("[VALUETYPE] %p\n",p);
1206 case MONO_TYPE_TYPEDBYREF: {
1207 guint8 *p = va_arg (ap, gpointer);
1209 size = mono_type_size (type, &align);
1216 for (j = 0; p && j < size; j++)
1217 printf ("%02x,", p [j]);
1221 printf ("[TYPEDBYREF]\n");
1226 printf ("(unknown return type %x)",
1227 mono_method_signature (method)->ret->type);
1230 ip = ((gint64) __builtin_return_address (0));
1231 printf (" ip: %p\n", (gpointer) ip);
1234 /*========================= End of Function ========================*/
1236 /*------------------------------------------------------------------*/
1238 /* Name - catch_SIGILL */
1240 /* Function - Catch SIGILL as a result of testing for long */
1241 /* displacement facility. */
1243 /*------------------------------------------------------------------*/
1246 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1252 /*========================= End of Function ========================*/
1254 /*------------------------------------------------------------------*/
1256 /* Name - mono_arch_cpu_init */
1258 /* Function - Perform CPU specific initialization to execute */
1261 /*------------------------------------------------------------------*/
1264 mono_arch_cpu_init (void)
1266 struct sigaction sa,
1270 /*--------------------------------------*/
1271 /* Set default rounding mode for FP */
1272 /*--------------------------------------*/
1273 __asm__ ("SRNM\t%0\n\t"
1276 /*--------------------------------------*/
1277 /* Determine if we have long displace- */
1278 /* ment facility on this processor */
1279 /*--------------------------------------*/
1280 sa.sa_sigaction = catch_SIGILL;
1281 sigemptyset (&sa.sa_mask);
1282 sa.sa_flags = SA_SIGINFO;
1284 sigaction (SIGILL, &sa, oldSa);
1286 /*--------------------------------------*/
1287 /* We test by executing the STY inst */
1288 /*--------------------------------------*/
1289 __asm__ ("LGHI\t0,1\n\t"
1291 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1292 : "=m" (has_ld) : : "0", "1");
1294 sigaction (SIGILL, oldSa, NULL);
1297 /*========================= End of Function ========================*/
1299 /*------------------------------------------------------------------*/
1301 /* Name - mono_arch_init. */
1303 /* Function - Initialize architecture specific code. */
1305 /*------------------------------------------------------------------*/
1308 mono_arch_init (void)
1314 * When we do an architectural level set at z9 or better
1315 * we can use the STFLE instruction to show us
1316 * what hardware facilities are available
1318 int lFacility = sizeof(facs) % 8;
1320 memset((char *) &facs, 0, sizeof(facs));
1322 __asm__ (" lgfr 0,%1\n"
1324 : "=m" (facs) : "r" (lFacility) : "0", "cc");
1327 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1328 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1329 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1331 code = (guint8 *) &breakpointCode;
1332 s390_basr(code, s390_r13, 0);
1334 s390_llong(code, 0);
1335 s390_lg(code, s390_r13, 0, s390_r13, 4);
1336 s390_lg(code, s390_r0, 0, s390_r13, 0);
1339 /*========================= End of Function ========================*/
1341 /*------------------------------------------------------------------*/
1343 /* Name - mono_arch_cleanup. */
1345 /* Function - Cleanup architecture specific code . */
1347 /*------------------------------------------------------------------*/
1350 mono_arch_cleanup (void)
1354 /*========================= End of Function ========================*/
1356 /*------------------------------------------------------------------*/
1358 /* Name - mono_arch_cpu_optimizations */
1360 /* Function - Returns the optimizations supported on this CPU */
1362 /*------------------------------------------------------------------*/
1365 mono_arch_cpu_optimizations (guint32 *exclude_mask)
1369 /*----------------------------------------------------------*/
1370 /* No s390-specific optimizations yet */
1371 /*----------------------------------------------------------*/
1372 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1373 // *exclude_mask = MONO_OPT_INLINE;
1377 /*========================= End of Function ========================*/
1379 /*------------------------------------------------------------------*/
1381 /* Name - mono_arch_cpu_enumerate_simd_versions */
1383 /* Function - Returns the SIMD instruction sets on this CPU */
1385 /*------------------------------------------------------------------*/
1387 mono_arch_cpu_enumerate_simd_versions (void)
1389 /* SIMD is currently unimplemented */
1392 /*========================= End of Function ========================*/
1394 /*------------------------------------------------------------------*/
1400 /*------------------------------------------------------------------*/
1403 is_regsize_var (MonoType *t) {
1406 switch (mono_type_get_underlying_type (t)->type) {
1414 case MONO_TYPE_FNPTR:
1416 case MONO_TYPE_OBJECT:
1417 case MONO_TYPE_STRING:
1418 case MONO_TYPE_CLASS:
1419 case MONO_TYPE_SZARRAY:
1420 case MONO_TYPE_ARRAY:
1422 case MONO_TYPE_VALUETYPE:
1423 if (t->data.klass->enumtype)
1424 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1430 /*========================= End of Function ========================*/
1432 /*------------------------------------------------------------------*/
1434 /* Name - mono_arch_get_allocatable_int_vars */
1438 /*------------------------------------------------------------------*/
1441 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1446 for (i = 0; i < cfg->num_varinfo; i++) {
1447 MonoInst *ins = cfg->varinfo [i];
1448 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1451 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1454 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1455 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1458 /* we can only allocate 32 bit values */
1459 if (is_regsize_var (ins->inst_vtype)) {
1460 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1461 g_assert (i == vmv->idx);
1462 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1469 /*========================= End of Function ========================*/
1471 /*------------------------------------------------------------------*/
1473 /* Name - mono_arch_global_int_regs */
1475 /* Function - Return a list of usable integer registers. */
1477 /*------------------------------------------------------------------*/
1480 mono_arch_get_global_int_regs (MonoCompile *cfg)
1483 MonoMethodHeader *header;
1486 header = cfg->header;
1487 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1488 cfg->frame_reg = s390_r11;
1491 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1493 for (i = 8; i < top; ++i) {
1494 if (cfg->frame_reg != i)
1495 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1501 /*========================= End of Function ========================*/
1503 /*------------------------------------------------------------------*/
1505 /* Name - mono_arch_flush_icache */
1507 /* Function - Flush the CPU icache. */
1509 /*------------------------------------------------------------------*/
1512 mono_arch_flush_icache (guint8 *code, gint size)
1516 /*========================= End of Function ========================*/
1518 /*------------------------------------------------------------------*/
1520 /* Name - add_general */
1522 /* Function - Determine code and stack size incremements for a */
1525 /*------------------------------------------------------------------*/
1528 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1530 if (*gr > S390_LAST_ARG_REG) {
1531 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1532 ainfo->offset = sz->stack_size;
1533 ainfo->reg = STK_BASE;
1534 ainfo->regtype = RegTypeBase;
1535 sz->stack_size += sizeof(long);
1536 sz->local_size += sizeof(long);
1537 sz->offStruct += sizeof(long);
1538 sz->code_size += 12;
1546 /*========================= End of Function ========================*/
1548 /*------------------------------------------------------------------*/
1550 /* Name - add_stackParm */
1552 /* Function - Determine code and stack size incremements for a */
1555 /*------------------------------------------------------------------*/
1558 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1560 if (*gr > S390_LAST_ARG_REG) {
1561 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1562 ainfo->reg = STK_BASE;
1563 ainfo->offset = sz->stack_size;
1564 ainfo->regtype = RegTypeStructByAddrOnStack;
1565 sz->stack_size += sizeof (gpointer);
1566 sz->parm_size += sizeof(gpointer);
1567 sz->offStruct += sizeof(gpointer);
1570 ainfo->offset = sz->stack_size;
1571 ainfo->regtype = RegTypeStructByAddr;
1574 ainfo->offparm = sz->offset;
1575 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1577 ainfo->vtsize = size;
1578 sz->parm_size += size;
1581 /*========================= End of Function ========================*/
1583 /*------------------------------------------------------------------*/
1585 /* Name - add_float */
1587 /* Function - Determine code and stack size incremements for a */
1588 /* float parameter. */
1590 /*------------------------------------------------------------------*/
1593 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1595 if ((*fr) <= S390_LAST_FPARG_REG) {
1596 ainfo->regtype = RegTypeFP;
1602 ainfo->offset = sz->stack_size;
1603 ainfo->reg = STK_BASE;
1604 ainfo->regtype = RegTypeBase;
1606 sz->stack_size += sizeof(double);
1607 sz->local_size += sizeof(double);
1608 sz->offStruct += sizeof(double);
1612 /*========================= End of Function ========================*/
1614 /*------------------------------------------------------------------*/
1616 /* Name - get_call_info */
1618 /* Function - Determine the amount of space required for code */
1619 /* and stack. In addition determine starting points */
1620 /* for stack-based parameters, and area for struct- */
1621 /* ures being returned on the stack. */
1623 /*------------------------------------------------------------------*/
1626 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1628 guint i, fr, gr, size, pstart;
1629 int nParm = sig->hasthis + sig->param_count;
1631 guint32 simpletype, align;
1634 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1637 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1639 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1644 cinfo->struct_ret = 0;
1648 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1649 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1656 /*----------------------------------------------------------*/
1657 /* We determine the size of the return code/stack in case we*/
1658 /* need to reserve a register to be used to address a stack */
1659 /* area that the callee will use. */
1660 /*----------------------------------------------------------*/
1662 ret_type = mono_type_get_underlying_type (sig->ret);
1663 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1664 simpletype = ret_type->type;
1666 switch (simpletype) {
1667 case MONO_TYPE_BOOLEAN:
1672 case MONO_TYPE_CHAR:
1677 case MONO_TYPE_CLASS:
1678 case MONO_TYPE_OBJECT:
1679 case MONO_TYPE_SZARRAY:
1680 case MONO_TYPE_ARRAY:
1682 case MONO_TYPE_FNPTR:
1683 case MONO_TYPE_STRING:
1684 cinfo->ret.reg = s390_r2;
1689 cinfo->ret.reg = s390_f0;
1694 cinfo->ret.reg = s390_r2;
1697 case MONO_TYPE_GENERICINST:
1698 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1699 cinfo->ret.reg = s390_r2;
1704 case MONO_TYPE_VALUETYPE: {
1705 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1706 if (klass->enumtype) {
1707 simpletype = mono_class_enum_basetype (klass)->type;
1711 size = mono_class_native_size (klass, &align);
1713 size = mono_class_value_size (klass, &align);
1715 cinfo->struct_ret = 1;
1716 cinfo->ret.size = size;
1717 cinfo->ret.vtsize = size;
1720 case MONO_TYPE_TYPEDBYREF:
1721 size = sizeof (MonoTypedRef);
1722 cinfo->struct_ret = 1;
1723 cinfo->ret.size = size;
1724 cinfo->ret.vtsize = size;
1726 case MONO_TYPE_VOID:
1729 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1735 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1736 * the first argument, allowing 'this' to be always passed in the first arg reg.
1737 * Also do this if the first argument is a reference type, since virtual calls
1738 * are sometimes made using calli without sig->hasthis set, like in the delegate
1741 if (cinfo->struct_ret && !is_pinvoke &&
1743 (sig->param_count > 0 &&
1744 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1746 cinfo->args[nParm].size = sizeof (gpointer);
1747 add_general (&gr, sz, cinfo->args + nParm);
1749 cinfo->args[nParm].size = sizeof (gpointer);
1750 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1754 cinfo->vret_arg_index = 1;
1755 cinfo->ret.reg = gr;
1760 cinfo->args[nParm].size = sizeof (gpointer);
1761 add_general (&gr, sz, cinfo->args + nParm);
1765 if (cinfo->struct_ret) {
1766 cinfo->ret.reg = gr;
1771 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1772 gr = S390_LAST_ARG_REG + 1;
1773 fr = S390_LAST_FPARG_REG + 1;
1775 /* Emit the signature cookie just before the implicit arguments */
1776 add_general (&gr, sz, &cinfo->sigCookie);
1779 /*----------------------------------------------------------*/
1780 /* We determine the size of the parameter code and stack */
1781 /* requirements by checking the types and sizes of the */
1783 /*----------------------------------------------------------*/
1785 for (i = pstart; i < sig->param_count; ++i) {
1788 /*--------------------------------------------------*/
1789 /* Handle vararg type calls. All args are put on */
1791 /*--------------------------------------------------*/
1792 if ((sig->call_convention == MONO_CALL_VARARG) &&
1793 (i == sig->sentinelpos)) {
1794 gr = S390_LAST_ARG_REG + 1;
1795 fr = S390_LAST_FPARG_REG + 1;
1796 add_general (&gr, sz, &cinfo->sigCookie);
1799 if (sig->params [i]->byref) {
1800 add_general (&gr, sz, cinfo->args+nParm);
1801 cinfo->args[nParm].size = sizeof(gpointer);
1806 ptype = mono_type_get_underlying_type (sig->params [i]);
1807 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1808 simpletype = ptype->type;
1809 cinfo->args[nParm].type = simpletype;
1810 switch (simpletype) {
1811 case MONO_TYPE_BOOLEAN:
1814 cinfo->args[nParm].size = sizeof(char);
1815 add_general (&gr, sz, cinfo->args+nParm);
1820 case MONO_TYPE_CHAR:
1821 cinfo->args[nParm].size = sizeof(short);
1822 add_general (&gr, sz, cinfo->args+nParm);
1827 cinfo->args[nParm].size = sizeof(int);
1828 add_general (&gr, sz, cinfo->args+nParm);
1834 case MONO_TYPE_FNPTR:
1835 case MONO_TYPE_CLASS:
1836 case MONO_TYPE_OBJECT:
1837 case MONO_TYPE_STRING:
1838 case MONO_TYPE_SZARRAY:
1839 case MONO_TYPE_ARRAY:
1840 cinfo->args[nParm].size = sizeof(gpointer);
1841 add_general (&gr, sz, cinfo->args+nParm);
1846 cinfo->args[nParm].size = sizeof(long long);
1847 add_general (&gr, sz, cinfo->args+nParm);
1851 cinfo->args[nParm].size = sizeof(float);
1852 add_float (&fr, sz, cinfo->args+nParm);
1856 cinfo->args[nParm].size = sizeof(double);
1857 add_float (&fr, sz, cinfo->args+nParm);
1860 case MONO_TYPE_GENERICINST:
1861 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1862 cinfo->args[nParm].size = sizeof(gpointer);
1863 add_general (&gr, sz, cinfo->args+nParm);
1868 case MONO_TYPE_VALUETYPE: {
1869 MonoMarshalType *info;
1870 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1872 size = mono_class_native_size (klass, &align);
1874 size = mono_class_value_size (klass, &align);
1876 info = mono_marshal_load_type_info (klass);
1878 if ((info->native_size == sizeof(float)) &&
1879 (info->num_fields == 1) &&
1880 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1881 cinfo->args[nParm].size = sizeof(float);
1882 add_float(&fr, sz, cinfo->args+nParm);
1887 if ((info->native_size == sizeof(double)) &&
1888 (info->num_fields == 1) &&
1889 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1890 cinfo->args[nParm].size = sizeof(double);
1891 add_float(&fr, sz, cinfo->args+nParm);
1896 cinfo->args[nParm].vtsize = 0;
1897 cinfo->args[nParm].size = 0;
1900 /*----------------------------------*/
1901 /* On S/390, structures of size 1, */
1902 /* 2, 4, and 8 bytes are passed in */
1903 /* (a) register(s). */
1904 /*----------------------------------*/
1910 add_general(&gr, sz, cinfo->args+nParm);
1911 cinfo->args[nParm].size = size;
1912 cinfo->args[nParm].regtype = RegTypeStructByVal;
1914 sz->local_size += sizeof(long);
1917 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1922 case MONO_TYPE_TYPEDBYREF: {
1923 int size = sizeof (MonoTypedRef);
1925 cinfo->args[nParm].vtsize = 0;
1926 cinfo->args[nParm].size = 0;
1929 /*----------------------------------*/
1930 /* On S/390, structures of size 1, */
1931 /* 2, 4, and 8 bytes are passed in */
1932 /* (a) register(s). */
1933 /*----------------------------------*/
1939 add_general(&gr, sz, cinfo->args+nParm);
1940 cinfo->args[nParm].size = size;
1941 cinfo->args[nParm].regtype = RegTypeStructByVal;
1943 sz->local_size += sizeof(long);
1946 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1952 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1956 /*----------------------------------------------------------*/
1957 /* Handle the case where there are no implicit arguments */
1958 /*----------------------------------------------------------*/
1959 if ((sig->call_convention == MONO_CALL_VARARG) &&
1962 (sig->param_count == sig->sentinelpos)) {
1963 gr = S390_LAST_ARG_REG + 1;
1964 fr = S390_LAST_FPARG_REG + 1;
1965 add_general (&gr, sz, &cinfo->sigCookie);
1968 /*----------------------------------------------------------*/
1969 /* If we are passing a structure back then if it won't be */
1970 /* in a register(s) then we make room at the end of the */
1971 /* parameters that may have been placed on the stack */
1972 /*----------------------------------------------------------*/
1973 if (cinfo->struct_ret) {
1974 cinfo->ret.offset = sz->stack_size;
1975 switch (cinfo->ret.size) {
1983 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1988 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1990 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1995 /*========================= End of Function ========================*/
1997 /*------------------------------------------------------------------*/
1999 /* Name - mono_arch_allocate_vars */
2001 /* Function - Set var information according to the calling */
2002 /* convention for S/390. The local var stuff should */
2003 /* most likely be split in another method. */
2005 /* Parameter - @m - Compile unit. */
2007 /*------------------------------------------------------------------*/
2010 mono_arch_allocate_vars (MonoCompile *cfg)
2012 MonoMethodSignature *sig;
2013 MonoMethodHeader *header;
2016 int iParm, iVar, offset, align, size, curinst;
2017 int frame_reg = STK_BASE;
2020 header = cfg->header;
2022 cfg->flags |= MONO_CFG_HAS_SPILLUP;
2024 /*---------------------------------------------------------*/
2025 /* We use the frame register also for any method that has */
2026 /* filter clauses. This way, when the handlers are called, */
2027 /* the code will reference local variables using the frame */
2028 /* reg instead of the stack pointer: if we had to restore */
2029 /* the stack pointer, we'd corrupt the method frames that */
2030 /* are already on the stack (since filters get called */
2031 /* before stack unwinding happens) when the filter code */
2032 /* would call any method. */
2033 /*---------------------------------------------------------*/
2034 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2035 frame_reg = s390_r11;
2037 cfg->frame_reg = frame_reg;
2039 cfg->arch.bkchain_reg = -1;
2041 if (frame_reg != STK_BASE)
2042 cfg->used_int_regs |= 1 << frame_reg;
2044 sig = mono_method_signature (cfg->method);
2046 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2048 if (!cinfo->struct_ret) {
2049 switch (mono_type_get_underlying_type (sig->ret)->type) {
2050 case MONO_TYPE_VOID:
2053 cfg->ret->opcode = OP_REGVAR;
2054 cfg->ret->dreg = s390_r2;
2059 /*--------------------------------------------------------------*/
2060 /* local vars are at a positive offset from the stack pointer */
2061 /* also note that if the function uses alloca, we use s390_r11 */
2062 /* to point at the local variables. */
2063 /* add parameter area size for called functions */
2064 /*--------------------------------------------------------------*/
2065 if (cfg->param_area == 0)
2066 offset = S390_MINIMAL_STACK_SIZE;
2068 offset = cfg->param_area;
2070 cfg->sig_cookie = 0;
2072 if (cinfo->struct_ret) {
2073 inst = cfg->vret_addr;
2074 offset = S390_ALIGN(offset, sizeof(gpointer));
2075 inst->inst_offset = offset;
2076 inst->opcode = OP_REGOFFSET;
2077 inst->inst_basereg = frame_reg;
2078 offset += sizeof(gpointer);
2079 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2080 printf ("vret_addr =");
2081 mono_print_ins (cfg->vret_addr);
2086 inst = cfg->args [0];
2087 if (inst->opcode != OP_REGVAR) {
2088 inst->opcode = OP_REGOFFSET;
2089 inst->inst_basereg = frame_reg;
2090 offset = S390_ALIGN(offset, sizeof(gpointer));
2091 inst->inst_offset = offset;
2092 offset += sizeof (gpointer);
2099 eArg = sig->param_count + sArg;
2101 if (sig->call_convention == MONO_CALL_VARARG)
2102 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2104 for (iParm = sArg; iParm < eArg; ++iParm) {
2105 inst = cfg->args [curinst];
2106 if (inst->opcode != OP_REGVAR) {
2107 switch (cinfo->args[iParm].regtype) {
2108 case RegTypeStructByAddr : {
2111 size = sizeof (gpointer);
2113 inst->opcode = OP_REGOFFSET;
2114 inst->inst_basereg = frame_reg;
2115 offset = S390_ALIGN (offset, sizeof (gpointer));
2116 inst->inst_offset = offset;
2118 /* Add a level of indirection */
2119 MONO_INST_NEW (cfg, indir, 0);
2121 inst->opcode = OP_VTARG_ADDR;
2122 inst->inst_left = indir;
2125 case RegTypeStructByAddrOnStack : {
2128 size = sizeof (gpointer);
2130 /* Similar to the == STK_BASE case below */
2131 cfg->arch.bkchain_reg = s390_r12;
2132 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2134 inst->opcode = OP_REGOFFSET;
2135 inst->dreg = mono_alloc_preg (cfg);
2136 inst->inst_basereg = cfg->arch.bkchain_reg;
2137 inst->inst_offset = cinfo->args [iParm].offset;
2139 /* Add a level of indirection */
2140 MONO_INST_NEW (cfg, indir, 0);
2142 inst->opcode = OP_VTARG_ADDR;
2143 inst->inst_left = indir;
2146 case RegTypeStructByVal :
2147 size = cinfo->args[iParm].size;
2148 offset = S390_ALIGN(offset, size);
2149 inst->opcode = OP_REGOFFSET;
2150 inst->inst_basereg = frame_reg;
2151 inst->inst_offset = offset;
2154 if (cinfo->args [iParm].reg == STK_BASE) {
2156 * These arguments are in the previous frame, so we can't
2157 * compute their offset from the current frame pointer right
2158 * now, since cfg->stack_offset is not yet known, so dedicate a
2159 * register holding the previous frame pointer.
2161 cfg->arch.bkchain_reg = s390_r12;
2162 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2164 inst->opcode = OP_REGOFFSET;
2165 inst->inst_basereg = cfg->arch.bkchain_reg;
2166 size = (cinfo->args[iParm].size < 8
2167 ? 8 - cinfo->args[iParm].size
2169 inst->inst_offset = cinfo->args [iParm].offset + size;
2170 size = sizeof (long);
2172 inst->opcode = OP_REGOFFSET;
2173 inst->inst_basereg = frame_reg;
2174 size = (cinfo->args[iParm].size < 8
2177 offset = S390_ALIGN(offset, size);
2178 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2179 inst->inst_offset = offset;
2181 inst->inst_offset = offset + (8 - size);
2186 if ((sig->call_convention == MONO_CALL_VARARG) &&
2187 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2188 (iParm < sig->sentinelpos))
2189 cfg->sig_cookie += size;
2190 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2193 offset += MAX(size, 8);
2198 cfg->locals_min_stack_offset = offset;
2200 curinst = cfg->locals_start;
2201 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2202 inst = cfg->varinfo [iVar];
2203 if ((inst->flags & MONO_INST_IS_DEAD) ||
2204 (inst->opcode == OP_REGVAR))
2207 /*--------------------------------------------------*/
2208 /* inst->backend.is_pinvoke indicates native sized */
2209 /* value typs this is used by the pinvoke wrappers */
2210 /* when they call functions returning structure */
2211 /*--------------------------------------------------*/
2212 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2213 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2214 (guint32 *) &align);
2216 size = mono_type_size (inst->inst_vtype, &align);
2218 offset = S390_ALIGN(offset, align);
2219 inst->inst_offset = offset;
2220 inst->opcode = OP_REGOFFSET;
2221 inst->inst_basereg = frame_reg;
2223 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2224 iVar, inst->inst_offset, size));
2227 cfg->locals_max_stack_offset = offset;
2229 /*------------------------------------------------------*/
2230 /* Allow space for the trace method stack area if needed*/
2231 /*------------------------------------------------------*/
2232 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2233 offset += S390_TRACE_STACK_SIZE;
2235 /*------------------------------------------------------*/
2236 /* Reserve space to save LMF and caller saved registers */
2237 /*------------------------------------------------------*/
2238 if (cfg->method->save_lmf)
2239 offset += sizeof (MonoLMF);
2241 /*------------------------------------------------------*/
2242 /* align the offset */
2243 /*------------------------------------------------------*/
2244 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2246 /*------------------------------------------------------*/
2247 /* Fix offsets for args whose value is in parent frame */
2248 /*------------------------------------------------------*/
2249 for (iParm = sArg; iParm < eArg; ++iParm) {
2250 inst = cfg->args [iParm];
2252 if (inst->opcode == OP_S390_STKARG) {
2253 inst->opcode = OP_REGOFFSET;
2254 inst->inst_offset += cfg->stack_offset;
2259 /*========================= End of Function ========================*/
2261 /*------------------------------------------------------------------*/
2263 /* Name - mono_arch_create_vars */
2265 /*------------------------------------------------------------------*/
2268 mono_arch_create_vars (MonoCompile *cfg)
2270 MonoMethodSignature *sig;
2273 sig = mono_method_signature (cfg->method);
2275 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2277 if (cinfo->struct_ret) {
2278 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2279 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2280 printf ("vret_addr = ");
2281 mono_print_ins (cfg->vret_addr);
2286 /*========================= End of Function ========================*/
2288 /*------------------------------------------------------------------*/
2290 /* Name - add_outarg_reg2. */
2292 /*------------------------------------------------------------------*/
2295 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2300 case RegTypeGeneral:
2301 MONO_INST_NEW (cfg, ins, OP_MOVE);
2302 ins->dreg = mono_alloc_ireg (cfg);
2303 ins->sreg1 = tree->dreg;
2304 MONO_ADD_INS (cfg->cbb, ins);
2305 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2308 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2309 ins->dreg = mono_alloc_freg (cfg);
2310 ins->sreg1 = tree->dreg;
2311 MONO_ADD_INS (cfg->cbb, ins);
2312 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2315 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2316 ins->dreg = mono_alloc_freg (cfg);
2317 ins->sreg1 = tree->dreg;
2318 MONO_ADD_INS (cfg->cbb, ins);
2319 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2322 g_assert_not_reached ();
2326 /*========================= End of Function ========================*/
2328 /*------------------------------------------------------------------*/
2330 /* Name - emit_sig_cookie. */
2332 /*------------------------------------------------------------------*/
2335 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2337 MonoMethodSignature *tmpSig;
2340 cfg->disable_aot = TRUE;
2342 /*----------------------------------------------------------*/
2343 /* mono_ArgIterator_Setup assumes the signature cookie is */
2344 /* passed first and all the arguments which were before it */
2345 /* passed on the stack after the signature. So compensate */
2346 /* by passing a different signature. */
2347 /*----------------------------------------------------------*/
2348 tmpSig = mono_metadata_signature_dup (call->signature);
2349 tmpSig->param_count -= call->signature->sentinelpos;
2350 tmpSig->sentinelpos = 0;
2351 if (tmpSig->param_count > 0)
2352 memcpy (tmpSig->params,
2353 call->signature->params + call->signature->sentinelpos,
2354 tmpSig->param_count * sizeof(MonoType *));
2356 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2357 sig_arg->dreg = mono_alloc_ireg (cfg);
2358 sig_arg->inst_p0 = tmpSig;
2359 MONO_ADD_INS (cfg->cbb, sig_arg);
2361 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2362 cinfo->sigCookie.offset, sig_arg->dreg);
2365 /*========================= End of Function ========================*/
2367 /*------------------------------------------------------------------*/
2369 /* Name - mono_arch_emit_call */
2371 /*------------------------------------------------------------------*/
2374 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2377 MonoMethodSignature *sig;
2379 int i, n, lParamArea;
2381 ArgInfo *ainfo = NULL;
2383 MonoMethodHeader *header;
2386 sig = call->signature;
2387 n = sig->param_count + sig->hasthis;
2388 DEBUG (g_print ("Call requires: %d parameters\n",n));
2390 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2392 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2393 cinfo->sz.parm_size + cinfo->sz.offset;
2394 call->stack_usage = MAX(stackSize, call->stack_usage);
2395 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2396 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2397 cfg->flags |= MONO_CFG_HAS_CALLS;
2399 if (cinfo->struct_ret) {
2400 MONO_INST_NEW (cfg, ins, OP_MOVE);
2401 ins->sreg1 = call->vret_var->dreg;
2402 ins->dreg = mono_alloc_preg (cfg);
2403 MONO_ADD_INS (cfg->cbb, ins);
2404 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2407 header = cfg->header;
2408 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2413 for (i = 0; i < n; ++i) {
2416 ainfo = cinfo->args + i;
2417 if (i >= sig->hasthis)
2418 t = sig->params [i - sig->hasthis];
2420 t = &mono_defaults.int_class->byval_arg;
2421 t = mono_type_get_underlying_type (t);
2423 in = call->args [i];
2425 if ((sig->call_convention == MONO_CALL_VARARG) &&
2427 (i == sig->sentinelpos)) {
2428 emit_sig_cookie (cfg, call, cinfo);
2431 switch (ainfo->regtype) {
2432 case RegTypeGeneral:
2433 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2436 if (MONO_TYPE_ISSTRUCT (t)) {
2437 /* Valuetype passed in one fp register */
2438 ainfo->regtype = RegTypeStructByValInFP;
2441 if (ainfo->size == 4)
2442 ainfo->regtype = RegTypeFPR4;
2443 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2446 case RegTypeStructByVal:
2447 case RegTypeStructByAddr:
2448 case RegTypeStructByAddrOnStack: {
2452 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2453 size = sizeof (MonoTypedRef);
2454 align = sizeof (gpointer);
2458 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2461 * Other backends use mono_type_stack_size (), but that
2462 * aligns the size to 8, which is larger than the size of
2463 * the source, leading to reads of invalid memory if the
2464 * source is at the end of address space.
2466 size = mono_class_value_size (in->klass, &align);
2469 g_assert (in->klass);
2471 ainfo->offparm += cinfo->sz.offStruct;
2473 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2474 ins->sreg1 = in->dreg;
2475 ins->klass = in->klass;
2476 ins->backend.size = ainfo->size;
2477 ins->inst_p0 = call;
2478 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2479 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2481 MONO_ADD_INS (cfg->cbb, ins);
2483 if (ainfo->regtype == RegTypeStructByAddr) {
2485 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2486 * use the normal OUTARG opcodes to pass the address of the location to
2489 int treg = mono_alloc_preg (cfg);
2490 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2491 frmReg, ainfo->offparm);
2492 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2493 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2494 /* The address of the valuetype is passed on the stack */
2495 int treg = mono_alloc_preg (cfg);
2496 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2497 frmReg, ainfo->offparm);
2498 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2499 ainfo->reg, ainfo->offset, treg);
2501 if (cfg->compute_gc_maps) {
2504 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2510 if (!t->byref && t->type == MONO_TYPE_R4) {
2511 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2512 STK_BASE, ainfo->offset + 4,
2514 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2515 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2516 STK_BASE, ainfo->offset,
2519 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2520 ins->inst_destbasereg = STK_BASE;
2521 ins->inst_offset = ainfo->offset;
2522 ins->sreg1 = in->dreg;
2525 /* This is needed by MonoTypedRef->value to point to the correct data */
2526 if ((sig->call_convention == MONO_CALL_VARARG) &&
2527 (i >= sig->sentinelpos)) {
2528 switch (ainfo->size) {
2530 ins->opcode = OP_STOREI1_MEMBASE_REG;
2533 ins->opcode = OP_STOREI2_MEMBASE_REG;
2536 ins->opcode = OP_STOREI4_MEMBASE_REG;
2544 MONO_ADD_INS (cfg->cbb, ins);
2548 g_assert_not_reached ();
2554 * Handle the case where there are no implicit arguments
2556 if ((sig->call_convention == MONO_CALL_VARARG) &&
2558 (i == sig->sentinelpos)) {
2559 emit_sig_cookie (cfg, call, cinfo);
2563 /*========================= End of Function ========================*/
2565 /*------------------------------------------------------------------*/
2567 /* Name - mono_arch_emit_outarg_vt */
2569 /*------------------------------------------------------------------*/
2572 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2574 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2575 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2576 int size = ins->backend.size;
2578 if (ainfo->regtype == RegTypeStructByVal) {
2580 arg->ins.sreg1 = ainfo->reg;
2581 arg->ins.opcode = OP_OUTARG_VT;
2582 arg->size = ainfo->size;
2583 arg->offset = ainfo->offset;
2584 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2586 if (ainfo->reg != STK_BASE) {
2587 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2589 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2592 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2593 int dreg = mono_alloc_freg (cfg);
2595 if (ainfo->size == 4) {
2596 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2597 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2599 g_assert (ainfo->size == 8);
2601 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2604 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2606 MonoMethodHeader *header;
2609 header = mono_method_get_header (cfg->method);
2610 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2615 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2616 src->dreg, 0, size);
2618 if (cfg->compute_gc_maps) {
2621 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2626 /*========================= End of Function ========================*/
2628 /*------------------------------------------------------------------*/
2630 /* Name - mono_arch_emit_setret */
2632 /*------------------------------------------------------------------*/
2635 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2637 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2640 if (ret->type == MONO_TYPE_R4) {
2641 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2643 } else if (ret->type == MONO_TYPE_R8) {
2644 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2649 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2652 /*========================= End of Function ========================*/
2654 /*------------------------------------------------------------------*/
2656 /* Name - mono_arch_instrument_mem_needs */
2658 /* Function - Allow tracing to work with this interface (with */
2659 /* an optional argument). */
2661 /*------------------------------------------------------------------*/
2664 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2666 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2668 /* split prolog-epilog requirements? */
2669 *code = 50; /* max bytes needed: check this number */
2672 /*========================= End of Function ========================*/
2674 /*------------------------------------------------------------------*/
2676 /* Name - mono_arch_instrument_prolog */
2678 /* Function - Create an "instrumented" prolog. */
2680 /*------------------------------------------------------------------*/
2683 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2684 gboolean enable_arguments)
2691 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2692 if (cfg->method->save_lmf)
2693 parmOffset -= sizeof(MonoLMF);
2694 fpOffset = parmOffset + (5*sizeof(gpointer));
2695 if ((!has_ld) && (fpOffset > 4096)) {
2696 s390_lgr (code, s390_r12, STK_BASE);
2698 while (fpOffset > 4096) {
2699 s390_aghi (code, baseReg, 4096);
2707 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2709 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2710 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2711 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2712 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2714 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2715 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2716 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2717 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2719 s390_basr (code, s390_r13, 0);
2721 s390_llong(code, cfg->method);
2722 s390_llong(code, func);
2723 s390_lg (code, s390_r2, 0, s390_r13, 4);
2725 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2727 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2728 s390_lgr (code, s390_r4, STK_BASE);
2729 s390_aghi (code, s390_r4, cfg->stack_usage);
2730 s390_lg (code, s390_r1, 0, s390_r13, 12);
2731 s390_basr (code, s390_r14, s390_r1);
2733 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2734 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2735 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2736 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2738 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2739 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2740 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2741 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2743 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2748 /*========================= End of Function ========================*/
2750 /*------------------------------------------------------------------*/
2752 /* Name - mono_arch_instrument_epilog */
2754 /* Function - Create an epilog that will handle the returned */
2755 /* values used in instrumentation. */
2757 /*------------------------------------------------------------------*/
2760 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2763 int save_mode = SAVE_NONE,
2765 MonoMethod *method = cfg->method;
2766 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2768 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2769 if (method->save_lmf)
2770 saveOffset -= sizeof(MonoLMF);
2774 case MONO_TYPE_VOID:
2775 /* special case string .ctor icall */
2776 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2777 save_mode = SAVE_ONE;
2779 save_mode = SAVE_NONE;
2783 save_mode = SAVE_ONE;
2786 save_mode = SAVE_R4;
2789 save_mode = SAVE_R8;
2791 case MONO_TYPE_VALUETYPE:
2792 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2793 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2796 save_mode = SAVE_STRUCT;
2799 save_mode = SAVE_ONE;
2803 switch (save_mode) {
2805 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2806 if (enable_arguments) {
2807 s390_lgr (code, s390_r3, s390_r2);
2811 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2812 if (enable_arguments) {
2813 s390_ldebr (code, s390_f0, s390_f0);
2817 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2820 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2821 if (enable_arguments) {
2822 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2823 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2831 s390_basr (code, s390_r13, 0);
2833 s390_llong(code, cfg->method);
2834 s390_llong(code, func);
2835 s390_lg (code, s390_r2, 0, s390_r13, 4);
2836 s390_lg (code, s390_r1, 0, s390_r13, 12);
2837 s390_basr (code, s390_r14, s390_r1);
2839 switch (save_mode) {
2841 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2845 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2848 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2858 /*========================= End of Function ========================*/
2860 /*------------------------------------------------------------------*/
2862 /* Name - mono_arch_peephole_pass_1 */
2864 /* Function - Form a peephole pass at the code looking for */
2865 /* simple optimizations. */
2867 /*------------------------------------------------------------------*/
2870 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2874 /*========================= End of Function ========================*/
2876 /*------------------------------------------------------------------*/
2878 /* Name - mono_arch_peephole_pass_2 */
2880 /* Function - Form a peephole pass at the code looking for */
2881 /* simple optimizations. */
2883 /*------------------------------------------------------------------*/
2886 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2890 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2891 mono_peephole_ins (bb, ins);
2895 /*========================= End of Function ========================*/
2897 /*------------------------------------------------------------------*/
2899 /* Name - mono_arch_lowering_pass. */
2901 /*------------------------------------------------------------------*/
2904 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2906 MonoInst *ins, *next;
2908 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2909 switch (ins->opcode) {
2914 case OP_IDIV_UN_IMM:
2915 case OP_IREM_UN_IMM:
2919 case OP_LOCALLOC_IMM:
2920 mono_decompose_op_imm (cfg, bb, ins);
2923 if (!s390_is_imm16 (ins->inst_imm))
2924 /* This is created by the memcpy code which ignores is_inst_imm */
2925 mono_decompose_op_imm (cfg, bb, ins);
2932 bb->max_vreg = cfg->next_vreg;
2935 /*========================= End of Function ========================*/
2937 /*------------------------------------------------------------------*/
2939 /* Name - emit_float_to_int */
2941 /* Function - Create instructions which will convert a floating */
2942 /* point value to integer. */
2944 /*------------------------------------------------------------------*/
2947 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2949 /* sreg is a float, dreg is an integer reg. */
2951 s390_cgdbr (code, dreg, 5, sreg);
2954 s390_lghi (code, s390_r0, 0);
2955 s390_lghi (code, s390_r13, 0xff);
2956 s390_ltgr (code, dreg, dreg);
2958 s390_lghi (code, s390_r0, 0x80);
2959 s390_ngr (code, dreg, s390_r13);
2960 s390_ogr (code, dreg, s390_r0);
2965 s390_basr (code, s390_r13, 0);
2967 s390_llong (code, 0x41e0000000000000llu);
2968 s390_llong (code, 0x41f0000000000000llu);
2969 s390_ldr (code, s390_f15, sreg);
2970 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2971 s390_jl (code, 0); CODEPTR (code, o[0]);
2972 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2973 s390_cfdbr (code, dreg, 7, s390_f15);
2975 PTRSLOT (code, o[0]);
2976 s390_cfdbr (code, dreg, 5, sreg);
2979 s390_lghi (code, s390_r0, 0xff);
2980 s390_ngr (code, dreg, s390_r0);
2983 s390_lghi (code, s390_r0, -1);
2984 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2985 s390_ngr (code, dreg, s390_r0);
2992 /*========================= End of Function ========================*/
2994 /*------------------------------------------------------------------*/
2996 /* Name - gboolean_is_unsigned. */
2998 /* Function - Return TRUE if next opcode is checking for un- */
3001 /*------------------------------------------------------------------*/
3004 gboolean is_unsigned (MonoInst *next)
3007 (((next->opcode >= OP_IBNE_UN) &&
3008 (next->opcode <= OP_IBLT_UN)) ||
3009 ((next->opcode >= OP_LBNE_UN) &&
3010 (next->opcode <= OP_LBLT_UN)) ||
3011 ((next->opcode >= OP_COND_EXC_NE_UN) &&
3012 (next->opcode <= OP_COND_EXC_LT_UN)) ||
3013 ((next->opcode >= OP_COND_EXC_INE_UN) &&
3014 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
3015 ((next->opcode == OP_CLT_UN) ||
3016 (next->opcode == OP_CGT_UN)) ||
3017 ((next->opcode == OP_ICLT_UN) ||
3018 (next->opcode == OP_ICGT_UN) ||
3019 (next->opcode == OP_LCLT_UN) ||
3020 (next->opcode == OP_LCGT_UN))))
3026 /*========================= End of Function ========================*/
3028 /*------------------------------------------------------------------*/
3030 /* Name - mono_arch_output_basic_block */
3032 /* Function - Perform the "real" work of emitting instructions */
3033 /* that will do the work of in the basic block. */
3035 /*------------------------------------------------------------------*/
3038 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
3043 guint8 *code = cfg->native_code + cfg->code_len;
3044 guint last_offset = 0;
3045 int max_len, cpos, src2;
3047 /* we don't align basic blocks of loops on s390 */
3049 if (cfg->verbose_level > 2)
3050 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
3052 cpos = bb->max_offset;
3054 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
3055 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
3056 //g_assert (!mono_compile_aot);
3059 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
3060 /* this is not thread save, but good enough */
3061 /* fixme: howto handle overflows? */
3062 //x86_inc_mem (code, &cov->data [bb->dfn].count);
3065 MONO_BB_FOR_EACH_INS (bb, ins) {
3066 offset = code - cfg->native_code;
3068 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
3070 if (offset > (cfg->code_size - max_len - 16)) {
3071 cfg->code_size *= 2;
3072 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
3073 code = cfg->native_code + offset;
3076 mono_debug_record_line_number (cfg, ins, offset);
3078 switch (ins->opcode) {
3079 case OP_STOREI1_MEMBASE_IMM: {
3080 s390_lghi (code, s390_r0, ins->inst_imm);
3081 S390_LONG (code, stcy, stc, s390_r0, 0,
3082 ins->inst_destbasereg, ins->inst_offset);
3085 case OP_STOREI2_MEMBASE_IMM: {
3086 s390_lghi (code, s390_r0, ins->inst_imm);
3087 S390_LONG (code, sthy, sth, s390_r0, 0,
3088 ins->inst_destbasereg, ins->inst_offset);
3091 case OP_STOREI4_MEMBASE_IMM: {
3092 if (s390_is_imm16(ins->inst_imm)) {
3093 s390_lghi (code, s390_r0, ins->inst_imm);
3095 s390_basr (code, s390_r13, 0);
3097 s390_llong(code, ins->inst_imm);
3098 s390_lg (code, s390_r0, 0, s390_r13, 4);
3100 S390_LONG (code, sty, st, s390_r0, 0,
3101 ins->inst_destbasereg, ins->inst_offset);
3104 case OP_STORE_MEMBASE_IMM:
3105 case OP_STOREI8_MEMBASE_IMM: {
3106 if (s390_is_imm16(ins->inst_imm)) {
3107 s390_lghi (code, s390_r0, ins->inst_imm);
3109 s390_basr (code, s390_r13, 0);
3111 s390_llong(code, ins->inst_imm);
3112 s390_lg (code, s390_r0, 0, s390_r13, 4);
3114 S390_LONG (code, stg, stg, s390_r0, 0,
3115 ins->inst_destbasereg, ins->inst_offset);
3118 case OP_STOREI1_MEMBASE_REG: {
3119 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3120 ins->inst_destbasereg, ins->inst_offset);
3123 case OP_STOREI2_MEMBASE_REG: {
3124 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3125 ins->inst_destbasereg, ins->inst_offset);
3128 case OP_STOREI4_MEMBASE_REG: {
3129 S390_LONG (code, sty, st, ins->sreg1, 0,
3130 ins->inst_destbasereg, ins->inst_offset);
3133 case OP_STORE_MEMBASE_REG:
3134 case OP_STOREI8_MEMBASE_REG: {
3135 S390_LONG (code, stg, stg, ins->sreg1, 0,
3136 ins->inst_destbasereg, ins->inst_offset);
3140 g_assert_not_reached ();
3142 case OP_LOAD_MEMBASE:
3143 case OP_LOADI8_MEMBASE: {
3144 S390_LONG (code, lg, lg, ins->dreg, 0,
3145 ins->inst_basereg, ins->inst_offset);
3148 case OP_LOADI4_MEMBASE: {
3149 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3150 ins->inst_basereg, ins->inst_offset);
3153 case OP_LOADU4_MEMBASE: {
3154 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3155 ins->inst_basereg, ins->inst_offset);
3158 case OP_LOADU1_MEMBASE: {
3159 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3160 ins->inst_basereg, ins->inst_offset);
3163 case OP_LOADI1_MEMBASE: {
3164 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3165 ins->inst_basereg, ins->inst_offset);
3168 case OP_LOADU2_MEMBASE: {
3169 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3170 ins->inst_basereg, ins->inst_offset);
3173 case OP_LOADI2_MEMBASE: {
3174 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3175 ins->inst_basereg, ins->inst_offset);
3178 case OP_LCONV_TO_I1: {
3180 s390_lgbr (code, ins->dreg, ins->sreg1);
3182 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
3183 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
3187 case OP_LCONV_TO_I2: {
3189 s390_lghr (code, ins->dreg, ins->sreg1);
3191 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
3192 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
3196 case OP_LCONV_TO_U1: {
3198 s390_llghr (code, ins->dreg, ins->sreg1);
3200 if (ins->dreg != ins->sreg1)
3201 s390_lgr (code, ins->dreg, ins->sreg1);
3202 s390_lghi (code, s390_r0, 0xff);
3203 s390_ngr (code, ins->dreg, s390_r0);
3207 case OP_LCONV_TO_U2: {
3209 s390_llghr (code, ins->dreg, ins->sreg1);
3211 if (ins->dreg != ins->sreg1)
3212 s390_lgr (code, ins->dreg, ins->sreg1);
3213 s390_lghi (code, s390_r0, -1);
3214 s390_srlg (code, s390_r0, s390_r0, 0, 48);
3215 s390_ngr (code, ins->dreg, s390_r0);
3219 case OP_ICONV_TO_I1: {
3221 s390_lbr (code, ins->dreg, ins->sreg1);
3223 if (ins->dreg != ins->sreg1)
3224 s390_lr (code, ins->dreg, ins->sreg1);
3225 s390_sll (code, ins->dreg, 0, 24);
3226 s390_sra (code, ins->dreg, 0, 24);
3231 case OP_ICONV_TO_I2: {
3233 s390_lhr (code, ins->dreg, ins->sreg1);
3235 if (ins->dreg != ins->sreg1)
3236 s390_lr (code, ins->dreg, ins->sreg1);
3237 s390_sll (code, ins->dreg, 0, 16);
3238 s390_sra (code, ins->dreg, 0, 16);
3242 case OP_ICONV_TO_U1: {
3244 s390_llcr (code, ins->dreg, ins->sreg1);
3246 if (ins->dreg != ins->sreg1)
3247 s390_lr (code, ins->dreg, ins->sreg1);
3248 s390_lhi (code, s390_r0, 0xff);
3249 s390_nr (code, ins->dreg, s390_r0);
3253 case OP_ICONV_TO_U2: {
3255 s390_llhr (code, ins->dreg, ins->sreg1);
3257 if (ins->dreg != ins->sreg1)
3258 s390_lr (code, ins->dreg, ins->sreg1);
3259 s390_lhi (code, s390_r0, -1);
3260 s390_srl (code, s390_r0, 0, 16);
3261 s390_nr (code, ins->dreg, s390_r0);
3267 if (is_unsigned (ins->next))
3268 s390_clgr (code, ins->sreg1, ins->sreg2);
3270 s390_cgr (code, ins->sreg1, ins->sreg2);
3274 if (is_unsigned (ins->next))
3275 s390_clr (code, ins->sreg1, ins->sreg2);
3277 s390_cr (code, ins->sreg1, ins->sreg2);
3280 case OP_COMPARE_IMM:
3281 case OP_LCOMPARE_IMM: {
3282 if (s390_is_imm16 (ins->inst_imm)) {
3283 s390_lghi (code, s390_r0, ins->inst_imm);
3284 if (is_unsigned (ins->next))
3285 s390_clgr (code, ins->sreg1, s390_r0);
3287 s390_cgr (code, ins->sreg1, s390_r0);
3289 s390_basr (code, s390_r13, 0);
3291 s390_llong(code, ins->inst_imm);
3292 if (is_unsigned (ins->next))
3293 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3295 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3299 case OP_ICOMPARE_IMM: {
3300 if (s390_is_imm16 (ins->inst_imm)) {
3301 s390_lghi (code, s390_r0, ins->inst_imm);
3302 if (is_unsigned (ins->next))
3303 s390_clr (code, ins->sreg1, s390_r0);
3305 s390_cr (code, ins->sreg1, s390_r0);
3308 s390_basr (code, s390_r13, 0);
3310 s390_word (code, ins->inst_imm);
3311 if (is_unsigned (ins->next))
3312 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3314 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3319 s390_basr (code, s390_r13, 0);
3321 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3323 s390_llong (code, mono_break);
3324 s390_lg (code, s390_r14, 0, s390_r13, 4);
3325 s390_basr (code, s390_r14, s390_r14);
3330 s390_agr (code, ins->dreg, src2);
3335 s390_agr (code, ins->dreg, src2);
3340 s390_alcgr (code, ins->dreg, src2);
3344 if (ins->dreg != ins->sreg1) {
3345 s390_lgr (code, ins->dreg, ins->sreg1);
3347 if (s390_is_imm16 (ins->inst_imm)) {
3348 s390_aghi (code, ins->dreg, ins->inst_imm);
3350 s390_basr (code, s390_r13, 0);
3352 s390_llong(code, ins->inst_imm);
3353 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3358 if (ins->dreg != ins->sreg1) {
3359 s390_lgr (code, ins->dreg, ins->sreg1);
3361 g_assert (s390_is_imm16 (ins->inst_imm));
3362 s390_aghi (code, ins->dreg, ins->inst_imm);
3366 if (ins->dreg != ins->sreg1) {
3367 s390_lgr (code, ins->dreg, ins->sreg1);
3369 if (s390_is_imm16 (ins->inst_imm)) {
3370 s390_lghi (code, s390_r0, ins->inst_imm);
3371 s390_alcgr (code, ins->dreg, s390_r0);
3373 s390_basr (code, s390_r13, 0);
3375 s390_llong (code, ins->inst_imm);
3376 s390_lg (code, s390_r13, 0, s390_r13, 4);
3377 s390_alcgr (code, ins->dreg, s390_r13);
3382 case OP_S390_IADD_OVF: {
3384 s390_ar (code, ins->dreg, src2);
3385 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3386 s390_lgfr (code, ins->dreg, ins->dreg);
3389 case OP_IADD_OVF_UN:
3390 case OP_S390_IADD_OVF_UN: {
3392 s390_algr (code, ins->dreg, src2);
3393 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3394 s390_llgfr (code, ins->dreg, ins->dreg);
3397 case OP_ADD_OVF_CARRY: {
3399 s390_lghi (code, s390_r0, 0);
3400 s390_lgr (code, s390_r1, s390_r0);
3401 s390_alcgr (code, s390_r0, s390_r1);
3402 s390_agr (code, ins->dreg, src2);
3403 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3404 s390_agr (code, ins->dreg, s390_r0);
3405 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3408 case OP_ADD_OVF_UN_CARRY: {
3410 s390_alcgr (code, ins->dreg, src2);
3411 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3416 s390_sgr (code, ins->dreg, src2);
3421 s390_sgr (code, ins->dreg, src2);
3426 s390_slbgr(code, ins->dreg, src2);
3430 if (ins->dreg != ins->sreg1) {
3431 s390_lgr (code, ins->dreg, ins->sreg1);
3433 if (s390_is_imm16 (-ins->inst_imm)) {
3434 s390_lghi (code, s390_r0, ins->inst_imm);
3435 s390_slgr (code, ins->dreg, s390_r0);
3437 s390_basr (code, s390_r13, 0);
3439 s390_llong(code, ins->inst_imm);
3440 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3445 if (ins->dreg != ins->sreg1) {
3446 s390_lgr (code, ins->dreg, ins->sreg1);
3448 if (s390_is_imm16 (-ins->inst_imm)) {
3449 s390_lghi (code, s390_r0, ins->inst_imm);
3450 s390_slgr (code, ins->dreg, s390_r0);
3452 s390_basr (code, s390_r13, 0);
3454 s390_llong(code, ins->inst_imm);
3455 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3460 if (ins->dreg != ins->sreg1) {
3461 s390_lgr (code, ins->dreg, ins->sreg1);
3463 if (s390_is_imm16 (-ins->inst_imm)) {
3464 s390_lghi (code, s390_r0, ins->inst_imm);
3465 s390_slbgr (code, ins->dreg, s390_r0);
3467 s390_basr (code, s390_r13, 0);
3469 s390_llong(code, ins->inst_imm);
3470 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3474 case OP_SUB_OVF_CARRY: {
3476 s390_lghi (code, s390_r0, 0);
3477 s390_lgr (code, s390_r1, s390_r0);
3478 s390_slbgr (code, s390_r0, s390_r1);
3479 s390_sgr (code, ins->dreg, src2);
3480 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3481 s390_agr (code, ins->dreg, s390_r0);
3482 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3485 case OP_SUB_OVF_UN_CARRY: {
3487 s390_slbgr (code, ins->dreg, src2);
3488 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3492 if (ins->sreg1 == ins->dreg) {
3493 s390_ngr (code, ins->dreg, ins->sreg2);
3496 if (ins->sreg2 == ins->dreg) {
3497 s390_ngr (code, ins->dreg, ins->sreg1);
3500 s390_lgr (code, ins->dreg, ins->sreg1);
3501 s390_ngr (code, ins->dreg, ins->sreg2);
3507 if (ins->dreg != ins->sreg1) {
3508 s390_lgr (code, ins->dreg, ins->sreg1);
3510 if (s390_is_imm16 (ins->inst_imm)) {
3511 s390_lghi (code, s390_r0, ins->inst_imm);
3512 s390_ngr (code, ins->dreg, s390_r0);
3514 s390_basr (code, s390_r13, 0);
3516 s390_llong(code, ins->inst_imm);
3517 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3522 s390_lgr (code, s390_r1, ins->sreg1);
3523 s390_dsgr (code, s390_r0, ins->sreg2);
3524 s390_lgr (code, ins->dreg, s390_r1);
3528 s390_lgr (code, s390_r1, ins->sreg1);
3529 s390_lghi (code, s390_r0, 0);
3530 s390_dlgr (code, s390_r0, ins->sreg2);
3531 s390_lgr (code, ins->dreg, s390_r1);
3535 s390_lgr (code, s390_r1, ins->sreg1);
3536 s390_dsgr (code, s390_r0, ins->sreg2);
3537 s390_lgr (code, ins->dreg, s390_r0);
3541 s390_lgr (code, s390_r1, ins->sreg1);
3542 s390_lghi (code, s390_r0, 0);
3543 s390_dlgr (code, s390_r0, ins->sreg2);
3544 s390_lgr (code, ins->dreg, s390_r0);
3548 if (ins->sreg1 == ins->dreg) {
3549 s390_ogr (code, ins->dreg, ins->sreg2);
3552 if (ins->sreg2 == ins->dreg) {
3553 s390_ogr (code, ins->dreg, ins->sreg1);
3556 s390_lgr (code, ins->dreg, ins->sreg1);
3557 s390_ogr (code, ins->dreg, ins->sreg2);
3563 if (ins->dreg != ins->sreg1) {
3564 s390_lgr (code, ins->dreg, ins->sreg1);
3566 if (s390_is_imm16 (ins->inst_imm)) {
3567 s390_lghi (code, s390_r0, ins->inst_imm);
3568 s390_ogr (code, ins->dreg, s390_r0);
3570 s390_basr (code, s390_r13, 0);
3572 s390_llong(code, ins->inst_imm);
3573 s390_og (code, ins->dreg, 0, s390_r13, 4);
3578 if (ins->sreg1 == ins->dreg) {
3579 s390_xgr (code, ins->dreg, ins->sreg2);
3582 if (ins->sreg2 == ins->dreg) {
3583 s390_xgr (code, ins->dreg, ins->sreg1);
3586 s390_lgr (code, ins->dreg, ins->sreg1);
3587 s390_xgr (code, ins->dreg, ins->sreg2);
3593 if (ins->dreg != ins->sreg1) {
3594 s390_lgr (code, ins->dreg, ins->sreg1);
3596 if (s390_is_imm16 (ins->inst_imm)) {
3597 s390_lghi (code, s390_r0, ins->inst_imm);
3598 s390_xgr (code, ins->dreg, s390_r0);
3600 s390_basr (code, s390_r13, 0);
3602 s390_llong(code, ins->inst_imm);
3603 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3609 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3614 if (ins->sreg1 != ins->dreg) {
3615 s390_lgr (code, ins->dreg, ins->sreg1);
3617 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3622 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3627 if (ins->sreg1 != ins->dreg) {
3628 s390_lgr (code, ins->dreg, ins->sreg1);
3630 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3634 case OP_LSHR_UN_IMM: {
3635 if (ins->sreg1 != ins->dreg) {
3636 s390_lgr (code, ins->dreg, ins->sreg1);
3638 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3643 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3647 if (ins->sreg1 != ins->dreg) {
3648 s390_lgr (code, ins->dreg, ins->sreg1);
3650 s390_lghi (code, s390_r0, -1);
3651 s390_xgr (code, ins->dreg, s390_r0);
3655 s390_lcgr (code, ins->dreg, ins->sreg1);
3660 s390_msgr (code, ins->dreg, src2);
3665 if (ins->dreg != ins->sreg1) {
3666 s390_lgr (code, ins->dreg, ins->sreg1);
3668 if (s390_is_imm16 (ins->inst_imm)) {
3669 s390_lghi (code, s390_r13, ins->inst_imm);
3671 s390_basr (code, s390_r13, 0);
3673 s390_llong(code, ins->inst_imm);
3674 s390_lg (code, s390_r13, 0, s390_r13, 4);
3676 s390_msgr (code, ins->dreg, s390_r13);
3681 s390_ltgr (code, s390_r1, ins->sreg1);
3682 s390_jz (code, 0); CODEPTR(code, o[0]);
3683 s390_ltgr (code, s390_r0, ins->sreg2);
3685 s390_lghi (code, s390_r1, 0);
3686 s390_j (code, 0); CODEPTR(code, o[1]);
3687 s390_xgr (code, s390_r0, s390_r1);
3688 s390_msgr (code, s390_r1, ins->sreg2);
3689 s390_xgr (code, s390_r0, s390_r1);
3690 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3691 s390_ltgr (code, s390_r0, s390_r0);
3692 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3693 PTRSLOT (code, o[0]);
3694 PTRSLOT (code, o[1]);
3695 s390_lgr (code, ins->dreg, s390_r1);
3698 case OP_LMUL_OVF_UN: {
3699 s390_lghi (code, s390_r0, 0);
3700 s390_lgr (code, s390_r1, ins->sreg1);
3701 s390_mlgr (code, s390_r0, ins->sreg2);
3702 s390_ltgr (code, s390_r0, s390_r0);
3703 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3704 s390_lgr (code, ins->dreg, s390_r1);
3708 g_assert_not_reached ();
3710 s390_algr (code, ins->dreg, src2);
3715 s390_agr (code, ins->dreg, src2);
3719 g_assert_not_reached ();
3721 s390_alcgr (code, ins->dreg, src2);
3725 if (ins->dreg != ins->sreg1) {
3726 s390_lgfr (code, ins->dreg, ins->sreg1);
3728 if (s390_is_imm16 (ins->inst_imm)) {
3729 s390_aghi(code, ins->dreg, ins->inst_imm);
3731 s390_basr (code, s390_r13, 0);
3733 s390_word (code, ins->inst_imm);
3734 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3739 if (ins->dreg != ins->sreg1) {
3740 s390_lgfr (code, ins->dreg, ins->sreg1);
3742 if (s390_is_imm16 (ins->inst_imm)) {
3743 s390_lghi (code, s390_r0, ins->inst_imm);
3744 s390_alcgr (code, ins->dreg, s390_r0);
3746 s390_basr (code, s390_r13, 0);
3748 s390_word (code, ins->inst_imm);
3749 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3750 s390_alcgr (code, ins->dreg, s390_r13);
3755 case OP_S390_LADD_OVF: {
3757 s390_agr (code, ins->dreg, src2);
3758 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3761 case OP_LADD_OVF_UN:
3762 case OP_S390_LADD_OVF_UN: {
3764 s390_algr (code, ins->dreg, src2);
3765 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3769 CHECK_SRCDST_NCOM_I;
3770 s390_slgr (code, ins->dreg, src2);
3774 CHECK_SRCDST_NCOM_I;
3775 s390_sgr (code, ins->dreg, src2);
3779 CHECK_SRCDST_NCOM_I;
3780 s390_slbgr (code, ins->dreg, src2);
3784 if (ins->dreg != ins->sreg1) {
3785 s390_lgfr (code, ins->dreg, ins->sreg1);
3787 if (s390_is_imm16 (-ins->inst_imm)) {
3788 s390_aghi (code, ins->dreg, -ins->inst_imm);
3790 s390_basr (code, s390_r13, 0);
3792 s390_word (code, ins->inst_imm);
3793 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3798 s390_basr (code, s390_r13, 0);
3800 s390_word (code, ins->inst_imm);
3801 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3805 case OP_S390_ISUB_OVF: {
3807 s390_sr (code, ins->dreg, src2);
3808 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3809 s390_lgfr (code, ins->dreg, ins->dreg);
3812 case OP_ISUB_OVF_UN:
3813 case OP_S390_ISUB_OVF_UN: {
3815 s390_slr (code, ins->dreg, src2);
3816 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3817 s390_llgfr(code, ins->dreg, ins->dreg);
3821 case OP_S390_LSUB_OVF: {
3823 s390_sgr (code, ins->dreg, src2);
3824 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3827 case OP_LSUB_OVF_UN:
3828 case OP_S390_LSUB_OVF_UN: {
3830 s390_slgr (code, ins->dreg, src2);
3831 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3835 CHECK_SRCDST_NCOM_I;
3836 s390_ngr (code, ins->dreg, src2);
3840 if (ins->dreg != ins->sreg1) {
3841 s390_lgfr (code, ins->dreg, ins->sreg1);
3843 if (s390_is_imm16 (ins->inst_imm)) {
3844 s390_lghi (code, s390_r0, ins->inst_imm);
3845 s390_ngr (code, ins->dreg, s390_r0);
3847 s390_basr (code, s390_r13, 0);
3849 s390_llong(code, ins->inst_imm);
3850 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3855 s390_lgfr (code, s390_r0, ins->sreg1);
3856 s390_srda (code, s390_r0, 0, 32);
3857 s390_dr (code, s390_r0, ins->sreg2);
3858 s390_lgfr (code, ins->dreg, s390_r1);
3862 s390_lgfr (code, s390_r0, ins->sreg1);
3863 s390_srdl (code, s390_r0, 0, 32);
3864 s390_dlr (code, s390_r0, ins->sreg2);
3865 s390_lgfr (code, ins->dreg, s390_r1);
3869 if (s390_is_imm16 (ins->inst_imm)) {
3870 s390_lghi (code, s390_r13, ins->inst_imm);
3871 s390_lgfr (code, s390_r0, ins->sreg1);
3873 s390_basr (code, s390_r13, 0);
3875 s390_word (code, ins->inst_imm);
3876 s390_lgfr (code, s390_r0, ins->sreg1);
3877 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3879 s390_srda (code, s390_r0, 0, 32);
3880 s390_dr (code, s390_r0, ins->sreg2);
3881 s390_lgfr (code, ins->dreg, s390_r1);
3885 s390_lgfr (code, s390_r0, ins->sreg1);
3886 s390_srda (code, s390_r0, 0, 32);
3887 s390_dr (code, s390_r0, ins->sreg2);
3888 s390_lgfr (code, ins->dreg, s390_r0);
3891 s390_lgfr (code, s390_r0, ins->sreg1);
3892 s390_srdl (code, s390_r0, 0, 32);
3893 s390_dlr (code, s390_r0, ins->sreg2);
3894 s390_lgfr (code, ins->dreg, s390_r0);
3898 if (s390_is_imm16 (ins->inst_imm)) {
3899 s390_lghi (code, s390_r13, ins->inst_imm);
3900 s390_lgfr (code, s390_r0, ins->sreg1);
3902 s390_basr (code, s390_r13, 0);
3904 s390_word (code, ins->inst_imm);
3905 s390_lgfr (code, s390_r0, ins->sreg1);
3906 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3908 s390_srda (code, s390_r0, 0, 32);
3909 s390_dr (code, s390_r0, ins->sreg2);
3910 s390_lgfr (code, ins->dreg, s390_r0);
3915 s390_ogr (code, ins->dreg, src2);
3919 if (ins->dreg != ins->sreg1) {
3920 s390_lgfr (code, ins->dreg, ins->sreg1);
3922 if (s390_is_imm16 (ins->inst_imm)) {
3923 s390_lghi (code, s390_r0, ins->inst_imm);
3924 s390_ogr (code, ins->dreg, s390_r0);
3926 s390_basr (code, s390_r13, 0);
3928 s390_llong(code, ins->inst_imm);
3929 s390_og (code, ins->dreg, 0, s390_r13, 4);
3935 s390_xgr (code, ins->dreg, src2);
3939 if (ins->dreg != ins->sreg1) {
3940 s390_lgfr (code, ins->dreg, ins->sreg1);
3942 if (s390_is_imm16 (ins->inst_imm)) {
3943 s390_lghi (code, s390_r0, ins->inst_imm);
3944 s390_xgr (code, ins->dreg, s390_r0);
3946 s390_basr (code, s390_r13, 0);
3948 s390_llong(code, ins->inst_imm);
3949 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3955 s390_sll (code, ins->dreg, src2, 0);
3959 if (ins->sreg1 != ins->dreg) {
3960 s390_lgfr (code, ins->dreg, ins->sreg1);
3962 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3967 s390_sra (code, ins->dreg, src2, 0);
3971 if (ins->sreg1 != ins->dreg) {
3972 s390_lgfr (code, ins->dreg, ins->sreg1);
3974 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3977 case OP_ISHR_UN_IMM: {
3978 if (ins->sreg1 != ins->dreg) {
3979 s390_lgfr (code, ins->dreg, ins->sreg1);
3981 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3986 s390_srl (code, ins->dreg, src2, 0);
3990 if (ins->sreg1 != ins->dreg) {
3991 s390_lgfr (code, ins->dreg, ins->sreg1);
3993 s390_lghi (code, s390_r0, -1);
3994 s390_xgr (code, ins->dreg, s390_r0);
3998 s390_lcgr (code, ins->dreg, ins->sreg1);
4003 s390_msr (code, ins->dreg, src2);
4007 if (ins->dreg != ins->sreg1) {
4008 s390_lgfr (code, ins->dreg, ins->sreg1);
4010 if (s390_is_imm16 (ins->inst_imm)) {
4011 s390_lghi (code, s390_r13, ins->inst_imm);
4013 s390_basr (code, s390_r13, 0);
4015 s390_word (code, ins->inst_imm);
4016 s390_lgf (code, s390_r13, 0, s390_r13, 4);
4018 s390_msr (code, ins->dreg, s390_r13);
4023 s390_ltr (code, s390_r1, ins->sreg1);
4024 s390_jz (code, 0); CODEPTR(code, o[0]);
4025 s390_ltr (code, s390_r0, ins->sreg2);
4027 s390_lhi (code, s390_r1, 0);
4028 s390_j (code, 0); CODEPTR(code, o[1]);
4029 s390_xr (code, s390_r0, s390_r1);
4030 s390_msr (code, s390_r1, ins->sreg2);
4031 s390_xr (code, s390_r0, s390_r1);
4032 s390_srl (code, s390_r0, 0, 31);
4033 s390_ltr (code, s390_r0, s390_r0);
4034 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4035 PTRSLOT (code, o[0]);
4036 PTRSLOT (code, o[1]);
4037 s390_lgfr (code, ins->dreg, s390_r1);
4040 case OP_IMUL_OVF_UN: {
4041 s390_lhi (code, s390_r0, 0);
4042 s390_lr (code, s390_r1, ins->sreg1);
4043 s390_mlr (code, s390_r0, ins->sreg2);
4044 s390_ltr (code, s390_r0, s390_r0);
4045 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4046 s390_lgfr (code, ins->dreg, s390_r1);
4051 if (s390_is_imm16(ins->inst_c0)) {
4052 s390_lghi (code, ins->dreg, ins->inst_c0);
4054 s390_basr (code, s390_r13, 0);
4056 s390_llong(code, ins->inst_c0);
4057 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4062 s390_basr (code, s390_r13, 0);
4064 mono_add_patch_info (cfg, code - cfg->native_code,
4065 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4066 s390_llong(code, 0);
4067 s390_lg (code,ins->dreg, 0, s390_r13, 4);
4070 case OP_JUMP_TABLE: {
4071 mono_add_patch_info (cfg, code - cfg->native_code,
4072 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4073 s390_basr (code, s390_r13, 0);
4075 s390_llong (code, 0);
4076 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4080 if (ins->dreg != ins->sreg1) {
4081 s390_lgr (code, ins->dreg, ins->sreg1);
4085 case OP_LCONV_TO_I8:
4087 s390_lgfr (code, ins->dreg, ins->sreg1);
4089 case OP_LCONV_TO_I4:
4090 s390_lgfr (code, ins->dreg, ins->sreg1);
4093 case OP_LCONV_TO_U8:
4094 case OP_LCONV_TO_U4:
4096 s390_llgfr (code, ins->dreg, ins->sreg1);
4098 case OP_LCONV_TO_OVF_U4:
4099 s390_basr (code, s390_r13, 0);
4101 s390_llong(code, 4294967295);
4102 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
4103 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4104 s390_ltgr (code, ins->sreg1, ins->sreg1);
4105 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4106 s390_llgfr(code, ins->dreg, ins->sreg1);
4108 case OP_LCONV_TO_OVF_I4_UN:
4109 s390_basr (code, s390_r13, 0);
4111 s390_llong(code, 2147483647);
4112 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
4113 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4114 s390_ltgr (code, ins->sreg1, ins->sreg1);
4115 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4116 s390_lgfr (code, ins->dreg, ins->sreg1);
4119 case OP_FCONV_TO_R4: {
4120 if (ins->dreg != ins->sreg1) {
4121 s390_ldr (code, ins->dreg, ins->sreg1);
4125 case OP_S390_SETF4RET: {
4126 s390_ledbr (code, ins->dreg, ins->sreg1);
4130 if (s390_is_imm16 (ins->inst_offset)) {
4131 s390_lghi (code, s390_r13, ins->inst_offset);
4133 s390_bras (code, s390_r13, 0);
4135 s390_llong(code, ins->inst_offset);
4136 s390_lg (code, s390_r13, 0, s390_r13, 4);
4138 s390_ear (code, s390_r1, 0);
4139 s390_sllg(code, s390_r1, s390_r1, 0, 32);
4140 s390_ear (code, s390_r1, 1);
4141 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
4145 if (cfg->method->save_lmf)
4146 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4148 if (cfg->flags & MONO_CFG_HAS_TAIL) {
4149 code = emit_load_volatile_arguments (code, cfg);
4152 code = backUpStackPtr(cfg, code);
4153 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
4154 mono_add_patch_info (cfg, code - cfg->native_code,
4155 MONO_PATCH_INFO_METHOD_JUMP,
4157 s390_jcl (code, S390_CC_UN, 0);
4160 case OP_CHECK_THIS: {
4161 /* ensure ins->sreg1 is not NULL */
4162 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
4163 s390_ltgr (code, s390_r0, s390_r0);
4167 int offset = cfg->sig_cookie + cfg->stack_usage;
4169 if (s390_is_imm16 (offset))
4170 s390_lghi (code, s390_r0, offset);
4172 s390_basr (code, s390_r13, 0);
4174 s390_llong(code, offset);
4175 s390_lg (code, s390_r0, 0, s390_r13, 0);
4177 s390_agr (code, s390_r0, cfg->frame_reg);
4178 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
4182 s390_basr (code, s390_r13, 0);
4184 call = (MonoCallInst*)ins;
4185 if (ins->flags & MONO_INST_HAS_METHOD)
4186 mono_add_patch_info (cfg, code-cfg->native_code,
4187 MONO_PATCH_INFO_METHOD,
4190 mono_add_patch_info (cfg, code-cfg->native_code,
4191 MONO_PATCH_INFO_ABS,
4193 s390_llong(code, 0);
4194 s390_lg (code, s390_r14, 0, s390_r13, 4);
4195 s390_basr (code, s390_r14, s390_r14);
4196 if (call->signature->ret->type == MONO_TYPE_R4)
4197 s390_ldebr (code, s390_f0, s390_f0);
4205 s390_basr (code, s390_r13, 0);
4207 call = (MonoCallInst*)ins;
4208 if (ins->flags & MONO_INST_HAS_METHOD)
4209 mono_add_patch_info (cfg, code-cfg->native_code,
4210 MONO_PATCH_INFO_METHOD,
4213 mono_add_patch_info (cfg, code-cfg->native_code,
4214 MONO_PATCH_INFO_ABS,
4216 s390_llong(code, 0);
4217 s390_lg (code, s390_r14, 0, s390_r13, 4);
4218 s390_basr (code, s390_r14, s390_r14);
4221 case OP_FCALL_REG: {
4222 call = (MonoCallInst*)ins;
4223 s390_lgr (code, s390_r1, ins->sreg1);
4224 s390_basr (code, s390_r14, s390_r1);
4225 if (call->signature->ret->type == MONO_TYPE_R4)
4226 s390_ldebr (code, s390_f0, s390_f0);
4232 case OP_VOIDCALL_REG:
4234 s390_lgr (code, s390_r1, ins->sreg1);
4235 s390_basr (code, s390_r14, s390_r1);
4238 case OP_FCALL_MEMBASE: {
4239 call = (MonoCallInst*)ins;
4240 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4241 s390_basr (code, s390_r14, s390_r1);
4242 if (call->signature->ret->type == MONO_TYPE_R4)
4243 s390_ldebr (code, s390_f0, s390_f0);
4246 case OP_LCALL_MEMBASE:
4247 case OP_VCALL_MEMBASE:
4248 case OP_VCALL2_MEMBASE:
4249 case OP_VOIDCALL_MEMBASE:
4250 case OP_CALL_MEMBASE: {
4251 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4252 s390_basr (code, s390_r14, s390_r1);
4259 if (cfg->param_area == 0)
4260 alloca_skip = S390_MINIMAL_STACK_SIZE;
4262 alloca_skip = cfg->param_area;
4264 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4265 s390_lgr (code, s390_r1, ins->sreg1);
4266 if (ins->flags & MONO_INST_INIT)
4267 s390_lgr (code, s390_r0, ins->sreg1);
4268 s390_aghi (code, s390_r1, 14);
4269 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4270 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4271 if (cfg->method->save_lmf) {
4272 /*----------------------------------*/
4273 /* we have to adjust lmf ebp value */
4274 /*----------------------------------*/
4275 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4277 s390_lgr (code, s390_r13, cfg->frame_reg);
4278 if (s390_is_imm16(lmfOffset))
4279 s390_aghi (code, s390_r13, lmfOffset);
4281 s390_basr (code, s390_r14, 0);
4283 s390_word (code, lmfOffset);
4284 s390_agf (code, s390_r13, 0, s390_r14, 4);
4286 s390_lgr (code, s390_r14, STK_BASE);
4287 s390_sgr (code, s390_r14, s390_r1);
4288 s390_stg (code, s390_r14, 0, s390_r13,
4289 G_STRUCT_OFFSET(MonoLMF, ebp));
4291 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4292 s390_sgr (code, STK_BASE, s390_r1);
4293 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4294 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4295 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4296 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4297 if (ins->flags & MONO_INST_INIT) {
4298 s390_lgr (code, s390_r1, s390_r0);
4299 s390_lgr (code, s390_r0, ins->dreg);
4300 s390_lgr (code, s390_r14, s390_r12);
4301 s390_lghi (code, s390_r13, 0);
4302 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4304 s390_lgr (code, s390_r12, s390_r14);
4309 s390_lgr (code, s390_r2, ins->sreg1);
4310 s390_basr (code, s390_r13, 0);
4312 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4313 (gpointer) "mono_arch_throw_exception");
4314 s390_llong(code, 0);
4315 s390_lg (code, s390_r14, 0, s390_r13, 4);
4316 s390_basr (code, s390_r14, s390_r14);
4320 s390_lgr (code, s390_r2, ins->sreg1);
4321 s390_basr (code, s390_r13, 0);
4323 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4324 (gpointer) "mono_arch_rethrow_exception");
4325 s390_llong(code, 0);
4326 s390_lg (code, s390_r14, 0, s390_r13, 4);
4327 s390_basr (code, s390_r14, s390_r14);
4330 case OP_START_HANDLER: {
4331 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4333 S390_LONG (code, stg, stg, s390_r14, 0,
4334 spvar->inst_basereg,
4335 spvar->inst_offset);
4338 case OP_ENDFILTER: {
4339 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4341 if (ins->sreg1 != s390_r2)
4342 s390_lgr(code, s390_r2, ins->sreg1);
4343 S390_LONG (code, lg, lg, s390_r14, 0,
4344 spvar->inst_basereg,
4345 spvar->inst_offset);
4346 s390_br (code, s390_r14);
4349 case OP_ENDFINALLY: {
4350 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4352 S390_LONG (code, lg, lg, s390_r14, 0,
4353 spvar->inst_basereg,
4354 spvar->inst_offset);
4355 s390_br (code, s390_r14);
4358 case OP_CALL_HANDLER: {
4359 mono_add_patch_info (cfg, code-cfg->native_code,
4360 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4361 s390_brasl (code, s390_r14, 0);
4362 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4366 ins->inst_c0 = code - cfg->native_code;
4369 case OP_RELAXED_NOP:
4372 case OP_DUMMY_STORE:
4373 case OP_NOT_REACHED:
4377 case OP_SEQ_POINT: {
4380 if (cfg->compile_aot)
4384 * Read from the single stepping trigger page. This will cause a
4385 * SIGSEGV when single stepping is enabled.
4386 * We do this _before_ the breakpoint, so single stepping after
4387 * a breakpoint is hit will step to the next IL offset.
4389 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4390 breakpointCode.pTrigger = ss_trigger_page;
4391 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4392 code += BREAKPOINT_SIZE;
4395 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4398 * A placeholder for a possible breakpoint inserted by
4399 * mono_arch_set_breakpoint ().
4401 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4407 EMIT_UNCOND_BRANCH(ins);
4410 s390_br (code, ins->sreg1);
4416 s390_lghi(code, ins->dreg, 1);
4418 s390_lghi(code, ins->dreg, 0);
4424 s390_lghi(code, ins->dreg, 1);
4426 s390_lghi(code, ins->dreg, 0);
4432 s390_lghi(code, ins->dreg, 1);
4434 s390_lghi(code, ins->dreg, 0);
4440 s390_lghi(code, ins->dreg, 1);
4442 s390_lghi(code, ins->dreg, 0);
4448 s390_lghi(code, ins->dreg, 1);
4450 s390_lghi(code, ins->dreg, 0);
4453 case OP_COND_EXC_EQ:
4454 case OP_COND_EXC_IEQ:
4455 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4457 case OP_COND_EXC_NE_UN:
4458 case OP_COND_EXC_INE_UN:
4459 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4461 case OP_COND_EXC_LT:
4462 case OP_COND_EXC_ILT:
4463 case OP_COND_EXC_LT_UN:
4464 case OP_COND_EXC_ILT_UN:
4465 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4467 case OP_COND_EXC_GT:
4468 case OP_COND_EXC_IGT:
4469 case OP_COND_EXC_GT_UN:
4470 case OP_COND_EXC_IGT_UN:
4471 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4473 case OP_COND_EXC_GE:
4474 case OP_COND_EXC_IGE:
4475 case OP_COND_EXC_GE_UN:
4476 case OP_COND_EXC_IGE_UN:
4477 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4479 case OP_COND_EXC_LE:
4480 case OP_COND_EXC_ILE:
4481 case OP_COND_EXC_LE_UN:
4482 case OP_COND_EXC_ILE_UN:
4483 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4485 case OP_COND_EXC_OV:
4486 case OP_COND_EXC_IOV:
4487 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4489 case OP_COND_EXC_NO:
4490 case OP_COND_EXC_INO:
4491 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4494 case OP_COND_EXC_IC:
4495 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4497 case OP_COND_EXC_NC:
4498 case OP_COND_EXC_INC:
4499 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4503 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4507 EMIT_COND_BRANCH (ins, S390_CC_NE);
4513 EMIT_COND_BRANCH (ins, S390_CC_LT);
4519 EMIT_COND_BRANCH (ins, S390_CC_GT);
4525 EMIT_COND_BRANCH (ins, S390_CC_GE);
4531 EMIT_COND_BRANCH (ins, S390_CC_LE);
4534 /* floating point opcodes */
4536 if (*((double *) ins->inst_p0) == 0) {
4537 s390_lzdr (code, ins->dreg);
4539 s390_basr (code, s390_r13, 0);
4541 s390_llong (code, ins->inst_p0);
4542 s390_lg (code, s390_r13, 0, s390_r13, 4);
4543 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4548 if (*((float *) ins->inst_p0) == 0) {
4549 s390_lzdr (code, ins->dreg);
4551 s390_basr (code, s390_r13, 0);
4553 s390_llong(code, ins->inst_p0);
4554 s390_lg (code, s390_r13, 0, s390_r13, 4);
4555 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4559 case OP_STORER8_MEMBASE_REG: {
4560 S390_LONG (code, stdy, std, ins->sreg1, 0,
4561 ins->inst_destbasereg, ins->inst_offset);
4564 case OP_LOADR8_MEMBASE: {
4565 S390_LONG (code, ldy, ld, ins->dreg, 0,
4566 ins->inst_basereg, ins->inst_offset);
4569 case OP_STORER4_MEMBASE_REG: {
4570 s390_ledbr (code, s390_f15, ins->sreg1);
4571 S390_LONG (code, stey, ste, s390_f15, 0,
4572 ins->inst_destbasereg, ins->inst_offset);
4575 case OP_LOADR4_MEMBASE: {
4576 S390_LONG (code, ldy, ld, s390_f15, 0,
4577 ins->inst_basereg, ins->inst_offset);
4578 s390_ldebr (code, ins->dreg, s390_f15);
4581 case OP_ICONV_TO_R_UN: {
4582 s390_cdfbr (code, ins->dreg, ins->sreg1);
4583 s390_ltr (code, ins->sreg1, ins->sreg1);
4584 s390_jnl (code, 12);
4585 s390_basr (code, s390_r13, 0);
4587 s390_word (code, 0x41f00000);
4588 s390_word (code, 0);
4589 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4592 case OP_LCONV_TO_R_UN: {
4593 s390_cdgbr (code, ins->dreg, ins->sreg1);
4594 s390_ltgr (code, ins->sreg1, ins->sreg1);
4595 s390_jnl (code, 12);
4596 s390_basr (code, s390_r13, 0);
4598 s390_word (code, 0x41f00000);
4599 s390_word (code, 0);
4600 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4603 case OP_LCONV_TO_R4:
4604 case OP_ICONV_TO_R4: {
4605 s390_cdgbr (code, ins->dreg, ins->sreg1);
4608 case OP_LCONV_TO_R8:
4609 case OP_ICONV_TO_R8: {
4610 s390_cdgbr (code, ins->dreg, ins->sreg1);
4613 case OP_FCONV_TO_I1:
4614 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4616 case OP_FCONV_TO_U1:
4617 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4619 case OP_FCONV_TO_I2:
4620 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4622 case OP_FCONV_TO_U2:
4623 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4625 case OP_FCONV_TO_I4:
4627 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4629 case OP_FCONV_TO_U4:
4631 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4633 case OP_FCONV_TO_I8:
4634 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4636 case OP_LCONV_TO_OVF_I: {
4637 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4639 s390_ltgr (code, ins->sreg2, ins->sreg2);
4640 s390_jnl (code, 0); CODEPTR(code, o[0]);
4641 s390_ltgr (code, ins->sreg1, ins->sreg1);
4642 s390_jnl (code, 0); CODEPTR(code, o[1]);
4643 s390_lhi (code, s390_r13, -1);
4644 s390_cgr (code, ins->sreg1, s390_r13);
4645 s390_jnz (code, 0); CODEPTR(code, o[2]);
4646 if (ins->dreg != ins->sreg2)
4647 s390_lgr (code, ins->dreg, ins->sreg2);
4648 s390_j (code, 0); CODEPTR(code, o[3]);
4649 PTRSLOT(code, o[0]);
4650 s390_jz (code, 0); CODEPTR(code, o[4]);
4651 PTRSLOT(code, o[1]);
4652 PTRSLOT(code, o[2]);
4653 mono_add_patch_info (cfg, code - cfg->native_code,
4654 MONO_PATCH_INFO_EXC, "OverflowException");
4655 s390_brasl (code, s390_r14, 0);
4656 PTRSLOT(code, o[3]);
4657 PTRSLOT(code, o[4]);
4661 s390_lpdbr (code, ins->dreg, ins->sreg1);
4665 s390_sqdbr (code, ins->dreg, ins->sreg1);
4670 s390_adbr (code, ins->dreg, src2);
4674 CHECK_SRCDST_NCOM_F;
4675 s390_sdbr (code, ins->dreg, src2);
4680 s390_mdbr (code, ins->dreg, src2);
4684 CHECK_SRCDST_NCOM_F;
4685 s390_ddbr (code, ins->dreg, src2);
4689 s390_lcdbr (code, ins->dreg, ins->sreg1);
4693 CHECK_SRCDST_NCOM_F;
4694 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4698 s390_cdbr (code, ins->sreg1, ins->sreg2);
4702 s390_cdbr (code, ins->sreg1, ins->sreg2);
4703 s390_lghi (code, ins->dreg, 1);
4705 s390_lghi (code, ins->dreg, 0);
4709 s390_cdbr (code, ins->sreg1, ins->sreg2);
4710 s390_lghi (code, ins->dreg, 1);
4712 s390_lghi (code, ins->dreg, 0);
4716 s390_cdbr (code, ins->sreg1, ins->sreg2);
4717 s390_lghi (code, ins->dreg, 1);
4719 s390_lghi (code, ins->dreg, 0);
4723 s390_cdbr (code, ins->sreg1, ins->sreg2);
4724 s390_lghi (code, ins->dreg, 1);
4726 s390_lghi (code, ins->dreg, 0);
4730 s390_cdbr (code, ins->sreg1, ins->sreg2);
4731 s390_lghi (code, ins->dreg, 1);
4733 s390_lghi (code, ins->dreg, 0);
4738 s390_jo (code, 0); CODEPTR(code, o);
4739 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4744 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4748 s390_jo (code, 0); CODEPTR(code, o);
4749 EMIT_COND_BRANCH (ins, S390_CC_LT);
4754 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4758 s390_jo (code, 0); CODEPTR(code, o);
4759 EMIT_COND_BRANCH (ins, S390_CC_GT);
4764 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4768 s390_jo (code, 0); CODEPTR(code, o);
4769 EMIT_COND_BRANCH (ins, S390_CC_GE);
4774 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4778 s390_jo (code, 0); CODEPTR(code, o);
4779 EMIT_COND_BRANCH (ins, S390_CC_LE);
4784 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4788 s390_lhi (code, s390_r13, 0x7f);
4789 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4790 s390_jz (code, 0); CODEPTR(code, o);
4791 mono_add_patch_info (cfg, code - cfg->native_code,
4792 MONO_PATCH_INFO_EXC, "ArithmeticException");
4793 s390_brasl (code, s390_r14,0);
4797 case OP_S390_MOVE: {
4798 if (ins->backend.size > 0) {
4799 if (ins->backend.size <= 256) {
4800 s390_mvc (code, ins->backend.size, ins->dreg,
4801 ins->inst_offset, ins->sreg1, ins->inst_imm);
4803 s390_lgr (code, s390_r0, ins->dreg);
4804 if (ins->inst_offset > 0) {
4805 if (s390_is_imm16 (ins->inst_offset)) {
4806 s390_aghi (code, s390_r0, ins->inst_offset);
4808 s390_basr (code, s390_r13, 0);
4810 s390_llong(code, ins->inst_offset);
4811 s390_ag (code, s390_r0, 0, s390_r13, 4);
4814 s390_lgr (code, s390_r12, ins->sreg1);
4815 if (ins->inst_imm > 0) {
4816 if (s390_is_imm16 (ins->inst_imm)) {
4817 s390_aghi (code, s390_r12, ins->inst_imm);
4819 s390_basr (code, s390_r13, 0);
4821 s390_llong(code, ins->inst_imm);
4822 s390_ag (code, s390_r12, 0, s390_r13, 4);
4825 if (s390_is_imm16 (ins->backend.size)) {
4826 s390_lghi (code, s390_r1, ins->backend.size);
4828 s390_basr (code, s390_r13, 0);
4830 s390_llong(code, ins->backend.size);
4831 s390_lg (code, s390_r1, 0, s390_r13, 4);
4833 s390_lgr (code, s390_r13, s390_r1);
4834 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4840 case OP_ATOMIC_ADD_I8: {
4841 s390_lgr (code, s390_r1, ins->sreg2);
4842 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4843 s390_agr (code, s390_r1, s390_r0);
4844 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4845 s390_jnz (code, -10);
4846 s390_lgr (code, ins->dreg, s390_r1);
4849 case OP_ATOMIC_ADD_NEW_I8: {
4850 s390_lgr (code, s390_r1, ins->sreg2);
4851 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4852 s390_agr (code, s390_r1, s390_r0);
4853 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4854 s390_jnz (code, -10);
4855 s390_lgr (code, ins->dreg, s390_r1);
4858 case OP_ATOMIC_EXCHANGE_I8: {
4859 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4860 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4861 s390_jnz (code, -6);
4862 s390_lgr (code, ins->dreg, s390_r0);
4865 case OP_ATOMIC_ADD_I4: {
4866 s390_lgfr(code, s390_r1, ins->sreg2);
4867 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4868 s390_agr (code, s390_r1, s390_r0);
4869 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4870 s390_jnz (code, -9);
4871 s390_lgfr(code, ins->dreg, s390_r1);
4874 case OP_ATOMIC_ADD_NEW_I4: {
4875 s390_lgfr(code, s390_r1, ins->sreg2);
4876 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4877 s390_agr (code, s390_r1, s390_r0);
4878 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4879 s390_jnz (code, -9);
4880 s390_lgfr(code, ins->dreg, s390_r1);
4883 case OP_ATOMIC_EXCHANGE_I4: {
4884 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4885 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4886 s390_jnz (code, -4);
4887 s390_lgfr(code, ins->dreg, s390_r0);
4890 case OP_S390_BKCHAIN: {
4891 s390_lgr (code, ins->dreg, ins->sreg1);
4892 if (s390_is_imm16 (cfg->stack_offset)) {
4893 s390_aghi (code, ins->dreg, cfg->stack_offset);
4895 s390_basr (code, s390_r13, 0);
4897 s390_llong(code, cfg->stack_offset);
4898 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4902 case OP_MEMORY_BARRIER: {
4905 case OP_GC_LIVENESS_DEF:
4906 case OP_GC_LIVENESS_USE:
4907 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4908 ins->backend.pc_offset = code - cfg->native_code;
4910 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4911 ins->backend.pc_offset = code - cfg->native_code;
4912 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4915 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4916 g_assert_not_reached ();
4919 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4920 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4921 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4922 g_assert_not_reached ();
4927 last_offset = offset;
4930 cfg->code_len = code - cfg->native_code;
4933 /*========================= End of Function ========================*/
4935 /*------------------------------------------------------------------*/
4937 /* Name - mono_arch_register_lowlevel_calls */
4939 /* Function - Register routines to help with --trace operation. */
4941 /*------------------------------------------------------------------*/
4944 mono_arch_register_lowlevel_calls (void)
4948 /*========================= End of Function ========================*/
4950 /*------------------------------------------------------------------*/
4952 /* Name - mono_arch_patch_code */
4954 /* Function - Process the patch data created during the */
4955 /* instruction build process. This resolves jumps, */
4956 /* calls, variables etc. */
4958 /*------------------------------------------------------------------*/
4961 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4962 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4964 MonoJumpInfo *patch_info;
4966 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4967 unsigned char *ip = patch_info->ip.i + code;
4968 gconstpointer target = NULL;
4970 target = mono_resolve_patch_target (method, domain, code,
4971 patch_info, run_cctors);
4973 switch (patch_info->type) {
4974 case MONO_PATCH_INFO_IP:
4975 case MONO_PATCH_INFO_EXC_NAME:
4976 case MONO_PATCH_INFO_LDSTR:
4977 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4978 case MONO_PATCH_INFO_LDTOKEN:
4979 case MONO_PATCH_INFO_EXC:
4980 case MONO_PATCH_INFO_ABS:
4981 case MONO_PATCH_INFO_METHOD:
4982 case MONO_PATCH_INFO_INTERNAL_METHOD:
4983 case MONO_PATCH_INFO_CLASS_INIT:
4984 s390_patch_addr (ip, (guint64) target);
4986 case MONO_PATCH_INFO_SWITCH:
4987 /*----------------------------------*/
4988 /* ip points at the basr r13,0/j +4 */
4989 /* instruction the vtable value */
4990 /* follows this (i.e. ip+6) */
4991 /*----------------------------------*/
4992 *((gconstpointer *)(ip+6)) = target;
4994 case MONO_PATCH_INFO_METHODCONST:
4995 case MONO_PATCH_INFO_CLASS:
4996 case MONO_PATCH_INFO_IMAGE:
4997 case MONO_PATCH_INFO_FIELD:
4998 case MONO_PATCH_INFO_IID:
4999 target = S390_RELATIVE(target, ip);
5000 s390_patch_rel (ip, (guint64) target);
5002 case MONO_PATCH_INFO_R4:
5003 case MONO_PATCH_INFO_R8:
5004 case MONO_PATCH_INFO_METHOD_REL:
5005 g_assert_not_reached ();
5008 target = S390_RELATIVE(target, ip);
5010 s390_patch_rel (ip, (guint64) target);
5015 /*========================= End of Function ========================*/
5017 /*------------------------------------------------------------------*/
5019 /* Name - emit_load_volatile_arguments */
5021 /* Function - Emit the instructions to reload parameter regist- */
5022 /* registers for use with "tail" operations. */
5024 /* The register loading operations performed here */
5025 /* are the mirror of the store operations performed */
5026 /* in mono_arch_emit_prolog and need to be kept in */
5027 /* synchronization with it. */
5029 /*------------------------------------------------------------------*/
5032 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
5035 MonoMethod *method = cfg->method;
5036 MonoMethodSignature *sig = mono_method_signature(method);
5040 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
5042 if (cinfo->struct_ret) {
5043 ArgInfo *ainfo = &cinfo->ret;
5044 inst = cfg->vret_addr;
5045 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5048 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5049 ArgInfo *ainfo = cinfo->args + i;
5050 inst = cfg->args [pos];
5052 if (inst->opcode == OP_REGVAR) {
5053 if (ainfo->regtype == RegTypeGeneral)
5054 s390_lgr (code, ainfo->reg, inst->dreg);
5055 else if (ainfo->regtype == RegTypeFP) {
5056 if (inst->dreg != ainfo->reg) {
5057 if (ainfo->size == 4) {
5058 s390_ldebr (code, ainfo->reg, inst->dreg);
5060 s390_ldr (code, ainfo->reg, inst->dreg);
5064 else if (ainfo->regtype == RegTypeBase) {
5066 g_assert_not_reached ();
5068 if (ainfo->regtype == RegTypeGeneral) {
5069 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5070 g_assert_not_reached();
5071 switch (ainfo->size) {
5073 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5076 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5079 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5082 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5085 } else if (ainfo->regtype == RegTypeBase) {
5086 } else if (ainfo->regtype == RegTypeFP) {
5087 if (ainfo->size == 8)
5088 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5089 else if (ainfo->size == 4)
5090 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5092 g_assert_not_reached ();
5093 } else if (ainfo->regtype == RegTypeStructByVal) {
5094 if (ainfo->reg != STK_BASE) {
5095 switch (ainfo->size) {
5097 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5100 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5103 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5106 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5110 } else if (ainfo->regtype == RegTypeStructByAddr) {
5111 if (ainfo->reg != STK_BASE) {
5112 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5115 g_assert_not_reached ();
5123 /*========================= End of Function ========================*/
5125 /*------------------------------------------------------------------*/
5127 /* Name - mono_arch_emit_prolog */
5129 /* Function - Create the instruction sequence for a function */
5132 /*------------------------------------------------------------------*/
5135 mono_arch_emit_prolog (MonoCompile *cfg)
5137 MonoMethod *method = cfg->method;
5139 MonoMethodSignature *sig;
5141 long alloc_size, pos, max_offset, i, cfa_offset = 0;
5148 cfg->code_size = 512;
5150 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5152 cfg->code_size += 256;
5155 if (method->save_lmf)
5156 cfg->code_size += 200;
5158 cfg->native_code = code = g_malloc (cfg->code_size);
5160 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
5161 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
5162 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5163 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
5165 if (cfg->arch.bkchain_reg != -1)
5166 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
5168 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5169 cfg->used_int_regs |= 1 << 11;
5172 alloc_size = cfg->stack_offset;
5174 cfg->stack_usage = cfa_offset = alloc_size;
5175 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
5176 s390_lgr (code, s390_r11, STK_BASE);
5177 if (s390_is_imm16 (alloc_size)) {
5178 s390_aghi (code, STK_BASE, -alloc_size);
5180 int stackSize = alloc_size;
5181 while (stackSize > 32767) {
5182 s390_aghi (code, STK_BASE, -32767);
5185 s390_aghi (code, STK_BASE, -stackSize);
5187 s390_stg (code, s390_r11, 0, STK_BASE, 0);
5189 if (cfg->frame_reg != STK_BASE)
5190 s390_lgr (code, s390_r11, STK_BASE);
5192 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
5194 /* compute max_offset in order to use short forward jumps
5195 * we always do it on s390 because the immediate displacement
5196 * for jumps is too small
5199 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5201 bb->max_offset = max_offset;
5203 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5206 MONO_BB_FOR_EACH_INS (bb, ins)
5207 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5210 /* load arguments allocated to register from the stack */
5211 sig = mono_method_signature (method);
5214 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
5216 if (cinfo->struct_ret) {
5217 ArgInfo *ainfo = &cinfo->ret;
5218 inst = cfg->vret_addr;
5219 inst->backend.size = ainfo->vtsize;
5220 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5223 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5224 ArgInfo *ainfo = cinfo->args + i;
5225 inst = cfg->args [pos];
5227 if (inst->opcode == OP_VTARG_ADDR)
5228 inst = inst->inst_left;
5230 if (inst->opcode == OP_REGVAR) {
5231 if (ainfo->regtype == RegTypeGeneral)
5232 s390_lgr (code, inst->dreg, ainfo->reg);
5233 else if (ainfo->regtype == RegTypeFP) {
5234 if (inst->dreg != ainfo->reg) {
5235 if (ainfo->size == 4) {
5236 s390_ledbr (code, inst->dreg, ainfo->reg);
5238 s390_ldr (code, inst->dreg, ainfo->reg);
5242 else if (ainfo->regtype == RegTypeBase) {
5243 s390_lgr (code, s390_r13, STK_BASE);
5244 s390_aghi (code, s390_r13, alloc_size);
5245 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5247 g_assert_not_reached ();
5249 if (cfg->verbose_level > 2)
5250 g_print ("Argument %d assigned to register %s\n",
5251 pos, mono_arch_regname (inst->dreg));
5253 if (ainfo->regtype == RegTypeGeneral) {
5254 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5255 g_assert_not_reached();
5256 switch (ainfo->size) {
5258 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5261 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5264 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5267 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5270 } else if (ainfo->regtype == RegTypeBase) {
5271 } else if (ainfo->regtype == RegTypeFP) {
5272 if (ainfo->size == 8)
5273 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5274 else if (ainfo->size == 4)
5275 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5277 g_assert_not_reached ();
5278 } else if (ainfo->regtype == RegTypeStructByVal) {
5279 int doffset = inst->inst_offset;
5281 if (ainfo->reg != STK_BASE)
5285 s390_lgr (code, s390_r13, STK_BASE);
5286 s390_aghi (code, s390_r13, alloc_size);
5289 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5290 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5295 if (ainfo->reg == STK_BASE)
5296 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5297 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5300 if (ainfo->reg == STK_BASE)
5301 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5302 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5305 if (ainfo->reg == STK_BASE)
5306 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5307 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5310 if (ainfo->reg == STK_BASE)
5311 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5312 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5315 } else if (ainfo->regtype == RegTypeStructByAddr) {
5316 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5317 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5319 g_assert_not_reached ();
5324 if (method->save_lmf) {
5325 /*---------------------------------------------------------------*/
5326 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5327 /*---------------------------------------------------------------*/
5328 lmfOffset = alloc_size - sizeof(MonoLMF);
5330 s390_lgr (code, s390_r13, cfg->frame_reg);
5331 s390_aghi (code, s390_r13, lmfOffset);
5333 /*---------------------------------------------------------------*/
5334 /* Preserve the parameter registers while we fix up the lmf */
5335 /*---------------------------------------------------------------*/
5336 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5337 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5339 /*---------------------------------------------------------------*/
5340 /* On return from this call r2 have the address of the &lmf */
5341 /*---------------------------------------------------------------*/
5342 if (lmf_addr_tls_offset == -1) {
5343 s390_basr(code, s390_r14, 0);
5345 mono_add_patch_info (cfg, code - cfg->native_code,
5346 MONO_PATCH_INFO_INTERNAL_METHOD,
5347 (gpointer)"mono_get_lmf_addr");
5348 s390_llong(code, 0);
5349 s390_lg (code, s390_r1, 0, s390_r14, 4);
5350 s390_basr (code, s390_r14, s390_r1);
5352 /*-------------------------------------------------------*/
5353 /* Get LMF by getting value from thread level storage */
5354 /*-------------------------------------------------------*/
5355 s390_ear (code, s390_r1, 0);
5356 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5357 s390_ear (code, s390_r1, 1);
5358 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5361 /*---------------------------------------------------------------*/
5362 /* Set lmf.lmf_addr = jit_tls->lmf */
5363 /*---------------------------------------------------------------*/
5364 s390_stg (code, s390_r2, 0, s390_r13,
5365 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5367 /*---------------------------------------------------------------*/
5368 /* Get current lmf */
5369 /*---------------------------------------------------------------*/
5370 s390_lg (code, s390_r0, 0, s390_r2, 0);
5372 /*---------------------------------------------------------------*/
5373 /* Set our lmf as the current lmf */
5374 /*---------------------------------------------------------------*/
5375 s390_stg (code, s390_r13, 0, s390_r2, 0);
5377 /*---------------------------------------------------------------*/
5378 /* Have our lmf.previous_lmf point to the last lmf */
5379 /*---------------------------------------------------------------*/
5380 s390_stg (code, s390_r0, 0, s390_r13,
5381 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5383 /*---------------------------------------------------------------*/
5384 /* save method info */
5385 /*---------------------------------------------------------------*/
5386 s390_basr (code, s390_r1, 0);
5388 s390_llong (code, method);
5389 s390_lg (code, s390_r1, 0, s390_r1, 4);
5390 s390_stg (code, s390_r1, 0, s390_r13,
5391 G_STRUCT_OFFSET(MonoLMF, method));
5393 /*---------------------------------------------------------------*/
5394 /* save the current IP */
5395 /*---------------------------------------------------------------*/
5396 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5397 s390_basr (code, s390_r1, 0);
5398 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5400 /*---------------------------------------------------------------*/
5401 /* Save general and floating point registers */
5402 /*---------------------------------------------------------------*/
5403 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5404 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5405 for (i = 0; i < 16; i++) {
5406 s390_std (code, i, 0, s390_r13,
5407 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5410 /*---------------------------------------------------------------*/
5411 /* Restore the parameter registers now that we've set up the lmf */
5412 /*---------------------------------------------------------------*/
5413 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5414 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5418 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5420 cfg->code_len = code - cfg->native_code;
5421 g_assert (cfg->code_len < cfg->code_size);
5426 /*========================= End of Function ========================*/
5428 /*------------------------------------------------------------------*/
5430 /* Name - mono_arch_emit_epilog */
5432 /* Function - Emit the instructions for a function epilog. */
5434 /*------------------------------------------------------------------*/
5437 mono_arch_emit_epilog (MonoCompile *cfg)
5439 MonoMethod *method = cfg->method;
5442 int max_epilog_size = 96;
5444 if (cfg->method->save_lmf)
5445 max_epilog_size += 128;
5447 if (mono_jit_trace_calls != NULL)
5448 max_epilog_size += 128;
5450 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5451 max_epilog_size += 128;
5453 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5454 cfg->code_size *= 2;
5455 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5456 cfg->stat_code_reallocs++;
5459 code = cfg->native_code + cfg->code_len;
5461 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5462 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5466 if (method->save_lmf)
5467 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5469 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5470 // if (cfg->frame_reg != STK_BASE)
5471 // s390_lgr (code, STK_BASE, cfg->frame_reg);
5472 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5474 code = backUpStackPtr(cfg, code);
5476 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5477 s390_br (code, s390_r14);
5479 cfg->code_len = code - cfg->native_code;
5481 g_assert (cfg->code_len < cfg->code_size);
5485 /*========================= End of Function ========================*/
5487 /*------------------------------------------------------------------*/
5489 /* Name - mono_arch_emit_exceptions */
5491 /* Function - Emit the blocks to handle exception conditions. */
5493 /*------------------------------------------------------------------*/
5496 mono_arch_emit_exceptions (MonoCompile *cfg)
5498 MonoJumpInfo *patch_info;
5504 MonoClass *exc_classes [MAX_EXC];
5505 guint8 *exc_throw_start [MAX_EXC];
5507 for (patch_info = cfg->patch_info;
5509 patch_info = patch_info->next) {
5510 if (patch_info->type == MONO_PATCH_INFO_EXC)
5514 code_size = exc_count * 48;
5516 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5517 cfg->code_size *= 2;
5518 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5519 cfg->stat_code_reallocs++;
5522 code = cfg->native_code + cfg->code_len;
5524 /*---------------------------------------------------------------------*/
5525 /* Add code to raise exceptions */
5526 /*---------------------------------------------------------------------*/
5527 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5528 switch (patch_info->type) {
5529 case MONO_PATCH_INFO_EXC: {
5530 guint8 *ip = patch_info->ip.i + cfg->native_code;
5531 MonoClass *exc_class;
5534 /*-----------------------------------------------------*/
5535 /* Patch the branch in epilog to come here */
5536 /*-----------------------------------------------------*/
5537 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5539 exc_class = mono_class_from_name (mono_defaults.corlib,
5541 patch_info->data.name);
5542 g_assert (exc_class);
5543 throw_ip = patch_info->ip.i;
5545 for (iExc = 0; iExc < nThrows; ++iExc)
5546 if (exc_classes [iExc] == exc_class)
5549 if (iExc < nThrows) {
5550 s390_jcl (code, S390_CC_UN,
5551 (guint64) exc_throw_start [iExc]);
5552 patch_info->type = MONO_PATCH_INFO_NONE;
5555 if (nThrows < MAX_EXC) {
5556 exc_classes [nThrows] = exc_class;
5557 exc_throw_start [nThrows] = code;
5560 /*---------------------------------------------*/
5561 /* Patch the parameter passed to the handler */
5562 /*---------------------------------------------*/
5563 s390_basr (code, s390_r13, 0);
5565 // s390_llong(code, patch_info->data.target);
5566 s390_llong(code, exc_class->type_token);
5567 /*---------------------------------------------*/
5568 /* Load return address & parameter register */
5569 /*---------------------------------------------*/
5570 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5571 cfg->native_code + 8), code));
5572 s390_lg (code, s390_r2, 0, s390_r13, 4);
5573 /*---------------------------------------------*/
5574 /* Reuse the current patch to set the jump */
5575 /*---------------------------------------------*/
5576 s390_basr (code, s390_r13, 0);
5578 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5579 patch_info->data.name = "mono_arch_throw_corlib_exception";
5580 patch_info->ip.i = code - cfg->native_code;
5581 s390_llong(code, 0);
5582 s390_lg (code, s390_r1, 0, s390_r13, 4);
5583 s390_br (code, s390_r1);
5593 cfg->code_len = code - cfg->native_code;
5595 g_assert (cfg->code_len < cfg->code_size);
5599 /*========================= End of Function ========================*/
5601 /*------------------------------------------------------------------*/
5603 /* Name - mono_arch_finish_init */
5605 /* Function - Setup the JIT's Thread Level Specific Data. */
5607 /*------------------------------------------------------------------*/
5610 mono_arch_finish_init (void)
5612 appdomain_tls_offset = mono_domain_get_tls_offset();
5613 lmf_tls_offset = mono_get_lmf_tls_offset();
5614 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5617 /*========================= End of Function ========================*/
5619 /*------------------------------------------------------------------*/
5621 /* Name - mono_arch_free_jit_tls_data */
5623 /* Function - Free tls data. */
5625 /*------------------------------------------------------------------*/
5628 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5632 /*========================= End of Function ========================*/
5634 /*------------------------------------------------------------------*/
5636 /* Name - mono_arch_emit_inst_for_method */
5638 /*------------------------------------------------------------------*/
5641 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5646 /*========================= End of Function ========================*/
5648 /*------------------------------------------------------------------*/
5650 /* Name - mono_arch_decompose_opts */
5652 /* Function - Decompose opcode into a System z opcode. */
5654 /*------------------------------------------------------------------*/
5657 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5660 * Have to rename these to avoid being decomposed normally, since the normal
5661 * decomposition does not work on S390.
5663 switch (ins->opcode) {
5665 ins->opcode = OP_S390_ISUB_OVF;
5667 case OP_ISUB_OVF_UN:
5668 ins->opcode = OP_S390_ISUB_OVF_UN;
5671 ins->opcode = OP_S390_IADD_OVF;
5673 case OP_IADD_OVF_UN:
5674 ins->opcode = OP_S390_IADD_OVF_UN;
5677 ins->opcode = OP_S390_LADD_OVF;
5679 case OP_LADD_OVF_UN:
5680 ins->opcode = OP_S390_LADD_OVF_UN;
5683 ins->opcode = OP_S390_LSUB_OVF;
5685 case OP_LSUB_OVF_UN:
5686 ins->opcode = OP_S390_LSUB_OVF_UN;
5693 /*========================= End of Function ========================*/
5695 /*------------------------------------------------------------------*/
5697 /* Name - mono_arch_print_tree */
5699 /* Function - Print platform-specific opcode details. */
5701 /* Returns - 1 - opcode details have been printed */
5702 /* 0 - opcode details have not been printed */
5704 /*------------------------------------------------------------------*/
5707 mono_arch_print_tree (MonoInst *tree, int arity)
5711 switch (tree->opcode) {
5712 case OP_S390_LOADARG:
5713 case OP_S390_ARGREG:
5714 case OP_S390_ARGPTR:
5715 printf ("[0x%lx(%s)]", tree->inst_offset,
5716 mono_arch_regname (tree->inst_basereg));
5719 case OP_S390_STKARG:
5720 printf ("[0x%lx(previous_frame)]",
5725 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5726 tree->inst_offset, tree->backend.size,
5727 mono_arch_regname(tree->dreg),
5729 mono_arch_regname(tree->sreg1));
5732 case OP_S390_SETF4RET:
5733 printf ("[f%s,f%s]",
5734 mono_arch_regname (tree->dreg),
5735 mono_arch_regname (tree->sreg1));
5739 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5741 mono_arch_regname (tree->sreg1));
5744 case OP_S390_BKCHAIN:
5745 printf ("[previous_frame(%s)]",
5746 mono_arch_regname (tree->sreg1));
5754 /*========================= End of Function ========================*/
5756 /*------------------------------------------------------------------*/
5758 /* Name - mono_arch_regalloc_cost */
5760 /* Function - Determine the cost, in the number of memory */
5761 /* references, of the action of allocating the var- */
5762 /* iable VMV into a register during global register */
5765 /* Returns - Cost */
5767 /*------------------------------------------------------------------*/
5770 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5776 /*========================= End of Function ========================*/
5778 /*------------------------------------------------------------------*/
5780 /* Name - mono_arch_get_domain_intrinsic */
5786 /*------------------------------------------------------------------*/
5789 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5793 if (appdomain_tls_offset == -1)
5796 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5797 ins->inst_offset = appdomain_tls_offset;
5801 /*========================= End of Function ========================*/
5803 /*------------------------------------------------------------------*/
5805 /* Name - mono_arch_flush_register_windows */
5811 /*------------------------------------------------------------------*/
5814 mono_arch_flush_register_windows (void)
5818 /*========================= End of Function ========================*/
5820 /*------------------------------------------------------------------*/
5822 /* Name - mono_arch_is_inst_imm */
5824 /* Function - Determine if operand qualifies as an immediate */
5825 /* value. For s390 this is a value -32768-32768 */
5827 /* Returns - True|False - is [not] immediate value. */
5829 /*------------------------------------------------------------------*/
5832 mono_arch_is_inst_imm (gint64 imm)
5834 return s390_is_imm16 (imm);
5837 /*========================= End of Function ========================*/
5839 /*------------------------------------------------------------------*/
5841 /* Name - mono_arch_get_patch_offset */
5843 /* Function - Dummy entry point until s390x supports aot. */
5845 /* Returns - Offset for patch. */
5847 /*------------------------------------------------------------------*/
5850 mono_arch_get_patch_offset (guint8 *code)
5855 /*========================= End of Function ========================*/
5857 /*------------------------------------------------------------------*/
5859 /* Name - mono_arch_context_get_int_reg. */
5863 /* Returns - Return a register from the context. */
5865 /*------------------------------------------------------------------*/
5868 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5870 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5873 /*========================= End of Function ========================*/
5875 /*------------------------------------------------------------------*/
5877 /* Name - mono_arch_context_set_int_reg. */
5879 /* Function - Set a value in a specified register. */
5881 /*------------------------------------------------------------------*/
5884 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5886 ctx->uc_mcontext.gregs[reg] = val;
5889 /*========================= End of Function ========================*/
5891 /*------------------------------------------------------------------*/
5893 /* Name - mono_arch_get_this_arg_from_call. */
5897 /*------------------------------------------------------------------*/
5900 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5902 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5904 return (gpointer) lmf->gregs [s390_r2];
5907 /*========================= End of Function ========================*/
5909 /*------------------------------------------------------------------*/
5911 /* Name - get_delegate_invoke_impl. */
5915 /*------------------------------------------------------------------*/
5918 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5920 guint8 *code, *start;
5925 start = code = mono_global_codeman_reserve (size);
5927 /* Replace the this argument with the target */
5928 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5929 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5930 s390_br (code, s390_r1);
5931 g_assert ((code - start) <= size);
5933 mono_arch_flush_icache (start, size);
5937 size = 32 + param_count * 8;
5938 start = code = mono_global_codeman_reserve (size);
5940 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5941 /* slide down the arguments */
5942 for (i = 0; i < param_count; ++i) {
5943 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5945 s390_br (code, s390_r1);
5947 g_assert ((code - start) <= size);
5949 mono_arch_flush_icache (start, size);
5953 *code_len = code - start;
5958 /*========================= End of Function ========================*/
5960 /*------------------------------------------------------------------*/
5962 /* Name - mono_arch_get_delegate_invoke_impls. */
5966 /*------------------------------------------------------------------*/
5969 mono_arch_get_delegate_invoke_impls (void)
5976 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5977 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
5979 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5980 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5981 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
5987 /*========================= End of Function ========================*/
5989 /*------------------------------------------------------------------*/
5991 /* Name - mono_arch_get_delegate_invoke_impl. */
5995 /*------------------------------------------------------------------*/
5998 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
6000 guint8 *code, *start;
6002 /* FIXME: Support more cases */
6003 if (MONO_TYPE_ISSTRUCT (sig->ret))
6007 static guint8* cached = NULL;
6013 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
6015 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
6017 mono_memory_barrier ();
6021 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
6024 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
6026 for (i = 0; i < sig->param_count; ++i)
6027 if (!mono_is_regsize_var (sig->params [i]))
6031 code = cache [sig->param_count];
6035 if (mono_aot_only) {
6036 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
6037 start = mono_aot_get_trampoline (name);
6040 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
6043 mono_memory_barrier ();
6045 cache [sig->param_count] = start;
6050 /*========================= End of Function ========================*/
6052 /*------------------------------------------------------------------*/
6054 /* Name - mono_arch_build_imt_thunk. */
6058 /*------------------------------------------------------------------*/
6061 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
6062 MonoIMTCheckItem **imt_entries, int count,
6063 gpointer fail_tramp)
6067 guchar *code, *start;
6069 for (i = 0; i < count; ++i) {
6070 MonoIMTCheckItem *item = imt_entries [i];
6071 if (item->is_equals) {
6072 if (item->check_target_idx) {
6073 if (!item->compare_done)
6074 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6075 if (item->has_target_code)
6076 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
6078 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
6082 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
6084 if (!item->has_target_code)
6085 item->chunk_size += LOAD_SIZE;
6087 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
6088 #if ENABLE_WRONG_METHOD_CHECK
6089 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6094 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6095 imt_entries [item->check_target_idx]->compare_done = TRUE;
6097 size += item->chunk_size;
6101 code = mono_method_alloc_generic_virtual_thunk (domain, size);
6103 code = mono_domain_code_reserve (domain, size);
6107 for (i = 0; i < count; ++i) {
6108 MonoIMTCheckItem *item = imt_entries [i];
6109 item->code_target = (guint8 *) code;
6110 if (item->is_equals) {
6111 if (item->check_target_idx) {
6112 if (!item->compare_done) {
6113 s390_basr (code, s390_r13, s390_r0);
6115 s390_llong(code, item->key);
6116 s390_lg (code, s390_r0, 0, s390_r13, 4);
6117 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6119 item->jmp_code = (guint8*) code;
6120 s390_jcl (code, S390_CC_NE, 0);
6122 s390_basr (code, s390_r13, s390_r0);
6124 if (item->has_target_code) {
6125 s390_llong(code, item->value.target_code);
6126 s390_lg (code, s390_r1, 0, s390_r13, 4);
6128 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6129 s390_lg (code, s390_r1, 0, s390_r13, 4);
6130 s390_lg (code, s390_r1, 0, s390_r1, 0);
6132 s390_br (code, s390_r1);
6137 s390_basr (code, s390_r13, s390_r0);
6139 s390_llong(code, item->key);
6140 s390_lg (code, s390_r0, 0, s390_r13, 4);
6141 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6142 item->jmp_code = (guint8*) code;
6143 s390_jcl (code, S390_CC_NE, 0);
6144 s390_basr (code, s390_r13, s390_r0);
6146 if (item->has_target_code) {
6147 s390_llong(code, item->value.target_code);
6148 s390_lg (code, s390_r1, 0, s390_r13, 4);
6151 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6152 s390_lg (code, s390_r1, 0, s390_r13, 4);
6153 s390_lg (code, s390_r1, 0, s390_r1, 0);
6155 s390_br (code, s390_r1);
6156 target = S390_RELATIVE(code, item->jmp_code);
6157 s390_patch_rel(item->jmp_code+2, target);
6158 s390_basr (code, s390_r13, s390_r0);
6160 s390_llong(code, fail_tramp);
6161 s390_lg (code, s390_r1, 0, s390_r13, 4);
6162 s390_br (code, s390_r1);
6163 item->jmp_code = NULL;
6165 /* enable the commented code to assert on wrong method */
6166 #if ENABLE_WRONG_METHOD_CHECK
6167 g_assert_not_reached ();
6169 s390_basr (code, s390_r13, s390_r0);
6171 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6172 s390_lg (code, s390_r1, 0, s390_r13, 4);
6173 s390_lg (code, s390_r1, 0, s390_r1, 0);
6174 s390_br (code, s390_r1);
6175 #if ENABLE_WRONG_METHOD_CHECK
6176 g_assert_not_reached ();
6181 s390_basr (code, s390_r13, s390_r0);
6183 s390_llong(code, item->key);
6184 s390_lg (code, s390_r0, 0, s390_r13, 4);
6185 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6186 item->jmp_code = (guint8 *) code;
6187 s390_jcl (code, S390_CC_GE, 0);
6190 /* patch the branches to get to the target items */
6191 for (i = 0; i < count; ++i) {
6192 MonoIMTCheckItem *item = imt_entries [i];
6193 if (item->jmp_code) {
6194 if (item->check_target_idx) {
6196 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6198 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6203 mono_arch_flush_icache ((guint8*)start, (code - start));
6206 mono_stats.imt_thunks_size += (code - start);
6208 g_assert (code - start <= size);
6213 /*========================= End of Function ========================*/
6215 /*------------------------------------------------------------------*/
6217 /* Name - mono_arch_find_imt_method. */
6219 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6220 /* found in the save area. */
6222 /*------------------------------------------------------------------*/
6225 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6227 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
6229 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
6232 /*========================= End of Function ========================*/
6234 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6236 /*------------------------------------------------------------------*/
6238 /* Name - mono_arch_set_breakpoint. */
6240 /* Function - Set a breakpoint at the native code corresponding */
6241 /* to JI at NATIVE_OFFSET. The location should */
6242 /* contain code emitted by OP_SEQ_POINT. */
6244 /*------------------------------------------------------------------*/
6247 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6251 breakpointCode.pTrigger = bp_trigger_page;
6252 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6253 code += BREAKPOINT_SIZE;
6256 /*========================= End of Function ========================*/
6258 /*------------------------------------------------------------------*/
6260 /* Name - mono_arch_clear_breakpoint. */
6262 /* Function - Clear the breakpoint at IP. */
6264 /*------------------------------------------------------------------*/
6267 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6272 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6276 /*========================= End of Function ========================*/
6278 /*------------------------------------------------------------------*/
6280 /* Name - mono_arch_is_breakpoint_event. */
6284 /*------------------------------------------------------------------*/
6287 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6289 siginfo_t* sinfo = (siginfo_t*) info;
6290 /* Sometimes the address is off by 4 */
6291 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6297 /*========================= End of Function ========================*/
6299 /*------------------------------------------------------------------*/
6301 /* Name - mono_arch_skip_breakpoint. */
6303 /* Function - Modify the CTX so the IP is placed after the */
6304 /* breakpoint instruction, so when we resume, the */
6305 /* instruction is not executed again. */
6307 /*------------------------------------------------------------------*/
6310 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6312 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6315 /*========================= End of Function ========================*/
6317 /*------------------------------------------------------------------*/
6319 /* Name - mono_arch_start_single_stepping. */
6321 /* Function - Start single stepping. */
6323 /*------------------------------------------------------------------*/
6326 mono_arch_start_single_stepping (void)
6328 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6331 /*========================= End of Function ========================*/
6333 /*------------------------------------------------------------------*/
6335 /* Name - mono_arch_stop_single_stepping. */
6337 /* Function - Stop single stepping. */
6339 /*------------------------------------------------------------------*/
6342 mono_arch_stop_single_stepping (void)
6344 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6347 /*========================= End of Function ========================*/
6349 /*------------------------------------------------------------------*/
6351 /* Name - mono_arch_is_single_step_event. */
6353 /* Function - Return whether the machine state in sigctx cor- */
6354 /* responds to a single step event. */
6356 /*------------------------------------------------------------------*/
6359 mono_arch_is_single_step_event (void *info, void *sigctx)
6361 siginfo_t* sinfo = (siginfo_t*) info;
6363 /* Sometimes the address is off by 4 */
6364 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6370 /*========================= End of Function ========================*/
6372 /*------------------------------------------------------------------*/
6374 /* Name - mono_arch_skip_single_step. */
6376 /* Function - Modify the ctx so the IP is placed after the */
6377 /* single step trigger instruction, so that the */
6378 /* instruction is not executed again. */
6380 /*------------------------------------------------------------------*/
6383 mono_arch_skip_single_step (MonoContext *ctx)
6385 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6388 /*========================= End of Function ========================*/
6390 /*------------------------------------------------------------------*/
6392 /* Name - mono_arch_create_seq_point_info. */
6394 /* Function - Return a pointer to a data struction which is */
6395 /* used by the sequence point implementation in */
6398 /*------------------------------------------------------------------*/
6401 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6407 /*========================= End of Function ========================*/