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 cfg->locals_min_stack_offset = offset;
2185 curinst = cfg->locals_start;
2186 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2187 inst = cfg->varinfo [iVar];
2188 if ((inst->flags & MONO_INST_IS_DEAD) ||
2189 (inst->opcode == OP_REGVAR))
2192 /*--------------------------------------------------*/
2193 /* inst->backend.is_pinvoke indicates native sized */
2194 /* value typs this is used by the pinvoke wrappers */
2195 /* when they call functions returning structure */
2196 /*--------------------------------------------------*/
2197 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2198 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2199 (guint32 *) &align);
2201 size = mono_type_size (inst->inst_vtype, &align);
2203 offset = S390_ALIGN(offset, align);
2204 inst->inst_offset = offset;
2205 inst->opcode = OP_REGOFFSET;
2206 inst->inst_basereg = frame_reg;
2208 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2209 iVar, inst->inst_offset, size));
2212 cfg->locals_max_stack_offset = offset;
2214 /*------------------------------------------------------*/
2215 /* Allow space for the trace method stack area if needed*/
2216 /*------------------------------------------------------*/
2217 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2218 offset += S390_TRACE_STACK_SIZE;
2220 /*------------------------------------------------------*/
2221 /* Reserve space to save LMF and caller saved registers */
2222 /*------------------------------------------------------*/
2223 if (cfg->method->save_lmf)
2224 offset += sizeof (MonoLMF);
2226 /*------------------------------------------------------*/
2227 /* align the offset */
2228 /*------------------------------------------------------*/
2229 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2231 /*------------------------------------------------------*/
2232 /* Fix offsets for args whose value is in parent frame */
2233 /*------------------------------------------------------*/
2234 for (iParm = sArg; iParm < eArg; ++iParm) {
2235 inst = cfg->args [iParm];
2237 if (inst->opcode == OP_S390_STKARG) {
2238 inst->opcode = OP_REGOFFSET;
2239 inst->inst_offset += cfg->stack_offset;
2244 /*========================= End of Function ========================*/
2246 /*------------------------------------------------------------------*/
2248 /* Name - mono_arch_create_vars */
2250 /*------------------------------------------------------------------*/
2253 mono_arch_create_vars (MonoCompile *cfg)
2255 MonoMethodSignature *sig;
2258 sig = mono_method_signature (cfg->method);
2260 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2262 if (cinfo->struct_ret) {
2263 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2264 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2265 printf ("vret_addr = ");
2266 mono_print_ins (cfg->vret_addr);
2271 /*========================= End of Function ========================*/
2273 /*------------------------------------------------------------------*/
2275 /* Name - add_outarg_reg2. */
2277 /*------------------------------------------------------------------*/
2280 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2285 case RegTypeGeneral:
2286 MONO_INST_NEW (cfg, ins, OP_MOVE);
2287 ins->dreg = mono_alloc_ireg (cfg);
2288 ins->sreg1 = tree->dreg;
2289 MONO_ADD_INS (cfg->cbb, ins);
2290 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2293 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2294 ins->dreg = mono_alloc_freg (cfg);
2295 ins->sreg1 = tree->dreg;
2296 MONO_ADD_INS (cfg->cbb, ins);
2297 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2300 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2301 ins->dreg = mono_alloc_freg (cfg);
2302 ins->sreg1 = tree->dreg;
2303 MONO_ADD_INS (cfg->cbb, ins);
2304 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2307 g_assert_not_reached ();
2311 /*========================= End of Function ========================*/
2313 /*------------------------------------------------------------------*/
2315 /* Name - emit_sig_cookie. */
2317 /*------------------------------------------------------------------*/
2320 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2322 MonoMethodSignature *tmpSig;
2325 cfg->disable_aot = TRUE;
2327 /*----------------------------------------------------------*/
2328 /* mono_ArgIterator_Setup assumes the signature cookie is */
2329 /* passed first and all the arguments which were before it */
2330 /* passed on the stack after the signature. So compensate */
2331 /* by passing a different signature. */
2332 /*----------------------------------------------------------*/
2333 tmpSig = mono_metadata_signature_dup (call->signature);
2334 tmpSig->param_count -= call->signature->sentinelpos;
2335 tmpSig->sentinelpos = 0;
2336 if (tmpSig->param_count > 0)
2337 memcpy (tmpSig->params,
2338 call->signature->params + call->signature->sentinelpos,
2339 tmpSig->param_count * sizeof(MonoType *));
2341 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2342 sig_arg->dreg = mono_alloc_ireg (cfg);
2343 sig_arg->inst_p0 = tmpSig;
2344 MONO_ADD_INS (cfg->cbb, sig_arg);
2346 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2347 cinfo->sigCookie.offset, sig_arg->dreg);
2350 /*========================= End of Function ========================*/
2352 /*------------------------------------------------------------------*/
2354 /* Name - mono_arch_emit_call */
2356 /*------------------------------------------------------------------*/
2359 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2362 MonoMethodSignature *sig;
2364 int i, n, lParamArea;
2366 ArgInfo *ainfo = NULL;
2368 MonoMethodHeader *header;
2371 sig = call->signature;
2372 n = sig->param_count + sig->hasthis;
2373 DEBUG (g_print ("Call requires: %d parameters\n",n));
2375 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2377 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2378 cinfo->sz.parm_size + cinfo->sz.offset;
2379 call->stack_usage = MAX(stackSize, call->stack_usage);
2380 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2381 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2382 cfg->flags |= MONO_CFG_HAS_CALLS;
2384 if (cinfo->struct_ret) {
2385 MONO_INST_NEW (cfg, ins, OP_MOVE);
2386 ins->sreg1 = call->vret_var->dreg;
2387 ins->dreg = mono_alloc_preg (cfg);
2388 MONO_ADD_INS (cfg->cbb, ins);
2389 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2392 header = cfg->header;
2393 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2398 for (i = 0; i < n; ++i) {
2401 ainfo = cinfo->args + i;
2402 if (i >= sig->hasthis)
2403 t = sig->params [i - sig->hasthis];
2405 t = &mono_defaults.int_class->byval_arg;
2406 t = mono_type_get_underlying_type (t);
2408 in = call->args [i];
2410 if ((sig->call_convention == MONO_CALL_VARARG) &&
2412 (i == sig->sentinelpos)) {
2413 emit_sig_cookie (cfg, call, cinfo);
2416 switch (ainfo->regtype) {
2417 case RegTypeGeneral:
2418 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2421 if (MONO_TYPE_ISSTRUCT (t)) {
2422 /* Valuetype passed in one fp register */
2423 ainfo->regtype = RegTypeStructByValInFP;
2426 if (ainfo->size == 4)
2427 ainfo->regtype = RegTypeFPR4;
2428 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2431 case RegTypeStructByVal:
2432 case RegTypeStructByAddr:
2433 case RegTypeStructByAddrOnStack: {
2437 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2438 size = sizeof (MonoTypedRef);
2439 align = sizeof (gpointer);
2443 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2446 * Other backends use mono_type_stack_size (), but that
2447 * aligns the size to 8, which is larger than the size of
2448 * the source, leading to reads of invalid memory if the
2449 * source is at the end of address space.
2451 size = mono_class_value_size (in->klass, &align);
2454 g_assert (in->klass);
2456 ainfo->offparm += cinfo->sz.offStruct;
2458 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2459 ins->sreg1 = in->dreg;
2460 ins->klass = in->klass;
2461 ins->backend.size = ainfo->size;
2462 ins->inst_p0 = call;
2463 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2464 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2466 MONO_ADD_INS (cfg->cbb, ins);
2468 if (ainfo->regtype == RegTypeStructByAddr) {
2470 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2471 * use the normal OUTARG opcodes to pass the address of the location to
2474 int treg = mono_alloc_preg (cfg);
2475 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2476 frmReg, ainfo->offparm);
2477 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2478 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2479 /* The address of the valuetype is passed on the stack */
2480 int treg = mono_alloc_preg (cfg);
2481 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2482 frmReg, ainfo->offparm);
2483 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2484 ainfo->reg, ainfo->offset, treg);
2486 if (cfg->compute_gc_maps) {
2489 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2495 if (!t->byref && t->type == MONO_TYPE_R4) {
2496 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2497 STK_BASE, ainfo->offset + 4,
2499 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2500 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2501 STK_BASE, ainfo->offset,
2504 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2505 ins->inst_destbasereg = STK_BASE;
2506 ins->inst_offset = ainfo->offset;
2507 ins->sreg1 = in->dreg;
2510 /* This is needed by MonoTypedRef->value to point to the correct data */
2511 if ((sig->call_convention == MONO_CALL_VARARG) &&
2512 (i >= sig->sentinelpos)) {
2513 switch (ainfo->size) {
2515 ins->opcode = OP_STOREI1_MEMBASE_REG;
2518 ins->opcode = OP_STOREI2_MEMBASE_REG;
2521 ins->opcode = OP_STOREI4_MEMBASE_REG;
2529 MONO_ADD_INS (cfg->cbb, ins);
2533 g_assert_not_reached ();
2539 * Handle the case where there are no implicit arguments
2541 if ((sig->call_convention == MONO_CALL_VARARG) &&
2543 (i == sig->sentinelpos)) {
2544 emit_sig_cookie (cfg, call, cinfo);
2548 /*========================= End of Function ========================*/
2550 /*------------------------------------------------------------------*/
2552 /* Name - mono_arch_emit_outarg_vt */
2554 /*------------------------------------------------------------------*/
2557 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2559 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2560 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2561 int size = ins->backend.size;
2563 if (ainfo->regtype == RegTypeStructByVal) {
2565 arg->ins.sreg1 = ainfo->reg;
2566 arg->ins.opcode = OP_OUTARG_VT;
2567 arg->size = ainfo->size;
2568 arg->offset = ainfo->offset;
2569 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2571 if (ainfo->reg != STK_BASE) {
2572 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2574 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2577 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2578 int dreg = mono_alloc_freg (cfg);
2580 if (ainfo->size == 4) {
2581 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2582 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2584 g_assert (ainfo->size == 8);
2586 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2589 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2591 MonoMethodHeader *header;
2594 header = mono_method_get_header (cfg->method);
2595 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2600 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2601 src->dreg, 0, size);
2603 if (cfg->compute_gc_maps) {
2606 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2611 /*========================= End of Function ========================*/
2613 /*------------------------------------------------------------------*/
2615 /* Name - mono_arch_emit_setret */
2617 /*------------------------------------------------------------------*/
2620 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2622 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2625 if (ret->type == MONO_TYPE_R4) {
2626 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2628 } else if (ret->type == MONO_TYPE_R8) {
2629 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2634 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2637 /*========================= End of Function ========================*/
2639 /*------------------------------------------------------------------*/
2641 /* Name - mono_arch_instrument_mem_needs */
2643 /* Function - Allow tracing to work with this interface (with */
2644 /* an optional argument). */
2646 /*------------------------------------------------------------------*/
2649 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2651 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2653 /* split prolog-epilog requirements? */
2654 *code = 50; /* max bytes needed: check this number */
2657 /*========================= End of Function ========================*/
2659 /*------------------------------------------------------------------*/
2661 /* Name - mono_arch_instrument_prolog */
2663 /* Function - Create an "instrumented" prolog. */
2665 /*------------------------------------------------------------------*/
2668 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2669 gboolean enable_arguments)
2676 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2677 if (cfg->method->save_lmf)
2678 parmOffset -= sizeof(MonoLMF);
2679 fpOffset = parmOffset + (5*sizeof(gpointer));
2680 if ((!has_ld) && (fpOffset > 4096)) {
2681 s390_lgr (code, s390_r12, STK_BASE);
2683 while (fpOffset > 4096) {
2684 s390_aghi (code, baseReg, 4096);
2692 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2694 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2695 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2696 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2697 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2699 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2700 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2701 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2702 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2704 s390_basr (code, s390_r13, 0);
2706 s390_llong(code, cfg->method);
2707 s390_llong(code, func);
2708 s390_lg (code, s390_r2, 0, s390_r13, 4);
2710 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2712 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2713 s390_lgr (code, s390_r4, STK_BASE);
2714 s390_aghi (code, s390_r4, cfg->stack_usage);
2715 s390_lg (code, s390_r1, 0, s390_r13, 12);
2716 s390_basr (code, s390_r14, s390_r1);
2718 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2719 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2720 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2721 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2723 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2724 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2725 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2726 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2728 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2733 /*========================= End of Function ========================*/
2735 /*------------------------------------------------------------------*/
2737 /* Name - mono_arch_instrument_epilog */
2739 /* Function - Create an epilog that will handle the returned */
2740 /* values used in instrumentation. */
2742 /*------------------------------------------------------------------*/
2745 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2748 int save_mode = SAVE_NONE,
2750 MonoMethod *method = cfg->method;
2751 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2753 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2754 if (method->save_lmf)
2755 saveOffset -= sizeof(MonoLMF);
2759 case MONO_TYPE_VOID:
2760 /* special case string .ctor icall */
2761 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2762 save_mode = SAVE_ONE;
2764 save_mode = SAVE_NONE;
2768 save_mode = SAVE_ONE;
2771 save_mode = SAVE_R4;
2774 save_mode = SAVE_R8;
2776 case MONO_TYPE_VALUETYPE:
2777 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2778 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2781 save_mode = SAVE_STRUCT;
2784 save_mode = SAVE_ONE;
2788 switch (save_mode) {
2790 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2791 if (enable_arguments) {
2792 s390_lgr (code, s390_r3, s390_r2);
2796 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2797 if (enable_arguments) {
2798 s390_ldebr (code, s390_f0, s390_f0);
2802 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2805 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2806 if (enable_arguments) {
2807 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2808 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2816 s390_basr (code, s390_r13, 0);
2818 s390_llong(code, cfg->method);
2819 s390_llong(code, func);
2820 s390_lg (code, s390_r2, 0, s390_r13, 4);
2821 s390_lg (code, s390_r1, 0, s390_r13, 12);
2822 s390_basr (code, s390_r14, s390_r1);
2824 switch (save_mode) {
2826 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2830 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2833 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2843 /*========================= End of Function ========================*/
2845 /*------------------------------------------------------------------*/
2847 /* Name - mono_arch_peephole_pass_1 */
2849 /* Function - Form a peephole pass at the code looking for */
2850 /* simple optimizations. */
2852 /*------------------------------------------------------------------*/
2855 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2859 /*========================= End of Function ========================*/
2861 /*------------------------------------------------------------------*/
2863 /* Name - mono_arch_peephole_pass_2 */
2865 /* Function - Form a peephole pass at the code looking for */
2866 /* simple optimizations. */
2868 /*------------------------------------------------------------------*/
2871 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2875 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2876 mono_peephole_ins (bb, ins);
2880 /*========================= End of Function ========================*/
2882 /*------------------------------------------------------------------*/
2884 /* Name - mono_arch_lowering_pass. */
2886 /*------------------------------------------------------------------*/
2889 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2891 MonoInst *ins, *next;
2893 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2894 switch (ins->opcode) {
2899 case OP_IDIV_UN_IMM:
2900 case OP_IREM_UN_IMM:
2904 case OP_LOCALLOC_IMM:
2905 mono_decompose_op_imm (cfg, bb, ins);
2908 if (!s390_is_imm16 (ins->inst_imm))
2909 /* This is created by the memcpy code which ignores is_inst_imm */
2910 mono_decompose_op_imm (cfg, bb, ins);
2917 bb->max_vreg = cfg->next_vreg;
2920 /*========================= End of Function ========================*/
2922 /*------------------------------------------------------------------*/
2924 /* Name - emit_float_to_int */
2926 /* Function - Create instructions which will convert a floating */
2927 /* point value to integer. */
2929 /*------------------------------------------------------------------*/
2932 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2934 /* sreg is a float, dreg is an integer reg. */
2936 s390_cgdbr (code, dreg, 5, sreg);
2939 s390_lghi (code, s390_r0, 0);
2940 s390_lghi (code, s390_r13, 0xff);
2941 s390_ltgr (code, dreg, dreg);
2943 s390_lghi (code, s390_r0, 0x80);
2944 s390_ngr (code, dreg, s390_r13);
2945 s390_ogr (code, dreg, s390_r0);
2950 s390_basr (code, s390_r13, 0);
2952 s390_llong (code, 0x41e0000000000000llu);
2953 s390_llong (code, 0x41f0000000000000llu);
2954 s390_ldr (code, s390_f15, sreg);
2955 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2956 s390_jl (code, 0); CODEPTR (code, o[0]);
2957 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2958 s390_cfdbr (code, dreg, 7, s390_f15);
2960 PTRSLOT (code, o[0]);
2961 s390_cfdbr (code, dreg, 5, sreg);
2964 s390_lghi (code, s390_r0, 0xff);
2965 s390_ngr (code, dreg, s390_r0);
2968 s390_lghi (code, s390_r0, -1);
2969 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2970 s390_ngr (code, dreg, s390_r0);
2977 /*========================= End of Function ========================*/
2979 /*------------------------------------------------------------------*/
2981 /* Name - gboolean_is_unsigned. */
2983 /* Function - Return TRUE if next opcode is checking for un- */
2986 /*------------------------------------------------------------------*/
2989 gboolean is_unsigned (MonoInst *next)
2992 (((next->opcode >= OP_IBNE_UN) &&
2993 (next->opcode <= OP_IBLT_UN)) ||
2994 ((next->opcode >= OP_LBNE_UN) &&
2995 (next->opcode <= OP_LBLT_UN)) ||
2996 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2997 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2998 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2999 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
3000 ((next->opcode == OP_CLT_UN) ||
3001 (next->opcode == OP_CGT_UN)) ||
3002 ((next->opcode == OP_ICLT_UN) ||
3003 (next->opcode == OP_ICGT_UN) ||
3004 (next->opcode == OP_LCLT_UN) ||
3005 (next->opcode == OP_LCGT_UN))))
3011 /*========================= End of Function ========================*/
3013 /*------------------------------------------------------------------*/
3015 /* Name - mono_arch_output_basic_block */
3017 /* Function - Perform the "real" work of emitting instructions */
3018 /* that will do the work of in the basic block. */
3020 /*------------------------------------------------------------------*/
3023 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
3028 guint8 *code = cfg->native_code + cfg->code_len;
3029 guint last_offset = 0;
3030 int max_len, cpos, src2;
3032 /* we don't align basic blocks of loops on s390 */
3034 if (cfg->verbose_level > 2)
3035 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
3037 cpos = bb->max_offset;
3039 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
3040 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
3041 //g_assert (!mono_compile_aot);
3044 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
3045 /* this is not thread save, but good enough */
3046 /* fixme: howto handle overflows? */
3047 //x86_inc_mem (code, &cov->data [bb->dfn].count);
3050 MONO_BB_FOR_EACH_INS (bb, ins) {
3051 offset = code - cfg->native_code;
3053 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
3055 if (offset > (cfg->code_size - max_len - 16)) {
3056 cfg->code_size *= 2;
3057 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
3058 code = cfg->native_code + offset;
3061 mono_debug_record_line_number (cfg, ins, offset);
3063 switch (ins->opcode) {
3064 case OP_STOREI1_MEMBASE_IMM: {
3065 s390_lghi (code, s390_r0, ins->inst_imm);
3066 S390_LONG (code, stcy, stc, s390_r0, 0,
3067 ins->inst_destbasereg, ins->inst_offset);
3070 case OP_STOREI2_MEMBASE_IMM: {
3071 s390_lghi (code, s390_r0, ins->inst_imm);
3072 S390_LONG (code, sthy, sth, s390_r0, 0,
3073 ins->inst_destbasereg, ins->inst_offset);
3076 case OP_STOREI4_MEMBASE_IMM: {
3077 if (s390_is_imm16(ins->inst_imm)) {
3078 s390_lghi (code, s390_r0, ins->inst_imm);
3080 s390_basr (code, s390_r13, 0);
3082 s390_llong(code, ins->inst_imm);
3083 s390_lg (code, s390_r0, 0, s390_r13, 4);
3085 S390_LONG (code, sty, st, s390_r0, 0,
3086 ins->inst_destbasereg, ins->inst_offset);
3089 case OP_STORE_MEMBASE_IMM:
3090 case OP_STOREI8_MEMBASE_IMM: {
3091 if (s390_is_imm16(ins->inst_imm)) {
3092 s390_lghi (code, s390_r0, ins->inst_imm);
3094 s390_basr (code, s390_r13, 0);
3096 s390_llong(code, ins->inst_imm);
3097 s390_lg (code, s390_r0, 0, s390_r13, 4);
3099 S390_LONG (code, stg, stg, s390_r0, 0,
3100 ins->inst_destbasereg, ins->inst_offset);
3103 case OP_STOREI1_MEMBASE_REG: {
3104 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3105 ins->inst_destbasereg, ins->inst_offset);
3108 case OP_STOREI2_MEMBASE_REG: {
3109 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3110 ins->inst_destbasereg, ins->inst_offset);
3113 case OP_STOREI4_MEMBASE_REG: {
3114 S390_LONG (code, sty, st, ins->sreg1, 0,
3115 ins->inst_destbasereg, ins->inst_offset);
3118 case OP_STORE_MEMBASE_REG:
3119 case OP_STOREI8_MEMBASE_REG: {
3120 S390_LONG (code, stg, stg, ins->sreg1, 0,
3121 ins->inst_destbasereg, ins->inst_offset);
3125 g_assert_not_reached ();
3127 case OP_LOAD_MEMBASE:
3128 case OP_LOADI8_MEMBASE: {
3129 S390_LONG (code, lg, lg, ins->dreg, 0,
3130 ins->inst_basereg, ins->inst_offset);
3133 case OP_LOADI4_MEMBASE: {
3134 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3135 ins->inst_basereg, ins->inst_offset);
3138 case OP_LOADU4_MEMBASE: {
3139 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3140 ins->inst_basereg, ins->inst_offset);
3143 case OP_LOADU1_MEMBASE: {
3144 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3145 ins->inst_basereg, ins->inst_offset);
3148 case OP_LOADI1_MEMBASE: {
3149 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3150 ins->inst_basereg, ins->inst_offset);
3153 case OP_LOADU2_MEMBASE: {
3154 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3155 ins->inst_basereg, ins->inst_offset);
3158 case OP_LOADI2_MEMBASE: {
3159 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3160 ins->inst_basereg, ins->inst_offset);
3163 case OP_LCONV_TO_I1: {
3165 s390_lgbr (code, ins->dreg, ins->sreg1);
3167 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
3168 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
3172 case OP_LCONV_TO_I2: {
3174 s390_lghr (code, ins->dreg, ins->sreg1);
3176 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
3177 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
3181 case OP_LCONV_TO_U1: {
3183 s390_llghr (code, ins->dreg, ins->sreg1);
3185 if (ins->dreg != ins->sreg1)
3186 s390_lgr (code, ins->dreg, ins->sreg1);
3187 s390_lghi (code, s390_r0, 0xff);
3188 s390_ngr (code, ins->dreg, s390_r0);
3192 case OP_LCONV_TO_U2: {
3194 s390_llghr (code, ins->dreg, ins->sreg1);
3196 if (ins->dreg != ins->sreg1)
3197 s390_lgr (code, ins->dreg, ins->sreg1);
3198 s390_lghi (code, s390_r0, -1);
3199 s390_srlg (code, s390_r0, s390_r0, 0, 48);
3200 s390_ngr (code, ins->dreg, s390_r0);
3204 case OP_ICONV_TO_I1: {
3206 s390_lbr (code, ins->dreg, ins->sreg1);
3208 if (ins->dreg != ins->sreg1)
3209 s390_lr (code, ins->dreg, ins->sreg1);
3210 s390_sll (code, ins->dreg, 0, 24);
3211 s390_sra (code, ins->dreg, 0, 24);
3216 case OP_ICONV_TO_I2: {
3218 s390_lhr (code, ins->dreg, ins->sreg1);
3220 if (ins->dreg != ins->sreg1)
3221 s390_lr (code, ins->dreg, ins->sreg1);
3222 s390_sll (code, ins->dreg, 0, 16);
3223 s390_sra (code, ins->dreg, 0, 16);
3227 case OP_ICONV_TO_U1: {
3229 s390_llcr (code, ins->dreg, ins->sreg1);
3231 if (ins->dreg != ins->sreg1)
3232 s390_lr (code, ins->dreg, ins->sreg1);
3233 s390_lhi (code, s390_r0, 0xff);
3234 s390_nr (code, ins->dreg, s390_r0);
3238 case OP_ICONV_TO_U2: {
3240 s390_llhr (code, ins->dreg, ins->sreg1);
3242 if (ins->dreg != ins->sreg1)
3243 s390_lr (code, ins->dreg, ins->sreg1);
3244 s390_lhi (code, s390_r0, -1);
3245 s390_srl (code, s390_r0, 0, 16);
3246 s390_nr (code, ins->dreg, s390_r0);
3252 if (is_unsigned (ins->next))
3253 s390_clgr (code, ins->sreg1, ins->sreg2);
3255 s390_cgr (code, ins->sreg1, ins->sreg2);
3259 if (is_unsigned (ins->next))
3260 s390_clr (code, ins->sreg1, ins->sreg2);
3262 s390_cr (code, ins->sreg1, ins->sreg2);
3265 case OP_COMPARE_IMM:
3266 case OP_LCOMPARE_IMM: {
3267 if (s390_is_imm16 (ins->inst_imm)) {
3268 s390_lghi (code, s390_r0, ins->inst_imm);
3269 if (is_unsigned (ins->next))
3270 s390_clgr (code, ins->sreg1, s390_r0);
3272 s390_cgr (code, ins->sreg1, s390_r0);
3274 s390_basr (code, s390_r13, 0);
3276 s390_llong(code, ins->inst_imm);
3277 if (is_unsigned (ins->next))
3278 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3280 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3284 case OP_ICOMPARE_IMM: {
3285 if (s390_is_imm16 (ins->inst_imm)) {
3286 s390_lghi (code, s390_r0, ins->inst_imm);
3287 if (is_unsigned (ins->next))
3288 s390_clr (code, ins->sreg1, s390_r0);
3290 s390_cr (code, ins->sreg1, s390_r0);
3293 s390_basr (code, s390_r13, 0);
3295 s390_word (code, ins->inst_imm);
3296 if (is_unsigned (ins->next))
3297 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3299 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3304 s390_basr (code, s390_r13, 0);
3306 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3308 s390_llong (code, mono_break);
3309 s390_lg (code, s390_r14, 0, s390_r13, 4);
3310 s390_basr (code, s390_r14, s390_r14);
3315 s390_agr (code, ins->dreg, src2);
3320 s390_agr (code, ins->dreg, src2);
3325 s390_alcgr (code, ins->dreg, src2);
3329 if (ins->dreg != ins->sreg1) {
3330 s390_lgr (code, ins->dreg, ins->sreg1);
3332 if (s390_is_imm16 (ins->inst_imm)) {
3333 s390_aghi (code, ins->dreg, ins->inst_imm);
3335 s390_basr (code, s390_r13, 0);
3337 s390_llong(code, ins->inst_imm);
3338 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3343 if (ins->dreg != ins->sreg1) {
3344 s390_lgr (code, ins->dreg, ins->sreg1);
3346 g_assert (s390_is_imm16 (ins->inst_imm));
3347 s390_aghi (code, ins->dreg, ins->inst_imm);
3351 if (ins->dreg != ins->sreg1) {
3352 s390_lgr (code, ins->dreg, ins->sreg1);
3354 if (s390_is_imm16 (ins->inst_imm)) {
3355 s390_lghi (code, s390_r0, ins->inst_imm);
3356 s390_alcgr (code, ins->dreg, s390_r0);
3358 s390_basr (code, s390_r13, 0);
3360 s390_llong (code, ins->inst_imm);
3361 s390_lg (code, s390_r13, 0, s390_r13, 4);
3362 s390_alcgr (code, ins->dreg, s390_r13);
3367 case OP_S390_IADD_OVF: {
3369 s390_ar (code, ins->dreg, src2);
3370 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3371 s390_lgfr (code, ins->dreg, ins->dreg);
3374 case OP_IADD_OVF_UN:
3375 case OP_S390_IADD_OVF_UN: {
3377 s390_algr (code, ins->dreg, src2);
3378 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3379 s390_llgfr (code, ins->dreg, ins->dreg);
3382 case OP_ADD_OVF_CARRY: {
3384 s390_lghi (code, s390_r0, 0);
3385 s390_lgr (code, s390_r1, s390_r0);
3386 s390_alcgr (code, s390_r0, s390_r1);
3387 s390_agr (code, ins->dreg, src2);
3388 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3389 s390_agr (code, ins->dreg, s390_r0);
3390 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3393 case OP_ADD_OVF_UN_CARRY: {
3395 s390_alcgr (code, ins->dreg, src2);
3396 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3401 s390_sgr (code, ins->dreg, src2);
3406 s390_sgr (code, ins->dreg, src2);
3411 s390_slbgr(code, ins->dreg, src2);
3415 if (ins->dreg != ins->sreg1) {
3416 s390_lgr (code, ins->dreg, ins->sreg1);
3418 if (s390_is_imm16 (-ins->inst_imm)) {
3419 s390_lghi (code, s390_r0, ins->inst_imm);
3420 s390_slgr (code, ins->dreg, s390_r0);
3422 s390_basr (code, s390_r13, 0);
3424 s390_llong(code, ins->inst_imm);
3425 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3430 if (ins->dreg != ins->sreg1) {
3431 s390_lgr (code, ins->dreg, ins->sreg1);
3433 if (s390_is_imm16 (-ins->inst_imm)) {
3434 s390_lghi (code, s390_r0, ins->inst_imm);
3435 s390_slgr (code, ins->dreg, s390_r0);
3437 s390_basr (code, s390_r13, 0);
3439 s390_llong(code, ins->inst_imm);
3440 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3445 if (ins->dreg != ins->sreg1) {
3446 s390_lgr (code, ins->dreg, ins->sreg1);
3448 if (s390_is_imm16 (-ins->inst_imm)) {
3449 s390_lghi (code, s390_r0, ins->inst_imm);
3450 s390_slbgr (code, ins->dreg, s390_r0);
3452 s390_basr (code, s390_r13, 0);
3454 s390_llong(code, ins->inst_imm);
3455 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3459 case OP_SUB_OVF_CARRY: {
3461 s390_lghi (code, s390_r0, 0);
3462 s390_lgr (code, s390_r1, s390_r0);
3463 s390_slbgr (code, s390_r0, s390_r1);
3464 s390_sgr (code, ins->dreg, src2);
3465 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3466 s390_agr (code, ins->dreg, s390_r0);
3467 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3470 case OP_SUB_OVF_UN_CARRY: {
3472 s390_slbgr (code, ins->dreg, src2);
3473 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3477 if (ins->sreg1 == ins->dreg) {
3478 s390_ngr (code, ins->dreg, ins->sreg2);
3481 if (ins->sreg2 == ins->dreg) {
3482 s390_ngr (code, ins->dreg, ins->sreg1);
3485 s390_lgr (code, ins->dreg, ins->sreg1);
3486 s390_ngr (code, ins->dreg, ins->sreg2);
3492 if (ins->dreg != ins->sreg1) {
3493 s390_lgr (code, ins->dreg, ins->sreg1);
3495 if (s390_is_imm16 (ins->inst_imm)) {
3496 s390_lghi (code, s390_r0, ins->inst_imm);
3497 s390_ngr (code, ins->dreg, s390_r0);
3499 s390_basr (code, s390_r13, 0);
3501 s390_llong(code, ins->inst_imm);
3502 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3507 s390_lgr (code, s390_r1, ins->sreg1);
3508 s390_dsgr (code, s390_r0, ins->sreg2);
3509 s390_lgr (code, ins->dreg, s390_r1);
3513 s390_lgr (code, s390_r1, ins->sreg1);
3514 s390_lghi (code, s390_r0, 0);
3515 s390_dlgr (code, s390_r0, ins->sreg2);
3516 s390_lgr (code, ins->dreg, s390_r1);
3520 s390_lgr (code, s390_r1, ins->sreg1);
3521 s390_dsgr (code, s390_r0, ins->sreg2);
3522 s390_lgr (code, ins->dreg, s390_r0);
3526 s390_lgr (code, s390_r1, ins->sreg1);
3527 s390_lghi (code, s390_r0, 0);
3528 s390_dlgr (code, s390_r0, ins->sreg2);
3529 s390_lgr (code, ins->dreg, s390_r0);
3533 if (ins->sreg1 == ins->dreg) {
3534 s390_ogr (code, ins->dreg, ins->sreg2);
3537 if (ins->sreg2 == ins->dreg) {
3538 s390_ogr (code, ins->dreg, ins->sreg1);
3541 s390_lgr (code, ins->dreg, ins->sreg1);
3542 s390_ogr (code, ins->dreg, ins->sreg2);
3548 if (ins->dreg != ins->sreg1) {
3549 s390_lgr (code, ins->dreg, ins->sreg1);
3551 if (s390_is_imm16 (ins->inst_imm)) {
3552 s390_lghi (code, s390_r0, ins->inst_imm);
3553 s390_ogr (code, ins->dreg, s390_r0);
3555 s390_basr (code, s390_r13, 0);
3557 s390_llong(code, ins->inst_imm);
3558 s390_og (code, ins->dreg, 0, s390_r13, 4);
3563 if (ins->sreg1 == ins->dreg) {
3564 s390_xgr (code, ins->dreg, ins->sreg2);
3567 if (ins->sreg2 == ins->dreg) {
3568 s390_xgr (code, ins->dreg, ins->sreg1);
3571 s390_lgr (code, ins->dreg, ins->sreg1);
3572 s390_xgr (code, ins->dreg, ins->sreg2);
3578 if (ins->dreg != ins->sreg1) {
3579 s390_lgr (code, ins->dreg, ins->sreg1);
3581 if (s390_is_imm16 (ins->inst_imm)) {
3582 s390_lghi (code, s390_r0, ins->inst_imm);
3583 s390_xgr (code, ins->dreg, s390_r0);
3585 s390_basr (code, s390_r13, 0);
3587 s390_llong(code, ins->inst_imm);
3588 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3594 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3599 if (ins->sreg1 != ins->dreg) {
3600 s390_lgr (code, ins->dreg, ins->sreg1);
3602 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3607 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3612 if (ins->sreg1 != ins->dreg) {
3613 s390_lgr (code, ins->dreg, ins->sreg1);
3615 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3619 case OP_LSHR_UN_IMM: {
3620 if (ins->sreg1 != ins->dreg) {
3621 s390_lgr (code, ins->dreg, ins->sreg1);
3623 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3628 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3632 if (ins->sreg1 != ins->dreg) {
3633 s390_lgr (code, ins->dreg, ins->sreg1);
3635 s390_lghi (code, s390_r0, -1);
3636 s390_xgr (code, ins->dreg, s390_r0);
3640 s390_lcgr (code, ins->dreg, ins->sreg1);
3645 s390_msgr (code, ins->dreg, src2);
3650 if (ins->dreg != ins->sreg1) {
3651 s390_lgr (code, ins->dreg, ins->sreg1);
3653 if (s390_is_imm16 (ins->inst_imm)) {
3654 s390_lghi (code, s390_r13, ins->inst_imm);
3656 s390_basr (code, s390_r13, 0);
3658 s390_llong(code, ins->inst_imm);
3659 s390_lg (code, s390_r13, 0, s390_r13, 4);
3661 s390_msgr (code, ins->dreg, s390_r13);
3666 s390_ltgr (code, s390_r1, ins->sreg1);
3667 s390_jz (code, 0); CODEPTR(code, o[0]);
3668 s390_ltgr (code, s390_r0, ins->sreg2);
3670 s390_lghi (code, s390_r1, 0);
3671 s390_j (code, 0); CODEPTR(code, o[1]);
3672 s390_xgr (code, s390_r0, s390_r1);
3673 s390_msgr (code, s390_r1, ins->sreg2);
3674 s390_xgr (code, s390_r0, s390_r1);
3675 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3676 s390_ltgr (code, s390_r0, s390_r0);
3677 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3678 PTRSLOT (code, o[0]);
3679 PTRSLOT (code, o[1]);
3680 s390_lgr (code, ins->dreg, s390_r1);
3683 case OP_LMUL_OVF_UN: {
3684 s390_lghi (code, s390_r0, 0);
3685 s390_lgr (code, s390_r1, ins->sreg1);
3686 s390_mlgr (code, s390_r0, ins->sreg2);
3687 s390_ltgr (code, s390_r0, s390_r0);
3688 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3689 s390_lgr (code, ins->dreg, s390_r1);
3693 g_assert_not_reached ();
3695 s390_algr (code, ins->dreg, src2);
3700 s390_agr (code, ins->dreg, src2);
3704 g_assert_not_reached ();
3706 s390_alcgr (code, ins->dreg, src2);
3710 if (ins->dreg != ins->sreg1) {
3711 s390_lgfr (code, ins->dreg, ins->sreg1);
3713 if (s390_is_imm16 (ins->inst_imm)) {
3714 s390_aghi(code, ins->dreg, ins->inst_imm);
3716 s390_basr (code, s390_r13, 0);
3718 s390_word (code, ins->inst_imm);
3719 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3724 if (ins->dreg != ins->sreg1) {
3725 s390_lgfr (code, ins->dreg, ins->sreg1);
3727 if (s390_is_imm16 (ins->inst_imm)) {
3728 s390_lghi (code, s390_r0, ins->inst_imm);
3729 s390_alcgr (code, ins->dreg, s390_r0);
3731 s390_basr (code, s390_r13, 0);
3733 s390_word (code, ins->inst_imm);
3734 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3735 s390_alcgr (code, ins->dreg, s390_r13);
3740 case OP_S390_LADD_OVF: {
3742 s390_agr (code, ins->dreg, src2);
3743 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3746 case OP_LADD_OVF_UN:
3747 case OP_S390_LADD_OVF_UN: {
3749 s390_algr (code, ins->dreg, src2);
3750 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3754 CHECK_SRCDST_NCOM_I;
3755 s390_slgr (code, ins->dreg, src2);
3759 CHECK_SRCDST_NCOM_I;
3760 s390_sgr (code, ins->dreg, src2);
3764 CHECK_SRCDST_NCOM_I;
3765 s390_slbgr (code, ins->dreg, src2);
3769 if (ins->dreg != ins->sreg1) {
3770 s390_lgfr (code, ins->dreg, ins->sreg1);
3772 if (s390_is_imm16 (-ins->inst_imm)) {
3773 s390_aghi (code, ins->dreg, -ins->inst_imm);
3775 s390_basr (code, s390_r13, 0);
3777 s390_word (code, ins->inst_imm);
3778 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3783 s390_basr (code, s390_r13, 0);
3785 s390_word (code, ins->inst_imm);
3786 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3790 case OP_S390_ISUB_OVF: {
3792 s390_sr (code, ins->dreg, src2);
3793 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3794 s390_lgfr (code, ins->dreg, ins->dreg);
3797 case OP_ISUB_OVF_UN:
3798 case OP_S390_ISUB_OVF_UN: {
3800 s390_slr (code, ins->dreg, src2);
3801 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3802 s390_llgfr(code, ins->dreg, ins->dreg);
3806 case OP_S390_LSUB_OVF: {
3808 s390_sgr (code, ins->dreg, src2);
3809 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3812 case OP_LSUB_OVF_UN:
3813 case OP_S390_LSUB_OVF_UN: {
3815 s390_slgr (code, ins->dreg, src2);
3816 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3820 CHECK_SRCDST_NCOM_I;
3821 s390_ngr (code, ins->dreg, src2);
3825 if (ins->dreg != ins->sreg1) {
3826 s390_lgfr (code, ins->dreg, ins->sreg1);
3828 if (s390_is_imm16 (ins->inst_imm)) {
3829 s390_lghi (code, s390_r0, ins->inst_imm);
3830 s390_ngr (code, ins->dreg, s390_r0);
3832 s390_basr (code, s390_r13, 0);
3834 s390_llong(code, ins->inst_imm);
3835 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3840 s390_lgfr (code, s390_r0, ins->sreg1);
3841 s390_srda (code, s390_r0, 0, 32);
3842 s390_dr (code, s390_r0, ins->sreg2);
3843 s390_lgfr (code, ins->dreg, s390_r1);
3847 s390_lgfr (code, s390_r0, ins->sreg1);
3848 s390_srdl (code, s390_r0, 0, 32);
3849 s390_dlr (code, s390_r0, ins->sreg2);
3850 s390_lgfr (code, ins->dreg, s390_r1);
3854 if (s390_is_imm16 (ins->inst_imm)) {
3855 s390_lghi (code, s390_r13, ins->inst_imm);
3856 s390_lgfr (code, s390_r0, ins->sreg1);
3858 s390_basr (code, s390_r13, 0);
3860 s390_word (code, ins->inst_imm);
3861 s390_lgfr (code, s390_r0, ins->sreg1);
3862 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3864 s390_srda (code, s390_r0, 0, 32);
3865 s390_dr (code, s390_r0, ins->sreg2);
3866 s390_lgfr (code, ins->dreg, s390_r1);
3870 s390_lgfr (code, s390_r0, ins->sreg1);
3871 s390_srda (code, s390_r0, 0, 32);
3872 s390_dr (code, s390_r0, ins->sreg2);
3873 s390_lgfr (code, ins->dreg, s390_r0);
3876 s390_lgfr (code, s390_r0, ins->sreg1);
3877 s390_srdl (code, s390_r0, 0, 32);
3878 s390_dlr (code, s390_r0, ins->sreg2);
3879 s390_lgfr (code, ins->dreg, s390_r0);
3883 if (s390_is_imm16 (ins->inst_imm)) {
3884 s390_lghi (code, s390_r13, ins->inst_imm);
3885 s390_lgfr (code, s390_r0, ins->sreg1);
3887 s390_basr (code, s390_r13, 0);
3889 s390_word (code, ins->inst_imm);
3890 s390_lgfr (code, s390_r0, ins->sreg1);
3891 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3893 s390_srda (code, s390_r0, 0, 32);
3894 s390_dr (code, s390_r0, ins->sreg2);
3895 s390_lgfr (code, ins->dreg, s390_r0);
3900 s390_ogr (code, ins->dreg, src2);
3904 if (ins->dreg != ins->sreg1) {
3905 s390_lgfr (code, ins->dreg, ins->sreg1);
3907 if (s390_is_imm16 (ins->inst_imm)) {
3908 s390_lghi (code, s390_r0, ins->inst_imm);
3909 s390_ogr (code, ins->dreg, s390_r0);
3911 s390_basr (code, s390_r13, 0);
3913 s390_llong(code, ins->inst_imm);
3914 s390_og (code, ins->dreg, 0, s390_r13, 4);
3920 s390_xgr (code, ins->dreg, src2);
3924 if (ins->dreg != ins->sreg1) {
3925 s390_lgfr (code, ins->dreg, ins->sreg1);
3927 if (s390_is_imm16 (ins->inst_imm)) {
3928 s390_lghi (code, s390_r0, ins->inst_imm);
3929 s390_xgr (code, ins->dreg, s390_r0);
3931 s390_basr (code, s390_r13, 0);
3933 s390_llong(code, ins->inst_imm);
3934 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3940 s390_sll (code, ins->dreg, src2, 0);
3944 if (ins->sreg1 != ins->dreg) {
3945 s390_lgfr (code, ins->dreg, ins->sreg1);
3947 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3952 s390_sra (code, ins->dreg, src2, 0);
3956 if (ins->sreg1 != ins->dreg) {
3957 s390_lgfr (code, ins->dreg, ins->sreg1);
3959 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3962 case OP_ISHR_UN_IMM: {
3963 if (ins->sreg1 != ins->dreg) {
3964 s390_lgfr (code, ins->dreg, ins->sreg1);
3966 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3971 s390_srl (code, ins->dreg, src2, 0);
3975 if (ins->sreg1 != ins->dreg) {
3976 s390_lgfr (code, ins->dreg, ins->sreg1);
3978 s390_lghi (code, s390_r0, -1);
3979 s390_xgr (code, ins->dreg, s390_r0);
3983 s390_lcgr (code, ins->dreg, ins->sreg1);
3988 s390_msr (code, ins->dreg, src2);
3992 if (ins->dreg != ins->sreg1) {
3993 s390_lgfr (code, ins->dreg, ins->sreg1);
3995 if (s390_is_imm16 (ins->inst_imm)) {
3996 s390_lghi (code, s390_r13, ins->inst_imm);
3998 s390_basr (code, s390_r13, 0);
4000 s390_word (code, ins->inst_imm);
4001 s390_lgf (code, s390_r13, 0, s390_r13, 4);
4003 s390_msr (code, ins->dreg, s390_r13);
4008 s390_ltr (code, s390_r1, ins->sreg1);
4009 s390_jz (code, 0); CODEPTR(code, o[0]);
4010 s390_ltr (code, s390_r0, ins->sreg2);
4012 s390_lhi (code, s390_r1, 0);
4013 s390_j (code, 0); CODEPTR(code, o[1]);
4014 s390_xr (code, s390_r0, s390_r1);
4015 s390_msr (code, s390_r1, ins->sreg2);
4016 s390_xr (code, s390_r0, s390_r1);
4017 s390_srl (code, s390_r0, 0, 31);
4018 s390_ltr (code, s390_r0, s390_r0);
4019 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4020 PTRSLOT (code, o[0]);
4021 PTRSLOT (code, o[1]);
4022 s390_lgfr (code, ins->dreg, s390_r1);
4025 case OP_IMUL_OVF_UN: {
4026 s390_lhi (code, s390_r0, 0);
4027 s390_lr (code, s390_r1, ins->sreg1);
4028 s390_mlr (code, s390_r0, ins->sreg2);
4029 s390_ltr (code, s390_r0, s390_r0);
4030 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4031 s390_lgfr (code, ins->dreg, s390_r1);
4036 if (s390_is_imm16(ins->inst_c0)) {
4037 s390_lghi (code, ins->dreg, ins->inst_c0);
4039 s390_basr (code, s390_r13, 0);
4041 s390_llong(code, ins->inst_c0);
4042 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4047 s390_basr (code, s390_r13, 0);
4049 mono_add_patch_info (cfg, code - cfg->native_code,
4050 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4051 s390_llong(code, 0);
4052 s390_lg (code,ins->dreg, 0, s390_r13, 4);
4055 case OP_JUMP_TABLE: {
4056 mono_add_patch_info (cfg, code - cfg->native_code,
4057 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4058 s390_basr (code, s390_r13, 0);
4060 s390_llong (code, 0);
4061 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4065 if (ins->dreg != ins->sreg1) {
4066 s390_lgr (code, ins->dreg, ins->sreg1);
4070 case OP_LCONV_TO_I8:
4072 s390_lgfr (code, ins->dreg, ins->sreg1);
4074 case OP_LCONV_TO_I4:
4075 s390_lgfr (code, ins->dreg, ins->sreg1);
4078 case OP_LCONV_TO_U8:
4079 case OP_LCONV_TO_U4:
4081 s390_llgfr (code, ins->dreg, ins->sreg1);
4083 case OP_LCONV_TO_OVF_U4:
4084 s390_basr (code, s390_r13, 0);
4086 s390_llong(code, 4294967295);
4087 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
4088 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4089 s390_ltgr (code, ins->sreg1, ins->sreg1);
4090 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4091 s390_llgfr(code, ins->dreg, ins->sreg1);
4093 case OP_LCONV_TO_OVF_I4_UN:
4094 s390_basr (code, s390_r13, 0);
4096 s390_llong(code, 2147483647);
4097 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
4098 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4099 s390_ltgr (code, ins->sreg1, ins->sreg1);
4100 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4101 s390_lgfr (code, ins->dreg, ins->sreg1);
4104 case OP_FCONV_TO_R4: {
4105 if (ins->dreg != ins->sreg1) {
4106 s390_ldr (code, ins->dreg, ins->sreg1);
4110 case OP_S390_SETF4RET: {
4111 s390_ledbr (code, ins->dreg, ins->sreg1);
4115 if (s390_is_imm16 (ins->inst_offset)) {
4116 s390_lghi (code, s390_r13, ins->inst_offset);
4118 s390_bras (code, s390_r13, 0);
4120 s390_llong(code, ins->inst_offset);
4121 s390_lg (code, s390_r13, 0, s390_r13, 4);
4123 s390_ear (code, s390_r1, 0);
4124 s390_sllg(code, s390_r1, s390_r1, 0, 32);
4125 s390_ear (code, s390_r1, 1);
4126 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
4130 if (cfg->method->save_lmf)
4131 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4133 if (cfg->flags & MONO_CFG_HAS_TAIL) {
4134 code = emit_load_volatile_arguments (code, cfg);
4137 code = backUpStackPtr(cfg, code);
4138 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
4139 mono_add_patch_info (cfg, code - cfg->native_code,
4140 MONO_PATCH_INFO_METHOD_JUMP,
4142 s390_jcl (code, S390_CC_UN, 0);
4145 case OP_CHECK_THIS: {
4146 /* ensure ins->sreg1 is not NULL */
4147 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
4148 s390_ltgr (code, s390_r0, s390_r0);
4152 int offset = cfg->sig_cookie + cfg->stack_usage;
4154 if (s390_is_imm16 (offset))
4155 s390_lghi (code, s390_r0, offset);
4157 s390_basr (code, s390_r13, 0);
4159 s390_llong(code, offset);
4160 s390_lg (code, s390_r0, 0, s390_r13, 0);
4162 s390_agr (code, s390_r0, cfg->frame_reg);
4163 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
4167 s390_basr (code, s390_r13, 0);
4169 call = (MonoCallInst*)ins;
4170 if (ins->flags & MONO_INST_HAS_METHOD)
4171 mono_add_patch_info (cfg, code-cfg->native_code,
4172 MONO_PATCH_INFO_METHOD,
4175 mono_add_patch_info (cfg, code-cfg->native_code,
4176 MONO_PATCH_INFO_ABS,
4178 s390_llong(code, 0);
4179 s390_lg (code, s390_r14, 0, s390_r13, 4);
4180 s390_basr (code, s390_r14, s390_r14);
4181 if (call->signature->ret->type == MONO_TYPE_R4)
4182 s390_ldebr (code, s390_f0, s390_f0);
4190 s390_basr (code, s390_r13, 0);
4192 call = (MonoCallInst*)ins;
4193 if (ins->flags & MONO_INST_HAS_METHOD)
4194 mono_add_patch_info (cfg, code-cfg->native_code,
4195 MONO_PATCH_INFO_METHOD,
4198 mono_add_patch_info (cfg, code-cfg->native_code,
4199 MONO_PATCH_INFO_ABS,
4201 s390_llong(code, 0);
4202 s390_lg (code, s390_r14, 0, s390_r13, 4);
4203 s390_basr (code, s390_r14, s390_r14);
4206 case OP_FCALL_REG: {
4207 call = (MonoCallInst*)ins;
4208 s390_lgr (code, s390_r1, ins->sreg1);
4209 s390_basr (code, s390_r14, s390_r1);
4210 if (call->signature->ret->type == MONO_TYPE_R4)
4211 s390_ldebr (code, s390_f0, s390_f0);
4217 case OP_VOIDCALL_REG:
4219 s390_lgr (code, s390_r1, ins->sreg1);
4220 s390_basr (code, s390_r14, s390_r1);
4223 case OP_FCALL_MEMBASE: {
4224 call = (MonoCallInst*)ins;
4225 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4226 s390_basr (code, s390_r14, s390_r1);
4227 if (call->signature->ret->type == MONO_TYPE_R4)
4228 s390_ldebr (code, s390_f0, s390_f0);
4231 case OP_LCALL_MEMBASE:
4232 case OP_VCALL_MEMBASE:
4233 case OP_VCALL2_MEMBASE:
4234 case OP_VOIDCALL_MEMBASE:
4235 case OP_CALL_MEMBASE: {
4236 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4237 s390_basr (code, s390_r14, s390_r1);
4244 if (cfg->param_area == 0)
4245 alloca_skip = S390_MINIMAL_STACK_SIZE;
4247 alloca_skip = cfg->param_area;
4249 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4250 s390_lgr (code, s390_r1, ins->sreg1);
4251 if (ins->flags & MONO_INST_INIT)
4252 s390_lgr (code, s390_r0, ins->sreg1);
4253 s390_aghi (code, s390_r1, 14);
4254 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4255 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4256 if (cfg->method->save_lmf) {
4257 /*----------------------------------*/
4258 /* we have to adjust lmf ebp value */
4259 /*----------------------------------*/
4260 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4262 s390_lgr (code, s390_r13, cfg->frame_reg);
4263 if (s390_is_imm16(lmfOffset))
4264 s390_aghi (code, s390_r13, lmfOffset);
4266 s390_basr (code, s390_r14, 0);
4268 s390_word (code, lmfOffset);
4269 s390_agf (code, s390_r13, 0, s390_r14, 4);
4271 s390_lgr (code, s390_r14, STK_BASE);
4272 s390_sgr (code, s390_r14, s390_r1);
4273 s390_stg (code, s390_r14, 0, s390_r13,
4274 G_STRUCT_OFFSET(MonoLMF, ebp));
4276 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4277 s390_sgr (code, STK_BASE, s390_r1);
4278 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4279 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4280 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4281 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4282 if (ins->flags & MONO_INST_INIT) {
4283 s390_lgr (code, s390_r1, s390_r0);
4284 s390_lgr (code, s390_r0, ins->dreg);
4285 s390_lgr (code, s390_r14, s390_r12);
4286 s390_lghi (code, s390_r13, 0);
4287 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4289 s390_lgr (code, s390_r12, s390_r14);
4294 s390_lgr (code, s390_r2, ins->sreg1);
4295 s390_basr (code, s390_r13, 0);
4297 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4298 (gpointer) "mono_arch_throw_exception");
4299 s390_llong(code, 0);
4300 s390_lg (code, s390_r14, 0, s390_r13, 4);
4301 s390_basr (code, s390_r14, s390_r14);
4305 s390_lgr (code, s390_r2, ins->sreg1);
4306 s390_basr (code, s390_r13, 0);
4308 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4309 (gpointer) "mono_arch_rethrow_exception");
4310 s390_llong(code, 0);
4311 s390_lg (code, s390_r14, 0, s390_r13, 4);
4312 s390_basr (code, s390_r14, s390_r14);
4315 case OP_START_HANDLER: {
4316 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4318 S390_LONG (code, stg, stg, s390_r14, 0,
4319 spvar->inst_basereg,
4320 spvar->inst_offset);
4323 case OP_ENDFILTER: {
4324 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4326 if (ins->sreg1 != s390_r2)
4327 s390_lgr(code, s390_r2, ins->sreg1);
4328 S390_LONG (code, lg, lg, s390_r14, 0,
4329 spvar->inst_basereg,
4330 spvar->inst_offset);
4331 s390_br (code, s390_r14);
4334 case OP_ENDFINALLY: {
4335 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4337 S390_LONG (code, lg, lg, s390_r14, 0,
4338 spvar->inst_basereg,
4339 spvar->inst_offset);
4340 s390_br (code, s390_r14);
4343 case OP_CALL_HANDLER: {
4344 mono_add_patch_info (cfg, code-cfg->native_code,
4345 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4346 s390_brasl (code, s390_r14, 0);
4347 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4351 ins->inst_c0 = code - cfg->native_code;
4354 case OP_RELAXED_NOP:
4357 case OP_DUMMY_STORE:
4358 case OP_NOT_REACHED:
4362 case OP_SEQ_POINT: {
4365 if (cfg->compile_aot)
4369 * Read from the single stepping trigger page. This will cause a
4370 * SIGSEGV when single stepping is enabled.
4371 * We do this _before_ the breakpoint, so single stepping after
4372 * a breakpoint is hit will step to the next IL offset.
4374 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4375 breakpointCode.pTrigger = ss_trigger_page;
4376 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4377 code += BREAKPOINT_SIZE;
4380 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4383 * A placeholder for a possible breakpoint inserted by
4384 * mono_arch_set_breakpoint ().
4386 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4392 EMIT_UNCOND_BRANCH(ins);
4395 s390_br (code, ins->sreg1);
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);
4425 s390_lghi(code, ins->dreg, 1);
4427 s390_lghi(code, ins->dreg, 0);
4433 s390_lghi(code, ins->dreg, 1);
4435 s390_lghi(code, ins->dreg, 0);
4438 case OP_COND_EXC_EQ:
4439 case OP_COND_EXC_IEQ:
4440 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4442 case OP_COND_EXC_NE_UN:
4443 case OP_COND_EXC_INE_UN:
4444 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4446 case OP_COND_EXC_LT:
4447 case OP_COND_EXC_ILT:
4448 case OP_COND_EXC_LT_UN:
4449 case OP_COND_EXC_ILT_UN:
4450 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4452 case OP_COND_EXC_GT:
4453 case OP_COND_EXC_IGT:
4454 case OP_COND_EXC_GT_UN:
4455 case OP_COND_EXC_IGT_UN:
4456 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4458 case OP_COND_EXC_GE:
4459 case OP_COND_EXC_IGE:
4460 case OP_COND_EXC_GE_UN:
4461 case OP_COND_EXC_IGE_UN:
4462 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4464 case OP_COND_EXC_LE:
4465 case OP_COND_EXC_ILE:
4466 case OP_COND_EXC_LE_UN:
4467 case OP_COND_EXC_ILE_UN:
4468 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4470 case OP_COND_EXC_OV:
4471 case OP_COND_EXC_IOV:
4472 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4474 case OP_COND_EXC_NO:
4475 case OP_COND_EXC_INO:
4476 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4479 case OP_COND_EXC_IC:
4480 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4482 case OP_COND_EXC_NC:
4483 case OP_COND_EXC_INC:
4484 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4488 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4492 EMIT_COND_BRANCH (ins, S390_CC_NE);
4498 EMIT_COND_BRANCH (ins, S390_CC_LT);
4504 EMIT_COND_BRANCH (ins, S390_CC_GT);
4510 EMIT_COND_BRANCH (ins, S390_CC_GE);
4516 EMIT_COND_BRANCH (ins, S390_CC_LE);
4519 /* floating point opcodes */
4521 if (*((double *) ins->inst_p0) == 0) {
4522 s390_lzdr (code, ins->dreg);
4524 s390_basr (code, s390_r13, 0);
4526 s390_llong (code, ins->inst_p0);
4527 s390_lg (code, s390_r13, 0, s390_r13, 4);
4528 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4533 if (*((float *) ins->inst_p0) == 0) {
4534 s390_lzdr (code, ins->dreg);
4536 s390_basr (code, s390_r13, 0);
4538 s390_llong(code, ins->inst_p0);
4539 s390_lg (code, s390_r13, 0, s390_r13, 4);
4540 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4544 case OP_STORER8_MEMBASE_REG: {
4545 S390_LONG (code, stdy, std, ins->sreg1, 0,
4546 ins->inst_destbasereg, ins->inst_offset);
4549 case OP_LOADR8_MEMBASE: {
4550 S390_LONG (code, ldy, ld, ins->dreg, 0,
4551 ins->inst_basereg, ins->inst_offset);
4554 case OP_STORER4_MEMBASE_REG: {
4555 s390_ledbr (code, s390_f15, ins->sreg1);
4556 S390_LONG (code, stey, ste, s390_f15, 0,
4557 ins->inst_destbasereg, ins->inst_offset);
4560 case OP_LOADR4_MEMBASE: {
4561 S390_LONG (code, ldy, ld, s390_f15, 0,
4562 ins->inst_basereg, ins->inst_offset);
4563 s390_ldebr (code, ins->dreg, s390_f15);
4566 case OP_ICONV_TO_R_UN: {
4567 s390_cdfbr (code, ins->dreg, ins->sreg1);
4568 s390_ltr (code, ins->sreg1, ins->sreg1);
4569 s390_jnl (code, 12);
4570 s390_basr (code, s390_r13, 0);
4572 s390_word (code, 0x41f00000);
4573 s390_word (code, 0);
4574 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4577 case OP_LCONV_TO_R_UN: {
4578 s390_cdgbr (code, ins->dreg, ins->sreg1);
4579 s390_ltgr (code, ins->sreg1, ins->sreg1);
4580 s390_jnl (code, 12);
4581 s390_basr (code, s390_r13, 0);
4583 s390_word (code, 0x41f00000);
4584 s390_word (code, 0);
4585 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4588 case OP_LCONV_TO_R4:
4589 case OP_ICONV_TO_R4: {
4590 s390_cdgbr (code, ins->dreg, ins->sreg1);
4593 case OP_LCONV_TO_R8:
4594 case OP_ICONV_TO_R8: {
4595 s390_cdgbr (code, ins->dreg, ins->sreg1);
4598 case OP_FCONV_TO_I1:
4599 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4601 case OP_FCONV_TO_U1:
4602 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4604 case OP_FCONV_TO_I2:
4605 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4607 case OP_FCONV_TO_U2:
4608 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4610 case OP_FCONV_TO_I4:
4612 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4614 case OP_FCONV_TO_U4:
4616 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4618 case OP_FCONV_TO_I8:
4619 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4621 case OP_LCONV_TO_OVF_I: {
4622 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4624 s390_ltgr (code, ins->sreg2, ins->sreg2);
4625 s390_jnl (code, 0); CODEPTR(code, o[0]);
4626 s390_ltgr (code, ins->sreg1, ins->sreg1);
4627 s390_jnl (code, 0); CODEPTR(code, o[1]);
4628 s390_lhi (code, s390_r13, -1);
4629 s390_cgr (code, ins->sreg1, s390_r13);
4630 s390_jnz (code, 0); CODEPTR(code, o[2]);
4631 if (ins->dreg != ins->sreg2)
4632 s390_lgr (code, ins->dreg, ins->sreg2);
4633 s390_j (code, 0); CODEPTR(code, o[3]);
4634 PTRSLOT(code, o[0]);
4635 s390_jz (code, 0); CODEPTR(code, o[4]);
4636 PTRSLOT(code, o[1]);
4637 PTRSLOT(code, o[2]);
4638 mono_add_patch_info (cfg, code - cfg->native_code,
4639 MONO_PATCH_INFO_EXC, "OverflowException");
4640 s390_brasl (code, s390_r14, 0);
4641 PTRSLOT(code, o[3]);
4642 PTRSLOT(code, o[4]);
4646 s390_lpdbr (code, ins->dreg, ins->sreg1);
4650 s390_sqdbr (code, ins->dreg, ins->sreg1);
4655 s390_adbr (code, ins->dreg, src2);
4659 CHECK_SRCDST_NCOM_F;
4660 s390_sdbr (code, ins->dreg, src2);
4665 s390_mdbr (code, ins->dreg, src2);
4669 CHECK_SRCDST_NCOM_F;
4670 s390_ddbr (code, ins->dreg, src2);
4674 s390_lcdbr (code, ins->dreg, ins->sreg1);
4678 CHECK_SRCDST_NCOM_F;
4679 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4683 s390_cdbr (code, ins->sreg1, ins->sreg2);
4687 s390_cdbr (code, ins->sreg1, ins->sreg2);
4688 s390_lghi (code, ins->dreg, 1);
4690 s390_lghi (code, ins->dreg, 0);
4694 s390_cdbr (code, ins->sreg1, ins->sreg2);
4695 s390_lghi (code, ins->dreg, 1);
4697 s390_lghi (code, ins->dreg, 0);
4701 s390_cdbr (code, ins->sreg1, ins->sreg2);
4702 s390_lghi (code, ins->dreg, 1);
4704 s390_lghi (code, ins->dreg, 0);
4708 s390_cdbr (code, ins->sreg1, ins->sreg2);
4709 s390_lghi (code, ins->dreg, 1);
4711 s390_lghi (code, ins->dreg, 0);
4715 s390_cdbr (code, ins->sreg1, ins->sreg2);
4716 s390_lghi (code, ins->dreg, 1);
4718 s390_lghi (code, ins->dreg, 0);
4723 s390_jo (code, 0); CODEPTR(code, o);
4724 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4729 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4733 s390_jo (code, 0); CODEPTR(code, o);
4734 EMIT_COND_BRANCH (ins, S390_CC_LT);
4739 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4743 s390_jo (code, 0); CODEPTR(code, o);
4744 EMIT_COND_BRANCH (ins, S390_CC_GT);
4749 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4753 s390_jo (code, 0); CODEPTR(code, o);
4754 EMIT_COND_BRANCH (ins, S390_CC_GE);
4759 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4763 s390_jo (code, 0); CODEPTR(code, o);
4764 EMIT_COND_BRANCH (ins, S390_CC_LE);
4769 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4773 s390_lhi (code, s390_r13, 0x7f);
4774 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4775 s390_jz (code, 0); CODEPTR(code, o);
4776 mono_add_patch_info (cfg, code - cfg->native_code,
4777 MONO_PATCH_INFO_EXC, "ArithmeticException");
4778 s390_brasl (code, s390_r14,0);
4782 case OP_S390_MOVE: {
4783 if (ins->backend.size > 0) {
4784 if (ins->backend.size <= 256) {
4785 s390_mvc (code, ins->backend.size, ins->dreg,
4786 ins->inst_offset, ins->sreg1, ins->inst_imm);
4788 s390_lgr (code, s390_r0, ins->dreg);
4789 if (ins->inst_offset > 0) {
4790 if (s390_is_imm16 (ins->inst_offset)) {
4791 s390_aghi (code, s390_r0, ins->inst_offset);
4793 s390_basr (code, s390_r13, 0);
4795 s390_llong(code, ins->inst_offset);
4796 s390_ag (code, s390_r0, 0, s390_r13, 4);
4799 s390_lgr (code, s390_r12, ins->sreg1);
4800 if (ins->inst_imm > 0) {
4801 if (s390_is_imm16 (ins->inst_imm)) {
4802 s390_aghi (code, s390_r12, ins->inst_imm);
4804 s390_basr (code, s390_r13, 0);
4806 s390_llong(code, ins->inst_imm);
4807 s390_ag (code, s390_r12, 0, s390_r13, 4);
4810 if (s390_is_imm16 (ins->backend.size)) {
4811 s390_lghi (code, s390_r1, ins->backend.size);
4813 s390_basr (code, s390_r13, 0);
4815 s390_llong(code, ins->backend.size);
4816 s390_lg (code, s390_r1, 0, s390_r13, 4);
4818 s390_lgr (code, s390_r13, s390_r1);
4819 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4825 case OP_ATOMIC_ADD_I8: {
4826 s390_lgr (code, s390_r1, ins->sreg2);
4827 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4828 s390_agr (code, s390_r1, s390_r0);
4829 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4830 s390_jnz (code, -10);
4831 s390_lgr (code, ins->dreg, s390_r1);
4834 case OP_ATOMIC_ADD_NEW_I8: {
4835 s390_lgr (code, s390_r1, ins->sreg2);
4836 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4837 s390_agr (code, s390_r1, s390_r0);
4838 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4839 s390_jnz (code, -10);
4840 s390_lgr (code, ins->dreg, s390_r1);
4843 case OP_ATOMIC_EXCHANGE_I8: {
4844 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4845 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4846 s390_jnz (code, -6);
4847 s390_lgr (code, ins->dreg, s390_r0);
4850 case OP_ATOMIC_ADD_I4: {
4851 s390_lgfr(code, s390_r1, ins->sreg2);
4852 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4853 s390_agr (code, s390_r1, s390_r0);
4854 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4855 s390_jnz (code, -9);
4856 s390_lgfr(code, ins->dreg, s390_r1);
4859 case OP_ATOMIC_ADD_NEW_I4: {
4860 s390_lgfr(code, s390_r1, ins->sreg2);
4861 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4862 s390_agr (code, s390_r1, s390_r0);
4863 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4864 s390_jnz (code, -9);
4865 s390_lgfr(code, ins->dreg, s390_r1);
4868 case OP_ATOMIC_EXCHANGE_I4: {
4869 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4870 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4871 s390_jnz (code, -4);
4872 s390_lgfr(code, ins->dreg, s390_r0);
4875 case OP_S390_BKCHAIN: {
4876 s390_lgr (code, ins->dreg, ins->sreg1);
4877 if (s390_is_imm16 (cfg->stack_offset)) {
4878 s390_aghi (code, ins->dreg, cfg->stack_offset);
4880 s390_basr (code, s390_r13, 0);
4882 s390_llong(code, cfg->stack_offset);
4883 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4887 case OP_MEMORY_BARRIER: {
4890 case OP_GC_LIVENESS_DEF:
4891 case OP_GC_LIVENESS_USE:
4892 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4893 ins->backend.pc_offset = code - cfg->native_code;
4895 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4896 ins->backend.pc_offset = code - cfg->native_code;
4897 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4900 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4901 g_assert_not_reached ();
4904 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4905 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4906 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4907 g_assert_not_reached ();
4912 last_offset = offset;
4915 cfg->code_len = code - cfg->native_code;
4918 /*========================= End of Function ========================*/
4920 /*------------------------------------------------------------------*/
4922 /* Name - mono_arch_register_lowlevel_calls */
4924 /* Function - Register routines to help with --trace operation. */
4926 /*------------------------------------------------------------------*/
4929 mono_arch_register_lowlevel_calls (void)
4933 /*========================= End of Function ========================*/
4935 /*------------------------------------------------------------------*/
4937 /* Name - mono_arch_patch_code */
4939 /* Function - Process the patch data created during the */
4940 /* instruction build process. This resolves jumps, */
4941 /* calls, variables etc. */
4943 /*------------------------------------------------------------------*/
4946 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4947 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4949 MonoJumpInfo *patch_info;
4951 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4952 unsigned char *ip = patch_info->ip.i + code;
4953 gconstpointer target = NULL;
4955 target = mono_resolve_patch_target (method, domain, code,
4956 patch_info, run_cctors);
4958 switch (patch_info->type) {
4959 case MONO_PATCH_INFO_IP:
4960 case MONO_PATCH_INFO_EXC_NAME:
4961 case MONO_PATCH_INFO_LDSTR:
4962 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4963 case MONO_PATCH_INFO_LDTOKEN:
4964 case MONO_PATCH_INFO_EXC:
4965 case MONO_PATCH_INFO_ABS:
4966 case MONO_PATCH_INFO_METHOD:
4967 case MONO_PATCH_INFO_INTERNAL_METHOD:
4968 case MONO_PATCH_INFO_CLASS_INIT:
4969 s390_patch_addr (ip, (guint64) target);
4971 case MONO_PATCH_INFO_SWITCH:
4972 /*----------------------------------*/
4973 /* ip points at the basr r13,0/j +4 */
4974 /* instruction the vtable value */
4975 /* follows this (i.e. ip+6) */
4976 /*----------------------------------*/
4977 *((gconstpointer *)(ip+6)) = target;
4979 case MONO_PATCH_INFO_METHODCONST:
4980 case MONO_PATCH_INFO_CLASS:
4981 case MONO_PATCH_INFO_IMAGE:
4982 case MONO_PATCH_INFO_FIELD:
4983 case MONO_PATCH_INFO_IID:
4984 target = S390_RELATIVE(target, ip);
4985 s390_patch_rel (ip, (guint64) target);
4987 case MONO_PATCH_INFO_R4:
4988 case MONO_PATCH_INFO_R8:
4989 case MONO_PATCH_INFO_METHOD_REL:
4990 g_assert_not_reached ();
4993 target = S390_RELATIVE(target, ip);
4995 s390_patch_rel (ip, (guint64) target);
5000 /*========================= End of Function ========================*/
5002 /*------------------------------------------------------------------*/
5004 /* Name - emit_load_volatile_arguments */
5006 /* Function - Emit the instructions to reload parameter regist- */
5007 /* registers for use with "tail" operations. */
5009 /* The register loading operations performed here */
5010 /* are the mirror of the store operations performed */
5011 /* in mono_arch_emit_prolog and need to be kept in */
5012 /* synchronization with it. */
5014 /*------------------------------------------------------------------*/
5017 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
5020 MonoMethod *method = cfg->method;
5021 MonoMethodSignature *sig = mono_method_signature(method);
5025 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
5027 if (cinfo->struct_ret) {
5028 ArgInfo *ainfo = &cinfo->ret;
5029 inst = cfg->vret_addr;
5030 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5033 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5034 ArgInfo *ainfo = cinfo->args + i;
5035 inst = cfg->args [pos];
5037 if (inst->opcode == OP_REGVAR) {
5038 if (ainfo->regtype == RegTypeGeneral)
5039 s390_lgr (code, ainfo->reg, inst->dreg);
5040 else if (ainfo->regtype == RegTypeFP) {
5041 if (inst->dreg != ainfo->reg) {
5042 if (ainfo->size == 4) {
5043 s390_ldebr (code, ainfo->reg, inst->dreg);
5045 s390_ldr (code, ainfo->reg, inst->dreg);
5049 else if (ainfo->regtype == RegTypeBase) {
5051 g_assert_not_reached ();
5053 if (ainfo->regtype == RegTypeGeneral) {
5054 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5055 g_assert_not_reached();
5056 switch (ainfo->size) {
5058 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5061 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5064 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5067 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5070 } else if (ainfo->regtype == RegTypeBase) {
5071 } else if (ainfo->regtype == RegTypeFP) {
5072 if (ainfo->size == 8)
5073 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5074 else if (ainfo->size == 4)
5075 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5077 g_assert_not_reached ();
5078 } else if (ainfo->regtype == RegTypeStructByVal) {
5079 if (ainfo->reg != STK_BASE) {
5080 switch (ainfo->size) {
5082 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5085 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5088 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5091 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5095 } else if (ainfo->regtype == RegTypeStructByAddr) {
5096 if (ainfo->reg != STK_BASE) {
5097 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5100 g_assert_not_reached ();
5108 /*========================= End of Function ========================*/
5110 /*------------------------------------------------------------------*/
5112 /* Name - mono_arch_emit_prolog */
5114 /* Function - Create the instruction sequence for a function */
5117 /*------------------------------------------------------------------*/
5120 mono_arch_emit_prolog (MonoCompile *cfg)
5122 MonoMethod *method = cfg->method;
5124 MonoMethodSignature *sig;
5126 long alloc_size, pos, max_offset, i, cfa_offset = 0;
5133 cfg->code_size = 512;
5135 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5137 cfg->code_size += 256;
5140 if (method->save_lmf)
5141 cfg->code_size += 200;
5143 cfg->native_code = code = g_malloc (cfg->code_size);
5145 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
5146 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
5147 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5148 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
5150 if (cfg->arch.bkchain_reg != -1)
5151 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
5153 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5154 cfg->used_int_regs |= 1 << 11;
5157 alloc_size = cfg->stack_offset;
5159 cfg->stack_usage = cfa_offset = alloc_size;
5160 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
5161 s390_lgr (code, s390_r11, STK_BASE);
5162 if (s390_is_imm16 (alloc_size)) {
5163 s390_aghi (code, STK_BASE, -alloc_size);
5165 int stackSize = alloc_size;
5166 while (stackSize > 32767) {
5167 s390_aghi (code, STK_BASE, -32767);
5170 s390_aghi (code, STK_BASE, -stackSize);
5172 s390_stg (code, s390_r11, 0, STK_BASE, 0);
5174 if (cfg->frame_reg != STK_BASE)
5175 s390_lgr (code, s390_r11, STK_BASE);
5177 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
5179 /* compute max_offset in order to use short forward jumps
5180 * we always do it on s390 because the immediate displacement
5181 * for jumps is too small
5184 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5186 bb->max_offset = max_offset;
5188 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5191 MONO_BB_FOR_EACH_INS (bb, ins)
5192 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5195 /* load arguments allocated to register from the stack */
5196 sig = mono_method_signature (method);
5199 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
5201 if (cinfo->struct_ret) {
5202 ArgInfo *ainfo = &cinfo->ret;
5203 inst = cfg->vret_addr;
5204 inst->backend.size = ainfo->vtsize;
5205 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5208 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5209 ArgInfo *ainfo = cinfo->args + i;
5210 inst = cfg->args [pos];
5212 if (inst->opcode == OP_VTARG_ADDR)
5213 inst = inst->inst_left;
5215 if (inst->opcode == OP_REGVAR) {
5216 if (ainfo->regtype == RegTypeGeneral)
5217 s390_lgr (code, inst->dreg, ainfo->reg);
5218 else if (ainfo->regtype == RegTypeFP) {
5219 if (inst->dreg != ainfo->reg) {
5220 if (ainfo->size == 4) {
5221 s390_ledbr (code, inst->dreg, ainfo->reg);
5223 s390_ldr (code, inst->dreg, ainfo->reg);
5227 else if (ainfo->regtype == RegTypeBase) {
5228 s390_lgr (code, s390_r13, STK_BASE);
5229 s390_aghi (code, s390_r13, alloc_size);
5230 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5232 g_assert_not_reached ();
5234 if (cfg->verbose_level > 2)
5235 g_print ("Argument %d assigned to register %s\n",
5236 pos, mono_arch_regname (inst->dreg));
5238 if (ainfo->regtype == RegTypeGeneral) {
5239 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5240 g_assert_not_reached();
5241 switch (ainfo->size) {
5243 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5246 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5249 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5252 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5255 } else if (ainfo->regtype == RegTypeBase) {
5256 } else if (ainfo->regtype == RegTypeFP) {
5257 if (ainfo->size == 8)
5258 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5259 else if (ainfo->size == 4)
5260 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5262 g_assert_not_reached ();
5263 } else if (ainfo->regtype == RegTypeStructByVal) {
5264 int doffset = inst->inst_offset;
5266 if (ainfo->reg != STK_BASE)
5270 s390_lgr (code, s390_r13, STK_BASE);
5271 s390_aghi (code, s390_r13, alloc_size);
5274 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5275 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5280 if (ainfo->reg == STK_BASE)
5281 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5282 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5285 if (ainfo->reg == STK_BASE)
5286 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5287 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5290 if (ainfo->reg == STK_BASE)
5291 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5292 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5295 if (ainfo->reg == STK_BASE)
5296 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5297 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5300 } else if (ainfo->regtype == RegTypeStructByAddr) {
5301 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5302 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5304 g_assert_not_reached ();
5309 if (method->save_lmf) {
5310 /*---------------------------------------------------------------*/
5311 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5312 /*---------------------------------------------------------------*/
5313 lmfOffset = alloc_size - sizeof(MonoLMF);
5315 s390_lgr (code, s390_r13, cfg->frame_reg);
5316 s390_aghi (code, s390_r13, lmfOffset);
5318 /*---------------------------------------------------------------*/
5319 /* Preserve the parameter registers while we fix up the lmf */
5320 /*---------------------------------------------------------------*/
5321 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5322 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5324 /*---------------------------------------------------------------*/
5325 /* On return from this call r2 have the address of the &lmf */
5326 /*---------------------------------------------------------------*/
5327 if (lmf_addr_tls_offset == -1) {
5328 s390_basr(code, s390_r14, 0);
5330 mono_add_patch_info (cfg, code - cfg->native_code,
5331 MONO_PATCH_INFO_INTERNAL_METHOD,
5332 (gpointer)"mono_get_lmf_addr");
5333 s390_llong(code, 0);
5334 s390_lg (code, s390_r1, 0, s390_r14, 4);
5335 s390_basr (code, s390_r14, s390_r1);
5337 /*-------------------------------------------------------*/
5338 /* Get LMF by getting value from thread level storage */
5339 /*-------------------------------------------------------*/
5340 s390_ear (code, s390_r1, 0);
5341 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5342 s390_ear (code, s390_r1, 1);
5343 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5346 /*---------------------------------------------------------------*/
5347 /* Set lmf.lmf_addr = jit_tls->lmf */
5348 /*---------------------------------------------------------------*/
5349 s390_stg (code, s390_r2, 0, s390_r13,
5350 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5352 /*---------------------------------------------------------------*/
5353 /* Get current lmf */
5354 /*---------------------------------------------------------------*/
5355 s390_lg (code, s390_r0, 0, s390_r2, 0);
5357 /*---------------------------------------------------------------*/
5358 /* Set our lmf as the current lmf */
5359 /*---------------------------------------------------------------*/
5360 s390_stg (code, s390_r13, 0, s390_r2, 0);
5362 /*---------------------------------------------------------------*/
5363 /* Have our lmf.previous_lmf point to the last lmf */
5364 /*---------------------------------------------------------------*/
5365 s390_stg (code, s390_r0, 0, s390_r13,
5366 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5368 /*---------------------------------------------------------------*/
5369 /* save method info */
5370 /*---------------------------------------------------------------*/
5371 s390_basr (code, s390_r1, 0);
5373 s390_llong (code, method);
5374 s390_lg (code, s390_r1, 0, s390_r1, 4);
5375 s390_stg (code, s390_r1, 0, s390_r13,
5376 G_STRUCT_OFFSET(MonoLMF, method));
5378 /*---------------------------------------------------------------*/
5379 /* save the current IP */
5380 /*---------------------------------------------------------------*/
5381 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5382 s390_basr (code, s390_r1, 0);
5383 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5385 /*---------------------------------------------------------------*/
5386 /* Save general and floating point registers */
5387 /*---------------------------------------------------------------*/
5388 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5389 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5390 for (i = 0; i < 16; i++) {
5391 s390_std (code, i, 0, s390_r13,
5392 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5395 /*---------------------------------------------------------------*/
5396 /* Restore the parameter registers now that we've set up the lmf */
5397 /*---------------------------------------------------------------*/
5398 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5399 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5403 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5405 cfg->code_len = code - cfg->native_code;
5406 g_assert (cfg->code_len < cfg->code_size);
5411 /*========================= End of Function ========================*/
5413 /*------------------------------------------------------------------*/
5415 /* Name - mono_arch_emit_epilog */
5417 /* Function - Emit the instructions for a function epilog. */
5419 /*------------------------------------------------------------------*/
5422 mono_arch_emit_epilog (MonoCompile *cfg)
5424 MonoMethod *method = cfg->method;
5427 int max_epilog_size = 96;
5429 if (cfg->method->save_lmf)
5430 max_epilog_size += 128;
5432 if (mono_jit_trace_calls != NULL)
5433 max_epilog_size += 128;
5435 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5436 max_epilog_size += 128;
5438 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5439 cfg->code_size *= 2;
5440 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5441 cfg->stat_code_reallocs++;
5444 code = cfg->native_code + cfg->code_len;
5446 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5447 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5451 if (method->save_lmf)
5452 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5454 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5455 // if (cfg->frame_reg != STK_BASE)
5456 // s390_lgr (code, STK_BASE, cfg->frame_reg);
5457 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5459 code = backUpStackPtr(cfg, code);
5461 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5462 s390_br (code, s390_r14);
5464 cfg->code_len = code - cfg->native_code;
5466 g_assert (cfg->code_len < cfg->code_size);
5470 /*========================= End of Function ========================*/
5472 /*------------------------------------------------------------------*/
5474 /* Name - mono_arch_emit_exceptions */
5476 /* Function - Emit the blocks to handle exception conditions. */
5478 /*------------------------------------------------------------------*/
5481 mono_arch_emit_exceptions (MonoCompile *cfg)
5483 MonoJumpInfo *patch_info;
5489 MonoClass *exc_classes [MAX_EXC];
5490 guint8 *exc_throw_start [MAX_EXC];
5492 for (patch_info = cfg->patch_info;
5494 patch_info = patch_info->next) {
5495 if (patch_info->type == MONO_PATCH_INFO_EXC)
5499 code_size = exc_count * 48;
5501 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5502 cfg->code_size *= 2;
5503 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5504 cfg->stat_code_reallocs++;
5507 code = cfg->native_code + cfg->code_len;
5509 /*---------------------------------------------------------------------*/
5510 /* Add code to raise exceptions */
5511 /*---------------------------------------------------------------------*/
5512 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5513 switch (patch_info->type) {
5514 case MONO_PATCH_INFO_EXC: {
5515 guint8 *ip = patch_info->ip.i + cfg->native_code;
5516 MonoClass *exc_class;
5519 /*-----------------------------------------------------*/
5520 /* Patch the branch in epilog to come here */
5521 /*-----------------------------------------------------*/
5522 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5524 exc_class = mono_class_from_name (mono_defaults.corlib,
5526 patch_info->data.name);
5527 g_assert (exc_class);
5528 throw_ip = patch_info->ip.i;
5530 for (iExc = 0; iExc < nThrows; ++iExc)
5531 if (exc_classes [iExc] == exc_class)
5534 if (iExc < nThrows) {
5535 s390_jcl (code, S390_CC_UN,
5536 (guint64) exc_throw_start [iExc]);
5537 patch_info->type = MONO_PATCH_INFO_NONE;
5540 if (nThrows < MAX_EXC) {
5541 exc_classes [nThrows] = exc_class;
5542 exc_throw_start [nThrows] = code;
5545 /*---------------------------------------------*/
5546 /* Patch the parameter passed to the handler */
5547 /*---------------------------------------------*/
5548 s390_basr (code, s390_r13, 0);
5550 // s390_llong(code, patch_info->data.target);
5551 s390_llong(code, exc_class->type_token);
5552 /*---------------------------------------------*/
5553 /* Load return address & parameter register */
5554 /*---------------------------------------------*/
5555 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5556 cfg->native_code + 8), code));
5557 s390_lg (code, s390_r2, 0, s390_r13, 4);
5558 /*---------------------------------------------*/
5559 /* Reuse the current patch to set the jump */
5560 /*---------------------------------------------*/
5561 s390_basr (code, s390_r13, 0);
5563 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5564 patch_info->data.name = "mono_arch_throw_corlib_exception";
5565 patch_info->ip.i = code - cfg->native_code;
5566 s390_llong(code, 0);
5567 s390_lg (code, s390_r1, 0, s390_r13, 4);
5568 s390_br (code, s390_r1);
5578 cfg->code_len = code - cfg->native_code;
5580 g_assert (cfg->code_len < cfg->code_size);
5584 /*========================= End of Function ========================*/
5586 /*------------------------------------------------------------------*/
5588 /* Name - mono_arch_finish_init */
5590 /* Function - Setup the JIT's Thread Level Specific Data. */
5592 /*------------------------------------------------------------------*/
5595 mono_arch_finish_init (void)
5597 appdomain_tls_offset = mono_domain_get_tls_offset();
5598 lmf_tls_offset = mono_get_lmf_tls_offset();
5599 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5602 /*========================= End of Function ========================*/
5604 /*------------------------------------------------------------------*/
5606 /* Name - mono_arch_free_jit_tls_data */
5608 /* Function - Free tls data. */
5610 /*------------------------------------------------------------------*/
5613 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5617 /*========================= End of Function ========================*/
5619 /*------------------------------------------------------------------*/
5621 /* Name - mono_arch_emit_inst_for_method */
5623 /*------------------------------------------------------------------*/
5626 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5631 /*========================= End of Function ========================*/
5633 /*------------------------------------------------------------------*/
5635 /* Name - mono_arch_decompose_opts */
5637 /* Function - Decompose opcode into a System z opcode. */
5639 /*------------------------------------------------------------------*/
5642 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5645 * Have to rename these to avoid being decomposed normally, since the normal
5646 * decomposition does not work on S390.
5648 switch (ins->opcode) {
5650 ins->opcode = OP_S390_ISUB_OVF;
5652 case OP_ISUB_OVF_UN:
5653 ins->opcode = OP_S390_ISUB_OVF_UN;
5656 ins->opcode = OP_S390_IADD_OVF;
5658 case OP_IADD_OVF_UN:
5659 ins->opcode = OP_S390_IADD_OVF_UN;
5662 ins->opcode = OP_S390_LADD_OVF;
5664 case OP_LADD_OVF_UN:
5665 ins->opcode = OP_S390_LADD_OVF_UN;
5668 ins->opcode = OP_S390_LSUB_OVF;
5670 case OP_LSUB_OVF_UN:
5671 ins->opcode = OP_S390_LSUB_OVF_UN;
5678 /*========================= End of Function ========================*/
5680 /*------------------------------------------------------------------*/
5682 /* Name - mono_arch_print_tree */
5684 /* Function - Print platform-specific opcode details. */
5686 /* Returns - 1 - opcode details have been printed */
5687 /* 0 - opcode details have not been printed */
5689 /*------------------------------------------------------------------*/
5692 mono_arch_print_tree (MonoInst *tree, int arity)
5696 switch (tree->opcode) {
5697 case OP_S390_LOADARG:
5698 case OP_S390_ARGREG:
5699 case OP_S390_ARGPTR:
5700 printf ("[0x%lx(%s)]", tree->inst_offset,
5701 mono_arch_regname (tree->inst_basereg));
5704 case OP_S390_STKARG:
5705 printf ("[0x%lx(previous_frame)]",
5710 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5711 tree->inst_offset, tree->backend.size,
5712 mono_arch_regname(tree->dreg),
5714 mono_arch_regname(tree->sreg1));
5717 case OP_S390_SETF4RET:
5718 printf ("[f%s,f%s]",
5719 mono_arch_regname (tree->dreg),
5720 mono_arch_regname (tree->sreg1));
5724 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5726 mono_arch_regname (tree->sreg1));
5729 case OP_S390_BKCHAIN:
5730 printf ("[previous_frame(%s)]",
5731 mono_arch_regname (tree->sreg1));
5739 /*========================= End of Function ========================*/
5741 /*------------------------------------------------------------------*/
5743 /* Name - mono_arch_regalloc_cost */
5745 /* Function - Determine the cost, in the number of memory */
5746 /* references, of the action of allocating the var- */
5747 /* iable VMV into a register during global register */
5750 /* Returns - Cost */
5752 /*------------------------------------------------------------------*/
5755 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5761 /*========================= End of Function ========================*/
5763 /*------------------------------------------------------------------*/
5765 /* Name - mono_arch_get_domain_intrinsic */
5771 /*------------------------------------------------------------------*/
5774 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5778 if (appdomain_tls_offset == -1)
5781 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5782 ins->inst_offset = appdomain_tls_offset;
5786 /*========================= End of Function ========================*/
5788 /*------------------------------------------------------------------*/
5790 /* Name - mono_arch_flush_register_windows */
5796 /*------------------------------------------------------------------*/
5799 mono_arch_flush_register_windows (void)
5803 /*========================= End of Function ========================*/
5805 /*------------------------------------------------------------------*/
5807 /* Name - mono_arch_is_inst_imm */
5809 /* Function - Determine if operand qualifies as an immediate */
5810 /* value. For s390 this is a value -32768-32768 */
5812 /* Returns - True|False - is [not] immediate value. */
5814 /*------------------------------------------------------------------*/
5817 mono_arch_is_inst_imm (gint64 imm)
5819 return s390_is_imm16 (imm);
5822 /*========================= End of Function ========================*/
5824 /*------------------------------------------------------------------*/
5826 /* Name - mono_arch_get_patch_offset */
5828 /* Function - Dummy entry point until s390x supports aot. */
5830 /* Returns - Offset for patch. */
5832 /*------------------------------------------------------------------*/
5835 mono_arch_get_patch_offset (guint8 *code)
5840 /*========================= End of Function ========================*/
5842 /*------------------------------------------------------------------*/
5844 /* Name - mono_arch_context_get_int_reg. */
5848 /* Returns - Return a register from the context. */
5850 /*------------------------------------------------------------------*/
5853 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5855 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5858 /*========================= End of Function ========================*/
5860 /*------------------------------------------------------------------*/
5862 /* Name - mono_arch_context_set_int_reg. */
5864 /* Function - Set a value in a specified register. */
5866 /*------------------------------------------------------------------*/
5869 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5871 ctx->uc_mcontext.gregs[reg] = val;
5874 /*========================= End of Function ========================*/
5876 /*------------------------------------------------------------------*/
5878 /* Name - mono_arch_get_this_arg_from_call. */
5882 /*------------------------------------------------------------------*/
5885 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5887 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5889 return (gpointer) lmf->gregs [s390_r2];
5892 /*========================= End of Function ========================*/
5894 /*------------------------------------------------------------------*/
5896 /* Name - get_delegate_invoke_impl. */
5900 /*------------------------------------------------------------------*/
5903 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5905 guint8 *code, *start;
5910 start = code = mono_global_codeman_reserve (size);
5912 /* Replace the this argument with the target */
5913 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5914 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5915 s390_br (code, s390_r1);
5916 g_assert ((code - start) <= size);
5918 mono_arch_flush_icache (start, size);
5922 size = 32 + param_count * 8;
5923 start = code = mono_global_codeman_reserve (size);
5925 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5926 /* slide down the arguments */
5927 for (i = 0; i < param_count; ++i) {
5928 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5930 s390_br (code, s390_r1);
5932 g_assert ((code - start) <= size);
5934 mono_arch_flush_icache (start, size);
5938 *code_len = code - start;
5943 /*========================= End of Function ========================*/
5945 /*------------------------------------------------------------------*/
5947 /* Name - mono_arch_get_delegate_invoke_impls. */
5951 /*------------------------------------------------------------------*/
5954 mono_arch_get_delegate_invoke_impls (void)
5961 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5962 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
5964 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5965 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5966 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
5972 /*========================= End of Function ========================*/
5974 /*------------------------------------------------------------------*/
5976 /* Name - mono_arch_get_delegate_invoke_impl. */
5980 /*------------------------------------------------------------------*/
5983 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5985 guint8 *code, *start;
5987 /* FIXME: Support more cases */
5988 if (MONO_TYPE_ISSTRUCT (sig->ret))
5992 static guint8* cached = NULL;
5998 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
6000 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
6002 mono_memory_barrier ();
6006 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
6009 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
6011 for (i = 0; i < sig->param_count; ++i)
6012 if (!mono_is_regsize_var (sig->params [i]))
6016 code = cache [sig->param_count];
6020 if (mono_aot_only) {
6021 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
6022 start = mono_aot_get_trampoline (name);
6025 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
6028 mono_memory_barrier ();
6030 cache [sig->param_count] = start;
6035 /*========================= End of Function ========================*/
6037 /*------------------------------------------------------------------*/
6039 /* Name - mono_arch_build_imt_thunk. */
6043 /*------------------------------------------------------------------*/
6046 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
6047 MonoIMTCheckItem **imt_entries, int count,
6048 gpointer fail_tramp)
6052 guchar *code, *start;
6054 for (i = 0; i < count; ++i) {
6055 MonoIMTCheckItem *item = imt_entries [i];
6056 if (item->is_equals) {
6057 if (item->check_target_idx) {
6058 if (!item->compare_done)
6059 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6060 if (item->has_target_code)
6061 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
6063 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
6067 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
6069 if (!item->has_target_code)
6070 item->chunk_size += LOAD_SIZE;
6072 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
6073 #if ENABLE_WRONG_METHOD_CHECK
6074 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6079 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6080 imt_entries [item->check_target_idx]->compare_done = TRUE;
6082 size += item->chunk_size;
6086 code = mono_method_alloc_generic_virtual_thunk (domain, size);
6088 code = mono_domain_code_reserve (domain, size);
6092 for (i = 0; i < count; ++i) {
6093 MonoIMTCheckItem *item = imt_entries [i];
6094 item->code_target = (guint8 *) code;
6095 if (item->is_equals) {
6096 if (item->check_target_idx) {
6097 if (!item->compare_done) {
6098 s390_basr (code, s390_r13, s390_r0);
6100 s390_llong(code, item->key);
6101 s390_lg (code, s390_r0, 0, s390_r13, 4);
6102 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6104 item->jmp_code = (guint8*) code;
6105 s390_jcl (code, S390_CC_NE, 0);
6107 s390_basr (code, s390_r13, s390_r0);
6109 if (item->has_target_code) {
6110 s390_llong(code, item->value.target_code);
6111 s390_lg (code, s390_r1, 0, s390_r13, 4);
6113 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6114 s390_lg (code, s390_r1, 0, s390_r13, 4);
6115 s390_lg (code, s390_r1, 0, s390_r1, 0);
6117 s390_br (code, s390_r1);
6122 s390_basr (code, s390_r13, s390_r0);
6124 s390_llong(code, item->key);
6125 s390_lg (code, s390_r0, 0, s390_r13, 4);
6126 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6127 item->jmp_code = (guint8*) code;
6128 s390_jcl (code, S390_CC_NE, 0);
6129 s390_basr (code, s390_r13, s390_r0);
6131 if (item->has_target_code) {
6132 s390_llong(code, item->value.target_code);
6133 s390_lg (code, s390_r1, 0, s390_r13, 4);
6136 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6137 s390_lg (code, s390_r1, 0, s390_r13, 4);
6138 s390_lg (code, s390_r1, 0, s390_r1, 0);
6140 s390_br (code, s390_r1);
6141 target = S390_RELATIVE(code, item->jmp_code);
6142 s390_patch_rel(item->jmp_code+2, target);
6143 s390_basr (code, s390_r13, s390_r0);
6145 s390_llong(code, fail_tramp);
6146 s390_lg (code, s390_r1, 0, s390_r13, 4);
6147 s390_br (code, s390_r1);
6148 item->jmp_code = NULL;
6150 /* enable the commented code to assert on wrong method */
6151 #if ENABLE_WRONG_METHOD_CHECK
6152 g_assert_not_reached ();
6154 s390_basr (code, s390_r13, s390_r0);
6156 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6157 s390_lg (code, s390_r1, 0, s390_r13, 4);
6158 s390_lg (code, s390_r1, 0, s390_r1, 0);
6159 s390_br (code, s390_r1);
6160 #if ENABLE_WRONG_METHOD_CHECK
6161 g_assert_not_reached ();
6166 s390_basr (code, s390_r13, s390_r0);
6168 s390_llong(code, item->key);
6169 s390_lg (code, s390_r0, 0, s390_r13, 4);
6170 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6171 item->jmp_code = (guint8 *) code;
6172 s390_jcl (code, S390_CC_GE, 0);
6175 /* patch the branches to get to the target items */
6176 for (i = 0; i < count; ++i) {
6177 MonoIMTCheckItem *item = imt_entries [i];
6178 if (item->jmp_code) {
6179 if (item->check_target_idx) {
6181 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6183 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6188 mono_arch_flush_icache ((guint8*)start, (code - start));
6191 mono_stats.imt_thunks_size += (code - start);
6193 g_assert (code - start <= size);
6198 /*========================= End of Function ========================*/
6200 /*------------------------------------------------------------------*/
6202 /* Name - mono_arch_find_imt_method. */
6204 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6205 /* found in the save area. */
6207 /*------------------------------------------------------------------*/
6210 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6212 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
6214 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
6217 /*========================= End of Function ========================*/
6219 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6221 /*------------------------------------------------------------------*/
6223 /* Name - mono_arch_set_breakpoint. */
6225 /* Function - Set a breakpoint at the native code corresponding */
6226 /* to JI at NATIVE_OFFSET. The location should */
6227 /* contain code emitted by OP_SEQ_POINT. */
6229 /*------------------------------------------------------------------*/
6232 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6236 breakpointCode.pTrigger = bp_trigger_page;
6237 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6238 code += BREAKPOINT_SIZE;
6241 /*========================= End of Function ========================*/
6243 /*------------------------------------------------------------------*/
6245 /* Name - mono_arch_clear_breakpoint. */
6247 /* Function - Clear the breakpoint at IP. */
6249 /*------------------------------------------------------------------*/
6252 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6257 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6261 /*========================= End of Function ========================*/
6263 /*------------------------------------------------------------------*/
6265 /* Name - mono_arch_is_breakpoint_event. */
6269 /*------------------------------------------------------------------*/
6272 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6274 siginfo_t* sinfo = (siginfo_t*) info;
6275 /* Sometimes the address is off by 4 */
6276 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6282 /*========================= End of Function ========================*/
6284 /*------------------------------------------------------------------*/
6286 /* Name - mono_arch_skip_breakpoint. */
6288 /* Function - Modify the CTX so the IP is placed after the */
6289 /* breakpoint instruction, so when we resume, the */
6290 /* instruction is not executed again. */
6292 /*------------------------------------------------------------------*/
6295 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6297 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6300 /*========================= End of Function ========================*/
6302 /*------------------------------------------------------------------*/
6304 /* Name - mono_arch_start_single_stepping. */
6306 /* Function - Start single stepping. */
6308 /*------------------------------------------------------------------*/
6311 mono_arch_start_single_stepping (void)
6313 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6316 /*========================= End of Function ========================*/
6318 /*------------------------------------------------------------------*/
6320 /* Name - mono_arch_stop_single_stepping. */
6322 /* Function - Stop single stepping. */
6324 /*------------------------------------------------------------------*/
6327 mono_arch_stop_single_stepping (void)
6329 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6332 /*========================= End of Function ========================*/
6334 /*------------------------------------------------------------------*/
6336 /* Name - mono_arch_is_single_step_event. */
6338 /* Function - Return whether the machine state in sigctx cor- */
6339 /* responds to a single step event. */
6341 /*------------------------------------------------------------------*/
6344 mono_arch_is_single_step_event (void *info, void *sigctx)
6346 siginfo_t* sinfo = (siginfo_t*) info;
6348 /* Sometimes the address is off by 4 */
6349 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6355 /*========================= End of Function ========================*/
6357 /*------------------------------------------------------------------*/
6359 /* Name - mono_arch_skip_single_step. */
6361 /* Function - Modify the ctx so the IP is placed after the */
6362 /* single step trigger instruction, so that the */
6363 /* instruction is not executed again. */
6365 /*------------------------------------------------------------------*/
6368 mono_arch_skip_single_step (MonoContext *ctx)
6370 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6373 /*========================= End of Function ========================*/
6375 /*------------------------------------------------------------------*/
6377 /* Name - mono_arch_create_seq_point_info. */
6379 /* Function - Return a pointer to a data struction which is */
6380 /* used by the sequence point implementation in */
6383 /*------------------------------------------------------------------*/
6386 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6392 /*========================= End of Function ========================*/