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(RR_Format)
237 #define MAX(a, b) ((a) > (b) ? (a) : (b))
240 * imt thunking size values
243 #define LOADCON_SIZE 20
247 #define ENABLE_WRONG_METHOD_CHECK 0
249 #define mono_mini_arch_lock() mono_mutex_lock (&mini_arch_mutex)
250 #define mono_mini_arch_unlock() mono_mutex_unlock (&mini_arch_mutex)
252 /*========================= End of Defines =========================*/
254 /*------------------------------------------------------------------*/
255 /* I n c l u d e s */
256 /*------------------------------------------------------------------*/
260 #include <sys/types.h>
263 #include <mono/metadata/abi-details.h>
264 #include <mono/metadata/appdomain.h>
265 #include <mono/metadata/debug-helpers.h>
266 #include <mono/metadata/profiler-private.h>
267 #include <mono/utils/mono-math.h>
268 #include <mono/utils/mono-mmap.h>
269 #include <mono/utils/mono-hwcap-s390x.h>
271 #include "mini-s390x.h"
272 #include "cpu-s390x.h"
273 #include "support-s390x.h"
274 #include "jit-icalls.h"
278 /*========================= End of Includes ========================*/
280 /*------------------------------------------------------------------*/
281 /* T y p e d e f s */
282 /*------------------------------------------------------------------*/
294 /*------------------------------------------------------------------*/
295 /* Used by the instrument_emit_epilog */
296 /*------------------------------------------------------------------*/
307 typedef struct InstList InstList;
321 RegTypeStructByValInFP,
323 RegTypeStructByAddrOnStack
327 gint32 offset; /* offset from caller's stack */
328 gint32 offparm; /* offset from callee's stack */
329 guint16 vtsize; /* in param area */
332 guint32 size; /* Size of structure used by RegTypeStructByVal */
333 gint32 type; /* Data type of argument */
349 gint64 gr[5]; /* R2-R6 */
350 gdouble fp[3]; /* F0-F2 */
351 } __attribute__ ((packed)) RegParm;
359 } __attribute__ ((packed)) breakpoint_t;
361 /*========================= End of Typedefs ========================*/
363 /*------------------------------------------------------------------*/
364 /* P r o t o t y p e s */
365 /*------------------------------------------------------------------*/
367 static void indent (int);
368 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
369 static void decodeParm (MonoType *, void *, int);
370 static void enter_method (MonoMethod *, RegParm *, char *);
371 static void leave_method (MonoMethod *, ...);
372 static inline void add_general (guint *, size_data *, ArgInfo *);
373 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
374 static inline void add_float (guint *, size_data *, ArgInfo *);
375 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
376 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
377 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
378 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
380 /*========================= End of Prototypes ======================*/
382 /*------------------------------------------------------------------*/
383 /* G l o b a l V a r i a b l e s */
384 /*------------------------------------------------------------------*/
386 int mono_exc_esp_offset = 0;
388 __thread int indent_level = 0;
390 static gint appdomain_tls_offset = -1,
392 lmf_addr_tls_offset = -1;
394 pthread_key_t lmf_addr_key;
396 gboolean lmf_addr_key_inited = FALSE;
401 * The code generated for sequence points reads from this location,
402 * which is made read-only when single stepping is enabled.
404 static gpointer ss_trigger_page;
407 * Enabled breakpoints read from this trigger page
409 static gpointer bp_trigger_page;
411 breakpoint_t breakpointCode;
413 static mono_mutex_t mini_arch_mutex;
415 /*====================== End of Global Variables ===================*/
417 /*------------------------------------------------------------------*/
419 /* Name - mono_arch_regname */
421 /* Function - Returns the name of the register specified by */
422 /* the input parameter. */
424 /*------------------------------------------------------------------*/
427 mono_arch_regname (int reg) {
428 static const char * rnames[] = {
429 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
430 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
431 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
435 if (reg >= 0 && reg < 16)
441 /*========================= End of Function ========================*/
443 /*------------------------------------------------------------------*/
445 /* Name - mono_arch_fregname */
447 /* Function - Returns the name of the register specified by */
448 /* the input parameter. */
450 /*------------------------------------------------------------------*/
453 mono_arch_fregname (int reg) {
454 static const char * rnames[] = {
455 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
456 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
457 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
461 if (reg >= 0 && reg < 16)
467 /*========================= End of Function ========================*/
469 /*------------------------------------------------------------------*/
471 /* Name - arch_get_argument_info */
473 /* Function - Gathers information on parameters such as size, */
474 /* alignment, and padding. arg_info should be large */
475 /* enough to hold param_count + 1 entries. */
477 /* Parameters - @csig - Method signature */
478 /* @param_count - No. of parameters to consider */
479 /* @arg_info - An array to store the result info */
481 /* Returns - Size of the activation frame */
483 /*------------------------------------------------------------------*/
486 mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig,
488 MonoJitArgumentInfo *arg_info)
490 int k, frame_size = 0;
491 int size, align, pad;
494 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
495 frame_size += sizeof (gpointer);
499 arg_info [0].offset = offset;
502 frame_size += sizeof (gpointer);
506 arg_info [0].size = frame_size;
508 for (k = 0; k < param_count; k++) {
511 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
513 size = mini_type_stack_size (NULL, csig->params [k], &align);
515 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
516 arg_info [k].pad = pad;
518 arg_info [k + 1].pad = 0;
519 arg_info [k + 1].size = size;
521 arg_info [k + 1].offset = offset;
525 align = MONO_ARCH_FRAME_ALIGNMENT;
526 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
527 arg_info [k].pad = pad;
532 /*========================= End of Function ========================*/
534 /*------------------------------------------------------------------*/
536 /* Name - emit_unwind_regs. */
538 /* Function - Determines if a value can be returned in one or */
541 /*------------------------------------------------------------------*/
543 static void __inline__
544 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
548 for (i = start; i < end; i++) {
549 mono_emit_unwind_op_offset (cfg, code, i, offset);
550 offset += sizeof(gulong);
554 /*========================= End of Function ========================*/
556 /*------------------------------------------------------------------*/
558 /* Name - retFitsInReg. */
560 /* Function - Determines if a value can be returned in one or */
563 /*------------------------------------------------------------------*/
565 static inline gboolean
566 retFitsInReg(guint32 size)
581 /*========================= End of Function ========================*/
583 /*------------------------------------------------------------------*/
585 /* Name - backStackPtr. */
587 /* Function - Restore Stack Pointer to previous frame. */
589 /*------------------------------------------------------------------*/
591 static inline guint8 *
592 backUpStackPtr(MonoCompile *cfg, guint8 *code)
594 int stackSize = cfg->stack_usage;
596 if (cfg->frame_reg != STK_BASE)
597 s390_lgr (code, STK_BASE, cfg->frame_reg);
599 if (s390_is_imm16 (stackSize)) {
600 s390_aghi (code, STK_BASE, stackSize);
602 while (stackSize > 32767) {
603 s390_aghi (code, STK_BASE, 32767);
606 s390_aghi (code, STK_BASE, stackSize);
611 /*========================= End of Function ========================*/
613 /*------------------------------------------------------------------*/
617 /* Function - Perform nice indenting to current level */
619 /*------------------------------------------------------------------*/
625 indent_level += diff;
627 printf("%p [%3d] ",pthread_self(),v);
632 indent_level += diff;
635 /*========================= End of Function ========================*/
637 /*------------------------------------------------------------------*/
639 /* Name - cvtMonoType */
641 /* Function - Convert a mono-type to a string. */
643 /*------------------------------------------------------------------*/
646 cvtMonoType(MonoTypeEnum t)
651 return "MONO_TYPE_END";
653 return "MONO_TYPE_VOID";
654 case MONO_TYPE_BOOLEAN:
655 return "MONO_TYPE_BOOLEAN";
657 return "MONO_TYPE_CHAR";
659 return "MONO_TYPE_I1";
661 return "MONO_TYPE_U1";
663 return "MONO_TYPE_I2";
665 return "MONO_TYPE_U2";
667 return "MONO_TYPE_I4";
669 return "MONO_TYPE_U4";
671 return "MONO_TYPE_I8";
673 return "MONO_TYPE_U8";
675 return "MONO_TYPE_R4";
677 return "MONO_TYPE_R8";
678 case MONO_TYPE_STRING:
679 return "MONO_TYPE_STRING";
681 return "MONO_TYPE_PTR";
682 case MONO_TYPE_BYREF:
683 return "MONO_TYPE_BYREF";
684 case MONO_TYPE_VALUETYPE:
685 return "MONO_TYPE_VALUETYPE";
686 case MONO_TYPE_CLASS:
687 return "MONO_TYPE_CLASS";
689 return "MONO_TYPE_VAR";
690 case MONO_TYPE_ARRAY:
691 return "MONO_TYPE_ARRAY";
692 case MONO_TYPE_GENERICINST:
693 return "MONO_TYPE_GENERICINST";
694 case MONO_TYPE_TYPEDBYREF:
695 return "MONO_TYPE_TYPEDBYREF";
697 return "MONO_TYPE_I";
699 return "MONO_TYPE_U";
700 case MONO_TYPE_FNPTR:
701 return "MONO_TYPE_FNPTR";
702 case MONO_TYPE_OBJECT:
703 return "MONO_TYPE_OBJECT";
704 case MONO_TYPE_SZARRAY:
705 return "MONO_TYPE_SZARRAY";
707 return "MONO_TYPE_MVAR";
708 case MONO_TYPE_CMOD_REQD:
709 return "MONO_TYPE_CMOD_REQD";
710 case MONO_TYPE_CMOD_OPT:
711 return "MONO_TYPE_CMOD_OPT";
712 case MONO_TYPE_INTERNAL:
713 return "MONO_TYPE_INTERNAL";
714 case MONO_TYPE_MODIFIER:
715 return "MONO_TYPE_MODIFIER";
716 case MONO_TYPE_SENTINEL:
717 return "MONO_TYPE_SENTINEL";
718 case MONO_TYPE_PINNED:
719 return "MONO_TYPE_PINNED";
726 /*========================= End of Function ========================*/
728 /*------------------------------------------------------------------*/
730 /* Name - decodeParm */
732 /* Function - Decode a parameter for the trace. */
734 /*------------------------------------------------------------------*/
737 decodeParm(MonoType *type, void *curParm, int size)
742 printf("[BYREF:%p], ", *((char **) curParm));
744 simpleType = mono_type_get_underlying_type(type)->type;
746 switch (simpleType) {
748 printf ("[INTPTR:%p], ", *((int **) curParm));
751 printf ("[UINTPTR:%p], ", *((int **) curParm));
753 case MONO_TYPE_BOOLEAN :
754 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
756 case MONO_TYPE_CHAR :
757 printf ("[CHAR:%c], ", *((int *) curParm));
760 printf ("[INT1:%ld], ", *((gint64 *) curParm));
763 printf ("[INT2:%ld], ", *((gint64 *) curParm));
766 printf ("[INT4:%ld], ", *((gint64 *) curParm));
769 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
772 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
775 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
778 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
780 case MONO_TYPE_STRING : {
781 MonoString *s = *((MonoString **) curParm);
783 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
784 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
786 printf("[STRING:null], ");
790 case MONO_TYPE_CLASS :
791 case MONO_TYPE_OBJECT : {
792 MonoObject *obj = *((MonoObject **) curParm);
794 if ((obj) && (obj->vtable)) {
795 printf("[CLASS/OBJ:");
796 class = obj->vtable->klass;
797 printf("%p [%p] ",obj,curParm);
798 if (class == mono_defaults.string_class) {
799 printf("[STRING:%p:%s]",
800 obj, mono_string_to_utf8 ((MonoString *) obj));
801 } else if (class == mono_defaults.int32_class) {
802 printf("[INT32:%p:%d]",
803 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
806 class->name_space, class->name, obj);
809 printf("[OBJECT:null], ");
814 printf("[PTR:%p], ", *((gpointer **) (curParm)));
816 case MONO_TYPE_FNPTR :
817 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
819 case MONO_TYPE_ARRAY :
820 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
822 case MONO_TYPE_SZARRAY :
823 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
826 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
829 printf("[FLOAT4:%g], ", *((float *) (curParm)));
832 printf("[FLOAT8:%g], ", *((double *) (curParm)));
834 case MONO_TYPE_VALUETYPE : {
836 MonoMarshalType *info;
838 if (type->data.klass->enumtype) {
839 simpleType = mono_class_enum_basetype (type->data.klass)->type;
840 printf("{VALUETYPE} - ");
844 info = mono_marshal_load_type_info (type->data.klass);
846 if ((info->native_size == sizeof(float)) &&
847 (info->num_fields == 1) &&
848 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
849 printf("[FLOAT4:%f], ", *((float *) (curParm)));
853 if ((info->native_size == sizeof(double)) &&
854 (info->num_fields == 1) &&
855 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
856 printf("[FLOAT8:%g], ", *((double *) (curParm)));
860 printf("[VALUETYPE:");
861 for (i = 0; i < size; i++)
862 printf("%02x,", *((guint8 *)curParm+i));
866 case MONO_TYPE_TYPEDBYREF: {
868 printf("[TYPEDBYREF:");
869 for (i = 0; i < size; i++)
870 printf("%02x,", *((guint8 *)curParm+i));
875 printf("[%s], ",cvtMonoType(simpleType));
880 /*========================= End of Function ========================*/
882 /*------------------------------------------------------------------*/
884 /* Name - enter_method */
886 /* Function - Perform tracing of the entry to the current */
889 /*------------------------------------------------------------------*/
892 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
894 int i, oParm = 0, iParm = 0;
897 MonoMethodSignature *sig;
904 fname = mono_method_full_name (method, TRUE);
906 printf ("ENTER: %s ", fname);
909 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
910 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
915 sig = mono_method_signature (method);
917 cinfo = get_call_info (NULL, NULL, sig);
919 if (cinfo->struct_ret) {
920 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
925 gpointer *this = (gpointer *) rParm->gr[iParm];
926 obj = (MonoObject *) this;
927 switch(method->klass->this_arg.type) {
928 case MONO_TYPE_VALUETYPE:
930 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
931 printf("this:[value:%p:%016lx], ", this, *value);
933 printf ("this:[NULL], ");
935 case MONO_TYPE_STRING:
938 class = obj->vtable->klass;
939 if (class == mono_defaults.string_class) {
940 printf ("this:[STRING:%p:%s], ",
941 obj, mono_string_to_utf8 ((MonoString *)obj));
943 printf ("this:%p[%s.%s], ",
944 obj, class->name_space, class->name);
947 printf("vtable:[NULL], ");
949 printf ("this:[NULL], ");
952 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
957 for (i = 0; i < sig->param_count; ++i) {
958 ainfo = &cinfo->args[i + oParm];
959 switch (ainfo->regtype) {
960 case RegTypeGeneral :
961 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
964 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
967 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
969 case RegTypeStructByVal :
970 if (ainfo->reg != STK_BASE) {
971 int offset = sizeof(glong) - ainfo->size;
972 curParm = &(rParm->gr[ainfo->reg-2])+offset;
975 curParm = sp+ainfo->offset;
977 if (retFitsInReg (ainfo->vtsize))
978 decodeParm(sig->params[i],
982 decodeParm(sig->params[i],
983 *((char **) curParm),
986 case RegTypeStructByAddr :
987 if (ainfo->reg != STK_BASE)
988 curParm = &(rParm->gr[ainfo->reg-2]);
990 curParm = sp+ainfo->offset;
992 decodeParm(sig->params[i],
993 *((char **) curParm),
1005 /*========================= End of Function ========================*/
1007 /*------------------------------------------------------------------*/
1009 /* Name - leave_method */
1013 /*------------------------------------------------------------------*/
1016 leave_method (MonoMethod *method, ...)
1023 va_start(ap, method);
1025 fname = mono_method_full_name (method, TRUE);
1027 printf ("LEAVE: %s", fname);
1030 type = mono_method_signature (method)->ret;
1033 switch (type->type) {
1034 case MONO_TYPE_VOID:
1036 case MONO_TYPE_BOOLEAN: {
1037 int val = va_arg (ap, int);
1039 printf ("[TRUE:%d]", val);
1045 case MONO_TYPE_CHAR: {
1046 int val = va_arg (ap, int);
1047 printf ("[CHAR:%d]", val);
1050 case MONO_TYPE_I1: {
1051 int val = va_arg (ap, int);
1052 printf ("[INT1:%d]", val);
1055 case MONO_TYPE_U1: {
1056 int val = va_arg (ap, int);
1057 printf ("[UINT1:%d]", val);
1060 case MONO_TYPE_I2: {
1061 int val = va_arg (ap, int);
1062 printf ("[INT2:%d]", val);
1065 case MONO_TYPE_U2: {
1066 int val = va_arg (ap, int);
1067 printf ("[UINT2:%d]", val);
1070 case MONO_TYPE_I4: {
1071 int val = va_arg (ap, int);
1072 printf ("[INT4:%d]", val);
1075 case MONO_TYPE_U4: {
1076 int val = va_arg (ap, int);
1077 printf ("[UINT4:%d]", val);
1081 gint64 val = va_arg (ap, gint64);
1082 printf ("[INT:%ld]", val);
1087 gint64 val = va_arg (ap, gint64);
1088 printf ("[UINT:%lu]", val);
1092 case MONO_TYPE_STRING: {
1093 MonoString *s = va_arg (ap, MonoString *);
1096 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1097 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1099 printf ("[STRING:null], ");
1102 case MONO_TYPE_CLASS:
1103 case MONO_TYPE_OBJECT: {
1104 MonoObject *o = va_arg (ap, MonoObject *);
1106 if ((o) && (o->vtable)) {
1107 if (o->vtable->klass == mono_defaults.boolean_class) {
1108 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1109 } else if (o->vtable->klass == mono_defaults.int32_class) {
1110 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1111 } else if (o->vtable->klass == mono_defaults.int64_class) {
1112 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1114 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1116 printf ("[OBJECT:%p]", o);
1121 case MONO_TYPE_FNPTR:
1122 case MONO_TYPE_ARRAY:
1123 case MONO_TYPE_SZARRAY: {
1124 gpointer p = va_arg (ap, gpointer);
1125 printf ("[result=%p]", p);
1128 case MONO_TYPE_I8: {
1129 gint64 l = va_arg (ap, gint64);
1130 printf ("[LONG:%ld]", l);
1133 case MONO_TYPE_U8: {
1134 guint64 l = va_arg (ap, guint64);
1135 printf ("[ULONG:%lu]", l);
1138 case MONO_TYPE_R4: {
1139 double f = va_arg (ap, double);
1140 printf ("[FLOAT4:%g]\n", f);
1143 case MONO_TYPE_R8: {
1144 double f = va_arg (ap, double);
1145 printf ("[FLOAT8:%g]\n", f);
1148 case MONO_TYPE_VALUETYPE: {
1149 MonoMarshalType *info;
1150 if (type->data.klass->enumtype) {
1151 type = mono_class_enum_basetype (type->data.klass);
1156 info = mono_marshal_load_type_info (type->data.klass);
1158 if ((info->native_size == sizeof(float)) &&
1159 (info->num_fields == 1) &&
1160 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1161 double f = va_arg (ap, double);
1162 printf("[FLOAT4:%g]\n", (double) f);
1166 if ((info->native_size == sizeof(double)) &&
1167 (info->num_fields == 1) &&
1168 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1169 double f = va_arg (ap, double);
1170 printf("[FLOAT8:%g]\n", f);
1174 size = mono_type_size (type, &align);
1177 guint32 p = va_arg (ap, guint32);
1178 printf ("[%02x]\n",p);
1182 guint32 p = va_arg (ap, guint32);
1183 printf ("[%04x]\n",p);
1187 guint32 p = va_arg (ap, guint32);
1188 printf ("[%08x]\n",p);
1192 guint64 p = va_arg (ap, guint64);
1193 printf ("[%016lx]\n",p);
1197 gpointer p = va_arg (ap, gpointer);
1198 printf ("[VALUETYPE] %p\n",p);
1204 case MONO_TYPE_TYPEDBYREF: {
1205 guint8 *p = va_arg (ap, gpointer);
1207 size = mono_type_size (type, &align);
1214 for (j = 0; p && j < size; j++)
1215 printf ("%02x,", p [j]);
1219 printf ("[TYPEDBYREF]\n");
1224 printf ("(unknown return type %x)",
1225 mono_method_signature (method)->ret->type);
1228 ip = ((gint64) __builtin_extract_return_addr (__builtin_return_address (0)));
1229 printf (" ip: %p\n", (gpointer) ip);
1232 /*========================= End of Function ========================*/
1234 /*------------------------------------------------------------------*/
1236 /* Name - mono_arch_cpu_init */
1238 /* Function - Perform CPU specific initialization to execute */
1241 /*------------------------------------------------------------------*/
1244 mono_arch_cpu_init (void)
1248 /*========================= End of Function ========================*/
1250 /*------------------------------------------------------------------*/
1252 /* Name - mono_arch_init. */
1254 /* Function - Initialize architecture specific code. */
1256 /*------------------------------------------------------------------*/
1259 mono_arch_init (void)
1263 mono_mutex_init_recursive (&mini_arch_mutex);
1265 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1266 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1267 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1269 code = (guint8 *) &breakpointCode;
1270 s390_basr(code, s390_r13, 0);
1272 s390_llong(code, 0);
1273 s390_lg(code, s390_r13, 0, s390_r13, 4);
1274 s390_lg(code, s390_r0, 0, s390_r13, 0);
1277 /*========================= End of Function ========================*/
1279 /*------------------------------------------------------------------*/
1281 /* Name - mono_arch_cleanup. */
1283 /* Function - Cleanup architecture specific code . */
1285 /*------------------------------------------------------------------*/
1288 mono_arch_cleanup (void)
1290 if (ss_trigger_page)
1291 mono_vfree (ss_trigger_page, mono_pagesize ());
1292 if (bp_trigger_page)
1293 mono_vfree (bp_trigger_page, mono_pagesize ());
1294 mono_mutex_destroy (&mini_arch_mutex);
1297 /*========================= End of Function ========================*/
1299 /*------------------------------------------------------------------*/
1301 /* Name - mono_arch_cpu_optimizations */
1303 /* Function - Returns the optimizations supported on this CPU */
1305 /*------------------------------------------------------------------*/
1308 mono_arch_cpu_optimizations (guint32 *exclude_mask)
1312 /*----------------------------------------------------------*/
1313 /* No s390-specific optimizations yet */
1314 /*----------------------------------------------------------*/
1315 *exclude_mask = MONO_OPT_LINEARS;
1319 /*========================= End of Function ========================*/
1321 /*------------------------------------------------------------------*/
1323 /* Name - mono_arch_cpu_enumerate_simd_versions */
1325 /* Function - Returns the SIMD instruction sets on this CPU */
1327 /*------------------------------------------------------------------*/
1329 mono_arch_cpu_enumerate_simd_versions (void)
1331 /* SIMD is currently unimplemented */
1334 /*========================= End of Function ========================*/
1336 /*------------------------------------------------------------------*/
1338 /* Name - mono_arch_get_allocatable_int_vars */
1342 /*------------------------------------------------------------------*/
1345 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1350 for (i = 0; i < cfg->num_varinfo; i++) {
1351 MonoInst *ins = cfg->varinfo [i];
1352 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1355 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1358 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1359 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1362 /* we can only allocate 32 bit values */
1363 if (mono_is_regsize_var(ins->inst_vtype)) {
1364 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1365 g_assert (i == vmv->idx);
1366 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1373 /*========================= End of Function ========================*/
1375 /*------------------------------------------------------------------*/
1377 /* Name - mono_arch_global_int_regs */
1379 /* Function - Return a list of usable integer registers. */
1381 /*------------------------------------------------------------------*/
1384 mono_arch_get_global_int_regs (MonoCompile *cfg)
1387 MonoMethodHeader *header;
1390 header = cfg->header;
1391 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1392 cfg->frame_reg = s390_r11;
1395 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1397 for (i = 8; i < top; ++i) {
1398 if (cfg->frame_reg != i)
1399 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1405 /*========================= End of Function ========================*/
1407 /*------------------------------------------------------------------*/
1409 /* Name - mono_arch_flush_icache */
1411 /* Function - Flush the CPU icache. */
1413 /*------------------------------------------------------------------*/
1416 mono_arch_flush_icache (guint8 *code, gint size)
1420 /*========================= End of Function ========================*/
1422 /*------------------------------------------------------------------*/
1424 /* Name - add_general */
1426 /* Function - Determine code and stack size incremements for a */
1429 /*------------------------------------------------------------------*/
1432 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1434 if (*gr > S390_LAST_ARG_REG) {
1435 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1436 ainfo->offset = sz->stack_size;
1437 ainfo->reg = STK_BASE;
1438 ainfo->regtype = RegTypeBase;
1439 sz->stack_size += sizeof(long);
1440 sz->local_size += sizeof(long);
1441 sz->offStruct += sizeof(long);
1442 sz->code_size += 12;
1450 /*========================= End of Function ========================*/
1452 /*------------------------------------------------------------------*/
1454 /* Name - add_stackParm */
1456 /* Function - Determine code and stack size incremements for a */
1459 /*------------------------------------------------------------------*/
1462 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1464 if (*gr > S390_LAST_ARG_REG) {
1465 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1466 ainfo->reg = STK_BASE;
1467 ainfo->offset = sz->stack_size;
1468 ainfo->regtype = RegTypeStructByAddrOnStack;
1469 sz->stack_size += sizeof (gpointer);
1470 sz->parm_size += sizeof(gpointer);
1471 sz->offStruct += sizeof(gpointer);
1474 ainfo->offset = sz->stack_size;
1475 ainfo->regtype = RegTypeStructByAddr;
1478 ainfo->offparm = sz->offset;
1479 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1481 ainfo->vtsize = size;
1482 sz->parm_size += size;
1485 /*========================= End of Function ========================*/
1487 /*------------------------------------------------------------------*/
1489 /* Name - add_float */
1491 /* Function - Determine code and stack size incremements for a */
1492 /* float parameter. */
1494 /*------------------------------------------------------------------*/
1497 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1499 if ((*fr) <= S390_LAST_FPARG_REG) {
1500 ainfo->regtype = RegTypeFP;
1506 ainfo->offset = sz->stack_size;
1507 ainfo->reg = STK_BASE;
1508 ainfo->regtype = RegTypeBase;
1510 sz->stack_size += sizeof(double);
1511 sz->local_size += sizeof(double);
1512 sz->offStruct += sizeof(double);
1516 /*========================= End of Function ========================*/
1518 /*------------------------------------------------------------------*/
1520 /* Name - get_call_info */
1522 /* Function - Determine the amount of space required for code */
1523 /* and stack. In addition determine starting points */
1524 /* for stack-based parameters, and area for struct- */
1525 /* ures being returned on the stack. */
1527 /*------------------------------------------------------------------*/
1530 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
1532 guint i, fr, gr, size, pstart;
1533 int nParm = sig->hasthis + sig->param_count;
1535 guint32 simpleType, align;
1536 gboolean is_pinvoke = sig->pinvoke;
1539 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1542 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1544 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1549 cinfo->struct_ret = 0;
1553 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1554 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1561 /*----------------------------------------------------------*/
1562 /* We determine the size of the return code/stack in case we*/
1563 /* need to reserve a register to be used to address a stack */
1564 /* area that the callee will use. */
1565 /*----------------------------------------------------------*/
1567 ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
1568 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1569 simpleType = ret_type->type;
1571 switch (simpleType) {
1572 case MONO_TYPE_BOOLEAN:
1577 case MONO_TYPE_CHAR:
1582 case MONO_TYPE_CLASS:
1583 case MONO_TYPE_OBJECT:
1584 case MONO_TYPE_SZARRAY:
1585 case MONO_TYPE_ARRAY:
1587 case MONO_TYPE_FNPTR:
1588 case MONO_TYPE_STRING:
1589 cinfo->ret.reg = s390_r2;
1594 cinfo->ret.reg = s390_f0;
1599 cinfo->ret.reg = s390_r2;
1602 case MONO_TYPE_GENERICINST:
1603 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1604 cinfo->ret.reg = s390_r2;
1609 case MONO_TYPE_VALUETYPE: {
1610 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1611 if (klass->enumtype) {
1612 simpleType = mono_class_enum_basetype (klass)->type;
1615 size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1617 cinfo->struct_ret = 1;
1618 cinfo->ret.size = size;
1619 cinfo->ret.vtsize = size;
1622 case MONO_TYPE_TYPEDBYREF:
1623 size = sizeof (MonoTypedRef);
1624 cinfo->struct_ret = 1;
1625 cinfo->ret.size = size;
1626 cinfo->ret.vtsize = size;
1628 case MONO_TYPE_VOID:
1631 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1637 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1638 * the first argument, allowing 'this' to be always passed in the first arg reg.
1639 * Also do this if the first argument is a reference type, since virtual calls
1640 * are sometimes made using calli without sig->hasthis set, like in the delegate
1643 if (cinfo->struct_ret && !is_pinvoke &&
1645 (sig->param_count > 0 &&
1646 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1648 cinfo->args[nParm].size = sizeof (gpointer);
1649 add_general (&gr, sz, cinfo->args + nParm);
1651 cinfo->args[nParm].size = sizeof (gpointer);
1652 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1656 cinfo->vret_arg_index = 1;
1657 cinfo->ret.reg = gr;
1662 cinfo->args[nParm].size = sizeof (gpointer);
1663 add_general (&gr, sz, cinfo->args + nParm);
1667 if (cinfo->struct_ret) {
1668 cinfo->ret.reg = gr;
1673 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1674 gr = S390_LAST_ARG_REG + 1;
1675 fr = S390_LAST_FPARG_REG + 1;
1677 /* Emit the signature cookie just before the implicit arguments */
1678 add_general (&gr, sz, &cinfo->sigCookie);
1681 /*----------------------------------------------------------*/
1682 /* We determine the size of the parameter code and stack */
1683 /* requirements by checking the types and sizes of the */
1685 /*----------------------------------------------------------*/
1687 for (i = pstart; i < sig->param_count; ++i) {
1690 /*--------------------------------------------------*/
1691 /* Handle vararg type calls. All args are put on */
1693 /*--------------------------------------------------*/
1694 if ((sig->call_convention == MONO_CALL_VARARG) &&
1695 (i == sig->sentinelpos)) {
1696 gr = S390_LAST_ARG_REG + 1;
1697 fr = S390_LAST_FPARG_REG + 1;
1698 add_general (&gr, sz, &cinfo->sigCookie);
1701 if (sig->params [i]->byref) {
1702 add_general (&gr, sz, cinfo->args+nParm);
1703 cinfo->args[nParm].size = sizeof(gpointer);
1708 ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
1709 simpleType = ptype->type;
1710 cinfo->args[nParm].type = simpleType;
1711 switch (simpleType) {
1712 case MONO_TYPE_BOOLEAN:
1715 cinfo->args[nParm].size = sizeof(char);
1716 add_general (&gr, sz, cinfo->args+nParm);
1721 case MONO_TYPE_CHAR:
1722 cinfo->args[nParm].size = sizeof(short);
1723 add_general (&gr, sz, cinfo->args+nParm);
1728 cinfo->args[nParm].size = sizeof(int);
1729 add_general (&gr, sz, cinfo->args+nParm);
1735 case MONO_TYPE_FNPTR:
1736 case MONO_TYPE_CLASS:
1737 case MONO_TYPE_OBJECT:
1738 case MONO_TYPE_STRING:
1739 case MONO_TYPE_SZARRAY:
1740 case MONO_TYPE_ARRAY:
1741 cinfo->args[nParm].size = sizeof(gpointer);
1742 add_general (&gr, sz, cinfo->args+nParm);
1747 cinfo->args[nParm].size = sizeof(long long);
1748 add_general (&gr, sz, cinfo->args+nParm);
1752 cinfo->args[nParm].size = sizeof(float);
1753 add_float (&fr, sz, cinfo->args+nParm);
1757 cinfo->args[nParm].size = sizeof(double);
1758 add_float (&fr, sz, cinfo->args+nParm);
1761 case MONO_TYPE_GENERICINST:
1762 if (!mono_type_generic_inst_is_valuetype (ptype)) {
1763 cinfo->args[nParm].size = sizeof(gpointer);
1764 add_general (&gr, sz, cinfo->args+nParm);
1769 case MONO_TYPE_VALUETYPE: {
1770 MonoMarshalType *info;
1771 MonoClass *klass = mono_class_from_mono_type (ptype);
1774 size = mono_class_native_size(klass, NULL);
1776 size = mono_class_value_size(klass, NULL);
1778 if (simpleType != MONO_TYPE_GENERICINST) {
1779 info = mono_marshal_load_type_info(klass);
1781 if ((info->native_size == sizeof(float)) &&
1782 (info->num_fields == 1) &&
1783 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1784 cinfo->args[nParm].size = sizeof(float);
1785 add_float(&fr, sz, cinfo->args+nParm);
1790 if ((info->native_size == sizeof(double)) &&
1791 (info->num_fields == 1) &&
1792 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1793 cinfo->args[nParm].size = sizeof(double);
1794 add_float(&fr, sz, cinfo->args+nParm);
1800 cinfo->args[nParm].vtsize = 0;
1801 cinfo->args[nParm].size = 0;
1804 /*----------------------------------*/
1805 /* On S/390, structures of size 1, */
1806 /* 2, 4, and 8 bytes are passed in */
1807 /* (a) register(s). */
1808 /*----------------------------------*/
1814 add_general(&gr, sz, cinfo->args+nParm);
1815 cinfo->args[nParm].size = size;
1816 cinfo->args[nParm].regtype = RegTypeStructByVal;
1818 sz->local_size += sizeof(long);
1821 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1826 case MONO_TYPE_TYPEDBYREF: {
1827 int size = sizeof (MonoTypedRef);
1829 cinfo->args[nParm].vtsize = 0;
1830 cinfo->args[nParm].size = 0;
1833 /*----------------------------------*/
1834 /* On S/390, structures of size 1, */
1835 /* 2, 4, and 8 bytes are passed in */
1836 /* (a) register(s). */
1837 /*----------------------------------*/
1843 add_general(&gr, sz, cinfo->args+nParm);
1844 cinfo->args[nParm].size = size;
1845 cinfo->args[nParm].regtype = RegTypeStructByVal;
1847 sz->local_size += sizeof(long);
1850 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1856 g_error ("Can't trampoline 0x%x", ptype);
1860 /*----------------------------------------------------------*/
1861 /* Handle the case where there are no implicit arguments */
1862 /*----------------------------------------------------------*/
1863 if ((sig->call_convention == MONO_CALL_VARARG) &&
1866 (sig->param_count == sig->sentinelpos)) {
1867 gr = S390_LAST_ARG_REG + 1;
1868 fr = S390_LAST_FPARG_REG + 1;
1869 add_general (&gr, sz, &cinfo->sigCookie);
1872 /*----------------------------------------------------------*/
1873 /* If we are passing a structure back then if it won't be */
1874 /* in a register(s) then we make room at the end of the */
1875 /* parameters that may have been placed on the stack */
1876 /*----------------------------------------------------------*/
1877 if (cinfo->struct_ret) {
1878 cinfo->ret.offset = sz->stack_size;
1879 switch (cinfo->ret.size) {
1887 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1892 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1894 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1899 /*========================= End of Function ========================*/
1901 /*------------------------------------------------------------------*/
1903 /* Name - mono_arch_allocate_vars */
1905 /* Function - Set var information according to the calling */
1906 /* convention for S/390. The local var stuff should */
1907 /* most likely be split in another method. */
1909 /* Parameter - @m - Compile unit. */
1911 /*------------------------------------------------------------------*/
1914 mono_arch_allocate_vars (MonoCompile *cfg)
1916 MonoMethodSignature *sig;
1917 MonoMethodHeader *header;
1920 int iParm, iVar, offset, align, size, curinst;
1921 int frame_reg = STK_BASE;
1924 header = cfg->header;
1926 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1928 /*---------------------------------------------------------*/
1929 /* We use the frame register also for any method that has */
1930 /* filter clauses. This way, when the handlers are called, */
1931 /* the code will reference local variables using the frame */
1932 /* reg instead of the stack pointer: if we had to restore */
1933 /* the stack pointer, we'd corrupt the method frames that */
1934 /* are already on the stack (since filters get called */
1935 /* before stack unwinding happens) when the filter code */
1936 /* would call any method. */
1937 /*---------------------------------------------------------*/
1938 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1939 frame_reg = s390_r11;
1941 cfg->frame_reg = frame_reg;
1943 cfg->arch.bkchain_reg = -1;
1945 if (frame_reg != STK_BASE)
1946 cfg->used_int_regs |= 1 << frame_reg;
1948 sig = mono_method_signature (cfg->method);
1950 cinfo = get_call_info (cfg, cfg->mempool, sig);
1952 if (!cinfo->struct_ret) {
1953 switch (mini_type_get_underlying_type (cfg->generic_sharing_context, sig->ret)->type) {
1954 case MONO_TYPE_VOID:
1957 cfg->ret->opcode = OP_REGVAR;
1958 cfg->ret->dreg = s390_r2;
1963 /*--------------------------------------------------------------*/
1964 /* local vars are at a positive offset from the stack pointer */
1965 /* also note that if the function uses alloca, we use s390_r11 */
1966 /* to point at the local variables. */
1967 /* add parameter area size for called functions */
1968 /*--------------------------------------------------------------*/
1969 if (cfg->param_area == 0)
1970 offset = S390_MINIMAL_STACK_SIZE;
1972 offset = cfg->param_area;
1974 cfg->sig_cookie = 0;
1976 if (cinfo->struct_ret) {
1977 inst = cfg->vret_addr;
1978 offset = S390_ALIGN(offset, sizeof(gpointer));
1979 inst->inst_offset = offset;
1980 inst->opcode = OP_REGOFFSET;
1981 inst->inst_basereg = frame_reg;
1982 offset += sizeof(gpointer);
1983 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1984 printf ("vret_addr =");
1985 mono_print_ins (cfg->vret_addr);
1990 inst = cfg->args [0];
1991 if (inst->opcode != OP_REGVAR) {
1992 inst->opcode = OP_REGOFFSET;
1993 inst->inst_basereg = frame_reg;
1994 offset = S390_ALIGN(offset, sizeof(gpointer));
1995 inst->inst_offset = offset;
1996 offset += sizeof (gpointer);
2003 eArg = sig->param_count + sArg;
2005 if (sig->call_convention == MONO_CALL_VARARG)
2006 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2008 for (iParm = sArg; iParm < eArg; ++iParm) {
2009 inst = cfg->args [curinst];
2010 if (inst->opcode != OP_REGVAR) {
2011 switch (cinfo->args[iParm].regtype) {
2012 case RegTypeStructByAddr : {
2015 size = sizeof (gpointer);
2017 inst->opcode = OP_REGOFFSET;
2018 inst->inst_basereg = frame_reg;
2019 offset = S390_ALIGN (offset, sizeof (gpointer));
2020 inst->inst_offset = offset;
2022 /* Add a level of indirection */
2023 MONO_INST_NEW (cfg, indir, 0);
2025 inst->opcode = OP_VTARG_ADDR;
2026 inst->inst_left = indir;
2029 case RegTypeStructByAddrOnStack : {
2032 size = sizeof (gpointer);
2034 /* Similar to the == STK_BASE case below */
2035 cfg->arch.bkchain_reg = s390_r12;
2036 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2038 inst->opcode = OP_REGOFFSET;
2039 inst->dreg = mono_alloc_preg (cfg);
2040 inst->inst_basereg = cfg->arch.bkchain_reg;
2041 inst->inst_offset = cinfo->args [iParm].offset;
2043 /* Add a level of indirection */
2044 MONO_INST_NEW (cfg, indir, 0);
2046 inst->opcode = OP_VTARG_ADDR;
2047 inst->inst_left = indir;
2050 case RegTypeStructByVal :
2051 size = cinfo->args[iParm].size;
2052 offset = S390_ALIGN(offset, size);
2053 inst->opcode = OP_REGOFFSET;
2054 inst->inst_basereg = frame_reg;
2055 inst->inst_offset = offset;
2058 if (cinfo->args [iParm].reg == STK_BASE) {
2060 * These arguments are in the previous frame, so we can't
2061 * compute their offset from the current frame pointer right
2062 * now, since cfg->stack_offset is not yet known, so dedicate a
2063 * register holding the previous frame pointer.
2065 cfg->arch.bkchain_reg = s390_r12;
2066 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2068 inst->opcode = OP_REGOFFSET;
2069 inst->inst_basereg = cfg->arch.bkchain_reg;
2070 size = (cinfo->args[iParm].size < 8
2071 ? 8 - cinfo->args[iParm].size
2073 inst->inst_offset = cinfo->args [iParm].offset + size;
2074 size = sizeof (long);
2076 inst->opcode = OP_REGOFFSET;
2077 inst->inst_basereg = frame_reg;
2078 size = (cinfo->args[iParm].size < 8
2081 offset = S390_ALIGN(offset, size);
2082 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2083 inst->inst_offset = offset;
2085 inst->inst_offset = offset + (8 - size);
2090 if ((sig->call_convention == MONO_CALL_VARARG) &&
2091 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2092 (iParm < sig->sentinelpos))
2093 cfg->sig_cookie += size;
2094 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2097 offset += MAX(size, 8);
2102 cfg->locals_min_stack_offset = offset;
2104 curinst = cfg->locals_start;
2105 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2106 inst = cfg->varinfo [iVar];
2107 if ((inst->flags & MONO_INST_IS_DEAD) ||
2108 (inst->opcode == OP_REGVAR))
2111 /*--------------------------------------------------*/
2112 /* inst->backend.is_pinvoke indicates native sized */
2113 /* value typs this is used by the pinvoke wrappers */
2114 /* when they call functions returning structure */
2115 /*--------------------------------------------------*/
2116 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2117 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2118 (guint32 *) &align);
2120 size = mono_type_size (inst->inst_vtype, &align);
2122 offset = S390_ALIGN(offset, align);
2123 inst->inst_offset = offset;
2124 inst->opcode = OP_REGOFFSET;
2125 inst->inst_basereg = frame_reg;
2127 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2128 iVar, inst->inst_offset, size));
2131 cfg->locals_max_stack_offset = offset;
2133 /*------------------------------------------------------*/
2134 /* Allow space for the trace method stack area if needed*/
2135 /*------------------------------------------------------*/
2136 if ((mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2137 || (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE))
2138 offset += S390_TRACE_STACK_SIZE;
2140 /*------------------------------------------------------*/
2141 /* Reserve space to save LMF and caller saved registers */
2142 /*------------------------------------------------------*/
2143 if (cfg->method->save_lmf)
2144 offset += sizeof (MonoLMF);
2146 /*------------------------------------------------------*/
2147 /* align the offset */
2148 /*------------------------------------------------------*/
2149 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2151 /*------------------------------------------------------*/
2152 /* Fix offsets for args whose value is in parent frame */
2153 /*------------------------------------------------------*/
2154 for (iParm = sArg; iParm < eArg; ++iParm) {
2155 inst = cfg->args [iParm];
2157 if (inst->opcode == OP_S390_STKARG) {
2158 inst->opcode = OP_REGOFFSET;
2159 inst->inst_offset += cfg->stack_offset;
2164 /*========================= End of Function ========================*/
2166 /*------------------------------------------------------------------*/
2168 /* Name - mono_arch_create_vars */
2170 /*------------------------------------------------------------------*/
2173 mono_arch_create_vars (MonoCompile *cfg)
2175 MonoMethodSignature *sig;
2178 sig = mono_method_signature (cfg->method);
2180 cinfo = get_call_info (cfg, cfg->mempool, sig);
2182 if (cinfo->struct_ret) {
2183 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2184 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2185 printf ("vret_addr = ");
2186 mono_print_ins (cfg->vret_addr);
2191 /*========================= End of Function ========================*/
2193 /*------------------------------------------------------------------*/
2195 /* Name - add_outarg_reg2. */
2197 /*------------------------------------------------------------------*/
2200 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2205 case RegTypeGeneral:
2206 MONO_INST_NEW (cfg, ins, OP_MOVE);
2207 ins->dreg = mono_alloc_ireg (cfg);
2208 ins->sreg1 = tree->dreg;
2209 MONO_ADD_INS (cfg->cbb, ins);
2210 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2213 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2214 ins->dreg = mono_alloc_freg (cfg);
2215 ins->sreg1 = tree->dreg;
2216 MONO_ADD_INS (cfg->cbb, ins);
2217 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2220 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2221 ins->dreg = mono_alloc_freg (cfg);
2222 ins->sreg1 = tree->dreg;
2223 MONO_ADD_INS (cfg->cbb, ins);
2224 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2227 g_assert_not_reached ();
2231 /*========================= End of Function ========================*/
2233 /*------------------------------------------------------------------*/
2235 /* Name - emit_sig_cookie. */
2237 /*------------------------------------------------------------------*/
2240 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2242 MonoMethodSignature *tmpSig;
2245 cfg->disable_aot = TRUE;
2247 /*----------------------------------------------------------*/
2248 /* mono_ArgIterator_Setup assumes the signature cookie is */
2249 /* passed first and all the arguments which were before it */
2250 /* passed on the stack after the signature. So compensate */
2251 /* by passing a different signature. */
2252 /*----------------------------------------------------------*/
2253 tmpSig = mono_metadata_signature_dup (call->signature);
2254 tmpSig->param_count -= call->signature->sentinelpos;
2255 tmpSig->sentinelpos = 0;
2256 if (tmpSig->param_count > 0)
2257 memcpy (tmpSig->params,
2258 call->signature->params + call->signature->sentinelpos,
2259 tmpSig->param_count * sizeof(MonoType *));
2261 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2262 sig_arg->dreg = mono_alloc_ireg (cfg);
2263 sig_arg->inst_p0 = tmpSig;
2264 MONO_ADD_INS (cfg->cbb, sig_arg);
2266 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2267 cinfo->sigCookie.offset, sig_arg->dreg);
2270 /*========================= End of Function ========================*/
2272 /*------------------------------------------------------------------*/
2274 /* Name - mono_arch_emit_call */
2276 /*------------------------------------------------------------------*/
2279 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2282 MonoMethodSignature *sig;
2284 int i, n, lParamArea;
2286 ArgInfo *ainfo = NULL;
2288 MonoMethodHeader *header;
2291 sig = call->signature;
2292 n = sig->param_count + sig->hasthis;
2293 DEBUG (g_print ("Call requires: %d parameters\n",n));
2295 cinfo = get_call_info (cfg, cfg->mempool, sig);
2297 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2298 cinfo->sz.parm_size + cinfo->sz.offset;
2299 call->stack_usage = MAX(stackSize, call->stack_usage);
2300 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2301 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2302 cfg->flags |= MONO_CFG_HAS_CALLS;
2304 if (cinfo->struct_ret) {
2305 MONO_INST_NEW (cfg, ins, OP_MOVE);
2306 ins->sreg1 = call->vret_var->dreg;
2307 ins->dreg = mono_alloc_preg (cfg);
2308 MONO_ADD_INS (cfg->cbb, ins);
2309 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2312 header = cfg->header;
2313 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2318 for (i = 0; i < n; ++i) {
2321 ainfo = cinfo->args + i;
2322 if (i >= sig->hasthis)
2323 t = sig->params [i - sig->hasthis];
2325 t = &mono_defaults.int_class->byval_arg;
2326 t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
2328 in = call->args [i];
2330 if ((sig->call_convention == MONO_CALL_VARARG) &&
2332 (i == sig->sentinelpos)) {
2333 emit_sig_cookie (cfg, call, cinfo);
2336 switch (ainfo->regtype) {
2337 case RegTypeGeneral:
2338 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2341 if (MONO_TYPE_ISSTRUCT (t)) {
2342 /* Valuetype passed in one fp register */
2343 ainfo->regtype = RegTypeStructByValInFP;
2346 if (ainfo->size == 4)
2347 ainfo->regtype = RegTypeFPR4;
2348 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2351 case RegTypeStructByVal:
2352 case RegTypeStructByAddr:
2353 case RegTypeStructByAddrOnStack: {
2357 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2358 size = sizeof (MonoTypedRef);
2359 align = sizeof (gpointer);
2363 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2366 * Other backends use mono_type_stack_size (), but that
2367 * aligns the size to 8, which is larger than the size of
2368 * the source, leading to reads of invalid memory if the
2369 * source is at the end of address space.
2371 size = mono_class_value_size (in->klass, &align);
2374 g_assert (in->klass);
2376 ainfo->offparm += cinfo->sz.offStruct;
2378 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2379 ins->sreg1 = in->dreg;
2380 ins->klass = in->klass;
2381 ins->backend.size = ainfo->size;
2382 ins->inst_p0 = call;
2383 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2384 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2386 MONO_ADD_INS (cfg->cbb, ins);
2388 if (ainfo->regtype == RegTypeStructByAddr) {
2390 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2391 * use the normal OUTARG opcodes to pass the address of the location to
2394 int treg = mono_alloc_preg (cfg);
2395 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2396 frmReg, ainfo->offparm);
2397 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2398 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2399 /* The address of the valuetype is passed on the stack */
2400 int treg = mono_alloc_preg (cfg);
2401 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2402 frmReg, ainfo->offparm);
2403 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2404 ainfo->reg, ainfo->offset, treg);
2406 if (cfg->compute_gc_maps) {
2409 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2415 if (!t->byref && t->type == MONO_TYPE_R4) {
2416 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2417 STK_BASE, ainfo->offset + 4,
2419 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2420 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2421 STK_BASE, ainfo->offset,
2424 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2425 ins->inst_destbasereg = STK_BASE;
2426 ins->inst_offset = ainfo->offset;
2427 ins->sreg1 = in->dreg;
2430 /* This is needed by MonoTypedRef->value to point to the correct data */
2431 if ((sig->call_convention == MONO_CALL_VARARG) &&
2432 (i >= sig->sentinelpos)) {
2433 switch (ainfo->size) {
2435 ins->opcode = OP_STOREI1_MEMBASE_REG;
2438 ins->opcode = OP_STOREI2_MEMBASE_REG;
2441 ins->opcode = OP_STOREI4_MEMBASE_REG;
2449 MONO_ADD_INS (cfg->cbb, ins);
2453 g_assert_not_reached ();
2459 * Handle the case where there are no implicit arguments
2461 if ((sig->call_convention == MONO_CALL_VARARG) &&
2463 (i == sig->sentinelpos)) {
2464 emit_sig_cookie (cfg, call, cinfo);
2468 /*========================= End of Function ========================*/
2470 /*------------------------------------------------------------------*/
2472 /* Name - mono_arch_emit_outarg_vt */
2474 /*------------------------------------------------------------------*/
2477 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2479 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2480 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2481 int size = ins->backend.size;
2483 if (ainfo->regtype == RegTypeStructByVal) {
2485 arg->ins.sreg1 = ainfo->reg;
2486 arg->ins.opcode = OP_OUTARG_VT;
2487 arg->size = ainfo->size;
2488 arg->offset = ainfo->offset;
2489 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2491 if (ainfo->reg != STK_BASE) {
2492 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2494 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2497 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2498 int dreg = mono_alloc_freg (cfg);
2500 if (ainfo->size == 4) {
2501 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2502 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2504 g_assert (ainfo->size == 8);
2506 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2509 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2511 MonoMethodHeader *header;
2514 header = mono_method_get_header (cfg->method);
2515 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2520 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2521 src->dreg, 0, size);
2523 if (cfg->compute_gc_maps) {
2526 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2531 /*========================= End of Function ========================*/
2533 /*------------------------------------------------------------------*/
2535 /* Name - mono_arch_emit_setret */
2537 /*------------------------------------------------------------------*/
2540 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2542 MonoType *ret = mini_type_get_underlying_type (cfg->generic_sharing_context,
2543 mono_method_signature (method)->ret);
2546 if (ret->type == MONO_TYPE_R4) {
2547 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2549 } else if (ret->type == MONO_TYPE_R8) {
2550 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2555 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2558 /*========================= End of Function ========================*/
2560 /*------------------------------------------------------------------*/
2562 /* Name - mono_arch_instrument_mem_needs */
2564 /* Function - Allow tracing to work with this interface (with */
2565 /* an optional argument). */
2567 /*------------------------------------------------------------------*/
2570 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2572 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2574 /* split prolog-epilog requirements? */
2575 *code = 50; /* max bytes needed: check this number */
2578 /*========================= End of Function ========================*/
2580 /*------------------------------------------------------------------*/
2582 /* Name - mono_arch_instrument_prolog */
2584 /* Function - Create an "instrumented" prolog. */
2586 /*------------------------------------------------------------------*/
2589 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2590 gboolean enable_arguments)
2597 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2598 if (cfg->method->save_lmf)
2599 parmOffset -= sizeof(MonoLMF);
2600 fpOffset = parmOffset + (5*sizeof(gpointer));
2603 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2604 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2605 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2606 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2607 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2608 S390_SET (code, s390_r1, func);
2609 S390_SET (code, s390_r2, cfg->method);
2610 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2611 s390_lgr (code, s390_r4, STK_BASE);
2612 s390_aghi (code, s390_r4, cfg->stack_usage);
2613 s390_basr (code, s390_r14, s390_r1);
2614 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2615 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2616 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2617 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2618 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2623 /*========================= End of Function ========================*/
2625 /*------------------------------------------------------------------*/
2627 /* Name - mono_arch_instrument_epilog */
2629 /* Function - Create an epilog that will handle the returned */
2630 /* values used in instrumentation. */
2632 /*------------------------------------------------------------------*/
2635 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2638 int save_mode = SAVE_NONE,
2641 MonoMethod *method = cfg->method;
2642 int rtype = mini_type_get_underlying_type (cfg->generic_sharing_context,
2643 mono_method_signature (method)->ret)->type;
2645 offset = code - cfg->native_code;
2646 /*-----------------------------------------*/
2647 /* We need about 128 bytes of instructions */
2648 /*-----------------------------------------*/
2649 if (offset > (cfg->code_size - 128)) {
2650 cfg->code_size *= 2;
2651 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2652 code = cfg->native_code + offset;
2655 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2656 if (method->save_lmf)
2657 saveOffset -= sizeof(MonoLMF);
2661 case MONO_TYPE_VOID:
2662 /* special case string .ctor icall */
2663 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2664 save_mode = SAVE_ONE;
2666 save_mode = SAVE_NONE;
2670 save_mode = SAVE_ONE;
2673 save_mode = SAVE_R4;
2676 save_mode = SAVE_R8;
2678 case MONO_TYPE_VALUETYPE:
2679 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2680 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2683 save_mode = SAVE_STRUCT;
2686 save_mode = SAVE_ONE;
2690 switch (save_mode) {
2692 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2693 if (enable_arguments) {
2694 s390_lgr (code, s390_r3, s390_r2);
2698 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2699 if (enable_arguments) {
2700 s390_ldebr (code, s390_f0, s390_f0);
2704 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2707 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2708 if (enable_arguments) {
2709 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2710 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2718 S390_SET (code, s390_r1, func);
2719 S390_SET (code, s390_r2, cfg->method);
2720 s390_basr (code, s390_r14, s390_r1);
2722 switch (save_mode) {
2724 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2728 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2731 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2741 /*========================= End of Function ========================*/
2743 /*------------------------------------------------------------------*/
2745 /* Name - mono_arch_peephole_pass_1 */
2747 /* Function - Form a peephole pass at the code looking for */
2748 /* simple optimizations. */
2750 /*------------------------------------------------------------------*/
2753 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2757 /*========================= End of Function ========================*/
2759 /*------------------------------------------------------------------*/
2761 /* Name - mono_arch_peephole_pass_2 */
2763 /* Function - Form a peephole pass at the code looking for */
2764 /* simple optimizations. */
2766 /*------------------------------------------------------------------*/
2769 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2773 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2774 mono_peephole_ins (bb, ins);
2778 /*========================= End of Function ========================*/
2780 /*------------------------------------------------------------------*/
2782 /* Name - mono_arch_lowering_pass. */
2784 /*------------------------------------------------------------------*/
2787 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2789 MonoInst *ins, *next;
2791 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2792 switch (ins->opcode) {
2797 case OP_IDIV_UN_IMM:
2798 case OP_IREM_UN_IMM:
2802 case OP_LOCALLOC_IMM:
2803 mono_decompose_op_imm (cfg, bb, ins);
2806 if (!s390_is_imm16 (ins->inst_imm))
2807 /* This is created by the memcpy code which ignores is_inst_imm */
2808 mono_decompose_op_imm (cfg, bb, ins);
2815 bb->max_vreg = cfg->next_vreg;
2818 /*========================= End of Function ========================*/
2820 /*------------------------------------------------------------------*/
2822 /* Name - emit_float_to_int */
2824 /* Function - Create instructions which will convert a floating */
2825 /* point value to integer. */
2827 /*------------------------------------------------------------------*/
2830 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2832 /* sreg is a float, dreg is an integer reg. */
2834 s390_cgdbr (code, dreg, 5, sreg);
2837 s390_lghi (code, s390_r0, 0);
2838 s390_lghi (code, s390_r13, 0xff);
2839 s390_ltgr (code, dreg, dreg);
2841 s390_lghi (code, s390_r0, 0x80);
2842 s390_ngr (code, dreg, s390_r13);
2843 s390_ogr (code, dreg, s390_r0);
2848 S390_SET (code, s390_r13, 0x41e0000000000000llu);
2849 s390_ldgr (code, s390_f14, s390_r13);
2850 s390_ldr (code, s390_f15, sreg);
2851 s390_cdbr (code, s390_f15, s390_f14);
2852 s390_jl (code, 0); CODEPTR (code, o[0]);
2853 S390_SET (code, s390_r13, 0x41f0000000000000llu);
2854 s390_ldgr (code, s390_f14, s390_r13);
2855 s390_sdbr (code, s390_f15, s390_f14);
2856 s390_cfdbr (code, dreg, 7, s390_f15);
2858 PTRSLOT (code, o[0]);
2859 s390_cfdbr (code, dreg, 5, sreg);
2862 s390_lghi (code, s390_r0, 0xff);
2863 s390_ngr (code, dreg, s390_r0);
2866 s390_lghi (code, s390_r0, -1);
2867 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2868 s390_ngr (code, dreg, s390_r0);
2875 /*========================= End of Function ========================*/
2877 /*------------------------------------------------------------------*/
2879 /* Name - gboolean_is_unsigned. */
2881 /* Function - Return TRUE if next opcode is checking for un- */
2884 /*------------------------------------------------------------------*/
2887 gboolean is_unsigned (MonoInst *next)
2890 (((next->opcode >= OP_IBNE_UN) &&
2891 (next->opcode <= OP_IBLT_UN)) ||
2892 ((next->opcode >= OP_LBNE_UN) &&
2893 (next->opcode <= OP_LBLT_UN)) ||
2894 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2895 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2896 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2897 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2898 ((next->opcode == OP_CLT_UN) ||
2899 (next->opcode == OP_CGT_UN)) ||
2900 ((next->opcode == OP_ICLT_UN) ||
2901 (next->opcode == OP_ICGT_UN) ||
2902 (next->opcode == OP_LCLT_UN) ||
2903 (next->opcode == OP_LCGT_UN))))
2909 /*========================= End of Function ========================*/
2911 /*------------------------------------------------------------------*/
2913 /* Name - mono_arch_output_basic_block */
2915 /* Function - Perform the "real" work of emitting instructions */
2916 /* that will do the work of in the basic block. */
2918 /*------------------------------------------------------------------*/
2921 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2926 guint8 *code = cfg->native_code + cfg->code_len;
2927 guint last_offset = 0;
2928 int max_len, cpos, src2;
2930 /* we don't align basic blocks of loops on s390 */
2932 if (cfg->verbose_level > 2)
2933 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2935 cpos = bb->max_offset;
2937 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2938 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2939 //g_assert (!mono_compile_aot);
2942 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2943 /* this is not thread save, but good enough */
2944 /* fixme: howto handle overflows? */
2945 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2948 MONO_BB_FOR_EACH_INS (bb, ins) {
2949 offset = code - cfg->native_code;
2951 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2953 if (offset > (cfg->code_size - max_len - 16)) {
2954 cfg->code_size *= 2;
2955 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2956 code = cfg->native_code + offset;
2959 mono_debug_record_line_number (cfg, ins, offset);
2961 switch (ins->opcode) {
2962 case OP_STOREI1_MEMBASE_IMM: {
2963 s390_lghi (code, s390_r0, ins->inst_imm);
2964 S390_LONG (code, stcy, stc, s390_r0, 0,
2965 ins->inst_destbasereg, ins->inst_offset);
2968 case OP_STOREI2_MEMBASE_IMM: {
2969 s390_lghi (code, s390_r0, ins->inst_imm);
2970 S390_LONG (code, sthy, sth, s390_r0, 0,
2971 ins->inst_destbasereg, ins->inst_offset);
2974 case OP_STOREI4_MEMBASE_IMM: {
2975 s390_lgfi (code, s390_r0, ins->inst_imm);
2976 S390_LONG (code, sty, st, s390_r0, 0,
2977 ins->inst_destbasereg, ins->inst_offset);
2980 case OP_STORE_MEMBASE_IMM:
2981 case OP_STOREI8_MEMBASE_IMM: {
2982 S390_SET (code, s390_r0, ins->inst_imm);
2983 S390_LONG (code, stg, stg, s390_r0, 0,
2984 ins->inst_destbasereg, ins->inst_offset);
2987 case OP_STOREI1_MEMBASE_REG: {
2988 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2989 ins->inst_destbasereg, ins->inst_offset);
2992 case OP_STOREI2_MEMBASE_REG: {
2993 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2994 ins->inst_destbasereg, ins->inst_offset);
2997 case OP_STOREI4_MEMBASE_REG: {
2998 S390_LONG (code, sty, st, ins->sreg1, 0,
2999 ins->inst_destbasereg, ins->inst_offset);
3002 case OP_STORE_MEMBASE_REG:
3003 case OP_STOREI8_MEMBASE_REG: {
3004 S390_LONG (code, stg, stg, ins->sreg1, 0,
3005 ins->inst_destbasereg, ins->inst_offset);
3009 g_assert_not_reached ();
3011 case OP_LOAD_MEMBASE:
3012 case OP_LOADI8_MEMBASE: {
3013 S390_LONG (code, lg, lg, ins->dreg, 0,
3014 ins->inst_basereg, ins->inst_offset);
3017 case OP_LOADI4_MEMBASE: {
3018 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3019 ins->inst_basereg, ins->inst_offset);
3022 case OP_LOADU4_MEMBASE: {
3023 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3024 ins->inst_basereg, ins->inst_offset);
3027 case OP_LOADU1_MEMBASE: {
3028 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3029 ins->inst_basereg, ins->inst_offset);
3032 case OP_LOADI1_MEMBASE: {
3033 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3034 ins->inst_basereg, ins->inst_offset);
3037 case OP_LOADU2_MEMBASE: {
3038 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3039 ins->inst_basereg, ins->inst_offset);
3042 case OP_LOADI2_MEMBASE: {
3043 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3044 ins->inst_basereg, ins->inst_offset);
3047 case OP_LCONV_TO_I1: {
3048 s390_lgbr (code, ins->dreg, ins->sreg1);
3051 case OP_LCONV_TO_I2: {
3052 s390_lghr (code, ins->dreg, ins->sreg1);
3055 case OP_LCONV_TO_U1: {
3056 s390_llgcr (code, ins->dreg, ins->sreg1);
3059 case OP_LCONV_TO_U2: {
3060 s390_llghr (code, ins->dreg, ins->sreg1);
3063 case OP_ICONV_TO_I1: {
3064 s390_lgbr (code, ins->dreg, ins->sreg1);
3067 case OP_ICONV_TO_I2: {
3068 s390_lghr (code, ins->dreg, ins->sreg1);
3071 case OP_ICONV_TO_U1: {
3072 s390_llgcr (code, ins->dreg, ins->sreg1);
3075 case OP_ICONV_TO_U2: {
3076 s390_llghr (code, ins->dreg, ins->sreg1);
3081 if (is_unsigned (ins->next))
3082 s390_clgr (code, ins->sreg1, ins->sreg2);
3084 s390_cgr (code, ins->sreg1, ins->sreg2);
3088 if (is_unsigned (ins->next))
3089 s390_clr (code, ins->sreg1, ins->sreg2);
3091 s390_cr (code, ins->sreg1, ins->sreg2);
3094 case OP_COMPARE_IMM:
3095 case OP_LCOMPARE_IMM: {
3096 S390_SET (code, s390_r0, ins->inst_imm);
3097 if (is_unsigned (ins->next))
3098 s390_clgr (code, ins->sreg1, s390_r0);
3100 s390_cgr (code, ins->sreg1, s390_r0);
3103 case OP_ICOMPARE_IMM: {
3104 S390_SET (code, s390_r0, ins->inst_imm);
3105 if (is_unsigned (ins->next))
3106 s390_clr (code, ins->sreg1, s390_r0);
3108 s390_cr (code, ins->sreg1, s390_r0);
3112 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3114 S390_CALL_TEMPLATE (code, s390_r14);
3119 s390_agr (code, ins->dreg, src2);
3124 s390_agr (code, ins->dreg, src2);
3129 s390_alcgr (code, ins->dreg, src2);
3133 if (ins->dreg != ins->sreg1) {
3134 s390_lgr (code, ins->dreg, ins->sreg1);
3136 if (s390_is_imm16 (ins->inst_imm)) {
3137 s390_aghi (code, ins->dreg, ins->inst_imm);
3138 } else if (s390_is_imm32 (ins->inst_imm)) {
3139 s390_agfi (code, ins->dreg, ins->inst_imm);
3141 S390_SET (code, s390_r0, ins->inst_imm);
3142 s390_agr (code, ins->dreg, s390_r0);
3147 if (ins->dreg != ins->sreg1) {
3148 s390_lgr (code, ins->dreg, ins->sreg1);
3150 g_assert (s390_is_imm16 (ins->inst_imm));
3151 s390_aghi (code, ins->dreg, ins->inst_imm);
3155 if (ins->dreg != ins->sreg1) {
3156 s390_lgr (code, ins->dreg, ins->sreg1);
3158 if (s390_is_imm16 (ins->inst_imm)) {
3159 s390_lghi (code, s390_r0, ins->inst_imm);
3160 s390_alcgr (code, ins->dreg, s390_r0);
3162 S390_SET (code, s390_r0, ins->inst_imm);
3163 s390_alcgr (code, ins->dreg, s390_r0);
3168 case OP_S390_IADD_OVF: {
3170 s390_ar (code, ins->dreg, src2);
3171 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3172 s390_lgfr (code, ins->dreg, ins->dreg);
3175 case OP_IADD_OVF_UN:
3176 case OP_S390_IADD_OVF_UN: {
3178 s390_algr (code, ins->dreg, src2);
3179 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3180 s390_llgfr (code, ins->dreg, ins->dreg);
3183 case OP_ADD_OVF_CARRY: {
3185 s390_lghi (code, s390_r0, 0);
3186 s390_lgr (code, s390_r1, s390_r0);
3187 s390_alcgr (code, s390_r0, s390_r1);
3188 s390_agr (code, ins->dreg, src2);
3189 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3190 s390_agr (code, ins->dreg, s390_r0);
3191 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3194 case OP_ADD_OVF_UN_CARRY: {
3196 s390_alcgr (code, ins->dreg, src2);
3197 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3202 s390_sgr (code, ins->dreg, src2);
3207 s390_sgr (code, ins->dreg, src2);
3212 s390_slbgr(code, ins->dreg, src2);
3216 if (ins->dreg != ins->sreg1) {
3217 s390_lgr (code, ins->dreg, ins->sreg1);
3219 if (s390_is_imm16 (-ins->inst_imm)) {
3220 s390_aghi (code, ins->dreg, -ins->inst_imm);
3221 } else if (s390_is_imm32 (-ins->inst_imm)) {
3222 s390_slgfi (code, ins->dreg, ins->inst_imm);
3224 S390_SET (code, s390_r0, ins->inst_imm);
3225 s390_slgr (code, ins->dreg, s390_r0);
3230 if (ins->dreg != ins->sreg1) {
3231 s390_lgr (code, ins->dreg, ins->sreg1);
3233 if (s390_is_imm16 (-ins->inst_imm)) {
3234 s390_aghi (code, ins->dreg, -ins->inst_imm);
3235 } else if (s390_is_imm32 (-ins->inst_imm)) {
3236 s390_slgfi (code, ins->dreg, ins->inst_imm);
3238 S390_SET (code, s390_r0, ins->inst_imm);
3239 s390_slgr (code, ins->dreg, s390_r0);
3244 if (ins->dreg != ins->sreg1) {
3245 s390_lgr (code, ins->dreg, ins->sreg1);
3247 if (s390_is_imm16 (-ins->inst_imm)) {
3248 s390_lghi (code, s390_r0, ins->inst_imm);
3249 s390_slbgr (code, ins->dreg, s390_r0);
3251 S390_SET (code, s390_r0, ins->inst_imm);
3252 s390_slbgr(code, ins->dreg, s390_r0);
3256 case OP_SUB_OVF_CARRY: {
3258 s390_lghi (code, s390_r0, 0);
3259 s390_lgr (code, s390_r1, s390_r0);
3260 s390_slbgr (code, s390_r0, s390_r1);
3261 s390_sgr (code, ins->dreg, src2);
3262 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3263 s390_agr (code, ins->dreg, s390_r0);
3264 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3267 case OP_SUB_OVF_UN_CARRY: {
3269 s390_slbgr (code, ins->dreg, src2);
3270 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3274 if (ins->sreg1 == ins->dreg) {
3275 s390_ngr (code, ins->dreg, ins->sreg2);
3278 if (ins->sreg2 == ins->dreg) {
3279 s390_ngr (code, ins->dreg, ins->sreg1);
3282 s390_lgr (code, ins->dreg, ins->sreg1);
3283 s390_ngr (code, ins->dreg, ins->sreg2);
3289 if (ins->dreg != ins->sreg1) {
3290 s390_lgr (code, ins->dreg, ins->sreg1);
3292 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3293 s390_ngr (code, ins->dreg, s390_r0);
3297 s390_lgr (code, s390_r1, ins->sreg1);
3298 s390_dsgr (code, s390_r0, ins->sreg2);
3299 s390_lgr (code, ins->dreg, s390_r1);
3303 s390_lgr (code, s390_r1, ins->sreg1);
3304 s390_lghi (code, s390_r0, 0);
3305 s390_dlgr (code, s390_r0, ins->sreg2);
3306 s390_lgr (code, ins->dreg, s390_r1);
3310 s390_lgr (code, s390_r1, ins->sreg1);
3311 s390_dsgr (code, s390_r0, ins->sreg2);
3312 s390_lgr (code, ins->dreg, s390_r0);
3316 s390_lgr (code, s390_r1, ins->sreg1);
3317 s390_lghi (code, s390_r0, 0);
3318 s390_dlgr (code, s390_r0, ins->sreg2);
3319 s390_lgr (code, ins->dreg, s390_r0);
3323 if (ins->sreg1 == ins->dreg) {
3324 s390_ogr (code, ins->dreg, ins->sreg2);
3327 if (ins->sreg2 == ins->dreg) {
3328 s390_ogr (code, ins->dreg, ins->sreg1);
3331 s390_lgr (code, ins->dreg, ins->sreg1);
3332 s390_ogr (code, ins->dreg, ins->sreg2);
3338 if (ins->dreg != ins->sreg1) {
3339 s390_lgr (code, ins->dreg, ins->sreg1);
3341 S390_SET_MASK(code, s390_r0, ins->inst_imm);
3342 s390_ogr (code, ins->dreg, s390_r0);
3346 if (ins->sreg1 == ins->dreg) {
3347 s390_xgr (code, ins->dreg, ins->sreg2);
3350 if (ins->sreg2 == ins->dreg) {
3351 s390_xgr (code, ins->dreg, ins->sreg1);
3354 s390_lgr (code, ins->dreg, ins->sreg1);
3355 s390_xgr (code, ins->dreg, ins->sreg2);
3361 if (ins->dreg != ins->sreg1) {
3362 s390_lgr (code, ins->dreg, ins->sreg1);
3364 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3365 s390_xgr (code, ins->dreg, s390_r0);
3370 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3375 if (ins->sreg1 != ins->dreg) {
3376 s390_lgr (code, ins->dreg, ins->sreg1);
3378 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3383 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3388 if (ins->sreg1 != ins->dreg) {
3389 s390_lgr (code, ins->dreg, ins->sreg1);
3391 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3395 case OP_LSHR_UN_IMM: {
3396 if (ins->sreg1 != ins->dreg) {
3397 s390_lgr (code, ins->dreg, ins->sreg1);
3399 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3404 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3408 if (ins->sreg1 != ins->dreg) {
3409 s390_lgr (code, ins->dreg, ins->sreg1);
3411 s390_lghi (code, s390_r0, -1);
3412 s390_xgr (code, ins->dreg, s390_r0);
3416 s390_lcgr (code, ins->dreg, ins->sreg1);
3421 s390_msgr (code, ins->dreg, src2);
3426 if (ins->dreg != ins->sreg1) {
3427 s390_lgr (code, ins->dreg, ins->sreg1);
3429 if (s390_is_imm16 (ins->inst_imm)) {
3430 s390_lghi (code, s390_r13, ins->inst_imm);
3431 } else if (s390_is_imm32 (ins->inst_imm)) {
3432 s390_lgfi (code, s390_r13, ins->inst_imm);
3434 S390_SET (code, s390_r13, ins->inst_imm);
3436 s390_msgr (code, ins->dreg, s390_r13);
3441 s390_ltgr (code, s390_r1, ins->sreg1);
3442 s390_jz (code, 0); CODEPTR(code, o[0]);
3443 s390_ltgr (code, s390_r0, ins->sreg2);
3445 s390_lghi (code, s390_r1, 0);
3446 s390_j (code, 0); CODEPTR(code, o[1]);
3447 s390_xgr (code, s390_r0, s390_r1);
3448 s390_msgr (code, s390_r1, ins->sreg2);
3449 s390_xgr (code, s390_r0, s390_r1);
3450 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3451 s390_ltgr (code, s390_r0, s390_r0);
3452 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3453 PTRSLOT (code, o[0]);
3454 PTRSLOT (code, o[1]);
3455 s390_lgr (code, ins->dreg, s390_r1);
3458 case OP_LMUL_OVF_UN: {
3459 s390_lghi (code, s390_r0, 0);
3460 s390_lgr (code, s390_r1, ins->sreg1);
3461 s390_mlgr (code, s390_r0, ins->sreg2);
3462 s390_ltgr (code, s390_r0, s390_r0);
3463 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3464 s390_lgr (code, ins->dreg, s390_r1);
3468 g_assert_not_reached ();
3470 s390_algr (code, ins->dreg, src2);
3475 s390_agr (code, ins->dreg, src2);
3479 g_assert_not_reached ();
3481 s390_alcgr (code, ins->dreg, src2);
3485 if (ins->dreg != ins->sreg1) {
3486 s390_lgfr (code, ins->dreg, ins->sreg1);
3488 if (s390_is_imm16 (ins->inst_imm)) {
3489 s390_aghi (code, ins->dreg, ins->inst_imm);
3491 s390_afi (code, ins->dreg, ins->inst_imm);
3496 if (ins->dreg != ins->sreg1) {
3497 s390_lgfr (code, ins->dreg, ins->sreg1);
3499 if (s390_is_imm16 (ins->inst_imm)) {
3500 s390_lghi (code, s390_r0, ins->inst_imm);
3501 s390_alcgr (code, ins->dreg, s390_r0);
3503 S390_SET (code, s390_r0, ins->inst_imm);
3504 s390_alcgr (code, ins->dreg, s390_r0);
3509 case OP_S390_LADD_OVF: {
3511 s390_agr (code, ins->dreg, src2);
3512 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3515 case OP_LADD_OVF_UN:
3516 case OP_S390_LADD_OVF_UN: {
3518 s390_algr (code, ins->dreg, src2);
3519 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3523 CHECK_SRCDST_NCOM_I;
3524 s390_slgr (code, ins->dreg, src2);
3528 CHECK_SRCDST_NCOM_I;
3529 s390_sgr (code, ins->dreg, src2);
3533 CHECK_SRCDST_NCOM_I;
3534 s390_slbgr (code, ins->dreg, src2);
3538 if (ins->dreg != ins->sreg1) {
3539 s390_lgfr (code, ins->dreg, ins->sreg1);
3541 if (s390_is_imm16 (-ins->inst_imm)) {
3542 s390_aghi (code, ins->dreg, -ins->inst_imm);
3544 s390_agfi (code, ins->dreg, -ins->inst_imm);
3549 S390_SET (code, s390_r0, ins->inst_imm);
3550 s390_slgfr (code, ins->dreg, s390_r0);
3554 case OP_S390_ISUB_OVF: {
3556 s390_sr (code, ins->dreg, src2);
3557 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3558 s390_lgfr (code, ins->dreg, ins->dreg);
3561 case OP_ISUB_OVF_UN:
3562 case OP_S390_ISUB_OVF_UN: {
3564 s390_slr (code, ins->dreg, src2);
3565 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3566 s390_llgfr(code, ins->dreg, ins->dreg);
3570 case OP_S390_LSUB_OVF: {
3572 s390_sgr (code, ins->dreg, src2);
3573 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3576 case OP_LSUB_OVF_UN:
3577 case OP_S390_LSUB_OVF_UN: {
3579 s390_slgr (code, ins->dreg, src2);
3580 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3584 CHECK_SRCDST_NCOM_I;
3585 s390_ngr (code, ins->dreg, src2);
3589 if (ins->dreg != ins->sreg1) {
3590 s390_lgfr (code, ins->dreg, ins->sreg1);
3592 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3593 s390_ngr (code, ins->dreg, s390_r0);
3597 s390_lgfr (code, s390_r0, ins->sreg1);
3598 s390_srda (code, s390_r0, 0, 32);
3599 s390_dr (code, s390_r0, ins->sreg2);
3600 s390_lgfr (code, ins->dreg, s390_r1);
3604 s390_lgfr (code, s390_r0, ins->sreg1);
3605 s390_srdl (code, s390_r0, 0, 32);
3606 s390_dlr (code, s390_r0, ins->sreg2);
3607 s390_lgfr (code, ins->dreg, s390_r1);
3611 if (s390_is_imm16 (ins->inst_imm)) {
3612 s390_lghi (code, s390_r13, ins->inst_imm);
3614 s390_lgfi (code, s390_r13, ins->inst_imm);
3616 s390_lgfr (code, s390_r0, ins->sreg1);
3617 s390_srda (code, s390_r0, 0, 32);
3618 s390_dr (code, s390_r0, ins->sreg2);
3619 s390_lgfr (code, ins->dreg, s390_r1);
3623 s390_lgfr (code, s390_r0, ins->sreg1);
3624 s390_srda (code, s390_r0, 0, 32);
3625 s390_dr (code, s390_r0, ins->sreg2);
3626 s390_lgfr (code, ins->dreg, s390_r0);
3629 s390_lgfr (code, s390_r0, ins->sreg1);
3630 s390_srdl (code, s390_r0, 0, 32);
3631 s390_dlr (code, s390_r0, ins->sreg2);
3632 s390_lgfr (code, ins->dreg, s390_r0);
3636 if (s390_is_imm16 (ins->inst_imm)) {
3637 s390_lghi (code, s390_r13, ins->inst_imm);
3639 s390_lgfi (code, s390_r13, ins->inst_imm);
3641 s390_lgfr (code, s390_r0, ins->sreg1);
3642 s390_srda (code, s390_r0, 0, 32);
3643 s390_dr (code, s390_r0, ins->sreg2);
3644 s390_lgfr (code, ins->dreg, s390_r0);
3649 s390_ogr (code, ins->dreg, src2);
3653 if (ins->dreg != ins->sreg1) {
3654 s390_lgfr (code, ins->dreg, ins->sreg1);
3656 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3657 s390_ogr (code, ins->dreg, s390_r0);
3662 s390_xgr (code, ins->dreg, src2);
3666 if (ins->dreg != ins->sreg1) {
3667 s390_lgfr (code, ins->dreg, ins->sreg1);
3669 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3670 s390_xgr (code, ins->dreg, s390_r0);
3675 s390_sll (code, ins->dreg, src2, 0);
3679 if (ins->sreg1 != ins->dreg) {
3680 s390_lgfr (code, ins->dreg, ins->sreg1);
3682 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3687 s390_sra (code, ins->dreg, src2, 0);
3691 if (ins->sreg1 != ins->dreg) {
3692 s390_lgfr (code, ins->dreg, ins->sreg1);
3694 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3697 case OP_ISHR_UN_IMM: {
3698 if (ins->sreg1 != ins->dreg) {
3699 s390_lgfr (code, ins->dreg, ins->sreg1);
3701 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3706 s390_srl (code, ins->dreg, src2, 0);
3710 if (ins->sreg1 != ins->dreg) {
3711 s390_lgfr (code, ins->dreg, ins->sreg1);
3713 s390_lghi (code, s390_r0, -1);
3714 s390_xgr (code, ins->dreg, s390_r0);
3718 s390_lcgr (code, ins->dreg, ins->sreg1);
3723 s390_msr (code, ins->dreg, src2);
3727 if (ins->dreg != ins->sreg1) {
3728 s390_lgfr (code, ins->dreg, ins->sreg1);
3730 if (s390_is_imm16 (ins->inst_imm)) {
3731 s390_lghi (code, s390_r0, ins->inst_imm);
3733 s390_lgfi (code, s390_r0, ins->inst_imm);
3735 s390_msr (code, ins->dreg, s390_r0);
3740 s390_ltr (code, s390_r1, ins->sreg1);
3741 s390_jz (code, 0); CODEPTR(code, o[0]);
3742 s390_ltr (code, s390_r0, ins->sreg2);
3744 s390_lhi (code, s390_r1, 0);
3745 s390_j (code, 0); CODEPTR(code, o[1]);
3746 s390_xr (code, s390_r0, s390_r1);
3747 s390_msr (code, s390_r1, ins->sreg2);
3748 s390_xr (code, s390_r0, s390_r1);
3749 s390_srl (code, s390_r0, 0, 31);
3750 s390_ltr (code, s390_r0, s390_r0);
3751 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3752 PTRSLOT (code, o[0]);
3753 PTRSLOT (code, o[1]);
3754 s390_lgfr (code, ins->dreg, s390_r1);
3757 case OP_IMUL_OVF_UN: {
3758 s390_lhi (code, s390_r0, 0);
3759 s390_lr (code, s390_r1, ins->sreg1);
3760 s390_mlr (code, s390_r0, ins->sreg2);
3761 s390_ltr (code, s390_r0, s390_r0);
3762 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3763 s390_lgfr (code, ins->dreg, s390_r1);
3768 S390_SET (code, ins->dreg, ins->inst_c0);
3772 mono_add_patch_info (cfg, code - cfg->native_code,
3773 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3774 S390_LOAD_TEMPLATE (code, ins->dreg);
3777 case OP_JUMP_TABLE: {
3778 mono_add_patch_info (cfg, code - cfg->native_code,
3779 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3780 S390_LOAD_TEMPLATE (code, ins->dreg);
3784 if (ins->dreg != ins->sreg1) {
3785 s390_lgr (code, ins->dreg, ins->sreg1);
3789 case OP_LCONV_TO_I8:
3791 s390_lgfr (code, ins->dreg, ins->sreg1);
3793 case OP_LCONV_TO_I4:
3794 s390_lgfr (code, ins->dreg, ins->sreg1);
3797 case OP_LCONV_TO_U8:
3798 case OP_LCONV_TO_U4:
3800 s390_llgfr (code, ins->dreg, ins->sreg1);
3802 case OP_LCONV_TO_OVF_U4:
3803 S390_SET (code, s390_r0, 4294967295);
3804 s390_clgr (code, ins->sreg1, s390_r0);
3805 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3806 s390_ltgr (code, ins->sreg1, ins->sreg1);
3807 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3808 s390_llgfr(code, ins->dreg, ins->sreg1);
3810 case OP_LCONV_TO_OVF_I4_UN:
3811 S390_SET (code, s390_r0, 2147483647);
3812 s390_cgr (code, ins->sreg1, s390_r0);
3813 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3814 s390_ltgr (code, ins->sreg1, ins->sreg1);
3815 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3816 s390_lgfr (code, ins->dreg, ins->sreg1);
3819 if (ins->dreg != ins->sreg1) {
3820 s390_ldr (code, ins->dreg, ins->sreg1);
3824 case OP_FCONV_TO_R4: {
3825 s390_ledbr (code, ins->dreg, ins->sreg1);
3826 s390_ldebr (code, ins->dreg, ins->dreg);
3829 case OP_S390_SETF4RET: {
3830 s390_ledbr (code, ins->dreg, ins->sreg1);
3834 if (s390_is_imm16 (ins->inst_offset)) {
3835 s390_lghi (code, s390_r13, ins->inst_offset);
3836 } else if (s390_is_imm32 (ins->inst_offset)) {
3837 s390_lgfi (code, s390_r13, ins->inst_offset);
3839 S390_SET (code, s390_r13, ins->inst_offset);
3841 s390_ear (code, s390_r1, 0);
3842 s390_sllg(code, s390_r1, s390_r1, 0, 32);
3843 s390_ear (code, s390_r1, 1);
3844 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
3848 if (cfg->method->save_lmf)
3849 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3851 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3852 code = emit_load_volatile_arguments (code, cfg);
3855 code = backUpStackPtr(cfg, code);
3856 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
3857 mono_add_patch_info (cfg, code - cfg->native_code,
3858 MONO_PATCH_INFO_METHOD_JUMP,
3860 s390_jcl (code, S390_CC_UN, 0);
3863 case OP_CHECK_THIS: {
3864 /* ensure ins->sreg1 is not NULL */
3865 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3866 s390_ltgr (code, s390_r0, s390_r0);
3867 // EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
3871 int offset = cfg->sig_cookie + cfg->stack_usage;
3873 if (s390_is_imm16 (offset)) {
3874 s390_lghi (code, s390_r0, offset);
3875 } else if (s390_is_imm32 (offset)) {
3876 s390_lgfi (code, s390_r0, offset);
3878 S390_SET (code, s390_r0, offset);
3880 s390_agr (code, s390_r0, cfg->frame_reg);
3881 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3885 call = (MonoCallInst*)ins;
3886 if (ins->flags & MONO_INST_HAS_METHOD)
3887 mono_add_patch_info (cfg, code-cfg->native_code,
3888 MONO_PATCH_INFO_METHOD,
3891 mono_add_patch_info (cfg, code-cfg->native_code,
3892 MONO_PATCH_INFO_ABS,
3894 S390_CALL_TEMPLATE (code, s390_r14);
3895 if (call->signature->ret->type == MONO_TYPE_R4)
3896 s390_ldebr (code, s390_f0, s390_f0);
3904 call = (MonoCallInst*)ins;
3905 if (ins->flags & MONO_INST_HAS_METHOD)
3906 mono_add_patch_info (cfg, code-cfg->native_code,
3907 MONO_PATCH_INFO_METHOD,
3910 mono_add_patch_info (cfg, code-cfg->native_code,
3911 MONO_PATCH_INFO_ABS,
3913 S390_CALL_TEMPLATE (code, s390_r14);
3916 case OP_FCALL_REG: {
3917 call = (MonoCallInst*)ins;
3918 s390_lgr (code, s390_r1, ins->sreg1);
3919 s390_basr (code, s390_r14, s390_r1);
3920 if (call->signature->ret->type == MONO_TYPE_R4)
3921 s390_ldebr (code, s390_f0, s390_f0);
3927 case OP_VOIDCALL_REG:
3929 s390_lgr (code, s390_r1, ins->sreg1);
3930 s390_basr (code, s390_r14, s390_r1);
3933 case OP_FCALL_MEMBASE: {
3934 call = (MonoCallInst*)ins;
3935 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3936 s390_basr (code, s390_r14, s390_r1);
3937 if (call->signature->ret->type == MONO_TYPE_R4)
3938 s390_ldebr (code, s390_f0, s390_f0);
3941 case OP_LCALL_MEMBASE:
3942 case OP_VCALL_MEMBASE:
3943 case OP_VCALL2_MEMBASE:
3944 case OP_VOIDCALL_MEMBASE:
3945 case OP_CALL_MEMBASE: {
3946 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3947 s390_basr (code, s390_r14, s390_r1);
3954 if (cfg->param_area == 0)
3955 alloca_skip = S390_MINIMAL_STACK_SIZE;
3957 alloca_skip = cfg->param_area;
3959 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3960 s390_lgr (code, s390_r1, ins->sreg1);
3961 if (ins->flags & MONO_INST_INIT)
3962 s390_lgr (code, s390_r0, ins->sreg1);
3963 s390_aghi (code, s390_r1, 14);
3964 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3965 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3966 if (cfg->method->save_lmf) {
3967 /*----------------------------------*/
3968 /* we have to adjust lmf ebp value */
3969 /*----------------------------------*/
3970 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3972 s390_lgr (code, s390_r13, cfg->frame_reg);
3973 if (s390_is_imm16(lmfOffset)) {
3974 s390_aghi (code, s390_r13, lmfOffset);
3975 } else if (s390_is_imm32(lmfOffset)) {
3976 s390_agfi (code, s390_r13, lmfOffset);
3978 S390_SET (code, s390_r13, lmfOffset);
3980 s390_lgr (code, s390_r14, STK_BASE);
3981 s390_sgr (code, s390_r14, s390_r1);
3982 s390_stg (code, s390_r14, 0, s390_r13,
3983 G_STRUCT_OFFSET(MonoLMF, ebp));
3985 s390_lg (code, s390_r13, 0, STK_BASE, 0);
3986 s390_sgr (code, STK_BASE, s390_r1);
3987 s390_stg (code, s390_r13, 0, STK_BASE, 0);
3988 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
3989 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
3990 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
3991 if (ins->flags & MONO_INST_INIT) {
3992 s390_lgr (code, s390_r1, s390_r0);
3993 s390_lgr (code, s390_r0, ins->dreg);
3994 s390_lgr (code, s390_r14, s390_r12);
3995 s390_lghi (code, s390_r13, 0);
3996 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
3998 s390_lgr (code, s390_r12, s390_r14);
4003 s390_lgr (code, s390_r2, ins->sreg1);
4004 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4005 (gpointer) "mono_arch_throw_exception");
4006 S390_CALL_TEMPLATE(code, s390_r14);
4010 s390_lgr (code, s390_r2, ins->sreg1);
4011 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4012 (gpointer) "mono_arch_rethrow_exception");
4013 S390_CALL_TEMPLATE(code, s390_r14);
4016 case OP_START_HANDLER: {
4017 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4019 S390_LONG (code, stg, stg, s390_r14, 0,
4020 spvar->inst_basereg,
4021 spvar->inst_offset);
4024 case OP_ENDFILTER: {
4025 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4027 if (ins->sreg1 != s390_r2)
4028 s390_lgr(code, s390_r2, ins->sreg1);
4029 S390_LONG (code, lg, lg, s390_r14, 0,
4030 spvar->inst_basereg,
4031 spvar->inst_offset);
4032 s390_br (code, s390_r14);
4035 case OP_ENDFINALLY: {
4036 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4038 S390_LONG (code, lg, lg, s390_r14, 0,
4039 spvar->inst_basereg,
4040 spvar->inst_offset);
4041 s390_br (code, s390_r14);
4044 case OP_CALL_HANDLER: {
4045 mono_add_patch_info (cfg, code-cfg->native_code,
4046 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4047 s390_brasl (code, s390_r14, 0);
4048 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4052 ins->inst_c0 = code - cfg->native_code;
4055 case OP_RELAXED_NOP:
4058 case OP_DUMMY_STORE:
4059 case OP_NOT_REACHED:
4063 case OP_SEQ_POINT: {
4066 if (cfg->compile_aot)
4070 * Read from the single stepping trigger page. This will cause a
4071 * SIGSEGV when single stepping is enabled.
4072 * We do this _before_ the breakpoint, so single stepping after
4073 * a breakpoint is hit will step to the next IL offset.
4075 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4076 breakpointCode.pTrigger = ss_trigger_page;
4077 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4078 code += BREAKPOINT_SIZE;
4081 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4084 * A placeholder for a possible breakpoint inserted by
4085 * mono_arch_set_breakpoint ().
4087 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4091 * Add an additional nop so skipping the bp doesn't cause the ip to point
4092 * to another IL offset.
4100 EMIT_UNCOND_BRANCH(ins);
4103 s390_br (code, ins->sreg1);
4109 s390_lghi(code, ins->dreg, 1);
4111 s390_lghi(code, ins->dreg, 0);
4117 s390_lghi(code, ins->dreg, 1);
4119 s390_lghi(code, ins->dreg, 0);
4125 s390_lghi(code, ins->dreg, 1);
4127 s390_lghi(code, ins->dreg, 0);
4133 s390_lghi(code, ins->dreg, 1);
4135 s390_lghi(code, ins->dreg, 0);
4141 s390_lghi(code, ins->dreg, 1);
4143 s390_lghi(code, ins->dreg, 0);
4146 case OP_COND_EXC_EQ:
4147 case OP_COND_EXC_IEQ:
4148 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4150 case OP_COND_EXC_NE_UN:
4151 case OP_COND_EXC_INE_UN:
4152 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4154 case OP_COND_EXC_LT:
4155 case OP_COND_EXC_ILT:
4156 case OP_COND_EXC_LT_UN:
4157 case OP_COND_EXC_ILT_UN:
4158 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4160 case OP_COND_EXC_GT:
4161 case OP_COND_EXC_IGT:
4162 case OP_COND_EXC_GT_UN:
4163 case OP_COND_EXC_IGT_UN:
4164 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4166 case OP_COND_EXC_GE:
4167 case OP_COND_EXC_IGE:
4168 case OP_COND_EXC_GE_UN:
4169 case OP_COND_EXC_IGE_UN:
4170 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4172 case OP_COND_EXC_LE:
4173 case OP_COND_EXC_ILE:
4174 case OP_COND_EXC_LE_UN:
4175 case OP_COND_EXC_ILE_UN:
4176 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4178 case OP_COND_EXC_OV:
4179 case OP_COND_EXC_IOV:
4180 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4182 case OP_COND_EXC_NO:
4183 case OP_COND_EXC_INO:
4184 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4187 case OP_COND_EXC_IC:
4188 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4190 case OP_COND_EXC_NC:
4191 case OP_COND_EXC_INC:
4192 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4196 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4200 EMIT_COND_BRANCH (ins, S390_CC_NE);
4206 EMIT_COND_BRANCH (ins, S390_CC_LT);
4212 EMIT_COND_BRANCH (ins, S390_CC_GT);
4218 EMIT_COND_BRANCH (ins, S390_CC_GE);
4224 EMIT_COND_BRANCH (ins, S390_CC_LE);
4227 /* floating point opcodes */
4229 if (*((double *) ins->inst_p0) == 0) {
4230 s390_lzdr (code, ins->dreg);
4232 S390_SET (code, s390_r13, ins->inst_p0);
4233 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4238 if (*((float *) ins->inst_p0) == 0) {
4239 s390_lzdr (code, ins->dreg);
4241 S390_SET (code, s390_r13, ins->inst_p0);
4242 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4246 case OP_STORER8_MEMBASE_REG: {
4247 S390_LONG (code, stdy, std, ins->sreg1, 0,
4248 ins->inst_destbasereg, ins->inst_offset);
4251 case OP_LOADR8_MEMBASE: {
4252 S390_LONG (code, ldy, ld, ins->dreg, 0,
4253 ins->inst_basereg, ins->inst_offset);
4256 case OP_STORER4_MEMBASE_REG: {
4257 s390_ledbr (code, s390_f15, ins->sreg1);
4258 S390_LONG (code, stey, ste, s390_f15, 0,
4259 ins->inst_destbasereg, ins->inst_offset);
4262 case OP_LOADR4_MEMBASE: {
4263 S390_LONG (code, ldy, ld, s390_f15, 0,
4264 ins->inst_basereg, ins->inst_offset);
4265 s390_ldebr (code, ins->dreg, s390_f15);
4268 case OP_ICONV_TO_R_UN: {
4269 s390_cdfbr (code, ins->dreg, ins->sreg1);
4270 s390_ltr (code, ins->sreg1, ins->sreg1);
4272 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4273 s390_ldgr (code, s390_f15, s390_r13);
4274 s390_adbr (code, ins->dreg, s390_f15);
4277 case OP_LCONV_TO_R_UN: {
4278 s390_cdgbr (code, ins->dreg, ins->sreg1);
4279 s390_ltgr (code, ins->sreg1, ins->sreg1);
4281 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4282 s390_ldgr (code, s390_f15, s390_r13);
4283 s390_adbr (code, ins->dreg, s390_f15);
4286 case OP_LCONV_TO_R4:
4287 case OP_ICONV_TO_R4: {
4288 s390_cegbr (code, ins->dreg, ins->sreg1);
4289 s390_ldebr (code, ins->dreg, ins->dreg);
4292 case OP_LCONV_TO_R8:
4293 case OP_ICONV_TO_R8: {
4294 s390_cdgbr (code, ins->dreg, ins->sreg1);
4297 case OP_FCONV_TO_I1:
4298 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4300 case OP_FCONV_TO_U1:
4301 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4303 case OP_FCONV_TO_I2:
4304 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4306 case OP_FCONV_TO_U2:
4307 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4309 case OP_FCONV_TO_I4:
4311 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4313 case OP_FCONV_TO_U4:
4315 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4317 case OP_FCONV_TO_I8:
4318 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4320 case OP_LCONV_TO_OVF_I: {
4321 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4323 s390_ltgr (code, ins->sreg2, ins->sreg2);
4324 s390_jnl (code, 0); CODEPTR(code, o[0]);
4325 s390_ltgr (code, ins->sreg1, ins->sreg1);
4326 s390_jnl (code, 0); CODEPTR(code, o[1]);
4327 s390_lhi (code, s390_r13, -1);
4328 s390_cgr (code, ins->sreg1, s390_r13);
4329 s390_jnz (code, 0); CODEPTR(code, o[2]);
4330 if (ins->dreg != ins->sreg2)
4331 s390_lgr (code, ins->dreg, ins->sreg2);
4332 s390_j (code, 0); CODEPTR(code, o[3]);
4333 PTRSLOT(code, o[0]);
4334 s390_jz (code, 0); CODEPTR(code, o[4]);
4335 PTRSLOT(code, o[1]);
4336 PTRSLOT(code, o[2]);
4337 mono_add_patch_info (cfg, code - cfg->native_code,
4338 MONO_PATCH_INFO_EXC, "OverflowException");
4339 s390_brasl (code, s390_r14, 0);
4340 PTRSLOT(code, o[3]);
4341 PTRSLOT(code, o[4]);
4345 s390_lpdbr (code, ins->dreg, ins->sreg1);
4349 s390_sqdbr (code, ins->dreg, ins->sreg1);
4354 s390_adbr (code, ins->dreg, src2);
4358 CHECK_SRCDST_NCOM_F;
4359 s390_sdbr (code, ins->dreg, src2);
4364 s390_mdbr (code, ins->dreg, src2);
4368 CHECK_SRCDST_NCOM_F;
4369 s390_ddbr (code, ins->dreg, src2);
4373 s390_lcdbr (code, ins->dreg, ins->sreg1);
4377 CHECK_SRCDST_NCOM_F;
4378 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4382 s390_cdbr (code, ins->sreg1, ins->sreg2);
4386 s390_cdbr (code, ins->sreg1, ins->sreg2);
4387 s390_lghi (code, ins->dreg, 1);
4389 s390_lghi (code, ins->dreg, 0);
4393 s390_cdbr (code, ins->sreg1, ins->sreg2);
4394 s390_lghi (code, ins->dreg, 1);
4396 s390_lghi (code, ins->dreg, 0);
4400 s390_cdbr (code, ins->sreg1, ins->sreg2);
4401 s390_lghi (code, ins->dreg, 1);
4403 s390_lghi (code, ins->dreg, 0);
4407 s390_cdbr (code, ins->sreg1, ins->sreg2);
4408 s390_lghi (code, ins->dreg, 1);
4410 s390_lghi (code, ins->dreg, 0);
4414 s390_cdbr (code, ins->sreg1, ins->sreg2);
4415 s390_lghi (code, ins->dreg, 1);
4417 s390_lghi (code, ins->dreg, 0);
4422 s390_jo (code, 0); CODEPTR(code, o);
4423 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4428 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4432 s390_jo (code, 0); CODEPTR(code, o);
4433 EMIT_COND_BRANCH (ins, S390_CC_LT);
4438 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4442 s390_jo (code, 0); CODEPTR(code, o);
4443 EMIT_COND_BRANCH (ins, S390_CC_GT);
4448 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4452 s390_jo (code, 0); CODEPTR(code, o);
4453 EMIT_COND_BRANCH (ins, S390_CC_GE);
4458 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4462 s390_jo (code, 0); CODEPTR(code, o);
4463 EMIT_COND_BRANCH (ins, S390_CC_LE);
4468 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4472 s390_lhi (code, s390_r13, 0x7f);
4473 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4474 s390_jz (code, 0); CODEPTR(code, o);
4475 mono_add_patch_info (cfg, code - cfg->native_code,
4476 MONO_PATCH_INFO_EXC, "ArithmeticException");
4477 s390_brasl (code, s390_r14,0);
4481 case OP_S390_MOVE: {
4482 if (ins->backend.size > 0) {
4483 if (ins->backend.size <= 256) {
4484 s390_mvc (code, ins->backend.size, ins->dreg,
4485 ins->inst_offset, ins->sreg1, ins->inst_imm);
4487 s390_lgr (code, s390_r0, ins->dreg);
4488 if (ins->inst_offset > 0) {
4489 if (s390_is_imm16 (ins->inst_offset)) {
4490 s390_aghi (code, s390_r0, ins->inst_offset);
4491 } else if (s390_is_imm32 (ins->inst_offset)) {
4492 s390_agfi (code, s390_r0, ins->inst_offset);
4494 S390_SET (code, s390_r13, ins->inst_offset);
4495 s390_agr (code, s390_r0, s390_r13);
4498 s390_lgr (code, s390_r12, ins->sreg1);
4499 if (ins->inst_imm > 0) {
4500 if (s390_is_imm16 (ins->inst_imm)) {
4501 s390_aghi (code, s390_r12, ins->inst_imm);
4502 } else if (s390_is_imm32 (ins->inst_imm)) {
4503 s390_agfi (code, s390_r12, ins->inst_imm);
4505 S390_SET (code, s390_r13, ins->inst_imm);
4506 s390_agr (code, s390_r12, s390_r13);
4509 if (s390_is_imm16 (ins->backend.size)) {
4510 s390_lghi (code, s390_r1, ins->backend.size);
4511 } else if (s390_is_imm32 (ins->inst_offset)) {
4512 s390_agfi (code, s390_r1, ins->backend.size);
4514 S390_SET (code, s390_r13, ins->backend.size);
4515 s390_agr (code, s390_r1, s390_r13);
4517 s390_lgr (code, s390_r13, s390_r1);
4518 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4524 case OP_ATOMIC_ADD_I8: {
4525 s390_lgr (code, s390_r1, ins->sreg2);
4526 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4527 s390_agr (code, s390_r1, s390_r0);
4528 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4529 s390_jnz (code, -10);
4530 s390_lgr (code, ins->dreg, s390_r1);
4533 case OP_ATOMIC_EXCHANGE_I8: {
4534 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4535 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4536 s390_jnz (code, -6);
4537 s390_lgr (code, ins->dreg, s390_r0);
4540 case OP_ATOMIC_ADD_I4: {
4541 s390_lgfr(code, s390_r1, ins->sreg2);
4542 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4543 s390_agr (code, s390_r1, s390_r0);
4544 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4545 s390_jnz (code, -9);
4546 s390_lgfr(code, ins->dreg, s390_r1);
4549 case OP_ATOMIC_EXCHANGE_I4: {
4550 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4551 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4552 s390_jnz (code, -4);
4553 s390_lgfr(code, ins->dreg, s390_r0);
4556 case OP_S390_BKCHAIN: {
4557 s390_lgr (code, ins->dreg, ins->sreg1);
4558 if (s390_is_imm16 (cfg->stack_offset)) {
4559 s390_aghi (code, ins->dreg, cfg->stack_offset);
4560 } else if (s390_is_imm32 (cfg->stack_offset)) {
4561 s390_agfi (code, ins->dreg, cfg->stack_offset);
4563 S390_SET (code, s390_r13, cfg->stack_offset);
4564 s390_agr (code, ins->dreg, s390_r13);
4568 case OP_MEMORY_BARRIER: {
4571 case OP_GC_LIVENESS_DEF:
4572 case OP_GC_LIVENESS_USE:
4573 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4574 ins->backend.pc_offset = code - cfg->native_code;
4576 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4577 ins->backend.pc_offset = code - cfg->native_code;
4578 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4581 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4582 g_assert_not_reached ();
4585 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4586 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4587 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4588 g_assert_not_reached ();
4593 last_offset = offset;
4596 cfg->code_len = code - cfg->native_code;
4599 /*========================= End of Function ========================*/
4601 /*------------------------------------------------------------------*/
4603 /* Name - mono_arch_register_lowlevel_calls */
4605 /* Function - Register routines to help with --trace operation. */
4607 /*------------------------------------------------------------------*/
4610 mono_arch_register_lowlevel_calls (void)
4614 /*========================= End of Function ========================*/
4616 /*------------------------------------------------------------------*/
4618 /* Name - mono_arch_patch_code */
4620 /* Function - Process the patch data created during the */
4621 /* instruction build process. This resolves jumps, */
4622 /* calls, variables etc. */
4624 /*------------------------------------------------------------------*/
4627 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4628 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4630 MonoJumpInfo *patch_info;
4632 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4633 unsigned char *ip = patch_info->ip.i + code;
4634 gconstpointer target = NULL;
4636 target = mono_resolve_patch_target (method, domain, code,
4637 patch_info, run_cctors);
4639 switch (patch_info->type) {
4640 case MONO_PATCH_INFO_IP:
4641 case MONO_PATCH_INFO_LDSTR:
4642 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4643 case MONO_PATCH_INFO_LDTOKEN:
4644 case MONO_PATCH_INFO_EXC:
4645 s390_patch_addr (ip, (guint64) target);
4647 case MONO_PATCH_INFO_METHOD:
4648 case MONO_PATCH_INFO_INTERNAL_METHOD:
4649 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4650 case MONO_PATCH_INFO_CLASS_INIT:
4651 case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
4652 case MONO_PATCH_INFO_RGCTX_FETCH:
4653 case MONO_PATCH_INFO_ABS: {
4654 S390_EMIT_CALL (ip, target);
4657 case MONO_PATCH_INFO_SWITCH:
4658 /*----------------------------------*/
4659 /* ip points at the basr r13,0/j +4 */
4660 /* instruction the vtable value */
4661 /* follows this (i.e. ip+6) */
4662 /*----------------------------------*/
4663 S390_EMIT_LOAD (ip, target);
4665 case MONO_PATCH_INFO_METHODCONST:
4666 case MONO_PATCH_INFO_CLASS:
4667 case MONO_PATCH_INFO_IMAGE:
4668 case MONO_PATCH_INFO_FIELD:
4669 case MONO_PATCH_INFO_IID:
4670 case MONO_PATCH_INFO_EXC_NAME:
4671 target = S390_RELATIVE(target, ip);
4672 s390_patch_rel (ip, (guint64) target);
4674 case MONO_PATCH_INFO_R4:
4675 case MONO_PATCH_INFO_R8:
4676 case MONO_PATCH_INFO_METHOD_REL:
4677 g_assert_not_reached ();
4680 target = S390_RELATIVE(target, ip);
4682 s390_patch_rel (ip, (guint64) target);
4687 /*========================= End of Function ========================*/
4689 /*------------------------------------------------------------------*/
4691 /* Name - emit_load_volatile_arguments */
4693 /* Function - Emit the instructions to reload parameter regist- */
4694 /* registers for use with "tail" operations. */
4696 /* The register loading operations performed here */
4697 /* are the mirror of the store operations performed */
4698 /* in mono_arch_emit_prolog and need to be kept in */
4699 /* synchronization with it. */
4701 /*------------------------------------------------------------------*/
4704 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4707 MonoMethod *method = cfg->method;
4708 MonoMethodSignature *sig = mono_method_signature(method);
4712 cinfo = get_call_info (NULL, NULL, sig);
4714 if (cinfo->struct_ret) {
4715 ArgInfo *ainfo = &cinfo->ret;
4716 inst = cfg->vret_addr;
4717 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4720 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4721 ArgInfo *ainfo = cinfo->args + i;
4722 inst = cfg->args [pos];
4724 if (inst->opcode == OP_REGVAR) {
4725 if (ainfo->regtype == RegTypeGeneral)
4726 s390_lgr (code, ainfo->reg, inst->dreg);
4727 else if (ainfo->regtype == RegTypeFP) {
4728 if (inst->dreg != ainfo->reg) {
4729 if (ainfo->size == 4) {
4730 s390_ldebr (code, ainfo->reg, inst->dreg);
4732 s390_ldr (code, ainfo->reg, inst->dreg);
4736 else if (ainfo->regtype == RegTypeBase) {
4738 g_assert_not_reached ();
4740 if (ainfo->regtype == RegTypeGeneral) {
4741 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4742 g_assert_not_reached();
4743 switch (ainfo->size) {
4745 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4748 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4751 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4754 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4757 } else if (ainfo->regtype == RegTypeBase) {
4758 } else if (ainfo->regtype == RegTypeFP) {
4759 if (ainfo->size == 8)
4760 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4761 else if (ainfo->size == 4)
4762 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4764 g_assert_not_reached ();
4765 } else if (ainfo->regtype == RegTypeStructByVal) {
4766 if (ainfo->reg != STK_BASE) {
4767 switch (ainfo->size) {
4769 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4772 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4775 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4778 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4782 } else if (ainfo->regtype == RegTypeStructByAddr) {
4783 if (ainfo->reg != STK_BASE) {
4784 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4787 g_assert_not_reached ();
4795 /*========================= End of Function ========================*/
4797 /*------------------------------------------------------------------*/
4799 /* Name - mono_arch_emit_prolog */
4801 /* Function - Create the instruction sequence for a function */
4804 /*------------------------------------------------------------------*/
4807 mono_arch_emit_prolog (MonoCompile *cfg)
4809 MonoMethod *method = cfg->method;
4811 MonoMethodSignature *sig;
4813 long alloc_size, pos, max_offset, i, cfa_offset = 0;
4820 cfg->code_size = 512;
4822 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4824 cfg->code_size += 256;
4825 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4826 cfg->code_size += 256;
4828 if (method->save_lmf)
4829 cfg->code_size += 200;
4831 cfg->native_code = code = g_malloc (cfg->code_size);
4833 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
4834 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
4835 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4836 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
4838 if (cfg->arch.bkchain_reg != -1)
4839 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4841 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4842 cfg->used_int_regs |= 1 << 11;
4845 alloc_size = cfg->stack_offset;
4847 cfg->stack_usage = cfa_offset = alloc_size;
4848 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
4849 s390_lgr (code, s390_r11, STK_BASE);
4850 if (s390_is_imm16 (alloc_size)) {
4851 s390_aghi (code, STK_BASE, -alloc_size);
4852 } else if (s390_is_imm32 (alloc_size)) {
4853 s390_agfi (code, STK_BASE, -alloc_size);
4855 int stackSize = alloc_size;
4856 while (stackSize > INT_MAX) {
4857 s390_agfi (code, STK_BASE, -INT_MAX);
4858 stackSize -= INT_MAX;
4860 s390_agfi (code, STK_BASE, -stackSize);
4862 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4864 if (cfg->frame_reg != STK_BASE)
4865 s390_lgr (code, s390_r11, STK_BASE);
4867 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
4869 /* store runtime generic context */
4870 if (cfg->rgctx_var) {
4871 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
4873 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
4874 cfg->rgctx_var->inst_basereg,
4875 cfg->rgctx_var->inst_offset);
4878 /* compute max_offset in order to use short forward jumps
4879 * we always do it on s390 because the immediate displacement
4880 * for jumps is too small
4883 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4885 bb->max_offset = max_offset;
4887 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4890 MONO_BB_FOR_EACH_INS (bb, ins)
4891 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4894 /* load arguments allocated to register from the stack */
4895 sig = mono_method_signature (method);
4898 cinfo = get_call_info (cfg, cfg->mempool, sig);
4900 if (cinfo->struct_ret) {
4901 ArgInfo *ainfo = &cinfo->ret;
4902 inst = cfg->vret_addr;
4903 inst->backend.size = ainfo->vtsize;
4904 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4907 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4908 ArgInfo *ainfo = cinfo->args + i;
4909 inst = cfg->args [pos];
4911 if (inst->opcode == OP_VTARG_ADDR)
4912 inst = inst->inst_left;
4914 if (inst->opcode == OP_REGVAR) {
4915 if (ainfo->regtype == RegTypeGeneral)
4916 s390_lgr (code, inst->dreg, ainfo->reg);
4917 else if (ainfo->regtype == RegTypeFP) {
4918 if (inst->dreg != ainfo->reg) {
4919 if (ainfo->size == 4) {
4920 s390_ledbr (code, inst->dreg, ainfo->reg);
4922 s390_ldr (code, inst->dreg, ainfo->reg);
4926 else if (ainfo->regtype == RegTypeBase) {
4927 s390_lgr (code, s390_r13, STK_BASE);
4928 s390_aghi (code, s390_r13, alloc_size);
4929 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4931 g_assert_not_reached ();
4933 if (cfg->verbose_level > 2)
4934 g_print ("Argument %d assigned to register %s\n",
4935 pos, mono_arch_regname (inst->dreg));
4937 if (ainfo->regtype == RegTypeGeneral) {
4938 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4939 g_assert_not_reached();
4940 switch (ainfo->size) {
4942 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4945 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4948 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4951 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4954 } else if (ainfo->regtype == RegTypeBase) {
4955 } else if (ainfo->regtype == RegTypeFP) {
4956 if (ainfo->size == 8)
4957 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4958 else if (ainfo->size == 4)
4959 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4961 g_assert_not_reached ();
4962 } else if (ainfo->regtype == RegTypeStructByVal) {
4963 int doffset = inst->inst_offset;
4965 if (ainfo->reg != STK_BASE)
4969 s390_lgr (code, s390_r13, STK_BASE);
4970 s390_aghi (code, s390_r13, alloc_size);
4973 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
4974 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
4979 if (ainfo->reg == STK_BASE)
4980 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
4981 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4984 if (ainfo->reg == STK_BASE)
4985 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
4986 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4989 if (ainfo->reg == STK_BASE)
4990 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
4991 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4994 if (ainfo->reg == STK_BASE)
4995 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
4996 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
4999 } else if (ainfo->regtype == RegTypeStructByAddr) {
5000 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5001 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5003 g_assert_not_reached ();
5008 if (method->save_lmf) {
5009 /*---------------------------------------------------------------*/
5010 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5011 /*---------------------------------------------------------------*/
5012 lmfOffset = alloc_size - sizeof(MonoLMF);
5014 s390_lgr (code, s390_r13, cfg->frame_reg);
5015 s390_aghi (code, s390_r13, lmfOffset);
5017 /*---------------------------------------------------------------*/
5018 /* Preserve the parameter registers while we fix up the lmf */
5019 /*---------------------------------------------------------------*/
5020 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5021 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5023 /*---------------------------------------------------------------*/
5024 /* On return from this call r2 have the address of the &lmf */
5025 /*---------------------------------------------------------------*/
5026 if (lmf_addr_tls_offset == -1) {
5027 mono_add_patch_info (cfg, code - cfg->native_code,
5028 MONO_PATCH_INFO_INTERNAL_METHOD,
5029 (gpointer)"mono_get_lmf_addr");
5030 S390_CALL_TEMPLATE(code, s390_r1);
5032 /*-------------------------------------------------------*/
5033 /* Get LMF by getting value from thread level storage */
5034 /*-------------------------------------------------------*/
5035 s390_ear (code, s390_r1, 0);
5036 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5037 s390_ear (code, s390_r1, 1);
5038 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5041 /*---------------------------------------------------------------*/
5042 /* Set lmf.lmf_addr = jit_tls->lmf */
5043 /*---------------------------------------------------------------*/
5044 s390_stg (code, s390_r2, 0, s390_r13,
5045 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5047 /*---------------------------------------------------------------*/
5048 /* Get current lmf */
5049 /*---------------------------------------------------------------*/
5050 s390_lg (code, s390_r0, 0, s390_r2, 0);
5052 /*---------------------------------------------------------------*/
5053 /* Set our lmf as the current lmf */
5054 /*---------------------------------------------------------------*/
5055 s390_stg (code, s390_r13, 0, s390_r2, 0);
5057 /*---------------------------------------------------------------*/
5058 /* Have our lmf.previous_lmf point to the last lmf */
5059 /*---------------------------------------------------------------*/
5060 s390_stg (code, s390_r0, 0, s390_r13,
5061 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5063 /*---------------------------------------------------------------*/
5064 /* save method info */
5065 /*---------------------------------------------------------------*/
5066 S390_SET (code, s390_r1, method);
5067 s390_stg (code, s390_r1, 0, s390_r13,
5068 G_STRUCT_OFFSET(MonoLMF, method));
5070 /*---------------------------------------------------------------*/
5071 /* save the current IP */
5072 /*---------------------------------------------------------------*/
5073 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5074 s390_basr (code, s390_r1, 0);
5075 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5077 /*---------------------------------------------------------------*/
5078 /* Save general and floating point registers */
5079 /*---------------------------------------------------------------*/
5080 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5081 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5082 for (i = 0; i < 16; i++) {
5083 s390_std (code, i, 0, s390_r13,
5084 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5087 /*---------------------------------------------------------------*/
5088 /* Restore the parameter registers now that we've set up the lmf */
5089 /*---------------------------------------------------------------*/
5090 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5091 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5095 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5097 cfg->code_len = code - cfg->native_code;
5098 g_assert (cfg->code_len < cfg->code_size);
5103 /*========================= End of Function ========================*/
5105 /*------------------------------------------------------------------*/
5107 /* Name - mono_arch_emit_epilog */
5109 /* Function - Emit the instructions for a function epilog. */
5111 /*------------------------------------------------------------------*/
5114 mono_arch_emit_epilog (MonoCompile *cfg)
5116 MonoMethod *method = cfg->method;
5119 int max_epilog_size = 96;
5121 if (cfg->method->save_lmf)
5122 max_epilog_size += 128;
5124 if (mono_jit_trace_calls != NULL)
5125 max_epilog_size += 128;
5126 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5127 max_epilog_size += 128;
5129 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5130 cfg->code_size *= 2;
5131 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5132 cfg->stat_code_reallocs++;
5135 code = cfg->native_code + cfg->code_len;
5137 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5138 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5142 if (method->save_lmf)
5143 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5145 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5146 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5148 code = backUpStackPtr(cfg, code);
5150 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5151 s390_br (code, s390_r14);
5153 cfg->code_len = code - cfg->native_code;
5155 g_assert (cfg->code_len < cfg->code_size);
5159 /*========================= End of Function ========================*/
5161 /*------------------------------------------------------------------*/
5163 /* Name - mono_arch_emit_exceptions */
5165 /* Function - Emit the blocks to handle exception conditions. */
5167 /*------------------------------------------------------------------*/
5170 mono_arch_emit_exceptions (MonoCompile *cfg)
5172 MonoJumpInfo *patch_info;
5178 MonoClass *exc_classes [MAX_EXC];
5179 guint8 *exc_throw_start [MAX_EXC];
5181 for (patch_info = cfg->patch_info;
5183 patch_info = patch_info->next) {
5184 if (patch_info->type == MONO_PATCH_INFO_EXC)
5188 code_size = exc_count * 48;
5190 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5191 cfg->code_size *= 2;
5192 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5193 cfg->stat_code_reallocs++;
5196 code = cfg->native_code + cfg->code_len;
5198 /*---------------------------------------------------------------------*/
5199 /* Add code to raise exceptions */
5200 /*---------------------------------------------------------------------*/
5201 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5202 switch (patch_info->type) {
5203 case MONO_PATCH_INFO_EXC: {
5204 guint8 *ip = patch_info->ip.i + cfg->native_code;
5205 MonoClass *exc_class;
5208 /*-----------------------------------------------------*/
5209 /* Patch the branch in epilog to come here */
5210 /*-----------------------------------------------------*/
5211 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5213 exc_class = mono_class_from_name (mono_defaults.corlib,
5215 patch_info->data.name);
5216 g_assert (exc_class);
5217 throw_ip = patch_info->ip.i;
5219 for (iExc = 0; iExc < nThrows; ++iExc)
5220 if (exc_classes [iExc] == exc_class)
5223 if (iExc < nThrows) {
5224 s390_jcl (code, S390_CC_UN,
5225 (guint64) exc_throw_start [iExc]);
5226 patch_info->type = MONO_PATCH_INFO_NONE;
5229 if (nThrows < MAX_EXC) {
5230 exc_classes [nThrows] = exc_class;
5231 exc_throw_start [nThrows] = code;
5234 /*---------------------------------------------*/
5235 /* Patch the parameter passed to the handler */
5236 /*---------------------------------------------*/
5237 S390_SET (code, s390_r2, exc_class->type_token);
5238 /*---------------------------------------------*/
5239 /* Load return address & parameter register */
5240 /*---------------------------------------------*/
5241 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5242 cfg->native_code + 8), code));
5243 /*---------------------------------------------*/
5244 /* Reuse the current patch to set the jump */
5245 /*---------------------------------------------*/
5246 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5247 patch_info->data.name = "mono_arch_throw_corlib_exception";
5248 patch_info->ip.i = code - cfg->native_code;
5249 S390_BR_TEMPLATE (code, s390_r1);
5259 cfg->code_len = code - cfg->native_code;
5261 g_assert (cfg->code_len < cfg->code_size);
5265 /*========================= End of Function ========================*/
5267 /*------------------------------------------------------------------*/
5269 /* Name - mono_arch_finish_init */
5271 /* Function - Setup the JIT's Thread Level Specific Data. */
5273 /*------------------------------------------------------------------*/
5276 mono_arch_finish_init (void)
5278 appdomain_tls_offset = mono_domain_get_tls_offset();
5279 lmf_tls_offset = mono_get_lmf_tls_offset();
5280 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5283 /*========================= End of Function ========================*/
5285 /*------------------------------------------------------------------*/
5287 /* Name - mono_arch_free_jit_tls_data */
5289 /* Function - Free tls data. */
5291 /*------------------------------------------------------------------*/
5294 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5298 /*========================= End of Function ========================*/
5300 /*------------------------------------------------------------------*/
5302 /* Name - mono_arch_emit_inst_for_method */
5304 /*------------------------------------------------------------------*/
5307 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5312 /*========================= End of Function ========================*/
5314 /*------------------------------------------------------------------*/
5316 /* Name - mono_arch_decompose_opts */
5318 /* Function - Decompose opcode into a System z opcode. */
5320 /*------------------------------------------------------------------*/
5323 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5326 * Have to rename these to avoid being decomposed normally, since the normal
5327 * decomposition does not work on S390.
5329 switch (ins->opcode) {
5331 ins->opcode = OP_S390_ISUB_OVF;
5333 case OP_ISUB_OVF_UN:
5334 ins->opcode = OP_S390_ISUB_OVF_UN;
5337 ins->opcode = OP_S390_IADD_OVF;
5339 case OP_IADD_OVF_UN:
5340 ins->opcode = OP_S390_IADD_OVF_UN;
5343 ins->opcode = OP_S390_LADD_OVF;
5345 case OP_LADD_OVF_UN:
5346 ins->opcode = OP_S390_LADD_OVF_UN;
5349 ins->opcode = OP_S390_LSUB_OVF;
5351 case OP_LSUB_OVF_UN:
5352 ins->opcode = OP_S390_LSUB_OVF_UN;
5359 /*========================= End of Function ========================*/
5361 /*------------------------------------------------------------------*/
5363 /* Name - mono_arch_print_tree */
5365 /* Function - Print platform-specific opcode details. */
5367 /* Returns - 1 - opcode details have been printed */
5368 /* 0 - opcode details have not been printed */
5370 /*------------------------------------------------------------------*/
5373 mono_arch_print_tree (MonoInst *tree, int arity)
5377 switch (tree->opcode) {
5378 case OP_S390_LOADARG:
5379 case OP_S390_ARGREG:
5380 case OP_S390_ARGPTR:
5381 printf ("[0x%lx(%s)]", tree->inst_offset,
5382 mono_arch_regname (tree->inst_basereg));
5385 case OP_S390_STKARG:
5386 printf ("[0x%lx(previous_frame)]",
5391 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5392 tree->inst_offset, tree->backend.size,
5393 mono_arch_regname(tree->dreg),
5395 mono_arch_regname(tree->sreg1));
5398 case OP_S390_SETF4RET:
5399 printf ("[f%s,f%s]",
5400 mono_arch_regname (tree->dreg),
5401 mono_arch_regname (tree->sreg1));
5405 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5407 mono_arch_regname (tree->sreg1));
5410 case OP_S390_BKCHAIN:
5411 printf ("[previous_frame(%s)]",
5412 mono_arch_regname (tree->sreg1));
5420 /*========================= End of Function ========================*/
5422 /*------------------------------------------------------------------*/
5424 /* Name - mono_arch_regalloc_cost */
5426 /* Function - Determine the cost, in the number of memory */
5427 /* references, of the action of allocating the var- */
5428 /* iable VMV into a register during global register */
5431 /* Returns - Cost */
5433 /*------------------------------------------------------------------*/
5436 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5442 /*========================= End of Function ========================*/
5444 /*------------------------------------------------------------------*/
5446 /* Name - mono_arch_flush_register_windows */
5452 /*------------------------------------------------------------------*/
5455 mono_arch_flush_register_windows (void)
5459 /*========================= End of Function ========================*/
5461 /*------------------------------------------------------------------*/
5463 /* Name - mono_arch_is_inst_imm */
5465 /* Function - Determine if operand qualifies as an immediate */
5466 /* value. For s390 this is a value -32768-32768 */
5468 /* Returns - True|False - is [not] immediate value. */
5470 /*------------------------------------------------------------------*/
5473 mono_arch_is_inst_imm (gint64 imm)
5475 return s390_is_imm32 (imm);
5478 /*========================= End of Function ========================*/
5480 /*------------------------------------------------------------------*/
5482 /* Name - mono_arch_get_patch_offset */
5484 /* Function - Dummy entry point until s390x supports aot. */
5486 /* Returns - Offset for patch. */
5488 /*------------------------------------------------------------------*/
5491 mono_arch_get_patch_offset (guint8 *code)
5496 /*========================= End of Function ========================*/
5498 /*------------------------------------------------------------------*/
5500 /* Name - mono_arch_context_get_int_reg. */
5504 /* Returns - Return a register from the context. */
5506 /*------------------------------------------------------------------*/
5509 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5511 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5514 /*========================= End of Function ========================*/
5516 /*------------------------------------------------------------------*/
5518 /* Name - mono_arch_context_set_int_reg. */
5520 /* Function - Set a value in a specified register. */
5522 /*------------------------------------------------------------------*/
5525 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5527 ctx->uc_mcontext.gregs[reg] = val;
5530 /*========================= End of Function ========================*/
5532 /*------------------------------------------------------------------*/
5534 /* Name - mono_arch_get_this_arg_from_call. */
5538 /*------------------------------------------------------------------*/
5541 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5543 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5545 return (gpointer) lmf->gregs [s390_r2];
5548 /*========================= End of Function ========================*/
5550 /*------------------------------------------------------------------*/
5552 /* Name - mono_arch_install_handler_block_guard */
5556 /*------------------------------------------------------------------*/
5559 mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause,
5560 MonoContext *ctx, gpointer new_value)
5563 gpointer *sp, old_value;
5566 offset = clause->exvar_offset;
5569 bp = MONO_CONTEXT_GET_BP (ctx);
5570 sp = *(gpointer*)(bp + offset);
5573 if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size))
5581 /*========================= End of Function ========================*/
5583 /*------------------------------------------------------------------*/
5585 /* Name - get_delegate_invoke_impl. */
5589 /*------------------------------------------------------------------*/
5592 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5594 guint8 *code, *start;
5599 start = code = mono_global_codeman_reserve (size);
5601 /* Replace the this argument with the target */
5602 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5603 s390_lg (code, s390_r2, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, target));
5604 s390_br (code, s390_r1);
5605 g_assert ((code - start) <= size);
5607 mono_arch_flush_icache (start, size);
5611 size = 32 + param_count * 8;
5612 start = code = mono_global_codeman_reserve (size);
5614 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5615 /* slide down the arguments */
5616 for (i = 0; i < param_count; ++i) {
5617 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5619 s390_br (code, s390_r1);
5621 g_assert ((code - start) <= size);
5623 mono_arch_flush_icache (start, size);
5627 *code_len = code - start;
5632 /*========================= End of Function ========================*/
5634 /*------------------------------------------------------------------*/
5636 /* Name - mono_arch_get_delegate_invoke_impls. */
5640 /*------------------------------------------------------------------*/
5643 mono_arch_get_delegate_invoke_impls (void)
5651 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5652 res = g_slist_prepend (res, mono_tramp_info_create ("delegate_invoke_impl_has_target", code, code_len, NULL, NULL));
5654 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5655 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5656 tramp_name = g_strdup_printf ("delegate_invoke_impl_target_%d", i);
5657 res = g_slist_prepend (res, mono_tramp_info_create (tramp_name, code, code_len, NULL, NULL));
5658 g_free (tramp_name);
5664 /*========================= End of Function ========================*/
5666 /*------------------------------------------------------------------*/
5668 /* Name - mono_arch_get_delegate_invoke_impl. */
5672 /*------------------------------------------------------------------*/
5675 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5677 guint8 *code, *start;
5679 /* FIXME: Support more cases */
5680 if (MONO_TYPE_ISSTRUCT (sig->ret))
5684 static guint8* cached = NULL;
5690 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5692 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5694 mono_memory_barrier ();
5698 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5701 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5703 for (i = 0; i < sig->param_count; ++i)
5704 if (!mono_is_regsize_var (sig->params [i]))
5708 code = cache [sig->param_count];
5712 if (mono_aot_only) {
5713 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5714 start = mono_aot_get_trampoline (name);
5717 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5720 mono_memory_barrier ();
5722 cache [sig->param_count] = start;
5727 /*========================= End of Function ========================*/
5729 /*------------------------------------------------------------------*/
5731 /* Name - mono_arch_get_delegate_virtual_invoke_impl. */
5735 /*------------------------------------------------------------------*/
5738 mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method, int offset, gboolean load_imt_reg)
5743 /*========================= End of Function ========================*/
5745 /*------------------------------------------------------------------*/
5747 /* Name - mono_arch_build_imt_thunk. */
5751 /*------------------------------------------------------------------*/
5754 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5755 MonoIMTCheckItem **imt_entries, int count,
5756 gpointer fail_tramp)
5760 guchar *code, *start;
5762 for (i = 0; i < count; ++i) {
5763 MonoIMTCheckItem *item = imt_entries [i];
5764 if (item->is_equals) {
5765 if (item->check_target_idx) {
5766 if (!item->compare_done)
5767 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5768 if (item->has_target_code)
5769 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5771 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5775 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5777 if (!item->has_target_code)
5778 item->chunk_size += LOAD_SIZE;
5780 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5781 #if ENABLE_WRONG_METHOD_CHECK
5782 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5787 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5788 imt_entries [item->check_target_idx]->compare_done = TRUE;
5790 size += item->chunk_size;
5794 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5796 code = mono_domain_code_reserve (domain, size);
5800 for (i = 0; i < count; ++i) {
5801 MonoIMTCheckItem *item = imt_entries [i];
5802 item->code_target = (guint8 *) code;
5803 if (item->is_equals) {
5804 if (item->check_target_idx) {
5805 if (!item->compare_done) {
5806 S390_SET (code, s390_r0, item->key);
5807 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5809 item->jmp_code = (guint8*) code;
5810 s390_jcl (code, S390_CC_NE, 0);
5812 if (item->has_target_code) {
5813 S390_SET (code, s390_r1, item->value.target_code);
5815 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5816 s390_lg (code, s390_r1, 0, s390_r1, 0);
5818 s390_br (code, s390_r1);
5823 S390_SET (code, s390_r0, item->key);
5824 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5825 item->jmp_code = (guint8*) code;
5826 s390_jcl (code, S390_CC_NE, 0);
5827 if (item->has_target_code) {
5828 S390_SET (code, s390_r1, item->value.target_code);
5831 S390_SET (code, s390_r1,
5832 (&(vtable->vtable [item->value.vtable_slot])));
5833 s390_lg (code, s390_r1, 0, s390_r1, 0);
5835 s390_br (code, s390_r1);
5836 target = S390_RELATIVE(code, item->jmp_code);
5837 s390_patch_rel(item->jmp_code+2, target);
5838 S390_SET (code, s390_r1, fail_tramp);
5839 s390_br (code, s390_r1);
5840 item->jmp_code = NULL;
5842 /* enable the commented code to assert on wrong method */
5843 #if ENABLE_WRONG_METHOD_CHECK
5844 g_assert_not_reached ();
5846 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5847 s390_lg (code, s390_r1, 0, s390_r1, 0);
5848 s390_br (code, s390_r1);
5852 S390_SET (code, s390_r0, item->key);
5853 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5854 item->jmp_code = (guint8 *) code;
5855 s390_jcl (code, S390_CC_GE, 0);
5859 * patch the branches to get to the target items
5861 for (i = 0; i < count; ++i) {
5862 MonoIMTCheckItem *item = imt_entries [i];
5863 if (item->jmp_code) {
5864 if (item->check_target_idx) {
5866 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5868 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5873 mono_arch_flush_icache ((guint8*)start, (code - start));
5876 mono_stats.imt_thunks_size += (code - start);
5878 g_assert (code - start <= size);
5883 /*========================= End of Function ========================*/
5885 /*------------------------------------------------------------------*/
5887 /* Name - mono_arch_find_imt_method. */
5889 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5890 /* found in the save area. */
5892 /*------------------------------------------------------------------*/
5895 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5897 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5899 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
5902 /*========================= End of Function ========================*/
5904 /*------------------------------------------------------------------*/
5906 /* Name - mono_arch_find_static_call_vtable */
5908 /* Function - Find the static call vtable. */
5910 /*------------------------------------------------------------------*/
5913 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
5915 mgreg_t *r = (mgreg_t*)regs;
5917 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
5920 /*========================= End of Function ========================*/
5922 /*------------------------------------------------------------------*/
5924 /* Name - mono_arch_get_cie_program */
5926 /* Function - Find the static call vtable. */
5928 /*------------------------------------------------------------------*/
5931 mono_arch_get_cie_program (void)
5935 mono_add_unwind_op_def_cfa (l, NULL, NULL, STK_BASE, 0);
5940 /*========================= End of Function ========================*/
5942 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
5944 /*------------------------------------------------------------------*/
5946 /* Name - mono_arch_set_breakpoint. */
5948 /* Function - Set a breakpoint at the native code corresponding */
5949 /* to JI at NATIVE_OFFSET. The location should */
5950 /* contain code emitted by OP_SEQ_POINT. */
5952 /*------------------------------------------------------------------*/
5955 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
5959 breakpointCode.pTrigger = bp_trigger_page;
5960 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
5961 code += BREAKPOINT_SIZE;
5964 /*========================= End of Function ========================*/
5966 /*------------------------------------------------------------------*/
5968 /* Name - mono_arch_clear_breakpoint. */
5970 /* Function - Clear the breakpoint at IP. */
5972 /*------------------------------------------------------------------*/
5975 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
5980 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
5984 /*========================= End of Function ========================*/
5986 /*------------------------------------------------------------------*/
5988 /* Name - mono_arch_is_breakpoint_event. */
5992 /*------------------------------------------------------------------*/
5995 mono_arch_is_breakpoint_event (void *info, void *sigctx)
5997 siginfo_t* sinfo = (siginfo_t*) info;
6000 * Sometimes the address is off by 4
6002 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6008 /*========================= End of Function ========================*/
6010 /*------------------------------------------------------------------*/
6012 /* Name - mono_arch_skip_breakpoint. */
6014 /* Function - Modify the CTX so the IP is placed after the */
6015 /* breakpoint instruction, so when we resume, the */
6016 /* instruction is not executed again. */
6018 /*------------------------------------------------------------------*/
6021 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6023 MONO_CONTEXT_SET_IP (ctx, ((guint8*)MONO_CONTEXT_GET_IP (ctx) + sizeof(RXY_Format)));
6026 /*========================= End of Function ========================*/
6028 /*------------------------------------------------------------------*/
6030 /* Name - mono_arch_start_single_stepping. */
6032 /* Function - Start single stepping. */
6034 /*------------------------------------------------------------------*/
6037 mono_arch_start_single_stepping (void)
6039 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6042 /*========================= End of Function ========================*/
6044 /*------------------------------------------------------------------*/
6046 /* Name - mono_arch_stop_single_stepping. */
6048 /* Function - Stop single stepping. */
6050 /*------------------------------------------------------------------*/
6053 mono_arch_stop_single_stepping (void)
6055 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6058 /*========================= End of Function ========================*/
6060 /*------------------------------------------------------------------*/
6062 /* Name - mono_arch_is_single_step_event. */
6064 /* Function - Return whether the machine state in sigctx cor- */
6065 /* responds to a single step event. */
6067 /*------------------------------------------------------------------*/
6070 mono_arch_is_single_step_event (void *info, void *sigctx)
6072 siginfo_t* sinfo = (siginfo_t*) info;
6075 * Sometimes the address is off by 4
6077 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6083 /*========================= End of Function ========================*/
6085 /*------------------------------------------------------------------*/
6087 /* Name - mono_arch_skip_single_step. */
6089 /* Function - Modify the ctx so the IP is placed after the */
6090 /* single step trigger instruction, so that the */
6091 /* instruction is not executed again. */
6093 /*------------------------------------------------------------------*/
6096 mono_arch_skip_single_step (MonoContext *ctx)
6098 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6101 /*========================= End of Function ========================*/
6103 /*------------------------------------------------------------------*/
6105 /* Name - mono_arch_create_seq_point_info. */
6107 /* Function - Return a pointer to a data struction which is */
6108 /* used by the sequence point implementation in */
6111 /*------------------------------------------------------------------*/
6114 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6120 /*------------------------------------------------------------------*/
6122 /* Name - mono_arch_init_lmf_ext. */
6126 /*------------------------------------------------------------------*/
6129 mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
6131 ext->lmf.previous_lmf = prev_lmf;
6132 /* Mark that this is a MonoLMFExt */
6133 ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
6134 ext->lmf.ebp = (gssize)ext;
6137 /*========================= End of Function ========================*/
6142 mono_arch_opcode_supported (int opcode)
6145 case OP_ATOMIC_ADD_I4:
6146 case OP_ATOMIC_ADD_I8:
6147 case OP_ATOMIC_EXCHANGE_I4:
6148 case OP_ATOMIC_EXCHANGE_I8: