1 /*------------------------------------------------------------------*/
3 /* Name - mini-s390.c */
5 /* Function - S/390 backend for the Mono code generator. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 #define MAX_ARCH_DELEGATE_PARAMS 7
23 #define EMIT_COND_BRANCH(ins,cond) \
25 if (ins->inst_true_bb->native_offset) { \
27 displace = ((cfg->native_code + \
28 ins->inst_true_bb->native_offset) - code) / 2; \
29 if (s390_is_imm16(displace)) { \
30 s390_brc (code, cond, displace); \
32 s390_jcl (code, cond, displace); \
35 mono_add_patch_info (cfg, code - cfg->native_code, \
36 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
37 s390_jcl (code, cond, 0); \
41 #define EMIT_UNCOND_BRANCH(ins) \
43 if (ins->inst_target_bb->native_offset) { \
45 displace = ((cfg->native_code + \
46 ins->inst_target_bb->native_offset) - code) / 2; \
47 if (s390_is_imm16(displace)) { \
48 s390_brc (code, S390_CC_UN, displace); \
50 s390_jcl (code, S390_CC_UN, displace); \
53 mono_add_patch_info (cfg, code - cfg->native_code, \
54 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
55 s390_jcl (code, S390_CC_UN, 0); \
59 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
61 mono_add_patch_info (cfg, code - cfg->native_code, \
62 MONO_PATCH_INFO_EXC, exc_name); \
63 s390_jcl (code, cond, 0); \
66 #define CHECK_SRCDST_COM \
67 if (ins->dreg == ins->sreg2) { \
71 if (ins->dreg != ins->sreg1) { \
72 s390_lgr (code, ins->dreg, ins->sreg1); \
76 #define CHECK_SRCDST_NCOM \
77 if (ins->dreg == ins->sreg2) { \
79 s390_lgr (code, s390_r13, ins->sreg2); \
83 if (ins->dreg != ins->sreg1) { \
84 s390_lgr (code, ins->dreg, ins->sreg1); \
87 #define CHECK_SRCDST_COM_I \
88 if (ins->dreg == ins->sreg2) { \
92 if (ins->dreg != ins->sreg1) { \
93 s390_lgfr (code, ins->dreg, ins->sreg1); \
97 #define CHECK_SRCDST_NCOM_I \
98 if (ins->dreg == ins->sreg2) { \
100 s390_lgfr (code, s390_r13, ins->sreg2); \
104 if (ins->dreg != ins->sreg1) { \
105 s390_lgfr (code, ins->dreg, ins->sreg1); \
108 #define CHECK_SRCDST_COM_F \
109 if (ins->dreg == ins->sreg2) { \
113 if (ins->dreg != ins->sreg1) { \
114 s390_ldr (code, ins->dreg, ins->sreg1); \
118 #define CHECK_SRCDST_NCOM_F \
119 if (ins->dreg == ins->sreg2) { \
121 s390_ldr (code, s390_r13, ins->sreg2); \
125 if (ins->dreg != ins->sreg1) { \
126 s390_ldr (code, ins->dreg, ins->sreg1); \
129 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
132 MONO_INST_NEW (cfg, inst, OP_NOP); \
135 inst->inst_offset = offset; \
137 inst->inst_imm = imm; \
139 if (s390_is_uimm12(offset)) { \
141 inst->inst_offset = offset; \
143 dReg = mono_alloc_preg (cfg); \
144 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
145 dReg, dest, offset); \
147 inst->inst_offset = 0; \
149 if (s390_is_uimm12(imm)) { \
151 inst->inst_imm = imm; \
153 sReg = mono_alloc_preg (cfg); \
154 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
156 inst->sreg1 = sReg; \
157 inst->inst_imm = 0; \
160 inst->opcode = OP_S390_MOVE; \
161 inst->backend.size = size; \
162 MONO_ADD_INS (cfg->cbb, inst); \
165 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
166 int reg = mono_alloc_preg (cfg); \
169 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
172 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
176 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
180 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
184 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
188 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
191 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
195 tmpr = mono_alloc_preg (cfg); \
196 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
197 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
201 tmpr = mono_alloc_preg (cfg); \
202 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
204 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
208 tmpr = mono_alloc_preg (cfg); \
209 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
211 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
215 tmpr = mono_alloc_preg (cfg); \
216 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
218 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
222 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
228 #define DEBUG(a) if (cfg->verbose_level > 1) a
232 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
234 #define BREAKPOINT_SIZE sizeof(breakpoint_t)
235 #define S390X_NOP_SIZE sizeof(I_Format)
237 #define MAX(a, b) ((a) > (b) ? (a) : (b))
240 * imt thunking size values
243 #define LOADCON_SIZE 20
247 #define ENABLE_WRONG_METHOD_CHECK 0
249 /*========================= End of Defines =========================*/
251 /*------------------------------------------------------------------*/
252 /* I n c l u d e s */
253 /*------------------------------------------------------------------*/
258 #include <mono/metadata/appdomain.h>
259 #include <mono/metadata/debug-helpers.h>
260 #include <mono/metadata/profiler-private.h>
261 #include <mono/utils/mono-math.h>
262 #include <mono/utils/mono-mmap.h>
264 #include "mini-s390x.h"
265 #include "cpu-s390x.h"
266 #include "jit-icalls.h"
270 /*========================= End of Includes ========================*/
272 /*------------------------------------------------------------------*/
273 /* T y p e d e f s */
274 /*------------------------------------------------------------------*/
286 /*------------------------------------------------------------------*/
287 /* Used by the instrument_emit_epilog */
288 /*------------------------------------------------------------------*/
299 typedef struct InstList InstList;
313 RegTypeStructByValInFP,
315 RegTypeStructByAddrOnStack
319 gint32 offset; /* offset from caller's stack */
320 gint32 offparm; /* offset from callee's stack */
321 guint16 vtsize; /* in param area */
324 guint32 size; /* Size of structure used by RegTypeStructByVal */
325 gint32 type; /* Data type of argument */
341 gint64 gr[5]; /* R2-R6 */
342 gdouble fp[3]; /* F0-F2 */
343 } __attribute__ ((packed)) RegParm;
351 } __attribute__ ((packed)) breakpoint_t;
353 /*========================= End of Typedefs ========================*/
355 /*------------------------------------------------------------------*/
356 /* P r o t o t y p e s */
357 /*------------------------------------------------------------------*/
359 static void indent (int);
360 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
361 static void decodeParm (MonoType *, void *, int);
362 static void enter_method (MonoMethod *, RegParm *, char *);
363 static void leave_method (MonoMethod *, ...);
364 static gboolean is_regsize_var (MonoType *);
365 static inline void add_general (guint *, size_data *, ArgInfo *);
366 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
367 static inline void add_float (guint *, size_data *, ArgInfo *);
368 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
369 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
370 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
371 static void catch_SIGILL(int, siginfo_t *, void *);
372 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
374 /*========================= End of Prototypes ======================*/
376 /*------------------------------------------------------------------*/
377 /* G l o b a l V a r i a b l e s */
378 /*------------------------------------------------------------------*/
380 int mono_exc_esp_offset = 0;
382 static int indent_level = 0;
386 static gint appdomain_tls_offset = -1,
388 lmf_addr_tls_offset = -1;
390 pthread_key_t lmf_addr_key;
392 gboolean lmf_addr_key_inited = FALSE;
398 extern __thread MonoDomain *tls_appdomain;
399 extern __thread MonoThread *tls_current_object;
400 extern __thread gpointer mono_lmf_addr;
405 * The code generated for sequence points reads from this location,
406 * which is made read-only when single stepping is enabled.
408 static gpointer ss_trigger_page;
411 * Enabled breakpoints read from this trigger page
413 static gpointer bp_trigger_page;
415 breakpoint_t breakpointCode;
417 /*====================== End of Global Variables ===================*/
419 /*------------------------------------------------------------------*/
421 /* Name - mono_arch_regname */
423 /* Function - Returns the name of the register specified by */
424 /* the input parameter. */
426 /*------------------------------------------------------------------*/
429 mono_arch_regname (int reg) {
430 static const char * rnames[] = {
431 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
432 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
433 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
437 if (reg >= 0 && reg < 16)
443 /*========================= End of Function ========================*/
445 /*------------------------------------------------------------------*/
447 /* Name - mono_arch_fregname */
449 /* Function - Returns the name of the register specified by */
450 /* the input parameter. */
452 /*------------------------------------------------------------------*/
455 mono_arch_fregname (int reg) {
456 static const char * rnames[] = {
457 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
458 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
459 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
463 if (reg >= 0 && reg < 16)
469 /*========================= End of Function ========================*/
471 /*------------------------------------------------------------------*/
473 /* Name - arch_get_argument_info */
475 /* Function - Gathers information on parameters such as size, */
476 /* alignment, and padding. arg_info should be large */
477 /* enough to hold param_count + 1 entries. */
479 /* Parameters - @csig - Method signature */
480 /* @param_count - No. of parameters to consider */
481 /* @arg_info - An array to store the result info */
483 /* Returns - Size of the activation frame */
485 /*------------------------------------------------------------------*/
488 mono_arch_get_argument_info (MonoMethodSignature *csig,
490 MonoJitArgumentInfo *arg_info)
492 int k, frame_size = 0;
493 int size, align, pad;
496 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
497 frame_size += sizeof (gpointer);
501 arg_info [0].offset = offset;
504 frame_size += sizeof (gpointer);
508 arg_info [0].size = frame_size;
510 for (k = 0; k < param_count; k++) {
513 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
515 size = mini_type_stack_size (NULL, csig->params [k], &align);
517 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
518 arg_info [k].pad = pad;
520 arg_info [k + 1].pad = 0;
521 arg_info [k + 1].size = size;
523 arg_info [k + 1].offset = offset;
527 align = MONO_ARCH_FRAME_ALIGNMENT;
528 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
529 arg_info [k].pad = pad;
534 /*========================= End of Function ========================*/
536 /*------------------------------------------------------------------*/
538 /* Name - emit_unwind_regs. */
540 /* Function - Determines if a value can be returned in one or */
543 /*------------------------------------------------------------------*/
545 static void __inline__
546 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
550 for (i = start; i < end; i++) {
551 mono_emit_unwind_op_offset (cfg, code, i, offset);
552 offset += sizeof(gulong);
556 /*========================= End of Function ========================*/
558 /*------------------------------------------------------------------*/
560 /* Name - retFitsInReg. */
562 /* Function - Determines if a value can be returned in one or */
565 /*------------------------------------------------------------------*/
567 static inline gboolean
568 retFitsInReg(guint32 size)
583 /*========================= End of Function ========================*/
585 /*------------------------------------------------------------------*/
587 /* Name - backStackPtr. */
589 /* Function - Restore Stack Pointer to previous frame. */
591 /*------------------------------------------------------------------*/
593 static inline guint8 *
594 backUpStackPtr(MonoCompile *cfg, guint8 *code)
596 int stackSize = cfg->stack_usage;
598 if (cfg->frame_reg != STK_BASE)
599 s390_lgr (code, STK_BASE, cfg->frame_reg);
601 if (s390_is_imm16 (stackSize)) {
602 s390_aghi (code, STK_BASE, stackSize);
604 while (stackSize > 32767) {
605 s390_aghi (code, STK_BASE, 32767);
608 s390_aghi (code, STK_BASE, stackSize);
613 /*========================= End of Function ========================*/
615 /*------------------------------------------------------------------*/
619 /* Function - Perform nice indenting to current level */
621 /*------------------------------------------------------------------*/
627 indent_level += diff;
634 indent_level += diff;
637 /*========================= End of Function ========================*/
639 /*------------------------------------------------------------------*/
641 /* Name - cvtMonoType */
643 /* Function - Convert a mono-type to a string. */
645 /*------------------------------------------------------------------*/
648 cvtMonoType(MonoTypeEnum t)
653 return "MONO_TYPE_END";
655 return "MONO_TYPE_VOID";
656 case MONO_TYPE_BOOLEAN:
657 return "MONO_TYPE_BOOLEAN";
659 return "MONO_TYPE_CHAR";
661 return "MONO_TYPE_I1";
663 return "MONO_TYPE_U1";
665 return "MONO_TYPE_I2";
667 return "MONO_TYPE_U2";
669 return "MONO_TYPE_I4";
671 return "MONO_TYPE_U4";
673 return "MONO_TYPE_I8";
675 return "MONO_TYPE_U8";
677 return "MONO_TYPE_R4";
679 return "MONO_TYPE_R8";
680 case MONO_TYPE_STRING:
681 return "MONO_TYPE_STRING";
683 return "MONO_TYPE_PTR";
684 case MONO_TYPE_BYREF:
685 return "MONO_TYPE_BYREF";
686 case MONO_TYPE_VALUETYPE:
687 return "MONO_TYPE_VALUETYPE";
688 case MONO_TYPE_CLASS:
689 return "MONO_TYPE_CLASS";
691 return "MONO_TYPE_VAR";
692 case MONO_TYPE_ARRAY:
693 return "MONO_TYPE_ARRAY";
694 case MONO_TYPE_GENERICINST:
695 return "MONO_TYPE_GENERICINST";
696 case MONO_TYPE_TYPEDBYREF:
697 return "MONO_TYPE_TYPEDBYREF";
699 return "MONO_TYPE_I";
701 return "MONO_TYPE_U";
702 case MONO_TYPE_FNPTR:
703 return "MONO_TYPE_FNPTR";
704 case MONO_TYPE_OBJECT:
705 return "MONO_TYPE_OBJECT";
706 case MONO_TYPE_SZARRAY:
707 return "MONO_TYPE_SZARRAY";
709 return "MONO_TYPE_MVAR";
710 case MONO_TYPE_CMOD_REQD:
711 return "MONO_TYPE_CMOD_REQD";
712 case MONO_TYPE_CMOD_OPT:
713 return "MONO_TYPE_CMOD_OPT";
714 case MONO_TYPE_INTERNAL:
715 return "MONO_TYPE_INTERNAL";
716 case MONO_TYPE_MODIFIER:
717 return "MONO_TYPE_MODIFIER";
718 case MONO_TYPE_SENTINEL:
719 return "MONO_TYPE_SENTINEL";
720 case MONO_TYPE_PINNED:
721 return "MONO_TYPE_PINNED";
728 /*========================= End of Function ========================*/
730 /*------------------------------------------------------------------*/
732 /* Name - decodeParm */
734 /* Function - Decode a parameter for the trace. */
736 /*------------------------------------------------------------------*/
739 decodeParm(MonoType *type, void *curParm, int size)
744 printf("[BYREF:%p], ", *((char **) curParm));
746 simpleType = mono_type_get_underlying_type(type)->type;
748 switch (simpleType) {
750 printf ("[INTPTR:%p], ", *((int **) curParm));
753 printf ("[UINTPTR:%p], ", *((int **) curParm));
755 case MONO_TYPE_BOOLEAN :
756 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
758 case MONO_TYPE_CHAR :
759 printf ("[CHAR:%c], ", *((int *) curParm));
762 printf ("[INT1:%ld], ", *((gint64 *) curParm));
765 printf ("[INT2:%ld], ", *((gint64 *) curParm));
768 printf ("[INT4:%ld], ", *((gint64 *) curParm));
771 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
774 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
777 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
780 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
782 case MONO_TYPE_STRING : {
783 MonoString *s = *((MonoString **) curParm);
785 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
786 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
788 printf("[STRING:null], ");
792 case MONO_TYPE_CLASS :
793 case MONO_TYPE_OBJECT : {
794 MonoObject *obj = *((MonoObject **) curParm);
796 if ((obj) && (obj->vtable)) {
797 printf("[CLASS/OBJ:");
798 class = obj->vtable->klass;
799 printf("%p [%p] ",obj,curParm);
800 if (class == mono_defaults.string_class) {
801 printf("[STRING:%p:%s]",
802 obj, mono_string_to_utf8 ((MonoString *) obj));
803 } else if (class == mono_defaults.int32_class) {
804 printf("[INT32:%p:%d]",
805 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
808 class->name_space, class->name, obj);
811 printf("[OBJECT:null], ");
816 printf("[PTR:%p], ", *((gpointer **) (curParm)));
818 case MONO_TYPE_FNPTR :
819 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
821 case MONO_TYPE_ARRAY :
822 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
824 case MONO_TYPE_SZARRAY :
825 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
828 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
831 printf("[FLOAT4:%g], ", *((float *) (curParm)));
834 printf("[FLOAT8:%g], ", *((double *) (curParm)));
836 case MONO_TYPE_VALUETYPE : {
838 MonoMarshalType *info;
840 if (type->data.klass->enumtype) {
841 simpleType = mono_class_enum_basetype (type->data.klass)->type;
842 printf("{VALUETYPE} - ");
846 info = mono_marshal_load_type_info (type->data.klass);
848 if ((info->native_size == sizeof(float)) &&
849 (info->num_fields == 1) &&
850 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
851 printf("[FLOAT4:%f], ", *((float *) (curParm)));
855 if ((info->native_size == sizeof(double)) &&
856 (info->num_fields == 1) &&
857 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
858 printf("[FLOAT8:%g], ", *((double *) (curParm)));
862 printf("[VALUETYPE:");
863 for (i = 0; i < size; i++)
864 printf("%02x,", *((guint8 *)curParm+i));
868 case MONO_TYPE_TYPEDBYREF: {
870 printf("[TYPEDBYREF:");
871 for (i = 0; i < size; i++)
872 printf("%02x,", *((guint8 *)curParm+i));
877 printf("[%s], ",cvtMonoType(simpleType));
882 /*========================= End of Function ========================*/
884 /*------------------------------------------------------------------*/
886 /* Name - enter_method */
888 /* Function - Perform tracing of the entry to the current */
891 /*------------------------------------------------------------------*/
894 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
896 int i, oParm = 0, iParm = 0;
899 MonoMethodSignature *sig;
906 fname = mono_method_full_name (method, TRUE);
908 printf ("ENTER: %s ", fname);
911 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
912 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
917 sig = mono_method_signature (method);
919 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
921 if (cinfo->struct_ret) {
922 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
927 gpointer *this = (gpointer *) rParm->gr[iParm];
928 obj = (MonoObject *) this;
929 switch(method->klass->this_arg.type) {
930 case MONO_TYPE_VALUETYPE:
932 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
933 printf("this:[value:%p:%016lx], ", this, *value);
935 printf ("this:[NULL], ");
937 case MONO_TYPE_STRING:
940 class = obj->vtable->klass;
941 if (class == mono_defaults.string_class) {
942 printf ("this:[STRING:%p:%s], ",
943 obj, mono_string_to_utf8 ((MonoString *)obj));
945 printf ("this:%p[%s.%s], ",
946 obj, class->name_space, class->name);
949 printf("vtable:[NULL], ");
951 printf ("this:[NULL], ");
954 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
959 for (i = 0; i < sig->param_count; ++i) {
960 ainfo = &cinfo->args[i + oParm];
961 switch (ainfo->regtype) {
962 case RegTypeGeneral :
963 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
966 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
969 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
971 case RegTypeStructByVal :
972 if (ainfo->reg != STK_BASE) {
973 int offset = sizeof(glong) - ainfo->size;
974 curParm = &(rParm->gr[ainfo->reg-2])+offset;
977 curParm = sp+ainfo->offset;
979 if (retFitsInReg (ainfo->vtsize))
980 decodeParm(sig->params[i],
984 decodeParm(sig->params[i],
985 *((char **) curParm),
988 case RegTypeStructByAddr :
989 if (ainfo->reg != STK_BASE)
990 curParm = &(rParm->gr[ainfo->reg-2]);
992 curParm = sp+ainfo->offset;
994 decodeParm(sig->params[i],
995 *((char **) curParm),
1007 /*========================= End of Function ========================*/
1009 /*------------------------------------------------------------------*/
1011 /* Name - leave_method */
1015 /*------------------------------------------------------------------*/
1018 leave_method (MonoMethod *method, ...)
1025 va_start(ap, method);
1027 fname = mono_method_full_name (method, TRUE);
1029 printf ("LEAVE: %s", fname);
1032 type = mono_method_signature (method)->ret;
1035 switch (type->type) {
1036 case MONO_TYPE_VOID:
1038 case MONO_TYPE_BOOLEAN: {
1039 int val = va_arg (ap, int);
1041 printf ("[TRUE:%d]", val);
1047 case MONO_TYPE_CHAR: {
1048 int val = va_arg (ap, int);
1049 printf ("[CHAR:%d]", val);
1052 case MONO_TYPE_I1: {
1053 int val = va_arg (ap, int);
1054 printf ("[INT1:%d]", val);
1057 case MONO_TYPE_U1: {
1058 int val = va_arg (ap, int);
1059 printf ("[UINT1:%d]", val);
1062 case MONO_TYPE_I2: {
1063 int val = va_arg (ap, int);
1064 printf ("[INT2:%d]", val);
1067 case MONO_TYPE_U2: {
1068 int val = va_arg (ap, int);
1069 printf ("[UINT2:%d]", val);
1072 case MONO_TYPE_I4: {
1073 int val = va_arg (ap, int);
1074 printf ("[INT4:%d]", val);
1077 case MONO_TYPE_U4: {
1078 int val = va_arg (ap, int);
1079 printf ("[UINT4:%d]", val);
1083 gint64 val = va_arg (ap, gint64);
1084 printf ("[INT:%ld]", val);
1089 gint64 val = va_arg (ap, gint64);
1090 printf ("[UINT:%lu]", val);
1094 case MONO_TYPE_STRING: {
1095 MonoString *s = va_arg (ap, MonoString *);
1098 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1099 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1101 printf ("[STRING:null], ");
1104 case MONO_TYPE_CLASS:
1105 case MONO_TYPE_OBJECT: {
1106 MonoObject *o = va_arg (ap, MonoObject *);
1108 if ((o) && (o->vtable)) {
1109 if (o->vtable->klass == mono_defaults.boolean_class) {
1110 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1111 } else if (o->vtable->klass == mono_defaults.int32_class) {
1112 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1113 } else if (o->vtable->klass == mono_defaults.int64_class) {
1114 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1116 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1118 printf ("[OBJECT:%p]", o);
1123 case MONO_TYPE_FNPTR:
1124 case MONO_TYPE_ARRAY:
1125 case MONO_TYPE_SZARRAY: {
1126 gpointer p = va_arg (ap, gpointer);
1127 printf ("[result=%p]", p);
1130 case MONO_TYPE_I8: {
1131 gint64 l = va_arg (ap, gint64);
1132 printf ("[LONG:%ld]", l);
1135 case MONO_TYPE_U8: {
1136 guint64 l = va_arg (ap, guint64);
1137 printf ("[ULONG:%lu]", l);
1140 case MONO_TYPE_R4: {
1141 double f = va_arg (ap, double);
1142 printf ("[FLOAT4:%g]\n", f);
1145 case MONO_TYPE_R8: {
1146 double f = va_arg (ap, double);
1147 printf ("[FLOAT8:%g]\n", f);
1150 case MONO_TYPE_VALUETYPE: {
1151 MonoMarshalType *info;
1152 if (type->data.klass->enumtype) {
1153 type = mono_class_enum_basetype (type->data.klass);
1158 info = mono_marshal_load_type_info (type->data.klass);
1160 if ((info->native_size == sizeof(float)) &&
1161 (info->num_fields == 1) &&
1162 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1163 double f = va_arg (ap, double);
1164 printf("[FLOAT4:%g]\n", (double) f);
1168 if ((info->native_size == sizeof(double)) &&
1169 (info->num_fields == 1) &&
1170 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1171 double f = va_arg (ap, double);
1172 printf("[FLOAT8:%g]\n", f);
1176 size = mono_type_size (type, &align);
1179 guint32 p = va_arg (ap, guint32);
1180 printf ("[%02x]\n",p);
1184 guint32 p = va_arg (ap, guint32);
1185 printf ("[%04x]\n",p);
1189 guint32 p = va_arg (ap, guint32);
1190 printf ("[%08x]\n",p);
1194 guint64 p = va_arg (ap, guint64);
1195 printf ("[%016lx]\n",p);
1199 gpointer p = va_arg (ap, gpointer);
1200 printf ("[VALUETYPE] %p\n",p);
1206 case MONO_TYPE_TYPEDBYREF: {
1207 guint8 *p = va_arg (ap, gpointer);
1209 size = mono_type_size (type, &align);
1216 for (j = 0; p && j < size; j++)
1217 printf ("%02x,", p [j]);
1221 printf ("[TYPEDBYREF]\n");
1226 printf ("(unknown return type %x)",
1227 mono_method_signature (method)->ret->type);
1230 ip = ((gint64) __builtin_return_address (0));
1231 printf (" ip: %p\n", (gpointer) ip);
1234 /*========================= End of Function ========================*/
1236 /*------------------------------------------------------------------*/
1238 /* Name - catch_SIGILL */
1240 /* Function - Catch SIGILL as a result of testing for long */
1241 /* displacement facility. */
1243 /*------------------------------------------------------------------*/
1246 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1252 /*========================= End of Function ========================*/
1254 /*------------------------------------------------------------------*/
1256 /* Name - mono_arch_cpu_init */
1258 /* Function - Perform CPU specific initialization to execute */
1261 /*------------------------------------------------------------------*/
1264 mono_arch_cpu_init (void)
1266 struct sigaction sa,
1270 /*--------------------------------------*/
1271 /* Set default rounding mode for FP */
1272 /*--------------------------------------*/
1273 __asm__ ("SRNM\t%0\n\t"
1276 /*--------------------------------------*/
1277 /* Determine if we have long displace- */
1278 /* ment facility on this processor */
1279 /*--------------------------------------*/
1280 sa.sa_sigaction = catch_SIGILL;
1281 sigemptyset (&sa.sa_mask);
1282 sa.sa_flags = SA_SIGINFO;
1284 sigaction (SIGILL, &sa, oldSa);
1286 /*--------------------------------------*/
1287 /* We test by executing the STY inst */
1288 /*--------------------------------------*/
1289 __asm__ ("LGHI\t0,1\n\t"
1291 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1292 : "=m" (has_ld) : : "0", "1");
1294 sigaction (SIGILL, oldSa, NULL);
1297 /*========================= End of Function ========================*/
1299 /*------------------------------------------------------------------*/
1301 /* Name - mono_arch_init. */
1303 /* Function - Initialize architecture specific code. */
1305 /*------------------------------------------------------------------*/
1308 mono_arch_init (void)
1314 * When we do an architectural level set at z9 or better
1315 * we can use the STFLE instruction to show us
1316 * what hardware facilities are available
1318 int lFacility = sizeof(facs) % 8;
1320 memset((char *) &facs, 0, sizeof(facs));
1322 __asm__ (" lgfr 0,%1\n"
1324 : "=m" (facs) : "r" (lFacility) : "0", "cc");
1327 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1328 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1329 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1331 code = (guint8 *) &breakpointCode;
1332 s390_basr(code, s390_r13, 0);
1334 s390_llong(code, 0);
1335 s390_lg(code, s390_r13, 0, s390_r13, 4);
1336 s390_lg(code, s390_r0, 0, s390_r13, 0);
1339 /*========================= End of Function ========================*/
1341 /*------------------------------------------------------------------*/
1343 /* Name - mono_arch_cleanup. */
1345 /* Function - Cleanup architecture specific code . */
1347 /*------------------------------------------------------------------*/
1350 mono_arch_cleanup (void)
1354 /*========================= End of Function ========================*/
1356 /*------------------------------------------------------------------*/
1358 /* Name - mono_arch_cpu_optimizazions */
1360 /* Function - Returns the optimizations supported on this CPU */
1362 /*------------------------------------------------------------------*/
1365 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1369 /*----------------------------------------------------------*/
1370 /* No s390-specific optimizations yet */
1371 /*----------------------------------------------------------*/
1372 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1373 // *exclude_mask = MONO_OPT_INLINE;
1377 /*========================= End of Function ========================*/
1379 /*------------------------------------------------------------------*/
1385 /*------------------------------------------------------------------*/
1388 is_regsize_var (MonoType *t) {
1391 switch (mono_type_get_underlying_type (t)->type) {
1399 case MONO_TYPE_FNPTR:
1401 case MONO_TYPE_OBJECT:
1402 case MONO_TYPE_STRING:
1403 case MONO_TYPE_CLASS:
1404 case MONO_TYPE_SZARRAY:
1405 case MONO_TYPE_ARRAY:
1407 case MONO_TYPE_VALUETYPE:
1408 if (t->data.klass->enumtype)
1409 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1415 /*========================= End of Function ========================*/
1417 /*------------------------------------------------------------------*/
1419 /* Name - mono_arch_get_allocatable_int_vars */
1423 /*------------------------------------------------------------------*/
1426 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1431 for (i = 0; i < cfg->num_varinfo; i++) {
1432 MonoInst *ins = cfg->varinfo [i];
1433 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1436 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1439 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1440 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1443 /* we can only allocate 32 bit values */
1444 if (is_regsize_var (ins->inst_vtype)) {
1445 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1446 g_assert (i == vmv->idx);
1447 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1454 /*========================= End of Function ========================*/
1456 /*------------------------------------------------------------------*/
1458 /* Name - mono_arch_global_int_regs */
1460 /* Function - Return a list of usable integer registers. */
1462 /*------------------------------------------------------------------*/
1465 mono_arch_get_global_int_regs (MonoCompile *cfg)
1468 MonoMethodHeader *header;
1471 header = cfg->header;
1472 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1473 cfg->frame_reg = s390_r11;
1476 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1478 for (i = 8; i < top; ++i) {
1479 if (cfg->frame_reg != i)
1480 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1486 /*========================= End of Function ========================*/
1488 /*------------------------------------------------------------------*/
1490 /* Name - mono_arch_flush_icache */
1492 /* Function - Flush the CPU icache. */
1494 /*------------------------------------------------------------------*/
1497 mono_arch_flush_icache (guint8 *code, gint size)
1501 /*========================= End of Function ========================*/
1503 /*------------------------------------------------------------------*/
1505 /* Name - add_general */
1507 /* Function - Determine code and stack size incremements for a */
1510 /*------------------------------------------------------------------*/
1513 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1515 if (*gr > S390_LAST_ARG_REG) {
1516 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1517 ainfo->offset = sz->stack_size;
1518 ainfo->reg = STK_BASE;
1519 ainfo->regtype = RegTypeBase;
1520 sz->stack_size += sizeof(long);
1521 sz->local_size += sizeof(long);
1522 sz->offStruct += sizeof(long);
1523 sz->code_size += 12;
1531 /*========================= End of Function ========================*/
1533 /*------------------------------------------------------------------*/
1535 /* Name - add_stackParm */
1537 /* Function - Determine code and stack size incremements for a */
1540 /*------------------------------------------------------------------*/
1543 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1545 if (*gr > S390_LAST_ARG_REG) {
1546 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1547 ainfo->reg = STK_BASE;
1548 ainfo->offset = sz->stack_size;
1549 ainfo->regtype = RegTypeStructByAddrOnStack;
1550 sz->stack_size += sizeof (gpointer);
1551 sz->parm_size += sizeof(gpointer);
1552 sz->offStruct += sizeof(gpointer);
1555 ainfo->offset = sz->stack_size;
1556 ainfo->regtype = RegTypeStructByAddr;
1559 ainfo->offparm = sz->offset;
1560 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1562 ainfo->vtsize = size;
1563 sz->parm_size += size;
1566 /*========================= End of Function ========================*/
1568 /*------------------------------------------------------------------*/
1570 /* Name - add_float */
1572 /* Function - Determine code and stack size incremements for a */
1573 /* float parameter. */
1575 /*------------------------------------------------------------------*/
1578 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1580 if ((*fr) <= S390_LAST_FPARG_REG) {
1581 ainfo->regtype = RegTypeFP;
1587 ainfo->offset = sz->stack_size;
1588 ainfo->reg = STK_BASE;
1589 ainfo->regtype = RegTypeBase;
1591 sz->stack_size += sizeof(double);
1592 sz->local_size += sizeof(double);
1593 sz->offStruct += sizeof(double);
1597 /*========================= End of Function ========================*/
1599 /*------------------------------------------------------------------*/
1601 /* Name - get_call_info */
1603 /* Function - Determine the amount of space required for code */
1604 /* and stack. In addition determine starting points */
1605 /* for stack-based parameters, and area for struct- */
1606 /* ures being returned on the stack. */
1608 /*------------------------------------------------------------------*/
1611 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1613 guint i, fr, gr, size, pstart;
1614 int nParm = sig->hasthis + sig->param_count;
1616 guint32 simpletype, align;
1619 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1622 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1624 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1629 cinfo->struct_ret = 0;
1633 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1634 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1641 /*----------------------------------------------------------*/
1642 /* We determine the size of the return code/stack in case we*/
1643 /* need to reserve a register to be used to address a stack */
1644 /* area that the callee will use. */
1645 /*----------------------------------------------------------*/
1647 ret_type = mono_type_get_underlying_type (sig->ret);
1648 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1649 simpletype = ret_type->type;
1651 switch (simpletype) {
1652 case MONO_TYPE_BOOLEAN:
1657 case MONO_TYPE_CHAR:
1662 case MONO_TYPE_CLASS:
1663 case MONO_TYPE_OBJECT:
1664 case MONO_TYPE_SZARRAY:
1665 case MONO_TYPE_ARRAY:
1667 case MONO_TYPE_FNPTR:
1668 case MONO_TYPE_STRING:
1669 cinfo->ret.reg = s390_r2;
1674 cinfo->ret.reg = s390_f0;
1679 cinfo->ret.reg = s390_r2;
1682 case MONO_TYPE_GENERICINST:
1683 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1684 cinfo->ret.reg = s390_r2;
1689 case MONO_TYPE_VALUETYPE: {
1690 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1691 if (klass->enumtype) {
1692 simpletype = mono_class_enum_basetype (klass)->type;
1696 size = mono_class_native_size (klass, &align);
1698 size = mono_class_value_size (klass, &align);
1700 cinfo->struct_ret = 1;
1701 cinfo->ret.size = size;
1702 cinfo->ret.vtsize = size;
1705 case MONO_TYPE_TYPEDBYREF:
1706 size = sizeof (MonoTypedRef);
1707 cinfo->struct_ret = 1;
1708 cinfo->ret.size = size;
1709 cinfo->ret.vtsize = size;
1711 case MONO_TYPE_VOID:
1714 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1720 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1721 * the first argument, allowing 'this' to be always passed in the first arg reg.
1722 * Also do this if the first argument is a reference type, since virtual calls
1723 * are sometimes made using calli without sig->hasthis set, like in the delegate
1726 if (cinfo->struct_ret && !is_pinvoke &&
1728 (sig->param_count > 0 &&
1729 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1731 cinfo->args[nParm].size = sizeof (gpointer);
1732 add_general (&gr, sz, cinfo->args + nParm);
1734 cinfo->args[nParm].size = sizeof (gpointer);
1735 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1739 cinfo->vret_arg_index = 1;
1740 cinfo->ret.reg = gr;
1745 cinfo->args[nParm].size = sizeof (gpointer);
1746 add_general (&gr, sz, cinfo->args + nParm);
1750 if (cinfo->struct_ret) {
1751 cinfo->ret.reg = gr;
1756 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1757 gr = S390_LAST_ARG_REG + 1;
1758 fr = S390_LAST_FPARG_REG + 1;
1760 /* Emit the signature cookie just before the implicit arguments */
1761 add_general (&gr, sz, &cinfo->sigCookie);
1764 /*----------------------------------------------------------*/
1765 /* We determine the size of the parameter code and stack */
1766 /* requirements by checking the types and sizes of the */
1768 /*----------------------------------------------------------*/
1770 for (i = pstart; i < sig->param_count; ++i) {
1773 /*--------------------------------------------------*/
1774 /* Handle vararg type calls. All args are put on */
1776 /*--------------------------------------------------*/
1777 if ((sig->call_convention == MONO_CALL_VARARG) &&
1778 (i == sig->sentinelpos)) {
1779 gr = S390_LAST_ARG_REG + 1;
1780 fr = S390_LAST_FPARG_REG + 1;
1781 add_general (&gr, sz, &cinfo->sigCookie);
1784 if (sig->params [i]->byref) {
1785 add_general (&gr, sz, cinfo->args+nParm);
1786 cinfo->args[nParm].size = sizeof(gpointer);
1791 ptype = mono_type_get_underlying_type (sig->params [i]);
1792 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1793 simpletype = ptype->type;
1794 cinfo->args[nParm].type = simpletype;
1795 switch (simpletype) {
1796 case MONO_TYPE_BOOLEAN:
1799 cinfo->args[nParm].size = sizeof(char);
1800 add_general (&gr, sz, cinfo->args+nParm);
1805 case MONO_TYPE_CHAR:
1806 cinfo->args[nParm].size = sizeof(short);
1807 add_general (&gr, sz, cinfo->args+nParm);
1812 cinfo->args[nParm].size = sizeof(int);
1813 add_general (&gr, sz, cinfo->args+nParm);
1819 case MONO_TYPE_FNPTR:
1820 case MONO_TYPE_CLASS:
1821 case MONO_TYPE_OBJECT:
1822 case MONO_TYPE_STRING:
1823 case MONO_TYPE_SZARRAY:
1824 case MONO_TYPE_ARRAY:
1825 cinfo->args[nParm].size = sizeof(gpointer);
1826 add_general (&gr, sz, cinfo->args+nParm);
1831 cinfo->args[nParm].size = sizeof(long long);
1832 add_general (&gr, sz, cinfo->args+nParm);
1836 cinfo->args[nParm].size = sizeof(float);
1837 add_float (&fr, sz, cinfo->args+nParm);
1841 cinfo->args[nParm].size = sizeof(double);
1842 add_float (&fr, sz, cinfo->args+nParm);
1845 case MONO_TYPE_GENERICINST:
1846 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1847 cinfo->args[nParm].size = sizeof(gpointer);
1848 add_general (&gr, sz, cinfo->args+nParm);
1853 case MONO_TYPE_VALUETYPE: {
1854 MonoMarshalType *info;
1855 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1857 size = mono_class_native_size (klass, &align);
1859 size = mono_class_value_size (klass, &align);
1861 info = mono_marshal_load_type_info (klass);
1863 if ((info->native_size == sizeof(float)) &&
1864 (info->num_fields == 1) &&
1865 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1866 cinfo->args[nParm].size = sizeof(float);
1867 add_float(&fr, sz, cinfo->args+nParm);
1872 if ((info->native_size == sizeof(double)) &&
1873 (info->num_fields == 1) &&
1874 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1875 cinfo->args[nParm].size = sizeof(double);
1876 add_float(&fr, sz, cinfo->args+nParm);
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);
1907 case MONO_TYPE_TYPEDBYREF: {
1908 int size = sizeof (MonoTypedRef);
1910 cinfo->args[nParm].vtsize = 0;
1911 cinfo->args[nParm].size = 0;
1914 /*----------------------------------*/
1915 /* On S/390, structures of size 1, */
1916 /* 2, 4, and 8 bytes are passed in */
1917 /* (a) register(s). */
1918 /*----------------------------------*/
1924 add_general(&gr, sz, cinfo->args+nParm);
1925 cinfo->args[nParm].size = size;
1926 cinfo->args[nParm].regtype = RegTypeStructByVal;
1928 sz->local_size += sizeof(long);
1931 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1937 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1941 /*----------------------------------------------------------*/
1942 /* Handle the case where there are no implicit arguments */
1943 /*----------------------------------------------------------*/
1944 if ((sig->call_convention == MONO_CALL_VARARG) &&
1947 (sig->param_count == sig->sentinelpos)) {
1948 gr = S390_LAST_ARG_REG + 1;
1949 fr = S390_LAST_FPARG_REG + 1;
1950 add_general (&gr, sz, &cinfo->sigCookie);
1953 /*----------------------------------------------------------*/
1954 /* If we are passing a structure back then if it won't be */
1955 /* in a register(s) then we make room at the end of the */
1956 /* parameters that may have been placed on the stack */
1957 /*----------------------------------------------------------*/
1958 if (cinfo->struct_ret) {
1959 cinfo->ret.offset = sz->stack_size;
1960 switch (cinfo->ret.size) {
1968 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1973 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1975 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1980 /*========================= End of Function ========================*/
1982 /*------------------------------------------------------------------*/
1984 /* Name - mono_arch_allocate_vars */
1986 /* Function - Set var information according to the calling */
1987 /* convention for S/390. The local var stuff should */
1988 /* most likely be split in another method. */
1990 /* Parameter - @m - Compile unit. */
1992 /*------------------------------------------------------------------*/
1995 mono_arch_allocate_vars (MonoCompile *cfg)
1997 MonoMethodSignature *sig;
1998 MonoMethodHeader *header;
2001 int iParm, iVar, offset, align, size, curinst;
2002 int frame_reg = STK_BASE;
2005 header = cfg->header;
2007 cfg->flags |= MONO_CFG_HAS_SPILLUP;
2009 /*---------------------------------------------------------*/
2010 /* We use the frame register also for any method that has */
2011 /* filter clauses. This way, when the handlers are called, */
2012 /* the code will reference local variables using the frame */
2013 /* reg instead of the stack pointer: if we had to restore */
2014 /* the stack pointer, we'd corrupt the method frames that */
2015 /* are already on the stack (since filters get called */
2016 /* before stack unwinding happens) when the filter code */
2017 /* would call any method. */
2018 /*---------------------------------------------------------*/
2019 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2020 frame_reg = s390_r11;
2022 cfg->frame_reg = frame_reg;
2024 cfg->arch.bkchain_reg = -1;
2026 if (frame_reg != STK_BASE)
2027 cfg->used_int_regs |= 1 << frame_reg;
2029 sig = mono_method_signature (cfg->method);
2031 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2033 if (!cinfo->struct_ret) {
2034 switch (mono_type_get_underlying_type (sig->ret)->type) {
2035 case MONO_TYPE_VOID:
2038 cfg->ret->opcode = OP_REGVAR;
2039 cfg->ret->dreg = s390_r2;
2044 /*--------------------------------------------------------------*/
2045 /* local vars are at a positive offset from the stack pointer */
2046 /* also note that if the function uses alloca, we use s390_r11 */
2047 /* to point at the local variables. */
2048 /* add parameter area size for called functions */
2049 /*--------------------------------------------------------------*/
2050 if (cfg->param_area == 0)
2051 offset = S390_MINIMAL_STACK_SIZE;
2053 offset = cfg->param_area;
2055 cfg->sig_cookie = 0;
2057 if (cinfo->struct_ret) {
2058 inst = cfg->vret_addr;
2059 offset = S390_ALIGN(offset, sizeof(gpointer));
2060 inst->inst_offset = offset;
2061 inst->opcode = OP_REGOFFSET;
2062 inst->inst_basereg = frame_reg;
2063 offset += sizeof(gpointer);
2064 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2065 printf ("vret_addr =");
2066 mono_print_ins (cfg->vret_addr);
2071 inst = cfg->args [0];
2072 if (inst->opcode != OP_REGVAR) {
2073 inst->opcode = OP_REGOFFSET;
2074 inst->inst_basereg = frame_reg;
2075 offset = S390_ALIGN(offset, sizeof(gpointer));
2076 inst->inst_offset = offset;
2077 offset += sizeof (gpointer);
2084 eArg = sig->param_count + sArg;
2086 if (sig->call_convention == MONO_CALL_VARARG)
2087 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2089 for (iParm = sArg; iParm < eArg; ++iParm) {
2090 inst = cfg->args [curinst];
2091 if (inst->opcode != OP_REGVAR) {
2092 switch (cinfo->args[iParm].regtype) {
2093 case RegTypeStructByAddr : {
2096 size = sizeof (gpointer);
2098 inst->opcode = OP_REGOFFSET;
2099 inst->inst_basereg = frame_reg;
2100 offset = S390_ALIGN (offset, sizeof (gpointer));
2101 inst->inst_offset = offset;
2103 /* Add a level of indirection */
2104 MONO_INST_NEW (cfg, indir, 0);
2106 inst->opcode = OP_VTARG_ADDR;
2107 inst->inst_left = indir;
2110 case RegTypeStructByAddrOnStack : {
2113 size = sizeof (gpointer);
2115 /* Similar to the == STK_BASE case below */
2116 cfg->arch.bkchain_reg = s390_r12;
2117 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2119 inst->opcode = OP_REGOFFSET;
2120 inst->dreg = mono_alloc_preg (cfg);
2121 inst->inst_basereg = cfg->arch.bkchain_reg;
2122 inst->inst_offset = cinfo->args [iParm].offset;
2124 /* Add a level of indirection */
2125 MONO_INST_NEW (cfg, indir, 0);
2127 inst->opcode = OP_VTARG_ADDR;
2128 inst->inst_left = indir;
2131 case RegTypeStructByVal :
2132 size = cinfo->args[iParm].size;
2133 offset = S390_ALIGN(offset, size);
2134 inst->opcode = OP_REGOFFSET;
2135 inst->inst_basereg = frame_reg;
2136 inst->inst_offset = offset;
2139 if (cinfo->args [iParm].reg == STK_BASE) {
2141 * These arguments are in the previous frame, so we can't
2142 * compute their offset from the current frame pointer right
2143 * now, since cfg->stack_offset is not yet known, so dedicate a
2144 * register holding the previous frame pointer.
2146 cfg->arch.bkchain_reg = s390_r12;
2147 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2149 inst->opcode = OP_REGOFFSET;
2150 inst->inst_basereg = cfg->arch.bkchain_reg;
2151 size = (cinfo->args[iParm].size < 8
2152 ? 8 - cinfo->args[iParm].size
2154 inst->inst_offset = cinfo->args [iParm].offset + size;
2155 size = sizeof (long);
2157 inst->opcode = OP_REGOFFSET;
2158 inst->inst_basereg = frame_reg;
2159 size = (cinfo->args[iParm].size < 8
2162 offset = S390_ALIGN(offset, size);
2163 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2164 inst->inst_offset = offset;
2166 inst->inst_offset = offset + (8 - size);
2171 if ((sig->call_convention == MONO_CALL_VARARG) &&
2172 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2173 (iParm < sig->sentinelpos))
2174 cfg->sig_cookie += size;
2175 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2178 offset += MAX(size, 8);
2183 curinst = cfg->locals_start;
2184 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2185 inst = cfg->varinfo [iVar];
2186 if ((inst->flags & MONO_INST_IS_DEAD) ||
2187 (inst->opcode == OP_REGVAR))
2190 /*--------------------------------------------------*/
2191 /* inst->backend.is_pinvoke indicates native sized */
2192 /* value typs this is used by the pinvoke wrappers */
2193 /* when they call functions returning structure */
2194 /*--------------------------------------------------*/
2195 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2196 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2197 (guint32 *) &align);
2199 size = mono_type_size (inst->inst_vtype, &align);
2201 offset = S390_ALIGN(offset, align);
2202 inst->inst_offset = offset;
2203 inst->opcode = OP_REGOFFSET;
2204 inst->inst_basereg = frame_reg;
2206 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2207 iVar, inst->inst_offset, size));
2210 /*------------------------------------------------------*/
2211 /* Allow space for the trace method stack area if needed*/
2212 /*------------------------------------------------------*/
2213 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2214 offset += S390_TRACE_STACK_SIZE;
2216 /*------------------------------------------------------*/
2217 /* Reserve space to save LMF and caller saved registers */
2218 /*------------------------------------------------------*/
2219 if (cfg->method->save_lmf)
2220 offset += sizeof (MonoLMF);
2222 /*------------------------------------------------------*/
2223 /* align the offset */
2224 /*------------------------------------------------------*/
2225 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2227 /*------------------------------------------------------*/
2228 /* Fix offsets for args whose value is in parent frame */
2229 /*------------------------------------------------------*/
2230 for (iParm = sArg; iParm < eArg; ++iParm) {
2231 inst = cfg->args [iParm];
2233 if (inst->opcode == OP_S390_STKARG) {
2234 inst->opcode = OP_REGOFFSET;
2235 inst->inst_offset += cfg->stack_offset;
2240 /*========================= End of Function ========================*/
2242 /*------------------------------------------------------------------*/
2244 /* Name - mono_arch_create_vars */
2246 /*------------------------------------------------------------------*/
2249 mono_arch_create_vars (MonoCompile *cfg)
2251 MonoMethodSignature *sig;
2254 sig = mono_method_signature (cfg->method);
2256 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2258 if (cinfo->struct_ret) {
2259 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2260 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2261 printf ("vret_addr = ");
2262 mono_print_ins (cfg->vret_addr);
2267 /*========================= End of Function ========================*/
2269 /*------------------------------------------------------------------*/
2271 /* Name - add_outarg_reg2. */
2273 /*------------------------------------------------------------------*/
2276 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2281 case RegTypeGeneral:
2282 MONO_INST_NEW (cfg, ins, OP_MOVE);
2283 ins->dreg = mono_alloc_ireg (cfg);
2284 ins->sreg1 = tree->dreg;
2285 MONO_ADD_INS (cfg->cbb, ins);
2286 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2289 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2290 ins->dreg = mono_alloc_freg (cfg);
2291 ins->sreg1 = tree->dreg;
2292 MONO_ADD_INS (cfg->cbb, ins);
2293 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2296 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2297 ins->dreg = mono_alloc_freg (cfg);
2298 ins->sreg1 = tree->dreg;
2299 MONO_ADD_INS (cfg->cbb, ins);
2300 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2303 g_assert_not_reached ();
2307 /*========================= End of Function ========================*/
2309 /*------------------------------------------------------------------*/
2311 /* Name - emit_sig_cookie. */
2313 /*------------------------------------------------------------------*/
2316 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2318 MonoMethodSignature *tmpSig;
2321 cfg->disable_aot = TRUE;
2323 /*----------------------------------------------------------*/
2324 /* mono_ArgIterator_Setup assumes the signature cookie is */
2325 /* passed first and all the arguments which were before it */
2326 /* passed on the stack after the signature. So compensate */
2327 /* by passing a different signature. */
2328 /*----------------------------------------------------------*/
2329 tmpSig = mono_metadata_signature_dup (call->signature);
2330 tmpSig->param_count -= call->signature->sentinelpos;
2331 tmpSig->sentinelpos = 0;
2332 if (tmpSig->param_count > 0)
2333 memcpy (tmpSig->params,
2334 call->signature->params + call->signature->sentinelpos,
2335 tmpSig->param_count * sizeof(MonoType *));
2337 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2338 sig_arg->dreg = mono_alloc_ireg (cfg);
2339 sig_arg->inst_p0 = tmpSig;
2340 MONO_ADD_INS (cfg->cbb, sig_arg);
2342 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2343 cinfo->sigCookie.offset, sig_arg->dreg);
2346 /*========================= End of Function ========================*/
2348 /*------------------------------------------------------------------*/
2350 /* Name - mono_arch_emit_call */
2352 /*------------------------------------------------------------------*/
2355 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2358 MonoMethodSignature *sig;
2360 int i, n, lParamArea;
2362 ArgInfo *ainfo = NULL;
2364 MonoMethodHeader *header;
2367 sig = call->signature;
2368 n = sig->param_count + sig->hasthis;
2369 DEBUG (g_print ("Call requires: %d parameters\n",n));
2371 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2373 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2374 cinfo->sz.parm_size + cinfo->sz.offset;
2375 call->stack_usage = MAX(stackSize, call->stack_usage);
2376 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2377 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2378 cfg->flags |= MONO_CFG_HAS_CALLS;
2380 if (cinfo->struct_ret) {
2381 MONO_INST_NEW (cfg, ins, OP_MOVE);
2382 ins->sreg1 = call->vret_var->dreg;
2383 ins->dreg = mono_alloc_preg (cfg);
2384 MONO_ADD_INS (cfg->cbb, ins);
2385 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2388 header = cfg->header;
2389 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2394 for (i = 0; i < n; ++i) {
2397 ainfo = cinfo->args + i;
2398 if (i >= sig->hasthis)
2399 t = sig->params [i - sig->hasthis];
2401 t = &mono_defaults.int_class->byval_arg;
2402 t = mono_type_get_underlying_type (t);
2404 in = call->args [i];
2406 if ((sig->call_convention == MONO_CALL_VARARG) &&
2408 (i == sig->sentinelpos)) {
2409 emit_sig_cookie (cfg, call, cinfo);
2412 switch (ainfo->regtype) {
2413 case RegTypeGeneral:
2414 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2417 if (MONO_TYPE_ISSTRUCT (t)) {
2418 /* Valuetype passed in one fp register */
2419 ainfo->regtype = RegTypeStructByValInFP;
2422 if (ainfo->size == 4)
2423 ainfo->regtype = RegTypeFPR4;
2424 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2427 case RegTypeStructByVal:
2428 case RegTypeStructByAddr:
2429 case RegTypeStructByAddrOnStack: {
2433 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2434 size = sizeof (MonoTypedRef);
2435 align = sizeof (gpointer);
2439 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2442 * Other backends use mono_type_stack_size (), but that
2443 * aligns the size to 8, which is larger than the size of
2444 * the source, leading to reads of invalid memory if the
2445 * source is at the end of address space.
2447 size = mono_class_value_size (in->klass, &align);
2450 g_assert (in->klass);
2452 ainfo->offparm += cinfo->sz.offStruct;
2454 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2455 ins->sreg1 = in->dreg;
2456 ins->klass = in->klass;
2457 ins->backend.size = ainfo->size;
2458 ins->inst_p0 = call;
2459 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2460 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2462 MONO_ADD_INS (cfg->cbb, ins);
2464 if (ainfo->regtype == RegTypeStructByAddr) {
2466 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2467 * use the normal OUTARG opcodes to pass the address of the location to
2470 int treg = mono_alloc_preg (cfg);
2471 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2472 frmReg, ainfo->offparm);
2473 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2474 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2475 /* The address of the valuetype is passed on the stack */
2476 int treg = mono_alloc_preg (cfg);
2477 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2478 frmReg, ainfo->offparm);
2479 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2480 ainfo->reg, ainfo->offset, treg);
2485 if (!t->byref && t->type == MONO_TYPE_R4) {
2486 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2487 STK_BASE, ainfo->offset + 4,
2489 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2490 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2491 STK_BASE, ainfo->offset,
2494 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2495 ins->inst_destbasereg = STK_BASE;
2496 ins->inst_offset = ainfo->offset;
2497 ins->sreg1 = in->dreg;
2500 /* This is needed by MonoTypedRef->value to point to the correct data */
2501 if ((sig->call_convention == MONO_CALL_VARARG) &&
2502 (i >= sig->sentinelpos)) {
2503 switch (ainfo->size) {
2505 ins->opcode = OP_STOREI1_MEMBASE_REG;
2508 ins->opcode = OP_STOREI2_MEMBASE_REG;
2511 ins->opcode = OP_STOREI4_MEMBASE_REG;
2519 MONO_ADD_INS (cfg->cbb, ins);
2523 g_assert_not_reached ();
2529 * Handle the case where there are no implicit arguments
2531 if ((sig->call_convention == MONO_CALL_VARARG) &&
2533 (i == sig->sentinelpos)) {
2534 emit_sig_cookie (cfg, call, cinfo);
2538 /*========================= End of Function ========================*/
2540 /*------------------------------------------------------------------*/
2542 /* Name - mono_arch_emit_outarg_vt */
2544 /*------------------------------------------------------------------*/
2547 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2549 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2550 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2551 int size = ins->backend.size;
2553 if (ainfo->regtype == RegTypeStructByVal) {
2555 arg->ins.sreg1 = ainfo->reg;
2556 arg->ins.opcode = OP_OUTARG_VT;
2557 arg->size = ainfo->size;
2558 arg->offset = ainfo->offset;
2559 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2561 if (ainfo->reg != STK_BASE) {
2562 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2564 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2567 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2568 int dreg = mono_alloc_freg (cfg);
2570 if (ainfo->size == 4) {
2571 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2572 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2574 g_assert (ainfo->size == 8);
2576 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2579 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2581 MonoMethodHeader *header;
2584 header = mono_method_get_header (cfg->method);
2585 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2590 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2591 src->dreg, 0, size);
2595 /*========================= End of Function ========================*/
2597 /*------------------------------------------------------------------*/
2599 /* Name - mono_arch_emit_setret */
2601 /*------------------------------------------------------------------*/
2604 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2606 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2609 if (ret->type == MONO_TYPE_R4) {
2610 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2612 } else if (ret->type == MONO_TYPE_R8) {
2613 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2618 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2621 /*========================= End of Function ========================*/
2623 /*------------------------------------------------------------------*/
2625 /* Name - mono_arch_instrument_mem_needs */
2627 /* Function - Allow tracing to work with this interface (with */
2628 /* an optional argument). */
2630 /*------------------------------------------------------------------*/
2633 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2635 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2637 /* split prolog-epilog requirements? */
2638 *code = 50; /* max bytes needed: check this number */
2641 /*========================= End of Function ========================*/
2643 /*------------------------------------------------------------------*/
2645 /* Name - mono_arch_instrument_prolog */
2647 /* Function - Create an "instrumented" prolog. */
2649 /*------------------------------------------------------------------*/
2652 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2653 gboolean enable_arguments)
2660 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2661 if (cfg->method->save_lmf)
2662 parmOffset -= sizeof(MonoLMF);
2663 fpOffset = parmOffset + (5*sizeof(gpointer));
2664 if ((!has_ld) && (fpOffset > 4096)) {
2665 s390_lgr (code, s390_r12, STK_BASE);
2667 while (fpOffset > 4096) {
2668 s390_aghi (code, baseReg, 4096);
2676 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2678 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2679 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2680 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2681 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2683 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2684 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2685 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2686 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2688 s390_basr (code, s390_r13, 0);
2690 s390_llong(code, cfg->method);
2691 s390_llong(code, func);
2692 s390_lg (code, s390_r2, 0, s390_r13, 4);
2694 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2696 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2697 s390_lgr (code, s390_r4, STK_BASE);
2698 s390_aghi (code, s390_r4, cfg->stack_usage);
2699 s390_lg (code, s390_r1, 0, s390_r13, 12);
2700 s390_basr (code, s390_r14, s390_r1);
2702 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2703 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2704 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2705 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2707 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2708 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2709 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2710 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2712 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2717 /*========================= End of Function ========================*/
2719 /*------------------------------------------------------------------*/
2721 /* Name - mono_arch_instrument_epilog */
2723 /* Function - Create an epilog that will handle the returned */
2724 /* values used in instrumentation. */
2726 /*------------------------------------------------------------------*/
2729 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2732 int save_mode = SAVE_NONE,
2734 MonoMethod *method = cfg->method;
2735 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2737 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2738 if (method->save_lmf)
2739 saveOffset -= sizeof(MonoLMF);
2743 case MONO_TYPE_VOID:
2744 /* special case string .ctor icall */
2745 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2746 save_mode = SAVE_ONE;
2748 save_mode = SAVE_NONE;
2752 save_mode = SAVE_ONE;
2755 save_mode = SAVE_R4;
2758 save_mode = SAVE_R8;
2760 case MONO_TYPE_VALUETYPE:
2761 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2762 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2765 save_mode = SAVE_STRUCT;
2768 save_mode = SAVE_ONE;
2772 switch (save_mode) {
2774 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2775 if (enable_arguments) {
2776 s390_lgr (code, s390_r3, s390_r2);
2780 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2781 if (enable_arguments) {
2782 s390_ldebr (code, s390_f0, s390_f0);
2786 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2789 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2790 if (enable_arguments) {
2791 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2792 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2800 s390_basr (code, s390_r13, 0);
2802 s390_llong(code, cfg->method);
2803 s390_llong(code, func);
2804 s390_lg (code, s390_r2, 0, s390_r13, 4);
2805 s390_lg (code, s390_r1, 0, s390_r13, 12);
2806 s390_basr (code, s390_r14, s390_r1);
2808 switch (save_mode) {
2810 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2814 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2817 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2827 /*========================= End of Function ========================*/
2829 /*------------------------------------------------------------------*/
2831 /* Name - mono_arch_peephole_pass_1 */
2833 /* Function - Form a peephole pass at the code looking for */
2834 /* simple optimizations. */
2836 /*------------------------------------------------------------------*/
2839 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2843 /*========================= End of Function ========================*/
2845 /*------------------------------------------------------------------*/
2847 /* Name - mono_arch_peephole_pass_2 */
2849 /* Function - Form a peephole pass at the code looking for */
2850 /* simple optimizations. */
2852 /*------------------------------------------------------------------*/
2855 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2859 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2860 mono_peephole_ins (bb, ins);
2864 /*========================= End of Function ========================*/
2866 /*------------------------------------------------------------------*/
2868 /* Name - mono_arch_lowering_pass. */
2870 /*------------------------------------------------------------------*/
2873 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2875 MonoInst *ins, *next;
2877 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2878 switch (ins->opcode) {
2883 case OP_IDIV_UN_IMM:
2884 case OP_IREM_UN_IMM:
2888 case OP_LOCALLOC_IMM:
2889 mono_decompose_op_imm (cfg, bb, ins);
2892 if (!s390_is_imm16 (ins->inst_imm))
2893 /* This is created by the memcpy code which ignores is_inst_imm */
2894 mono_decompose_op_imm (cfg, bb, ins);
2901 bb->max_vreg = cfg->next_vreg;
2904 /*========================= End of Function ========================*/
2906 /*------------------------------------------------------------------*/
2908 /* Name - emit_float_to_int */
2910 /* Function - Create instructions which will convert a floating */
2911 /* point value to integer. */
2913 /*------------------------------------------------------------------*/
2916 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2918 /* sreg is a float, dreg is an integer reg. */
2920 s390_cgdbr (code, dreg, 5, sreg);
2923 s390_lghi (code, s390_r0, 0);
2924 s390_lghi (code, s390_r13, 0xff);
2925 s390_ltgr (code, dreg, dreg);
2927 s390_lghi (code, s390_r0, 0x80);
2928 s390_ngr (code, dreg, s390_r13);
2929 s390_ogr (code, dreg, s390_r0);
2934 s390_basr (code, s390_r13, 0);
2936 s390_llong (code, 0x41e0000000000000llu);
2937 s390_llong (code, 0x41f0000000000000llu);
2938 s390_ldr (code, s390_f15, sreg);
2939 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2940 s390_jl (code, 0); CODEPTR (code, o[0]);
2941 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2942 s390_cfdbr (code, dreg, 7, s390_f15);
2944 PTRSLOT (code, o[0]);
2945 s390_cfdbr (code, dreg, 5, sreg);
2948 s390_lghi (code, s390_r0, 0xff);
2949 s390_ngr (code, dreg, s390_r0);
2952 s390_lghi (code, s390_r0, -1);
2953 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2954 s390_ngr (code, dreg, s390_r0);
2961 /*========================= End of Function ========================*/
2963 /*------------------------------------------------------------------*/
2965 /* Name - gboolean_is_unsigned. */
2967 /* Function - Return TRUE if next opcode is checking for un- */
2970 /*------------------------------------------------------------------*/
2973 gboolean is_unsigned (MonoInst *next)
2976 (((next->opcode >= OP_IBNE_UN) &&
2977 (next->opcode <= OP_IBLT_UN)) ||
2978 ((next->opcode >= OP_LBNE_UN) &&
2979 (next->opcode <= OP_LBLT_UN)) ||
2980 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2981 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2982 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2983 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2984 ((next->opcode == OP_CLT_UN) ||
2985 (next->opcode == OP_CGT_UN)) ||
2986 ((next->opcode == OP_ICLT_UN) ||
2987 (next->opcode == OP_ICGT_UN) ||
2988 (next->opcode == OP_LCLT_UN) ||
2989 (next->opcode == OP_LCGT_UN))))
2995 /*========================= End of Function ========================*/
2997 /*------------------------------------------------------------------*/
2999 /* Name - mono_arch_output_basic_block */
3001 /* Function - Perform the "real" work of emitting instructions */
3002 /* that will do the work of in the basic block. */
3004 /*------------------------------------------------------------------*/
3007 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
3012 guint8 *code = cfg->native_code + cfg->code_len;
3013 guint last_offset = 0;
3014 int max_len, cpos, src2;
3016 /* we don't align basic blocks of loops on s390 */
3018 if (cfg->verbose_level > 2)
3019 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
3021 cpos = bb->max_offset;
3023 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
3024 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
3025 //g_assert (!mono_compile_aot);
3028 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
3029 /* this is not thread save, but good enough */
3030 /* fixme: howto handle overflows? */
3031 //x86_inc_mem (code, &cov->data [bb->dfn].count);
3034 MONO_BB_FOR_EACH_INS (bb, ins) {
3035 offset = code - cfg->native_code;
3037 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
3039 if (offset > (cfg->code_size - max_len - 16)) {
3040 cfg->code_size *= 2;
3041 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
3042 code = cfg->native_code + offset;
3045 mono_debug_record_line_number (cfg, ins, offset);
3047 switch (ins->opcode) {
3048 case OP_STOREI1_MEMBASE_IMM: {
3049 s390_lghi (code, s390_r0, ins->inst_imm);
3050 S390_LONG (code, stcy, stc, s390_r0, 0,
3051 ins->inst_destbasereg, ins->inst_offset);
3054 case OP_STOREI2_MEMBASE_IMM: {
3055 s390_lghi (code, s390_r0, ins->inst_imm);
3056 S390_LONG (code, sthy, sth, s390_r0, 0,
3057 ins->inst_destbasereg, ins->inst_offset);
3060 case OP_STOREI4_MEMBASE_IMM: {
3061 if (s390_is_imm16(ins->inst_imm)) {
3062 s390_lghi (code, s390_r0, ins->inst_imm);
3064 s390_basr (code, s390_r13, 0);
3066 s390_llong(code, ins->inst_imm);
3067 s390_lg (code, s390_r0, 0, s390_r13, 4);
3069 S390_LONG (code, sty, st, s390_r0, 0,
3070 ins->inst_destbasereg, ins->inst_offset);
3073 case OP_STORE_MEMBASE_IMM:
3074 case OP_STOREI8_MEMBASE_IMM: {
3075 if (s390_is_imm16(ins->inst_imm)) {
3076 s390_lghi (code, s390_r0, ins->inst_imm);
3078 s390_basr (code, s390_r13, 0);
3080 s390_llong(code, ins->inst_imm);
3081 s390_lg (code, s390_r0, 0, s390_r13, 4);
3083 S390_LONG (code, stg, stg, s390_r0, 0,
3084 ins->inst_destbasereg, ins->inst_offset);
3087 case OP_STOREI1_MEMBASE_REG: {
3088 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3089 ins->inst_destbasereg, ins->inst_offset);
3092 case OP_STOREI2_MEMBASE_REG: {
3093 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3094 ins->inst_destbasereg, ins->inst_offset);
3097 case OP_STOREI4_MEMBASE_REG: {
3098 S390_LONG (code, sty, st, ins->sreg1, 0,
3099 ins->inst_destbasereg, ins->inst_offset);
3102 case OP_STORE_MEMBASE_REG:
3103 case OP_STOREI8_MEMBASE_REG: {
3104 S390_LONG (code, stg, stg, ins->sreg1, 0,
3105 ins->inst_destbasereg, ins->inst_offset);
3109 g_assert_not_reached ();
3111 case OP_LOAD_MEMBASE:
3112 case OP_LOADI8_MEMBASE: {
3113 S390_LONG (code, lg, lg, ins->dreg, 0,
3114 ins->inst_basereg, ins->inst_offset);
3117 case OP_LOADI4_MEMBASE: {
3118 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3119 ins->inst_basereg, ins->inst_offset);
3122 case OP_LOADU4_MEMBASE: {
3123 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3124 ins->inst_basereg, ins->inst_offset);
3127 case OP_LOADU1_MEMBASE: {
3128 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3129 ins->inst_basereg, ins->inst_offset);
3132 case OP_LOADI1_MEMBASE: {
3133 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3134 ins->inst_basereg, ins->inst_offset);
3137 case OP_LOADU2_MEMBASE: {
3138 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3139 ins->inst_basereg, ins->inst_offset);
3142 case OP_LOADI2_MEMBASE: {
3143 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3144 ins->inst_basereg, ins->inst_offset);
3147 case OP_LCONV_TO_I1: {
3149 s390_lgbr (code, ins->dreg, ins->sreg1);
3151 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
3152 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
3156 case OP_LCONV_TO_I2: {
3158 s390_lghr (code, ins->dreg, ins->sreg1);
3160 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
3161 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
3165 case OP_LCONV_TO_U1: {
3167 s390_llghr (code, ins->dreg, ins->sreg1);
3169 if (ins->dreg != ins->sreg1)
3170 s390_lgr (code, ins->dreg, ins->sreg1);
3171 s390_lghi (code, s390_r0, 0xff);
3172 s390_ngr (code, ins->dreg, s390_r0);
3176 case OP_LCONV_TO_U2: {
3178 s390_llghr (code, ins->dreg, ins->sreg1);
3180 if (ins->dreg != ins->sreg1)
3181 s390_lgr (code, ins->dreg, ins->sreg1);
3182 s390_lghi (code, s390_r0, -1);
3183 s390_srlg (code, s390_r0, s390_r0, 0, 48);
3184 s390_ngr (code, ins->dreg, s390_r0);
3188 case OP_ICONV_TO_I1: {
3190 s390_lbr (code, ins->dreg, ins->sreg1);
3192 if (ins->dreg != ins->sreg1)
3193 s390_lr (code, ins->dreg, ins->sreg1);
3194 s390_sll (code, ins->dreg, 0, 24);
3195 s390_sra (code, ins->dreg, 0, 24);
3200 case OP_ICONV_TO_I2: {
3202 s390_lhr (code, ins->dreg, ins->sreg1);
3204 if (ins->dreg != ins->sreg1)
3205 s390_lr (code, ins->dreg, ins->sreg1);
3206 s390_sll (code, ins->dreg, 0, 16);
3207 s390_sra (code, ins->dreg, 0, 16);
3211 case OP_ICONV_TO_U1: {
3213 s390_llcr (code, ins->dreg, ins->sreg1);
3215 if (ins->dreg != ins->sreg1)
3216 s390_lr (code, ins->dreg, ins->sreg1);
3217 s390_lhi (code, s390_r0, 0xff);
3218 s390_nr (code, ins->dreg, s390_r0);
3222 case OP_ICONV_TO_U2: {
3224 s390_llhr (code, ins->dreg, ins->sreg1);
3226 if (ins->dreg != ins->sreg1)
3227 s390_lr (code, ins->dreg, ins->sreg1);
3228 s390_lhi (code, s390_r0, -1);
3229 s390_srl (code, s390_r0, 0, 16);
3230 s390_nr (code, ins->dreg, s390_r0);
3236 if (is_unsigned (ins->next))
3237 s390_clgr (code, ins->sreg1, ins->sreg2);
3239 s390_cgr (code, ins->sreg1, ins->sreg2);
3243 if (is_unsigned (ins->next))
3244 s390_clr (code, ins->sreg1, ins->sreg2);
3246 s390_cr (code, ins->sreg1, ins->sreg2);
3249 case OP_COMPARE_IMM:
3250 case OP_LCOMPARE_IMM: {
3251 if (s390_is_imm16 (ins->inst_imm)) {
3252 s390_lghi (code, s390_r0, ins->inst_imm);
3253 if (is_unsigned (ins->next))
3254 s390_clgr (code, ins->sreg1, s390_r0);
3256 s390_cgr (code, ins->sreg1, s390_r0);
3258 s390_basr (code, s390_r13, 0);
3260 s390_llong(code, ins->inst_imm);
3261 if (is_unsigned (ins->next))
3262 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3264 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3268 case OP_ICOMPARE_IMM: {
3269 if (s390_is_imm16 (ins->inst_imm)) {
3270 s390_lghi (code, s390_r0, ins->inst_imm);
3271 if (is_unsigned (ins->next))
3272 s390_clr (code, ins->sreg1, s390_r0);
3274 s390_cr (code, ins->sreg1, s390_r0);
3277 s390_basr (code, s390_r13, 0);
3279 s390_word (code, ins->inst_imm);
3280 if (is_unsigned (ins->next))
3281 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3283 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3288 s390_basr (code, s390_r13, 0);
3290 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3292 s390_llong (code, mono_break);
3293 s390_lg (code, s390_r14, 0, s390_r13, 4);
3294 s390_basr (code, s390_r14, s390_r14);
3299 s390_agr (code, ins->dreg, src2);
3304 s390_agr (code, ins->dreg, src2);
3309 s390_alcgr (code, ins->dreg, src2);
3313 if (ins->dreg != ins->sreg1) {
3314 s390_lgr (code, ins->dreg, ins->sreg1);
3316 if (s390_is_imm16 (ins->inst_imm)) {
3317 s390_aghi (code, ins->dreg, ins->inst_imm);
3319 s390_basr (code, s390_r13, 0);
3321 s390_llong(code, ins->inst_imm);
3322 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3327 if (ins->dreg != ins->sreg1) {
3328 s390_lgr (code, ins->dreg, ins->sreg1);
3330 g_assert (s390_is_imm16 (ins->inst_imm));
3331 s390_aghi (code, ins->dreg, ins->inst_imm);
3335 if (ins->dreg != ins->sreg1) {
3336 s390_lgr (code, ins->dreg, ins->sreg1);
3338 if (s390_is_imm16 (ins->inst_imm)) {
3339 s390_lghi (code, s390_r0, ins->inst_imm);
3340 s390_alcgr (code, ins->dreg, s390_r0);
3342 s390_basr (code, s390_r13, 0);
3344 s390_llong (code, ins->inst_imm);
3345 s390_lg (code, s390_r13, 0, s390_r13, 4);
3346 s390_alcgr (code, ins->dreg, s390_r13);
3351 case OP_S390_IADD_OVF: {
3353 s390_ar (code, ins->dreg, src2);
3354 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3355 s390_lgfr (code, ins->dreg, ins->dreg);
3358 case OP_IADD_OVF_UN:
3359 case OP_S390_IADD_OVF_UN: {
3361 s390_algr (code, ins->dreg, src2);
3362 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3363 s390_llgfr (code, ins->dreg, ins->dreg);
3366 case OP_ADD_OVF_CARRY: {
3368 s390_lghi (code, s390_r0, 0);
3369 s390_lgr (code, s390_r1, s390_r0);
3370 s390_alcgr (code, s390_r0, s390_r1);
3371 s390_agr (code, ins->dreg, src2);
3372 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3373 s390_agr (code, ins->dreg, s390_r0);
3374 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3377 case OP_ADD_OVF_UN_CARRY: {
3379 s390_alcgr (code, ins->dreg, src2);
3380 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3385 s390_sgr (code, ins->dreg, src2);
3390 s390_sgr (code, ins->dreg, src2);
3395 s390_slbgr(code, ins->dreg, src2);
3399 if (ins->dreg != ins->sreg1) {
3400 s390_lgr (code, ins->dreg, ins->sreg1);
3402 if (s390_is_imm16 (-ins->inst_imm)) {
3403 s390_lghi (code, s390_r0, ins->inst_imm);
3404 s390_slgr (code, ins->dreg, s390_r0);
3406 s390_basr (code, s390_r13, 0);
3408 s390_llong(code, ins->inst_imm);
3409 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3414 if (ins->dreg != ins->sreg1) {
3415 s390_lgr (code, ins->dreg, ins->sreg1);
3417 if (s390_is_imm16 (-ins->inst_imm)) {
3418 s390_lghi (code, s390_r0, ins->inst_imm);
3419 s390_slgr (code, ins->dreg, s390_r0);
3421 s390_basr (code, s390_r13, 0);
3423 s390_llong(code, ins->inst_imm);
3424 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3429 if (ins->dreg != ins->sreg1) {
3430 s390_lgr (code, ins->dreg, ins->sreg1);
3432 if (s390_is_imm16 (-ins->inst_imm)) {
3433 s390_lghi (code, s390_r0, ins->inst_imm);
3434 s390_slbgr (code, ins->dreg, s390_r0);
3436 s390_basr (code, s390_r13, 0);
3438 s390_llong(code, ins->inst_imm);
3439 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3443 case OP_SUB_OVF_CARRY: {
3445 s390_lghi (code, s390_r0, 0);
3446 s390_lgr (code, s390_r1, s390_r0);
3447 s390_slbgr (code, s390_r0, s390_r1);
3448 s390_sgr (code, ins->dreg, src2);
3449 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3450 s390_agr (code, ins->dreg, s390_r0);
3451 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3454 case OP_SUB_OVF_UN_CARRY: {
3456 s390_slbgr (code, ins->dreg, src2);
3457 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3461 if (ins->sreg1 == ins->dreg) {
3462 s390_ngr (code, ins->dreg, ins->sreg2);
3465 if (ins->sreg2 == ins->dreg) {
3466 s390_ngr (code, ins->dreg, ins->sreg1);
3469 s390_lgr (code, ins->dreg, ins->sreg1);
3470 s390_ngr (code, ins->dreg, ins->sreg2);
3476 if (ins->dreg != ins->sreg1) {
3477 s390_lgr (code, ins->dreg, ins->sreg1);
3479 if (s390_is_imm16 (ins->inst_imm)) {
3480 s390_lghi (code, s390_r0, ins->inst_imm);
3481 s390_ngr (code, ins->dreg, s390_r0);
3483 s390_basr (code, s390_r13, 0);
3485 s390_llong(code, ins->inst_imm);
3486 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3491 s390_lgr (code, s390_r1, ins->sreg1);
3492 s390_dsgr (code, s390_r0, ins->sreg2);
3493 s390_lgr (code, ins->dreg, s390_r1);
3497 s390_lgr (code, s390_r1, ins->sreg1);
3498 s390_lghi (code, s390_r0, 0);
3499 s390_dlgr (code, s390_r0, ins->sreg2);
3500 s390_lgr (code, ins->dreg, s390_r1);
3504 s390_lgr (code, s390_r1, ins->sreg1);
3505 s390_dsgr (code, s390_r0, ins->sreg2);
3506 s390_lgr (code, ins->dreg, s390_r0);
3510 s390_lgr (code, s390_r1, ins->sreg1);
3511 s390_lghi (code, s390_r0, 0);
3512 s390_dlgr (code, s390_r0, ins->sreg2);
3513 s390_lgr (code, ins->dreg, s390_r0);
3517 if (ins->sreg1 == ins->dreg) {
3518 s390_ogr (code, ins->dreg, ins->sreg2);
3521 if (ins->sreg2 == ins->dreg) {
3522 s390_ogr (code, ins->dreg, ins->sreg1);
3525 s390_lgr (code, ins->dreg, ins->sreg1);
3526 s390_ogr (code, ins->dreg, ins->sreg2);
3532 if (ins->dreg != ins->sreg1) {
3533 s390_lgr (code, ins->dreg, ins->sreg1);
3535 if (s390_is_imm16 (ins->inst_imm)) {
3536 s390_lghi (code, s390_r0, ins->inst_imm);
3537 s390_ogr (code, ins->dreg, s390_r0);
3539 s390_basr (code, s390_r13, 0);
3541 s390_llong(code, ins->inst_imm);
3542 s390_og (code, ins->dreg, 0, s390_r13, 4);
3547 if (ins->sreg1 == ins->dreg) {
3548 s390_xgr (code, ins->dreg, ins->sreg2);
3551 if (ins->sreg2 == ins->dreg) {
3552 s390_xgr (code, ins->dreg, ins->sreg1);
3555 s390_lgr (code, ins->dreg, ins->sreg1);
3556 s390_xgr (code, ins->dreg, ins->sreg2);
3562 if (ins->dreg != ins->sreg1) {
3563 s390_lgr (code, ins->dreg, ins->sreg1);
3565 if (s390_is_imm16 (ins->inst_imm)) {
3566 s390_lghi (code, s390_r0, ins->inst_imm);
3567 s390_xgr (code, ins->dreg, s390_r0);
3569 s390_basr (code, s390_r13, 0);
3571 s390_llong(code, ins->inst_imm);
3572 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3578 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3583 if (ins->sreg1 != ins->dreg) {
3584 s390_lgr (code, ins->dreg, ins->sreg1);
3586 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3591 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3596 if (ins->sreg1 != ins->dreg) {
3597 s390_lgr (code, ins->dreg, ins->sreg1);
3599 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3603 case OP_LSHR_UN_IMM: {
3604 if (ins->sreg1 != ins->dreg) {
3605 s390_lgr (code, ins->dreg, ins->sreg1);
3607 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3612 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3616 if (ins->sreg1 != ins->dreg) {
3617 s390_lgr (code, ins->dreg, ins->sreg1);
3619 s390_lghi (code, s390_r0, -1);
3620 s390_xgr (code, ins->dreg, s390_r0);
3624 s390_lcgr (code, ins->dreg, ins->sreg1);
3629 s390_msgr (code, ins->dreg, src2);
3634 if (ins->dreg != ins->sreg1) {
3635 s390_lgr (code, ins->dreg, ins->sreg1);
3637 if (s390_is_imm16 (ins->inst_imm)) {
3638 s390_lghi (code, s390_r13, ins->inst_imm);
3640 s390_basr (code, s390_r13, 0);
3642 s390_llong(code, ins->inst_imm);
3643 s390_lg (code, s390_r13, 0, s390_r13, 4);
3645 s390_msgr (code, ins->dreg, s390_r13);
3650 s390_ltgr (code, s390_r1, ins->sreg1);
3651 s390_jz (code, 0); CODEPTR(code, o[0]);
3652 s390_ltgr (code, s390_r0, ins->sreg2);
3654 s390_lghi (code, s390_r1, 0);
3655 s390_j (code, 0); CODEPTR(code, o[1]);
3656 s390_xgr (code, s390_r0, s390_r1);
3657 s390_msgr (code, s390_r1, ins->sreg2);
3658 s390_xgr (code, s390_r0, s390_r1);
3659 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3660 s390_ltgr (code, s390_r0, s390_r0);
3661 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3662 PTRSLOT (code, o[0]);
3663 PTRSLOT (code, o[1]);
3664 s390_lgr (code, ins->dreg, s390_r1);
3667 case OP_LMUL_OVF_UN: {
3668 s390_lghi (code, s390_r0, 0);
3669 s390_lgr (code, s390_r1, ins->sreg1);
3670 s390_mlgr (code, s390_r0, ins->sreg2);
3671 s390_ltgr (code, s390_r0, s390_r0);
3672 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3673 s390_lgr (code, ins->dreg, s390_r1);
3677 g_assert_not_reached ();
3679 s390_algr (code, ins->dreg, src2);
3684 s390_agr (code, ins->dreg, src2);
3688 g_assert_not_reached ();
3690 s390_alcgr (code, ins->dreg, src2);
3694 if (ins->dreg != ins->sreg1) {
3695 s390_lgfr (code, ins->dreg, ins->sreg1);
3697 if (s390_is_imm16 (ins->inst_imm)) {
3698 s390_aghi(code, ins->dreg, ins->inst_imm);
3700 s390_basr (code, s390_r13, 0);
3702 s390_word (code, ins->inst_imm);
3703 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3708 if (ins->dreg != ins->sreg1) {
3709 s390_lgfr (code, ins->dreg, ins->sreg1);
3711 if (s390_is_imm16 (ins->inst_imm)) {
3712 s390_lghi (code, s390_r0, ins->inst_imm);
3713 s390_alcgr (code, ins->dreg, s390_r0);
3715 s390_basr (code, s390_r13, 0);
3717 s390_word (code, ins->inst_imm);
3718 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3719 s390_alcgr (code, ins->dreg, s390_r13);
3724 case OP_S390_LADD_OVF: {
3726 s390_agr (code, ins->dreg, src2);
3727 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3730 case OP_LADD_OVF_UN:
3731 case OP_S390_LADD_OVF_UN: {
3733 s390_algr (code, ins->dreg, src2);
3734 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3738 CHECK_SRCDST_NCOM_I;
3739 s390_slgr (code, ins->dreg, src2);
3743 CHECK_SRCDST_NCOM_I;
3744 s390_sgr (code, ins->dreg, src2);
3748 CHECK_SRCDST_NCOM_I;
3749 s390_slbgr (code, ins->dreg, src2);
3753 if (ins->dreg != ins->sreg1) {
3754 s390_lgfr (code, ins->dreg, ins->sreg1);
3756 if (s390_is_imm16 (-ins->inst_imm)) {
3757 s390_aghi (code, ins->dreg, -ins->inst_imm);
3759 s390_basr (code, s390_r13, 0);
3761 s390_word (code, ins->inst_imm);
3762 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3767 s390_basr (code, s390_r13, 0);
3769 s390_word (code, ins->inst_imm);
3770 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3774 case OP_S390_ISUB_OVF: {
3776 s390_sr (code, ins->dreg, src2);
3777 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3778 s390_lgfr (code, ins->dreg, ins->dreg);
3781 case OP_ISUB_OVF_UN:
3782 case OP_S390_ISUB_OVF_UN: {
3784 s390_slr (code, ins->dreg, src2);
3785 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3786 s390_llgfr(code, ins->dreg, ins->dreg);
3790 case OP_S390_LSUB_OVF: {
3792 s390_sgr (code, ins->dreg, src2);
3793 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3796 case OP_LSUB_OVF_UN:
3797 case OP_S390_LSUB_OVF_UN: {
3799 s390_slgr (code, ins->dreg, src2);
3800 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3804 CHECK_SRCDST_NCOM_I;
3805 s390_ngr (code, ins->dreg, src2);
3809 if (ins->dreg != ins->sreg1) {
3810 s390_lgfr (code, ins->dreg, ins->sreg1);
3812 if (s390_is_imm16 (ins->inst_imm)) {
3813 s390_lghi (code, s390_r0, ins->inst_imm);
3814 s390_ngr (code, ins->dreg, s390_r0);
3816 s390_basr (code, s390_r13, 0);
3818 s390_llong(code, ins->inst_imm);
3819 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3824 s390_lgfr (code, s390_r0, ins->sreg1);
3825 s390_srda (code, s390_r0, 0, 32);
3826 s390_dr (code, s390_r0, ins->sreg2);
3827 s390_lgfr (code, ins->dreg, s390_r1);
3831 s390_lgfr (code, s390_r0, ins->sreg1);
3832 s390_srdl (code, s390_r0, 0, 32);
3833 s390_dlr (code, s390_r0, ins->sreg2);
3834 s390_lgfr (code, ins->dreg, s390_r1);
3838 if (s390_is_imm16 (ins->inst_imm)) {
3839 s390_lghi (code, s390_r13, ins->inst_imm);
3840 s390_lgfr (code, s390_r0, ins->sreg1);
3842 s390_basr (code, s390_r13, 0);
3844 s390_word (code, ins->inst_imm);
3845 s390_lgfr (code, s390_r0, ins->sreg1);
3846 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3848 s390_srda (code, s390_r0, 0, 32);
3849 s390_dr (code, s390_r0, ins->sreg2);
3850 s390_lgfr (code, ins->dreg, s390_r1);
3854 s390_lgfr (code, s390_r0, ins->sreg1);
3855 s390_srda (code, s390_r0, 0, 32);
3856 s390_dr (code, s390_r0, ins->sreg2);
3857 s390_lgfr (code, ins->dreg, s390_r0);
3860 s390_lgfr (code, s390_r0, ins->sreg1);
3861 s390_srdl (code, s390_r0, 0, 32);
3862 s390_dlr (code, s390_r0, ins->sreg2);
3863 s390_lgfr (code, ins->dreg, s390_r0);
3867 if (s390_is_imm16 (ins->inst_imm)) {
3868 s390_lghi (code, s390_r13, ins->inst_imm);
3869 s390_lgfr (code, s390_r0, ins->sreg1);
3871 s390_basr (code, s390_r13, 0);
3873 s390_word (code, ins->inst_imm);
3874 s390_lgfr (code, s390_r0, ins->sreg1);
3875 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3877 s390_srda (code, s390_r0, 0, 32);
3878 s390_dr (code, s390_r0, ins->sreg2);
3879 s390_lgfr (code, ins->dreg, s390_r0);
3884 s390_ogr (code, ins->dreg, src2);
3888 if (ins->dreg != ins->sreg1) {
3889 s390_lgfr (code, ins->dreg, ins->sreg1);
3891 if (s390_is_imm16 (ins->inst_imm)) {
3892 s390_lghi (code, s390_r0, ins->inst_imm);
3893 s390_ogr (code, ins->dreg, s390_r0);
3895 s390_basr (code, s390_r13, 0);
3897 s390_llong(code, ins->inst_imm);
3898 s390_og (code, ins->dreg, 0, s390_r13, 4);
3904 s390_xgr (code, ins->dreg, src2);
3908 if (ins->dreg != ins->sreg1) {
3909 s390_lgfr (code, ins->dreg, ins->sreg1);
3911 if (s390_is_imm16 (ins->inst_imm)) {
3912 s390_lghi (code, s390_r0, ins->inst_imm);
3913 s390_xgr (code, ins->dreg, s390_r0);
3915 s390_basr (code, s390_r13, 0);
3917 s390_llong(code, ins->inst_imm);
3918 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3924 s390_sll (code, ins->dreg, src2, 0);
3928 if (ins->sreg1 != ins->dreg) {
3929 s390_lgfr (code, ins->dreg, ins->sreg1);
3931 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3936 s390_sra (code, ins->dreg, src2, 0);
3940 if (ins->sreg1 != ins->dreg) {
3941 s390_lgfr (code, ins->dreg, ins->sreg1);
3943 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3946 case OP_ISHR_UN_IMM: {
3947 if (ins->sreg1 != ins->dreg) {
3948 s390_lgfr (code, ins->dreg, ins->sreg1);
3950 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3955 s390_srl (code, ins->dreg, src2, 0);
3959 if (ins->sreg1 != ins->dreg) {
3960 s390_lgfr (code, ins->dreg, ins->sreg1);
3962 s390_lghi (code, s390_r0, -1);
3963 s390_xgr (code, ins->dreg, s390_r0);
3967 s390_lcgr (code, ins->dreg, ins->sreg1);
3972 s390_msr (code, ins->dreg, src2);
3976 if (ins->dreg != ins->sreg1) {
3977 s390_lgfr (code, ins->dreg, ins->sreg1);
3979 if (s390_is_imm16 (ins->inst_imm)) {
3980 s390_lghi (code, s390_r13, ins->inst_imm);
3982 s390_basr (code, s390_r13, 0);
3984 s390_word (code, ins->inst_imm);
3985 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3987 s390_msr (code, ins->dreg, s390_r13);
3992 s390_ltr (code, s390_r1, ins->sreg1);
3993 s390_jz (code, 0); CODEPTR(code, o[0]);
3994 s390_ltr (code, s390_r0, ins->sreg2);
3996 s390_lhi (code, s390_r1, 0);
3997 s390_j (code, 0); CODEPTR(code, o[1]);
3998 s390_xr (code, s390_r0, s390_r1);
3999 s390_msr (code, s390_r1, ins->sreg2);
4000 s390_xr (code, s390_r0, s390_r1);
4001 s390_srl (code, s390_r0, 0, 31);
4002 s390_ltr (code, s390_r0, s390_r0);
4003 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4004 PTRSLOT (code, o[0]);
4005 PTRSLOT (code, o[1]);
4006 s390_lgfr (code, ins->dreg, s390_r1);
4009 case OP_IMUL_OVF_UN: {
4010 s390_lhi (code, s390_r0, 0);
4011 s390_lr (code, s390_r1, ins->sreg1);
4012 s390_mlr (code, s390_r0, ins->sreg2);
4013 s390_ltr (code, s390_r0, s390_r0);
4014 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4015 s390_lgfr (code, ins->dreg, s390_r1);
4020 if (s390_is_imm16(ins->inst_c0)) {
4021 s390_lghi (code, ins->dreg, ins->inst_c0);
4023 s390_basr (code, s390_r13, 0);
4025 s390_llong(code, ins->inst_c0);
4026 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4031 s390_basr (code, s390_r13, 0);
4033 mono_add_patch_info (cfg, code - cfg->native_code,
4034 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4035 s390_llong(code, 0);
4036 s390_lg (code,ins->dreg, 0, s390_r13, 4);
4039 case OP_JUMP_TABLE: {
4040 mono_add_patch_info (cfg, code - cfg->native_code,
4041 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4042 s390_basr (code, s390_r13, 0);
4044 s390_llong (code, 0);
4045 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4049 if (ins->dreg != ins->sreg1) {
4050 s390_lgr (code, ins->dreg, ins->sreg1);
4054 case OP_LCONV_TO_I8:
4056 s390_lgfr (code, ins->dreg, ins->sreg1);
4058 case OP_LCONV_TO_I4:
4059 s390_lgfr (code, ins->dreg, ins->sreg1);
4062 case OP_LCONV_TO_U8:
4063 case OP_LCONV_TO_U4:
4065 s390_llgfr (code, ins->dreg, ins->sreg1);
4067 case OP_LCONV_TO_OVF_U4:
4068 s390_basr (code, s390_r13, 0);
4070 s390_llong(code, 4294967295);
4071 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
4072 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4073 s390_ltgr (code, ins->sreg1, ins->sreg1);
4074 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4075 s390_llgfr(code, ins->dreg, ins->sreg1);
4077 case OP_LCONV_TO_OVF_I4_UN:
4078 s390_basr (code, s390_r13, 0);
4080 s390_llong(code, 2147483647);
4081 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
4082 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4083 s390_ltgr (code, ins->sreg1, ins->sreg1);
4084 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4085 s390_lgfr (code, ins->dreg, ins->sreg1);
4088 case OP_FCONV_TO_R4: {
4089 if (ins->dreg != ins->sreg1) {
4090 s390_ldr (code, ins->dreg, ins->sreg1);
4094 case OP_S390_SETF4RET: {
4095 s390_ledbr (code, ins->dreg, ins->sreg1);
4099 if (s390_is_imm16 (ins->inst_offset)) {
4100 s390_lghi (code, s390_r13, ins->inst_offset);
4102 s390_bras (code, s390_r13, 0);
4104 s390_llong(code, ins->inst_offset);
4105 s390_lg (code, s390_r13, 0, s390_r13, 4);
4107 s390_ear (code, s390_r1, 0);
4108 s390_sllg(code, s390_r1, s390_r1, 0, 32);
4109 s390_ear (code, s390_r1, 1);
4110 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
4114 if (cfg->method->save_lmf)
4115 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4117 if (cfg->flags & MONO_CFG_HAS_TAIL) {
4118 code = emit_load_volatile_arguments (code, cfg);
4121 code = backUpStackPtr(cfg, code);
4122 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
4123 mono_add_patch_info (cfg, code - cfg->native_code,
4124 MONO_PATCH_INFO_METHOD_JUMP,
4126 s390_jcl (code, S390_CC_UN, 0);
4129 case OP_CHECK_THIS: {
4130 /* ensure ins->sreg1 is not NULL */
4131 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
4132 s390_ltgr (code, s390_r0, s390_r0);
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 (*((float *) 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: {
4875 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4876 g_assert_not_reached ();
4879 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4880 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4881 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4882 g_assert_not_reached ();
4887 last_offset = offset;
4890 cfg->code_len = code - cfg->native_code;
4893 /*========================= End of Function ========================*/
4895 /*------------------------------------------------------------------*/
4897 /* Name - mono_arch_register_lowlevel_calls */
4899 /* Function - Register routines to help with --trace operation. */
4901 /*------------------------------------------------------------------*/
4904 mono_arch_register_lowlevel_calls (void)
4908 /*========================= End of Function ========================*/
4910 /*------------------------------------------------------------------*/
4912 /* Name - mono_arch_patch_code */
4914 /* Function - Process the patch data created during the */
4915 /* instruction build process. This resolves jumps, */
4916 /* calls, variables etc. */
4918 /*------------------------------------------------------------------*/
4921 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4922 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4924 MonoJumpInfo *patch_info;
4926 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4927 unsigned char *ip = patch_info->ip.i + code;
4928 gconstpointer target = NULL;
4930 target = mono_resolve_patch_target (method, domain, code,
4931 patch_info, run_cctors);
4933 switch (patch_info->type) {
4934 case MONO_PATCH_INFO_IP:
4935 case MONO_PATCH_INFO_EXC_NAME:
4936 case MONO_PATCH_INFO_LDSTR:
4937 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4938 case MONO_PATCH_INFO_LDTOKEN:
4939 case MONO_PATCH_INFO_EXC:
4940 case MONO_PATCH_INFO_ABS:
4941 case MONO_PATCH_INFO_METHOD:
4942 case MONO_PATCH_INFO_INTERNAL_METHOD:
4943 case MONO_PATCH_INFO_CLASS_INIT:
4944 s390_patch_addr (ip, (guint64) target);
4946 case MONO_PATCH_INFO_SWITCH:
4947 /*----------------------------------*/
4948 /* ip points at the basr r13,0/j +4 */
4949 /* instruction the vtable value */
4950 /* follows this (i.e. ip+6) */
4951 /*----------------------------------*/
4952 *((gconstpointer *)(ip+6)) = target;
4954 case MONO_PATCH_INFO_METHODCONST:
4955 case MONO_PATCH_INFO_CLASS:
4956 case MONO_PATCH_INFO_IMAGE:
4957 case MONO_PATCH_INFO_FIELD:
4958 case MONO_PATCH_INFO_IID:
4959 target = S390_RELATIVE(target, ip);
4960 s390_patch_rel (ip, (guint64) target);
4962 case MONO_PATCH_INFO_R4:
4963 case MONO_PATCH_INFO_R8:
4964 case MONO_PATCH_INFO_METHOD_REL:
4965 g_assert_not_reached ();
4968 target = S390_RELATIVE(target, ip);
4970 s390_patch_rel (ip, (guint64) target);
4975 /*========================= End of Function ========================*/
4977 /*------------------------------------------------------------------*/
4979 /* Name - emit_load_volatile_arguments */
4981 /* Function - Emit the instructions to reload parameter regist- */
4982 /* registers for use with "tail" operations. */
4984 /* The register loading operations performed here */
4985 /* are the mirror of the store operations performed */
4986 /* in mono_arch_emit_prolog and need to be kept in */
4987 /* synchronization with it. */
4989 /*------------------------------------------------------------------*/
4992 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4995 MonoMethod *method = cfg->method;
4996 MonoMethodSignature *sig = mono_method_signature(method);
5000 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
5002 if (cinfo->struct_ret) {
5003 ArgInfo *ainfo = &cinfo->ret;
5004 inst = cfg->vret_addr;
5005 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5008 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5009 ArgInfo *ainfo = cinfo->args + i;
5010 inst = cfg->args [pos];
5012 if (inst->opcode == OP_REGVAR) {
5013 if (ainfo->regtype == RegTypeGeneral)
5014 s390_lgr (code, ainfo->reg, inst->dreg);
5015 else if (ainfo->regtype == RegTypeFP) {
5016 if (inst->dreg != ainfo->reg) {
5017 if (ainfo->size == 4) {
5018 s390_ldebr (code, ainfo->reg, inst->dreg);
5020 s390_ldr (code, ainfo->reg, inst->dreg);
5024 else if (ainfo->regtype == RegTypeBase) {
5026 g_assert_not_reached ();
5028 if (ainfo->regtype == RegTypeGeneral) {
5029 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5030 g_assert_not_reached();
5031 switch (ainfo->size) {
5033 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5036 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5039 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5042 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5045 } else if (ainfo->regtype == RegTypeBase) {
5046 } else if (ainfo->regtype == RegTypeFP) {
5047 if (ainfo->size == 8)
5048 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5049 else if (ainfo->size == 4)
5050 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5052 g_assert_not_reached ();
5053 } else if (ainfo->regtype == RegTypeStructByVal) {
5054 if (ainfo->reg != STK_BASE) {
5055 switch (ainfo->size) {
5057 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5060 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5063 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5066 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5070 } else if (ainfo->regtype == RegTypeStructByAddr) {
5071 if (ainfo->reg != STK_BASE) {
5072 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5075 g_assert_not_reached ();
5083 /*========================= End of Function ========================*/
5085 /*------------------------------------------------------------------*/
5087 /* Name - mono_arch_emit_prolog */
5089 /* Function - Create the instruction sequence for a function */
5092 /*------------------------------------------------------------------*/
5095 mono_arch_emit_prolog (MonoCompile *cfg)
5097 MonoMethod *method = cfg->method;
5099 MonoMethodSignature *sig;
5101 long alloc_size, pos, max_offset, i, cfa_offset = 0;
5108 cfg->code_size = 512;
5110 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5112 cfg->code_size += 256;
5115 if (method->save_lmf)
5116 cfg->code_size += 200;
5118 cfg->native_code = code = g_malloc (cfg->code_size);
5120 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
5121 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
5122 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5123 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
5125 if (cfg->arch.bkchain_reg != -1)
5126 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
5128 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5129 cfg->used_int_regs |= 1 << 11;
5132 alloc_size = cfg->stack_offset;
5134 cfg->stack_usage = cfa_offset = alloc_size;
5135 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
5136 s390_lgr (code, s390_r11, STK_BASE);
5137 if (s390_is_imm16 (alloc_size)) {
5138 s390_aghi (code, STK_BASE, -alloc_size);
5140 int stackSize = alloc_size;
5141 while (stackSize > 32767) {
5142 s390_aghi (code, STK_BASE, -32767);
5145 s390_aghi (code, STK_BASE, -stackSize);
5147 s390_stg (code, s390_r11, 0, STK_BASE, 0);
5149 if (cfg->frame_reg != STK_BASE)
5150 s390_lgr (code, s390_r11, STK_BASE);
5152 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
5154 /* compute max_offset in order to use short forward jumps
5155 * we always do it on s390 because the immediate displacement
5156 * for jumps is too small
5159 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5161 bb->max_offset = max_offset;
5163 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5166 MONO_BB_FOR_EACH_INS (bb, ins)
5167 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5170 /* load arguments allocated to register from the stack */
5171 sig = mono_method_signature (method);
5174 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
5176 if (cinfo->struct_ret) {
5177 ArgInfo *ainfo = &cinfo->ret;
5178 inst = cfg->vret_addr;
5179 inst->backend.size = ainfo->vtsize;
5180 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5183 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5184 ArgInfo *ainfo = cinfo->args + i;
5185 inst = cfg->args [pos];
5187 if (inst->opcode == OP_VTARG_ADDR)
5188 inst = inst->inst_left;
5190 if (inst->opcode == OP_REGVAR) {
5191 if (ainfo->regtype == RegTypeGeneral)
5192 s390_lgr (code, inst->dreg, ainfo->reg);
5193 else if (ainfo->regtype == RegTypeFP) {
5194 if (inst->dreg != ainfo->reg) {
5195 if (ainfo->size == 4) {
5196 s390_ledbr (code, inst->dreg, ainfo->reg);
5198 s390_ldr (code, inst->dreg, ainfo->reg);
5202 else if (ainfo->regtype == RegTypeBase) {
5203 s390_lgr (code, s390_r13, STK_BASE);
5204 s390_aghi (code, s390_r13, alloc_size);
5205 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5207 g_assert_not_reached ();
5209 if (cfg->verbose_level > 2)
5210 g_print ("Argument %d assigned to register %s\n",
5211 pos, mono_arch_regname (inst->dreg));
5213 if (ainfo->regtype == RegTypeGeneral) {
5214 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5215 g_assert_not_reached();
5216 switch (ainfo->size) {
5218 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5221 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5224 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5227 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5230 } else if (ainfo->regtype == RegTypeBase) {
5231 } else if (ainfo->regtype == RegTypeFP) {
5232 if (ainfo->size == 8)
5233 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5234 else if (ainfo->size == 4)
5235 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5237 g_assert_not_reached ();
5238 } else if (ainfo->regtype == RegTypeStructByVal) {
5239 int doffset = inst->inst_offset;
5241 if (ainfo->reg != STK_BASE)
5245 s390_lgr (code, s390_r13, STK_BASE);
5246 s390_aghi (code, s390_r13, alloc_size);
5249 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5250 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5255 if (ainfo->reg == STK_BASE)
5256 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5257 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5260 if (ainfo->reg == STK_BASE)
5261 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5262 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5265 if (ainfo->reg == STK_BASE)
5266 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5267 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5270 if (ainfo->reg == STK_BASE)
5271 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5272 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5275 } else if (ainfo->regtype == RegTypeStructByAddr) {
5276 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5277 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5279 g_assert_not_reached ();
5284 if (method->save_lmf) {
5285 /*---------------------------------------------------------------*/
5286 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5287 /*---------------------------------------------------------------*/
5288 lmfOffset = alloc_size - sizeof(MonoLMF);
5290 s390_lgr (code, s390_r13, cfg->frame_reg);
5291 s390_aghi (code, s390_r13, lmfOffset);
5293 /*---------------------------------------------------------------*/
5294 /* Preserve the parameter registers while we fix up the lmf */
5295 /*---------------------------------------------------------------*/
5296 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5297 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5299 /*---------------------------------------------------------------*/
5300 /* On return from this call r2 have the address of the &lmf */
5301 /*---------------------------------------------------------------*/
5302 if (lmf_addr_tls_offset == -1) {
5303 s390_basr(code, s390_r14, 0);
5305 mono_add_patch_info (cfg, code - cfg->native_code,
5306 MONO_PATCH_INFO_INTERNAL_METHOD,
5307 (gpointer)"mono_get_lmf_addr");
5308 s390_llong(code, 0);
5309 s390_lg (code, s390_r1, 0, s390_r14, 4);
5310 s390_basr (code, s390_r14, s390_r1);
5312 /*-------------------------------------------------------*/
5313 /* Get LMF by getting value from thread level storage */
5314 /*-------------------------------------------------------*/
5315 s390_ear (code, s390_r1, 0);
5316 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5317 s390_ear (code, s390_r1, 1);
5318 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5321 /*---------------------------------------------------------------*/
5322 /* Set lmf.lmf_addr = jit_tls->lmf */
5323 /*---------------------------------------------------------------*/
5324 s390_stg (code, s390_r2, 0, s390_r13,
5325 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5327 /*---------------------------------------------------------------*/
5328 /* Get current lmf */
5329 /*---------------------------------------------------------------*/
5330 s390_lg (code, s390_r0, 0, s390_r2, 0);
5332 /*---------------------------------------------------------------*/
5333 /* Set our lmf as the current lmf */
5334 /*---------------------------------------------------------------*/
5335 s390_stg (code, s390_r13, 0, s390_r2, 0);
5337 /*---------------------------------------------------------------*/
5338 /* Have our lmf.previous_lmf point to the last lmf */
5339 /*---------------------------------------------------------------*/
5340 s390_stg (code, s390_r0, 0, s390_r13,
5341 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5343 /*---------------------------------------------------------------*/
5344 /* save method info */
5345 /*---------------------------------------------------------------*/
5346 s390_basr (code, s390_r1, 0);
5348 s390_llong (code, method);
5349 s390_lg (code, s390_r1, 0, s390_r1, 4);
5350 s390_stg (code, s390_r1, 0, s390_r13,
5351 G_STRUCT_OFFSET(MonoLMF, method));
5353 /*---------------------------------------------------------------*/
5354 /* save the current IP */
5355 /*---------------------------------------------------------------*/
5356 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5357 s390_basr (code, s390_r1, 0);
5358 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5360 /*---------------------------------------------------------------*/
5361 /* Save general and floating point registers */
5362 /*---------------------------------------------------------------*/
5363 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5364 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5365 for (i = 0; i < 16; i++) {
5366 s390_std (code, i, 0, s390_r13,
5367 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5370 /*---------------------------------------------------------------*/
5371 /* Restore the parameter registers now that we've set up the lmf */
5372 /*---------------------------------------------------------------*/
5373 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5374 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5378 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5380 cfg->code_len = code - cfg->native_code;
5381 g_assert (cfg->code_len < cfg->code_size);
5386 /*========================= End of Function ========================*/
5388 /*------------------------------------------------------------------*/
5390 /* Name - mono_arch_emit_epilog */
5392 /* Function - Emit the instructions for a function epilog. */
5394 /*------------------------------------------------------------------*/
5397 mono_arch_emit_epilog (MonoCompile *cfg)
5399 MonoMethod *method = cfg->method;
5402 int max_epilog_size = 96;
5404 if (cfg->method->save_lmf)
5405 max_epilog_size += 128;
5407 if (mono_jit_trace_calls != NULL)
5408 max_epilog_size += 128;
5410 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5411 max_epilog_size += 128;
5413 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5414 cfg->code_size *= 2;
5415 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5416 cfg->stat_code_reallocs++;
5419 code = cfg->native_code + cfg->code_len;
5421 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5422 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5426 if (method->save_lmf)
5427 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5429 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5430 // if (cfg->frame_reg != STK_BASE)
5431 // s390_lgr (code, STK_BASE, cfg->frame_reg);
5432 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5434 code = backUpStackPtr(cfg, code);
5436 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5437 s390_br (code, s390_r14);
5439 cfg->code_len = code - cfg->native_code;
5441 g_assert (cfg->code_len < cfg->code_size);
5445 /*========================= End of Function ========================*/
5447 /*------------------------------------------------------------------*/
5449 /* Name - mono_arch_emit_exceptions */
5451 /* Function - Emit the blocks to handle exception conditions. */
5453 /*------------------------------------------------------------------*/
5456 mono_arch_emit_exceptions (MonoCompile *cfg)
5458 MonoJumpInfo *patch_info;
5464 MonoClass *exc_classes [MAX_EXC];
5465 guint8 *exc_throw_start [MAX_EXC];
5467 for (patch_info = cfg->patch_info;
5469 patch_info = patch_info->next) {
5470 if (patch_info->type == MONO_PATCH_INFO_EXC)
5474 code_size = exc_count * 48;
5476 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5477 cfg->code_size *= 2;
5478 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5479 cfg->stat_code_reallocs++;
5482 code = cfg->native_code + cfg->code_len;
5484 /*---------------------------------------------------------------------*/
5485 /* Add code to raise exceptions */
5486 /*---------------------------------------------------------------------*/
5487 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5488 switch (patch_info->type) {
5489 case MONO_PATCH_INFO_EXC: {
5490 guint8 *ip = patch_info->ip.i + cfg->native_code;
5491 MonoClass *exc_class;
5494 /*-----------------------------------------------------*/
5495 /* Patch the branch in epilog to come here */
5496 /*-----------------------------------------------------*/
5497 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5499 exc_class = mono_class_from_name (mono_defaults.corlib,
5501 patch_info->data.name);
5502 g_assert (exc_class);
5503 throw_ip = patch_info->ip.i;
5505 for (iExc = 0; iExc < nThrows; ++iExc)
5506 if (exc_classes [iExc] == exc_class)
5509 if (iExc < nThrows) {
5510 s390_jcl (code, S390_CC_UN,
5511 (guint64) exc_throw_start [iExc]);
5512 patch_info->type = MONO_PATCH_INFO_NONE;
5515 if (nThrows < MAX_EXC) {
5516 exc_classes [nThrows] = exc_class;
5517 exc_throw_start [nThrows] = code;
5520 /*---------------------------------------------*/
5521 /* Patch the parameter passed to the handler */
5522 /*---------------------------------------------*/
5523 s390_basr (code, s390_r13, 0);
5525 // s390_llong(code, patch_info->data.target);
5526 s390_llong(code, exc_class->type_token);
5527 /*---------------------------------------------*/
5528 /* Load return address & parameter register */
5529 /*---------------------------------------------*/
5530 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5531 cfg->native_code + 8), code));
5532 s390_lg (code, s390_r2, 0, s390_r13, 4);
5533 /*---------------------------------------------*/
5534 /* Reuse the current patch to set the jump */
5535 /*---------------------------------------------*/
5536 s390_basr (code, s390_r13, 0);
5538 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5539 patch_info->data.name = "mono_arch_throw_corlib_exception";
5540 patch_info->ip.i = code - cfg->native_code;
5541 s390_llong(code, 0);
5542 s390_lg (code, s390_r1, 0, s390_r13, 4);
5543 s390_br (code, s390_r1);
5553 cfg->code_len = code - cfg->native_code;
5555 g_assert (cfg->code_len < cfg->code_size);
5559 /*========================= End of Function ========================*/
5561 /*------------------------------------------------------------------*/
5563 /* Name - mono_arch_finish_init */
5565 /* Function - Setup the JIT's Thread Level Specific Data. */
5567 /*------------------------------------------------------------------*/
5570 mono_arch_finish_init (void)
5572 appdomain_tls_offset = mono_domain_get_tls_offset();
5573 lmf_tls_offset = mono_get_lmf_tls_offset();
5574 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5577 /*========================= End of Function ========================*/
5579 /*------------------------------------------------------------------*/
5581 /* Name - mono_arch_free_jit_tls_data */
5583 /* Function - Free tls data. */
5585 /*------------------------------------------------------------------*/
5588 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5592 /*========================= End of Function ========================*/
5594 /*------------------------------------------------------------------*/
5596 /* Name - mono_arch_emit_inst_for_method */
5598 /*------------------------------------------------------------------*/
5601 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5606 /*========================= End of Function ========================*/
5608 /*------------------------------------------------------------------*/
5610 /* Name - mono_arch_decompose_opts */
5612 /* Function - Decompose opcode into a System z opcode. */
5614 /*------------------------------------------------------------------*/
5617 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5620 * Have to rename these to avoid being decomposed normally, since the normal
5621 * decomposition does not work on S390.
5623 switch (ins->opcode) {
5625 ins->opcode = OP_S390_ISUB_OVF;
5627 case OP_ISUB_OVF_UN:
5628 ins->opcode = OP_S390_ISUB_OVF_UN;
5631 ins->opcode = OP_S390_IADD_OVF;
5633 case OP_IADD_OVF_UN:
5634 ins->opcode = OP_S390_IADD_OVF_UN;
5637 ins->opcode = OP_S390_LADD_OVF;
5639 case OP_LADD_OVF_UN:
5640 ins->opcode = OP_S390_LADD_OVF_UN;
5643 ins->opcode = OP_S390_LSUB_OVF;
5645 case OP_LSUB_OVF_UN:
5646 ins->opcode = OP_S390_LSUB_OVF_UN;
5653 /*========================= End of Function ========================*/
5655 /*------------------------------------------------------------------*/
5657 /* Name - mono_arch_print_tree */
5659 /* Function - Print platform-specific opcode details. */
5661 /* Returns - 1 - opcode details have been printed */
5662 /* 0 - opcode details have not been printed */
5664 /*------------------------------------------------------------------*/
5667 mono_arch_print_tree (MonoInst *tree, int arity)
5671 switch (tree->opcode) {
5672 case OP_S390_LOADARG:
5673 case OP_S390_ARGREG:
5674 case OP_S390_ARGPTR:
5675 printf ("[0x%lx(%s)]", tree->inst_offset,
5676 mono_arch_regname (tree->inst_basereg));
5679 case OP_S390_STKARG:
5680 printf ("[0x%lx(previous_frame)]",
5685 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5686 tree->inst_offset, tree->backend.size,
5687 mono_arch_regname(tree->dreg),
5689 mono_arch_regname(tree->sreg1));
5692 case OP_S390_SETF4RET:
5693 printf ("[f%s,f%s]",
5694 mono_arch_regname (tree->dreg),
5695 mono_arch_regname (tree->sreg1));
5699 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5701 mono_arch_regname (tree->sreg1));
5704 case OP_S390_BKCHAIN:
5705 printf ("[previous_frame(%s)]",
5706 mono_arch_regname (tree->sreg1));
5714 /*========================= End of Function ========================*/
5716 /*------------------------------------------------------------------*/
5718 /* Name - mono_arch_regalloc_cost */
5720 /* Function - Determine the cost, in the number of memory */
5721 /* references, of the action of allocating the var- */
5722 /* iable VMV into a register during global register */
5725 /* Returns - Cost */
5727 /*------------------------------------------------------------------*/
5730 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5736 /*========================= End of Function ========================*/
5738 /*------------------------------------------------------------------*/
5740 /* Name - mono_arch_get_domain_intrinsic */
5746 /*------------------------------------------------------------------*/
5749 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5753 if (appdomain_tls_offset == -1)
5756 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5757 ins->inst_offset = appdomain_tls_offset;
5761 /*========================= End of Function ========================*/
5763 /*------------------------------------------------------------------*/
5765 /* Name - mono_arch_flush_register_windows */
5771 /*------------------------------------------------------------------*/
5774 mono_arch_flush_register_windows (void)
5778 /*========================= End of Function ========================*/
5780 /*------------------------------------------------------------------*/
5782 /* Name - mono_arch_is_inst_imm */
5784 /* Function - Determine if operand qualifies as an immediate */
5785 /* value. For s390 this is a value -32768-32768 */
5787 /* Returns - True|False - is [not] immediate value. */
5789 /*------------------------------------------------------------------*/
5792 mono_arch_is_inst_imm (gint64 imm)
5794 return s390_is_imm16 (imm);
5797 /*========================= End of Function ========================*/
5799 /*------------------------------------------------------------------*/
5801 /* Name - mono_arch_get_patch_offset */
5803 /* Function - Dummy entry point until s390x supports aot. */
5805 /* Returns - Offset for patch. */
5807 /*------------------------------------------------------------------*/
5810 mono_arch_get_patch_offset (guint8 *code)
5815 /*========================= End of Function ========================*/
5817 /*------------------------------------------------------------------*/
5819 /* Name - mono_arch_context_get_int_reg. */
5823 /* Returns - Return a register from the context. */
5825 /*------------------------------------------------------------------*/
5828 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5830 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5833 /*========================= End of Function ========================*/
5835 /*------------------------------------------------------------------*/
5837 /* Name - mono_arch_context_set_int_reg. */
5839 /* Function - Set a value in a specified register. */
5841 /*------------------------------------------------------------------*/
5844 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5846 ctx->uc_mcontext.gregs[reg] = val;
5849 /*========================= End of Function ========================*/
5851 /*------------------------------------------------------------------*/
5853 /* Name - mono_arch_get_this_arg_from_call. */
5857 /*------------------------------------------------------------------*/
5860 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5862 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5864 return (gpointer) lmf->gregs [s390_r2];
5867 /*========================= End of Function ========================*/
5869 /*------------------------------------------------------------------*/
5871 /* Name - get_delegate_invoke_impl. */
5875 /*------------------------------------------------------------------*/
5878 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5880 guint8 *code, *start;
5885 start = code = mono_global_codeman_reserve (size);
5887 /* Replace the this argument with the target */
5888 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5889 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5890 s390_br (code, s390_r1);
5891 g_assert ((code - start) <= size);
5893 mono_arch_flush_icache (start, size);
5897 size = 32 + param_count * 8;
5898 start = code = mono_global_codeman_reserve (size);
5900 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5901 /* slide down the arguments */
5902 for (i = 0; i < param_count; ++i) {
5903 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5905 s390_br (code, s390_r1);
5907 g_assert ((code - start) <= size);
5909 mono_arch_flush_icache (start, size);
5913 *code_len = code - start;
5918 /*========================= End of Function ========================*/
5920 /*------------------------------------------------------------------*/
5922 /* Name - mono_arch_get_delegate_invoke_impls. */
5926 /*------------------------------------------------------------------*/
5929 mono_arch_get_delegate_invoke_impls (void)
5936 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5937 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
5939 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5940 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5941 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
5947 /*========================= End of Function ========================*/
5949 /*------------------------------------------------------------------*/
5951 /* Name - mono_arch_get_delegate_invoke_impl. */
5955 /*------------------------------------------------------------------*/
5958 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5960 guint8 *code, *start;
5962 /* FIXME: Support more cases */
5963 if (MONO_TYPE_ISSTRUCT (sig->ret))
5967 static guint8* cached = NULL;
5973 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5975 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5977 mono_memory_barrier ();
5981 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5984 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5986 for (i = 0; i < sig->param_count; ++i)
5987 if (!mono_is_regsize_var (sig->params [i]))
5991 code = cache [sig->param_count];
5995 if (mono_aot_only) {
5996 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5997 start = mono_aot_get_trampoline (name);
6000 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
6003 mono_memory_barrier ();
6005 cache [sig->param_count] = start;
6010 /*========================= End of Function ========================*/
6012 /*------------------------------------------------------------------*/
6014 /* Name - mono_arch_build_imt_thunk. */
6018 /*------------------------------------------------------------------*/
6021 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
6022 MonoIMTCheckItem **imt_entries, int count,
6023 gpointer fail_tramp)
6027 guchar *code, *start;
6029 for (i = 0; i < count; ++i) {
6030 MonoIMTCheckItem *item = imt_entries [i];
6031 if (item->is_equals) {
6032 if (item->check_target_idx) {
6033 if (!item->compare_done)
6034 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6035 if (item->has_target_code)
6036 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
6038 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
6042 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
6044 if (!item->has_target_code)
6045 item->chunk_size += LOAD_SIZE;
6047 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
6048 #if ENABLE_WRONG_METHOD_CHECK
6049 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6054 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6055 imt_entries [item->check_target_idx]->compare_done = TRUE;
6057 size += item->chunk_size;
6061 code = mono_method_alloc_generic_virtual_thunk (domain, size);
6063 code = mono_domain_code_reserve (domain, size);
6067 for (i = 0; i < count; ++i) {
6068 MonoIMTCheckItem *item = imt_entries [i];
6069 item->code_target = (guint8 *) code;
6070 if (item->is_equals) {
6071 if (item->check_target_idx) {
6072 if (!item->compare_done) {
6073 s390_basr (code, s390_r13, s390_r0);
6075 s390_llong(code, item->key);
6076 s390_lg (code, s390_r0, 0, s390_r13, 4);
6077 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6079 item->jmp_code = (guint8*) code;
6080 s390_jcl (code, S390_CC_NE, 0);
6082 s390_basr (code, s390_r13, s390_r0);
6084 if (item->has_target_code) {
6085 s390_llong(code, item->value.target_code);
6086 s390_lg (code, s390_r1, 0, s390_r13, 4);
6088 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6089 s390_lg (code, s390_r1, 0, s390_r13, 4);
6090 s390_lg (code, s390_r1, 0, s390_r1, 0);
6092 s390_br (code, s390_r1);
6097 s390_basr (code, s390_r13, s390_r0);
6099 s390_llong(code, item->key);
6100 s390_lg (code, s390_r0, 0, s390_r13, 4);
6101 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6102 item->jmp_code = (guint8*) code;
6103 s390_jcl (code, S390_CC_NE, 0);
6104 s390_basr (code, s390_r13, s390_r0);
6106 if (item->has_target_code) {
6107 s390_llong(code, item->value.target_code);
6108 s390_lg (code, s390_r1, 0, s390_r13, 4);
6111 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6112 s390_lg (code, s390_r1, 0, s390_r13, 4);
6113 s390_lg (code, s390_r1, 0, s390_r1, 0);
6115 s390_br (code, s390_r1);
6116 target = S390_RELATIVE(code, item->jmp_code);
6117 s390_patch_rel(item->jmp_code+2, target);
6118 s390_basr (code, s390_r13, s390_r0);
6120 s390_llong(code, fail_tramp);
6121 s390_lg (code, s390_r1, 0, s390_r13, 4);
6122 s390_br (code, s390_r1);
6123 item->jmp_code = NULL;
6125 /* enable the commented code to assert on wrong method */
6126 #if ENABLE_WRONG_METHOD_CHECK
6127 g_assert_not_reached ();
6129 s390_basr (code, s390_r13, s390_r0);
6131 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6132 s390_lg (code, s390_r1, 0, s390_r13, 4);
6133 s390_lg (code, s390_r1, 0, s390_r1, 0);
6134 s390_br (code, s390_r1);
6135 #if ENABLE_WRONG_METHOD_CHECK
6136 g_assert_not_reached ();
6141 s390_basr (code, s390_r13, s390_r0);
6143 s390_llong(code, item->key);
6144 s390_lg (code, s390_r0, 0, s390_r13, 4);
6145 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6146 item->jmp_code = (guint8 *) code;
6147 s390_jcl (code, S390_CC_GE, 0);
6150 /* patch the branches to get to the target items */
6151 for (i = 0; i < count; ++i) {
6152 MonoIMTCheckItem *item = imt_entries [i];
6153 if (item->jmp_code) {
6154 if (item->check_target_idx) {
6156 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6158 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6163 mono_arch_flush_icache ((guint8*)start, (code - start));
6166 mono_stats.imt_thunks_size += (code - start);
6168 g_assert (code - start <= size);
6173 /*========================= End of Function ========================*/
6175 /*------------------------------------------------------------------*/
6177 /* Name - mono_arch_find_imt_method. */
6179 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6180 /* found in the save area. */
6182 /*------------------------------------------------------------------*/
6185 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6187 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
6189 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
6192 /*========================= End of Function ========================*/
6194 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6196 /*------------------------------------------------------------------*/
6198 /* Name - mono_arch_set_breakpoint. */
6200 /* Function - Set a breakpoint at the native code corresponding */
6201 /* to JI at NATIVE_OFFSET. The location should */
6202 /* contain code emitted by OP_SEQ_POINT. */
6204 /*------------------------------------------------------------------*/
6207 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6211 breakpointCode.pTrigger = bp_trigger_page;
6212 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6213 code += BREAKPOINT_SIZE;
6216 /*========================= End of Function ========================*/
6218 /*------------------------------------------------------------------*/
6220 /* Name - mono_arch_clear_breakpoint. */
6222 /* Function - Clear the breakpoint at IP. */
6224 /*------------------------------------------------------------------*/
6227 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6232 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6236 /*========================= End of Function ========================*/
6238 /*------------------------------------------------------------------*/
6240 /* Name - mono_arch_is_breakpoint_event. */
6244 /*------------------------------------------------------------------*/
6247 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6249 siginfo_t* sinfo = (siginfo_t*) info;
6250 /* Sometimes the address is off by 4 */
6251 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6257 /*========================= End of Function ========================*/
6259 /*------------------------------------------------------------------*/
6261 /* Name - mono_arch_skip_breakpoint. */
6263 /* Function - Modify the CTX so the IP is placed after the */
6264 /* breakpoint instruction, so when we resume, the */
6265 /* instruction is not executed again. */
6267 /*------------------------------------------------------------------*/
6270 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6272 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6275 /*========================= End of Function ========================*/
6277 /*------------------------------------------------------------------*/
6279 /* Name - mono_arch_start_single_stepping. */
6281 /* Function - Start single stepping. */
6283 /*------------------------------------------------------------------*/
6286 mono_arch_start_single_stepping (void)
6288 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6291 /*========================= End of Function ========================*/
6293 /*------------------------------------------------------------------*/
6295 /* Name - mono_arch_stop_single_stepping. */
6297 /* Function - Stop single stepping. */
6299 /*------------------------------------------------------------------*/
6302 mono_arch_stop_single_stepping (void)
6304 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6307 /*========================= End of Function ========================*/
6309 /*------------------------------------------------------------------*/
6311 /* Name - mono_arch_is_single_step_event. */
6313 /* Function - Return whether the machine state in sigctx cor- */
6314 /* responds to a single step event. */
6316 /*------------------------------------------------------------------*/
6319 mono_arch_is_single_step_event (void *info, void *sigctx)
6321 siginfo_t* sinfo = (siginfo_t*) info;
6323 /* Sometimes the address is off by 4 */
6324 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6330 /*========================= End of Function ========================*/
6332 /*------------------------------------------------------------------*/
6334 /* Name - mono_arch_skip_single_step. */
6336 /* Function - Modify the ctx so the IP is placed after the */
6337 /* single step trigger instruction, so that the */
6338 /* instruction is not executed again. */
6340 /*------------------------------------------------------------------*/
6343 mono_arch_skip_single_step (MonoContext *ctx)
6345 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6348 /*========================= End of Function ========================*/
6350 /*------------------------------------------------------------------*/
6352 /* Name - mono_arch_create_seq_point_info. */
6354 /* Function - Return a pointer to a data struction which is */
6355 /* used by the sequence point implementation in */
6358 /*------------------------------------------------------------------*/
6361 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6367 /*========================= End of Function ========================*/