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] ",(void *)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:
2803 case OP_LOCALLOC_IMM:
2804 mono_decompose_op_imm (cfg, bb, ins);
2807 if (!s390_is_imm16 (ins->inst_imm))
2808 /* This is created by the memcpy code which ignores is_inst_imm */
2809 mono_decompose_op_imm (cfg, bb, ins);
2816 bb->max_vreg = cfg->next_vreg;
2819 /*========================= End of Function ========================*/
2821 /*------------------------------------------------------------------*/
2823 /* Name - emit_float_to_int */
2825 /* Function - Create instructions which will convert a floating */
2826 /* point value to integer. */
2828 /*------------------------------------------------------------------*/
2831 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2833 /* sreg is a float, dreg is an integer reg. */
2835 s390_cgdbr (code, dreg, 5, sreg);
2838 s390_lghi (code, s390_r0, 0);
2839 s390_lghi (code, s390_r13, 0xff);
2840 s390_ltgr (code, dreg, dreg);
2842 s390_lghi (code, s390_r0, 0x80);
2843 s390_ngr (code, dreg, s390_r13);
2844 s390_ogr (code, dreg, s390_r0);
2849 S390_SET (code, s390_r13, 0x41e0000000000000llu);
2850 s390_ldgr (code, s390_f14, s390_r13);
2851 s390_ldr (code, s390_f15, sreg);
2852 s390_cdbr (code, s390_f15, s390_f14);
2853 s390_jl (code, 0); CODEPTR (code, o[0]);
2854 S390_SET (code, s390_r13, 0x41f0000000000000llu);
2855 s390_ldgr (code, s390_f14, s390_r13);
2856 s390_sdbr (code, s390_f15, s390_f14);
2857 s390_cfdbr (code, dreg, 7, s390_f15);
2859 PTRSLOT (code, o[0]);
2860 s390_cfdbr (code, dreg, 5, sreg);
2863 s390_lghi (code, s390_r0, 0xff);
2864 s390_ngr (code, dreg, s390_r0);
2867 s390_lghi (code, s390_r0, -1);
2868 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2869 s390_ngr (code, dreg, s390_r0);
2876 /*========================= End of Function ========================*/
2878 /*------------------------------------------------------------------*/
2880 /* Name - gboolean_is_unsigned. */
2882 /* Function - Return TRUE if next opcode is checking for un- */
2885 /*------------------------------------------------------------------*/
2888 gboolean is_unsigned (MonoInst *next)
2891 (((next->opcode >= OP_IBNE_UN) &&
2892 (next->opcode <= OP_IBLT_UN)) ||
2893 ((next->opcode >= OP_LBNE_UN) &&
2894 (next->opcode <= OP_LBLT_UN)) ||
2895 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2896 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2897 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2898 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2899 ((next->opcode == OP_CLT_UN) ||
2900 (next->opcode == OP_CGT_UN)) ||
2901 ((next->opcode == OP_ICLT_UN) ||
2902 (next->opcode == OP_ICGT_UN) ||
2903 (next->opcode == OP_LCLT_UN) ||
2904 (next->opcode == OP_LCGT_UN))))
2910 /*========================= End of Function ========================*/
2912 /*------------------------------------------------------------------*/
2914 /* Name - mono_arch_output_basic_block */
2916 /* Function - Perform the "real" work of emitting instructions */
2917 /* that will do the work of in the basic block. */
2919 /*------------------------------------------------------------------*/
2922 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2927 guint8 *code = cfg->native_code + cfg->code_len;
2928 guint last_offset = 0;
2931 /* we don't align basic blocks of loops on s390 */
2933 if (cfg->verbose_level > 2)
2934 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2936 if ((cfg->prof_options & MONO_PROFILE_COVERAGE) && cfg->coverage_info) {
2937 MonoProfileCoverageInfo *cov = cfg->coverage_info;
2938 g_assert (!mono_compile_aot);
2939 cov->data [bb->dfn].cil_code = bb->cil_code;
2940 /* This is not thread save, but good enough */
2941 S390_SET (code, s390_r1, &cov->data [bb->dfn].count);
2942 s390_alsi (code, 0, s390_r1, 1);
2945 MONO_BB_FOR_EACH_INS (bb, ins) {
2946 offset = code - cfg->native_code;
2948 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2950 if (offset > (cfg->code_size - max_len - 16)) {
2951 cfg->code_size *= 2;
2952 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2953 code = cfg->native_code + offset;
2956 mono_debug_record_line_number (cfg, ins, offset);
2958 switch (ins->opcode) {
2959 case OP_STOREI1_MEMBASE_IMM: {
2960 s390_lghi (code, s390_r0, ins->inst_imm);
2961 S390_LONG (code, stcy, stc, s390_r0, 0,
2962 ins->inst_destbasereg, ins->inst_offset);
2965 case OP_STOREI2_MEMBASE_IMM: {
2966 s390_lghi (code, s390_r0, ins->inst_imm);
2967 S390_LONG (code, sthy, sth, s390_r0, 0,
2968 ins->inst_destbasereg, ins->inst_offset);
2971 case OP_STOREI4_MEMBASE_IMM: {
2972 s390_lgfi (code, s390_r0, ins->inst_imm);
2973 S390_LONG (code, sty, st, s390_r0, 0,
2974 ins->inst_destbasereg, ins->inst_offset);
2977 case OP_STORE_MEMBASE_IMM:
2978 case OP_STOREI8_MEMBASE_IMM: {
2979 S390_SET (code, s390_r0, ins->inst_imm);
2980 S390_LONG (code, stg, stg, s390_r0, 0,
2981 ins->inst_destbasereg, ins->inst_offset);
2984 case OP_STOREI1_MEMBASE_REG: {
2985 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2986 ins->inst_destbasereg, ins->inst_offset);
2989 case OP_STOREI2_MEMBASE_REG: {
2990 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2991 ins->inst_destbasereg, ins->inst_offset);
2994 case OP_STOREI4_MEMBASE_REG: {
2995 S390_LONG (code, sty, st, ins->sreg1, 0,
2996 ins->inst_destbasereg, ins->inst_offset);
2999 case OP_STORE_MEMBASE_REG:
3000 case OP_STOREI8_MEMBASE_REG: {
3001 S390_LONG (code, stg, stg, ins->sreg1, 0,
3002 ins->inst_destbasereg, ins->inst_offset);
3006 g_assert_not_reached ();
3008 case OP_LOAD_MEMBASE:
3009 case OP_LOADI8_MEMBASE: {
3010 S390_LONG (code, lg, lg, ins->dreg, 0,
3011 ins->inst_basereg, ins->inst_offset);
3014 case OP_LOADI4_MEMBASE: {
3015 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3016 ins->inst_basereg, ins->inst_offset);
3019 case OP_LOADU4_MEMBASE: {
3020 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3021 ins->inst_basereg, ins->inst_offset);
3024 case OP_LOADU1_MEMBASE: {
3025 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3026 ins->inst_basereg, ins->inst_offset);
3029 case OP_LOADI1_MEMBASE: {
3030 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3031 ins->inst_basereg, ins->inst_offset);
3034 case OP_LOADU2_MEMBASE: {
3035 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3036 ins->inst_basereg, ins->inst_offset);
3039 case OP_LOADI2_MEMBASE: {
3040 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3041 ins->inst_basereg, ins->inst_offset);
3044 case OP_LCONV_TO_I1: {
3045 s390_lgbr (code, ins->dreg, ins->sreg1);
3048 case OP_LCONV_TO_I2: {
3049 s390_lghr (code, ins->dreg, ins->sreg1);
3052 case OP_LCONV_TO_U1: {
3053 s390_llgcr (code, ins->dreg, ins->sreg1);
3056 case OP_LCONV_TO_U2: {
3057 s390_llghr (code, ins->dreg, ins->sreg1);
3060 case OP_ICONV_TO_I1: {
3061 s390_lgbr (code, ins->dreg, ins->sreg1);
3064 case OP_ICONV_TO_I2: {
3065 s390_lghr (code, ins->dreg, ins->sreg1);
3068 case OP_ICONV_TO_U1: {
3069 s390_llgcr (code, ins->dreg, ins->sreg1);
3072 case OP_ICONV_TO_U2: {
3073 s390_llghr (code, ins->dreg, ins->sreg1);
3078 if (is_unsigned (ins->next))
3079 s390_clgr (code, ins->sreg1, ins->sreg2);
3081 s390_cgr (code, ins->sreg1, ins->sreg2);
3085 if (is_unsigned (ins->next))
3086 s390_clr (code, ins->sreg1, ins->sreg2);
3088 s390_cr (code, ins->sreg1, ins->sreg2);
3091 case OP_COMPARE_IMM:
3092 case OP_LCOMPARE_IMM: {
3093 S390_SET (code, s390_r0, ins->inst_imm);
3094 if (is_unsigned (ins->next))
3095 s390_clgr (code, ins->sreg1, s390_r0);
3097 s390_cgr (code, ins->sreg1, s390_r0);
3100 case OP_ICOMPARE_IMM: {
3101 S390_SET (code, s390_r0, ins->inst_imm);
3102 if (is_unsigned (ins->next))
3103 s390_clr (code, ins->sreg1, s390_r0);
3105 s390_cr (code, ins->sreg1, s390_r0);
3109 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3111 S390_CALL_TEMPLATE (code, s390_r14);
3116 s390_agr (code, ins->dreg, src2);
3121 s390_agr (code, ins->dreg, src2);
3126 s390_alcgr (code, ins->dreg, src2);
3130 if (ins->dreg != ins->sreg1) {
3131 s390_lgr (code, ins->dreg, ins->sreg1);
3133 if (s390_is_imm16 (ins->inst_imm)) {
3134 s390_aghi (code, ins->dreg, ins->inst_imm);
3135 } else if (s390_is_imm32 (ins->inst_imm)) {
3136 s390_agfi (code, ins->dreg, ins->inst_imm);
3138 S390_SET (code, s390_r0, ins->inst_imm);
3139 s390_agr (code, ins->dreg, s390_r0);
3144 if (ins->dreg != ins->sreg1) {
3145 s390_lgr (code, ins->dreg, ins->sreg1);
3147 g_assert (s390_is_imm16 (ins->inst_imm));
3148 s390_aghi (code, ins->dreg, ins->inst_imm);
3152 if (ins->dreg != ins->sreg1) {
3153 s390_lgr (code, ins->dreg, ins->sreg1);
3155 if (s390_is_imm16 (ins->inst_imm)) {
3156 s390_lghi (code, s390_r0, ins->inst_imm);
3157 s390_alcgr (code, ins->dreg, s390_r0);
3159 S390_SET (code, s390_r0, ins->inst_imm);
3160 s390_alcgr (code, ins->dreg, s390_r0);
3165 case OP_S390_IADD_OVF: {
3167 s390_ar (code, ins->dreg, src2);
3168 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3169 s390_lgfr (code, ins->dreg, ins->dreg);
3172 case OP_IADD_OVF_UN:
3173 case OP_S390_IADD_OVF_UN: {
3175 s390_algr (code, ins->dreg, src2);
3176 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3177 s390_llgfr (code, ins->dreg, ins->dreg);
3180 case OP_ADD_OVF_CARRY: {
3182 s390_lghi (code, s390_r0, 0);
3183 s390_lgr (code, s390_r1, s390_r0);
3184 s390_alcgr (code, s390_r0, s390_r1);
3185 s390_agr (code, ins->dreg, src2);
3186 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3187 s390_agr (code, ins->dreg, s390_r0);
3188 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3191 case OP_ADD_OVF_UN_CARRY: {
3193 s390_alcgr (code, ins->dreg, src2);
3194 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3199 s390_sgr (code, ins->dreg, src2);
3204 s390_sgr (code, ins->dreg, src2);
3209 s390_slbgr(code, ins->dreg, src2);
3213 if (ins->dreg != ins->sreg1) {
3214 s390_lgr (code, ins->dreg, ins->sreg1);
3216 if (s390_is_imm16 (-ins->inst_imm)) {
3217 s390_aghi (code, ins->dreg, -ins->inst_imm);
3218 } else if (s390_is_imm32 (-ins->inst_imm)) {
3219 s390_slgfi (code, ins->dreg, ins->inst_imm);
3221 S390_SET (code, s390_r0, ins->inst_imm);
3222 s390_slgr (code, ins->dreg, s390_r0);
3227 if (ins->dreg != ins->sreg1) {
3228 s390_lgr (code, ins->dreg, ins->sreg1);
3230 if (s390_is_imm16 (-ins->inst_imm)) {
3231 s390_aghi (code, ins->dreg, -ins->inst_imm);
3232 } else if (s390_is_imm32 (-ins->inst_imm)) {
3233 s390_slgfi (code, ins->dreg, ins->inst_imm);
3235 S390_SET (code, s390_r0, ins->inst_imm);
3236 s390_slgr (code, ins->dreg, s390_r0);
3241 if (ins->dreg != ins->sreg1) {
3242 s390_lgr (code, ins->dreg, ins->sreg1);
3244 if (s390_is_imm16 (-ins->inst_imm)) {
3245 s390_lghi (code, s390_r0, ins->inst_imm);
3246 s390_slbgr (code, ins->dreg, s390_r0);
3248 S390_SET (code, s390_r0, ins->inst_imm);
3249 s390_slbgr(code, ins->dreg, s390_r0);
3253 case OP_SUB_OVF_CARRY: {
3255 s390_lghi (code, s390_r0, 0);
3256 s390_lgr (code, s390_r1, s390_r0);
3257 s390_slbgr (code, s390_r0, s390_r1);
3258 s390_sgr (code, ins->dreg, src2);
3259 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3260 s390_agr (code, ins->dreg, s390_r0);
3261 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3264 case OP_SUB_OVF_UN_CARRY: {
3266 s390_slbgr (code, ins->dreg, src2);
3267 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3271 if (ins->sreg1 == ins->dreg) {
3272 s390_ngr (code, ins->dreg, ins->sreg2);
3275 if (ins->sreg2 == ins->dreg) {
3276 s390_ngr (code, ins->dreg, ins->sreg1);
3279 s390_lgr (code, ins->dreg, ins->sreg1);
3280 s390_ngr (code, ins->dreg, ins->sreg2);
3286 if (ins->dreg != ins->sreg1) {
3287 s390_lgr (code, ins->dreg, ins->sreg1);
3289 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3290 s390_ngr (code, ins->dreg, s390_r0);
3294 s390_lgr (code, s390_r1, ins->sreg1);
3295 s390_dsgr (code, s390_r0, ins->sreg2);
3296 s390_lgr (code, ins->dreg, s390_r1);
3300 s390_lgr (code, s390_r1, ins->sreg1);
3301 s390_lghi (code, s390_r0, 0);
3302 s390_dlgr (code, s390_r0, ins->sreg2);
3303 s390_lgr (code, ins->dreg, s390_r1);
3307 s390_lgr (code, s390_r1, ins->sreg1);
3308 s390_dsgr (code, s390_r0, ins->sreg2);
3309 s390_lgr (code, ins->dreg, s390_r0);
3313 if (s390_is_imm16 (ins->inst_imm)) {
3314 s390_lghi (code, s390_r13, ins->inst_imm);
3316 s390_lgfi (code, s390_r13, ins->inst_imm);
3318 s390_lgr (code, s390_r0, ins->sreg1);
3319 s390_dsgr (code, s390_r0, s390_r13);
3320 s390_lgfr (code, ins->dreg, s390_r0);
3324 s390_lgr (code, s390_r1, ins->sreg1);
3325 s390_lghi (code, s390_r0, 0);
3326 s390_dlgr (code, s390_r0, ins->sreg2);
3327 s390_lgr (code, ins->dreg, s390_r0);
3331 if (ins->sreg1 == ins->dreg) {
3332 s390_ogr (code, ins->dreg, ins->sreg2);
3335 if (ins->sreg2 == ins->dreg) {
3336 s390_ogr (code, ins->dreg, ins->sreg1);
3339 s390_lgr (code, ins->dreg, ins->sreg1);
3340 s390_ogr (code, ins->dreg, ins->sreg2);
3346 if (ins->dreg != ins->sreg1) {
3347 s390_lgr (code, ins->dreg, ins->sreg1);
3349 S390_SET_MASK(code, s390_r0, ins->inst_imm);
3350 s390_ogr (code, ins->dreg, s390_r0);
3354 if (ins->sreg1 == ins->dreg) {
3355 s390_xgr (code, ins->dreg, ins->sreg2);
3358 if (ins->sreg2 == ins->dreg) {
3359 s390_xgr (code, ins->dreg, ins->sreg1);
3362 s390_lgr (code, ins->dreg, ins->sreg1);
3363 s390_xgr (code, ins->dreg, ins->sreg2);
3369 if (ins->dreg != ins->sreg1) {
3370 s390_lgr (code, ins->dreg, ins->sreg1);
3372 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3373 s390_xgr (code, ins->dreg, s390_r0);
3378 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3383 if (ins->sreg1 != ins->dreg) {
3384 s390_lgr (code, ins->dreg, ins->sreg1);
3386 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3391 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3396 if (ins->sreg1 != ins->dreg) {
3397 s390_lgr (code, ins->dreg, ins->sreg1);
3399 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3403 case OP_LSHR_UN_IMM: {
3404 if (ins->sreg1 != ins->dreg) {
3405 s390_lgr (code, ins->dreg, ins->sreg1);
3407 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3412 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3416 if (ins->sreg1 != ins->dreg) {
3417 s390_lgr (code, ins->dreg, ins->sreg1);
3419 s390_lghi (code, s390_r0, -1);
3420 s390_xgr (code, ins->dreg, s390_r0);
3424 s390_lcgr (code, ins->dreg, ins->sreg1);
3429 s390_msgr (code, ins->dreg, src2);
3434 if (ins->dreg != ins->sreg1) {
3435 s390_lgr (code, ins->dreg, ins->sreg1);
3437 if (s390_is_imm16 (ins->inst_imm)) {
3438 s390_lghi (code, s390_r13, ins->inst_imm);
3439 } else if (s390_is_imm32 (ins->inst_imm)) {
3440 s390_lgfi (code, s390_r13, ins->inst_imm);
3442 S390_SET (code, s390_r13, ins->inst_imm);
3444 s390_msgr (code, ins->dreg, s390_r13);
3449 s390_ltgr (code, s390_r1, ins->sreg1);
3450 s390_jz (code, 0); CODEPTR(code, o[0]);
3451 s390_ltgr (code, s390_r0, ins->sreg2);
3453 s390_lghi (code, s390_r1, 0);
3454 s390_j (code, 0); CODEPTR(code, o[1]);
3455 s390_xgr (code, s390_r0, s390_r1);
3456 s390_msgr (code, s390_r1, ins->sreg2);
3457 s390_xgr (code, s390_r0, s390_r1);
3458 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3459 s390_ltgr (code, s390_r0, s390_r0);
3460 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3461 PTRSLOT (code, o[0]);
3462 PTRSLOT (code, o[1]);
3463 s390_lgr (code, ins->dreg, s390_r1);
3466 case OP_LMUL_OVF_UN: {
3467 s390_lghi (code, s390_r0, 0);
3468 s390_lgr (code, s390_r1, ins->sreg1);
3469 s390_mlgr (code, s390_r0, ins->sreg2);
3470 s390_ltgr (code, s390_r0, s390_r0);
3471 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3472 s390_lgr (code, ins->dreg, s390_r1);
3476 g_assert_not_reached ();
3478 s390_algr (code, ins->dreg, src2);
3483 s390_agr (code, ins->dreg, src2);
3487 g_assert_not_reached ();
3489 s390_alcgr (code, ins->dreg, src2);
3493 if (ins->dreg != ins->sreg1) {
3494 s390_lgfr (code, ins->dreg, ins->sreg1);
3496 if (s390_is_imm16 (ins->inst_imm)) {
3497 s390_aghi (code, ins->dreg, ins->inst_imm);
3499 s390_afi (code, ins->dreg, ins->inst_imm);
3504 if (ins->dreg != ins->sreg1) {
3505 s390_lgfr (code, ins->dreg, ins->sreg1);
3507 if (s390_is_imm16 (ins->inst_imm)) {
3508 s390_lghi (code, s390_r0, ins->inst_imm);
3509 s390_alcgr (code, ins->dreg, s390_r0);
3511 S390_SET (code, s390_r0, ins->inst_imm);
3512 s390_alcgr (code, ins->dreg, s390_r0);
3517 case OP_S390_LADD_OVF: {
3519 s390_agr (code, ins->dreg, src2);
3520 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3523 case OP_LADD_OVF_UN:
3524 case OP_S390_LADD_OVF_UN: {
3526 s390_algr (code, ins->dreg, src2);
3527 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3531 CHECK_SRCDST_NCOM_I;
3532 s390_slgr (code, ins->dreg, src2);
3536 CHECK_SRCDST_NCOM_I;
3537 s390_sgr (code, ins->dreg, src2);
3541 CHECK_SRCDST_NCOM_I;
3542 s390_slbgr (code, ins->dreg, src2);
3546 if (ins->dreg != ins->sreg1) {
3547 s390_lgfr (code, ins->dreg, ins->sreg1);
3549 if (s390_is_imm16 (-ins->inst_imm)) {
3550 s390_aghi (code, ins->dreg, -ins->inst_imm);
3552 s390_agfi (code, ins->dreg, -ins->inst_imm);
3557 S390_SET (code, s390_r0, ins->inst_imm);
3558 s390_slgfr (code, ins->dreg, s390_r0);
3562 case OP_S390_ISUB_OVF: {
3564 s390_sr (code, ins->dreg, src2);
3565 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3566 s390_lgfr (code, ins->dreg, ins->dreg);
3569 case OP_ISUB_OVF_UN:
3570 case OP_S390_ISUB_OVF_UN: {
3572 s390_slr (code, ins->dreg, src2);
3573 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3574 s390_llgfr(code, ins->dreg, ins->dreg);
3578 case OP_S390_LSUB_OVF: {
3580 s390_sgr (code, ins->dreg, src2);
3581 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3584 case OP_LSUB_OVF_UN:
3585 case OP_S390_LSUB_OVF_UN: {
3587 s390_slgr (code, ins->dreg, src2);
3588 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3592 CHECK_SRCDST_NCOM_I;
3593 s390_ngr (code, ins->dreg, src2);
3597 if (ins->dreg != ins->sreg1) {
3598 s390_lgfr (code, ins->dreg, ins->sreg1);
3600 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3601 s390_ngr (code, ins->dreg, s390_r0);
3605 s390_lgfr (code, s390_r0, ins->sreg1);
3606 s390_srda (code, s390_r0, 0, 32);
3607 s390_dr (code, s390_r0, ins->sreg2);
3608 s390_lgfr (code, ins->dreg, s390_r1);
3612 s390_lgfr (code, s390_r0, ins->sreg1);
3613 s390_srdl (code, s390_r0, 0, 32);
3614 s390_dlr (code, s390_r0, ins->sreg2);
3615 s390_lgfr (code, ins->dreg, s390_r1);
3619 if (s390_is_imm16 (ins->inst_imm)) {
3620 s390_lghi (code, s390_r13, ins->inst_imm);
3622 s390_lgfi (code, s390_r13, ins->inst_imm);
3624 s390_lgfr (code, s390_r0, ins->sreg1);
3625 s390_srda (code, s390_r0, 0, 32);
3626 s390_dr (code, s390_r0, ins->sreg2);
3627 s390_lgfr (code, ins->dreg, s390_r1);
3631 s390_lgfr (code, s390_r0, ins->sreg1);
3632 s390_srda (code, s390_r0, 0, 32);
3633 s390_dr (code, s390_r0, ins->sreg2);
3634 s390_lgfr (code, ins->dreg, s390_r0);
3637 s390_lgfr (code, s390_r0, ins->sreg1);
3638 s390_srdl (code, s390_r0, 0, 32);
3639 s390_dlr (code, s390_r0, ins->sreg2);
3640 s390_lgfr (code, ins->dreg, s390_r0);
3644 if (s390_is_imm16 (ins->inst_imm)) {
3645 s390_lghi (code, s390_r13, ins->inst_imm);
3647 s390_lgfi (code, s390_r13, ins->inst_imm);
3649 s390_lgfr (code, s390_r0, ins->sreg1);
3650 s390_srda (code, s390_r0, 0, 32);
3651 s390_dr (code, s390_r0, ins->sreg2);
3652 s390_lgfr (code, ins->dreg, s390_r0);
3657 s390_ogr (code, ins->dreg, src2);
3661 if (ins->dreg != ins->sreg1) {
3662 s390_lgfr (code, ins->dreg, ins->sreg1);
3664 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3665 s390_ogr (code, ins->dreg, s390_r0);
3670 s390_xgr (code, ins->dreg, src2);
3674 if (ins->dreg != ins->sreg1) {
3675 s390_lgfr (code, ins->dreg, ins->sreg1);
3677 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3678 s390_xgr (code, ins->dreg, s390_r0);
3683 s390_sll (code, ins->dreg, src2, 0);
3687 if (ins->sreg1 != ins->dreg) {
3688 s390_lgfr (code, ins->dreg, ins->sreg1);
3690 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3695 s390_sra (code, ins->dreg, src2, 0);
3699 if (ins->sreg1 != ins->dreg) {
3700 s390_lgfr (code, ins->dreg, ins->sreg1);
3702 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3705 case OP_ISHR_UN_IMM: {
3706 if (ins->sreg1 != ins->dreg) {
3707 s390_lgfr (code, ins->dreg, ins->sreg1);
3709 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3714 s390_srl (code, ins->dreg, src2, 0);
3718 if (ins->sreg1 != ins->dreg) {
3719 s390_lgfr (code, ins->dreg, ins->sreg1);
3721 s390_lghi (code, s390_r0, -1);
3722 s390_xgr (code, ins->dreg, s390_r0);
3726 s390_lcgr (code, ins->dreg, ins->sreg1);
3731 s390_msr (code, ins->dreg, src2);
3735 if (ins->dreg != ins->sreg1) {
3736 s390_lgfr (code, ins->dreg, ins->sreg1);
3738 if (s390_is_imm16 (ins->inst_imm)) {
3739 s390_lghi (code, s390_r0, ins->inst_imm);
3741 s390_lgfi (code, s390_r0, ins->inst_imm);
3743 s390_msr (code, ins->dreg, s390_r0);
3748 s390_ltr (code, s390_r1, ins->sreg1);
3749 s390_jz (code, 0); CODEPTR(code, o[0]);
3750 s390_ltr (code, s390_r0, ins->sreg2);
3752 s390_lhi (code, s390_r1, 0);
3753 s390_j (code, 0); CODEPTR(code, o[1]);
3754 s390_xr (code, s390_r0, s390_r1);
3755 s390_msr (code, s390_r1, ins->sreg2);
3756 s390_xr (code, s390_r0, s390_r1);
3757 s390_srl (code, s390_r0, 0, 31);
3758 s390_ltr (code, s390_r0, s390_r0);
3759 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3760 PTRSLOT (code, o[0]);
3761 PTRSLOT (code, o[1]);
3762 s390_lgfr (code, ins->dreg, s390_r1);
3765 case OP_IMUL_OVF_UN: {
3766 s390_lhi (code, s390_r0, 0);
3767 s390_lr (code, s390_r1, ins->sreg1);
3768 s390_mlr (code, s390_r0, ins->sreg2);
3769 s390_ltr (code, s390_r0, s390_r0);
3770 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3771 s390_lgfr (code, ins->dreg, s390_r1);
3776 S390_SET (code, ins->dreg, ins->inst_c0);
3780 mono_add_patch_info (cfg, code - cfg->native_code,
3781 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3782 S390_LOAD_TEMPLATE (code, ins->dreg);
3785 case OP_JUMP_TABLE: {
3786 mono_add_patch_info (cfg, code - cfg->native_code,
3787 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3788 S390_LOAD_TEMPLATE (code, ins->dreg);
3792 if (ins->dreg != ins->sreg1) {
3793 s390_lgr (code, ins->dreg, ins->sreg1);
3797 case OP_LCONV_TO_I8:
3799 s390_lgfr (code, ins->dreg, ins->sreg1);
3801 case OP_LCONV_TO_I4:
3802 s390_lgfr (code, ins->dreg, ins->sreg1);
3805 case OP_LCONV_TO_U8:
3806 case OP_LCONV_TO_U4:
3808 s390_llgfr (code, ins->dreg, ins->sreg1);
3810 case OP_LCONV_TO_OVF_U4:
3811 S390_SET (code, s390_r0, 4294967295);
3812 s390_clgr (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_llgfr(code, ins->dreg, ins->sreg1);
3818 case OP_LCONV_TO_OVF_I4_UN:
3819 S390_SET (code, s390_r0, 2147483647);
3820 s390_cgr (code, ins->sreg1, s390_r0);
3821 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3822 s390_ltgr (code, ins->sreg1, ins->sreg1);
3823 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3824 s390_lgfr (code, ins->dreg, ins->sreg1);
3827 if (ins->dreg != ins->sreg1) {
3828 s390_ldr (code, ins->dreg, ins->sreg1);
3831 case OP_MOVE_F_TO_I8:
3832 s390_lgdr (code, ins->dreg, ins->sreg1);
3834 case OP_MOVE_I8_TO_F:
3835 s390_ldgr (code, ins->dreg, ins->sreg1);
3837 case OP_MOVE_F_TO_I4:
3838 s390_lgdr (code, ins->dreg, ins->sreg1);
3840 case OP_MOVE_I4_TO_F:
3841 s390_lgfr (code, s390_r0, ins->sreg1);
3842 s390_ldgr (code, ins->dreg, s390_r0);
3844 case OP_FCONV_TO_R4:
3845 s390_ledbr (code, ins->dreg, ins->sreg1);
3846 s390_ldebr (code, ins->dreg, ins->dreg);
3848 case OP_S390_SETF4RET:
3849 s390_ledbr (code, ins->dreg, ins->sreg1);
3852 if (s390_is_imm16 (ins->inst_offset)) {
3853 s390_lghi (code, s390_r13, ins->inst_offset);
3854 } else if (s390_is_imm32 (ins->inst_offset)) {
3855 s390_lgfi (code, s390_r13, ins->inst_offset);
3857 S390_SET (code, s390_r13, ins->inst_offset);
3859 s390_ear (code, s390_r1, 0);
3860 s390_sllg(code, s390_r1, s390_r1, 0, 32);
3861 s390_ear (code, s390_r1, 1);
3862 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
3866 if (cfg->method->save_lmf)
3867 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3869 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3870 code = emit_load_volatile_arguments (code, cfg);
3873 code = backUpStackPtr(cfg, code);
3874 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
3875 mono_add_patch_info (cfg, code - cfg->native_code,
3876 MONO_PATCH_INFO_METHOD_JUMP,
3878 s390_jcl (code, S390_CC_UN, 0);
3881 case OP_CHECK_THIS: {
3882 /* ensure ins->sreg1 is not NULL */
3883 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3884 s390_ltgr (code, s390_r0, s390_r0);
3885 // EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
3889 int offset = cfg->sig_cookie + cfg->stack_usage;
3891 if (s390_is_imm16 (offset)) {
3892 s390_lghi (code, s390_r0, offset);
3893 } else if (s390_is_imm32 (offset)) {
3894 s390_lgfi (code, s390_r0, offset);
3896 S390_SET (code, s390_r0, offset);
3898 s390_agr (code, s390_r0, cfg->frame_reg);
3899 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3903 call = (MonoCallInst*)ins;
3904 if (ins->flags & MONO_INST_HAS_METHOD)
3905 mono_add_patch_info (cfg, code-cfg->native_code,
3906 MONO_PATCH_INFO_METHOD,
3909 mono_add_patch_info (cfg, code-cfg->native_code,
3910 MONO_PATCH_INFO_ABS,
3912 S390_CALL_TEMPLATE (code, s390_r14);
3913 if (call->signature->ret->type == MONO_TYPE_R4)
3914 s390_ldebr (code, s390_f0, s390_f0);
3922 call = (MonoCallInst*)ins;
3923 if (ins->flags & MONO_INST_HAS_METHOD)
3924 mono_add_patch_info (cfg, code-cfg->native_code,
3925 MONO_PATCH_INFO_METHOD,
3928 mono_add_patch_info (cfg, code-cfg->native_code,
3929 MONO_PATCH_INFO_ABS,
3931 S390_CALL_TEMPLATE (code, s390_r14);
3934 case OP_FCALL_REG: {
3935 call = (MonoCallInst*)ins;
3936 s390_lgr (code, s390_r1, ins->sreg1);
3937 s390_basr (code, s390_r14, s390_r1);
3938 if (call->signature->ret->type == MONO_TYPE_R4)
3939 s390_ldebr (code, s390_f0, s390_f0);
3945 case OP_VOIDCALL_REG:
3947 s390_lgr (code, s390_r1, ins->sreg1);
3948 s390_basr (code, s390_r14, s390_r1);
3951 case OP_FCALL_MEMBASE: {
3952 call = (MonoCallInst*)ins;
3953 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3954 s390_basr (code, s390_r14, s390_r1);
3955 if (call->signature->ret->type == MONO_TYPE_R4)
3956 s390_ldebr (code, s390_f0, s390_f0);
3959 case OP_LCALL_MEMBASE:
3960 case OP_VCALL_MEMBASE:
3961 case OP_VCALL2_MEMBASE:
3962 case OP_VOIDCALL_MEMBASE:
3963 case OP_CALL_MEMBASE: {
3964 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3965 s390_basr (code, s390_r14, s390_r1);
3972 if (cfg->param_area == 0)
3973 alloca_skip = S390_MINIMAL_STACK_SIZE;
3975 alloca_skip = cfg->param_area;
3977 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3978 s390_lgr (code, s390_r1, ins->sreg1);
3979 if (ins->flags & MONO_INST_INIT)
3980 s390_lgr (code, s390_r0, ins->sreg1);
3981 s390_aghi (code, s390_r1, 14);
3982 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3983 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3984 if (cfg->method->save_lmf) {
3985 /*----------------------------------*/
3986 /* we have to adjust lmf ebp value */
3987 /*----------------------------------*/
3988 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3990 s390_lgr (code, s390_r13, cfg->frame_reg);
3991 if (s390_is_imm16(lmfOffset)) {
3992 s390_aghi (code, s390_r13, lmfOffset);
3993 } else if (s390_is_imm32(lmfOffset)) {
3994 s390_agfi (code, s390_r13, lmfOffset);
3996 S390_SET (code, s390_r13, lmfOffset);
3998 s390_lgr (code, s390_r14, STK_BASE);
3999 s390_sgr (code, s390_r14, s390_r1);
4000 s390_stg (code, s390_r14, 0, s390_r13,
4001 G_STRUCT_OFFSET(MonoLMF, ebp));
4003 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4004 s390_sgr (code, STK_BASE, s390_r1);
4005 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4006 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4007 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4008 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4009 if (ins->flags & MONO_INST_INIT) {
4010 s390_lgr (code, s390_r1, s390_r0);
4011 s390_lgr (code, s390_r0, ins->dreg);
4012 s390_lgr (code, s390_r14, s390_r12);
4013 s390_lghi (code, s390_r13, 0);
4014 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4016 s390_lgr (code, s390_r12, s390_r14);
4021 s390_lgr (code, s390_r2, ins->sreg1);
4022 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4023 (gpointer) "mono_arch_throw_exception");
4024 S390_CALL_TEMPLATE(code, s390_r14);
4028 s390_lgr (code, s390_r2, ins->sreg1);
4029 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4030 (gpointer) "mono_arch_rethrow_exception");
4031 S390_CALL_TEMPLATE(code, s390_r14);
4034 case OP_START_HANDLER: {
4035 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4037 S390_LONG (code, stg, stg, s390_r14, 0,
4038 spvar->inst_basereg,
4039 spvar->inst_offset);
4042 case OP_ENDFILTER: {
4043 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4045 if (ins->sreg1 != s390_r2)
4046 s390_lgr(code, s390_r2, ins->sreg1);
4047 S390_LONG (code, lg, lg, s390_r14, 0,
4048 spvar->inst_basereg,
4049 spvar->inst_offset);
4050 s390_br (code, s390_r14);
4053 case OP_ENDFINALLY: {
4054 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4056 S390_LONG (code, lg, lg, s390_r14, 0,
4057 spvar->inst_basereg,
4058 spvar->inst_offset);
4059 s390_br (code, s390_r14);
4062 case OP_CALL_HANDLER: {
4063 mono_add_patch_info (cfg, code-cfg->native_code,
4064 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4065 s390_brasl (code, s390_r14, 0);
4066 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4070 ins->inst_c0 = code - cfg->native_code;
4073 case OP_RELAXED_NOP:
4076 case OP_DUMMY_STORE:
4077 case OP_NOT_REACHED:
4081 case OP_IL_SEQ_POINT:
4082 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4084 case OP_SEQ_POINT: {
4087 if (cfg->compile_aot)
4091 * Read from the single stepping trigger page. This will cause a
4092 * SIGSEGV when single stepping is enabled.
4093 * We do this _before_ the breakpoint, so single stepping after
4094 * a breakpoint is hit will step to the next IL offset.
4096 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4097 breakpointCode.pTrigger = ss_trigger_page;
4098 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4099 code += BREAKPOINT_SIZE;
4102 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4105 * A placeholder for a possible breakpoint inserted by
4106 * mono_arch_set_breakpoint ().
4108 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4112 * Add an additional nop so skipping the bp doesn't cause the ip to point
4113 * to another IL offset.
4121 EMIT_UNCOND_BRANCH(ins);
4124 s390_br (code, ins->sreg1);
4130 s390_lghi(code, ins->dreg, 1);
4132 s390_lghi(code, ins->dreg, 0);
4138 s390_lghi(code, ins->dreg, 1);
4140 s390_lghi(code, ins->dreg, 0);
4146 s390_lghi(code, ins->dreg, 1);
4148 s390_lghi(code, ins->dreg, 0);
4154 s390_lghi(code, ins->dreg, 1);
4156 s390_lghi(code, ins->dreg, 0);
4162 s390_lghi(code, ins->dreg, 1);
4164 s390_lghi(code, ins->dreg, 0);
4167 case OP_COND_EXC_EQ:
4168 case OP_COND_EXC_IEQ:
4169 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4171 case OP_COND_EXC_NE_UN:
4172 case OP_COND_EXC_INE_UN:
4173 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4175 case OP_COND_EXC_LT:
4176 case OP_COND_EXC_ILT:
4177 case OP_COND_EXC_LT_UN:
4178 case OP_COND_EXC_ILT_UN:
4179 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4181 case OP_COND_EXC_GT:
4182 case OP_COND_EXC_IGT:
4183 case OP_COND_EXC_GT_UN:
4184 case OP_COND_EXC_IGT_UN:
4185 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4187 case OP_COND_EXC_GE:
4188 case OP_COND_EXC_IGE:
4189 case OP_COND_EXC_GE_UN:
4190 case OP_COND_EXC_IGE_UN:
4191 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4193 case OP_COND_EXC_LE:
4194 case OP_COND_EXC_ILE:
4195 case OP_COND_EXC_LE_UN:
4196 case OP_COND_EXC_ILE_UN:
4197 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4199 case OP_COND_EXC_OV:
4200 case OP_COND_EXC_IOV:
4201 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4203 case OP_COND_EXC_NO:
4204 case OP_COND_EXC_INO:
4205 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4208 case OP_COND_EXC_IC:
4209 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4211 case OP_COND_EXC_NC:
4212 case OP_COND_EXC_INC:
4213 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4217 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4221 EMIT_COND_BRANCH (ins, S390_CC_NE);
4227 EMIT_COND_BRANCH (ins, S390_CC_LT);
4233 EMIT_COND_BRANCH (ins, S390_CC_GT);
4239 EMIT_COND_BRANCH (ins, S390_CC_GE);
4245 EMIT_COND_BRANCH (ins, S390_CC_LE);
4248 /* floating point opcodes */
4250 if (*((double *) ins->inst_p0) == 0) {
4251 s390_lzdr (code, ins->dreg);
4253 S390_SET (code, s390_r13, ins->inst_p0);
4254 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4259 if (*((float *) ins->inst_p0) == 0) {
4260 s390_lzdr (code, ins->dreg);
4262 S390_SET (code, s390_r13, ins->inst_p0);
4263 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4267 case OP_STORER8_MEMBASE_REG: {
4268 S390_LONG (code, stdy, std, ins->sreg1, 0,
4269 ins->inst_destbasereg, ins->inst_offset);
4272 case OP_LOADR8_MEMBASE: {
4273 S390_LONG (code, ldy, ld, ins->dreg, 0,
4274 ins->inst_basereg, ins->inst_offset);
4277 case OP_STORER4_MEMBASE_REG: {
4278 s390_ledbr (code, s390_f15, ins->sreg1);
4279 S390_LONG (code, stey, ste, s390_f15, 0,
4280 ins->inst_destbasereg, ins->inst_offset);
4283 case OP_LOADR4_MEMBASE: {
4284 S390_LONG (code, ldy, ld, s390_f15, 0,
4285 ins->inst_basereg, ins->inst_offset);
4286 s390_ldebr (code, ins->dreg, s390_f15);
4289 case OP_ICONV_TO_R_UN: {
4290 s390_cdfbr (code, ins->dreg, ins->sreg1);
4291 s390_ltr (code, ins->sreg1, ins->sreg1);
4293 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4294 s390_ldgr (code, s390_f15, s390_r13);
4295 s390_adbr (code, ins->dreg, s390_f15);
4298 case OP_LCONV_TO_R_UN: {
4299 s390_cdgbr (code, ins->dreg, ins->sreg1);
4300 s390_ltgr (code, ins->sreg1, ins->sreg1);
4302 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4303 s390_ldgr (code, s390_f15, s390_r13);
4304 s390_adbr (code, ins->dreg, s390_f15);
4307 case OP_LCONV_TO_R4:
4308 case OP_ICONV_TO_R4: {
4309 s390_cegbr (code, ins->dreg, ins->sreg1);
4310 s390_ldebr (code, ins->dreg, ins->dreg);
4313 case OP_LCONV_TO_R8:
4314 case OP_ICONV_TO_R8: {
4315 s390_cdgbr (code, ins->dreg, ins->sreg1);
4318 case OP_FCONV_TO_I1:
4319 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4321 case OP_FCONV_TO_U1:
4322 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4324 case OP_FCONV_TO_I2:
4325 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4327 case OP_FCONV_TO_U2:
4328 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4330 case OP_FCONV_TO_I4:
4332 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4334 case OP_FCONV_TO_U4:
4336 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4338 case OP_FCONV_TO_I8:
4339 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4341 case OP_LCONV_TO_OVF_I: {
4342 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4344 s390_ltgr (code, ins->sreg2, ins->sreg2);
4345 s390_jnl (code, 0); CODEPTR(code, o[0]);
4346 s390_ltgr (code, ins->sreg1, ins->sreg1);
4347 s390_jnl (code, 0); CODEPTR(code, o[1]);
4348 s390_lhi (code, s390_r13, -1);
4349 s390_cgr (code, ins->sreg1, s390_r13);
4350 s390_jnz (code, 0); CODEPTR(code, o[2]);
4351 if (ins->dreg != ins->sreg2)
4352 s390_lgr (code, ins->dreg, ins->sreg2);
4353 s390_j (code, 0); CODEPTR(code, o[3]);
4354 PTRSLOT(code, o[0]);
4355 s390_jz (code, 0); CODEPTR(code, o[4]);
4356 PTRSLOT(code, o[1]);
4357 PTRSLOT(code, o[2]);
4358 mono_add_patch_info (cfg, code - cfg->native_code,
4359 MONO_PATCH_INFO_EXC, "OverflowException");
4360 s390_brasl (code, s390_r14, 0);
4361 PTRSLOT(code, o[3]);
4362 PTRSLOT(code, o[4]);
4366 s390_lpdbr (code, ins->dreg, ins->sreg1);
4370 s390_sqdbr (code, ins->dreg, ins->sreg1);
4375 s390_adbr (code, ins->dreg, src2);
4379 CHECK_SRCDST_NCOM_F;
4380 s390_sdbr (code, ins->dreg, src2);
4385 s390_mdbr (code, ins->dreg, src2);
4389 CHECK_SRCDST_NCOM_F;
4390 s390_ddbr (code, ins->dreg, src2);
4394 s390_lcdbr (code, ins->dreg, ins->sreg1);
4398 CHECK_SRCDST_NCOM_F;
4399 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4403 s390_cdbr (code, ins->sreg1, ins->sreg2);
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);
4421 s390_cdbr (code, ins->sreg1, ins->sreg2);
4422 s390_lghi (code, ins->dreg, 1);
4424 s390_lghi (code, ins->dreg, 0);
4428 s390_cdbr (code, ins->sreg1, ins->sreg2);
4429 s390_lghi (code, ins->dreg, 1);
4431 s390_lghi (code, ins->dreg, 0);
4435 s390_cdbr (code, ins->sreg1, ins->sreg2);
4436 s390_lghi (code, ins->dreg, 1);
4438 s390_lghi (code, ins->dreg, 0);
4443 s390_jo (code, 0); CODEPTR(code, o);
4444 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4449 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4453 s390_jo (code, 0); CODEPTR(code, o);
4454 EMIT_COND_BRANCH (ins, S390_CC_LT);
4459 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4463 s390_jo (code, 0); CODEPTR(code, o);
4464 EMIT_COND_BRANCH (ins, S390_CC_GT);
4469 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4473 s390_jo (code, 0); CODEPTR(code, o);
4474 EMIT_COND_BRANCH (ins, S390_CC_GE);
4479 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4483 s390_jo (code, 0); CODEPTR(code, o);
4484 EMIT_COND_BRANCH (ins, S390_CC_LE);
4489 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4493 s390_lhi (code, s390_r13, 0x7f);
4494 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4495 s390_jz (code, 0); CODEPTR(code, o);
4496 mono_add_patch_info (cfg, code - cfg->native_code,
4497 MONO_PATCH_INFO_EXC, "ArithmeticException");
4498 s390_brasl (code, s390_r14,0);
4502 case OP_S390_MOVE: {
4503 if (ins->backend.size > 0) {
4504 if (ins->backend.size <= 256) {
4505 s390_mvc (code, ins->backend.size, ins->dreg,
4506 ins->inst_offset, ins->sreg1, ins->inst_imm);
4508 s390_lgr (code, s390_r0, ins->dreg);
4509 if (ins->inst_offset > 0) {
4510 if (s390_is_imm16 (ins->inst_offset)) {
4511 s390_aghi (code, s390_r0, ins->inst_offset);
4512 } else if (s390_is_imm32 (ins->inst_offset)) {
4513 s390_agfi (code, s390_r0, ins->inst_offset);
4515 S390_SET (code, s390_r13, ins->inst_offset);
4516 s390_agr (code, s390_r0, s390_r13);
4519 s390_lgr (code, s390_r12, ins->sreg1);
4520 if (ins->inst_imm > 0) {
4521 if (s390_is_imm16 (ins->inst_imm)) {
4522 s390_aghi (code, s390_r12, ins->inst_imm);
4523 } else if (s390_is_imm32 (ins->inst_imm)) {
4524 s390_agfi (code, s390_r12, ins->inst_imm);
4526 S390_SET (code, s390_r13, ins->inst_imm);
4527 s390_agr (code, s390_r12, s390_r13);
4530 if (s390_is_imm16 (ins->backend.size)) {
4531 s390_lghi (code, s390_r1, ins->backend.size);
4532 } else if (s390_is_imm32 (ins->inst_offset)) {
4533 s390_agfi (code, s390_r1, ins->backend.size);
4535 S390_SET (code, s390_r13, ins->backend.size);
4536 s390_agr (code, s390_r1, s390_r13);
4538 s390_lgr (code, s390_r13, s390_r1);
4539 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4545 case OP_ATOMIC_ADD_I8: {
4546 s390_lgr (code, s390_r1, ins->sreg2);
4547 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4548 s390_agr (code, s390_r1, s390_r0);
4549 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4550 s390_jnz (code, -10);
4551 s390_lgr (code, ins->dreg, s390_r1);
4554 case OP_ATOMIC_EXCHANGE_I8: {
4555 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4556 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4557 s390_jnz (code, -6);
4558 s390_lgr (code, ins->dreg, s390_r0);
4561 case OP_ATOMIC_ADD_I4: {
4562 s390_lgfr(code, s390_r1, ins->sreg2);
4563 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4564 s390_agr (code, s390_r1, s390_r0);
4565 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4566 s390_jnz (code, -9);
4567 s390_lgfr(code, ins->dreg, s390_r1);
4570 case OP_ATOMIC_EXCHANGE_I4: {
4571 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4572 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4573 s390_jnz (code, -4);
4574 s390_lgfr(code, ins->dreg, s390_r0);
4577 case OP_S390_BKCHAIN: {
4578 s390_lgr (code, ins->dreg, ins->sreg1);
4579 if (s390_is_imm16 (cfg->stack_offset)) {
4580 s390_aghi (code, ins->dreg, cfg->stack_offset);
4581 } else if (s390_is_imm32 (cfg->stack_offset)) {
4582 s390_agfi (code, ins->dreg, cfg->stack_offset);
4584 S390_SET (code, s390_r13, cfg->stack_offset);
4585 s390_agr (code, ins->dreg, s390_r13);
4589 case OP_MEMORY_BARRIER:
4592 case OP_GC_LIVENESS_DEF:
4593 case OP_GC_LIVENESS_USE:
4594 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4595 ins->backend.pc_offset = code - cfg->native_code;
4597 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4598 ins->backend.pc_offset = code - cfg->native_code;
4599 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4602 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4603 g_assert_not_reached ();
4606 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4607 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4608 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4609 g_assert_not_reached ();
4612 last_offset = offset;
4615 cfg->code_len = code - cfg->native_code;
4618 /*========================= End of Function ========================*/
4620 /*------------------------------------------------------------------*/
4622 /* Name - mono_arch_register_lowlevel_calls */
4624 /* Function - Register routines to help with --trace operation. */
4626 /*------------------------------------------------------------------*/
4629 mono_arch_register_lowlevel_calls (void)
4633 /*========================= End of Function ========================*/
4635 /*------------------------------------------------------------------*/
4637 /* Name - mono_arch_patch_code */
4639 /* Function - Process the patch data created during the */
4640 /* instruction build process. This resolves jumps, */
4641 /* calls, variables etc. */
4643 /*------------------------------------------------------------------*/
4646 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4647 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4649 MonoJumpInfo *patch_info;
4651 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4652 unsigned char *ip = patch_info->ip.i + code;
4653 gconstpointer target = NULL;
4655 target = mono_resolve_patch_target (method, domain, code,
4656 patch_info, run_cctors);
4658 switch (patch_info->type) {
4659 case MONO_PATCH_INFO_IP:
4660 case MONO_PATCH_INFO_LDSTR:
4661 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4662 case MONO_PATCH_INFO_LDTOKEN:
4663 case MONO_PATCH_INFO_EXC:
4664 s390_patch_addr (ip, (guint64) target);
4666 case MONO_PATCH_INFO_METHOD:
4667 case MONO_PATCH_INFO_INTERNAL_METHOD:
4668 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4669 case MONO_PATCH_INFO_CLASS_INIT:
4670 case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
4671 case MONO_PATCH_INFO_RGCTX_FETCH:
4672 case MONO_PATCH_INFO_ABS: {
4673 S390_EMIT_CALL (ip, target);
4676 case MONO_PATCH_INFO_SWITCH:
4677 /*----------------------------------*/
4678 /* ip points at the basr r13,0/j +4 */
4679 /* instruction the vtable value */
4680 /* follows this (i.e. ip+6) */
4681 /*----------------------------------*/
4682 S390_EMIT_LOAD (ip, target);
4684 case MONO_PATCH_INFO_METHODCONST:
4685 case MONO_PATCH_INFO_CLASS:
4686 case MONO_PATCH_INFO_IMAGE:
4687 case MONO_PATCH_INFO_FIELD:
4688 case MONO_PATCH_INFO_IID:
4689 case MONO_PATCH_INFO_EXC_NAME:
4690 target = S390_RELATIVE(target, ip);
4691 s390_patch_rel (ip, (guint64) target);
4693 case MONO_PATCH_INFO_R4:
4694 case MONO_PATCH_INFO_R8:
4695 case MONO_PATCH_INFO_METHOD_REL:
4696 g_assert_not_reached ();
4699 target = S390_RELATIVE(target, ip);
4701 s390_patch_rel (ip, (guint64) target);
4706 /*========================= End of Function ========================*/
4708 /*------------------------------------------------------------------*/
4710 /* Name - emit_load_volatile_arguments */
4712 /* Function - Emit the instructions to reload parameter regist- */
4713 /* registers for use with "tail" operations. */
4715 /* The register loading operations performed here */
4716 /* are the mirror of the store operations performed */
4717 /* in mono_arch_emit_prolog and need to be kept in */
4718 /* synchronization with it. */
4720 /*------------------------------------------------------------------*/
4723 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4726 MonoMethod *method = cfg->method;
4727 MonoMethodSignature *sig = mono_method_signature(method);
4731 cinfo = get_call_info (NULL, NULL, sig);
4733 if (cinfo->struct_ret) {
4734 ArgInfo *ainfo = &cinfo->ret;
4735 inst = cfg->vret_addr;
4736 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4739 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4740 ArgInfo *ainfo = cinfo->args + i;
4741 inst = cfg->args [pos];
4743 if (inst->opcode == OP_REGVAR) {
4744 if (ainfo->regtype == RegTypeGeneral)
4745 s390_lgr (code, ainfo->reg, inst->dreg);
4746 else if (ainfo->regtype == RegTypeFP) {
4747 if (inst->dreg != ainfo->reg) {
4748 if (ainfo->size == 4) {
4749 s390_ldebr (code, ainfo->reg, inst->dreg);
4751 s390_ldr (code, ainfo->reg, inst->dreg);
4755 else if (ainfo->regtype == RegTypeBase) {
4757 g_assert_not_reached ();
4759 if (ainfo->regtype == RegTypeGeneral) {
4760 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4761 g_assert_not_reached();
4762 switch (ainfo->size) {
4764 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4767 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4770 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4773 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4776 } else if (ainfo->regtype == RegTypeBase) {
4777 } else if (ainfo->regtype == RegTypeFP) {
4778 if (ainfo->size == 8)
4779 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4780 else if (ainfo->size == 4)
4781 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4783 g_assert_not_reached ();
4784 } else if (ainfo->regtype == RegTypeStructByVal) {
4785 if (ainfo->reg != STK_BASE) {
4786 switch (ainfo->size) {
4788 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4791 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4794 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4797 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4801 } else if (ainfo->regtype == RegTypeStructByAddr) {
4802 if (ainfo->reg != STK_BASE) {
4803 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4806 g_assert_not_reached ();
4814 /*========================= End of Function ========================*/
4816 /*------------------------------------------------------------------*/
4818 /* Name - mono_arch_emit_prolog */
4820 /* Function - Create the instruction sequence for a function */
4823 /*------------------------------------------------------------------*/
4826 mono_arch_emit_prolog (MonoCompile *cfg)
4828 MonoMethod *method = cfg->method;
4830 MonoMethodSignature *sig;
4832 long alloc_size, pos, max_offset, i, cfa_offset = 0;
4839 cfg->code_size = 512;
4841 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4843 cfg->code_size += 256;
4844 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4845 cfg->code_size += 256;
4847 if (method->save_lmf)
4848 cfg->code_size += 200;
4850 cfg->native_code = code = g_malloc (cfg->code_size);
4852 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
4853 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
4854 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4855 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
4857 if (cfg->arch.bkchain_reg != -1)
4858 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4860 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4861 cfg->used_int_regs |= 1 << 11;
4864 alloc_size = cfg->stack_offset;
4866 cfg->stack_usage = cfa_offset = alloc_size;
4867 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
4868 s390_lgr (code, s390_r11, STK_BASE);
4869 if (s390_is_imm16 (alloc_size)) {
4870 s390_aghi (code, STK_BASE, -alloc_size);
4871 } else if (s390_is_imm32 (alloc_size)) {
4872 s390_agfi (code, STK_BASE, -alloc_size);
4874 int stackSize = alloc_size;
4875 while (stackSize > INT_MAX) {
4876 s390_agfi (code, STK_BASE, -INT_MAX);
4877 stackSize -= INT_MAX;
4879 s390_agfi (code, STK_BASE, -stackSize);
4881 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4883 if (cfg->frame_reg != STK_BASE)
4884 s390_lgr (code, s390_r11, STK_BASE);
4886 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
4888 /* store runtime generic context */
4889 if (cfg->rgctx_var) {
4890 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
4892 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
4893 cfg->rgctx_var->inst_basereg,
4894 cfg->rgctx_var->inst_offset);
4897 /* compute max_offset in order to use short forward jumps
4898 * we always do it on s390 because the immediate displacement
4899 * for jumps is too small
4902 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4904 bb->max_offset = max_offset;
4906 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4909 MONO_BB_FOR_EACH_INS (bb, ins)
4910 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4913 /* load arguments allocated to register from the stack */
4914 sig = mono_method_signature (method);
4917 cinfo = get_call_info (cfg, cfg->mempool, sig);
4919 if (cinfo->struct_ret) {
4920 ArgInfo *ainfo = &cinfo->ret;
4921 inst = cfg->vret_addr;
4922 inst->backend.size = ainfo->vtsize;
4923 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4926 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4927 ArgInfo *ainfo = cinfo->args + i;
4928 inst = cfg->args [pos];
4930 if (inst->opcode == OP_VTARG_ADDR)
4931 inst = inst->inst_left;
4933 if (inst->opcode == OP_REGVAR) {
4934 if (ainfo->regtype == RegTypeGeneral)
4935 s390_lgr (code, inst->dreg, ainfo->reg);
4936 else if (ainfo->regtype == RegTypeFP) {
4937 if (inst->dreg != ainfo->reg) {
4938 if (ainfo->size == 4) {
4939 s390_ledbr (code, inst->dreg, ainfo->reg);
4941 s390_ldr (code, inst->dreg, ainfo->reg);
4945 else if (ainfo->regtype == RegTypeBase) {
4946 s390_lgr (code, s390_r13, STK_BASE);
4947 s390_aghi (code, s390_r13, alloc_size);
4948 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4950 g_assert_not_reached ();
4952 if (cfg->verbose_level > 2)
4953 g_print ("Argument %d assigned to register %s\n",
4954 pos, mono_arch_regname (inst->dreg));
4956 if (ainfo->regtype == RegTypeGeneral) {
4957 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4958 g_assert_not_reached();
4959 switch (ainfo->size) {
4961 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4964 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4967 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4970 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4973 } else if (ainfo->regtype == RegTypeBase) {
4974 } else if (ainfo->regtype == RegTypeFP) {
4975 if (ainfo->size == 8)
4976 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4977 else if (ainfo->size == 4)
4978 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4980 g_assert_not_reached ();
4981 } else if (ainfo->regtype == RegTypeStructByVal) {
4982 int doffset = inst->inst_offset;
4984 if (ainfo->reg != STK_BASE)
4988 s390_lgr (code, s390_r13, STK_BASE);
4989 s390_aghi (code, s390_r13, alloc_size);
4992 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
4993 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
4998 if (ainfo->reg == STK_BASE)
4999 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5000 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5003 if (ainfo->reg == STK_BASE)
5004 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5005 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5008 if (ainfo->reg == STK_BASE)
5009 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5010 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5013 if (ainfo->reg == STK_BASE)
5014 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5015 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5018 } else if (ainfo->regtype == RegTypeStructByAddr) {
5019 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5020 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5022 g_assert_not_reached ();
5027 if (method->save_lmf) {
5028 /*---------------------------------------------------------------*/
5029 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5030 /*---------------------------------------------------------------*/
5031 lmfOffset = alloc_size - sizeof(MonoLMF);
5033 s390_lgr (code, s390_r13, cfg->frame_reg);
5034 s390_aghi (code, s390_r13, lmfOffset);
5036 /*---------------------------------------------------------------*/
5037 /* Preserve the parameter registers while we fix up the lmf */
5038 /*---------------------------------------------------------------*/
5039 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5040 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5042 /*---------------------------------------------------------------*/
5043 /* On return from this call r2 have the address of the &lmf */
5044 /*---------------------------------------------------------------*/
5045 if (lmf_addr_tls_offset == -1) {
5046 mono_add_patch_info (cfg, code - cfg->native_code,
5047 MONO_PATCH_INFO_INTERNAL_METHOD,
5048 (gpointer)"mono_get_lmf_addr");
5049 S390_CALL_TEMPLATE(code, s390_r1);
5051 /*-------------------------------------------------------*/
5052 /* Get LMF by getting value from thread level storage */
5053 /*-------------------------------------------------------*/
5054 s390_ear (code, s390_r1, 0);
5055 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5056 s390_ear (code, s390_r1, 1);
5057 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5060 /*---------------------------------------------------------------*/
5061 /* Set lmf.lmf_addr = jit_tls->lmf */
5062 /*---------------------------------------------------------------*/
5063 s390_stg (code, s390_r2, 0, s390_r13,
5064 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5066 /*---------------------------------------------------------------*/
5067 /* Get current lmf */
5068 /*---------------------------------------------------------------*/
5069 s390_lg (code, s390_r0, 0, s390_r2, 0);
5071 /*---------------------------------------------------------------*/
5072 /* Set our lmf as the current lmf */
5073 /*---------------------------------------------------------------*/
5074 s390_stg (code, s390_r13, 0, s390_r2, 0);
5076 /*---------------------------------------------------------------*/
5077 /* Have our lmf.previous_lmf point to the last lmf */
5078 /*---------------------------------------------------------------*/
5079 s390_stg (code, s390_r0, 0, s390_r13,
5080 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5082 /*---------------------------------------------------------------*/
5083 /* save method info */
5084 /*---------------------------------------------------------------*/
5085 S390_SET (code, s390_r1, method);
5086 s390_stg (code, s390_r1, 0, s390_r13,
5087 G_STRUCT_OFFSET(MonoLMF, method));
5089 /*---------------------------------------------------------------*/
5090 /* save the current IP */
5091 /*---------------------------------------------------------------*/
5092 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5093 s390_basr (code, s390_r1, 0);
5094 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5096 /*---------------------------------------------------------------*/
5097 /* Save general and floating point registers */
5098 /*---------------------------------------------------------------*/
5099 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5100 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5101 for (i = 0; i < 16; i++) {
5102 s390_std (code, i, 0, s390_r13,
5103 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5106 /*---------------------------------------------------------------*/
5107 /* Restore the parameter registers now that we've set up the lmf */
5108 /*---------------------------------------------------------------*/
5109 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5110 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5114 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5116 cfg->code_len = code - cfg->native_code;
5117 g_assert (cfg->code_len < cfg->code_size);
5122 /*========================= End of Function ========================*/
5124 /*------------------------------------------------------------------*/
5126 /* Name - mono_arch_emit_epilog */
5128 /* Function - Emit the instructions for a function epilog. */
5130 /*------------------------------------------------------------------*/
5133 mono_arch_emit_epilog (MonoCompile *cfg)
5135 MonoMethod *method = cfg->method;
5138 int max_epilog_size = 96;
5140 if (cfg->method->save_lmf)
5141 max_epilog_size += 128;
5143 if (mono_jit_trace_calls != NULL)
5144 max_epilog_size += 128;
5145 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5146 max_epilog_size += 128;
5148 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5149 cfg->code_size *= 2;
5150 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5151 cfg->stat_code_reallocs++;
5154 code = cfg->native_code + cfg->code_len;
5156 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5157 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5161 if (method->save_lmf)
5162 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5164 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5165 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5167 code = backUpStackPtr(cfg, code);
5169 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5170 s390_br (code, s390_r14);
5172 cfg->code_len = code - cfg->native_code;
5174 g_assert (cfg->code_len < cfg->code_size);
5178 /*========================= End of Function ========================*/
5180 /*------------------------------------------------------------------*/
5182 /* Name - mono_arch_emit_exceptions */
5184 /* Function - Emit the blocks to handle exception conditions. */
5186 /*------------------------------------------------------------------*/
5189 mono_arch_emit_exceptions (MonoCompile *cfg)
5191 MonoJumpInfo *patch_info;
5197 MonoClass *exc_classes [MAX_EXC];
5198 guint8 *exc_throw_start [MAX_EXC];
5200 for (patch_info = cfg->patch_info;
5202 patch_info = patch_info->next) {
5203 if (patch_info->type == MONO_PATCH_INFO_EXC)
5207 code_size = exc_count * 48;
5209 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5210 cfg->code_size *= 2;
5211 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5212 cfg->stat_code_reallocs++;
5215 code = cfg->native_code + cfg->code_len;
5217 /*---------------------------------------------------------------------*/
5218 /* Add code to raise exceptions */
5219 /*---------------------------------------------------------------------*/
5220 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5221 switch (patch_info->type) {
5222 case MONO_PATCH_INFO_EXC: {
5223 guint8 *ip = patch_info->ip.i + cfg->native_code;
5224 MonoClass *exc_class;
5227 /*-----------------------------------------------------*/
5228 /* Patch the branch in epilog to come here */
5229 /*-----------------------------------------------------*/
5230 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5232 exc_class = mono_class_from_name (mono_defaults.corlib,
5234 patch_info->data.name);
5235 g_assert (exc_class);
5236 throw_ip = patch_info->ip.i;
5238 for (iExc = 0; iExc < nThrows; ++iExc)
5239 if (exc_classes [iExc] == exc_class)
5242 if (iExc < nThrows) {
5243 s390_jcl (code, S390_CC_UN,
5244 (guint64) exc_throw_start [iExc]);
5245 patch_info->type = MONO_PATCH_INFO_NONE;
5248 if (nThrows < MAX_EXC) {
5249 exc_classes [nThrows] = exc_class;
5250 exc_throw_start [nThrows] = code;
5253 /*---------------------------------------------*/
5254 /* Patch the parameter passed to the handler */
5255 /*---------------------------------------------*/
5256 S390_SET (code, s390_r2, exc_class->type_token);
5257 /*---------------------------------------------*/
5258 /* Load return address & parameter register */
5259 /*---------------------------------------------*/
5260 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5261 cfg->native_code + 8), code));
5262 /*---------------------------------------------*/
5263 /* Reuse the current patch to set the jump */
5264 /*---------------------------------------------*/
5265 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5266 patch_info->data.name = "mono_arch_throw_corlib_exception";
5267 patch_info->ip.i = code - cfg->native_code;
5268 S390_BR_TEMPLATE (code, s390_r1);
5278 cfg->code_len = code - cfg->native_code;
5280 g_assert (cfg->code_len < cfg->code_size);
5284 /*========================= End of Function ========================*/
5286 /*------------------------------------------------------------------*/
5288 /* Name - mono_arch_finish_init */
5290 /* Function - Setup the JIT's Thread Level Specific Data. */
5292 /*------------------------------------------------------------------*/
5295 mono_arch_finish_init (void)
5297 appdomain_tls_offset = mono_domain_get_tls_offset();
5298 lmf_tls_offset = mono_get_lmf_tls_offset();
5299 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5302 /*========================= End of Function ========================*/
5304 /*------------------------------------------------------------------*/
5306 /* Name - mono_arch_free_jit_tls_data */
5308 /* Function - Free tls data. */
5310 /*------------------------------------------------------------------*/
5313 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5317 /*========================= End of Function ========================*/
5319 /*------------------------------------------------------------------*/
5321 /* Name - mono_arch_emit_inst_for_method */
5323 /*------------------------------------------------------------------*/
5326 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5331 /*========================= End of Function ========================*/
5333 /*------------------------------------------------------------------*/
5335 /* Name - mono_arch_decompose_opts */
5337 /* Function - Decompose opcode into a System z opcode. */
5339 /*------------------------------------------------------------------*/
5342 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5345 * Have to rename these to avoid being decomposed normally, since the normal
5346 * decomposition does not work on S390.
5348 switch (ins->opcode) {
5350 ins->opcode = OP_S390_ISUB_OVF;
5352 case OP_ISUB_OVF_UN:
5353 ins->opcode = OP_S390_ISUB_OVF_UN;
5356 ins->opcode = OP_S390_IADD_OVF;
5358 case OP_IADD_OVF_UN:
5359 ins->opcode = OP_S390_IADD_OVF_UN;
5362 ins->opcode = OP_S390_LADD_OVF;
5364 case OP_LADD_OVF_UN:
5365 ins->opcode = OP_S390_LADD_OVF_UN;
5368 ins->opcode = OP_S390_LSUB_OVF;
5370 case OP_LSUB_OVF_UN:
5371 ins->opcode = OP_S390_LSUB_OVF_UN;
5378 /*========================= End of Function ========================*/
5380 /*------------------------------------------------------------------*/
5382 /* Name - mono_arch_print_tree */
5384 /* Function - Print platform-specific opcode details. */
5386 /* Returns - 1 - opcode details have been printed */
5387 /* 0 - opcode details have not been printed */
5389 /*------------------------------------------------------------------*/
5392 mono_arch_print_tree (MonoInst *tree, int arity)
5396 switch (tree->opcode) {
5397 case OP_S390_LOADARG:
5398 case OP_S390_ARGREG:
5399 case OP_S390_ARGPTR:
5400 printf ("[0x%lx(%s)]", tree->inst_offset,
5401 mono_arch_regname (tree->inst_basereg));
5404 case OP_S390_STKARG:
5405 printf ("[0x%lx(previous_frame)]",
5410 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5411 tree->inst_offset, tree->backend.size,
5412 mono_arch_regname(tree->dreg),
5414 mono_arch_regname(tree->sreg1));
5417 case OP_S390_SETF4RET:
5418 printf ("[f%s,f%s]",
5419 mono_arch_regname (tree->dreg),
5420 mono_arch_regname (tree->sreg1));
5424 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5426 mono_arch_regname (tree->sreg1));
5429 case OP_S390_BKCHAIN:
5430 printf ("[previous_frame(%s)]",
5431 mono_arch_regname (tree->sreg1));
5439 /*========================= End of Function ========================*/
5441 /*------------------------------------------------------------------*/
5443 /* Name - mono_arch_regalloc_cost */
5445 /* Function - Determine the cost, in the number of memory */
5446 /* references, of the action of allocating the var- */
5447 /* iable VMV into a register during global register */
5450 /* Returns - Cost */
5452 /*------------------------------------------------------------------*/
5455 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5461 /*========================= End of Function ========================*/
5463 /*------------------------------------------------------------------*/
5465 /* Name - mono_arch_flush_register_windows */
5471 /*------------------------------------------------------------------*/
5474 mono_arch_flush_register_windows (void)
5478 /*========================= End of Function ========================*/
5480 /*------------------------------------------------------------------*/
5482 /* Name - mono_arch_is_inst_imm */
5484 /* Function - Determine if operand qualifies as an immediate */
5485 /* value. For s390 this is a value -32768-32768 */
5487 /* Returns - True|False - is [not] immediate value. */
5489 /*------------------------------------------------------------------*/
5492 mono_arch_is_inst_imm (gint64 imm)
5494 return s390_is_imm32 (imm);
5497 /*========================= End of Function ========================*/
5499 /*------------------------------------------------------------------*/
5501 /* Name - mono_arch_get_patch_offset */
5503 /* Function - Dummy entry point until s390x supports aot. */
5505 /* Returns - Offset for patch. */
5507 /*------------------------------------------------------------------*/
5510 mono_arch_get_patch_offset (guint8 *code)
5515 /*========================= End of Function ========================*/
5517 /*------------------------------------------------------------------*/
5519 /* Name - mono_arch_context_get_int_reg. */
5523 /* Returns - Return a register from the context. */
5525 /*------------------------------------------------------------------*/
5528 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5530 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5533 /*========================= End of Function ========================*/
5535 /*------------------------------------------------------------------*/
5537 /* Name - mono_arch_context_set_int_reg. */
5539 /* Function - Set a value in a specified register. */
5541 /*------------------------------------------------------------------*/
5544 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5546 ctx->uc_mcontext.gregs[reg] = val;
5549 /*========================= End of Function ========================*/
5551 /*------------------------------------------------------------------*/
5553 /* Name - mono_arch_get_this_arg_from_call. */
5557 /*------------------------------------------------------------------*/
5560 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5562 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5564 return (gpointer) lmf->gregs [s390_r2];
5567 /*========================= End of Function ========================*/
5569 /*------------------------------------------------------------------*/
5571 /* Name - mono_arch_install_handler_block_guard */
5575 /*------------------------------------------------------------------*/
5578 mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause,
5579 MonoContext *ctx, gpointer new_value)
5582 gpointer *sp, old_value;
5585 offset = clause->exvar_offset;
5588 bp = MONO_CONTEXT_GET_BP (ctx);
5589 sp = *(gpointer*)(bp + offset);
5592 if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size))
5600 /*========================= End of Function ========================*/
5602 /*------------------------------------------------------------------*/
5604 /* Name - get_delegate_invoke_impl. */
5608 /*------------------------------------------------------------------*/
5611 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5613 guint8 *code, *start;
5618 start = code = mono_global_codeman_reserve (size);
5620 /* Replace the this argument with the target */
5621 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5622 s390_lg (code, s390_r2, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, target));
5623 s390_br (code, s390_r1);
5624 g_assert ((code - start) <= size);
5626 mono_arch_flush_icache (start, size);
5630 size = 32 + param_count * 8;
5631 start = code = mono_global_codeman_reserve (size);
5633 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5634 /* slide down the arguments */
5635 for (i = 0; i < param_count; ++i) {
5636 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5638 s390_br (code, s390_r1);
5640 g_assert ((code - start) <= size);
5642 mono_arch_flush_icache (start, size);
5645 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL);
5648 *code_len = code - start;
5653 /*========================= End of Function ========================*/
5655 /*------------------------------------------------------------------*/
5657 /* Name - mono_arch_get_delegate_invoke_impls. */
5661 /*------------------------------------------------------------------*/
5664 mono_arch_get_delegate_invoke_impls (void)
5672 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5673 res = g_slist_prepend (res, mono_tramp_info_create ("delegate_invoke_impl_has_target", code, code_len, NULL, NULL));
5675 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5676 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5677 tramp_name = g_strdup_printf ("delegate_invoke_impl_target_%d", i);
5678 res = g_slist_prepend (res, mono_tramp_info_create (tramp_name, code, code_len, NULL, NULL));
5679 g_free (tramp_name);
5685 /*========================= End of Function ========================*/
5687 /*------------------------------------------------------------------*/
5689 /* Name - mono_arch_get_delegate_invoke_impl. */
5693 /*------------------------------------------------------------------*/
5696 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5698 guint8 *code, *start;
5700 /* FIXME: Support more cases */
5701 if (MONO_TYPE_ISSTRUCT (sig->ret))
5705 static guint8* cached = NULL;
5711 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5713 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5715 mono_memory_barrier ();
5719 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5722 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5724 for (i = 0; i < sig->param_count; ++i)
5725 if (!mono_is_regsize_var (sig->params [i]))
5729 code = cache [sig->param_count];
5733 if (mono_aot_only) {
5734 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5735 start = mono_aot_get_trampoline (name);
5738 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5741 mono_memory_barrier ();
5743 cache [sig->param_count] = start;
5748 /*========================= End of Function ========================*/
5750 /*------------------------------------------------------------------*/
5752 /* Name - mono_arch_get_delegate_virtual_invoke_impl. */
5756 /*------------------------------------------------------------------*/
5759 mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method,
5760 int offset, gboolean load_imt_reg)
5762 guint8 *code, *start;
5765 start = code = mono_global_codeman_reserve (size);
5768 * Replace the "this" argument with the target
5770 s390_lgr (code, s390_r1, s390_r2);
5771 s390_lg (code, s390_r2, s390_r1, 0, MONO_STRUCT_OFFSET(MonoDelegate, target));
5774 * Load the IMT register, if needed
5777 s390_lg (code, MONO_ARCH_IMT_REG, s390_r2, 0, MONO_STRUCT_OFFSET(MonoDelegate, method));
5783 s390_lg (code, s390_r1, s390_r2, 0, MONO_STRUCT_OFFSET(MonoObject, vtable));
5784 s390_agfi(code, s390_r1, offset);
5785 s390_br (code, s390_r1);
5790 /*========================= End of Function ========================*/
5792 /*------------------------------------------------------------------*/
5794 /* Name - mono_arch_build_imt_thunk. */
5798 /*------------------------------------------------------------------*/
5801 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5802 MonoIMTCheckItem **imt_entries, int count,
5803 gpointer fail_tramp)
5807 guchar *code, *start;
5809 for (i = 0; i < count; ++i) {
5810 MonoIMTCheckItem *item = imt_entries [i];
5811 if (item->is_equals) {
5812 if (item->check_target_idx) {
5813 if (!item->compare_done)
5814 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5815 if (item->has_target_code)
5816 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5818 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5822 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5824 if (!item->has_target_code)
5825 item->chunk_size += LOAD_SIZE;
5827 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5828 #if ENABLE_WRONG_METHOD_CHECK
5829 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5834 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5835 imt_entries [item->check_target_idx]->compare_done = TRUE;
5837 size += item->chunk_size;
5841 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5843 code = mono_domain_code_reserve (domain, size);
5847 for (i = 0; i < count; ++i) {
5848 MonoIMTCheckItem *item = imt_entries [i];
5849 item->code_target = (guint8 *) code;
5850 if (item->is_equals) {
5851 if (item->check_target_idx) {
5852 if (!item->compare_done) {
5853 S390_SET (code, s390_r0, item->key);
5854 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5856 item->jmp_code = (guint8*) code;
5857 s390_jcl (code, S390_CC_NE, 0);
5859 if (item->has_target_code) {
5860 S390_SET (code, s390_r1, item->value.target_code);
5862 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5863 s390_lg (code, s390_r1, 0, s390_r1, 0);
5865 s390_br (code, s390_r1);
5870 S390_SET (code, s390_r0, item->key);
5871 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5872 item->jmp_code = (guint8*) code;
5873 s390_jcl (code, S390_CC_NE, 0);
5874 if (item->has_target_code) {
5875 S390_SET (code, s390_r1, item->value.target_code);
5878 S390_SET (code, s390_r1,
5879 (&(vtable->vtable [item->value.vtable_slot])));
5880 s390_lg (code, s390_r1, 0, s390_r1, 0);
5882 s390_br (code, s390_r1);
5883 target = (gint64) S390_RELATIVE(code, item->jmp_code);
5884 s390_patch_rel(item->jmp_code+2, target);
5885 S390_SET (code, s390_r1, fail_tramp);
5886 s390_br (code, s390_r1);
5887 item->jmp_code = NULL;
5889 /* enable the commented code to assert on wrong method */
5890 #if ENABLE_WRONG_METHOD_CHECK
5891 g_assert_not_reached ();
5893 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5894 s390_lg (code, s390_r1, 0, s390_r1, 0);
5895 s390_br (code, s390_r1);
5899 S390_SET (code, s390_r0, item->key);
5900 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5901 item->jmp_code = (guint8 *) code;
5902 s390_jcl (code, S390_CC_GE, 0);
5906 * patch the branches to get to the target items
5908 for (i = 0; i < count; ++i) {
5909 MonoIMTCheckItem *item = imt_entries [i];
5910 if (item->jmp_code) {
5911 if (item->check_target_idx) {
5913 offset = (gint64) S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5915 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5920 mono_arch_flush_icache ((guint8*)start, (code - start));
5921 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL);
5924 mono_stats.imt_thunks_size += (code - start);
5926 g_assert (code - start <= size);
5931 /*========================= End of Function ========================*/
5933 /*------------------------------------------------------------------*/
5935 /* Name - mono_arch_find_imt_method. */
5937 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5938 /* found in the save area. */
5940 /*------------------------------------------------------------------*/
5943 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5945 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5947 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
5950 /*========================= End of Function ========================*/
5952 /*------------------------------------------------------------------*/
5954 /* Name - mono_arch_find_static_call_vtable */
5956 /* Function - Find the static call vtable. */
5958 /*------------------------------------------------------------------*/
5961 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
5963 mgreg_t *r = (mgreg_t*)regs;
5965 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
5968 /*========================= End of Function ========================*/
5970 /*------------------------------------------------------------------*/
5972 /* Name - mono_arch_get_cie_program */
5974 /* Function - Find the static call vtable. */
5976 /*------------------------------------------------------------------*/
5979 mono_arch_get_cie_program (void)
5983 mono_add_unwind_op_def_cfa (l, 0, 0, STK_BASE, 0);
5988 /*========================= End of Function ========================*/
5990 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
5992 /*------------------------------------------------------------------*/
5994 /* Name - mono_arch_set_breakpoint. */
5996 /* Function - Set a breakpoint at the native code corresponding */
5997 /* to JI at NATIVE_OFFSET. The location should */
5998 /* contain code emitted by OP_SEQ_POINT. */
6000 /*------------------------------------------------------------------*/
6003 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6007 breakpointCode.pTrigger = bp_trigger_page;
6008 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6009 code += BREAKPOINT_SIZE;
6012 /*========================= End of Function ========================*/
6014 /*------------------------------------------------------------------*/
6016 /* Name - mono_arch_clear_breakpoint. */
6018 /* Function - Clear the breakpoint at IP. */
6020 /*------------------------------------------------------------------*/
6023 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6028 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6032 /*========================= End of Function ========================*/
6034 /*------------------------------------------------------------------*/
6036 /* Name - mono_arch_is_breakpoint_event. */
6040 /*------------------------------------------------------------------*/
6043 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6045 siginfo_t* sinfo = (siginfo_t*) info;
6048 * Sometimes the address is off by 4
6050 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6056 /*========================= End of Function ========================*/
6058 /*------------------------------------------------------------------*/
6060 /* Name - mono_arch_skip_breakpoint. */
6062 /* Function - Modify the CTX so the IP is placed after the */
6063 /* breakpoint instruction, so when we resume, the */
6064 /* instruction is not executed again. */
6066 /*------------------------------------------------------------------*/
6069 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6071 MONO_CONTEXT_SET_IP (ctx, ((guint8*)MONO_CONTEXT_GET_IP (ctx) + sizeof(RXY_Format)));
6074 /*========================= End of Function ========================*/
6076 /*------------------------------------------------------------------*/
6078 /* Name - mono_arch_start_single_stepping. */
6080 /* Function - Start single stepping. */
6082 /*------------------------------------------------------------------*/
6085 mono_arch_start_single_stepping (void)
6087 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6090 /*========================= End of Function ========================*/
6092 /*------------------------------------------------------------------*/
6094 /* Name - mono_arch_stop_single_stepping. */
6096 /* Function - Stop single stepping. */
6098 /*------------------------------------------------------------------*/
6101 mono_arch_stop_single_stepping (void)
6103 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6106 /*========================= End of Function ========================*/
6108 /*------------------------------------------------------------------*/
6110 /* Name - mono_arch_is_single_step_event. */
6112 /* Function - Return whether the machine state in sigctx cor- */
6113 /* responds to a single step event. */
6115 /*------------------------------------------------------------------*/
6118 mono_arch_is_single_step_event (void *info, void *sigctx)
6120 siginfo_t* sinfo = (siginfo_t*) info;
6123 * Sometimes the address is off by 4
6125 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6131 /*========================= End of Function ========================*/
6133 /*------------------------------------------------------------------*/
6135 /* Name - mono_arch_skip_single_step. */
6137 /* Function - Modify the ctx so the IP is placed after the */
6138 /* single step trigger instruction, so that the */
6139 /* instruction is not executed again. */
6141 /*------------------------------------------------------------------*/
6144 mono_arch_skip_single_step (MonoContext *ctx)
6146 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6149 /*========================= End of Function ========================*/
6151 /*------------------------------------------------------------------*/
6153 /* Name - mono_arch_create_seq_point_info. */
6155 /* Function - Return a pointer to a data struction which is */
6156 /* used by the sequence point implementation in */
6159 /*------------------------------------------------------------------*/
6162 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6168 /*------------------------------------------------------------------*/
6170 /* Name - mono_arch_init_lmf_ext. */
6174 /*------------------------------------------------------------------*/
6177 mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
6179 ext->lmf.previous_lmf = prev_lmf;
6180 /* Mark that this is a MonoLMFExt */
6181 ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
6182 ext->lmf.ebp = (gssize)ext;
6185 /*========================= End of Function ========================*/
6190 mono_arch_opcode_supported (int opcode)
6193 case OP_ATOMIC_ADD_I4:
6194 case OP_ATOMIC_ADD_I8:
6195 case OP_ATOMIC_EXCHANGE_I4:
6196 case OP_ATOMIC_EXCHANGE_I8: