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 #define mono_mini_arch_lock() EnterCriticalSection (&mini_arch_mutex)
250 #define mono_mini_arch_unlock() LeaveCriticalSection (&mini_arch_mutex)
252 /*========================= End of Defines =========================*/
254 /*------------------------------------------------------------------*/
255 /* I n c l u d e s */
256 /*------------------------------------------------------------------*/
261 #include <mono/metadata/appdomain.h>
262 #include <mono/metadata/debug-helpers.h>
263 #include <mono/metadata/profiler-private.h>
264 #include <mono/utils/mono-math.h>
265 #include <mono/utils/mono-mmap.h>
266 #include <mono/utils/mono-hwcap-s390x.h>
268 #include "mini-s390x.h"
269 #include "cpu-s390x.h"
270 #include "jit-icalls.h"
274 /*========================= End of Includes ========================*/
276 /*------------------------------------------------------------------*/
277 /* T y p e d e f s */
278 /*------------------------------------------------------------------*/
290 /*------------------------------------------------------------------*/
291 /* Used by the instrument_emit_epilog */
292 /*------------------------------------------------------------------*/
303 typedef struct InstList InstList;
317 RegTypeStructByValInFP,
319 RegTypeStructByAddrOnStack
323 gint32 offset; /* offset from caller's stack */
324 gint32 offparm; /* offset from callee's stack */
325 guint16 vtsize; /* in param area */
328 guint32 size; /* Size of structure used by RegTypeStructByVal */
329 gint32 type; /* Data type of argument */
345 gint64 gr[5]; /* R2-R6 */
346 gdouble fp[3]; /* F0-F2 */
347 } __attribute__ ((packed)) RegParm;
355 } __attribute__ ((packed)) breakpoint_t;
357 /*========================= End of Typedefs ========================*/
359 /*------------------------------------------------------------------*/
360 /* P r o t o t y p e s */
361 /*------------------------------------------------------------------*/
363 static void indent (int);
364 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
365 static void decodeParm (MonoType *, void *, int);
366 static void enter_method (MonoMethod *, RegParm *, char *);
367 static void leave_method (MonoMethod *, ...);
368 static gboolean is_regsize_var (MonoType *);
369 static inline void add_general (guint *, size_data *, ArgInfo *);
370 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
371 static inline void add_float (guint *, size_data *, ArgInfo *);
372 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
373 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
374 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
375 static void catch_SIGILL(int, siginfo_t *, void *);
376 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
378 /*========================= End of Prototypes ======================*/
380 /*------------------------------------------------------------------*/
381 /* G l o b a l V a r i a b l e s */
382 /*------------------------------------------------------------------*/
384 int mono_exc_esp_offset = 0;
386 static int indent_level = 0;
388 static gint appdomain_tls_offset = -1,
390 lmf_addr_tls_offset = -1;
392 pthread_key_t lmf_addr_key;
394 gboolean lmf_addr_key_inited = FALSE;
400 extern __thread MonoDomain *tls_appdomain;
401 extern __thread MonoThread *tls_current_object;
402 extern __thread gpointer mono_lmf_addr;
407 * The code generated for sequence points reads from this location,
408 * which is made read-only when single stepping is enabled.
410 static gpointer ss_trigger_page;
413 * Enabled breakpoints read from this trigger page
415 static gpointer bp_trigger_page;
417 breakpoint_t breakpointCode;
420 * This mutex protects architecture specific caches
422 static CRITICAL_SECTION mini_arch_mutex;
424 /*====================== End of Global Variables ===================*/
426 /*------------------------------------------------------------------*/
428 /* Name - mono_arch_regname */
430 /* Function - Returns the name of the register specified by */
431 /* the input parameter. */
433 /*------------------------------------------------------------------*/
436 mono_arch_regname (int reg) {
437 static const char * rnames[] = {
438 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
439 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
440 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
444 if (reg >= 0 && reg < 16)
450 /*========================= End of Function ========================*/
452 /*------------------------------------------------------------------*/
454 /* Name - mono_arch_fregname */
456 /* Function - Returns the name of the register specified by */
457 /* the input parameter. */
459 /*------------------------------------------------------------------*/
462 mono_arch_fregname (int reg) {
463 static const char * rnames[] = {
464 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
465 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
466 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
470 if (reg >= 0 && reg < 16)
476 /*========================= End of Function ========================*/
478 /*------------------------------------------------------------------*/
480 /* Name - arch_get_argument_info */
482 /* Function - Gathers information on parameters such as size, */
483 /* alignment, and padding. arg_info should be large */
484 /* enough to hold param_count + 1 entries. */
486 /* Parameters - @csig - Method signature */
487 /* @param_count - No. of parameters to consider */
488 /* @arg_info - An array to store the result info */
490 /* Returns - Size of the activation frame */
492 /*------------------------------------------------------------------*/
495 mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig,
497 MonoJitArgumentInfo *arg_info)
499 int k, frame_size = 0;
500 int size, align, pad;
503 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
504 frame_size += sizeof (gpointer);
508 arg_info [0].offset = offset;
511 frame_size += sizeof (gpointer);
515 arg_info [0].size = frame_size;
517 for (k = 0; k < param_count; k++) {
520 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
522 size = mini_type_stack_size (NULL, csig->params [k], &align);
524 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
525 arg_info [k].pad = pad;
527 arg_info [k + 1].pad = 0;
528 arg_info [k + 1].size = size;
530 arg_info [k + 1].offset = offset;
534 align = MONO_ARCH_FRAME_ALIGNMENT;
535 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
536 arg_info [k].pad = pad;
541 /*========================= End of Function ========================*/
543 /*------------------------------------------------------------------*/
545 /* Name - emit_unwind_regs. */
547 /* Function - Determines if a value can be returned in one or */
550 /*------------------------------------------------------------------*/
552 static void __inline__
553 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
557 for (i = start; i < end; i++) {
558 mono_emit_unwind_op_offset (cfg, code, i, offset);
559 offset += sizeof(gulong);
563 /*========================= End of Function ========================*/
565 /*------------------------------------------------------------------*/
567 /* Name - retFitsInReg. */
569 /* Function - Determines if a value can be returned in one or */
572 /*------------------------------------------------------------------*/
574 static inline gboolean
575 retFitsInReg(guint32 size)
590 /*========================= End of Function ========================*/
592 /*------------------------------------------------------------------*/
594 /* Name - backStackPtr. */
596 /* Function - Restore Stack Pointer to previous frame. */
598 /*------------------------------------------------------------------*/
600 static inline guint8 *
601 backUpStackPtr(MonoCompile *cfg, guint8 *code)
603 int stackSize = cfg->stack_usage;
605 if (cfg->frame_reg != STK_BASE)
606 s390_lgr (code, STK_BASE, cfg->frame_reg);
608 if (s390_is_imm16 (stackSize)) {
609 s390_aghi (code, STK_BASE, stackSize);
611 while (stackSize > 32767) {
612 s390_aghi (code, STK_BASE, 32767);
615 s390_aghi (code, STK_BASE, stackSize);
620 /*========================= End of Function ========================*/
622 /*------------------------------------------------------------------*/
626 /* Function - Perform nice indenting to current level */
628 /*------------------------------------------------------------------*/
634 indent_level += diff;
641 indent_level += diff;
644 /*========================= End of Function ========================*/
646 /*------------------------------------------------------------------*/
648 /* Name - cvtMonoType */
650 /* Function - Convert a mono-type to a string. */
652 /*------------------------------------------------------------------*/
655 cvtMonoType(MonoTypeEnum t)
660 return "MONO_TYPE_END";
662 return "MONO_TYPE_VOID";
663 case MONO_TYPE_BOOLEAN:
664 return "MONO_TYPE_BOOLEAN";
666 return "MONO_TYPE_CHAR";
668 return "MONO_TYPE_I1";
670 return "MONO_TYPE_U1";
672 return "MONO_TYPE_I2";
674 return "MONO_TYPE_U2";
676 return "MONO_TYPE_I4";
678 return "MONO_TYPE_U4";
680 return "MONO_TYPE_I8";
682 return "MONO_TYPE_U8";
684 return "MONO_TYPE_R4";
686 return "MONO_TYPE_R8";
687 case MONO_TYPE_STRING:
688 return "MONO_TYPE_STRING";
690 return "MONO_TYPE_PTR";
691 case MONO_TYPE_BYREF:
692 return "MONO_TYPE_BYREF";
693 case MONO_TYPE_VALUETYPE:
694 return "MONO_TYPE_VALUETYPE";
695 case MONO_TYPE_CLASS:
696 return "MONO_TYPE_CLASS";
698 return "MONO_TYPE_VAR";
699 case MONO_TYPE_ARRAY:
700 return "MONO_TYPE_ARRAY";
701 case MONO_TYPE_GENERICINST:
702 return "MONO_TYPE_GENERICINST";
703 case MONO_TYPE_TYPEDBYREF:
704 return "MONO_TYPE_TYPEDBYREF";
706 return "MONO_TYPE_I";
708 return "MONO_TYPE_U";
709 case MONO_TYPE_FNPTR:
710 return "MONO_TYPE_FNPTR";
711 case MONO_TYPE_OBJECT:
712 return "MONO_TYPE_OBJECT";
713 case MONO_TYPE_SZARRAY:
714 return "MONO_TYPE_SZARRAY";
716 return "MONO_TYPE_MVAR";
717 case MONO_TYPE_CMOD_REQD:
718 return "MONO_TYPE_CMOD_REQD";
719 case MONO_TYPE_CMOD_OPT:
720 return "MONO_TYPE_CMOD_OPT";
721 case MONO_TYPE_INTERNAL:
722 return "MONO_TYPE_INTERNAL";
723 case MONO_TYPE_MODIFIER:
724 return "MONO_TYPE_MODIFIER";
725 case MONO_TYPE_SENTINEL:
726 return "MONO_TYPE_SENTINEL";
727 case MONO_TYPE_PINNED:
728 return "MONO_TYPE_PINNED";
735 /*========================= End of Function ========================*/
737 /*------------------------------------------------------------------*/
739 /* Name - decodeParm */
741 /* Function - Decode a parameter for the trace. */
743 /*------------------------------------------------------------------*/
746 decodeParm(MonoType *type, void *curParm, int size)
751 printf("[BYREF:%p], ", *((char **) curParm));
753 simpleType = mono_type_get_underlying_type(type)->type;
755 switch (simpleType) {
757 printf ("[INTPTR:%p], ", *((int **) curParm));
760 printf ("[UINTPTR:%p], ", *((int **) curParm));
762 case MONO_TYPE_BOOLEAN :
763 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
765 case MONO_TYPE_CHAR :
766 printf ("[CHAR:%c], ", *((int *) curParm));
769 printf ("[INT1:%ld], ", *((gint64 *) curParm));
772 printf ("[INT2:%ld], ", *((gint64 *) curParm));
775 printf ("[INT4:%ld], ", *((gint64 *) curParm));
778 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
781 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
784 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
787 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
789 case MONO_TYPE_STRING : {
790 MonoString *s = *((MonoString **) curParm);
792 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
793 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
795 printf("[STRING:null], ");
799 case MONO_TYPE_CLASS :
800 case MONO_TYPE_OBJECT : {
801 MonoObject *obj = *((MonoObject **) curParm);
803 if ((obj) && (obj->vtable)) {
804 printf("[CLASS/OBJ:");
805 class = obj->vtable->klass;
806 printf("%p [%p] ",obj,curParm);
807 if (class == mono_defaults.string_class) {
808 printf("[STRING:%p:%s]",
809 obj, mono_string_to_utf8 ((MonoString *) obj));
810 } else if (class == mono_defaults.int32_class) {
811 printf("[INT32:%p:%d]",
812 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
815 class->name_space, class->name, obj);
818 printf("[OBJECT:null], ");
823 printf("[PTR:%p], ", *((gpointer **) (curParm)));
825 case MONO_TYPE_FNPTR :
826 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
828 case MONO_TYPE_ARRAY :
829 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
831 case MONO_TYPE_SZARRAY :
832 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
835 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
838 printf("[FLOAT4:%g], ", *((float *) (curParm)));
841 printf("[FLOAT8:%g], ", *((double *) (curParm)));
843 case MONO_TYPE_VALUETYPE : {
845 MonoMarshalType *info;
847 if (type->data.klass->enumtype) {
848 simpleType = mono_class_enum_basetype (type->data.klass)->type;
849 printf("{VALUETYPE} - ");
853 info = mono_marshal_load_type_info (type->data.klass);
855 if ((info->native_size == sizeof(float)) &&
856 (info->num_fields == 1) &&
857 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
858 printf("[FLOAT4:%f], ", *((float *) (curParm)));
862 if ((info->native_size == sizeof(double)) &&
863 (info->num_fields == 1) &&
864 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
865 printf("[FLOAT8:%g], ", *((double *) (curParm)));
869 printf("[VALUETYPE:");
870 for (i = 0; i < size; i++)
871 printf("%02x,", *((guint8 *)curParm+i));
875 case MONO_TYPE_TYPEDBYREF: {
877 printf("[TYPEDBYREF:");
878 for (i = 0; i < size; i++)
879 printf("%02x,", *((guint8 *)curParm+i));
884 printf("[%s], ",cvtMonoType(simpleType));
889 /*========================= End of Function ========================*/
891 /*------------------------------------------------------------------*/
893 /* Name - enter_method */
895 /* Function - Perform tracing of the entry to the current */
898 /*------------------------------------------------------------------*/
901 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
903 int i, oParm = 0, iParm = 0;
906 MonoMethodSignature *sig;
913 fname = mono_method_full_name (method, TRUE);
915 printf ("ENTER: %s ", fname);
918 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
919 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
924 sig = mono_method_signature (method);
926 cinfo = get_call_info (NULL, NULL, sig);
928 if (cinfo->struct_ret) {
929 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
934 gpointer *this = (gpointer *) rParm->gr[iParm];
935 obj = (MonoObject *) this;
936 switch(method->klass->this_arg.type) {
937 case MONO_TYPE_VALUETYPE:
939 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
940 printf("this:[value:%p:%016lx], ", this, *value);
942 printf ("this:[NULL], ");
944 case MONO_TYPE_STRING:
947 class = obj->vtable->klass;
948 if (class == mono_defaults.string_class) {
949 printf ("this:[STRING:%p:%s], ",
950 obj, mono_string_to_utf8 ((MonoString *)obj));
952 printf ("this:%p[%s.%s], ",
953 obj, class->name_space, class->name);
956 printf("vtable:[NULL], ");
958 printf ("this:[NULL], ");
961 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
966 for (i = 0; i < sig->param_count; ++i) {
967 ainfo = &cinfo->args[i + oParm];
968 switch (ainfo->regtype) {
969 case RegTypeGeneral :
970 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
973 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
976 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
978 case RegTypeStructByVal :
979 if (ainfo->reg != STK_BASE) {
980 int offset = sizeof(glong) - ainfo->size;
981 curParm = &(rParm->gr[ainfo->reg-2])+offset;
984 curParm = sp+ainfo->offset;
986 if (retFitsInReg (ainfo->vtsize))
987 decodeParm(sig->params[i],
991 decodeParm(sig->params[i],
992 *((char **) curParm),
995 case RegTypeStructByAddr :
996 if (ainfo->reg != STK_BASE)
997 curParm = &(rParm->gr[ainfo->reg-2]);
999 curParm = sp+ainfo->offset;
1001 decodeParm(sig->params[i],
1002 *((char **) curParm),
1014 /*========================= End of Function ========================*/
1016 /*------------------------------------------------------------------*/
1018 /* Name - leave_method */
1022 /*------------------------------------------------------------------*/
1025 leave_method (MonoMethod *method, ...)
1032 va_start(ap, method);
1034 fname = mono_method_full_name (method, TRUE);
1036 printf ("LEAVE: %s", fname);
1039 type = mono_method_signature (method)->ret;
1042 switch (type->type) {
1043 case MONO_TYPE_VOID:
1045 case MONO_TYPE_BOOLEAN: {
1046 int val = va_arg (ap, int);
1048 printf ("[TRUE:%d]", val);
1054 case MONO_TYPE_CHAR: {
1055 int val = va_arg (ap, int);
1056 printf ("[CHAR:%d]", val);
1059 case MONO_TYPE_I1: {
1060 int val = va_arg (ap, int);
1061 printf ("[INT1:%d]", val);
1064 case MONO_TYPE_U1: {
1065 int val = va_arg (ap, int);
1066 printf ("[UINT1:%d]", val);
1069 case MONO_TYPE_I2: {
1070 int val = va_arg (ap, int);
1071 printf ("[INT2:%d]", val);
1074 case MONO_TYPE_U2: {
1075 int val = va_arg (ap, int);
1076 printf ("[UINT2:%d]", val);
1079 case MONO_TYPE_I4: {
1080 int val = va_arg (ap, int);
1081 printf ("[INT4:%d]", val);
1084 case MONO_TYPE_U4: {
1085 int val = va_arg (ap, int);
1086 printf ("[UINT4:%d]", val);
1090 gint64 val = va_arg (ap, gint64);
1091 printf ("[INT:%ld]", val);
1096 gint64 val = va_arg (ap, gint64);
1097 printf ("[UINT:%lu]", val);
1101 case MONO_TYPE_STRING: {
1102 MonoString *s = va_arg (ap, MonoString *);
1105 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1106 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1108 printf ("[STRING:null], ");
1111 case MONO_TYPE_CLASS:
1112 case MONO_TYPE_OBJECT: {
1113 MonoObject *o = va_arg (ap, MonoObject *);
1115 if ((o) && (o->vtable)) {
1116 if (o->vtable->klass == mono_defaults.boolean_class) {
1117 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1118 } else if (o->vtable->klass == mono_defaults.int32_class) {
1119 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1120 } else if (o->vtable->klass == mono_defaults.int64_class) {
1121 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1123 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1125 printf ("[OBJECT:%p]", o);
1130 case MONO_TYPE_FNPTR:
1131 case MONO_TYPE_ARRAY:
1132 case MONO_TYPE_SZARRAY: {
1133 gpointer p = va_arg (ap, gpointer);
1134 printf ("[result=%p]", p);
1137 case MONO_TYPE_I8: {
1138 gint64 l = va_arg (ap, gint64);
1139 printf ("[LONG:%ld]", l);
1142 case MONO_TYPE_U8: {
1143 guint64 l = va_arg (ap, guint64);
1144 printf ("[ULONG:%lu]", l);
1147 case MONO_TYPE_R4: {
1148 double f = va_arg (ap, double);
1149 printf ("[FLOAT4:%g]\n", f);
1152 case MONO_TYPE_R8: {
1153 double f = va_arg (ap, double);
1154 printf ("[FLOAT8:%g]\n", f);
1157 case MONO_TYPE_VALUETYPE: {
1158 MonoMarshalType *info;
1159 if (type->data.klass->enumtype) {
1160 type = mono_class_enum_basetype (type->data.klass);
1165 info = mono_marshal_load_type_info (type->data.klass);
1167 if ((info->native_size == sizeof(float)) &&
1168 (info->num_fields == 1) &&
1169 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1170 double f = va_arg (ap, double);
1171 printf("[FLOAT4:%g]\n", (double) f);
1175 if ((info->native_size == sizeof(double)) &&
1176 (info->num_fields == 1) &&
1177 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1178 double f = va_arg (ap, double);
1179 printf("[FLOAT8:%g]\n", f);
1183 size = mono_type_size (type, &align);
1186 guint32 p = va_arg (ap, guint32);
1187 printf ("[%02x]\n",p);
1191 guint32 p = va_arg (ap, guint32);
1192 printf ("[%04x]\n",p);
1196 guint32 p = va_arg (ap, guint32);
1197 printf ("[%08x]\n",p);
1201 guint64 p = va_arg (ap, guint64);
1202 printf ("[%016lx]\n",p);
1206 gpointer p = va_arg (ap, gpointer);
1207 printf ("[VALUETYPE] %p\n",p);
1213 case MONO_TYPE_TYPEDBYREF: {
1214 guint8 *p = va_arg (ap, gpointer);
1216 size = mono_type_size (type, &align);
1223 for (j = 0; p && j < size; j++)
1224 printf ("%02x,", p [j]);
1228 printf ("[TYPEDBYREF]\n");
1233 printf ("(unknown return type %x)",
1234 mono_method_signature (method)->ret->type);
1237 ip = ((gint64) __builtin_return_address (0));
1238 printf (" ip: %p\n", (gpointer) ip);
1241 /*========================= End of Function ========================*/
1243 /*------------------------------------------------------------------*/
1245 /* Name - mono_arch_cpu_init */
1247 /* Function - Perform CPU specific initialization to execute */
1250 /*------------------------------------------------------------------*/
1253 mono_arch_cpu_init (void)
1257 /*========================= End of Function ========================*/
1259 /*------------------------------------------------------------------*/
1261 /* Name - mono_arch_init. */
1263 /* Function - Initialize architecture specific code. */
1265 /*------------------------------------------------------------------*/
1268 mono_arch_init (void)
1274 * When we do an architectural level set at z9 or better
1275 * we can use the STFLE instruction to show us
1276 * what hardware facilities are available
1278 int lFacility = sizeof(facs) % 8;
1280 memset((char *) &facs, 0, sizeof(facs));
1282 __asm__ (" lgfr 0,%1\n"
1284 : "=m" (facs) : "r" (lFacility) : "0", "cc");
1287 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1288 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1289 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1291 code = (guint8 *) &breakpointCode;
1292 s390_basr(code, s390_r13, 0);
1294 s390_llong(code, 0);
1295 s390_lg(code, s390_r13, 0, s390_r13, 4);
1296 s390_lg(code, s390_r0, 0, s390_r13, 0);
1299 /*========================= End of Function ========================*/
1301 /*------------------------------------------------------------------*/
1303 /* Name - mono_arch_cleanup. */
1305 /* Function - Cleanup architecture specific code . */
1307 /*------------------------------------------------------------------*/
1310 mono_arch_cleanup (void)
1314 /*========================= End of Function ========================*/
1316 /*------------------------------------------------------------------*/
1318 /* Name - mono_arch_cpu_optimizations */
1320 /* Function - Returns the optimizations supported on this CPU */
1322 /*------------------------------------------------------------------*/
1325 mono_arch_cpu_optimizations (guint32 *exclude_mask)
1329 /*----------------------------------------------------------*/
1330 /* No s390-specific optimizations yet */
1331 /*----------------------------------------------------------*/
1332 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1333 // *exclude_mask = MONO_OPT_INLINE;
1337 /*========================= End of Function ========================*/
1339 /*------------------------------------------------------------------*/
1341 /* Name - mono_arch_cpu_enumerate_simd_versions */
1343 /* Function - Returns the SIMD instruction sets on this CPU */
1345 /*------------------------------------------------------------------*/
1347 mono_arch_cpu_enumerate_simd_versions (void)
1349 /* SIMD is currently unimplemented */
1352 /*========================= End of Function ========================*/
1354 /*------------------------------------------------------------------*/
1360 /*------------------------------------------------------------------*/
1363 is_regsize_var (MonoType *t) {
1366 switch (mono_type_get_underlying_type (t)->type) {
1374 case MONO_TYPE_FNPTR:
1376 case MONO_TYPE_OBJECT:
1377 case MONO_TYPE_STRING:
1378 case MONO_TYPE_CLASS:
1379 case MONO_TYPE_SZARRAY:
1380 case MONO_TYPE_ARRAY:
1382 case MONO_TYPE_VALUETYPE:
1383 if (t->data.klass->enumtype)
1384 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1390 /*========================= End of Function ========================*/
1392 /*------------------------------------------------------------------*/
1394 /* Name - mono_arch_get_allocatable_int_vars */
1398 /*------------------------------------------------------------------*/
1401 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1406 for (i = 0; i < cfg->num_varinfo; i++) {
1407 MonoInst *ins = cfg->varinfo [i];
1408 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1411 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1414 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1415 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1418 /* we can only allocate 32 bit values */
1419 if (is_regsize_var (ins->inst_vtype)) {
1420 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1421 g_assert (i == vmv->idx);
1422 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1429 /*========================= End of Function ========================*/
1431 /*------------------------------------------------------------------*/
1433 /* Name - mono_arch_global_int_regs */
1435 /* Function - Return a list of usable integer registers. */
1437 /*------------------------------------------------------------------*/
1440 mono_arch_get_global_int_regs (MonoCompile *cfg)
1443 MonoMethodHeader *header;
1446 header = cfg->header;
1447 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1448 cfg->frame_reg = s390_r11;
1451 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1453 for (i = 8; i < top; ++i) {
1454 if (cfg->frame_reg != i)
1455 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1461 /*========================= End of Function ========================*/
1463 /*------------------------------------------------------------------*/
1465 /* Name - mono_arch_flush_icache */
1467 /* Function - Flush the CPU icache. */
1469 /*------------------------------------------------------------------*/
1472 mono_arch_flush_icache (guint8 *code, gint size)
1476 /*========================= End of Function ========================*/
1478 /*------------------------------------------------------------------*/
1480 /* Name - add_general */
1482 /* Function - Determine code and stack size incremements for a */
1485 /*------------------------------------------------------------------*/
1488 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1490 if (*gr > S390_LAST_ARG_REG) {
1491 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1492 ainfo->offset = sz->stack_size;
1493 ainfo->reg = STK_BASE;
1494 ainfo->regtype = RegTypeBase;
1495 sz->stack_size += sizeof(long);
1496 sz->local_size += sizeof(long);
1497 sz->offStruct += sizeof(long);
1498 sz->code_size += 12;
1506 /*========================= End of Function ========================*/
1508 /*------------------------------------------------------------------*/
1510 /* Name - add_stackParm */
1512 /* Function - Determine code and stack size incremements for a */
1515 /*------------------------------------------------------------------*/
1518 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1520 if (*gr > S390_LAST_ARG_REG) {
1521 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1522 ainfo->reg = STK_BASE;
1523 ainfo->offset = sz->stack_size;
1524 ainfo->regtype = RegTypeStructByAddrOnStack;
1525 sz->stack_size += sizeof (gpointer);
1526 sz->parm_size += sizeof(gpointer);
1527 sz->offStruct += sizeof(gpointer);
1530 ainfo->offset = sz->stack_size;
1531 ainfo->regtype = RegTypeStructByAddr;
1534 ainfo->offparm = sz->offset;
1535 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1537 ainfo->vtsize = size;
1538 sz->parm_size += size;
1541 /*========================= End of Function ========================*/
1543 /*------------------------------------------------------------------*/
1545 /* Name - add_float */
1547 /* Function - Determine code and stack size incremements for a */
1548 /* float parameter. */
1550 /*------------------------------------------------------------------*/
1553 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1555 if ((*fr) <= S390_LAST_FPARG_REG) {
1556 ainfo->regtype = RegTypeFP;
1562 ainfo->offset = sz->stack_size;
1563 ainfo->reg = STK_BASE;
1564 ainfo->regtype = RegTypeBase;
1566 sz->stack_size += sizeof(double);
1567 sz->local_size += sizeof(double);
1568 sz->offStruct += sizeof(double);
1572 /*========================= End of Function ========================*/
1574 /*------------------------------------------------------------------*/
1576 /* Name - get_call_info */
1578 /* Function - Determine the amount of space required for code */
1579 /* and stack. In addition determine starting points */
1580 /* for stack-based parameters, and area for struct- */
1581 /* ures being returned on the stack. */
1583 /*------------------------------------------------------------------*/
1586 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
1588 guint i, fr, gr, size, pstart;
1589 int nParm = sig->hasthis + sig->param_count;
1591 guint32 simpleType, align;
1592 gboolean is_pinvoke = sig->pinvoke;
1595 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1598 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1600 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1605 cinfo->struct_ret = 0;
1609 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1610 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1617 /*----------------------------------------------------------*/
1618 /* We determine the size of the return code/stack in case we*/
1619 /* need to reserve a register to be used to address a stack */
1620 /* area that the callee will use. */
1621 /*----------------------------------------------------------*/
1623 ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
1624 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1625 simpleType = ret_type->type;
1627 switch (simpleType) {
1628 case MONO_TYPE_BOOLEAN:
1633 case MONO_TYPE_CHAR:
1638 case MONO_TYPE_CLASS:
1639 case MONO_TYPE_OBJECT:
1640 case MONO_TYPE_SZARRAY:
1641 case MONO_TYPE_ARRAY:
1643 case MONO_TYPE_FNPTR:
1644 case MONO_TYPE_STRING:
1645 cinfo->ret.reg = s390_r2;
1650 cinfo->ret.reg = s390_f0;
1655 cinfo->ret.reg = s390_r2;
1658 case MONO_TYPE_GENERICINST:
1659 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1660 cinfo->ret.reg = s390_r2;
1665 case MONO_TYPE_VALUETYPE: {
1666 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1667 if (klass->enumtype) {
1668 simpleType = mono_class_enum_basetype (klass)->type;
1671 size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1673 cinfo->struct_ret = 1;
1674 cinfo->ret.size = size;
1675 cinfo->ret.vtsize = size;
1678 case MONO_TYPE_TYPEDBYREF:
1679 size = sizeof (MonoTypedRef);
1680 cinfo->struct_ret = 1;
1681 cinfo->ret.size = size;
1682 cinfo->ret.vtsize = size;
1684 case MONO_TYPE_VOID:
1687 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1693 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1694 * the first argument, allowing 'this' to be always passed in the first arg reg.
1695 * Also do this if the first argument is a reference type, since virtual calls
1696 * are sometimes made using calli without sig->hasthis set, like in the delegate
1699 if (cinfo->struct_ret && !is_pinvoke &&
1701 (sig->param_count > 0 &&
1702 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1704 cinfo->args[nParm].size = sizeof (gpointer);
1705 add_general (&gr, sz, cinfo->args + nParm);
1707 cinfo->args[nParm].size = sizeof (gpointer);
1708 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1712 cinfo->vret_arg_index = 1;
1713 cinfo->ret.reg = gr;
1718 cinfo->args[nParm].size = sizeof (gpointer);
1719 add_general (&gr, sz, cinfo->args + nParm);
1723 if (cinfo->struct_ret) {
1724 cinfo->ret.reg = gr;
1729 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1730 gr = S390_LAST_ARG_REG + 1;
1731 fr = S390_LAST_FPARG_REG + 1;
1733 /* Emit the signature cookie just before the implicit arguments */
1734 add_general (&gr, sz, &cinfo->sigCookie);
1737 /*----------------------------------------------------------*/
1738 /* We determine the size of the parameter code and stack */
1739 /* requirements by checking the types and sizes of the */
1741 /*----------------------------------------------------------*/
1743 for (i = pstart; i < sig->param_count; ++i) {
1746 /*--------------------------------------------------*/
1747 /* Handle vararg type calls. All args are put on */
1749 /*--------------------------------------------------*/
1750 if ((sig->call_convention == MONO_CALL_VARARG) &&
1751 (i == sig->sentinelpos)) {
1752 gr = S390_LAST_ARG_REG + 1;
1753 fr = S390_LAST_FPARG_REG + 1;
1754 add_general (&gr, sz, &cinfo->sigCookie);
1757 if (sig->params [i]->byref) {
1758 add_general (&gr, sz, cinfo->args+nParm);
1759 cinfo->args[nParm].size = sizeof(gpointer);
1764 ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
1765 simpleType = ptype->type;
1766 cinfo->args[nParm].type = simpleType;
1767 switch (simpleType) {
1768 case MONO_TYPE_BOOLEAN:
1771 cinfo->args[nParm].size = sizeof(char);
1772 add_general (&gr, sz, cinfo->args+nParm);
1777 case MONO_TYPE_CHAR:
1778 cinfo->args[nParm].size = sizeof(short);
1779 add_general (&gr, sz, cinfo->args+nParm);
1784 cinfo->args[nParm].size = sizeof(int);
1785 add_general (&gr, sz, cinfo->args+nParm);
1791 case MONO_TYPE_FNPTR:
1792 case MONO_TYPE_CLASS:
1793 case MONO_TYPE_OBJECT:
1794 case MONO_TYPE_STRING:
1795 case MONO_TYPE_SZARRAY:
1796 case MONO_TYPE_ARRAY:
1797 cinfo->args[nParm].size = sizeof(gpointer);
1798 add_general (&gr, sz, cinfo->args+nParm);
1803 cinfo->args[nParm].size = sizeof(long long);
1804 add_general (&gr, sz, cinfo->args+nParm);
1808 cinfo->args[nParm].size = sizeof(float);
1809 add_float (&fr, sz, cinfo->args+nParm);
1813 cinfo->args[nParm].size = sizeof(double);
1814 add_float (&fr, sz, cinfo->args+nParm);
1817 case MONO_TYPE_GENERICINST:
1818 if (!mono_type_generic_inst_is_valuetype (ptype)) {
1819 cinfo->args[nParm].size = sizeof(gpointer);
1820 add_general (&gr, sz, cinfo->args+nParm);
1825 case MONO_TYPE_VALUETYPE: {
1826 MonoMarshalType *info;
1827 MonoClass *klass = mono_class_from_mono_type (ptype);
1829 size = mini_type_stack_size_full(gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1830 if (simpleType != MONO_TYPE_GENERICINST) {
1831 info = mono_marshal_load_type_info(klass);
1833 if ((info->native_size == sizeof(float)) &&
1834 (info->num_fields == 1) &&
1835 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1836 cinfo->args[nParm].size = sizeof(float);
1837 add_float(&fr, sz, cinfo->args+nParm);
1842 if ((info->native_size == sizeof(double)) &&
1843 (info->num_fields == 1) &&
1844 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1845 cinfo->args[nParm].size = sizeof(double);
1846 add_float(&fr, sz, cinfo->args+nParm);
1852 cinfo->args[nParm].vtsize = 0;
1853 cinfo->args[nParm].size = 0;
1856 /*----------------------------------*/
1857 /* On S/390, structures of size 1, */
1858 /* 2, 4, and 8 bytes are passed in */
1859 /* (a) register(s). */
1860 /*----------------------------------*/
1866 add_general(&gr, sz, cinfo->args+nParm);
1867 cinfo->args[nParm].size = size;
1868 cinfo->args[nParm].regtype = RegTypeStructByVal;
1870 sz->local_size += sizeof(long);
1873 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1878 case MONO_TYPE_TYPEDBYREF: {
1879 int size = sizeof (MonoTypedRef);
1881 cinfo->args[nParm].vtsize = 0;
1882 cinfo->args[nParm].size = 0;
1885 /*----------------------------------*/
1886 /* On S/390, structures of size 1, */
1887 /* 2, 4, and 8 bytes are passed in */
1888 /* (a) register(s). */
1889 /*----------------------------------*/
1895 add_general(&gr, sz, cinfo->args+nParm);
1896 cinfo->args[nParm].size = size;
1897 cinfo->args[nParm].regtype = RegTypeStructByVal;
1899 sz->local_size += sizeof(long);
1902 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1908 g_error ("Can't trampoline 0x%x", ptype);
1912 /*----------------------------------------------------------*/
1913 /* Handle the case where there are no implicit arguments */
1914 /*----------------------------------------------------------*/
1915 if ((sig->call_convention == MONO_CALL_VARARG) &&
1918 (sig->param_count == sig->sentinelpos)) {
1919 gr = S390_LAST_ARG_REG + 1;
1920 fr = S390_LAST_FPARG_REG + 1;
1921 add_general (&gr, sz, &cinfo->sigCookie);
1924 /*----------------------------------------------------------*/
1925 /* If we are passing a structure back then if it won't be */
1926 /* in a register(s) then we make room at the end of the */
1927 /* parameters that may have been placed on the stack */
1928 /*----------------------------------------------------------*/
1929 if (cinfo->struct_ret) {
1930 cinfo->ret.offset = sz->stack_size;
1931 switch (cinfo->ret.size) {
1939 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1944 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1946 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1951 /*========================= End of Function ========================*/
1953 /*------------------------------------------------------------------*/
1955 /* Name - mono_arch_allocate_vars */
1957 /* Function - Set var information according to the calling */
1958 /* convention for S/390. The local var stuff should */
1959 /* most likely be split in another method. */
1961 /* Parameter - @m - Compile unit. */
1963 /*------------------------------------------------------------------*/
1966 mono_arch_allocate_vars (MonoCompile *cfg)
1968 MonoMethodSignature *sig;
1969 MonoMethodHeader *header;
1972 int iParm, iVar, offset, align, size, curinst;
1973 int frame_reg = STK_BASE;
1976 header = cfg->header;
1978 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1980 /*---------------------------------------------------------*/
1981 /* We use the frame register also for any method that has */
1982 /* filter clauses. This way, when the handlers are called, */
1983 /* the code will reference local variables using the frame */
1984 /* reg instead of the stack pointer: if we had to restore */
1985 /* the stack pointer, we'd corrupt the method frames that */
1986 /* are already on the stack (since filters get called */
1987 /* before stack unwinding happens) when the filter code */
1988 /* would call any method. */
1989 /*---------------------------------------------------------*/
1990 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1991 frame_reg = s390_r11;
1993 cfg->frame_reg = frame_reg;
1995 cfg->arch.bkchain_reg = -1;
1997 if (frame_reg != STK_BASE)
1998 cfg->used_int_regs |= 1 << frame_reg;
2000 sig = mono_method_signature (cfg->method);
2002 cinfo = get_call_info (cfg, cfg->mempool, sig);
2004 if (!cinfo->struct_ret) {
2005 switch (mono_type_get_underlying_type (sig->ret)->type) {
2006 case MONO_TYPE_VOID:
2009 cfg->ret->opcode = OP_REGVAR;
2010 cfg->ret->dreg = s390_r2;
2015 /*--------------------------------------------------------------*/
2016 /* local vars are at a positive offset from the stack pointer */
2017 /* also note that if the function uses alloca, we use s390_r11 */
2018 /* to point at the local variables. */
2019 /* add parameter area size for called functions */
2020 /*--------------------------------------------------------------*/
2021 if (cfg->param_area == 0)
2022 offset = S390_MINIMAL_STACK_SIZE;
2024 offset = cfg->param_area;
2026 cfg->sig_cookie = 0;
2028 if (cinfo->struct_ret) {
2029 inst = cfg->vret_addr;
2030 offset = S390_ALIGN(offset, sizeof(gpointer));
2031 inst->inst_offset = offset;
2032 inst->opcode = OP_REGOFFSET;
2033 inst->inst_basereg = frame_reg;
2034 offset += sizeof(gpointer);
2035 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2036 printf ("vret_addr =");
2037 mono_print_ins (cfg->vret_addr);
2042 inst = cfg->args [0];
2043 if (inst->opcode != OP_REGVAR) {
2044 inst->opcode = OP_REGOFFSET;
2045 inst->inst_basereg = frame_reg;
2046 offset = S390_ALIGN(offset, sizeof(gpointer));
2047 inst->inst_offset = offset;
2048 offset += sizeof (gpointer);
2055 eArg = sig->param_count + sArg;
2057 if (sig->call_convention == MONO_CALL_VARARG)
2058 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2060 for (iParm = sArg; iParm < eArg; ++iParm) {
2061 inst = cfg->args [curinst];
2062 if (inst->opcode != OP_REGVAR) {
2063 switch (cinfo->args[iParm].regtype) {
2064 case RegTypeStructByAddr : {
2067 size = sizeof (gpointer);
2069 inst->opcode = OP_REGOFFSET;
2070 inst->inst_basereg = frame_reg;
2071 offset = S390_ALIGN (offset, sizeof (gpointer));
2072 inst->inst_offset = offset;
2074 /* Add a level of indirection */
2075 MONO_INST_NEW (cfg, indir, 0);
2077 inst->opcode = OP_VTARG_ADDR;
2078 inst->inst_left = indir;
2081 case RegTypeStructByAddrOnStack : {
2084 size = sizeof (gpointer);
2086 /* Similar to the == STK_BASE case below */
2087 cfg->arch.bkchain_reg = s390_r12;
2088 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2090 inst->opcode = OP_REGOFFSET;
2091 inst->dreg = mono_alloc_preg (cfg);
2092 inst->inst_basereg = cfg->arch.bkchain_reg;
2093 inst->inst_offset = cinfo->args [iParm].offset;
2095 /* Add a level of indirection */
2096 MONO_INST_NEW (cfg, indir, 0);
2098 inst->opcode = OP_VTARG_ADDR;
2099 inst->inst_left = indir;
2102 case RegTypeStructByVal :
2103 size = cinfo->args[iParm].size;
2104 offset = S390_ALIGN(offset, size);
2105 inst->opcode = OP_REGOFFSET;
2106 inst->inst_basereg = frame_reg;
2107 inst->inst_offset = offset;
2110 if (cinfo->args [iParm].reg == STK_BASE) {
2112 * These arguments are in the previous frame, so we can't
2113 * compute their offset from the current frame pointer right
2114 * now, since cfg->stack_offset is not yet known, so dedicate a
2115 * register holding the previous frame pointer.
2117 cfg->arch.bkchain_reg = s390_r12;
2118 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2120 inst->opcode = OP_REGOFFSET;
2121 inst->inst_basereg = cfg->arch.bkchain_reg;
2122 size = (cinfo->args[iParm].size < 8
2123 ? 8 - cinfo->args[iParm].size
2125 inst->inst_offset = cinfo->args [iParm].offset + size;
2126 size = sizeof (long);
2128 inst->opcode = OP_REGOFFSET;
2129 inst->inst_basereg = frame_reg;
2130 size = (cinfo->args[iParm].size < 8
2133 offset = S390_ALIGN(offset, size);
2134 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2135 inst->inst_offset = offset;
2137 inst->inst_offset = offset + (8 - size);
2142 if ((sig->call_convention == MONO_CALL_VARARG) &&
2143 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2144 (iParm < sig->sentinelpos))
2145 cfg->sig_cookie += size;
2146 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2149 offset += MAX(size, 8);
2154 cfg->locals_min_stack_offset = offset;
2156 curinst = cfg->locals_start;
2157 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2158 inst = cfg->varinfo [iVar];
2159 if ((inst->flags & MONO_INST_IS_DEAD) ||
2160 (inst->opcode == OP_REGVAR))
2163 /*--------------------------------------------------*/
2164 /* inst->backend.is_pinvoke indicates native sized */
2165 /* value typs this is used by the pinvoke wrappers */
2166 /* when they call functions returning structure */
2167 /*--------------------------------------------------*/
2168 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2169 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2170 (guint32 *) &align);
2172 size = mono_type_size (inst->inst_vtype, &align);
2174 offset = S390_ALIGN(offset, align);
2175 inst->inst_offset = offset;
2176 inst->opcode = OP_REGOFFSET;
2177 inst->inst_basereg = frame_reg;
2179 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2180 iVar, inst->inst_offset, size));
2183 cfg->locals_max_stack_offset = offset;
2185 /*------------------------------------------------------*/
2186 /* Allow space for the trace method stack area if needed*/
2187 /*------------------------------------------------------*/
2188 if ((mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2189 || (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE))
2190 offset += S390_TRACE_STACK_SIZE;
2192 /*------------------------------------------------------*/
2193 /* Reserve space to save LMF and caller saved registers */
2194 /*------------------------------------------------------*/
2195 if (cfg->method->save_lmf)
2196 offset += sizeof (MonoLMF);
2198 /*------------------------------------------------------*/
2199 /* align the offset */
2200 /*------------------------------------------------------*/
2201 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2203 /*------------------------------------------------------*/
2204 /* Fix offsets for args whose value is in parent frame */
2205 /*------------------------------------------------------*/
2206 for (iParm = sArg; iParm < eArg; ++iParm) {
2207 inst = cfg->args [iParm];
2209 if (inst->opcode == OP_S390_STKARG) {
2210 inst->opcode = OP_REGOFFSET;
2211 inst->inst_offset += cfg->stack_offset;
2216 /*========================= End of Function ========================*/
2218 /*------------------------------------------------------------------*/
2220 /* Name - mono_arch_create_vars */
2222 /*------------------------------------------------------------------*/
2225 mono_arch_create_vars (MonoCompile *cfg)
2227 MonoMethodSignature *sig;
2230 sig = mono_method_signature (cfg->method);
2232 cinfo = get_call_info (cfg, cfg->mempool, sig);
2234 if (cinfo->struct_ret) {
2235 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2236 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2237 printf ("vret_addr = ");
2238 mono_print_ins (cfg->vret_addr);
2243 /*========================= End of Function ========================*/
2245 /*------------------------------------------------------------------*/
2247 /* Name - add_outarg_reg2. */
2249 /*------------------------------------------------------------------*/
2252 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2257 case RegTypeGeneral:
2258 MONO_INST_NEW (cfg, ins, OP_MOVE);
2259 ins->dreg = mono_alloc_ireg (cfg);
2260 ins->sreg1 = tree->dreg;
2261 MONO_ADD_INS (cfg->cbb, ins);
2262 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2265 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2266 ins->dreg = mono_alloc_freg (cfg);
2267 ins->sreg1 = tree->dreg;
2268 MONO_ADD_INS (cfg->cbb, ins);
2269 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2272 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2273 ins->dreg = mono_alloc_freg (cfg);
2274 ins->sreg1 = tree->dreg;
2275 MONO_ADD_INS (cfg->cbb, ins);
2276 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2279 g_assert_not_reached ();
2283 /*========================= End of Function ========================*/
2285 /*------------------------------------------------------------------*/
2287 /* Name - emit_sig_cookie. */
2289 /*------------------------------------------------------------------*/
2292 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2294 MonoMethodSignature *tmpSig;
2297 cfg->disable_aot = TRUE;
2299 /*----------------------------------------------------------*/
2300 /* mono_ArgIterator_Setup assumes the signature cookie is */
2301 /* passed first and all the arguments which were before it */
2302 /* passed on the stack after the signature. So compensate */
2303 /* by passing a different signature. */
2304 /*----------------------------------------------------------*/
2305 tmpSig = mono_metadata_signature_dup (call->signature);
2306 tmpSig->param_count -= call->signature->sentinelpos;
2307 tmpSig->sentinelpos = 0;
2308 if (tmpSig->param_count > 0)
2309 memcpy (tmpSig->params,
2310 call->signature->params + call->signature->sentinelpos,
2311 tmpSig->param_count * sizeof(MonoType *));
2313 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2314 sig_arg->dreg = mono_alloc_ireg (cfg);
2315 sig_arg->inst_p0 = tmpSig;
2316 MONO_ADD_INS (cfg->cbb, sig_arg);
2318 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2319 cinfo->sigCookie.offset, sig_arg->dreg);
2322 /*========================= End of Function ========================*/
2324 /*------------------------------------------------------------------*/
2326 /* Name - mono_arch_emit_call */
2328 /*------------------------------------------------------------------*/
2331 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2334 MonoMethodSignature *sig;
2336 int i, n, lParamArea;
2338 ArgInfo *ainfo = NULL;
2340 MonoMethodHeader *header;
2343 sig = call->signature;
2344 n = sig->param_count + sig->hasthis;
2345 DEBUG (g_print ("Call requires: %d parameters\n",n));
2347 cinfo = get_call_info (cfg, cfg->mempool, sig);
2349 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2350 cinfo->sz.parm_size + cinfo->sz.offset;
2351 call->stack_usage = MAX(stackSize, call->stack_usage);
2352 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2353 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2354 cfg->flags |= MONO_CFG_HAS_CALLS;
2356 if (cinfo->struct_ret) {
2357 MONO_INST_NEW (cfg, ins, OP_MOVE);
2358 ins->sreg1 = call->vret_var->dreg;
2359 ins->dreg = mono_alloc_preg (cfg);
2360 MONO_ADD_INS (cfg->cbb, ins);
2361 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2364 header = cfg->header;
2365 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2370 for (i = 0; i < n; ++i) {
2373 ainfo = cinfo->args + i;
2374 if (i >= sig->hasthis)
2375 t = sig->params [i - sig->hasthis];
2377 t = &mono_defaults.int_class->byval_arg;
2378 t = mono_type_get_underlying_type (t);
2380 in = call->args [i];
2382 if ((sig->call_convention == MONO_CALL_VARARG) &&
2384 (i == sig->sentinelpos)) {
2385 emit_sig_cookie (cfg, call, cinfo);
2388 switch (ainfo->regtype) {
2389 case RegTypeGeneral:
2390 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2393 if (MONO_TYPE_ISSTRUCT (t)) {
2394 /* Valuetype passed in one fp register */
2395 ainfo->regtype = RegTypeStructByValInFP;
2398 if (ainfo->size == 4)
2399 ainfo->regtype = RegTypeFPR4;
2400 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2403 case RegTypeStructByVal:
2404 case RegTypeStructByAddr:
2405 case RegTypeStructByAddrOnStack: {
2409 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2410 size = sizeof (MonoTypedRef);
2411 align = sizeof (gpointer);
2415 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2418 * Other backends use mono_type_stack_size (), but that
2419 * aligns the size to 8, which is larger than the size of
2420 * the source, leading to reads of invalid memory if the
2421 * source is at the end of address space.
2423 size = mono_class_value_size (in->klass, &align);
2426 g_assert (in->klass);
2428 ainfo->offparm += cinfo->sz.offStruct;
2430 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2431 ins->sreg1 = in->dreg;
2432 ins->klass = in->klass;
2433 ins->backend.size = ainfo->size;
2434 ins->inst_p0 = call;
2435 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2436 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2438 MONO_ADD_INS (cfg->cbb, ins);
2440 if (ainfo->regtype == RegTypeStructByAddr) {
2442 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2443 * use the normal OUTARG opcodes to pass the address of the location to
2446 int treg = mono_alloc_preg (cfg);
2447 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2448 frmReg, ainfo->offparm);
2449 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2450 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2451 /* The address of the valuetype is passed on the stack */
2452 int treg = mono_alloc_preg (cfg);
2453 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2454 frmReg, ainfo->offparm);
2455 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2456 ainfo->reg, ainfo->offset, treg);
2458 if (cfg->compute_gc_maps) {
2461 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2467 if (!t->byref && t->type == MONO_TYPE_R4) {
2468 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2469 STK_BASE, ainfo->offset + 4,
2471 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2472 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2473 STK_BASE, ainfo->offset,
2476 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2477 ins->inst_destbasereg = STK_BASE;
2478 ins->inst_offset = ainfo->offset;
2479 ins->sreg1 = in->dreg;
2482 /* This is needed by MonoTypedRef->value to point to the correct data */
2483 if ((sig->call_convention == MONO_CALL_VARARG) &&
2484 (i >= sig->sentinelpos)) {
2485 switch (ainfo->size) {
2487 ins->opcode = OP_STOREI1_MEMBASE_REG;
2490 ins->opcode = OP_STOREI2_MEMBASE_REG;
2493 ins->opcode = OP_STOREI4_MEMBASE_REG;
2501 MONO_ADD_INS (cfg->cbb, ins);
2505 g_assert_not_reached ();
2511 * Handle the case where there are no implicit arguments
2513 if ((sig->call_convention == MONO_CALL_VARARG) &&
2515 (i == sig->sentinelpos)) {
2516 emit_sig_cookie (cfg, call, cinfo);
2520 /*========================= End of Function ========================*/
2522 /*------------------------------------------------------------------*/
2524 /* Name - mono_arch_emit_outarg_vt */
2526 /*------------------------------------------------------------------*/
2529 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2531 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2532 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2533 int size = ins->backend.size;
2535 if (ainfo->regtype == RegTypeStructByVal) {
2537 arg->ins.sreg1 = ainfo->reg;
2538 arg->ins.opcode = OP_OUTARG_VT;
2539 arg->size = ainfo->size;
2540 arg->offset = ainfo->offset;
2541 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2543 if (ainfo->reg != STK_BASE) {
2544 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2546 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2549 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2550 int dreg = mono_alloc_freg (cfg);
2552 if (ainfo->size == 4) {
2553 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2554 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2556 g_assert (ainfo->size == 8);
2558 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2561 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2563 MonoMethodHeader *header;
2566 header = mono_method_get_header (cfg->method);
2567 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2572 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2573 src->dreg, 0, size);
2575 if (cfg->compute_gc_maps) {
2578 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2583 /*========================= End of Function ========================*/
2585 /*------------------------------------------------------------------*/
2587 /* Name - mono_arch_emit_setret */
2589 /*------------------------------------------------------------------*/
2592 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2594 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2597 if (ret->type == MONO_TYPE_R4) {
2598 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2600 } else if (ret->type == MONO_TYPE_R8) {
2601 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2606 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2609 /*========================= End of Function ========================*/
2611 /*------------------------------------------------------------------*/
2613 /* Name - mono_arch_instrument_mem_needs */
2615 /* Function - Allow tracing to work with this interface (with */
2616 /* an optional argument). */
2618 /*------------------------------------------------------------------*/
2621 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2623 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2625 /* split prolog-epilog requirements? */
2626 *code = 50; /* max bytes needed: check this number */
2629 /*========================= End of Function ========================*/
2631 /*------------------------------------------------------------------*/
2633 /* Name - mono_arch_instrument_prolog */
2635 /* Function - Create an "instrumented" prolog. */
2637 /*------------------------------------------------------------------*/
2640 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2641 gboolean enable_arguments)
2648 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2649 if (cfg->method->save_lmf)
2650 parmOffset -= sizeof(MonoLMF);
2651 fpOffset = parmOffset + (5*sizeof(gpointer));
2652 if ((!mono_hwcap_s390x_has_ld) && (fpOffset > 4096)) {
2653 s390_lgr (code, s390_r12, STK_BASE);
2655 while (fpOffset > 4096) {
2656 s390_aghi (code, baseReg, 4096);
2664 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2665 if (mono_hwcap_s390x_has_ld) {
2666 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2667 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2668 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2669 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2671 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2672 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2673 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2674 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2676 s390_basr (code, s390_r13, 0);
2678 s390_llong(code, cfg->method);
2679 s390_llong(code, func);
2680 s390_lg (code, s390_r2, 0, s390_r13, 4);
2681 if (mono_hwcap_s390x_has_ld)
2682 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2684 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2685 s390_lgr (code, s390_r4, STK_BASE);
2686 s390_aghi (code, s390_r4, cfg->stack_usage);
2687 s390_lg (code, s390_r1, 0, s390_r13, 12);
2688 s390_basr (code, s390_r14, s390_r1);
2689 if (mono_hwcap_s390x_has_ld) {
2690 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2691 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2692 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2693 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2695 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2696 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2697 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2698 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2700 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2705 /*========================= End of Function ========================*/
2707 /*------------------------------------------------------------------*/
2709 /* Name - mono_arch_instrument_epilog */
2711 /* Function - Create an epilog that will handle the returned */
2712 /* values used in instrumentation. */
2714 /*------------------------------------------------------------------*/
2717 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2720 int save_mode = SAVE_NONE,
2723 MonoMethod *method = cfg->method;
2724 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2726 offset = code - cfg->native_code;
2727 /*-----------------------------------------*/
2728 /* We need about 128 bytes of instructions */
2729 /*-----------------------------------------*/
2730 if (offset > (cfg->code_size - 128)) {
2731 cfg->code_size *= 2;
2732 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2733 code = cfg->native_code + offset;
2736 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2737 if (method->save_lmf)
2738 saveOffset -= sizeof(MonoLMF);
2742 case MONO_TYPE_VOID:
2743 /* special case string .ctor icall */
2744 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2745 save_mode = SAVE_ONE;
2747 save_mode = SAVE_NONE;
2751 save_mode = SAVE_ONE;
2754 save_mode = SAVE_R4;
2757 save_mode = SAVE_R8;
2759 case MONO_TYPE_VALUETYPE:
2760 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2761 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2764 save_mode = SAVE_STRUCT;
2767 save_mode = SAVE_ONE;
2771 switch (save_mode) {
2773 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2774 if (enable_arguments) {
2775 s390_lgr (code, s390_r3, s390_r2);
2779 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2780 if (enable_arguments) {
2781 s390_ldebr (code, s390_f0, s390_f0);
2785 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2788 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2789 if (enable_arguments) {
2790 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2791 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2799 s390_basr (code, s390_r13, 0);
2801 s390_llong(code, cfg->method);
2802 s390_llong(code, func);
2803 s390_lg (code, s390_r2, 0, s390_r13, 4);
2804 s390_lg (code, s390_r1, 0, s390_r13, 12);
2805 s390_basr (code, s390_r14, s390_r1);
2807 switch (save_mode) {
2809 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2813 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2816 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2826 /*========================= End of Function ========================*/
2828 /*------------------------------------------------------------------*/
2830 /* Name - mono_arch_peephole_pass_1 */
2832 /* Function - Form a peephole pass at the code looking for */
2833 /* simple optimizations. */
2835 /*------------------------------------------------------------------*/
2838 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2842 /*========================= End of Function ========================*/
2844 /*------------------------------------------------------------------*/
2846 /* Name - mono_arch_peephole_pass_2 */
2848 /* Function - Form a peephole pass at the code looking for */
2849 /* simple optimizations. */
2851 /*------------------------------------------------------------------*/
2854 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2858 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2859 mono_peephole_ins (bb, ins);
2863 /*========================= End of Function ========================*/
2865 /*------------------------------------------------------------------*/
2867 /* Name - mono_arch_lowering_pass. */
2869 /*------------------------------------------------------------------*/
2872 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2874 MonoInst *ins, *next;
2876 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2877 switch (ins->opcode) {
2882 case OP_IDIV_UN_IMM:
2883 case OP_IREM_UN_IMM:
2887 case OP_LOCALLOC_IMM:
2888 mono_decompose_op_imm (cfg, bb, ins);
2891 if (!s390_is_imm16 (ins->inst_imm))
2892 /* This is created by the memcpy code which ignores is_inst_imm */
2893 mono_decompose_op_imm (cfg, bb, ins);
2900 bb->max_vreg = cfg->next_vreg;
2903 /*========================= End of Function ========================*/
2905 /*------------------------------------------------------------------*/
2907 /* Name - emit_float_to_int */
2909 /* Function - Create instructions which will convert a floating */
2910 /* point value to integer. */
2912 /*------------------------------------------------------------------*/
2915 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2917 /* sreg is a float, dreg is an integer reg. */
2919 s390_cgdbr (code, dreg, 5, sreg);
2922 s390_lghi (code, s390_r0, 0);
2923 s390_lghi (code, s390_r13, 0xff);
2924 s390_ltgr (code, dreg, dreg);
2926 s390_lghi (code, s390_r0, 0x80);
2927 s390_ngr (code, dreg, s390_r13);
2928 s390_ogr (code, dreg, s390_r0);
2933 s390_basr (code, s390_r13, 0);
2935 s390_llong (code, 0x41e0000000000000llu);
2936 s390_llong (code, 0x41f0000000000000llu);
2937 s390_ldr (code, s390_f15, sreg);
2938 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2939 s390_jl (code, 0); CODEPTR (code, o[0]);
2940 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2941 s390_cfdbr (code, dreg, 7, s390_f15);
2943 PTRSLOT (code, o[0]);
2944 s390_cfdbr (code, dreg, 5, sreg);
2947 s390_lghi (code, s390_r0, 0xff);
2948 s390_ngr (code, dreg, s390_r0);
2951 s390_lghi (code, s390_r0, -1);
2952 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2953 s390_ngr (code, dreg, s390_r0);
2960 /*========================= End of Function ========================*/
2962 /*------------------------------------------------------------------*/
2964 /* Name - gboolean_is_unsigned. */
2966 /* Function - Return TRUE if next opcode is checking for un- */
2969 /*------------------------------------------------------------------*/
2972 gboolean is_unsigned (MonoInst *next)
2975 (((next->opcode >= OP_IBNE_UN) &&
2976 (next->opcode <= OP_IBLT_UN)) ||
2977 ((next->opcode >= OP_LBNE_UN) &&
2978 (next->opcode <= OP_LBLT_UN)) ||
2979 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2980 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2981 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2982 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2983 ((next->opcode == OP_CLT_UN) ||
2984 (next->opcode == OP_CGT_UN)) ||
2985 ((next->opcode == OP_ICLT_UN) ||
2986 (next->opcode == OP_ICGT_UN) ||
2987 (next->opcode == OP_LCLT_UN) ||
2988 (next->opcode == OP_LCGT_UN))))
2994 /*========================= End of Function ========================*/
2996 /*------------------------------------------------------------------*/
2998 /* Name - mono_arch_output_basic_block */
3000 /* Function - Perform the "real" work of emitting instructions */
3001 /* that will do the work of in the basic block. */
3003 /*------------------------------------------------------------------*/
3006 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
3011 guint8 *code = cfg->native_code + cfg->code_len;
3012 guint last_offset = 0;
3013 int max_len, cpos, src2;
3015 /* we don't align basic blocks of loops on s390 */
3017 if (cfg->verbose_level > 2)
3018 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
3020 cpos = bb->max_offset;
3022 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
3023 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
3024 //g_assert (!mono_compile_aot);
3027 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
3028 /* this is not thread save, but good enough */
3029 /* fixme: howto handle overflows? */
3030 //x86_inc_mem (code, &cov->data [bb->dfn].count);
3033 MONO_BB_FOR_EACH_INS (bb, ins) {
3034 offset = code - cfg->native_code;
3036 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
3038 if (offset > (cfg->code_size - max_len - 16)) {
3039 cfg->code_size *= 2;
3040 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
3041 code = cfg->native_code + offset;
3044 mono_debug_record_line_number (cfg, ins, offset);
3046 switch (ins->opcode) {
3047 case OP_STOREI1_MEMBASE_IMM: {
3048 s390_lghi (code, s390_r0, ins->inst_imm);
3049 S390_LONG (code, stcy, stc, s390_r0, 0,
3050 ins->inst_destbasereg, ins->inst_offset);
3053 case OP_STOREI2_MEMBASE_IMM: {
3054 s390_lghi (code, s390_r0, ins->inst_imm);
3055 S390_LONG (code, sthy, sth, s390_r0, 0,
3056 ins->inst_destbasereg, ins->inst_offset);
3059 case OP_STOREI4_MEMBASE_IMM: {
3060 if (s390_is_imm16(ins->inst_imm)) {
3061 s390_lghi (code, s390_r0, ins->inst_imm);
3063 s390_basr (code, s390_r13, 0);
3065 s390_llong(code, ins->inst_imm);
3066 s390_lg (code, s390_r0, 0, s390_r13, 4);
3068 S390_LONG (code, sty, st, s390_r0, 0,
3069 ins->inst_destbasereg, ins->inst_offset);
3072 case OP_STORE_MEMBASE_IMM:
3073 case OP_STOREI8_MEMBASE_IMM: {
3074 if (s390_is_imm16(ins->inst_imm)) {
3075 s390_lghi (code, s390_r0, ins->inst_imm);
3077 s390_basr (code, s390_r13, 0);
3079 s390_llong(code, ins->inst_imm);
3080 s390_lg (code, s390_r0, 0, s390_r13, 4);
3082 S390_LONG (code, stg, stg, s390_r0, 0,
3083 ins->inst_destbasereg, ins->inst_offset);
3086 case OP_STOREI1_MEMBASE_REG: {
3087 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3088 ins->inst_destbasereg, ins->inst_offset);
3091 case OP_STOREI2_MEMBASE_REG: {
3092 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3093 ins->inst_destbasereg, ins->inst_offset);
3096 case OP_STOREI4_MEMBASE_REG: {
3097 S390_LONG (code, sty, st, ins->sreg1, 0,
3098 ins->inst_destbasereg, ins->inst_offset);
3101 case OP_STORE_MEMBASE_REG:
3102 case OP_STOREI8_MEMBASE_REG: {
3103 S390_LONG (code, stg, stg, ins->sreg1, 0,
3104 ins->inst_destbasereg, ins->inst_offset);
3108 g_assert_not_reached ();
3110 case OP_LOAD_MEMBASE:
3111 case OP_LOADI8_MEMBASE: {
3112 S390_LONG (code, lg, lg, ins->dreg, 0,
3113 ins->inst_basereg, ins->inst_offset);
3116 case OP_LOADI4_MEMBASE: {
3117 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3118 ins->inst_basereg, ins->inst_offset);
3121 case OP_LOADU4_MEMBASE: {
3122 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3123 ins->inst_basereg, ins->inst_offset);
3126 case OP_LOADU1_MEMBASE: {
3127 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3128 ins->inst_basereg, ins->inst_offset);
3131 case OP_LOADI1_MEMBASE: {
3132 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3133 ins->inst_basereg, ins->inst_offset);
3136 case OP_LOADU2_MEMBASE: {
3137 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3138 ins->inst_basereg, ins->inst_offset);
3141 case OP_LOADI2_MEMBASE: {
3142 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3143 ins->inst_basereg, ins->inst_offset);
3146 case OP_LCONV_TO_I1: {
3148 s390_lgbr (code, ins->dreg, ins->sreg1);
3150 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
3151 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
3155 case OP_LCONV_TO_I2: {
3157 s390_lghr (code, ins->dreg, ins->sreg1);
3159 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
3160 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
3164 case OP_LCONV_TO_U1: {
3166 s390_llghr (code, ins->dreg, ins->sreg1);
3168 if (ins->dreg != ins->sreg1)
3169 s390_lgr (code, ins->dreg, ins->sreg1);
3170 s390_lghi (code, s390_r0, 0xff);
3171 s390_ngr (code, ins->dreg, s390_r0);
3175 case OP_LCONV_TO_U2: {
3177 s390_llghr (code, ins->dreg, ins->sreg1);
3179 if (ins->dreg != ins->sreg1)
3180 s390_lgr (code, ins->dreg, ins->sreg1);
3181 s390_lghi (code, s390_r0, -1);
3182 s390_srlg (code, s390_r0, s390_r0, 0, 48);
3183 s390_ngr (code, ins->dreg, s390_r0);
3187 case OP_ICONV_TO_I1: {
3189 s390_lbr (code, ins->dreg, ins->sreg1);
3191 if (ins->dreg != ins->sreg1)
3192 s390_lr (code, ins->dreg, ins->sreg1);
3193 s390_sll (code, ins->dreg, 0, 24);
3194 s390_sra (code, ins->dreg, 0, 24);
3199 case OP_ICONV_TO_I2: {
3201 s390_lhr (code, ins->dreg, ins->sreg1);
3203 if (ins->dreg != ins->sreg1)
3204 s390_lr (code, ins->dreg, ins->sreg1);
3205 s390_sll (code, ins->dreg, 0, 16);
3206 s390_sra (code, ins->dreg, 0, 16);
3210 case OP_ICONV_TO_U1: {
3212 s390_llcr (code, ins->dreg, ins->sreg1);
3214 if (ins->dreg != ins->sreg1)
3215 s390_lr (code, ins->dreg, ins->sreg1);
3216 s390_lhi (code, s390_r0, 0xff);
3217 s390_nr (code, ins->dreg, s390_r0);
3221 case OP_ICONV_TO_U2: {
3223 s390_llhr (code, ins->dreg, ins->sreg1);
3225 if (ins->dreg != ins->sreg1)
3226 s390_lr (code, ins->dreg, ins->sreg1);
3227 s390_lhi (code, s390_r0, -1);
3228 s390_srl (code, s390_r0, 0, 16);
3229 s390_nr (code, ins->dreg, s390_r0);
3235 if (is_unsigned (ins->next))
3236 s390_clgr (code, ins->sreg1, ins->sreg2);
3238 s390_cgr (code, ins->sreg1, ins->sreg2);
3242 if (is_unsigned (ins->next))
3243 s390_clr (code, ins->sreg1, ins->sreg2);
3245 s390_cr (code, ins->sreg1, ins->sreg2);
3248 case OP_COMPARE_IMM:
3249 case OP_LCOMPARE_IMM: {
3250 if (s390_is_imm16 (ins->inst_imm)) {
3251 s390_lghi (code, s390_r0, ins->inst_imm);
3252 if (is_unsigned (ins->next))
3253 s390_clgr (code, ins->sreg1, s390_r0);
3255 s390_cgr (code, ins->sreg1, s390_r0);
3257 s390_basr (code, s390_r13, 0);
3259 s390_llong(code, ins->inst_imm);
3260 if (is_unsigned (ins->next))
3261 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3263 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3267 case OP_ICOMPARE_IMM: {
3268 if (s390_is_imm16 (ins->inst_imm)) {
3269 s390_lghi (code, s390_r0, ins->inst_imm);
3270 if (is_unsigned (ins->next))
3271 s390_clr (code, ins->sreg1, s390_r0);
3273 s390_cr (code, ins->sreg1, s390_r0);
3276 s390_basr (code, s390_r13, 0);
3278 s390_word (code, ins->inst_imm);
3279 if (is_unsigned (ins->next))
3280 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3282 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3287 s390_basr (code, s390_r13, 0);
3289 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3291 s390_llong (code, mono_break);
3292 s390_lg (code, s390_r14, 0, s390_r13, 4);
3293 s390_basr (code, s390_r14, s390_r14);
3298 s390_agr (code, ins->dreg, src2);
3303 s390_agr (code, ins->dreg, src2);
3308 s390_alcgr (code, ins->dreg, src2);
3312 if (ins->dreg != ins->sreg1) {
3313 s390_lgr (code, ins->dreg, ins->sreg1);
3315 if (s390_is_imm16 (ins->inst_imm)) {
3316 s390_aghi (code, ins->dreg, ins->inst_imm);
3318 s390_basr (code, s390_r13, 0);
3320 s390_llong(code, ins->inst_imm);
3321 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3326 if (ins->dreg != ins->sreg1) {
3327 s390_lgr (code, ins->dreg, ins->sreg1);
3329 g_assert (s390_is_imm16 (ins->inst_imm));
3330 s390_aghi (code, ins->dreg, ins->inst_imm);
3334 if (ins->dreg != ins->sreg1) {
3335 s390_lgr (code, ins->dreg, ins->sreg1);
3337 if (s390_is_imm16 (ins->inst_imm)) {
3338 s390_lghi (code, s390_r0, ins->inst_imm);
3339 s390_alcgr (code, ins->dreg, s390_r0);
3341 s390_basr (code, s390_r13, 0);
3343 s390_llong (code, ins->inst_imm);
3344 s390_lg (code, s390_r13, 0, s390_r13, 4);
3345 s390_alcgr (code, ins->dreg, s390_r13);
3350 case OP_S390_IADD_OVF: {
3352 s390_ar (code, ins->dreg, src2);
3353 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3354 s390_lgfr (code, ins->dreg, ins->dreg);
3357 case OP_IADD_OVF_UN:
3358 case OP_S390_IADD_OVF_UN: {
3360 s390_algr (code, ins->dreg, src2);
3361 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3362 s390_llgfr (code, ins->dreg, ins->dreg);
3365 case OP_ADD_OVF_CARRY: {
3367 s390_lghi (code, s390_r0, 0);
3368 s390_lgr (code, s390_r1, s390_r0);
3369 s390_alcgr (code, s390_r0, s390_r1);
3370 s390_agr (code, ins->dreg, src2);
3371 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3372 s390_agr (code, ins->dreg, s390_r0);
3373 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3376 case OP_ADD_OVF_UN_CARRY: {
3378 s390_alcgr (code, ins->dreg, src2);
3379 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3384 s390_sgr (code, ins->dreg, src2);
3389 s390_sgr (code, ins->dreg, src2);
3394 s390_slbgr(code, ins->dreg, src2);
3398 if (ins->dreg != ins->sreg1) {
3399 s390_lgr (code, ins->dreg, ins->sreg1);
3401 if (s390_is_imm16 (-ins->inst_imm)) {
3402 s390_lghi (code, s390_r0, ins->inst_imm);
3403 s390_slgr (code, ins->dreg, s390_r0);
3405 s390_basr (code, s390_r13, 0);
3407 s390_llong(code, ins->inst_imm);
3408 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3413 if (ins->dreg != ins->sreg1) {
3414 s390_lgr (code, ins->dreg, ins->sreg1);
3416 if (s390_is_imm16 (-ins->inst_imm)) {
3417 s390_lghi (code, s390_r0, ins->inst_imm);
3418 s390_slgr (code, ins->dreg, s390_r0);
3420 s390_basr (code, s390_r13, 0);
3422 s390_llong(code, ins->inst_imm);
3423 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3428 if (ins->dreg != ins->sreg1) {
3429 s390_lgr (code, ins->dreg, ins->sreg1);
3431 if (s390_is_imm16 (-ins->inst_imm)) {
3432 s390_lghi (code, s390_r0, ins->inst_imm);
3433 s390_slbgr (code, ins->dreg, s390_r0);
3435 s390_basr (code, s390_r13, 0);
3437 s390_llong(code, ins->inst_imm);
3438 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3442 case OP_SUB_OVF_CARRY: {
3444 s390_lghi (code, s390_r0, 0);
3445 s390_lgr (code, s390_r1, s390_r0);
3446 s390_slbgr (code, s390_r0, s390_r1);
3447 s390_sgr (code, ins->dreg, src2);
3448 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3449 s390_agr (code, ins->dreg, s390_r0);
3450 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3453 case OP_SUB_OVF_UN_CARRY: {
3455 s390_slbgr (code, ins->dreg, src2);
3456 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3460 if (ins->sreg1 == ins->dreg) {
3461 s390_ngr (code, ins->dreg, ins->sreg2);
3464 if (ins->sreg2 == ins->dreg) {
3465 s390_ngr (code, ins->dreg, ins->sreg1);
3468 s390_lgr (code, ins->dreg, ins->sreg1);
3469 s390_ngr (code, ins->dreg, ins->sreg2);
3475 if (ins->dreg != ins->sreg1) {
3476 s390_lgr (code, ins->dreg, ins->sreg1);
3478 if (s390_is_imm16 (ins->inst_imm)) {
3479 s390_lghi (code, s390_r0, ins->inst_imm);
3480 s390_ngr (code, ins->dreg, s390_r0);
3482 s390_basr (code, s390_r13, 0);
3484 s390_llong(code, ins->inst_imm);
3485 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3490 s390_lgr (code, s390_r1, ins->sreg1);
3491 s390_dsgr (code, s390_r0, ins->sreg2);
3492 s390_lgr (code, ins->dreg, s390_r1);
3496 s390_lgr (code, s390_r1, ins->sreg1);
3497 s390_lghi (code, s390_r0, 0);
3498 s390_dlgr (code, s390_r0, ins->sreg2);
3499 s390_lgr (code, ins->dreg, s390_r1);
3503 s390_lgr (code, s390_r1, ins->sreg1);
3504 s390_dsgr (code, s390_r0, ins->sreg2);
3505 s390_lgr (code, ins->dreg, s390_r0);
3509 s390_lgr (code, s390_r1, ins->sreg1);
3510 s390_lghi (code, s390_r0, 0);
3511 s390_dlgr (code, s390_r0, ins->sreg2);
3512 s390_lgr (code, ins->dreg, s390_r0);
3516 if (ins->sreg1 == ins->dreg) {
3517 s390_ogr (code, ins->dreg, ins->sreg2);
3520 if (ins->sreg2 == ins->dreg) {
3521 s390_ogr (code, ins->dreg, ins->sreg1);
3524 s390_lgr (code, ins->dreg, ins->sreg1);
3525 s390_ogr (code, ins->dreg, ins->sreg2);
3531 if (ins->dreg != ins->sreg1) {
3532 s390_lgr (code, ins->dreg, ins->sreg1);
3534 if (s390_is_imm16 (ins->inst_imm)) {
3535 s390_lghi (code, s390_r0, ins->inst_imm);
3536 s390_ogr (code, ins->dreg, s390_r0);
3538 s390_basr (code, s390_r13, 0);
3540 s390_llong(code, ins->inst_imm);
3541 s390_og (code, ins->dreg, 0, s390_r13, 4);
3546 if (ins->sreg1 == ins->dreg) {
3547 s390_xgr (code, ins->dreg, ins->sreg2);
3550 if (ins->sreg2 == ins->dreg) {
3551 s390_xgr (code, ins->dreg, ins->sreg1);
3554 s390_lgr (code, ins->dreg, ins->sreg1);
3555 s390_xgr (code, ins->dreg, ins->sreg2);
3561 if (ins->dreg != ins->sreg1) {
3562 s390_lgr (code, ins->dreg, ins->sreg1);
3564 if (s390_is_imm16 (ins->inst_imm)) {
3565 s390_lghi (code, s390_r0, ins->inst_imm);
3566 s390_xgr (code, ins->dreg, s390_r0);
3568 s390_basr (code, s390_r13, 0);
3570 s390_llong(code, ins->inst_imm);
3571 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3577 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3582 if (ins->sreg1 != ins->dreg) {
3583 s390_lgr (code, ins->dreg, ins->sreg1);
3585 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3590 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3595 if (ins->sreg1 != ins->dreg) {
3596 s390_lgr (code, ins->dreg, ins->sreg1);
3598 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3602 case OP_LSHR_UN_IMM: {
3603 if (ins->sreg1 != ins->dreg) {
3604 s390_lgr (code, ins->dreg, ins->sreg1);
3606 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3611 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3615 if (ins->sreg1 != ins->dreg) {
3616 s390_lgr (code, ins->dreg, ins->sreg1);
3618 s390_lghi (code, s390_r0, -1);
3619 s390_xgr (code, ins->dreg, s390_r0);
3623 s390_lcgr (code, ins->dreg, ins->sreg1);
3628 s390_msgr (code, ins->dreg, src2);
3633 if (ins->dreg != ins->sreg1) {
3634 s390_lgr (code, ins->dreg, ins->sreg1);
3636 if (s390_is_imm16 (ins->inst_imm)) {
3637 s390_lghi (code, s390_r13, ins->inst_imm);
3639 s390_basr (code, s390_r13, 0);
3641 s390_llong(code, ins->inst_imm);
3642 s390_lg (code, s390_r13, 0, s390_r13, 4);
3644 s390_msgr (code, ins->dreg, s390_r13);
3649 s390_ltgr (code, s390_r1, ins->sreg1);
3650 s390_jz (code, 0); CODEPTR(code, o[0]);
3651 s390_ltgr (code, s390_r0, ins->sreg2);
3653 s390_lghi (code, s390_r1, 0);
3654 s390_j (code, 0); CODEPTR(code, o[1]);
3655 s390_xgr (code, s390_r0, s390_r1);
3656 s390_msgr (code, s390_r1, ins->sreg2);
3657 s390_xgr (code, s390_r0, s390_r1);
3658 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3659 s390_ltgr (code, s390_r0, s390_r0);
3660 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3661 PTRSLOT (code, o[0]);
3662 PTRSLOT (code, o[1]);
3663 s390_lgr (code, ins->dreg, s390_r1);
3666 case OP_LMUL_OVF_UN: {
3667 s390_lghi (code, s390_r0, 0);
3668 s390_lgr (code, s390_r1, ins->sreg1);
3669 s390_mlgr (code, s390_r0, ins->sreg2);
3670 s390_ltgr (code, s390_r0, s390_r0);
3671 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3672 s390_lgr (code, ins->dreg, s390_r1);
3676 g_assert_not_reached ();
3678 s390_algr (code, ins->dreg, src2);
3683 s390_agr (code, ins->dreg, src2);
3687 g_assert_not_reached ();
3689 s390_alcgr (code, ins->dreg, src2);
3693 if (ins->dreg != ins->sreg1) {
3694 s390_lgfr (code, ins->dreg, ins->sreg1);
3696 if (s390_is_imm16 (ins->inst_imm)) {
3697 s390_aghi(code, ins->dreg, ins->inst_imm);
3699 s390_basr (code, s390_r13, 0);
3701 s390_word (code, ins->inst_imm);
3702 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3707 if (ins->dreg != ins->sreg1) {
3708 s390_lgfr (code, ins->dreg, ins->sreg1);
3710 if (s390_is_imm16 (ins->inst_imm)) {
3711 s390_lghi (code, s390_r0, ins->inst_imm);
3712 s390_alcgr (code, ins->dreg, s390_r0);
3714 s390_basr (code, s390_r13, 0);
3716 s390_word (code, ins->inst_imm);
3717 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3718 s390_alcgr (code, ins->dreg, s390_r13);
3723 case OP_S390_LADD_OVF: {
3725 s390_agr (code, ins->dreg, src2);
3726 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3729 case OP_LADD_OVF_UN:
3730 case OP_S390_LADD_OVF_UN: {
3732 s390_algr (code, ins->dreg, src2);
3733 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3737 CHECK_SRCDST_NCOM_I;
3738 s390_slgr (code, ins->dreg, src2);
3742 CHECK_SRCDST_NCOM_I;
3743 s390_sgr (code, ins->dreg, src2);
3747 CHECK_SRCDST_NCOM_I;
3748 s390_slbgr (code, ins->dreg, src2);
3752 if (ins->dreg != ins->sreg1) {
3753 s390_lgfr (code, ins->dreg, ins->sreg1);
3755 if (s390_is_imm16 (-ins->inst_imm)) {
3756 s390_aghi (code, ins->dreg, -ins->inst_imm);
3758 s390_basr (code, s390_r13, 0);
3760 s390_word (code, ins->inst_imm);
3761 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3766 s390_basr (code, s390_r13, 0);
3768 s390_word (code, ins->inst_imm);
3769 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3773 case OP_S390_ISUB_OVF: {
3775 s390_sr (code, ins->dreg, src2);
3776 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3777 s390_lgfr (code, ins->dreg, ins->dreg);
3780 case OP_ISUB_OVF_UN:
3781 case OP_S390_ISUB_OVF_UN: {
3783 s390_slr (code, ins->dreg, src2);
3784 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3785 s390_llgfr(code, ins->dreg, ins->dreg);
3789 case OP_S390_LSUB_OVF: {
3791 s390_sgr (code, ins->dreg, src2);
3792 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3795 case OP_LSUB_OVF_UN:
3796 case OP_S390_LSUB_OVF_UN: {
3798 s390_slgr (code, ins->dreg, src2);
3799 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3803 CHECK_SRCDST_NCOM_I;
3804 s390_ngr (code, ins->dreg, src2);
3808 if (ins->dreg != ins->sreg1) {
3809 s390_lgfr (code, ins->dreg, ins->sreg1);
3811 if (s390_is_imm16 (ins->inst_imm)) {
3812 s390_lghi (code, s390_r0, ins->inst_imm);
3813 s390_ngr (code, ins->dreg, s390_r0);
3815 s390_basr (code, s390_r13, 0);
3817 s390_llong(code, ins->inst_imm);
3818 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3823 s390_lgfr (code, s390_r0, ins->sreg1);
3824 s390_srda (code, s390_r0, 0, 32);
3825 s390_dr (code, s390_r0, ins->sreg2);
3826 s390_lgfr (code, ins->dreg, s390_r1);
3830 s390_lgfr (code, s390_r0, ins->sreg1);
3831 s390_srdl (code, s390_r0, 0, 32);
3832 s390_dlr (code, s390_r0, ins->sreg2);
3833 s390_lgfr (code, ins->dreg, s390_r1);
3837 if (s390_is_imm16 (ins->inst_imm)) {
3838 s390_lghi (code, s390_r13, ins->inst_imm);
3839 s390_lgfr (code, s390_r0, ins->sreg1);
3841 s390_basr (code, s390_r13, 0);
3843 s390_word (code, ins->inst_imm);
3844 s390_lgfr (code, s390_r0, ins->sreg1);
3845 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3847 s390_srda (code, s390_r0, 0, 32);
3848 s390_dr (code, s390_r0, ins->sreg2);
3849 s390_lgfr (code, ins->dreg, s390_r1);
3853 s390_lgfr (code, s390_r0, ins->sreg1);
3854 s390_srda (code, s390_r0, 0, 32);
3855 s390_dr (code, s390_r0, ins->sreg2);
3856 s390_lgfr (code, ins->dreg, s390_r0);
3859 s390_lgfr (code, s390_r0, ins->sreg1);
3860 s390_srdl (code, s390_r0, 0, 32);
3861 s390_dlr (code, s390_r0, ins->sreg2);
3862 s390_lgfr (code, ins->dreg, s390_r0);
3866 if (s390_is_imm16 (ins->inst_imm)) {
3867 s390_lghi (code, s390_r13, ins->inst_imm);
3868 s390_lgfr (code, s390_r0, ins->sreg1);
3870 s390_basr (code, s390_r13, 0);
3872 s390_word (code, ins->inst_imm);
3873 s390_lgfr (code, s390_r0, ins->sreg1);
3874 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3876 s390_srda (code, s390_r0, 0, 32);
3877 s390_dr (code, s390_r0, ins->sreg2);
3878 s390_lgfr (code, ins->dreg, s390_r0);
3883 s390_ogr (code, ins->dreg, src2);
3887 if (ins->dreg != ins->sreg1) {
3888 s390_lgfr (code, ins->dreg, ins->sreg1);
3890 if (s390_is_imm16 (ins->inst_imm)) {
3891 s390_lghi (code, s390_r0, ins->inst_imm);
3892 s390_ogr (code, ins->dreg, s390_r0);
3894 s390_basr (code, s390_r13, 0);
3896 s390_llong(code, ins->inst_imm);
3897 s390_og (code, ins->dreg, 0, s390_r13, 4);
3903 s390_xgr (code, ins->dreg, src2);
3907 if (ins->dreg != ins->sreg1) {
3908 s390_lgfr (code, ins->dreg, ins->sreg1);
3910 if (s390_is_imm16 (ins->inst_imm)) {
3911 s390_lghi (code, s390_r0, ins->inst_imm);
3912 s390_xgr (code, ins->dreg, s390_r0);
3914 s390_basr (code, s390_r13, 0);
3916 s390_llong(code, ins->inst_imm);
3917 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3923 s390_sll (code, ins->dreg, src2, 0);
3927 if (ins->sreg1 != ins->dreg) {
3928 s390_lgfr (code, ins->dreg, ins->sreg1);
3930 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3935 s390_sra (code, ins->dreg, src2, 0);
3939 if (ins->sreg1 != ins->dreg) {
3940 s390_lgfr (code, ins->dreg, ins->sreg1);
3942 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3945 case OP_ISHR_UN_IMM: {
3946 if (ins->sreg1 != ins->dreg) {
3947 s390_lgfr (code, ins->dreg, ins->sreg1);
3949 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3954 s390_srl (code, ins->dreg, src2, 0);
3958 if (ins->sreg1 != ins->dreg) {
3959 s390_lgfr (code, ins->dreg, ins->sreg1);
3961 s390_lghi (code, s390_r0, -1);
3962 s390_xgr (code, ins->dreg, s390_r0);
3966 s390_lcgr (code, ins->dreg, ins->sreg1);
3971 s390_msr (code, ins->dreg, src2);
3975 if (ins->dreg != ins->sreg1) {
3976 s390_lgfr (code, ins->dreg, ins->sreg1);
3978 if (s390_is_imm16 (ins->inst_imm)) {
3979 s390_lghi (code, s390_r13, ins->inst_imm);
3981 s390_basr (code, s390_r13, 0);
3983 s390_word (code, ins->inst_imm);
3984 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3986 s390_msr (code, ins->dreg, s390_r13);
3991 s390_ltr (code, s390_r1, ins->sreg1);
3992 s390_jz (code, 0); CODEPTR(code, o[0]);
3993 s390_ltr (code, s390_r0, ins->sreg2);
3995 s390_lhi (code, s390_r1, 0);
3996 s390_j (code, 0); CODEPTR(code, o[1]);
3997 s390_xr (code, s390_r0, s390_r1);
3998 s390_msr (code, s390_r1, ins->sreg2);
3999 s390_xr (code, s390_r0, s390_r1);
4000 s390_srl (code, s390_r0, 0, 31);
4001 s390_ltr (code, s390_r0, s390_r0);
4002 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4003 PTRSLOT (code, o[0]);
4004 PTRSLOT (code, o[1]);
4005 s390_lgfr (code, ins->dreg, s390_r1);
4008 case OP_IMUL_OVF_UN: {
4009 s390_lhi (code, s390_r0, 0);
4010 s390_lr (code, s390_r1, ins->sreg1);
4011 s390_mlr (code, s390_r0, ins->sreg2);
4012 s390_ltr (code, s390_r0, s390_r0);
4013 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4014 s390_lgfr (code, ins->dreg, s390_r1);
4019 if (s390_is_imm16(ins->inst_c0)) {
4020 s390_lghi (code, ins->dreg, ins->inst_c0);
4022 s390_basr (code, s390_r13, 0);
4024 s390_llong(code, ins->inst_c0);
4025 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4030 s390_basr (code, s390_r13, 0);
4032 mono_add_patch_info (cfg, code - cfg->native_code,
4033 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4034 s390_llong(code, 0);
4035 s390_lg (code,ins->dreg, 0, s390_r13, 4);
4038 case OP_JUMP_TABLE: {
4039 mono_add_patch_info (cfg, code - cfg->native_code,
4040 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4041 s390_basr (code, s390_r13, 0);
4043 s390_llong (code, 0);
4044 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4048 if (ins->dreg != ins->sreg1) {
4049 s390_lgr (code, ins->dreg, ins->sreg1);
4053 case OP_LCONV_TO_I8:
4055 s390_lgfr (code, ins->dreg, ins->sreg1);
4057 case OP_LCONV_TO_I4:
4058 s390_lgfr (code, ins->dreg, ins->sreg1);
4061 case OP_LCONV_TO_U8:
4062 case OP_LCONV_TO_U4:
4064 s390_llgfr (code, ins->dreg, ins->sreg1);
4066 case OP_LCONV_TO_OVF_U4:
4067 s390_basr (code, s390_r13, 0);
4069 s390_llong(code, 4294967295);
4070 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
4071 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4072 s390_ltgr (code, ins->sreg1, ins->sreg1);
4073 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4074 s390_llgfr(code, ins->dreg, ins->sreg1);
4076 case OP_LCONV_TO_OVF_I4_UN:
4077 s390_basr (code, s390_r13, 0);
4079 s390_llong(code, 2147483647);
4080 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
4081 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4082 s390_ltgr (code, ins->sreg1, ins->sreg1);
4083 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4084 s390_lgfr (code, ins->dreg, ins->sreg1);
4087 case OP_FCONV_TO_R4: {
4088 if (ins->dreg != ins->sreg1) {
4089 s390_ldr (code, ins->dreg, ins->sreg1);
4093 case OP_S390_SETF4RET: {
4094 s390_ledbr (code, ins->dreg, ins->sreg1);
4098 if (s390_is_imm16 (ins->inst_offset)) {
4099 s390_lghi (code, s390_r13, ins->inst_offset);
4101 s390_bras (code, s390_r13, 0);
4103 s390_llong(code, ins->inst_offset);
4104 s390_lg (code, s390_r13, 0, s390_r13, 4);
4106 s390_ear (code, s390_r1, 0);
4107 s390_sllg(code, s390_r1, s390_r1, 0, 32);
4108 s390_ear (code, s390_r1, 1);
4109 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
4113 if (cfg->method->save_lmf)
4114 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4116 if (cfg->flags & MONO_CFG_HAS_TAIL) {
4117 code = emit_load_volatile_arguments (code, cfg);
4120 code = backUpStackPtr(cfg, code);
4121 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
4122 mono_add_patch_info (cfg, code - cfg->native_code,
4123 MONO_PATCH_INFO_METHOD_JUMP,
4125 s390_jcl (code, S390_CC_UN, 0);
4128 case OP_CHECK_THIS: {
4129 /* ensure ins->sreg1 is not NULL */
4130 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
4131 s390_ltgr (code, s390_r0, s390_r0);
4132 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
4136 int offset = cfg->sig_cookie + cfg->stack_usage;
4138 if (s390_is_imm16 (offset))
4139 s390_lghi (code, s390_r0, offset);
4141 s390_basr (code, s390_r13, 0);
4143 s390_llong(code, offset);
4144 s390_lg (code, s390_r0, 0, s390_r13, 0);
4146 s390_agr (code, s390_r0, cfg->frame_reg);
4147 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
4151 s390_basr (code, s390_r13, 0);
4153 call = (MonoCallInst*)ins;
4154 if (ins->flags & MONO_INST_HAS_METHOD)
4155 mono_add_patch_info (cfg, code-cfg->native_code,
4156 MONO_PATCH_INFO_METHOD,
4159 mono_add_patch_info (cfg, code-cfg->native_code,
4160 MONO_PATCH_INFO_ABS,
4162 s390_llong(code, 0);
4163 s390_lg (code, s390_r14, 0, s390_r13, 4);
4164 s390_basr (code, s390_r14, s390_r14);
4165 if (call->signature->ret->type == MONO_TYPE_R4)
4166 s390_ldebr (code, s390_f0, s390_f0);
4174 s390_basr (code, s390_r13, 0);
4176 call = (MonoCallInst*)ins;
4177 if (ins->flags & MONO_INST_HAS_METHOD)
4178 mono_add_patch_info (cfg, code-cfg->native_code,
4179 MONO_PATCH_INFO_METHOD,
4182 mono_add_patch_info (cfg, code-cfg->native_code,
4183 MONO_PATCH_INFO_ABS,
4185 s390_llong(code, 0);
4186 s390_lg (code, s390_r14, 0, s390_r13, 4);
4187 s390_basr (code, s390_r14, s390_r14);
4190 case OP_FCALL_REG: {
4191 call = (MonoCallInst*)ins;
4192 s390_lgr (code, s390_r1, ins->sreg1);
4193 s390_basr (code, s390_r14, s390_r1);
4194 if (call->signature->ret->type == MONO_TYPE_R4)
4195 s390_ldebr (code, s390_f0, s390_f0);
4201 case OP_VOIDCALL_REG:
4203 s390_lgr (code, s390_r1, ins->sreg1);
4204 s390_basr (code, s390_r14, s390_r1);
4207 case OP_FCALL_MEMBASE: {
4208 call = (MonoCallInst*)ins;
4209 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4210 s390_basr (code, s390_r14, s390_r1);
4211 if (call->signature->ret->type == MONO_TYPE_R4)
4212 s390_ldebr (code, s390_f0, s390_f0);
4215 case OP_LCALL_MEMBASE:
4216 case OP_VCALL_MEMBASE:
4217 case OP_VCALL2_MEMBASE:
4218 case OP_VOIDCALL_MEMBASE:
4219 case OP_CALL_MEMBASE: {
4220 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4221 s390_basr (code, s390_r14, s390_r1);
4228 if (cfg->param_area == 0)
4229 alloca_skip = S390_MINIMAL_STACK_SIZE;
4231 alloca_skip = cfg->param_area;
4233 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4234 s390_lgr (code, s390_r1, ins->sreg1);
4235 if (ins->flags & MONO_INST_INIT)
4236 s390_lgr (code, s390_r0, ins->sreg1);
4237 s390_aghi (code, s390_r1, 14);
4238 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4239 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4240 if (cfg->method->save_lmf) {
4241 /*----------------------------------*/
4242 /* we have to adjust lmf ebp value */
4243 /*----------------------------------*/
4244 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4246 s390_lgr (code, s390_r13, cfg->frame_reg);
4247 if (s390_is_imm16(lmfOffset))
4248 s390_aghi (code, s390_r13, lmfOffset);
4250 s390_basr (code, s390_r14, 0);
4252 s390_word (code, lmfOffset);
4253 s390_agf (code, s390_r13, 0, s390_r14, 4);
4255 s390_lgr (code, s390_r14, STK_BASE);
4256 s390_sgr (code, s390_r14, s390_r1);
4257 s390_stg (code, s390_r14, 0, s390_r13,
4258 G_STRUCT_OFFSET(MonoLMF, ebp));
4260 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4261 s390_sgr (code, STK_BASE, s390_r1);
4262 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4263 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4264 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4265 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4266 if (ins->flags & MONO_INST_INIT) {
4267 s390_lgr (code, s390_r1, s390_r0);
4268 s390_lgr (code, s390_r0, ins->dreg);
4269 s390_lgr (code, s390_r14, s390_r12);
4270 s390_lghi (code, s390_r13, 0);
4271 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4273 s390_lgr (code, s390_r12, s390_r14);
4278 s390_lgr (code, s390_r2, ins->sreg1);
4279 s390_basr (code, s390_r13, 0);
4281 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4282 (gpointer) "mono_arch_throw_exception");
4283 s390_llong(code, 0);
4284 s390_lg (code, s390_r14, 0, s390_r13, 4);
4285 s390_basr (code, s390_r14, s390_r14);
4289 s390_lgr (code, s390_r2, ins->sreg1);
4290 s390_basr (code, s390_r13, 0);
4292 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4293 (gpointer) "mono_arch_rethrow_exception");
4294 s390_llong(code, 0);
4295 s390_lg (code, s390_r14, 0, s390_r13, 4);
4296 s390_basr (code, s390_r14, s390_r14);
4299 case OP_START_HANDLER: {
4300 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4302 S390_LONG (code, stg, stg, s390_r14, 0,
4303 spvar->inst_basereg,
4304 spvar->inst_offset);
4307 case OP_ENDFILTER: {
4308 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4310 if (ins->sreg1 != s390_r2)
4311 s390_lgr(code, s390_r2, ins->sreg1);
4312 S390_LONG (code, lg, lg, s390_r14, 0,
4313 spvar->inst_basereg,
4314 spvar->inst_offset);
4315 s390_br (code, s390_r14);
4318 case OP_ENDFINALLY: {
4319 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4321 S390_LONG (code, lg, lg, s390_r14, 0,
4322 spvar->inst_basereg,
4323 spvar->inst_offset);
4324 s390_br (code, s390_r14);
4327 case OP_CALL_HANDLER: {
4328 mono_add_patch_info (cfg, code-cfg->native_code,
4329 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4330 s390_brasl (code, s390_r14, 0);
4331 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4335 ins->inst_c0 = code - cfg->native_code;
4338 case OP_RELAXED_NOP:
4341 case OP_DUMMY_STORE:
4342 case OP_NOT_REACHED:
4346 case OP_SEQ_POINT: {
4349 if (cfg->compile_aot)
4353 * Read from the single stepping trigger page. This will cause a
4354 * SIGSEGV when single stepping is enabled.
4355 * We do this _before_ the breakpoint, so single stepping after
4356 * a breakpoint is hit will step to the next IL offset.
4358 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4359 breakpointCode.pTrigger = ss_trigger_page;
4360 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4361 code += BREAKPOINT_SIZE;
4364 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4367 * A placeholder for a possible breakpoint inserted by
4368 * mono_arch_set_breakpoint ().
4370 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4376 EMIT_UNCOND_BRANCH(ins);
4379 s390_br (code, ins->sreg1);
4385 s390_lghi(code, ins->dreg, 1);
4387 s390_lghi(code, ins->dreg, 0);
4393 s390_lghi(code, ins->dreg, 1);
4395 s390_lghi(code, ins->dreg, 0);
4401 s390_lghi(code, ins->dreg, 1);
4403 s390_lghi(code, ins->dreg, 0);
4409 s390_lghi(code, ins->dreg, 1);
4411 s390_lghi(code, ins->dreg, 0);
4417 s390_lghi(code, ins->dreg, 1);
4419 s390_lghi(code, ins->dreg, 0);
4422 case OP_COND_EXC_EQ:
4423 case OP_COND_EXC_IEQ:
4424 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4426 case OP_COND_EXC_NE_UN:
4427 case OP_COND_EXC_INE_UN:
4428 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4430 case OP_COND_EXC_LT:
4431 case OP_COND_EXC_ILT:
4432 case OP_COND_EXC_LT_UN:
4433 case OP_COND_EXC_ILT_UN:
4434 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4436 case OP_COND_EXC_GT:
4437 case OP_COND_EXC_IGT:
4438 case OP_COND_EXC_GT_UN:
4439 case OP_COND_EXC_IGT_UN:
4440 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4442 case OP_COND_EXC_GE:
4443 case OP_COND_EXC_IGE:
4444 case OP_COND_EXC_GE_UN:
4445 case OP_COND_EXC_IGE_UN:
4446 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4448 case OP_COND_EXC_LE:
4449 case OP_COND_EXC_ILE:
4450 case OP_COND_EXC_LE_UN:
4451 case OP_COND_EXC_ILE_UN:
4452 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4454 case OP_COND_EXC_OV:
4455 case OP_COND_EXC_IOV:
4456 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4458 case OP_COND_EXC_NO:
4459 case OP_COND_EXC_INO:
4460 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4463 case OP_COND_EXC_IC:
4464 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4466 case OP_COND_EXC_NC:
4467 case OP_COND_EXC_INC:
4468 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4472 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4476 EMIT_COND_BRANCH (ins, S390_CC_NE);
4482 EMIT_COND_BRANCH (ins, S390_CC_LT);
4488 EMIT_COND_BRANCH (ins, S390_CC_GT);
4494 EMIT_COND_BRANCH (ins, S390_CC_GE);
4500 EMIT_COND_BRANCH (ins, S390_CC_LE);
4503 /* floating point opcodes */
4505 if (*((double *) ins->inst_p0) == 0) {
4506 s390_lzdr (code, ins->dreg);
4508 s390_basr (code, s390_r13, 0);
4510 s390_llong (code, ins->inst_p0);
4511 s390_lg (code, s390_r13, 0, s390_r13, 4);
4512 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4517 if (*((float *) ins->inst_p0) == 0) {
4518 s390_lzdr (code, ins->dreg);
4520 s390_basr (code, s390_r13, 0);
4522 s390_llong(code, ins->inst_p0);
4523 s390_lg (code, s390_r13, 0, s390_r13, 4);
4524 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4528 case OP_STORER8_MEMBASE_REG: {
4529 S390_LONG (code, stdy, std, ins->sreg1, 0,
4530 ins->inst_destbasereg, ins->inst_offset);
4533 case OP_LOADR8_MEMBASE: {
4534 S390_LONG (code, ldy, ld, ins->dreg, 0,
4535 ins->inst_basereg, ins->inst_offset);
4538 case OP_STORER4_MEMBASE_REG: {
4539 s390_ledbr (code, s390_f15, ins->sreg1);
4540 S390_LONG (code, stey, ste, s390_f15, 0,
4541 ins->inst_destbasereg, ins->inst_offset);
4544 case OP_LOADR4_MEMBASE: {
4545 S390_LONG (code, ldy, ld, s390_f15, 0,
4546 ins->inst_basereg, ins->inst_offset);
4547 s390_ldebr (code, ins->dreg, s390_f15);
4550 case OP_ICONV_TO_R_UN: {
4551 s390_cdfbr (code, ins->dreg, ins->sreg1);
4552 s390_ltr (code, ins->sreg1, ins->sreg1);
4553 s390_jnl (code, 12);
4554 s390_basr (code, s390_r13, 0);
4556 s390_word (code, 0x41f00000);
4557 s390_word (code, 0);
4558 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4561 case OP_LCONV_TO_R_UN: {
4562 s390_cdgbr (code, ins->dreg, ins->sreg1);
4563 s390_ltgr (code, ins->sreg1, ins->sreg1);
4564 s390_jnl (code, 12);
4565 s390_basr (code, s390_r13, 0);
4567 s390_word (code, 0x41f00000);
4568 s390_word (code, 0);
4569 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4572 case OP_LCONV_TO_R4:
4573 case OP_ICONV_TO_R4: {
4574 s390_cdgbr (code, ins->dreg, ins->sreg1);
4577 case OP_LCONV_TO_R8:
4578 case OP_ICONV_TO_R8: {
4579 s390_cdgbr (code, ins->dreg, ins->sreg1);
4582 case OP_FCONV_TO_I1:
4583 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4585 case OP_FCONV_TO_U1:
4586 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4588 case OP_FCONV_TO_I2:
4589 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4591 case OP_FCONV_TO_U2:
4592 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4594 case OP_FCONV_TO_I4:
4596 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4598 case OP_FCONV_TO_U4:
4600 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4602 case OP_FCONV_TO_I8:
4603 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4605 case OP_LCONV_TO_OVF_I: {
4606 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4608 s390_ltgr (code, ins->sreg2, ins->sreg2);
4609 s390_jnl (code, 0); CODEPTR(code, o[0]);
4610 s390_ltgr (code, ins->sreg1, ins->sreg1);
4611 s390_jnl (code, 0); CODEPTR(code, o[1]);
4612 s390_lhi (code, s390_r13, -1);
4613 s390_cgr (code, ins->sreg1, s390_r13);
4614 s390_jnz (code, 0); CODEPTR(code, o[2]);
4615 if (ins->dreg != ins->sreg2)
4616 s390_lgr (code, ins->dreg, ins->sreg2);
4617 s390_j (code, 0); CODEPTR(code, o[3]);
4618 PTRSLOT(code, o[0]);
4619 s390_jz (code, 0); CODEPTR(code, o[4]);
4620 PTRSLOT(code, o[1]);
4621 PTRSLOT(code, o[2]);
4622 mono_add_patch_info (cfg, code - cfg->native_code,
4623 MONO_PATCH_INFO_EXC, "OverflowException");
4624 s390_brasl (code, s390_r14, 0);
4625 PTRSLOT(code, o[3]);
4626 PTRSLOT(code, o[4]);
4630 s390_lpdbr (code, ins->dreg, ins->sreg1);
4634 s390_sqdbr (code, ins->dreg, ins->sreg1);
4639 s390_adbr (code, ins->dreg, src2);
4643 CHECK_SRCDST_NCOM_F;
4644 s390_sdbr (code, ins->dreg, src2);
4649 s390_mdbr (code, ins->dreg, src2);
4653 CHECK_SRCDST_NCOM_F;
4654 s390_ddbr (code, ins->dreg, src2);
4658 s390_lcdbr (code, ins->dreg, ins->sreg1);
4662 CHECK_SRCDST_NCOM_F;
4663 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4667 s390_cdbr (code, ins->sreg1, ins->sreg2);
4671 s390_cdbr (code, ins->sreg1, ins->sreg2);
4672 s390_lghi (code, ins->dreg, 1);
4674 s390_lghi (code, ins->dreg, 0);
4678 s390_cdbr (code, ins->sreg1, ins->sreg2);
4679 s390_lghi (code, ins->dreg, 1);
4681 s390_lghi (code, ins->dreg, 0);
4685 s390_cdbr (code, ins->sreg1, ins->sreg2);
4686 s390_lghi (code, ins->dreg, 1);
4688 s390_lghi (code, ins->dreg, 0);
4692 s390_cdbr (code, ins->sreg1, ins->sreg2);
4693 s390_lghi (code, ins->dreg, 1);
4695 s390_lghi (code, ins->dreg, 0);
4699 s390_cdbr (code, ins->sreg1, ins->sreg2);
4700 s390_lghi (code, ins->dreg, 1);
4702 s390_lghi (code, ins->dreg, 0);
4707 s390_jo (code, 0); CODEPTR(code, o);
4708 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4713 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4717 s390_jo (code, 0); CODEPTR(code, o);
4718 EMIT_COND_BRANCH (ins, S390_CC_LT);
4723 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4727 s390_jo (code, 0); CODEPTR(code, o);
4728 EMIT_COND_BRANCH (ins, S390_CC_GT);
4733 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4737 s390_jo (code, 0); CODEPTR(code, o);
4738 EMIT_COND_BRANCH (ins, S390_CC_GE);
4743 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4747 s390_jo (code, 0); CODEPTR(code, o);
4748 EMIT_COND_BRANCH (ins, S390_CC_LE);
4753 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4757 s390_lhi (code, s390_r13, 0x7f);
4758 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4759 s390_jz (code, 0); CODEPTR(code, o);
4760 mono_add_patch_info (cfg, code - cfg->native_code,
4761 MONO_PATCH_INFO_EXC, "ArithmeticException");
4762 s390_brasl (code, s390_r14,0);
4766 case OP_S390_MOVE: {
4767 if (ins->backend.size > 0) {
4768 if (ins->backend.size <= 256) {
4769 s390_mvc (code, ins->backend.size, ins->dreg,
4770 ins->inst_offset, ins->sreg1, ins->inst_imm);
4772 s390_lgr (code, s390_r0, ins->dreg);
4773 if (ins->inst_offset > 0) {
4774 if (s390_is_imm16 (ins->inst_offset)) {
4775 s390_aghi (code, s390_r0, ins->inst_offset);
4777 s390_basr (code, s390_r13, 0);
4779 s390_llong(code, ins->inst_offset);
4780 s390_ag (code, s390_r0, 0, s390_r13, 4);
4783 s390_lgr (code, s390_r12, ins->sreg1);
4784 if (ins->inst_imm > 0) {
4785 if (s390_is_imm16 (ins->inst_imm)) {
4786 s390_aghi (code, s390_r12, ins->inst_imm);
4788 s390_basr (code, s390_r13, 0);
4790 s390_llong(code, ins->inst_imm);
4791 s390_ag (code, s390_r12, 0, s390_r13, 4);
4794 if (s390_is_imm16 (ins->backend.size)) {
4795 s390_lghi (code, s390_r1, ins->backend.size);
4797 s390_basr (code, s390_r13, 0);
4799 s390_llong(code, ins->backend.size);
4800 s390_lg (code, s390_r1, 0, s390_r13, 4);
4802 s390_lgr (code, s390_r13, s390_r1);
4803 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4809 case OP_ATOMIC_ADD_I8: {
4810 s390_lgr (code, s390_r1, ins->sreg2);
4811 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4812 s390_agr (code, s390_r1, s390_r0);
4813 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4814 s390_jnz (code, -10);
4815 s390_lgr (code, ins->dreg, s390_r1);
4818 case OP_ATOMIC_ADD_NEW_I8: {
4819 s390_lgr (code, s390_r1, ins->sreg2);
4820 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4821 s390_agr (code, s390_r1, s390_r0);
4822 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4823 s390_jnz (code, -10);
4824 s390_lgr (code, ins->dreg, s390_r1);
4827 case OP_ATOMIC_EXCHANGE_I8: {
4828 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4829 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4830 s390_jnz (code, -6);
4831 s390_lgr (code, ins->dreg, s390_r0);
4834 case OP_ATOMIC_ADD_I4: {
4835 s390_lgfr(code, s390_r1, ins->sreg2);
4836 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4837 s390_agr (code, s390_r1, s390_r0);
4838 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4839 s390_jnz (code, -9);
4840 s390_lgfr(code, ins->dreg, s390_r1);
4843 case OP_ATOMIC_ADD_NEW_I4: {
4844 s390_lgfr(code, s390_r1, ins->sreg2);
4845 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4846 s390_agr (code, s390_r1, s390_r0);
4847 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4848 s390_jnz (code, -9);
4849 s390_lgfr(code, ins->dreg, s390_r1);
4852 case OP_ATOMIC_EXCHANGE_I4: {
4853 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4854 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4855 s390_jnz (code, -4);
4856 s390_lgfr(code, ins->dreg, s390_r0);
4859 case OP_S390_BKCHAIN: {
4860 s390_lgr (code, ins->dreg, ins->sreg1);
4861 if (s390_is_imm16 (cfg->stack_offset)) {
4862 s390_aghi (code, ins->dreg, cfg->stack_offset);
4864 s390_basr (code, s390_r13, 0);
4866 s390_llong(code, cfg->stack_offset);
4867 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4871 case OP_MEMORY_BARRIER: {
4874 case OP_GC_LIVENESS_DEF:
4875 case OP_GC_LIVENESS_USE:
4876 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4877 ins->backend.pc_offset = code - cfg->native_code;
4879 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4880 ins->backend.pc_offset = code - cfg->native_code;
4881 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4884 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4885 g_assert_not_reached ();
4888 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4889 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4890 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4891 g_assert_not_reached ();
4896 last_offset = offset;
4899 cfg->code_len = code - cfg->native_code;
4902 /*========================= End of Function ========================*/
4904 /*------------------------------------------------------------------*/
4906 /* Name - mono_arch_register_lowlevel_calls */
4908 /* Function - Register routines to help with --trace operation. */
4910 /*------------------------------------------------------------------*/
4913 mono_arch_register_lowlevel_calls (void)
4917 /*========================= End of Function ========================*/
4919 /*------------------------------------------------------------------*/
4921 /* Name - mono_arch_patch_code */
4923 /* Function - Process the patch data created during the */
4924 /* instruction build process. This resolves jumps, */
4925 /* calls, variables etc. */
4927 /*------------------------------------------------------------------*/
4930 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4931 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4933 MonoJumpInfo *patch_info;
4935 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4936 unsigned char *ip = patch_info->ip.i + code;
4937 gconstpointer target = NULL;
4939 target = mono_resolve_patch_target (method, domain, code,
4940 patch_info, run_cctors);
4942 switch (patch_info->type) {
4943 case MONO_PATCH_INFO_IP:
4944 case MONO_PATCH_INFO_EXC_NAME:
4945 case MONO_PATCH_INFO_LDSTR:
4946 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4947 case MONO_PATCH_INFO_LDTOKEN:
4948 case MONO_PATCH_INFO_EXC:
4949 case MONO_PATCH_INFO_ABS:
4950 case MONO_PATCH_INFO_METHOD:
4951 case MONO_PATCH_INFO_RGCTX_FETCH:
4952 case MONO_PATCH_INFO_INTERNAL_METHOD:
4953 case MONO_PATCH_INFO_CLASS_INIT:
4954 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4955 case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
4956 s390_patch_addr (ip, (guint64) target);
4958 case MONO_PATCH_INFO_SWITCH:
4959 /*----------------------------------*/
4960 /* ip points at the basr r13,0/j +4 */
4961 /* instruction the vtable value */
4962 /* follows this (i.e. ip+6) */
4963 /*----------------------------------*/
4964 *((gconstpointer *)(ip+6)) = target;
4966 case MONO_PATCH_INFO_METHODCONST:
4967 case MONO_PATCH_INFO_CLASS:
4968 case MONO_PATCH_INFO_IMAGE:
4969 case MONO_PATCH_INFO_FIELD:
4970 case MONO_PATCH_INFO_IID:
4971 target = S390_RELATIVE(target, ip);
4972 s390_patch_rel (ip, (guint64) target);
4974 case MONO_PATCH_INFO_R4:
4975 case MONO_PATCH_INFO_R8:
4976 case MONO_PATCH_INFO_METHOD_REL:
4977 g_assert_not_reached ();
4980 target = S390_RELATIVE(target, ip);
4982 s390_patch_rel (ip, (guint64) target);
4987 /*========================= End of Function ========================*/
4989 /*------------------------------------------------------------------*/
4991 /* Name - emit_load_volatile_arguments */
4993 /* Function - Emit the instructions to reload parameter regist- */
4994 /* registers for use with "tail" operations. */
4996 /* The register loading operations performed here */
4997 /* are the mirror of the store operations performed */
4998 /* in mono_arch_emit_prolog and need to be kept in */
4999 /* synchronization with it. */
5001 /*------------------------------------------------------------------*/
5004 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
5007 MonoMethod *method = cfg->method;
5008 MonoMethodSignature *sig = mono_method_signature(method);
5012 cinfo = get_call_info (NULL, NULL, sig);
5014 if (cinfo->struct_ret) {
5015 ArgInfo *ainfo = &cinfo->ret;
5016 inst = cfg->vret_addr;
5017 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5020 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5021 ArgInfo *ainfo = cinfo->args + i;
5022 inst = cfg->args [pos];
5024 if (inst->opcode == OP_REGVAR) {
5025 if (ainfo->regtype == RegTypeGeneral)
5026 s390_lgr (code, ainfo->reg, inst->dreg);
5027 else if (ainfo->regtype == RegTypeFP) {
5028 if (inst->dreg != ainfo->reg) {
5029 if (ainfo->size == 4) {
5030 s390_ldebr (code, ainfo->reg, inst->dreg);
5032 s390_ldr (code, ainfo->reg, inst->dreg);
5036 else if (ainfo->regtype == RegTypeBase) {
5038 g_assert_not_reached ();
5040 if (ainfo->regtype == RegTypeGeneral) {
5041 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5042 g_assert_not_reached();
5043 switch (ainfo->size) {
5045 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5048 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5051 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5054 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5057 } else if (ainfo->regtype == RegTypeBase) {
5058 } else if (ainfo->regtype == RegTypeFP) {
5059 if (ainfo->size == 8)
5060 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5061 else if (ainfo->size == 4)
5062 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5064 g_assert_not_reached ();
5065 } else if (ainfo->regtype == RegTypeStructByVal) {
5066 if (ainfo->reg != STK_BASE) {
5067 switch (ainfo->size) {
5069 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5072 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5075 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5078 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5082 } else if (ainfo->regtype == RegTypeStructByAddr) {
5083 if (ainfo->reg != STK_BASE) {
5084 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5087 g_assert_not_reached ();
5095 /*========================= End of Function ========================*/
5097 /*------------------------------------------------------------------*/
5099 /* Name - mono_arch_emit_prolog */
5101 /* Function - Create the instruction sequence for a function */
5104 /*------------------------------------------------------------------*/
5107 mono_arch_emit_prolog (MonoCompile *cfg)
5109 MonoMethod *method = cfg->method;
5111 MonoMethodSignature *sig;
5113 long alloc_size, pos, max_offset, i, cfa_offset = 0;
5120 cfg->code_size = 512;
5122 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5124 cfg->code_size += 256;
5125 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5126 cfg->code_size += 256;
5128 if (method->save_lmf)
5129 cfg->code_size += 200;
5131 cfg->native_code = code = g_malloc (cfg->code_size);
5133 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
5134 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
5135 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5136 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
5138 if (cfg->arch.bkchain_reg != -1)
5139 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
5141 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5142 cfg->used_int_regs |= 1 << 11;
5145 alloc_size = cfg->stack_offset;
5147 cfg->stack_usage = cfa_offset = alloc_size;
5148 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
5149 s390_lgr (code, s390_r11, STK_BASE);
5150 if (s390_is_imm16 (alloc_size)) {
5151 s390_aghi (code, STK_BASE, -alloc_size);
5153 int stackSize = alloc_size;
5154 while (stackSize > 32767) {
5155 s390_aghi (code, STK_BASE, -32767);
5158 s390_aghi (code, STK_BASE, -stackSize);
5160 s390_stg (code, s390_r11, 0, STK_BASE, 0);
5162 if (cfg->frame_reg != STK_BASE)
5163 s390_lgr (code, s390_r11, STK_BASE);
5165 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
5167 /* store runtime generic context */
5168 if (cfg->rgctx_var) {
5169 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
5171 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
5172 cfg->rgctx_var->inst_basereg,
5173 cfg->rgctx_var->inst_offset);
5176 /* compute max_offset in order to use short forward jumps
5177 * we always do it on s390 because the immediate displacement
5178 * for jumps is too small
5181 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5183 bb->max_offset = max_offset;
5185 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5188 MONO_BB_FOR_EACH_INS (bb, ins)
5189 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5192 /* load arguments allocated to register from the stack */
5193 sig = mono_method_signature (method);
5196 cinfo = get_call_info (cfg, cfg->mempool, sig);
5198 if (cinfo->struct_ret) {
5199 ArgInfo *ainfo = &cinfo->ret;
5200 inst = cfg->vret_addr;
5201 inst->backend.size = ainfo->vtsize;
5202 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5205 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5206 ArgInfo *ainfo = cinfo->args + i;
5207 inst = cfg->args [pos];
5209 if (inst->opcode == OP_VTARG_ADDR)
5210 inst = inst->inst_left;
5212 if (inst->opcode == OP_REGVAR) {
5213 if (ainfo->regtype == RegTypeGeneral)
5214 s390_lgr (code, inst->dreg, ainfo->reg);
5215 else if (ainfo->regtype == RegTypeFP) {
5216 if (inst->dreg != ainfo->reg) {
5217 if (ainfo->size == 4) {
5218 s390_ledbr (code, inst->dreg, ainfo->reg);
5220 s390_ldr (code, inst->dreg, ainfo->reg);
5224 else if (ainfo->regtype == RegTypeBase) {
5225 s390_lgr (code, s390_r13, STK_BASE);
5226 s390_aghi (code, s390_r13, alloc_size);
5227 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5229 g_assert_not_reached ();
5231 if (cfg->verbose_level > 2)
5232 g_print ("Argument %d assigned to register %s\n",
5233 pos, mono_arch_regname (inst->dreg));
5235 if (ainfo->regtype == RegTypeGeneral) {
5236 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5237 g_assert_not_reached();
5238 switch (ainfo->size) {
5240 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5243 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5246 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5249 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5252 } else if (ainfo->regtype == RegTypeBase) {
5253 } else if (ainfo->regtype == RegTypeFP) {
5254 if (ainfo->size == 8)
5255 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5256 else if (ainfo->size == 4)
5257 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5259 g_assert_not_reached ();
5260 } else if (ainfo->regtype == RegTypeStructByVal) {
5261 int doffset = inst->inst_offset;
5263 if (ainfo->reg != STK_BASE)
5267 s390_lgr (code, s390_r13, STK_BASE);
5268 s390_aghi (code, s390_r13, alloc_size);
5271 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5272 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5277 if (ainfo->reg == STK_BASE)
5278 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5279 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5282 if (ainfo->reg == STK_BASE)
5283 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5284 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5287 if (ainfo->reg == STK_BASE)
5288 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5289 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5292 if (ainfo->reg == STK_BASE)
5293 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5294 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5297 } else if (ainfo->regtype == RegTypeStructByAddr) {
5298 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5299 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5301 g_assert_not_reached ();
5306 if (method->save_lmf) {
5307 /*---------------------------------------------------------------*/
5308 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5309 /*---------------------------------------------------------------*/
5310 lmfOffset = alloc_size - sizeof(MonoLMF);
5312 s390_lgr (code, s390_r13, cfg->frame_reg);
5313 s390_aghi (code, s390_r13, lmfOffset);
5315 /*---------------------------------------------------------------*/
5316 /* Preserve the parameter registers while we fix up the lmf */
5317 /*---------------------------------------------------------------*/
5318 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5319 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5321 /*---------------------------------------------------------------*/
5322 /* On return from this call r2 have the address of the &lmf */
5323 /*---------------------------------------------------------------*/
5324 if (lmf_addr_tls_offset == -1) {
5325 s390_basr(code, s390_r14, 0);
5327 mono_add_patch_info (cfg, code - cfg->native_code,
5328 MONO_PATCH_INFO_INTERNAL_METHOD,
5329 (gpointer)"mono_get_lmf_addr");
5330 s390_llong(code, 0);
5331 s390_lg (code, s390_r1, 0, s390_r14, 4);
5332 s390_basr (code, s390_r14, s390_r1);
5334 /*-------------------------------------------------------*/
5335 /* Get LMF by getting value from thread level storage */
5336 /*-------------------------------------------------------*/
5337 s390_ear (code, s390_r1, 0);
5338 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5339 s390_ear (code, s390_r1, 1);
5340 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5343 /*---------------------------------------------------------------*/
5344 /* Set lmf.lmf_addr = jit_tls->lmf */
5345 /*---------------------------------------------------------------*/
5346 s390_stg (code, s390_r2, 0, s390_r13,
5347 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5349 /*---------------------------------------------------------------*/
5350 /* Get current lmf */
5351 /*---------------------------------------------------------------*/
5352 s390_lg (code, s390_r0, 0, s390_r2, 0);
5354 /*---------------------------------------------------------------*/
5355 /* Set our lmf as the current lmf */
5356 /*---------------------------------------------------------------*/
5357 s390_stg (code, s390_r13, 0, s390_r2, 0);
5359 /*---------------------------------------------------------------*/
5360 /* Have our lmf.previous_lmf point to the last lmf */
5361 /*---------------------------------------------------------------*/
5362 s390_stg (code, s390_r0, 0, s390_r13,
5363 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5365 /*---------------------------------------------------------------*/
5366 /* save method info */
5367 /*---------------------------------------------------------------*/
5368 s390_basr (code, s390_r1, 0);
5370 s390_llong (code, method);
5371 s390_lg (code, s390_r1, 0, s390_r1, 4);
5372 s390_stg (code, s390_r1, 0, s390_r13,
5373 G_STRUCT_OFFSET(MonoLMF, method));
5375 /*---------------------------------------------------------------*/
5376 /* save the current IP */
5377 /*---------------------------------------------------------------*/
5378 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5379 s390_basr (code, s390_r1, 0);
5380 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5382 /*---------------------------------------------------------------*/
5383 /* Save general and floating point registers */
5384 /*---------------------------------------------------------------*/
5385 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5386 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5387 for (i = 0; i < 16; i++) {
5388 s390_std (code, i, 0, s390_r13,
5389 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5392 /*---------------------------------------------------------------*/
5393 /* Restore the parameter registers now that we've set up the lmf */
5394 /*---------------------------------------------------------------*/
5395 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5396 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5400 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5402 cfg->code_len = code - cfg->native_code;
5403 g_assert (cfg->code_len < cfg->code_size);
5408 /*========================= End of Function ========================*/
5410 /*------------------------------------------------------------------*/
5412 /* Name - mono_arch_emit_epilog */
5414 /* Function - Emit the instructions for a function epilog. */
5416 /*------------------------------------------------------------------*/
5419 mono_arch_emit_epilog (MonoCompile *cfg)
5421 MonoMethod *method = cfg->method;
5424 int max_epilog_size = 96;
5426 if (cfg->method->save_lmf)
5427 max_epilog_size += 128;
5429 if (mono_jit_trace_calls != NULL)
5430 max_epilog_size += 128;
5431 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5432 max_epilog_size += 128;
5434 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5435 cfg->code_size *= 2;
5436 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5437 cfg->stat_code_reallocs++;
5440 code = cfg->native_code + cfg->code_len;
5442 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5443 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5447 if (method->save_lmf)
5448 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5450 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5451 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5453 code = backUpStackPtr(cfg, code);
5455 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5456 s390_br (code, s390_r14);
5458 cfg->code_len = code - cfg->native_code;
5460 g_assert (cfg->code_len < cfg->code_size);
5464 /*========================= End of Function ========================*/
5466 /*------------------------------------------------------------------*/
5468 /* Name - mono_arch_emit_exceptions */
5470 /* Function - Emit the blocks to handle exception conditions. */
5472 /*------------------------------------------------------------------*/
5475 mono_arch_emit_exceptions (MonoCompile *cfg)
5477 MonoJumpInfo *patch_info;
5483 MonoClass *exc_classes [MAX_EXC];
5484 guint8 *exc_throw_start [MAX_EXC];
5486 for (patch_info = cfg->patch_info;
5488 patch_info = patch_info->next) {
5489 if (patch_info->type == MONO_PATCH_INFO_EXC)
5493 code_size = exc_count * 48;
5495 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5496 cfg->code_size *= 2;
5497 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5498 cfg->stat_code_reallocs++;
5501 code = cfg->native_code + cfg->code_len;
5503 /*---------------------------------------------------------------------*/
5504 /* Add code to raise exceptions */
5505 /*---------------------------------------------------------------------*/
5506 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5507 switch (patch_info->type) {
5508 case MONO_PATCH_INFO_EXC: {
5509 guint8 *ip = patch_info->ip.i + cfg->native_code;
5510 MonoClass *exc_class;
5513 /*-----------------------------------------------------*/
5514 /* Patch the branch in epilog to come here */
5515 /*-----------------------------------------------------*/
5516 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5518 exc_class = mono_class_from_name (mono_defaults.corlib,
5520 patch_info->data.name);
5521 g_assert (exc_class);
5522 throw_ip = patch_info->ip.i;
5524 for (iExc = 0; iExc < nThrows; ++iExc)
5525 if (exc_classes [iExc] == exc_class)
5528 if (iExc < nThrows) {
5529 s390_jcl (code, S390_CC_UN,
5530 (guint64) exc_throw_start [iExc]);
5531 patch_info->type = MONO_PATCH_INFO_NONE;
5534 if (nThrows < MAX_EXC) {
5535 exc_classes [nThrows] = exc_class;
5536 exc_throw_start [nThrows] = code;
5539 /*---------------------------------------------*/
5540 /* Patch the parameter passed to the handler */
5541 /*---------------------------------------------*/
5542 s390_basr (code, s390_r13, 0);
5544 // s390_llong(code, patch_info->data.target);
5545 s390_llong(code, exc_class->type_token);
5546 /*---------------------------------------------*/
5547 /* Load return address & parameter register */
5548 /*---------------------------------------------*/
5549 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5550 cfg->native_code + 8), code));
5551 s390_lg (code, s390_r2, 0, s390_r13, 4);
5552 /*---------------------------------------------*/
5553 /* Reuse the current patch to set the jump */
5554 /*---------------------------------------------*/
5555 s390_basr (code, s390_r13, 0);
5557 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5558 patch_info->data.name = "mono_arch_throw_corlib_exception";
5559 patch_info->ip.i = code - cfg->native_code;
5560 s390_llong(code, 0);
5561 s390_lg (code, s390_r1, 0, s390_r13, 4);
5562 s390_br (code, s390_r1);
5572 cfg->code_len = code - cfg->native_code;
5574 g_assert (cfg->code_len < cfg->code_size);
5578 /*========================= End of Function ========================*/
5580 /*------------------------------------------------------------------*/
5582 /* Name - mono_arch_finish_init */
5584 /* Function - Setup the JIT's Thread Level Specific Data. */
5586 /*------------------------------------------------------------------*/
5589 mono_arch_finish_init (void)
5591 appdomain_tls_offset = mono_domain_get_tls_offset();
5592 lmf_tls_offset = mono_get_lmf_tls_offset();
5593 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5596 /*========================= End of Function ========================*/
5598 /*------------------------------------------------------------------*/
5600 /* Name - mono_arch_free_jit_tls_data */
5602 /* Function - Free tls data. */
5604 /*------------------------------------------------------------------*/
5607 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5611 /*========================= End of Function ========================*/
5613 /*------------------------------------------------------------------*/
5615 /* Name - mono_arch_emit_inst_for_method */
5617 /*------------------------------------------------------------------*/
5620 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5625 /*========================= End of Function ========================*/
5627 /*------------------------------------------------------------------*/
5629 /* Name - mono_arch_decompose_opts */
5631 /* Function - Decompose opcode into a System z opcode. */
5633 /*------------------------------------------------------------------*/
5636 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5639 * Have to rename these to avoid being decomposed normally, since the normal
5640 * decomposition does not work on S390.
5642 switch (ins->opcode) {
5644 ins->opcode = OP_S390_ISUB_OVF;
5646 case OP_ISUB_OVF_UN:
5647 ins->opcode = OP_S390_ISUB_OVF_UN;
5650 ins->opcode = OP_S390_IADD_OVF;
5652 case OP_IADD_OVF_UN:
5653 ins->opcode = OP_S390_IADD_OVF_UN;
5656 ins->opcode = OP_S390_LADD_OVF;
5658 case OP_LADD_OVF_UN:
5659 ins->opcode = OP_S390_LADD_OVF_UN;
5662 ins->opcode = OP_S390_LSUB_OVF;
5664 case OP_LSUB_OVF_UN:
5665 ins->opcode = OP_S390_LSUB_OVF_UN;
5672 /*========================= End of Function ========================*/
5674 /*------------------------------------------------------------------*/
5676 /* Name - mono_arch_print_tree */
5678 /* Function - Print platform-specific opcode details. */
5680 /* Returns - 1 - opcode details have been printed */
5681 /* 0 - opcode details have not been printed */
5683 /*------------------------------------------------------------------*/
5686 mono_arch_print_tree (MonoInst *tree, int arity)
5690 switch (tree->opcode) {
5691 case OP_S390_LOADARG:
5692 case OP_S390_ARGREG:
5693 case OP_S390_ARGPTR:
5694 printf ("[0x%lx(%s)]", tree->inst_offset,
5695 mono_arch_regname (tree->inst_basereg));
5698 case OP_S390_STKARG:
5699 printf ("[0x%lx(previous_frame)]",
5704 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5705 tree->inst_offset, tree->backend.size,
5706 mono_arch_regname(tree->dreg),
5708 mono_arch_regname(tree->sreg1));
5711 case OP_S390_SETF4RET:
5712 printf ("[f%s,f%s]",
5713 mono_arch_regname (tree->dreg),
5714 mono_arch_regname (tree->sreg1));
5718 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5720 mono_arch_regname (tree->sreg1));
5723 case OP_S390_BKCHAIN:
5724 printf ("[previous_frame(%s)]",
5725 mono_arch_regname (tree->sreg1));
5733 /*========================= End of Function ========================*/
5735 /*------------------------------------------------------------------*/
5737 /* Name - mono_arch_regalloc_cost */
5739 /* Function - Determine the cost, in the number of memory */
5740 /* references, of the action of allocating the var- */
5741 /* iable VMV into a register during global register */
5744 /* Returns - Cost */
5746 /*------------------------------------------------------------------*/
5749 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5755 /*========================= End of Function ========================*/
5757 /*------------------------------------------------------------------*/
5759 /* Name - mono_arch_get_domain_intrinsic */
5765 /*------------------------------------------------------------------*/
5768 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5772 if (appdomain_tls_offset == -1)
5775 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5776 ins->inst_offset = appdomain_tls_offset;
5780 /*========================= End of Function ========================*/
5782 /*------------------------------------------------------------------*/
5784 /* Name - mono_arch_flush_register_windows */
5790 /*------------------------------------------------------------------*/
5793 mono_arch_flush_register_windows (void)
5797 /*========================= End of Function ========================*/
5799 /*------------------------------------------------------------------*/
5801 /* Name - mono_arch_is_inst_imm */
5803 /* Function - Determine if operand qualifies as an immediate */
5804 /* value. For s390 this is a value -32768-32768 */
5806 /* Returns - True|False - is [not] immediate value. */
5808 /*------------------------------------------------------------------*/
5811 mono_arch_is_inst_imm (gint64 imm)
5813 return s390_is_imm16 (imm);
5816 /*========================= End of Function ========================*/
5818 /*------------------------------------------------------------------*/
5820 /* Name - mono_arch_get_patch_offset */
5822 /* Function - Dummy entry point until s390x supports aot. */
5824 /* Returns - Offset for patch. */
5826 /*------------------------------------------------------------------*/
5829 mono_arch_get_patch_offset (guint8 *code)
5834 /*========================= End of Function ========================*/
5836 /*------------------------------------------------------------------*/
5838 /* Name - mono_arch_context_get_int_reg. */
5842 /* Returns - Return a register from the context. */
5844 /*------------------------------------------------------------------*/
5847 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5849 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5852 /*========================= End of Function ========================*/
5854 /*------------------------------------------------------------------*/
5856 /* Name - mono_arch_context_set_int_reg. */
5858 /* Function - Set a value in a specified register. */
5860 /*------------------------------------------------------------------*/
5863 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5865 ctx->uc_mcontext.gregs[reg] = val;
5868 /*========================= End of Function ========================*/
5870 /*------------------------------------------------------------------*/
5872 /* Name - mono_arch_get_this_arg_from_call. */
5876 /*------------------------------------------------------------------*/
5879 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5881 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5883 return (gpointer) lmf->gregs [s390_r2];
5886 /*========================= End of Function ========================*/
5888 /*------------------------------------------------------------------*/
5890 /* Name - get_delegate_invoke_impl. */
5894 /*------------------------------------------------------------------*/
5897 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5899 guint8 *code, *start;
5904 start = code = mono_global_codeman_reserve (size);
5906 /* Replace the this argument with the target */
5907 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5908 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5909 s390_br (code, s390_r1);
5910 g_assert ((code - start) <= size);
5912 mono_arch_flush_icache (start, size);
5916 size = 32 + param_count * 8;
5917 start = code = mono_global_codeman_reserve (size);
5919 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5920 /* slide down the arguments */
5921 for (i = 0; i < param_count; ++i) {
5922 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5924 s390_br (code, s390_r1);
5926 g_assert ((code - start) <= size);
5928 mono_arch_flush_icache (start, size);
5932 *code_len = code - start;
5937 /*========================= End of Function ========================*/
5939 /*------------------------------------------------------------------*/
5941 /* Name - mono_arch_get_delegate_invoke_impls. */
5945 /*------------------------------------------------------------------*/
5948 mono_arch_get_delegate_invoke_impls (void)
5955 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5956 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
5958 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5959 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5960 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
5966 /*========================= End of Function ========================*/
5968 /*------------------------------------------------------------------*/
5970 /* Name - mono_arch_get_delegate_invoke_impl. */
5974 /*------------------------------------------------------------------*/
5977 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5979 guint8 *code, *start;
5981 /* FIXME: Support more cases */
5982 if (MONO_TYPE_ISSTRUCT (sig->ret))
5986 static guint8* cached = NULL;
5992 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5994 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5996 mono_memory_barrier ();
6000 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
6003 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
6005 for (i = 0; i < sig->param_count; ++i)
6006 if (!mono_is_regsize_var (sig->params [i]))
6010 code = cache [sig->param_count];
6014 if (mono_aot_only) {
6015 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
6016 start = mono_aot_get_trampoline (name);
6019 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
6022 mono_memory_barrier ();
6024 cache [sig->param_count] = start;
6029 /*========================= End of Function ========================*/
6031 /*------------------------------------------------------------------*/
6033 /* Name - mono_arch_build_imt_thunk. */
6037 /*------------------------------------------------------------------*/
6040 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
6041 MonoIMTCheckItem **imt_entries, int count,
6042 gpointer fail_tramp)
6046 guchar *code, *start;
6048 for (i = 0; i < count; ++i) {
6049 MonoIMTCheckItem *item = imt_entries [i];
6050 if (item->is_equals) {
6051 if (item->check_target_idx) {
6052 if (!item->compare_done)
6053 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6054 if (item->has_target_code)
6055 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
6057 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
6061 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
6063 if (!item->has_target_code)
6064 item->chunk_size += LOAD_SIZE;
6066 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
6067 #if ENABLE_WRONG_METHOD_CHECK
6068 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6073 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6074 imt_entries [item->check_target_idx]->compare_done = TRUE;
6076 size += item->chunk_size;
6080 code = mono_method_alloc_generic_virtual_thunk (domain, size);
6082 code = mono_domain_code_reserve (domain, size);
6086 for (i = 0; i < count; ++i) {
6087 MonoIMTCheckItem *item = imt_entries [i];
6088 item->code_target = (guint8 *) code;
6089 if (item->is_equals) {
6090 if (item->check_target_idx) {
6091 if (!item->compare_done) {
6092 s390_basr (code, s390_r13, s390_r0);
6094 s390_llong(code, item->key);
6095 s390_lg (code, s390_r0, 0, s390_r13, 4);
6096 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6098 item->jmp_code = (guint8*) code;
6099 s390_jcl (code, S390_CC_NE, 0);
6101 s390_basr (code, s390_r13, s390_r0);
6103 if (item->has_target_code) {
6104 s390_llong(code, item->value.target_code);
6105 s390_lg (code, s390_r1, 0, s390_r13, 4);
6107 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6108 s390_lg (code, s390_r1, 0, s390_r13, 4);
6109 s390_lg (code, s390_r1, 0, s390_r1, 0);
6111 s390_br (code, s390_r1);
6116 s390_basr (code, s390_r13, s390_r0);
6118 s390_llong(code, item->key);
6119 s390_lg (code, s390_r0, 0, s390_r13, 4);
6120 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6121 item->jmp_code = (guint8*) code;
6122 s390_jcl (code, S390_CC_NE, 0);
6123 s390_basr (code, s390_r13, s390_r0);
6125 if (item->has_target_code) {
6126 s390_llong(code, item->value.target_code);
6127 s390_lg (code, s390_r1, 0, s390_r13, 4);
6130 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6131 s390_lg (code, s390_r1, 0, s390_r13, 4);
6132 s390_lg (code, s390_r1, 0, s390_r1, 0);
6134 s390_br (code, s390_r1);
6135 target = S390_RELATIVE(code, item->jmp_code);
6136 s390_patch_rel(item->jmp_code+2, target);
6137 s390_basr (code, s390_r13, s390_r0);
6139 s390_llong(code, fail_tramp);
6140 s390_lg (code, s390_r1, 0, s390_r13, 4);
6141 s390_br (code, s390_r1);
6142 item->jmp_code = NULL;
6144 /* enable the commented code to assert on wrong method */
6145 #if ENABLE_WRONG_METHOD_CHECK
6146 g_assert_not_reached ();
6148 s390_basr (code, s390_r13, s390_r0);
6150 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6151 s390_lg (code, s390_r1, 0, s390_r13, 4);
6152 s390_lg (code, s390_r1, 0, s390_r1, 0);
6153 s390_br (code, s390_r1);
6154 #if ENABLE_WRONG_METHOD_CHECK
6155 g_assert_not_reached ();
6160 s390_basr (code, s390_r13, s390_r0);
6162 s390_llong(code, item->key);
6163 s390_lg (code, s390_r0, 0, s390_r13, 4);
6164 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6165 item->jmp_code = (guint8 *) code;
6166 s390_jcl (code, S390_CC_GE, 0);
6169 /* patch the branches to get to the target items */
6170 for (i = 0; i < count; ++i) {
6171 MonoIMTCheckItem *item = imt_entries [i];
6172 if (item->jmp_code) {
6173 if (item->check_target_idx) {
6175 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6177 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6182 mono_arch_flush_icache ((guint8*)start, (code - start));
6185 mono_stats.imt_thunks_size += (code - start);
6187 g_assert (code - start <= size);
6192 /*========================= End of Function ========================*/
6194 /*------------------------------------------------------------------*/
6196 /* Name - mono_arch_find_imt_method. */
6198 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6199 /* found in the save area. */
6201 /*------------------------------------------------------------------*/
6204 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6206 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
6208 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
6211 /*========================= End of Function ========================*/
6213 /*------------------------------------------------------------------*/
6215 /* Name - mono_arch_find_static_call_vtable */
6217 /* Function - Find the static call vtable. */
6219 /*------------------------------------------------------------------*/
6222 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
6224 mgreg_t *r = (mgreg_t*)regs;
6226 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
6229 /*========================= End of Function ========================*/
6231 /*------------------------------------------------------------------*/
6233 /* Name - mono_arch_get_cie_program */
6235 /* Function - Find the static call vtable. */
6237 /*------------------------------------------------------------------*/
6240 mono_arch_get_cie_program (void)
6244 mono_add_unwind_op_def_cfa (l, NULL, NULL, STK_BASE, 0);
6249 /*========================= End of Function ========================*/
6251 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6253 /*------------------------------------------------------------------*/
6255 /* Name - mono_arch_set_breakpoint. */
6257 /* Function - Set a breakpoint at the native code corresponding */
6258 /* to JI at NATIVE_OFFSET. The location should */
6259 /* contain code emitted by OP_SEQ_POINT. */
6261 /*------------------------------------------------------------------*/
6264 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6268 breakpointCode.pTrigger = bp_trigger_page;
6269 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6270 code += BREAKPOINT_SIZE;
6273 /*========================= End of Function ========================*/
6275 /*------------------------------------------------------------------*/
6277 /* Name - mono_arch_clear_breakpoint. */
6279 /* Function - Clear the breakpoint at IP. */
6281 /*------------------------------------------------------------------*/
6284 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6289 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6293 /*========================= End of Function ========================*/
6295 /*------------------------------------------------------------------*/
6297 /* Name - mono_arch_is_breakpoint_event. */
6301 /*------------------------------------------------------------------*/
6304 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6306 siginfo_t* sinfo = (siginfo_t*) info;
6307 /* Sometimes the address is off by 4 */
6308 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6314 /*========================= End of Function ========================*/
6316 /*------------------------------------------------------------------*/
6318 /* Name - mono_arch_skip_breakpoint. */
6320 /* Function - Modify the CTX so the IP is placed after the */
6321 /* breakpoint instruction, so when we resume, the */
6322 /* instruction is not executed again. */
6324 /*------------------------------------------------------------------*/
6327 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6329 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6332 /*========================= End of Function ========================*/
6334 /*------------------------------------------------------------------*/
6336 /* Name - mono_arch_start_single_stepping. */
6338 /* Function - Start single stepping. */
6340 /*------------------------------------------------------------------*/
6343 mono_arch_start_single_stepping (void)
6345 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6348 /*========================= End of Function ========================*/
6350 /*------------------------------------------------------------------*/
6352 /* Name - mono_arch_stop_single_stepping. */
6354 /* Function - Stop single stepping. */
6356 /*------------------------------------------------------------------*/
6359 mono_arch_stop_single_stepping (void)
6361 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6364 /*========================= End of Function ========================*/
6366 /*------------------------------------------------------------------*/
6368 /* Name - mono_arch_is_single_step_event. */
6370 /* Function - Return whether the machine state in sigctx cor- */
6371 /* responds to a single step event. */
6373 /*------------------------------------------------------------------*/
6376 mono_arch_is_single_step_event (void *info, void *sigctx)
6378 siginfo_t* sinfo = (siginfo_t*) info;
6380 /* Sometimes the address is off by 4 */
6381 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6387 /*========================= End of Function ========================*/
6389 /*------------------------------------------------------------------*/
6391 /* Name - mono_arch_skip_single_step. */
6393 /* Function - Modify the ctx so the IP is placed after the */
6394 /* single step trigger instruction, so that the */
6395 /* instruction is not executed again. */
6397 /*------------------------------------------------------------------*/
6400 mono_arch_skip_single_step (MonoContext *ctx)
6402 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6405 /*========================= End of Function ========================*/
6407 /*------------------------------------------------------------------*/
6409 /* Name - mono_arch_create_seq_point_info. */
6411 /* Function - Return a pointer to a data struction which is */
6412 /* used by the sequence point implementation in */
6415 /*------------------------------------------------------------------*/
6418 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6424 /*========================= End of Function ========================*/