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;
2929 int max_len, cpos, src2;
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 cpos = bb->max_offset;
2938 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2939 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2940 //g_assert (!mono_compile_aot);
2943 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2944 /* this is not thread save, but good enough */
2945 /* fixme: howto handle overflows? */
2946 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2949 MONO_BB_FOR_EACH_INS (bb, ins) {
2950 offset = code - cfg->native_code;
2952 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2954 if (offset > (cfg->code_size - max_len - 16)) {
2955 cfg->code_size *= 2;
2956 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2957 code = cfg->native_code + offset;
2960 mono_debug_record_line_number (cfg, ins, offset);
2962 switch (ins->opcode) {
2963 case OP_STOREI1_MEMBASE_IMM: {
2964 s390_lghi (code, s390_r0, ins->inst_imm);
2965 S390_LONG (code, stcy, stc, s390_r0, 0,
2966 ins->inst_destbasereg, ins->inst_offset);
2969 case OP_STOREI2_MEMBASE_IMM: {
2970 s390_lghi (code, s390_r0, ins->inst_imm);
2971 S390_LONG (code, sthy, sth, s390_r0, 0,
2972 ins->inst_destbasereg, ins->inst_offset);
2975 case OP_STOREI4_MEMBASE_IMM: {
2976 s390_lgfi (code, s390_r0, ins->inst_imm);
2977 S390_LONG (code, sty, st, s390_r0, 0,
2978 ins->inst_destbasereg, ins->inst_offset);
2981 case OP_STORE_MEMBASE_IMM:
2982 case OP_STOREI8_MEMBASE_IMM: {
2983 S390_SET (code, s390_r0, ins->inst_imm);
2984 S390_LONG (code, stg, stg, s390_r0, 0,
2985 ins->inst_destbasereg, ins->inst_offset);
2988 case OP_STOREI1_MEMBASE_REG: {
2989 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2990 ins->inst_destbasereg, ins->inst_offset);
2993 case OP_STOREI2_MEMBASE_REG: {
2994 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2995 ins->inst_destbasereg, ins->inst_offset);
2998 case OP_STOREI4_MEMBASE_REG: {
2999 S390_LONG (code, sty, st, ins->sreg1, 0,
3000 ins->inst_destbasereg, ins->inst_offset);
3003 case OP_STORE_MEMBASE_REG:
3004 case OP_STOREI8_MEMBASE_REG: {
3005 S390_LONG (code, stg, stg, ins->sreg1, 0,
3006 ins->inst_destbasereg, ins->inst_offset);
3010 g_assert_not_reached ();
3012 case OP_LOAD_MEMBASE:
3013 case OP_LOADI8_MEMBASE: {
3014 S390_LONG (code, lg, lg, ins->dreg, 0,
3015 ins->inst_basereg, ins->inst_offset);
3018 case OP_LOADI4_MEMBASE: {
3019 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3020 ins->inst_basereg, ins->inst_offset);
3023 case OP_LOADU4_MEMBASE: {
3024 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3025 ins->inst_basereg, ins->inst_offset);
3028 case OP_LOADU1_MEMBASE: {
3029 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3030 ins->inst_basereg, ins->inst_offset);
3033 case OP_LOADI1_MEMBASE: {
3034 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3035 ins->inst_basereg, ins->inst_offset);
3038 case OP_LOADU2_MEMBASE: {
3039 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3040 ins->inst_basereg, ins->inst_offset);
3043 case OP_LOADI2_MEMBASE: {
3044 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3045 ins->inst_basereg, ins->inst_offset);
3048 case OP_LCONV_TO_I1: {
3049 s390_lgbr (code, ins->dreg, ins->sreg1);
3052 case OP_LCONV_TO_I2: {
3053 s390_lghr (code, ins->dreg, ins->sreg1);
3056 case OP_LCONV_TO_U1: {
3057 s390_llgcr (code, ins->dreg, ins->sreg1);
3060 case OP_LCONV_TO_U2: {
3061 s390_llghr (code, ins->dreg, ins->sreg1);
3064 case OP_ICONV_TO_I1: {
3065 s390_lgbr (code, ins->dreg, ins->sreg1);
3068 case OP_ICONV_TO_I2: {
3069 s390_lghr (code, ins->dreg, ins->sreg1);
3072 case OP_ICONV_TO_U1: {
3073 s390_llgcr (code, ins->dreg, ins->sreg1);
3076 case OP_ICONV_TO_U2: {
3077 s390_llghr (code, ins->dreg, ins->sreg1);
3082 if (is_unsigned (ins->next))
3083 s390_clgr (code, ins->sreg1, ins->sreg2);
3085 s390_cgr (code, ins->sreg1, ins->sreg2);
3089 if (is_unsigned (ins->next))
3090 s390_clr (code, ins->sreg1, ins->sreg2);
3092 s390_cr (code, ins->sreg1, ins->sreg2);
3095 case OP_COMPARE_IMM:
3096 case OP_LCOMPARE_IMM: {
3097 S390_SET (code, s390_r0, ins->inst_imm);
3098 if (is_unsigned (ins->next))
3099 s390_clgr (code, ins->sreg1, s390_r0);
3101 s390_cgr (code, ins->sreg1, s390_r0);
3104 case OP_ICOMPARE_IMM: {
3105 S390_SET (code, s390_r0, ins->inst_imm);
3106 if (is_unsigned (ins->next))
3107 s390_clr (code, ins->sreg1, s390_r0);
3109 s390_cr (code, ins->sreg1, s390_r0);
3113 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3115 S390_CALL_TEMPLATE (code, s390_r14);
3120 s390_agr (code, ins->dreg, src2);
3125 s390_agr (code, ins->dreg, src2);
3130 s390_alcgr (code, ins->dreg, src2);
3134 if (ins->dreg != ins->sreg1) {
3135 s390_lgr (code, ins->dreg, ins->sreg1);
3137 if (s390_is_imm16 (ins->inst_imm)) {
3138 s390_aghi (code, ins->dreg, ins->inst_imm);
3139 } else if (s390_is_imm32 (ins->inst_imm)) {
3140 s390_agfi (code, ins->dreg, ins->inst_imm);
3142 S390_SET (code, s390_r0, ins->inst_imm);
3143 s390_agr (code, ins->dreg, s390_r0);
3148 if (ins->dreg != ins->sreg1) {
3149 s390_lgr (code, ins->dreg, ins->sreg1);
3151 g_assert (s390_is_imm16 (ins->inst_imm));
3152 s390_aghi (code, ins->dreg, ins->inst_imm);
3156 if (ins->dreg != ins->sreg1) {
3157 s390_lgr (code, ins->dreg, ins->sreg1);
3159 if (s390_is_imm16 (ins->inst_imm)) {
3160 s390_lghi (code, s390_r0, ins->inst_imm);
3161 s390_alcgr (code, ins->dreg, s390_r0);
3163 S390_SET (code, s390_r0, ins->inst_imm);
3164 s390_alcgr (code, ins->dreg, s390_r0);
3169 case OP_S390_IADD_OVF: {
3171 s390_ar (code, ins->dreg, src2);
3172 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3173 s390_lgfr (code, ins->dreg, ins->dreg);
3176 case OP_IADD_OVF_UN:
3177 case OP_S390_IADD_OVF_UN: {
3179 s390_algr (code, ins->dreg, src2);
3180 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3181 s390_llgfr (code, ins->dreg, ins->dreg);
3184 case OP_ADD_OVF_CARRY: {
3186 s390_lghi (code, s390_r0, 0);
3187 s390_lgr (code, s390_r1, s390_r0);
3188 s390_alcgr (code, s390_r0, s390_r1);
3189 s390_agr (code, ins->dreg, src2);
3190 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3191 s390_agr (code, ins->dreg, s390_r0);
3192 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3195 case OP_ADD_OVF_UN_CARRY: {
3197 s390_alcgr (code, ins->dreg, src2);
3198 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3203 s390_sgr (code, ins->dreg, src2);
3208 s390_sgr (code, ins->dreg, src2);
3213 s390_slbgr(code, ins->dreg, src2);
3217 if (ins->dreg != ins->sreg1) {
3218 s390_lgr (code, ins->dreg, ins->sreg1);
3220 if (s390_is_imm16 (-ins->inst_imm)) {
3221 s390_aghi (code, ins->dreg, -ins->inst_imm);
3222 } else if (s390_is_imm32 (-ins->inst_imm)) {
3223 s390_slgfi (code, ins->dreg, ins->inst_imm);
3225 S390_SET (code, s390_r0, ins->inst_imm);
3226 s390_slgr (code, ins->dreg, s390_r0);
3231 if (ins->dreg != ins->sreg1) {
3232 s390_lgr (code, ins->dreg, ins->sreg1);
3234 if (s390_is_imm16 (-ins->inst_imm)) {
3235 s390_aghi (code, ins->dreg, -ins->inst_imm);
3236 } else if (s390_is_imm32 (-ins->inst_imm)) {
3237 s390_slgfi (code, ins->dreg, ins->inst_imm);
3239 S390_SET (code, s390_r0, ins->inst_imm);
3240 s390_slgr (code, ins->dreg, s390_r0);
3245 if (ins->dreg != ins->sreg1) {
3246 s390_lgr (code, ins->dreg, ins->sreg1);
3248 if (s390_is_imm16 (-ins->inst_imm)) {
3249 s390_lghi (code, s390_r0, ins->inst_imm);
3250 s390_slbgr (code, ins->dreg, s390_r0);
3252 S390_SET (code, s390_r0, ins->inst_imm);
3253 s390_slbgr(code, ins->dreg, s390_r0);
3257 case OP_SUB_OVF_CARRY: {
3259 s390_lghi (code, s390_r0, 0);
3260 s390_lgr (code, s390_r1, s390_r0);
3261 s390_slbgr (code, s390_r0, s390_r1);
3262 s390_sgr (code, ins->dreg, src2);
3263 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3264 s390_agr (code, ins->dreg, s390_r0);
3265 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3268 case OP_SUB_OVF_UN_CARRY: {
3270 s390_slbgr (code, ins->dreg, src2);
3271 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3275 if (ins->sreg1 == ins->dreg) {
3276 s390_ngr (code, ins->dreg, ins->sreg2);
3279 if (ins->sreg2 == ins->dreg) {
3280 s390_ngr (code, ins->dreg, ins->sreg1);
3283 s390_lgr (code, ins->dreg, ins->sreg1);
3284 s390_ngr (code, ins->dreg, ins->sreg2);
3290 if (ins->dreg != ins->sreg1) {
3291 s390_lgr (code, ins->dreg, ins->sreg1);
3293 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3294 s390_ngr (code, ins->dreg, s390_r0);
3298 s390_lgr (code, s390_r1, ins->sreg1);
3299 s390_dsgr (code, s390_r0, ins->sreg2);
3300 s390_lgr (code, ins->dreg, s390_r1);
3304 s390_lgr (code, s390_r1, ins->sreg1);
3305 s390_lghi (code, s390_r0, 0);
3306 s390_dlgr (code, s390_r0, ins->sreg2);
3307 s390_lgr (code, ins->dreg, s390_r1);
3311 s390_lgr (code, s390_r1, ins->sreg1);
3312 s390_dsgr (code, s390_r0, ins->sreg2);
3313 s390_lgr (code, ins->dreg, s390_r0);
3317 if (s390_is_imm16 (ins->inst_imm)) {
3318 s390_lghi (code, s390_r13, ins->inst_imm);
3320 s390_lgfi (code, s390_r13, ins->inst_imm);
3322 s390_lgr (code, s390_r0, ins->sreg1);
3323 s390_dsgr (code, s390_r0, s390_r13);
3324 s390_lgfr (code, ins->dreg, s390_r0);
3328 s390_lgr (code, s390_r1, ins->sreg1);
3329 s390_lghi (code, s390_r0, 0);
3330 s390_dlgr (code, s390_r0, ins->sreg2);
3331 s390_lgr (code, ins->dreg, s390_r0);
3335 if (ins->sreg1 == ins->dreg) {
3336 s390_ogr (code, ins->dreg, ins->sreg2);
3339 if (ins->sreg2 == ins->dreg) {
3340 s390_ogr (code, ins->dreg, ins->sreg1);
3343 s390_lgr (code, ins->dreg, ins->sreg1);
3344 s390_ogr (code, ins->dreg, ins->sreg2);
3350 if (ins->dreg != ins->sreg1) {
3351 s390_lgr (code, ins->dreg, ins->sreg1);
3353 S390_SET_MASK(code, s390_r0, ins->inst_imm);
3354 s390_ogr (code, ins->dreg, s390_r0);
3358 if (ins->sreg1 == ins->dreg) {
3359 s390_xgr (code, ins->dreg, ins->sreg2);
3362 if (ins->sreg2 == ins->dreg) {
3363 s390_xgr (code, ins->dreg, ins->sreg1);
3366 s390_lgr (code, ins->dreg, ins->sreg1);
3367 s390_xgr (code, ins->dreg, ins->sreg2);
3373 if (ins->dreg != ins->sreg1) {
3374 s390_lgr (code, ins->dreg, ins->sreg1);
3376 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3377 s390_xgr (code, ins->dreg, s390_r0);
3382 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3387 if (ins->sreg1 != ins->dreg) {
3388 s390_lgr (code, ins->dreg, ins->sreg1);
3390 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3395 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3400 if (ins->sreg1 != ins->dreg) {
3401 s390_lgr (code, ins->dreg, ins->sreg1);
3403 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3407 case OP_LSHR_UN_IMM: {
3408 if (ins->sreg1 != ins->dreg) {
3409 s390_lgr (code, ins->dreg, ins->sreg1);
3411 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3416 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3420 if (ins->sreg1 != ins->dreg) {
3421 s390_lgr (code, ins->dreg, ins->sreg1);
3423 s390_lghi (code, s390_r0, -1);
3424 s390_xgr (code, ins->dreg, s390_r0);
3428 s390_lcgr (code, ins->dreg, ins->sreg1);
3433 s390_msgr (code, ins->dreg, src2);
3438 if (ins->dreg != ins->sreg1) {
3439 s390_lgr (code, ins->dreg, ins->sreg1);
3441 if (s390_is_imm16 (ins->inst_imm)) {
3442 s390_lghi (code, s390_r13, ins->inst_imm);
3443 } else if (s390_is_imm32 (ins->inst_imm)) {
3444 s390_lgfi (code, s390_r13, ins->inst_imm);
3446 S390_SET (code, s390_r13, ins->inst_imm);
3448 s390_msgr (code, ins->dreg, s390_r13);
3453 s390_ltgr (code, s390_r1, ins->sreg1);
3454 s390_jz (code, 0); CODEPTR(code, o[0]);
3455 s390_ltgr (code, s390_r0, ins->sreg2);
3457 s390_lghi (code, s390_r1, 0);
3458 s390_j (code, 0); CODEPTR(code, o[1]);
3459 s390_xgr (code, s390_r0, s390_r1);
3460 s390_msgr (code, s390_r1, ins->sreg2);
3461 s390_xgr (code, s390_r0, s390_r1);
3462 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3463 s390_ltgr (code, s390_r0, s390_r0);
3464 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3465 PTRSLOT (code, o[0]);
3466 PTRSLOT (code, o[1]);
3467 s390_lgr (code, ins->dreg, s390_r1);
3470 case OP_LMUL_OVF_UN: {
3471 s390_lghi (code, s390_r0, 0);
3472 s390_lgr (code, s390_r1, ins->sreg1);
3473 s390_mlgr (code, s390_r0, ins->sreg2);
3474 s390_ltgr (code, s390_r0, s390_r0);
3475 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3476 s390_lgr (code, ins->dreg, s390_r1);
3480 g_assert_not_reached ();
3482 s390_algr (code, ins->dreg, src2);
3487 s390_agr (code, ins->dreg, src2);
3491 g_assert_not_reached ();
3493 s390_alcgr (code, ins->dreg, src2);
3497 if (ins->dreg != ins->sreg1) {
3498 s390_lgfr (code, ins->dreg, ins->sreg1);
3500 if (s390_is_imm16 (ins->inst_imm)) {
3501 s390_aghi (code, ins->dreg, ins->inst_imm);
3503 s390_afi (code, ins->dreg, ins->inst_imm);
3508 if (ins->dreg != ins->sreg1) {
3509 s390_lgfr (code, ins->dreg, ins->sreg1);
3511 if (s390_is_imm16 (ins->inst_imm)) {
3512 s390_lghi (code, s390_r0, ins->inst_imm);
3513 s390_alcgr (code, ins->dreg, s390_r0);
3515 S390_SET (code, s390_r0, ins->inst_imm);
3516 s390_alcgr (code, ins->dreg, s390_r0);
3521 case OP_S390_LADD_OVF: {
3523 s390_agr (code, ins->dreg, src2);
3524 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3527 case OP_LADD_OVF_UN:
3528 case OP_S390_LADD_OVF_UN: {
3530 s390_algr (code, ins->dreg, src2);
3531 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3535 CHECK_SRCDST_NCOM_I;
3536 s390_slgr (code, ins->dreg, src2);
3540 CHECK_SRCDST_NCOM_I;
3541 s390_sgr (code, ins->dreg, src2);
3545 CHECK_SRCDST_NCOM_I;
3546 s390_slbgr (code, ins->dreg, src2);
3550 if (ins->dreg != ins->sreg1) {
3551 s390_lgfr (code, ins->dreg, ins->sreg1);
3553 if (s390_is_imm16 (-ins->inst_imm)) {
3554 s390_aghi (code, ins->dreg, -ins->inst_imm);
3556 s390_agfi (code, ins->dreg, -ins->inst_imm);
3561 S390_SET (code, s390_r0, ins->inst_imm);
3562 s390_slgfr (code, ins->dreg, s390_r0);
3566 case OP_S390_ISUB_OVF: {
3568 s390_sr (code, ins->dreg, src2);
3569 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3570 s390_lgfr (code, ins->dreg, ins->dreg);
3573 case OP_ISUB_OVF_UN:
3574 case OP_S390_ISUB_OVF_UN: {
3576 s390_slr (code, ins->dreg, src2);
3577 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3578 s390_llgfr(code, ins->dreg, ins->dreg);
3582 case OP_S390_LSUB_OVF: {
3584 s390_sgr (code, ins->dreg, src2);
3585 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3588 case OP_LSUB_OVF_UN:
3589 case OP_S390_LSUB_OVF_UN: {
3591 s390_slgr (code, ins->dreg, src2);
3592 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3596 CHECK_SRCDST_NCOM_I;
3597 s390_ngr (code, ins->dreg, src2);
3601 if (ins->dreg != ins->sreg1) {
3602 s390_lgfr (code, ins->dreg, ins->sreg1);
3604 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3605 s390_ngr (code, ins->dreg, s390_r0);
3609 s390_lgfr (code, s390_r0, ins->sreg1);
3610 s390_srda (code, s390_r0, 0, 32);
3611 s390_dr (code, s390_r0, ins->sreg2);
3612 s390_lgfr (code, ins->dreg, s390_r1);
3616 s390_lgfr (code, s390_r0, ins->sreg1);
3617 s390_srdl (code, s390_r0, 0, 32);
3618 s390_dlr (code, s390_r0, ins->sreg2);
3619 s390_lgfr (code, ins->dreg, s390_r1);
3623 if (s390_is_imm16 (ins->inst_imm)) {
3624 s390_lghi (code, s390_r13, ins->inst_imm);
3626 s390_lgfi (code, s390_r13, ins->inst_imm);
3628 s390_lgfr (code, s390_r0, ins->sreg1);
3629 s390_srda (code, s390_r0, 0, 32);
3630 s390_dr (code, s390_r0, ins->sreg2);
3631 s390_lgfr (code, ins->dreg, s390_r1);
3635 s390_lgfr (code, s390_r0, ins->sreg1);
3636 s390_srda (code, s390_r0, 0, 32);
3637 s390_dr (code, s390_r0, ins->sreg2);
3638 s390_lgfr (code, ins->dreg, s390_r0);
3641 s390_lgfr (code, s390_r0, ins->sreg1);
3642 s390_srdl (code, s390_r0, 0, 32);
3643 s390_dlr (code, s390_r0, ins->sreg2);
3644 s390_lgfr (code, ins->dreg, s390_r0);
3648 if (s390_is_imm16 (ins->inst_imm)) {
3649 s390_lghi (code, s390_r13, ins->inst_imm);
3651 s390_lgfi (code, s390_r13, ins->inst_imm);
3653 s390_lgfr (code, s390_r0, ins->sreg1);
3654 s390_srda (code, s390_r0, 0, 32);
3655 s390_dr (code, s390_r0, ins->sreg2);
3656 s390_lgfr (code, ins->dreg, s390_r0);
3661 s390_ogr (code, ins->dreg, src2);
3665 if (ins->dreg != ins->sreg1) {
3666 s390_lgfr (code, ins->dreg, ins->sreg1);
3668 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3669 s390_ogr (code, ins->dreg, s390_r0);
3674 s390_xgr (code, ins->dreg, src2);
3678 if (ins->dreg != ins->sreg1) {
3679 s390_lgfr (code, ins->dreg, ins->sreg1);
3681 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3682 s390_xgr (code, ins->dreg, s390_r0);
3687 s390_sll (code, ins->dreg, src2, 0);
3691 if (ins->sreg1 != ins->dreg) {
3692 s390_lgfr (code, ins->dreg, ins->sreg1);
3694 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3699 s390_sra (code, ins->dreg, src2, 0);
3703 if (ins->sreg1 != ins->dreg) {
3704 s390_lgfr (code, ins->dreg, ins->sreg1);
3706 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3709 case OP_ISHR_UN_IMM: {
3710 if (ins->sreg1 != ins->dreg) {
3711 s390_lgfr (code, ins->dreg, ins->sreg1);
3713 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3718 s390_srl (code, ins->dreg, src2, 0);
3722 if (ins->sreg1 != ins->dreg) {
3723 s390_lgfr (code, ins->dreg, ins->sreg1);
3725 s390_lghi (code, s390_r0, -1);
3726 s390_xgr (code, ins->dreg, s390_r0);
3730 s390_lcgr (code, ins->dreg, ins->sreg1);
3735 s390_msr (code, ins->dreg, src2);
3739 if (ins->dreg != ins->sreg1) {
3740 s390_lgfr (code, ins->dreg, ins->sreg1);
3742 if (s390_is_imm16 (ins->inst_imm)) {
3743 s390_lghi (code, s390_r0, ins->inst_imm);
3745 s390_lgfi (code, s390_r0, ins->inst_imm);
3747 s390_msr (code, ins->dreg, s390_r0);
3752 s390_ltr (code, s390_r1, ins->sreg1);
3753 s390_jz (code, 0); CODEPTR(code, o[0]);
3754 s390_ltr (code, s390_r0, ins->sreg2);
3756 s390_lhi (code, s390_r1, 0);
3757 s390_j (code, 0); CODEPTR(code, o[1]);
3758 s390_xr (code, s390_r0, s390_r1);
3759 s390_msr (code, s390_r1, ins->sreg2);
3760 s390_xr (code, s390_r0, s390_r1);
3761 s390_srl (code, s390_r0, 0, 31);
3762 s390_ltr (code, s390_r0, s390_r0);
3763 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3764 PTRSLOT (code, o[0]);
3765 PTRSLOT (code, o[1]);
3766 s390_lgfr (code, ins->dreg, s390_r1);
3769 case OP_IMUL_OVF_UN: {
3770 s390_lhi (code, s390_r0, 0);
3771 s390_lr (code, s390_r1, ins->sreg1);
3772 s390_mlr (code, s390_r0, ins->sreg2);
3773 s390_ltr (code, s390_r0, s390_r0);
3774 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3775 s390_lgfr (code, ins->dreg, s390_r1);
3780 S390_SET (code, ins->dreg, ins->inst_c0);
3784 mono_add_patch_info (cfg, code - cfg->native_code,
3785 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3786 S390_LOAD_TEMPLATE (code, ins->dreg);
3789 case OP_JUMP_TABLE: {
3790 mono_add_patch_info (cfg, code - cfg->native_code,
3791 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3792 S390_LOAD_TEMPLATE (code, ins->dreg);
3796 if (ins->dreg != ins->sreg1) {
3797 s390_lgr (code, ins->dreg, ins->sreg1);
3801 case OP_LCONV_TO_I8:
3803 s390_lgfr (code, ins->dreg, ins->sreg1);
3805 case OP_LCONV_TO_I4:
3806 s390_lgfr (code, ins->dreg, ins->sreg1);
3809 case OP_LCONV_TO_U8:
3810 case OP_LCONV_TO_U4:
3812 s390_llgfr (code, ins->dreg, ins->sreg1);
3814 case OP_LCONV_TO_OVF_U4:
3815 S390_SET (code, s390_r0, 4294967295);
3816 s390_clgr (code, ins->sreg1, s390_r0);
3817 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3818 s390_ltgr (code, ins->sreg1, ins->sreg1);
3819 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3820 s390_llgfr(code, ins->dreg, ins->sreg1);
3822 case OP_LCONV_TO_OVF_I4_UN:
3823 S390_SET (code, s390_r0, 2147483647);
3824 s390_cgr (code, ins->sreg1, s390_r0);
3825 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3826 s390_ltgr (code, ins->sreg1, ins->sreg1);
3827 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3828 s390_lgfr (code, ins->dreg, ins->sreg1);
3831 if (ins->dreg != ins->sreg1) {
3832 s390_ldr (code, ins->dreg, ins->sreg1);
3835 case OP_MOVE_F_TO_I8:
3836 s390_lgdr (code, ins->dreg, ins->sreg1);
3838 case OP_MOVE_I8_TO_F:
3839 s390_ldgr (code, ins->dreg, ins->sreg1);
3841 case OP_MOVE_F_TO_I4:
3842 s390_lgdr (code, ins->dreg, ins->sreg1);
3844 case OP_MOVE_I4_TO_F:
3845 s390_lgfr (code, s390_r0, ins->sreg1);
3846 s390_ldgr (code, ins->dreg, s390_r0);
3848 case OP_FCONV_TO_R4:
3849 s390_ledbr (code, ins->dreg, ins->sreg1);
3850 s390_ldebr (code, ins->dreg, ins->dreg);
3852 case OP_S390_SETF4RET:
3853 s390_ledbr (code, ins->dreg, ins->sreg1);
3856 if (s390_is_imm16 (ins->inst_offset)) {
3857 s390_lghi (code, s390_r13, ins->inst_offset);
3858 } else if (s390_is_imm32 (ins->inst_offset)) {
3859 s390_lgfi (code, s390_r13, ins->inst_offset);
3861 S390_SET (code, s390_r13, ins->inst_offset);
3863 s390_ear (code, s390_r1, 0);
3864 s390_sllg(code, s390_r1, s390_r1, 0, 32);
3865 s390_ear (code, s390_r1, 1);
3866 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
3870 if (cfg->method->save_lmf)
3871 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3873 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3874 code = emit_load_volatile_arguments (code, cfg);
3877 code = backUpStackPtr(cfg, code);
3878 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
3879 mono_add_patch_info (cfg, code - cfg->native_code,
3880 MONO_PATCH_INFO_METHOD_JUMP,
3882 s390_jcl (code, S390_CC_UN, 0);
3885 case OP_CHECK_THIS: {
3886 /* ensure ins->sreg1 is not NULL */
3887 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3888 s390_ltgr (code, s390_r0, s390_r0);
3889 // EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
3893 int offset = cfg->sig_cookie + cfg->stack_usage;
3895 if (s390_is_imm16 (offset)) {
3896 s390_lghi (code, s390_r0, offset);
3897 } else if (s390_is_imm32 (offset)) {
3898 s390_lgfi (code, s390_r0, offset);
3900 S390_SET (code, s390_r0, offset);
3902 s390_agr (code, s390_r0, cfg->frame_reg);
3903 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3907 call = (MonoCallInst*)ins;
3908 if (ins->flags & MONO_INST_HAS_METHOD)
3909 mono_add_patch_info (cfg, code-cfg->native_code,
3910 MONO_PATCH_INFO_METHOD,
3913 mono_add_patch_info (cfg, code-cfg->native_code,
3914 MONO_PATCH_INFO_ABS,
3916 S390_CALL_TEMPLATE (code, s390_r14);
3917 if (call->signature->ret->type == MONO_TYPE_R4)
3918 s390_ldebr (code, s390_f0, s390_f0);
3926 call = (MonoCallInst*)ins;
3927 if (ins->flags & MONO_INST_HAS_METHOD)
3928 mono_add_patch_info (cfg, code-cfg->native_code,
3929 MONO_PATCH_INFO_METHOD,
3932 mono_add_patch_info (cfg, code-cfg->native_code,
3933 MONO_PATCH_INFO_ABS,
3935 S390_CALL_TEMPLATE (code, s390_r14);
3938 case OP_FCALL_REG: {
3939 call = (MonoCallInst*)ins;
3940 s390_lgr (code, s390_r1, ins->sreg1);
3941 s390_basr (code, s390_r14, s390_r1);
3942 if (call->signature->ret->type == MONO_TYPE_R4)
3943 s390_ldebr (code, s390_f0, s390_f0);
3949 case OP_VOIDCALL_REG:
3951 s390_lgr (code, s390_r1, ins->sreg1);
3952 s390_basr (code, s390_r14, s390_r1);
3955 case OP_FCALL_MEMBASE: {
3956 call = (MonoCallInst*)ins;
3957 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3958 s390_basr (code, s390_r14, s390_r1);
3959 if (call->signature->ret->type == MONO_TYPE_R4)
3960 s390_ldebr (code, s390_f0, s390_f0);
3963 case OP_LCALL_MEMBASE:
3964 case OP_VCALL_MEMBASE:
3965 case OP_VCALL2_MEMBASE:
3966 case OP_VOIDCALL_MEMBASE:
3967 case OP_CALL_MEMBASE: {
3968 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3969 s390_basr (code, s390_r14, s390_r1);
3976 if (cfg->param_area == 0)
3977 alloca_skip = S390_MINIMAL_STACK_SIZE;
3979 alloca_skip = cfg->param_area;
3981 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3982 s390_lgr (code, s390_r1, ins->sreg1);
3983 if (ins->flags & MONO_INST_INIT)
3984 s390_lgr (code, s390_r0, ins->sreg1);
3985 s390_aghi (code, s390_r1, 14);
3986 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3987 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3988 if (cfg->method->save_lmf) {
3989 /*----------------------------------*/
3990 /* we have to adjust lmf ebp value */
3991 /*----------------------------------*/
3992 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3994 s390_lgr (code, s390_r13, cfg->frame_reg);
3995 if (s390_is_imm16(lmfOffset)) {
3996 s390_aghi (code, s390_r13, lmfOffset);
3997 } else if (s390_is_imm32(lmfOffset)) {
3998 s390_agfi (code, s390_r13, lmfOffset);
4000 S390_SET (code, s390_r13, lmfOffset);
4002 s390_lgr (code, s390_r14, STK_BASE);
4003 s390_sgr (code, s390_r14, s390_r1);
4004 s390_stg (code, s390_r14, 0, s390_r13,
4005 G_STRUCT_OFFSET(MonoLMF, ebp));
4007 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4008 s390_sgr (code, STK_BASE, s390_r1);
4009 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4010 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4011 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4012 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4013 if (ins->flags & MONO_INST_INIT) {
4014 s390_lgr (code, s390_r1, s390_r0);
4015 s390_lgr (code, s390_r0, ins->dreg);
4016 s390_lgr (code, s390_r14, s390_r12);
4017 s390_lghi (code, s390_r13, 0);
4018 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4020 s390_lgr (code, s390_r12, s390_r14);
4025 s390_lgr (code, s390_r2, ins->sreg1);
4026 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4027 (gpointer) "mono_arch_throw_exception");
4028 S390_CALL_TEMPLATE(code, s390_r14);
4032 s390_lgr (code, s390_r2, ins->sreg1);
4033 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4034 (gpointer) "mono_arch_rethrow_exception");
4035 S390_CALL_TEMPLATE(code, s390_r14);
4038 case OP_START_HANDLER: {
4039 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4041 S390_LONG (code, stg, stg, s390_r14, 0,
4042 spvar->inst_basereg,
4043 spvar->inst_offset);
4046 case OP_ENDFILTER: {
4047 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4049 if (ins->sreg1 != s390_r2)
4050 s390_lgr(code, s390_r2, ins->sreg1);
4051 S390_LONG (code, lg, lg, s390_r14, 0,
4052 spvar->inst_basereg,
4053 spvar->inst_offset);
4054 s390_br (code, s390_r14);
4057 case OP_ENDFINALLY: {
4058 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4060 S390_LONG (code, lg, lg, s390_r14, 0,
4061 spvar->inst_basereg,
4062 spvar->inst_offset);
4063 s390_br (code, s390_r14);
4066 case OP_CALL_HANDLER: {
4067 mono_add_patch_info (cfg, code-cfg->native_code,
4068 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4069 s390_brasl (code, s390_r14, 0);
4070 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4074 ins->inst_c0 = code - cfg->native_code;
4077 case OP_RELAXED_NOP:
4080 case OP_DUMMY_STORE:
4081 case OP_NOT_REACHED:
4085 case OP_IL_SEQ_POINT:
4086 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4088 case OP_SEQ_POINT: {
4091 if (cfg->compile_aot)
4095 * Read from the single stepping trigger page. This will cause a
4096 * SIGSEGV when single stepping is enabled.
4097 * We do this _before_ the breakpoint, so single stepping after
4098 * a breakpoint is hit will step to the next IL offset.
4100 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4101 breakpointCode.pTrigger = ss_trigger_page;
4102 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4103 code += BREAKPOINT_SIZE;
4106 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4109 * A placeholder for a possible breakpoint inserted by
4110 * mono_arch_set_breakpoint ().
4112 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4116 * Add an additional nop so skipping the bp doesn't cause the ip to point
4117 * to another IL offset.
4125 EMIT_UNCOND_BRANCH(ins);
4128 s390_br (code, ins->sreg1);
4134 s390_lghi(code, ins->dreg, 1);
4136 s390_lghi(code, ins->dreg, 0);
4142 s390_lghi(code, ins->dreg, 1);
4144 s390_lghi(code, ins->dreg, 0);
4150 s390_lghi(code, ins->dreg, 1);
4152 s390_lghi(code, ins->dreg, 0);
4158 s390_lghi(code, ins->dreg, 1);
4160 s390_lghi(code, ins->dreg, 0);
4166 s390_lghi(code, ins->dreg, 1);
4168 s390_lghi(code, ins->dreg, 0);
4171 case OP_COND_EXC_EQ:
4172 case OP_COND_EXC_IEQ:
4173 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4175 case OP_COND_EXC_NE_UN:
4176 case OP_COND_EXC_INE_UN:
4177 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4179 case OP_COND_EXC_LT:
4180 case OP_COND_EXC_ILT:
4181 case OP_COND_EXC_LT_UN:
4182 case OP_COND_EXC_ILT_UN:
4183 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4185 case OP_COND_EXC_GT:
4186 case OP_COND_EXC_IGT:
4187 case OP_COND_EXC_GT_UN:
4188 case OP_COND_EXC_IGT_UN:
4189 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4191 case OP_COND_EXC_GE:
4192 case OP_COND_EXC_IGE:
4193 case OP_COND_EXC_GE_UN:
4194 case OP_COND_EXC_IGE_UN:
4195 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4197 case OP_COND_EXC_LE:
4198 case OP_COND_EXC_ILE:
4199 case OP_COND_EXC_LE_UN:
4200 case OP_COND_EXC_ILE_UN:
4201 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4203 case OP_COND_EXC_OV:
4204 case OP_COND_EXC_IOV:
4205 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4207 case OP_COND_EXC_NO:
4208 case OP_COND_EXC_INO:
4209 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4212 case OP_COND_EXC_IC:
4213 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4215 case OP_COND_EXC_NC:
4216 case OP_COND_EXC_INC:
4217 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4221 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4225 EMIT_COND_BRANCH (ins, S390_CC_NE);
4231 EMIT_COND_BRANCH (ins, S390_CC_LT);
4237 EMIT_COND_BRANCH (ins, S390_CC_GT);
4243 EMIT_COND_BRANCH (ins, S390_CC_GE);
4249 EMIT_COND_BRANCH (ins, S390_CC_LE);
4252 /* floating point opcodes */
4254 if (*((double *) ins->inst_p0) == 0) {
4255 s390_lzdr (code, ins->dreg);
4257 S390_SET (code, s390_r13, ins->inst_p0);
4258 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4263 if (*((float *) ins->inst_p0) == 0) {
4264 s390_lzdr (code, ins->dreg);
4266 S390_SET (code, s390_r13, ins->inst_p0);
4267 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4271 case OP_STORER8_MEMBASE_REG: {
4272 S390_LONG (code, stdy, std, ins->sreg1, 0,
4273 ins->inst_destbasereg, ins->inst_offset);
4276 case OP_LOADR8_MEMBASE: {
4277 S390_LONG (code, ldy, ld, ins->dreg, 0,
4278 ins->inst_basereg, ins->inst_offset);
4281 case OP_STORER4_MEMBASE_REG: {
4282 s390_ledbr (code, s390_f15, ins->sreg1);
4283 S390_LONG (code, stey, ste, s390_f15, 0,
4284 ins->inst_destbasereg, ins->inst_offset);
4287 case OP_LOADR4_MEMBASE: {
4288 S390_LONG (code, ldy, ld, s390_f15, 0,
4289 ins->inst_basereg, ins->inst_offset);
4290 s390_ldebr (code, ins->dreg, s390_f15);
4293 case OP_ICONV_TO_R_UN: {
4294 s390_cdfbr (code, ins->dreg, ins->sreg1);
4295 s390_ltr (code, ins->sreg1, ins->sreg1);
4297 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4298 s390_ldgr (code, s390_f15, s390_r13);
4299 s390_adbr (code, ins->dreg, s390_f15);
4302 case OP_LCONV_TO_R_UN: {
4303 s390_cdgbr (code, ins->dreg, ins->sreg1);
4304 s390_ltgr (code, ins->sreg1, ins->sreg1);
4306 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4307 s390_ldgr (code, s390_f15, s390_r13);
4308 s390_adbr (code, ins->dreg, s390_f15);
4311 case OP_LCONV_TO_R4:
4312 case OP_ICONV_TO_R4: {
4313 s390_cegbr (code, ins->dreg, ins->sreg1);
4314 s390_ldebr (code, ins->dreg, ins->dreg);
4317 case OP_LCONV_TO_R8:
4318 case OP_ICONV_TO_R8: {
4319 s390_cdgbr (code, ins->dreg, ins->sreg1);
4322 case OP_FCONV_TO_I1:
4323 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4325 case OP_FCONV_TO_U1:
4326 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4328 case OP_FCONV_TO_I2:
4329 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4331 case OP_FCONV_TO_U2:
4332 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4334 case OP_FCONV_TO_I4:
4336 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4338 case OP_FCONV_TO_U4:
4340 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4342 case OP_FCONV_TO_I8:
4343 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4345 case OP_LCONV_TO_OVF_I: {
4346 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4348 s390_ltgr (code, ins->sreg2, ins->sreg2);
4349 s390_jnl (code, 0); CODEPTR(code, o[0]);
4350 s390_ltgr (code, ins->sreg1, ins->sreg1);
4351 s390_jnl (code, 0); CODEPTR(code, o[1]);
4352 s390_lhi (code, s390_r13, -1);
4353 s390_cgr (code, ins->sreg1, s390_r13);
4354 s390_jnz (code, 0); CODEPTR(code, o[2]);
4355 if (ins->dreg != ins->sreg2)
4356 s390_lgr (code, ins->dreg, ins->sreg2);
4357 s390_j (code, 0); CODEPTR(code, o[3]);
4358 PTRSLOT(code, o[0]);
4359 s390_jz (code, 0); CODEPTR(code, o[4]);
4360 PTRSLOT(code, o[1]);
4361 PTRSLOT(code, o[2]);
4362 mono_add_patch_info (cfg, code - cfg->native_code,
4363 MONO_PATCH_INFO_EXC, "OverflowException");
4364 s390_brasl (code, s390_r14, 0);
4365 PTRSLOT(code, o[3]);
4366 PTRSLOT(code, o[4]);
4370 s390_lpdbr (code, ins->dreg, ins->sreg1);
4374 s390_sqdbr (code, ins->dreg, ins->sreg1);
4379 s390_adbr (code, ins->dreg, src2);
4383 CHECK_SRCDST_NCOM_F;
4384 s390_sdbr (code, ins->dreg, src2);
4389 s390_mdbr (code, ins->dreg, src2);
4393 CHECK_SRCDST_NCOM_F;
4394 s390_ddbr (code, ins->dreg, src2);
4398 s390_lcdbr (code, ins->dreg, ins->sreg1);
4402 CHECK_SRCDST_NCOM_F;
4403 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4407 s390_cdbr (code, ins->sreg1, ins->sreg2);
4411 s390_cdbr (code, ins->sreg1, ins->sreg2);
4412 s390_lghi (code, ins->dreg, 1);
4414 s390_lghi (code, ins->dreg, 0);
4418 s390_cdbr (code, ins->sreg1, ins->sreg2);
4419 s390_lghi (code, ins->dreg, 1);
4421 s390_lghi (code, ins->dreg, 0);
4425 s390_cdbr (code, ins->sreg1, ins->sreg2);
4426 s390_lghi (code, ins->dreg, 1);
4428 s390_lghi (code, ins->dreg, 0);
4432 s390_cdbr (code, ins->sreg1, ins->sreg2);
4433 s390_lghi (code, ins->dreg, 1);
4435 s390_lghi (code, ins->dreg, 0);
4439 s390_cdbr (code, ins->sreg1, ins->sreg2);
4440 s390_lghi (code, ins->dreg, 1);
4442 s390_lghi (code, ins->dreg, 0);
4447 s390_jo (code, 0); CODEPTR(code, o);
4448 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4453 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4457 s390_jo (code, 0); CODEPTR(code, o);
4458 EMIT_COND_BRANCH (ins, S390_CC_LT);
4463 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4467 s390_jo (code, 0); CODEPTR(code, o);
4468 EMIT_COND_BRANCH (ins, S390_CC_GT);
4473 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4477 s390_jo (code, 0); CODEPTR(code, o);
4478 EMIT_COND_BRANCH (ins, S390_CC_GE);
4483 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4487 s390_jo (code, 0); CODEPTR(code, o);
4488 EMIT_COND_BRANCH (ins, S390_CC_LE);
4493 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4497 s390_lhi (code, s390_r13, 0x7f);
4498 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4499 s390_jz (code, 0); CODEPTR(code, o);
4500 mono_add_patch_info (cfg, code - cfg->native_code,
4501 MONO_PATCH_INFO_EXC, "ArithmeticException");
4502 s390_brasl (code, s390_r14,0);
4506 case OP_S390_MOVE: {
4507 if (ins->backend.size > 0) {
4508 if (ins->backend.size <= 256) {
4509 s390_mvc (code, ins->backend.size, ins->dreg,
4510 ins->inst_offset, ins->sreg1, ins->inst_imm);
4512 s390_lgr (code, s390_r0, ins->dreg);
4513 if (ins->inst_offset > 0) {
4514 if (s390_is_imm16 (ins->inst_offset)) {
4515 s390_aghi (code, s390_r0, ins->inst_offset);
4516 } else if (s390_is_imm32 (ins->inst_offset)) {
4517 s390_agfi (code, s390_r0, ins->inst_offset);
4519 S390_SET (code, s390_r13, ins->inst_offset);
4520 s390_agr (code, s390_r0, s390_r13);
4523 s390_lgr (code, s390_r12, ins->sreg1);
4524 if (ins->inst_imm > 0) {
4525 if (s390_is_imm16 (ins->inst_imm)) {
4526 s390_aghi (code, s390_r12, ins->inst_imm);
4527 } else if (s390_is_imm32 (ins->inst_imm)) {
4528 s390_agfi (code, s390_r12, ins->inst_imm);
4530 S390_SET (code, s390_r13, ins->inst_imm);
4531 s390_agr (code, s390_r12, s390_r13);
4534 if (s390_is_imm16 (ins->backend.size)) {
4535 s390_lghi (code, s390_r1, ins->backend.size);
4536 } else if (s390_is_imm32 (ins->inst_offset)) {
4537 s390_agfi (code, s390_r1, ins->backend.size);
4539 S390_SET (code, s390_r13, ins->backend.size);
4540 s390_agr (code, s390_r1, s390_r13);
4542 s390_lgr (code, s390_r13, s390_r1);
4543 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4549 case OP_ATOMIC_ADD_I8: {
4550 s390_lgr (code, s390_r1, ins->sreg2);
4551 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4552 s390_agr (code, s390_r1, s390_r0);
4553 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4554 s390_jnz (code, -10);
4555 s390_lgr (code, ins->dreg, s390_r1);
4558 case OP_ATOMIC_EXCHANGE_I8: {
4559 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4560 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4561 s390_jnz (code, -6);
4562 s390_lgr (code, ins->dreg, s390_r0);
4565 case OP_ATOMIC_ADD_I4: {
4566 s390_lgfr(code, s390_r1, ins->sreg2);
4567 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4568 s390_agr (code, s390_r1, s390_r0);
4569 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4570 s390_jnz (code, -9);
4571 s390_lgfr(code, ins->dreg, s390_r1);
4574 case OP_ATOMIC_EXCHANGE_I4: {
4575 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4576 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4577 s390_jnz (code, -4);
4578 s390_lgfr(code, ins->dreg, s390_r0);
4581 case OP_S390_BKCHAIN: {
4582 s390_lgr (code, ins->dreg, ins->sreg1);
4583 if (s390_is_imm16 (cfg->stack_offset)) {
4584 s390_aghi (code, ins->dreg, cfg->stack_offset);
4585 } else if (s390_is_imm32 (cfg->stack_offset)) {
4586 s390_agfi (code, ins->dreg, cfg->stack_offset);
4588 S390_SET (code, s390_r13, cfg->stack_offset);
4589 s390_agr (code, ins->dreg, s390_r13);
4593 case OP_MEMORY_BARRIER:
4596 case OP_GC_LIVENESS_DEF:
4597 case OP_GC_LIVENESS_USE:
4598 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4599 ins->backend.pc_offset = code - cfg->native_code;
4601 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4602 ins->backend.pc_offset = code - cfg->native_code;
4603 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4606 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4607 g_assert_not_reached ();
4610 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4611 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4612 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4613 g_assert_not_reached ();
4618 last_offset = offset;
4621 cfg->code_len = code - cfg->native_code;
4624 /*========================= End of Function ========================*/
4626 /*------------------------------------------------------------------*/
4628 /* Name - mono_arch_register_lowlevel_calls */
4630 /* Function - Register routines to help with --trace operation. */
4632 /*------------------------------------------------------------------*/
4635 mono_arch_register_lowlevel_calls (void)
4639 /*========================= End of Function ========================*/
4641 /*------------------------------------------------------------------*/
4643 /* Name - mono_arch_patch_code */
4645 /* Function - Process the patch data created during the */
4646 /* instruction build process. This resolves jumps, */
4647 /* calls, variables etc. */
4649 /*------------------------------------------------------------------*/
4652 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4653 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4655 MonoJumpInfo *patch_info;
4657 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4658 unsigned char *ip = patch_info->ip.i + code;
4659 gconstpointer target = NULL;
4661 target = mono_resolve_patch_target (method, domain, code,
4662 patch_info, run_cctors);
4664 switch (patch_info->type) {
4665 case MONO_PATCH_INFO_IP:
4666 case MONO_PATCH_INFO_LDSTR:
4667 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4668 case MONO_PATCH_INFO_LDTOKEN:
4669 case MONO_PATCH_INFO_EXC:
4670 s390_patch_addr (ip, (guint64) target);
4672 case MONO_PATCH_INFO_METHOD:
4673 case MONO_PATCH_INFO_INTERNAL_METHOD:
4674 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4675 case MONO_PATCH_INFO_CLASS_INIT:
4676 case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
4677 case MONO_PATCH_INFO_RGCTX_FETCH:
4678 case MONO_PATCH_INFO_ABS: {
4679 S390_EMIT_CALL (ip, target);
4682 case MONO_PATCH_INFO_SWITCH:
4683 /*----------------------------------*/
4684 /* ip points at the basr r13,0/j +4 */
4685 /* instruction the vtable value */
4686 /* follows this (i.e. ip+6) */
4687 /*----------------------------------*/
4688 S390_EMIT_LOAD (ip, target);
4690 case MONO_PATCH_INFO_METHODCONST:
4691 case MONO_PATCH_INFO_CLASS:
4692 case MONO_PATCH_INFO_IMAGE:
4693 case MONO_PATCH_INFO_FIELD:
4694 case MONO_PATCH_INFO_IID:
4695 case MONO_PATCH_INFO_EXC_NAME:
4696 target = S390_RELATIVE(target, ip);
4697 s390_patch_rel (ip, (guint64) target);
4699 case MONO_PATCH_INFO_R4:
4700 case MONO_PATCH_INFO_R8:
4701 case MONO_PATCH_INFO_METHOD_REL:
4702 g_assert_not_reached ();
4705 target = S390_RELATIVE(target, ip);
4707 s390_patch_rel (ip, (guint64) target);
4712 /*========================= End of Function ========================*/
4714 /*------------------------------------------------------------------*/
4716 /* Name - emit_load_volatile_arguments */
4718 /* Function - Emit the instructions to reload parameter regist- */
4719 /* registers for use with "tail" operations. */
4721 /* The register loading operations performed here */
4722 /* are the mirror of the store operations performed */
4723 /* in mono_arch_emit_prolog and need to be kept in */
4724 /* synchronization with it. */
4726 /*------------------------------------------------------------------*/
4729 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4732 MonoMethod *method = cfg->method;
4733 MonoMethodSignature *sig = mono_method_signature(method);
4737 cinfo = get_call_info (NULL, NULL, sig);
4739 if (cinfo->struct_ret) {
4740 ArgInfo *ainfo = &cinfo->ret;
4741 inst = cfg->vret_addr;
4742 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4745 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4746 ArgInfo *ainfo = cinfo->args + i;
4747 inst = cfg->args [pos];
4749 if (inst->opcode == OP_REGVAR) {
4750 if (ainfo->regtype == RegTypeGeneral)
4751 s390_lgr (code, ainfo->reg, inst->dreg);
4752 else if (ainfo->regtype == RegTypeFP) {
4753 if (inst->dreg != ainfo->reg) {
4754 if (ainfo->size == 4) {
4755 s390_ldebr (code, ainfo->reg, inst->dreg);
4757 s390_ldr (code, ainfo->reg, inst->dreg);
4761 else if (ainfo->regtype == RegTypeBase) {
4763 g_assert_not_reached ();
4765 if (ainfo->regtype == RegTypeGeneral) {
4766 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4767 g_assert_not_reached();
4768 switch (ainfo->size) {
4770 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4773 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4776 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4779 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4782 } else if (ainfo->regtype == RegTypeBase) {
4783 } else if (ainfo->regtype == RegTypeFP) {
4784 if (ainfo->size == 8)
4785 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4786 else if (ainfo->size == 4)
4787 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4789 g_assert_not_reached ();
4790 } else if (ainfo->regtype == RegTypeStructByVal) {
4791 if (ainfo->reg != STK_BASE) {
4792 switch (ainfo->size) {
4794 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4797 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4800 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4803 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4807 } else if (ainfo->regtype == RegTypeStructByAddr) {
4808 if (ainfo->reg != STK_BASE) {
4809 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4812 g_assert_not_reached ();
4820 /*========================= End of Function ========================*/
4822 /*------------------------------------------------------------------*/
4824 /* Name - mono_arch_emit_prolog */
4826 /* Function - Create the instruction sequence for a function */
4829 /*------------------------------------------------------------------*/
4832 mono_arch_emit_prolog (MonoCompile *cfg)
4834 MonoMethod *method = cfg->method;
4836 MonoMethodSignature *sig;
4838 long alloc_size, pos, max_offset, i, cfa_offset = 0;
4845 cfg->code_size = 512;
4847 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4849 cfg->code_size += 256;
4850 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4851 cfg->code_size += 256;
4853 if (method->save_lmf)
4854 cfg->code_size += 200;
4856 cfg->native_code = code = g_malloc (cfg->code_size);
4858 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
4859 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
4860 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4861 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
4863 if (cfg->arch.bkchain_reg != -1)
4864 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4866 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4867 cfg->used_int_regs |= 1 << 11;
4870 alloc_size = cfg->stack_offset;
4872 cfg->stack_usage = cfa_offset = alloc_size;
4873 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
4874 s390_lgr (code, s390_r11, STK_BASE);
4875 if (s390_is_imm16 (alloc_size)) {
4876 s390_aghi (code, STK_BASE, -alloc_size);
4877 } else if (s390_is_imm32 (alloc_size)) {
4878 s390_agfi (code, STK_BASE, -alloc_size);
4880 int stackSize = alloc_size;
4881 while (stackSize > INT_MAX) {
4882 s390_agfi (code, STK_BASE, -INT_MAX);
4883 stackSize -= INT_MAX;
4885 s390_agfi (code, STK_BASE, -stackSize);
4887 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4889 if (cfg->frame_reg != STK_BASE)
4890 s390_lgr (code, s390_r11, STK_BASE);
4892 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
4894 /* store runtime generic context */
4895 if (cfg->rgctx_var) {
4896 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
4898 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
4899 cfg->rgctx_var->inst_basereg,
4900 cfg->rgctx_var->inst_offset);
4903 /* compute max_offset in order to use short forward jumps
4904 * we always do it on s390 because the immediate displacement
4905 * for jumps is too small
4908 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4910 bb->max_offset = max_offset;
4912 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4915 MONO_BB_FOR_EACH_INS (bb, ins)
4916 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4919 /* load arguments allocated to register from the stack */
4920 sig = mono_method_signature (method);
4923 cinfo = get_call_info (cfg, cfg->mempool, sig);
4925 if (cinfo->struct_ret) {
4926 ArgInfo *ainfo = &cinfo->ret;
4927 inst = cfg->vret_addr;
4928 inst->backend.size = ainfo->vtsize;
4929 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4932 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4933 ArgInfo *ainfo = cinfo->args + i;
4934 inst = cfg->args [pos];
4936 if (inst->opcode == OP_VTARG_ADDR)
4937 inst = inst->inst_left;
4939 if (inst->opcode == OP_REGVAR) {
4940 if (ainfo->regtype == RegTypeGeneral)
4941 s390_lgr (code, inst->dreg, ainfo->reg);
4942 else if (ainfo->regtype == RegTypeFP) {
4943 if (inst->dreg != ainfo->reg) {
4944 if (ainfo->size == 4) {
4945 s390_ledbr (code, inst->dreg, ainfo->reg);
4947 s390_ldr (code, inst->dreg, ainfo->reg);
4951 else if (ainfo->regtype == RegTypeBase) {
4952 s390_lgr (code, s390_r13, STK_BASE);
4953 s390_aghi (code, s390_r13, alloc_size);
4954 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4956 g_assert_not_reached ();
4958 if (cfg->verbose_level > 2)
4959 g_print ("Argument %d assigned to register %s\n",
4960 pos, mono_arch_regname (inst->dreg));
4962 if (ainfo->regtype == RegTypeGeneral) {
4963 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4964 g_assert_not_reached();
4965 switch (ainfo->size) {
4967 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4970 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4973 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4976 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4979 } else if (ainfo->regtype == RegTypeBase) {
4980 } else if (ainfo->regtype == RegTypeFP) {
4981 if (ainfo->size == 8)
4982 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4983 else if (ainfo->size == 4)
4984 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4986 g_assert_not_reached ();
4987 } else if (ainfo->regtype == RegTypeStructByVal) {
4988 int doffset = inst->inst_offset;
4990 if (ainfo->reg != STK_BASE)
4994 s390_lgr (code, s390_r13, STK_BASE);
4995 s390_aghi (code, s390_r13, alloc_size);
4998 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
4999 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5004 if (ainfo->reg == STK_BASE)
5005 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5006 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5009 if (ainfo->reg == STK_BASE)
5010 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5011 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5014 if (ainfo->reg == STK_BASE)
5015 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5016 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5019 if (ainfo->reg == STK_BASE)
5020 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5021 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5024 } else if (ainfo->regtype == RegTypeStructByAddr) {
5025 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5026 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5028 g_assert_not_reached ();
5033 if (method->save_lmf) {
5034 /*---------------------------------------------------------------*/
5035 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5036 /*---------------------------------------------------------------*/
5037 lmfOffset = alloc_size - sizeof(MonoLMF);
5039 s390_lgr (code, s390_r13, cfg->frame_reg);
5040 s390_aghi (code, s390_r13, lmfOffset);
5042 /*---------------------------------------------------------------*/
5043 /* Preserve the parameter registers while we fix up the lmf */
5044 /*---------------------------------------------------------------*/
5045 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5046 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5048 /*---------------------------------------------------------------*/
5049 /* On return from this call r2 have the address of the &lmf */
5050 /*---------------------------------------------------------------*/
5051 if (lmf_addr_tls_offset == -1) {
5052 mono_add_patch_info (cfg, code - cfg->native_code,
5053 MONO_PATCH_INFO_INTERNAL_METHOD,
5054 (gpointer)"mono_get_lmf_addr");
5055 S390_CALL_TEMPLATE(code, s390_r1);
5057 /*-------------------------------------------------------*/
5058 /* Get LMF by getting value from thread level storage */
5059 /*-------------------------------------------------------*/
5060 s390_ear (code, s390_r1, 0);
5061 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5062 s390_ear (code, s390_r1, 1);
5063 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5066 /*---------------------------------------------------------------*/
5067 /* Set lmf.lmf_addr = jit_tls->lmf */
5068 /*---------------------------------------------------------------*/
5069 s390_stg (code, s390_r2, 0, s390_r13,
5070 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5072 /*---------------------------------------------------------------*/
5073 /* Get current lmf */
5074 /*---------------------------------------------------------------*/
5075 s390_lg (code, s390_r0, 0, s390_r2, 0);
5077 /*---------------------------------------------------------------*/
5078 /* Set our lmf as the current lmf */
5079 /*---------------------------------------------------------------*/
5080 s390_stg (code, s390_r13, 0, s390_r2, 0);
5082 /*---------------------------------------------------------------*/
5083 /* Have our lmf.previous_lmf point to the last lmf */
5084 /*---------------------------------------------------------------*/
5085 s390_stg (code, s390_r0, 0, s390_r13,
5086 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5088 /*---------------------------------------------------------------*/
5089 /* save method info */
5090 /*---------------------------------------------------------------*/
5091 S390_SET (code, s390_r1, method);
5092 s390_stg (code, s390_r1, 0, s390_r13,
5093 G_STRUCT_OFFSET(MonoLMF, method));
5095 /*---------------------------------------------------------------*/
5096 /* save the current IP */
5097 /*---------------------------------------------------------------*/
5098 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5099 s390_basr (code, s390_r1, 0);
5100 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5102 /*---------------------------------------------------------------*/
5103 /* Save general and floating point registers */
5104 /*---------------------------------------------------------------*/
5105 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5106 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5107 for (i = 0; i < 16; i++) {
5108 s390_std (code, i, 0, s390_r13,
5109 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5112 /*---------------------------------------------------------------*/
5113 /* Restore the parameter registers now that we've set up the lmf */
5114 /*---------------------------------------------------------------*/
5115 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5116 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5120 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5122 cfg->code_len = code - cfg->native_code;
5123 g_assert (cfg->code_len < cfg->code_size);
5128 /*========================= End of Function ========================*/
5130 /*------------------------------------------------------------------*/
5132 /* Name - mono_arch_emit_epilog */
5134 /* Function - Emit the instructions for a function epilog. */
5136 /*------------------------------------------------------------------*/
5139 mono_arch_emit_epilog (MonoCompile *cfg)
5141 MonoMethod *method = cfg->method;
5144 int max_epilog_size = 96;
5146 if (cfg->method->save_lmf)
5147 max_epilog_size += 128;
5149 if (mono_jit_trace_calls != NULL)
5150 max_epilog_size += 128;
5151 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5152 max_epilog_size += 128;
5154 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5155 cfg->code_size *= 2;
5156 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5157 cfg->stat_code_reallocs++;
5160 code = cfg->native_code + cfg->code_len;
5162 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5163 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5167 if (method->save_lmf)
5168 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5170 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5171 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5173 code = backUpStackPtr(cfg, code);
5175 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5176 s390_br (code, s390_r14);
5178 cfg->code_len = code - cfg->native_code;
5180 g_assert (cfg->code_len < cfg->code_size);
5184 /*========================= End of Function ========================*/
5186 /*------------------------------------------------------------------*/
5188 /* Name - mono_arch_emit_exceptions */
5190 /* Function - Emit the blocks to handle exception conditions. */
5192 /*------------------------------------------------------------------*/
5195 mono_arch_emit_exceptions (MonoCompile *cfg)
5197 MonoJumpInfo *patch_info;
5203 MonoClass *exc_classes [MAX_EXC];
5204 guint8 *exc_throw_start [MAX_EXC];
5206 for (patch_info = cfg->patch_info;
5208 patch_info = patch_info->next) {
5209 if (patch_info->type == MONO_PATCH_INFO_EXC)
5213 code_size = exc_count * 48;
5215 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5216 cfg->code_size *= 2;
5217 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5218 cfg->stat_code_reallocs++;
5221 code = cfg->native_code + cfg->code_len;
5223 /*---------------------------------------------------------------------*/
5224 /* Add code to raise exceptions */
5225 /*---------------------------------------------------------------------*/
5226 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5227 switch (patch_info->type) {
5228 case MONO_PATCH_INFO_EXC: {
5229 guint8 *ip = patch_info->ip.i + cfg->native_code;
5230 MonoClass *exc_class;
5233 /*-----------------------------------------------------*/
5234 /* Patch the branch in epilog to come here */
5235 /*-----------------------------------------------------*/
5236 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5238 exc_class = mono_class_from_name (mono_defaults.corlib,
5240 patch_info->data.name);
5241 g_assert (exc_class);
5242 throw_ip = patch_info->ip.i;
5244 for (iExc = 0; iExc < nThrows; ++iExc)
5245 if (exc_classes [iExc] == exc_class)
5248 if (iExc < nThrows) {
5249 s390_jcl (code, S390_CC_UN,
5250 (guint64) exc_throw_start [iExc]);
5251 patch_info->type = MONO_PATCH_INFO_NONE;
5254 if (nThrows < MAX_EXC) {
5255 exc_classes [nThrows] = exc_class;
5256 exc_throw_start [nThrows] = code;
5259 /*---------------------------------------------*/
5260 /* Patch the parameter passed to the handler */
5261 /*---------------------------------------------*/
5262 S390_SET (code, s390_r2, exc_class->type_token);
5263 /*---------------------------------------------*/
5264 /* Load return address & parameter register */
5265 /*---------------------------------------------*/
5266 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5267 cfg->native_code + 8), code));
5268 /*---------------------------------------------*/
5269 /* Reuse the current patch to set the jump */
5270 /*---------------------------------------------*/
5271 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5272 patch_info->data.name = "mono_arch_throw_corlib_exception";
5273 patch_info->ip.i = code - cfg->native_code;
5274 S390_BR_TEMPLATE (code, s390_r1);
5284 cfg->code_len = code - cfg->native_code;
5286 g_assert (cfg->code_len < cfg->code_size);
5290 /*========================= End of Function ========================*/
5292 /*------------------------------------------------------------------*/
5294 /* Name - mono_arch_finish_init */
5296 /* Function - Setup the JIT's Thread Level Specific Data. */
5298 /*------------------------------------------------------------------*/
5301 mono_arch_finish_init (void)
5303 appdomain_tls_offset = mono_domain_get_tls_offset();
5304 lmf_tls_offset = mono_get_lmf_tls_offset();
5305 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5308 /*========================= End of Function ========================*/
5310 /*------------------------------------------------------------------*/
5312 /* Name - mono_arch_free_jit_tls_data */
5314 /* Function - Free tls data. */
5316 /*------------------------------------------------------------------*/
5319 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5323 /*========================= End of Function ========================*/
5325 /*------------------------------------------------------------------*/
5327 /* Name - mono_arch_emit_inst_for_method */
5329 /*------------------------------------------------------------------*/
5332 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5337 /*========================= End of Function ========================*/
5339 /*------------------------------------------------------------------*/
5341 /* Name - mono_arch_decompose_opts */
5343 /* Function - Decompose opcode into a System z opcode. */
5345 /*------------------------------------------------------------------*/
5348 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5351 * Have to rename these to avoid being decomposed normally, since the normal
5352 * decomposition does not work on S390.
5354 switch (ins->opcode) {
5356 ins->opcode = OP_S390_ISUB_OVF;
5358 case OP_ISUB_OVF_UN:
5359 ins->opcode = OP_S390_ISUB_OVF_UN;
5362 ins->opcode = OP_S390_IADD_OVF;
5364 case OP_IADD_OVF_UN:
5365 ins->opcode = OP_S390_IADD_OVF_UN;
5368 ins->opcode = OP_S390_LADD_OVF;
5370 case OP_LADD_OVF_UN:
5371 ins->opcode = OP_S390_LADD_OVF_UN;
5374 ins->opcode = OP_S390_LSUB_OVF;
5376 case OP_LSUB_OVF_UN:
5377 ins->opcode = OP_S390_LSUB_OVF_UN;
5384 /*========================= End of Function ========================*/
5386 /*------------------------------------------------------------------*/
5388 /* Name - mono_arch_print_tree */
5390 /* Function - Print platform-specific opcode details. */
5392 /* Returns - 1 - opcode details have been printed */
5393 /* 0 - opcode details have not been printed */
5395 /*------------------------------------------------------------------*/
5398 mono_arch_print_tree (MonoInst *tree, int arity)
5402 switch (tree->opcode) {
5403 case OP_S390_LOADARG:
5404 case OP_S390_ARGREG:
5405 case OP_S390_ARGPTR:
5406 printf ("[0x%lx(%s)]", tree->inst_offset,
5407 mono_arch_regname (tree->inst_basereg));
5410 case OP_S390_STKARG:
5411 printf ("[0x%lx(previous_frame)]",
5416 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5417 tree->inst_offset, tree->backend.size,
5418 mono_arch_regname(tree->dreg),
5420 mono_arch_regname(tree->sreg1));
5423 case OP_S390_SETF4RET:
5424 printf ("[f%s,f%s]",
5425 mono_arch_regname (tree->dreg),
5426 mono_arch_regname (tree->sreg1));
5430 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5432 mono_arch_regname (tree->sreg1));
5435 case OP_S390_BKCHAIN:
5436 printf ("[previous_frame(%s)]",
5437 mono_arch_regname (tree->sreg1));
5445 /*========================= End of Function ========================*/
5447 /*------------------------------------------------------------------*/
5449 /* Name - mono_arch_regalloc_cost */
5451 /* Function - Determine the cost, in the number of memory */
5452 /* references, of the action of allocating the var- */
5453 /* iable VMV into a register during global register */
5456 /* Returns - Cost */
5458 /*------------------------------------------------------------------*/
5461 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5467 /*========================= End of Function ========================*/
5469 /*------------------------------------------------------------------*/
5471 /* Name - mono_arch_flush_register_windows */
5477 /*------------------------------------------------------------------*/
5480 mono_arch_flush_register_windows (void)
5484 /*========================= End of Function ========================*/
5486 /*------------------------------------------------------------------*/
5488 /* Name - mono_arch_is_inst_imm */
5490 /* Function - Determine if operand qualifies as an immediate */
5491 /* value. For s390 this is a value -32768-32768 */
5493 /* Returns - True|False - is [not] immediate value. */
5495 /*------------------------------------------------------------------*/
5498 mono_arch_is_inst_imm (gint64 imm)
5500 return s390_is_imm32 (imm);
5503 /*========================= End of Function ========================*/
5505 /*------------------------------------------------------------------*/
5507 /* Name - mono_arch_get_patch_offset */
5509 /* Function - Dummy entry point until s390x supports aot. */
5511 /* Returns - Offset for patch. */
5513 /*------------------------------------------------------------------*/
5516 mono_arch_get_patch_offset (guint8 *code)
5521 /*========================= End of Function ========================*/
5523 /*------------------------------------------------------------------*/
5525 /* Name - mono_arch_context_get_int_reg. */
5529 /* Returns - Return a register from the context. */
5531 /*------------------------------------------------------------------*/
5534 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5536 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5539 /*========================= End of Function ========================*/
5541 /*------------------------------------------------------------------*/
5543 /* Name - mono_arch_context_set_int_reg. */
5545 /* Function - Set a value in a specified register. */
5547 /*------------------------------------------------------------------*/
5550 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5552 ctx->uc_mcontext.gregs[reg] = val;
5555 /*========================= End of Function ========================*/
5557 /*------------------------------------------------------------------*/
5559 /* Name - mono_arch_get_this_arg_from_call. */
5563 /*------------------------------------------------------------------*/
5566 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5568 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5570 return (gpointer) lmf->gregs [s390_r2];
5573 /*========================= End of Function ========================*/
5575 /*------------------------------------------------------------------*/
5577 /* Name - mono_arch_install_handler_block_guard */
5581 /*------------------------------------------------------------------*/
5584 mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause,
5585 MonoContext *ctx, gpointer new_value)
5588 gpointer *sp, old_value;
5591 offset = clause->exvar_offset;
5594 bp = MONO_CONTEXT_GET_BP (ctx);
5595 sp = *(gpointer*)(bp + offset);
5598 if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size))
5606 /*========================= End of Function ========================*/
5608 /*------------------------------------------------------------------*/
5610 /* Name - get_delegate_invoke_impl. */
5614 /*------------------------------------------------------------------*/
5617 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5619 guint8 *code, *start;
5624 start = code = mono_global_codeman_reserve (size);
5626 /* Replace the this argument with the target */
5627 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5628 s390_lg (code, s390_r2, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, target));
5629 s390_br (code, s390_r1);
5630 g_assert ((code - start) <= size);
5632 mono_arch_flush_icache (start, size);
5636 size = 32 + param_count * 8;
5637 start = code = mono_global_codeman_reserve (size);
5639 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5640 /* slide down the arguments */
5641 for (i = 0; i < param_count; ++i) {
5642 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5644 s390_br (code, s390_r1);
5646 g_assert ((code - start) <= size);
5648 mono_arch_flush_icache (start, size);
5651 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL);
5654 *code_len = code - start;
5659 /*========================= End of Function ========================*/
5661 /*------------------------------------------------------------------*/
5663 /* Name - mono_arch_get_delegate_invoke_impls. */
5667 /*------------------------------------------------------------------*/
5670 mono_arch_get_delegate_invoke_impls (void)
5678 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5679 res = g_slist_prepend (res, mono_tramp_info_create ("delegate_invoke_impl_has_target", code, code_len, NULL, NULL));
5681 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5682 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5683 tramp_name = g_strdup_printf ("delegate_invoke_impl_target_%d", i);
5684 res = g_slist_prepend (res, mono_tramp_info_create (tramp_name, code, code_len, NULL, NULL));
5685 g_free (tramp_name);
5691 /*========================= End of Function ========================*/
5693 /*------------------------------------------------------------------*/
5695 /* Name - mono_arch_get_delegate_invoke_impl. */
5699 /*------------------------------------------------------------------*/
5702 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5704 guint8 *code, *start;
5706 /* FIXME: Support more cases */
5707 if (MONO_TYPE_ISSTRUCT (sig->ret))
5711 static guint8* cached = NULL;
5717 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5719 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5721 mono_memory_barrier ();
5725 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5728 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5730 for (i = 0; i < sig->param_count; ++i)
5731 if (!mono_is_regsize_var (sig->params [i]))
5735 code = cache [sig->param_count];
5739 if (mono_aot_only) {
5740 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5741 start = mono_aot_get_trampoline (name);
5744 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5747 mono_memory_barrier ();
5749 cache [sig->param_count] = start;
5754 /*========================= End of Function ========================*/
5756 /*------------------------------------------------------------------*/
5758 /* Name - mono_arch_get_delegate_virtual_invoke_impl. */
5762 /*------------------------------------------------------------------*/
5765 mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method,
5766 int offset, gboolean load_imt_reg)
5768 guint8 *code, *start;
5771 start = code = mono_global_codeman_reserve (size);
5774 * Replace the "this" argument with the target
5776 s390_lgr (code, s390_r1, s390_r2);
5777 s390_lg (code, s390_r2, s390_r1, 0, MONO_STRUCT_OFFSET(MonoDelegate, target));
5780 * Load the IMT register, if needed
5783 s390_lg (code, MONO_ARCH_IMT_REG, s390_r2, 0, MONO_STRUCT_OFFSET(MonoDelegate, method));
5789 s390_lg (code, s390_r1, s390_r2, 0, MONO_STRUCT_OFFSET(MonoObject, vtable));
5790 s390_agfi(code, s390_r1, offset);
5791 s390_br (code, s390_r1);
5796 /*========================= End of Function ========================*/
5798 /*------------------------------------------------------------------*/
5800 /* Name - mono_arch_build_imt_thunk. */
5804 /*------------------------------------------------------------------*/
5807 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5808 MonoIMTCheckItem **imt_entries, int count,
5809 gpointer fail_tramp)
5813 guchar *code, *start;
5815 for (i = 0; i < count; ++i) {
5816 MonoIMTCheckItem *item = imt_entries [i];
5817 if (item->is_equals) {
5818 if (item->check_target_idx) {
5819 if (!item->compare_done)
5820 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5821 if (item->has_target_code)
5822 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5824 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5828 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5830 if (!item->has_target_code)
5831 item->chunk_size += LOAD_SIZE;
5833 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5834 #if ENABLE_WRONG_METHOD_CHECK
5835 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5840 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5841 imt_entries [item->check_target_idx]->compare_done = TRUE;
5843 size += item->chunk_size;
5847 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5849 code = mono_domain_code_reserve (domain, size);
5853 for (i = 0; i < count; ++i) {
5854 MonoIMTCheckItem *item = imt_entries [i];
5855 item->code_target = (guint8 *) code;
5856 if (item->is_equals) {
5857 if (item->check_target_idx) {
5858 if (!item->compare_done) {
5859 S390_SET (code, s390_r0, item->key);
5860 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5862 item->jmp_code = (guint8*) code;
5863 s390_jcl (code, S390_CC_NE, 0);
5865 if (item->has_target_code) {
5866 S390_SET (code, s390_r1, item->value.target_code);
5868 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5869 s390_lg (code, s390_r1, 0, s390_r1, 0);
5871 s390_br (code, s390_r1);
5876 S390_SET (code, s390_r0, item->key);
5877 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5878 item->jmp_code = (guint8*) code;
5879 s390_jcl (code, S390_CC_NE, 0);
5880 if (item->has_target_code) {
5881 S390_SET (code, s390_r1, item->value.target_code);
5884 S390_SET (code, s390_r1,
5885 (&(vtable->vtable [item->value.vtable_slot])));
5886 s390_lg (code, s390_r1, 0, s390_r1, 0);
5888 s390_br (code, s390_r1);
5889 target = (gint64) S390_RELATIVE(code, item->jmp_code);
5890 s390_patch_rel(item->jmp_code+2, target);
5891 S390_SET (code, s390_r1, fail_tramp);
5892 s390_br (code, s390_r1);
5893 item->jmp_code = NULL;
5895 /* enable the commented code to assert on wrong method */
5896 #if ENABLE_WRONG_METHOD_CHECK
5897 g_assert_not_reached ();
5899 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5900 s390_lg (code, s390_r1, 0, s390_r1, 0);
5901 s390_br (code, s390_r1);
5905 S390_SET (code, s390_r0, item->key);
5906 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5907 item->jmp_code = (guint8 *) code;
5908 s390_jcl (code, S390_CC_GE, 0);
5912 * patch the branches to get to the target items
5914 for (i = 0; i < count; ++i) {
5915 MonoIMTCheckItem *item = imt_entries [i];
5916 if (item->jmp_code) {
5917 if (item->check_target_idx) {
5919 offset = (gint64) S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5921 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5926 mono_arch_flush_icache ((guint8*)start, (code - start));
5927 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL);
5930 mono_stats.imt_thunks_size += (code - start);
5932 g_assert (code - start <= size);
5937 /*========================= End of Function ========================*/
5939 /*------------------------------------------------------------------*/
5941 /* Name - mono_arch_find_imt_method. */
5943 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5944 /* found in the save area. */
5946 /*------------------------------------------------------------------*/
5949 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5951 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5953 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
5956 /*========================= End of Function ========================*/
5958 /*------------------------------------------------------------------*/
5960 /* Name - mono_arch_find_static_call_vtable */
5962 /* Function - Find the static call vtable. */
5964 /*------------------------------------------------------------------*/
5967 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
5969 mgreg_t *r = (mgreg_t*)regs;
5971 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
5974 /*========================= End of Function ========================*/
5976 /*------------------------------------------------------------------*/
5978 /* Name - mono_arch_get_cie_program */
5980 /* Function - Find the static call vtable. */
5982 /*------------------------------------------------------------------*/
5985 mono_arch_get_cie_program (void)
5989 mono_add_unwind_op_def_cfa (l, 0, 0, STK_BASE, 0);
5994 /*========================= End of Function ========================*/
5996 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
5998 /*------------------------------------------------------------------*/
6000 /* Name - mono_arch_set_breakpoint. */
6002 /* Function - Set a breakpoint at the native code corresponding */
6003 /* to JI at NATIVE_OFFSET. The location should */
6004 /* contain code emitted by OP_SEQ_POINT. */
6006 /*------------------------------------------------------------------*/
6009 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6013 breakpointCode.pTrigger = bp_trigger_page;
6014 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6015 code += BREAKPOINT_SIZE;
6018 /*========================= End of Function ========================*/
6020 /*------------------------------------------------------------------*/
6022 /* Name - mono_arch_clear_breakpoint. */
6024 /* Function - Clear the breakpoint at IP. */
6026 /*------------------------------------------------------------------*/
6029 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6034 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6038 /*========================= End of Function ========================*/
6040 /*------------------------------------------------------------------*/
6042 /* Name - mono_arch_is_breakpoint_event. */
6046 /*------------------------------------------------------------------*/
6049 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6051 siginfo_t* sinfo = (siginfo_t*) info;
6054 * Sometimes the address is off by 4
6056 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6062 /*========================= End of Function ========================*/
6064 /*------------------------------------------------------------------*/
6066 /* Name - mono_arch_skip_breakpoint. */
6068 /* Function - Modify the CTX so the IP is placed after the */
6069 /* breakpoint instruction, so when we resume, the */
6070 /* instruction is not executed again. */
6072 /*------------------------------------------------------------------*/
6075 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6077 MONO_CONTEXT_SET_IP (ctx, ((guint8*)MONO_CONTEXT_GET_IP (ctx) + sizeof(RXY_Format)));
6080 /*========================= End of Function ========================*/
6082 /*------------------------------------------------------------------*/
6084 /* Name - mono_arch_start_single_stepping. */
6086 /* Function - Start single stepping. */
6088 /*------------------------------------------------------------------*/
6091 mono_arch_start_single_stepping (void)
6093 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6096 /*========================= End of Function ========================*/
6098 /*------------------------------------------------------------------*/
6100 /* Name - mono_arch_stop_single_stepping. */
6102 /* Function - Stop single stepping. */
6104 /*------------------------------------------------------------------*/
6107 mono_arch_stop_single_stepping (void)
6109 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6112 /*========================= End of Function ========================*/
6114 /*------------------------------------------------------------------*/
6116 /* Name - mono_arch_is_single_step_event. */
6118 /* Function - Return whether the machine state in sigctx cor- */
6119 /* responds to a single step event. */
6121 /*------------------------------------------------------------------*/
6124 mono_arch_is_single_step_event (void *info, void *sigctx)
6126 siginfo_t* sinfo = (siginfo_t*) info;
6129 * Sometimes the address is off by 4
6131 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6137 /*========================= End of Function ========================*/
6139 /*------------------------------------------------------------------*/
6141 /* Name - mono_arch_skip_single_step. */
6143 /* Function - Modify the ctx so the IP is placed after the */
6144 /* single step trigger instruction, so that the */
6145 /* instruction is not executed again. */
6147 /*------------------------------------------------------------------*/
6150 mono_arch_skip_single_step (MonoContext *ctx)
6152 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6155 /*========================= End of Function ========================*/
6157 /*------------------------------------------------------------------*/
6159 /* Name - mono_arch_create_seq_point_info. */
6161 /* Function - Return a pointer to a data struction which is */
6162 /* used by the sequence point implementation in */
6165 /*------------------------------------------------------------------*/
6168 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6174 /*------------------------------------------------------------------*/
6176 /* Name - mono_arch_init_lmf_ext. */
6180 /*------------------------------------------------------------------*/
6183 mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
6185 ext->lmf.previous_lmf = prev_lmf;
6186 /* Mark that this is a MonoLMFExt */
6187 ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
6188 ext->lmf.ebp = (gssize)ext;
6191 /*========================= End of Function ========================*/
6196 mono_arch_opcode_supported (int opcode)
6199 case OP_ATOMIC_ADD_I4:
6200 case OP_ATOMIC_ADD_I8:
6201 case OP_ATOMIC_EXCHANGE_I4:
6202 case OP_ATOMIC_EXCHANGE_I8: