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>
270 #include <mono/utils/mono-threads.h>
272 #include "mini-s390x.h"
273 #include "cpu-s390x.h"
274 #include "support-s390x.h"
275 #include "jit-icalls.h"
279 /*========================= End of Includes ========================*/
281 /*------------------------------------------------------------------*/
282 /* T y p e d e f s */
283 /*------------------------------------------------------------------*/
295 /*------------------------------------------------------------------*/
296 /* Used by the instrument_emit_epilog */
297 /*------------------------------------------------------------------*/
308 typedef struct InstList InstList;
322 RegTypeStructByValInFP,
324 RegTypeStructByAddrOnStack
328 gint32 offset; /* offset from caller's stack */
329 gint32 offparm; /* offset from callee's stack */
330 guint16 vtsize; /* in param area */
333 guint32 size; /* Size of structure used by RegTypeStructByVal */
334 gint32 type; /* Data type of argument */
350 gint64 gr[5]; /* R2-R6 */
351 gdouble fp[3]; /* F0-F2 */
352 } __attribute__ ((packed)) RegParm;
360 } __attribute__ ((packed)) breakpoint_t;
362 /*========================= End of Typedefs ========================*/
364 /*------------------------------------------------------------------*/
365 /* P r o t o t y p e s */
366 /*------------------------------------------------------------------*/
368 static void indent (int);
369 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
370 static void decodeParm (MonoType *, void *, int);
371 static void enter_method (MonoMethod *, RegParm *, char *);
372 static void leave_method (MonoMethod *, ...);
373 static inline void add_general (guint *, size_data *, ArgInfo *);
374 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
375 static inline void add_float (guint *, size_data *, ArgInfo *);
376 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
377 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
378 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
379 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
381 /*========================= End of Prototypes ======================*/
383 /*------------------------------------------------------------------*/
384 /* G l o b a l V a r i a b l e s */
385 /*------------------------------------------------------------------*/
387 int mono_exc_esp_offset = 0;
389 __thread int indent_level = 0;
391 static gint appdomain_tls_offset = -1,
393 lmf_addr_tls_offset = -1;
395 pthread_key_t lmf_addr_key;
397 gboolean lmf_addr_key_inited = FALSE;
402 * The code generated for sequence points reads from this location,
403 * which is made read-only when single stepping is enabled.
405 static gpointer ss_trigger_page;
408 * Enabled breakpoints read from this trigger page
410 static gpointer bp_trigger_page;
412 breakpoint_t breakpointCode;
414 static mono_mutex_t mini_arch_mutex;
416 /*====================== End of Global Variables ===================*/
418 /*------------------------------------------------------------------*/
420 /* Name - mono_arch_regname */
422 /* Function - Returns the name of the register specified by */
423 /* the input parameter. */
425 /*------------------------------------------------------------------*/
428 mono_arch_regname (int reg) {
429 static const char * rnames[] = {
430 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
431 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
432 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
436 if (reg >= 0 && reg < 16)
442 /*========================= End of Function ========================*/
444 /*------------------------------------------------------------------*/
446 /* Name - mono_arch_fregname */
448 /* Function - Returns the name of the register specified by */
449 /* the input parameter. */
451 /*------------------------------------------------------------------*/
454 mono_arch_fregname (int reg) {
455 static const char * rnames[] = {
456 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
457 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
458 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
462 if (reg >= 0 && reg < 16)
468 /*========================= End of Function ========================*/
470 /*------------------------------------------------------------------*/
472 /* Name - arch_get_argument_info */
474 /* Function - Gathers information on parameters such as size, */
475 /* alignment, and padding. arg_info should be large */
476 /* enough to hold param_count + 1 entries. */
478 /* Parameters - @csig - Method signature */
479 /* @param_count - No. of parameters to consider */
480 /* @arg_info - An array to store the result info */
482 /* Returns - Size of the activation frame */
484 /*------------------------------------------------------------------*/
487 mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig,
489 MonoJitArgumentInfo *arg_info)
491 int k, frame_size = 0;
492 int size, align, pad;
495 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
496 frame_size += sizeof (gpointer);
500 arg_info [0].offset = offset;
503 frame_size += sizeof (gpointer);
507 arg_info [0].size = frame_size;
509 for (k = 0; k < param_count; k++) {
512 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
514 size = mini_type_stack_size (NULL, csig->params [k], &align);
516 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
517 arg_info [k].pad = pad;
519 arg_info [k + 1].pad = 0;
520 arg_info [k + 1].size = size;
522 arg_info [k + 1].offset = offset;
526 align = MONO_ARCH_FRAME_ALIGNMENT;
527 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
528 arg_info [k].pad = pad;
533 /*========================= End of Function ========================*/
535 /*------------------------------------------------------------------*/
537 /* Name - emit_unwind_regs. */
539 /* Function - Determines if a value can be returned in one or */
542 /*------------------------------------------------------------------*/
544 static void __inline__
545 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
549 for (i = start; i < end; i++) {
550 mono_emit_unwind_op_offset (cfg, code, i, offset);
551 offset += sizeof(gulong);
555 /*========================= End of Function ========================*/
557 /*------------------------------------------------------------------*/
559 /* Name - retFitsInReg. */
561 /* Function - Determines if a value can be returned in one or */
564 /*------------------------------------------------------------------*/
566 static inline gboolean
567 retFitsInReg(guint32 size)
582 /*========================= End of Function ========================*/
584 /*------------------------------------------------------------------*/
586 /* Name - backStackPtr. */
588 /* Function - Restore Stack Pointer to previous frame. */
590 /*------------------------------------------------------------------*/
592 static inline guint8 *
593 backUpStackPtr(MonoCompile *cfg, guint8 *code)
595 int stackSize = cfg->stack_usage;
597 if (cfg->frame_reg != STK_BASE)
598 s390_lgr (code, STK_BASE, cfg->frame_reg);
600 if (s390_is_imm16 (stackSize)) {
601 s390_aghi (code, STK_BASE, stackSize);
603 while (stackSize > 32767) {
604 s390_aghi (code, STK_BASE, 32767);
607 s390_aghi (code, STK_BASE, stackSize);
612 /*========================= End of Function ========================*/
614 /*------------------------------------------------------------------*/
618 /* Function - Perform nice indenting to current level */
620 /*------------------------------------------------------------------*/
626 indent_level += diff;
628 printf("%p [%3d] ",(void *)pthread_self(),v);
633 indent_level += diff;
636 /*========================= End of Function ========================*/
638 /*------------------------------------------------------------------*/
640 /* Name - cvtMonoType */
642 /* Function - Convert a mono-type to a string. */
644 /*------------------------------------------------------------------*/
647 cvtMonoType(MonoTypeEnum t)
652 return "MONO_TYPE_END";
654 return "MONO_TYPE_VOID";
655 case MONO_TYPE_BOOLEAN:
656 return "MONO_TYPE_BOOLEAN";
658 return "MONO_TYPE_CHAR";
660 return "MONO_TYPE_I1";
662 return "MONO_TYPE_U1";
664 return "MONO_TYPE_I2";
666 return "MONO_TYPE_U2";
668 return "MONO_TYPE_I4";
670 return "MONO_TYPE_U4";
672 return "MONO_TYPE_I8";
674 return "MONO_TYPE_U8";
676 return "MONO_TYPE_R4";
678 return "MONO_TYPE_R8";
679 case MONO_TYPE_STRING:
680 return "MONO_TYPE_STRING";
682 return "MONO_TYPE_PTR";
683 case MONO_TYPE_BYREF:
684 return "MONO_TYPE_BYREF";
685 case MONO_TYPE_VALUETYPE:
686 return "MONO_TYPE_VALUETYPE";
687 case MONO_TYPE_CLASS:
688 return "MONO_TYPE_CLASS";
690 return "MONO_TYPE_VAR";
691 case MONO_TYPE_ARRAY:
692 return "MONO_TYPE_ARRAY";
693 case MONO_TYPE_GENERICINST:
694 return "MONO_TYPE_GENERICINST";
695 case MONO_TYPE_TYPEDBYREF:
696 return "MONO_TYPE_TYPEDBYREF";
698 return "MONO_TYPE_I";
700 return "MONO_TYPE_U";
701 case MONO_TYPE_FNPTR:
702 return "MONO_TYPE_FNPTR";
703 case MONO_TYPE_OBJECT:
704 return "MONO_TYPE_OBJECT";
705 case MONO_TYPE_SZARRAY:
706 return "MONO_TYPE_SZARRAY";
708 return "MONO_TYPE_MVAR";
709 case MONO_TYPE_CMOD_REQD:
710 return "MONO_TYPE_CMOD_REQD";
711 case MONO_TYPE_CMOD_OPT:
712 return "MONO_TYPE_CMOD_OPT";
713 case MONO_TYPE_INTERNAL:
714 return "MONO_TYPE_INTERNAL";
715 case MONO_TYPE_MODIFIER:
716 return "MONO_TYPE_MODIFIER";
717 case MONO_TYPE_SENTINEL:
718 return "MONO_TYPE_SENTINEL";
719 case MONO_TYPE_PINNED:
720 return "MONO_TYPE_PINNED";
727 /*========================= End of Function ========================*/
729 /*------------------------------------------------------------------*/
731 /* Name - decodeParm */
733 /* Function - Decode a parameter for the trace. */
735 /*------------------------------------------------------------------*/
738 decodeParm(MonoType *type, void *curParm, int size)
743 printf("[BYREF:%p], ", *((char **) curParm));
745 simpleType = mono_type_get_underlying_type(type)->type;
747 switch (simpleType) {
749 printf ("[INTPTR:%p], ", *((int **) curParm));
752 printf ("[UINTPTR:%p], ", *((int **) curParm));
754 case MONO_TYPE_BOOLEAN :
755 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
757 case MONO_TYPE_CHAR :
758 printf ("[CHAR:%c], ", *((int *) curParm));
761 printf ("[INT1:%ld], ", *((gint64 *) curParm));
764 printf ("[INT2:%ld], ", *((gint64 *) curParm));
767 printf ("[INT4:%ld], ", *((gint64 *) curParm));
770 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
773 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
776 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
779 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
781 case MONO_TYPE_STRING : {
782 MonoString *s = *((MonoString **) curParm);
784 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
785 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
787 printf("[STRING:null], ");
791 case MONO_TYPE_CLASS :
792 case MONO_TYPE_OBJECT : {
793 MonoObject *obj = *((MonoObject **) curParm);
795 if ((obj) && (obj->vtable)) {
796 printf("[CLASS/OBJ:");
797 class = obj->vtable->klass;
798 printf("%p [%p] ",obj,curParm);
799 if (class == mono_defaults.string_class) {
800 printf("[STRING:%p:%s]",
801 obj, mono_string_to_utf8 ((MonoString *) obj));
802 } else if (class == mono_defaults.int32_class) {
803 printf("[INT32:%p:%d]",
804 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
807 class->name_space, class->name, obj);
810 printf("[OBJECT:null], ");
815 printf("[PTR:%p], ", *((gpointer **) (curParm)));
817 case MONO_TYPE_FNPTR :
818 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
820 case MONO_TYPE_ARRAY :
821 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
823 case MONO_TYPE_SZARRAY :
824 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
827 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
830 printf("[FLOAT4:%g], ", *((float *) (curParm)));
833 printf("[FLOAT8:%g], ", *((double *) (curParm)));
835 case MONO_TYPE_VALUETYPE : {
837 MonoMarshalType *info;
839 if (type->data.klass->enumtype) {
840 simpleType = mono_class_enum_basetype (type->data.klass)->type;
841 printf("{VALUETYPE} - ");
845 info = mono_marshal_load_type_info (type->data.klass);
847 if ((info->native_size == sizeof(float)) &&
848 (info->num_fields == 1) &&
849 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
850 printf("[FLOAT4:%f], ", *((float *) (curParm)));
854 if ((info->native_size == sizeof(double)) &&
855 (info->num_fields == 1) &&
856 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
857 printf("[FLOAT8:%g], ", *((double *) (curParm)));
861 printf("[VALUETYPE:");
862 for (i = 0; i < size; i++)
863 printf("%02x,", *((guint8 *)curParm+i));
867 case MONO_TYPE_TYPEDBYREF: {
869 printf("[TYPEDBYREF:");
870 for (i = 0; i < size; i++)
871 printf("%02x,", *((guint8 *)curParm+i));
876 printf("[%s], ",cvtMonoType(simpleType));
881 /*========================= End of Function ========================*/
883 /*------------------------------------------------------------------*/
885 /* Name - enter_method */
887 /* Function - Perform tracing of the entry to the current */
890 /*------------------------------------------------------------------*/
893 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
895 int i, oParm = 0, iParm = 0;
898 MonoMethodSignature *sig;
905 fname = mono_method_full_name (method, TRUE);
907 printf ("ENTER: %s ", fname);
910 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
911 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
916 sig = mono_method_signature (method);
918 cinfo = get_call_info (NULL, NULL, sig);
920 if (cinfo->struct_ret) {
921 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
926 gpointer *this = (gpointer *) rParm->gr[iParm];
927 obj = (MonoObject *) this;
928 switch(method->klass->this_arg.type) {
929 case MONO_TYPE_VALUETYPE:
931 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
932 printf("this:[value:%p:%016lx], ", this, *value);
934 printf ("this:[NULL], ");
936 case MONO_TYPE_STRING:
939 class = obj->vtable->klass;
940 if (class == mono_defaults.string_class) {
941 printf ("this:[STRING:%p:%s], ",
942 obj, mono_string_to_utf8 ((MonoString *)obj));
944 printf ("this:%p[%s.%s], ",
945 obj, class->name_space, class->name);
948 printf("vtable:[NULL], ");
950 printf ("this:[NULL], ");
953 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
958 for (i = 0; i < sig->param_count; ++i) {
959 ainfo = &cinfo->args[i + oParm];
960 switch (ainfo->regtype) {
961 case RegTypeGeneral :
962 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
965 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
968 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
970 case RegTypeStructByVal :
971 if (ainfo->reg != STK_BASE) {
972 int offset = sizeof(glong) - ainfo->size;
973 curParm = &(rParm->gr[ainfo->reg-2])+offset;
976 curParm = sp+ainfo->offset;
978 if (retFitsInReg (ainfo->vtsize))
979 decodeParm(sig->params[i],
983 decodeParm(sig->params[i],
984 *((char **) curParm),
987 case RegTypeStructByAddr :
988 if (ainfo->reg != STK_BASE)
989 curParm = &(rParm->gr[ainfo->reg-2]);
991 curParm = sp+ainfo->offset;
993 decodeParm(sig->params[i],
994 *((char **) curParm),
1006 /*========================= End of Function ========================*/
1008 /*------------------------------------------------------------------*/
1010 /* Name - leave_method */
1014 /*------------------------------------------------------------------*/
1017 leave_method (MonoMethod *method, ...)
1024 va_start(ap, method);
1026 fname = mono_method_full_name (method, TRUE);
1028 printf ("LEAVE: %s", fname);
1031 type = mono_method_signature (method)->ret;
1034 switch (type->type) {
1035 case MONO_TYPE_VOID:
1037 case MONO_TYPE_BOOLEAN: {
1038 int val = va_arg (ap, int);
1040 printf ("[TRUE:%d]", val);
1046 case MONO_TYPE_CHAR: {
1047 int val = va_arg (ap, int);
1048 printf ("[CHAR:%d]", val);
1051 case MONO_TYPE_I1: {
1052 int val = va_arg (ap, int);
1053 printf ("[INT1:%d]", val);
1056 case MONO_TYPE_U1: {
1057 int val = va_arg (ap, int);
1058 printf ("[UINT1:%d]", val);
1061 case MONO_TYPE_I2: {
1062 int val = va_arg (ap, int);
1063 printf ("[INT2:%d]", val);
1066 case MONO_TYPE_U2: {
1067 int val = va_arg (ap, int);
1068 printf ("[UINT2:%d]", val);
1071 case MONO_TYPE_I4: {
1072 int val = va_arg (ap, int);
1073 printf ("[INT4:%d]", val);
1076 case MONO_TYPE_U4: {
1077 int val = va_arg (ap, int);
1078 printf ("[UINT4:%d]", val);
1082 gint64 val = va_arg (ap, gint64);
1083 printf ("[INT:%ld]", val);
1088 gint64 val = va_arg (ap, gint64);
1089 printf ("[UINT:%lu]", val);
1093 case MONO_TYPE_STRING: {
1094 MonoString *s = va_arg (ap, MonoString *);
1097 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1098 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1100 printf ("[STRING:null], ");
1103 case MONO_TYPE_CLASS:
1104 case MONO_TYPE_OBJECT: {
1105 MonoObject *o = va_arg (ap, MonoObject *);
1107 if ((o) && (o->vtable)) {
1108 if (o->vtable->klass == mono_defaults.boolean_class) {
1109 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1110 } else if (o->vtable->klass == mono_defaults.int32_class) {
1111 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1112 } else if (o->vtable->klass == mono_defaults.int64_class) {
1113 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1115 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1117 printf ("[OBJECT:%p]", o);
1122 case MONO_TYPE_FNPTR:
1123 case MONO_TYPE_ARRAY:
1124 case MONO_TYPE_SZARRAY: {
1125 gpointer p = va_arg (ap, gpointer);
1126 printf ("[result=%p]", p);
1129 case MONO_TYPE_I8: {
1130 gint64 l = va_arg (ap, gint64);
1131 printf ("[LONG:%ld]", l);
1134 case MONO_TYPE_U8: {
1135 guint64 l = va_arg (ap, guint64);
1136 printf ("[ULONG:%lu]", l);
1139 case MONO_TYPE_R4: {
1140 double f = va_arg (ap, double);
1141 printf ("[FLOAT4:%g]\n", f);
1144 case MONO_TYPE_R8: {
1145 double f = va_arg (ap, double);
1146 printf ("[FLOAT8:%g]\n", f);
1149 case MONO_TYPE_VALUETYPE: {
1150 MonoMarshalType *info;
1151 if (type->data.klass->enumtype) {
1152 type = mono_class_enum_basetype (type->data.klass);
1157 info = mono_marshal_load_type_info (type->data.klass);
1159 if ((info->native_size == sizeof(float)) &&
1160 (info->num_fields == 1) &&
1161 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1162 double f = va_arg (ap, double);
1163 printf("[FLOAT4:%g]\n", (double) f);
1167 if ((info->native_size == sizeof(double)) &&
1168 (info->num_fields == 1) &&
1169 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1170 double f = va_arg (ap, double);
1171 printf("[FLOAT8:%g]\n", f);
1175 size = mono_type_size (type, &align);
1178 guint32 p = va_arg (ap, guint32);
1179 printf ("[%02x]\n",p);
1183 guint32 p = va_arg (ap, guint32);
1184 printf ("[%04x]\n",p);
1188 guint32 p = va_arg (ap, guint32);
1189 printf ("[%08x]\n",p);
1193 guint64 p = va_arg (ap, guint64);
1194 printf ("[%016lx]\n",p);
1198 gpointer p = va_arg (ap, gpointer);
1199 printf ("[VALUETYPE] %p\n",p);
1205 case MONO_TYPE_TYPEDBYREF: {
1206 guint8 *p = va_arg (ap, gpointer);
1208 size = mono_type_size (type, &align);
1215 for (j = 0; p && j < size; j++)
1216 printf ("%02x,", p [j]);
1220 printf ("[TYPEDBYREF]\n");
1225 printf ("(unknown return type %x)",
1226 mono_method_signature (method)->ret->type);
1229 ip = ((gint64) __builtin_extract_return_addr (__builtin_return_address (0)));
1230 printf (" ip: %p\n", (gpointer) ip);
1233 /*========================= End of Function ========================*/
1235 /*------------------------------------------------------------------*/
1237 /* Name - mono_arch_cpu_init */
1239 /* Function - Perform CPU specific initialization to execute */
1242 /*------------------------------------------------------------------*/
1245 mono_arch_cpu_init (void)
1249 /*========================= End of Function ========================*/
1251 /*------------------------------------------------------------------*/
1253 /* Name - mono_arch_init. */
1255 /* Function - Initialize architecture specific code. */
1257 /*------------------------------------------------------------------*/
1260 mono_arch_init (void)
1264 mono_mutex_init_recursive (&mini_arch_mutex);
1266 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1267 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1268 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1270 code = (guint8 *) &breakpointCode;
1271 s390_basr(code, s390_r13, 0);
1273 s390_llong(code, 0);
1274 s390_lg(code, s390_r13, 0, s390_r13, 4);
1275 s390_lg(code, s390_r0, 0, s390_r13, 0);
1278 /*========================= End of Function ========================*/
1280 /*------------------------------------------------------------------*/
1282 /* Name - mono_arch_cleanup. */
1284 /* Function - Cleanup architecture specific code . */
1286 /*------------------------------------------------------------------*/
1289 mono_arch_cleanup (void)
1291 if (ss_trigger_page)
1292 mono_vfree (ss_trigger_page, mono_pagesize ());
1293 if (bp_trigger_page)
1294 mono_vfree (bp_trigger_page, mono_pagesize ());
1295 mono_mutex_destroy (&mini_arch_mutex);
1298 /*========================= End of Function ========================*/
1300 /*------------------------------------------------------------------*/
1302 /* Name - mono_arch_cpu_optimizations */
1304 /* Function - Returns the optimizations supported on this CPU */
1306 /*------------------------------------------------------------------*/
1309 mono_arch_cpu_optimizations (guint32 *exclude_mask)
1313 /*----------------------------------------------------------*/
1314 /* No s390-specific optimizations yet */
1315 /*----------------------------------------------------------*/
1316 *exclude_mask = MONO_OPT_LINEARS;
1320 /*========================= End of Function ========================*/
1322 /*------------------------------------------------------------------*/
1324 /* Name - mono_arch_cpu_enumerate_simd_versions */
1326 /* Function - Returns the SIMD instruction sets on this CPU */
1328 /*------------------------------------------------------------------*/
1330 mono_arch_cpu_enumerate_simd_versions (void)
1332 /* SIMD is currently unimplemented */
1335 /*========================= End of Function ========================*/
1337 /*------------------------------------------------------------------*/
1339 /* Name - mono_arch_get_allocatable_int_vars */
1343 /*------------------------------------------------------------------*/
1346 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1351 for (i = 0; i < cfg->num_varinfo; i++) {
1352 MonoInst *ins = cfg->varinfo [i];
1353 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1356 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1359 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1360 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1363 /* we can only allocate 32 bit values */
1364 if (mono_is_regsize_var(ins->inst_vtype)) {
1365 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1366 g_assert (i == vmv->idx);
1367 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1374 /*========================= End of Function ========================*/
1376 /*------------------------------------------------------------------*/
1378 /* Name - mono_arch_global_int_regs */
1380 /* Function - Return a list of usable integer registers. */
1382 /*------------------------------------------------------------------*/
1385 mono_arch_get_global_int_regs (MonoCompile *cfg)
1388 MonoMethodHeader *header;
1391 header = cfg->header;
1392 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1393 cfg->frame_reg = s390_r11;
1396 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1398 for (i = 8; i < top; ++i) {
1399 if (cfg->frame_reg != i)
1400 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1406 /*========================= End of Function ========================*/
1408 /*------------------------------------------------------------------*/
1410 /* Name - mono_arch_flush_icache */
1412 /* Function - Flush the CPU icache. */
1414 /*------------------------------------------------------------------*/
1417 mono_arch_flush_icache (guint8 *code, gint size)
1421 /*========================= End of Function ========================*/
1423 /*------------------------------------------------------------------*/
1425 /* Name - add_general */
1427 /* Function - Determine code and stack size incremements for a */
1430 /*------------------------------------------------------------------*/
1433 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1435 if (*gr > S390_LAST_ARG_REG) {
1436 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1437 ainfo->offset = sz->stack_size;
1438 ainfo->reg = STK_BASE;
1439 ainfo->regtype = RegTypeBase;
1440 sz->stack_size += sizeof(long);
1441 sz->local_size += sizeof(long);
1442 sz->offStruct += sizeof(long);
1443 sz->code_size += 12;
1451 /*========================= End of Function ========================*/
1453 /*------------------------------------------------------------------*/
1455 /* Name - add_stackParm */
1457 /* Function - Determine code and stack size incremements for a */
1460 /*------------------------------------------------------------------*/
1463 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1465 if (*gr > S390_LAST_ARG_REG) {
1466 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1467 ainfo->reg = STK_BASE;
1468 ainfo->offset = sz->stack_size;
1469 ainfo->regtype = RegTypeStructByAddrOnStack;
1470 sz->stack_size += sizeof (gpointer);
1471 sz->parm_size += sizeof(gpointer);
1472 sz->offStruct += sizeof(gpointer);
1475 ainfo->offset = sz->stack_size;
1476 ainfo->regtype = RegTypeStructByAddr;
1479 ainfo->offparm = sz->offset;
1480 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1482 ainfo->vtsize = size;
1483 sz->parm_size += size;
1486 /*========================= End of Function ========================*/
1488 /*------------------------------------------------------------------*/
1490 /* Name - add_float */
1492 /* Function - Determine code and stack size incremements for a */
1493 /* float parameter. */
1495 /*------------------------------------------------------------------*/
1498 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1500 if ((*fr) <= S390_LAST_FPARG_REG) {
1501 ainfo->regtype = RegTypeFP;
1507 ainfo->offset = sz->stack_size;
1508 ainfo->reg = STK_BASE;
1509 ainfo->regtype = RegTypeBase;
1511 sz->stack_size += sizeof(double);
1512 sz->local_size += sizeof(double);
1513 sz->offStruct += sizeof(double);
1517 /*========================= End of Function ========================*/
1519 /*------------------------------------------------------------------*/
1521 /* Name - get_call_info */
1523 /* Function - Determine the amount of space required for code */
1524 /* and stack. In addition determine starting points */
1525 /* for stack-based parameters, and area for struct- */
1526 /* ures being returned on the stack. */
1528 /*------------------------------------------------------------------*/
1531 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
1533 guint i, fr, gr, size, pstart;
1534 int nParm = sig->hasthis + sig->param_count;
1536 guint32 simpleType, align;
1537 gboolean is_pinvoke = sig->pinvoke;
1540 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1543 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1545 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1550 cinfo->struct_ret = 0;
1554 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1555 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1562 /*----------------------------------------------------------*/
1563 /* We determine the size of the return code/stack in case we*/
1564 /* need to reserve a register to be used to address a stack */
1565 /* area that the callee will use. */
1566 /*----------------------------------------------------------*/
1568 ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
1569 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1570 simpleType = ret_type->type;
1572 switch (simpleType) {
1573 case MONO_TYPE_BOOLEAN:
1578 case MONO_TYPE_CHAR:
1583 case MONO_TYPE_CLASS:
1584 case MONO_TYPE_OBJECT:
1585 case MONO_TYPE_SZARRAY:
1586 case MONO_TYPE_ARRAY:
1588 case MONO_TYPE_FNPTR:
1589 case MONO_TYPE_STRING:
1590 cinfo->ret.reg = s390_r2;
1595 cinfo->ret.reg = s390_f0;
1600 cinfo->ret.reg = s390_r2;
1603 case MONO_TYPE_GENERICINST:
1604 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1605 cinfo->ret.reg = s390_r2;
1610 case MONO_TYPE_VALUETYPE: {
1611 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1612 if (klass->enumtype) {
1613 simpleType = mono_class_enum_basetype (klass)->type;
1616 size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1618 cinfo->struct_ret = 1;
1619 cinfo->ret.size = size;
1620 cinfo->ret.vtsize = size;
1623 case MONO_TYPE_TYPEDBYREF:
1624 size = sizeof (MonoTypedRef);
1625 cinfo->struct_ret = 1;
1626 cinfo->ret.size = size;
1627 cinfo->ret.vtsize = size;
1629 case MONO_TYPE_VOID:
1632 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1638 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1639 * the first argument, allowing 'this' to be always passed in the first arg reg.
1640 * Also do this if the first argument is a reference type, since virtual calls
1641 * are sometimes made using calli without sig->hasthis set, like in the delegate
1644 if (cinfo->struct_ret && !is_pinvoke &&
1646 (sig->param_count > 0 &&
1647 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1649 cinfo->args[nParm].size = sizeof (gpointer);
1650 add_general (&gr, sz, cinfo->args + nParm);
1652 cinfo->args[nParm].size = sizeof (gpointer);
1653 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1657 cinfo->vret_arg_index = 1;
1658 cinfo->ret.reg = gr;
1663 cinfo->args[nParm].size = sizeof (gpointer);
1664 add_general (&gr, sz, cinfo->args + nParm);
1668 if (cinfo->struct_ret) {
1669 cinfo->ret.reg = gr;
1674 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1675 gr = S390_LAST_ARG_REG + 1;
1676 fr = S390_LAST_FPARG_REG + 1;
1678 /* Emit the signature cookie just before the implicit arguments */
1679 add_general (&gr, sz, &cinfo->sigCookie);
1682 /*----------------------------------------------------------*/
1683 /* We determine the size of the parameter code and stack */
1684 /* requirements by checking the types and sizes of the */
1686 /*----------------------------------------------------------*/
1688 for (i = pstart; i < sig->param_count; ++i) {
1691 /*--------------------------------------------------*/
1692 /* Handle vararg type calls. All args are put on */
1694 /*--------------------------------------------------*/
1695 if ((sig->call_convention == MONO_CALL_VARARG) &&
1696 (i == sig->sentinelpos)) {
1697 gr = S390_LAST_ARG_REG + 1;
1698 fr = S390_LAST_FPARG_REG + 1;
1699 add_general (&gr, sz, &cinfo->sigCookie);
1702 if (sig->params [i]->byref) {
1703 add_general (&gr, sz, cinfo->args+nParm);
1704 cinfo->args[nParm].size = sizeof(gpointer);
1709 ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
1710 simpleType = ptype->type;
1711 cinfo->args[nParm].type = simpleType;
1712 switch (simpleType) {
1713 case MONO_TYPE_BOOLEAN:
1716 cinfo->args[nParm].size = sizeof(char);
1717 add_general (&gr, sz, cinfo->args+nParm);
1722 case MONO_TYPE_CHAR:
1723 cinfo->args[nParm].size = sizeof(short);
1724 add_general (&gr, sz, cinfo->args+nParm);
1729 cinfo->args[nParm].size = sizeof(int);
1730 add_general (&gr, sz, cinfo->args+nParm);
1736 case MONO_TYPE_FNPTR:
1737 case MONO_TYPE_CLASS:
1738 case MONO_TYPE_OBJECT:
1739 case MONO_TYPE_STRING:
1740 case MONO_TYPE_SZARRAY:
1741 case MONO_TYPE_ARRAY:
1742 cinfo->args[nParm].size = sizeof(gpointer);
1743 add_general (&gr, sz, cinfo->args+nParm);
1748 cinfo->args[nParm].size = sizeof(long long);
1749 add_general (&gr, sz, cinfo->args+nParm);
1753 cinfo->args[nParm].size = sizeof(float);
1754 add_float (&fr, sz, cinfo->args+nParm);
1758 cinfo->args[nParm].size = sizeof(double);
1759 add_float (&fr, sz, cinfo->args+nParm);
1762 case MONO_TYPE_GENERICINST:
1763 if (!mono_type_generic_inst_is_valuetype (ptype)) {
1764 cinfo->args[nParm].size = sizeof(gpointer);
1765 add_general (&gr, sz, cinfo->args+nParm);
1770 case MONO_TYPE_VALUETYPE: {
1771 MonoMarshalType *info;
1772 MonoClass *klass = mono_class_from_mono_type (ptype);
1775 size = mono_class_native_size(klass, NULL);
1777 size = mono_class_value_size(klass, NULL);
1779 if (simpleType != MONO_TYPE_GENERICINST) {
1780 info = mono_marshal_load_type_info(klass);
1782 if ((info->native_size == sizeof(float)) &&
1783 (info->num_fields == 1) &&
1784 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1785 cinfo->args[nParm].size = sizeof(float);
1786 add_float(&fr, sz, cinfo->args+nParm);
1791 if ((info->native_size == sizeof(double)) &&
1792 (info->num_fields == 1) &&
1793 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1794 cinfo->args[nParm].size = sizeof(double);
1795 add_float(&fr, sz, cinfo->args+nParm);
1801 cinfo->args[nParm].vtsize = 0;
1802 cinfo->args[nParm].size = 0;
1805 /*----------------------------------*/
1806 /* On S/390, structures of size 1, */
1807 /* 2, 4, and 8 bytes are passed in */
1808 /* (a) register(s). */
1809 /*----------------------------------*/
1815 add_general(&gr, sz, cinfo->args+nParm);
1816 cinfo->args[nParm].size = size;
1817 cinfo->args[nParm].regtype = RegTypeStructByVal;
1819 sz->local_size += sizeof(long);
1822 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1827 case MONO_TYPE_TYPEDBYREF: {
1828 int size = sizeof (MonoTypedRef);
1830 cinfo->args[nParm].vtsize = 0;
1831 cinfo->args[nParm].size = 0;
1834 /*----------------------------------*/
1835 /* On S/390, structures of size 1, */
1836 /* 2, 4, and 8 bytes are passed in */
1837 /* (a) register(s). */
1838 /*----------------------------------*/
1844 add_general(&gr, sz, cinfo->args+nParm);
1845 cinfo->args[nParm].size = size;
1846 cinfo->args[nParm].regtype = RegTypeStructByVal;
1848 sz->local_size += sizeof(long);
1851 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1857 g_error ("Can't trampoline 0x%x", ptype);
1861 /*----------------------------------------------------------*/
1862 /* Handle the case where there are no implicit arguments */
1863 /*----------------------------------------------------------*/
1864 if ((sig->call_convention == MONO_CALL_VARARG) &&
1867 (sig->param_count == sig->sentinelpos)) {
1868 gr = S390_LAST_ARG_REG + 1;
1869 fr = S390_LAST_FPARG_REG + 1;
1870 add_general (&gr, sz, &cinfo->sigCookie);
1873 /*----------------------------------------------------------*/
1874 /* If we are passing a structure back then if it won't be */
1875 /* in a register(s) then we make room at the end of the */
1876 /* parameters that may have been placed on the stack */
1877 /*----------------------------------------------------------*/
1878 if (cinfo->struct_ret) {
1879 cinfo->ret.offset = sz->stack_size;
1880 switch (cinfo->ret.size) {
1888 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1893 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1895 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1900 /*========================= End of Function ========================*/
1902 /*------------------------------------------------------------------*/
1904 /* Name - mono_arch_allocate_vars */
1906 /* Function - Set var information according to the calling */
1907 /* convention for S/390. The local var stuff should */
1908 /* most likely be split in another method. */
1910 /* Parameter - @m - Compile unit. */
1912 /*------------------------------------------------------------------*/
1915 mono_arch_allocate_vars (MonoCompile *cfg)
1917 MonoMethodSignature *sig;
1918 MonoMethodHeader *header;
1921 int iParm, iVar, offset, align, size, curinst;
1922 int frame_reg = STK_BASE;
1925 header = cfg->header;
1927 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1929 /*---------------------------------------------------------*/
1930 /* We use the frame register also for any method that has */
1931 /* filter clauses. This way, when the handlers are called, */
1932 /* the code will reference local variables using the frame */
1933 /* reg instead of the stack pointer: if we had to restore */
1934 /* the stack pointer, we'd corrupt the method frames that */
1935 /* are already on the stack (since filters get called */
1936 /* before stack unwinding happens) when the filter code */
1937 /* would call any method. */
1938 /*---------------------------------------------------------*/
1939 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1940 frame_reg = s390_r11;
1942 cfg->frame_reg = frame_reg;
1944 cfg->arch.bkchain_reg = -1;
1946 if (frame_reg != STK_BASE)
1947 cfg->used_int_regs |= (1 << frame_reg);
1949 if (cfg->uses_rgctx_reg)
1950 cfg->used_int_regs |= (1 << MONO_ARCH_IMT_REG);
1952 sig = mono_method_signature (cfg->method);
1954 cinfo = get_call_info (cfg, cfg->mempool, sig);
1956 if (!cinfo->struct_ret) {
1957 switch (mini_type_get_underlying_type (cfg->generic_sharing_context, sig->ret)->type) {
1958 case MONO_TYPE_VOID:
1961 cfg->ret->opcode = OP_REGVAR;
1962 cfg->ret->dreg = s390_r2;
1967 /*--------------------------------------------------------------*/
1968 /* local vars are at a positive offset from the stack pointer */
1969 /* also note that if the function uses alloca, we use s390_r11 */
1970 /* to point at the local variables. */
1971 /* add parameter area size for called functions */
1972 /*--------------------------------------------------------------*/
1973 if (cfg->param_area == 0)
1974 offset = S390_MINIMAL_STACK_SIZE;
1976 offset = cfg->param_area;
1978 cfg->sig_cookie = 0;
1980 if (cinfo->struct_ret) {
1981 inst = cfg->vret_addr;
1982 offset = S390_ALIGN(offset, sizeof(gpointer));
1983 inst->inst_offset = offset;
1984 inst->opcode = OP_REGOFFSET;
1985 inst->inst_basereg = frame_reg;
1986 offset += sizeof(gpointer);
1987 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1988 printf ("vret_addr =");
1989 mono_print_ins (cfg->vret_addr);
1994 inst = cfg->args [0];
1995 if (inst->opcode != OP_REGVAR) {
1996 inst->opcode = OP_REGOFFSET;
1997 inst->inst_basereg = frame_reg;
1998 offset = S390_ALIGN(offset, sizeof(gpointer));
1999 inst->inst_offset = offset;
2000 offset += sizeof (gpointer);
2007 eArg = sig->param_count + sArg;
2009 if (sig->call_convention == MONO_CALL_VARARG)
2010 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2012 for (iParm = sArg; iParm < eArg; ++iParm) {
2013 inst = cfg->args [curinst];
2014 if (inst->opcode != OP_REGVAR) {
2015 switch (cinfo->args[iParm].regtype) {
2016 case RegTypeStructByAddr : {
2019 size = sizeof (gpointer);
2021 inst->opcode = OP_REGOFFSET;
2022 inst->inst_basereg = frame_reg;
2023 offset = S390_ALIGN (offset, sizeof (gpointer));
2024 inst->inst_offset = offset;
2026 /* Add a level of indirection */
2027 MONO_INST_NEW (cfg, indir, 0);
2029 inst->opcode = OP_VTARG_ADDR;
2030 inst->inst_left = indir;
2033 case RegTypeStructByAddrOnStack : {
2036 size = sizeof (gpointer);
2038 /* Similar to the == STK_BASE case below */
2039 cfg->arch.bkchain_reg = s390_r12;
2040 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2042 inst->opcode = OP_REGOFFSET;
2043 inst->dreg = mono_alloc_preg (cfg);
2044 inst->inst_basereg = cfg->arch.bkchain_reg;
2045 inst->inst_offset = cinfo->args [iParm].offset;
2047 /* Add a level of indirection */
2048 MONO_INST_NEW (cfg, indir, 0);
2050 inst->opcode = OP_VTARG_ADDR;
2051 inst->inst_left = indir;
2054 case RegTypeStructByVal :
2055 size = cinfo->args[iParm].size;
2056 offset = S390_ALIGN(offset, size);
2057 inst->opcode = OP_REGOFFSET;
2058 inst->inst_basereg = frame_reg;
2059 inst->inst_offset = offset;
2062 if (cinfo->args [iParm].reg == STK_BASE) {
2064 * These arguments are in the previous frame, so we can't
2065 * compute their offset from the current frame pointer right
2066 * now, since cfg->stack_offset is not yet known, so dedicate a
2067 * register holding the previous frame pointer.
2069 cfg->arch.bkchain_reg = s390_r12;
2070 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2072 inst->opcode = OP_REGOFFSET;
2073 inst->inst_basereg = cfg->arch.bkchain_reg;
2074 size = (cinfo->args[iParm].size < 8
2075 ? 8 - cinfo->args[iParm].size
2077 inst->inst_offset = cinfo->args [iParm].offset + size;
2078 size = sizeof (long);
2080 inst->opcode = OP_REGOFFSET;
2081 inst->inst_basereg = frame_reg;
2082 size = (cinfo->args[iParm].size < 8
2085 offset = S390_ALIGN(offset, size);
2086 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2087 inst->inst_offset = offset;
2089 inst->inst_offset = offset + (8 - size);
2094 if ((sig->call_convention == MONO_CALL_VARARG) &&
2095 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2096 (iParm < sig->sentinelpos))
2097 cfg->sig_cookie += size;
2098 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2101 offset += MAX(size, 8);
2106 cfg->locals_min_stack_offset = offset;
2108 curinst = cfg->locals_start;
2109 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2110 inst = cfg->varinfo [iVar];
2111 if ((inst->flags & MONO_INST_IS_DEAD) ||
2112 (inst->opcode == OP_REGVAR))
2115 /*--------------------------------------------------*/
2116 /* inst->backend.is_pinvoke indicates native sized */
2117 /* value typs this is used by the pinvoke wrappers */
2118 /* when they call functions returning structure */
2119 /*--------------------------------------------------*/
2120 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2121 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2122 (guint32 *) &align);
2124 size = mono_type_size (inst->inst_vtype, &align);
2126 offset = S390_ALIGN(offset, align);
2127 inst->inst_offset = offset;
2128 inst->opcode = OP_REGOFFSET;
2129 inst->inst_basereg = frame_reg;
2131 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2132 iVar, inst->inst_offset, size));
2135 cfg->locals_max_stack_offset = offset;
2137 /*------------------------------------------------------*/
2138 /* Allow space for the trace method stack area if needed*/
2139 /*------------------------------------------------------*/
2140 if ((mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2141 || (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE))
2142 offset += S390_TRACE_STACK_SIZE;
2144 /*------------------------------------------------------*/
2145 /* Reserve space to save LMF and caller saved registers */
2146 /*------------------------------------------------------*/
2147 if (cfg->method->save_lmf)
2148 offset += sizeof (MonoLMF);
2150 /*------------------------------------------------------*/
2151 /* align the offset */
2152 /*------------------------------------------------------*/
2153 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2155 /*------------------------------------------------------*/
2156 /* Fix offsets for args whose value is in parent frame */
2157 /*------------------------------------------------------*/
2158 for (iParm = sArg; iParm < eArg; ++iParm) {
2159 inst = cfg->args [iParm];
2161 if (inst->opcode == OP_S390_STKARG) {
2162 inst->opcode = OP_REGOFFSET;
2163 inst->inst_offset += cfg->stack_offset;
2168 /*========================= End of Function ========================*/
2170 /*------------------------------------------------------------------*/
2172 /* Name - mono_arch_create_vars */
2174 /*------------------------------------------------------------------*/
2177 mono_arch_create_vars (MonoCompile *cfg)
2179 MonoMethodSignature *sig;
2182 sig = mono_method_signature (cfg->method);
2184 cinfo = get_call_info (cfg, cfg->mempool, sig);
2186 if (cinfo->struct_ret) {
2187 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2188 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2189 printf ("vret_addr = ");
2190 mono_print_ins (cfg->vret_addr);
2195 /*========================= End of Function ========================*/
2197 /*------------------------------------------------------------------*/
2199 /* Name - add_outarg_reg2. */
2201 /*------------------------------------------------------------------*/
2204 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2209 case RegTypeGeneral:
2210 MONO_INST_NEW (cfg, ins, OP_MOVE);
2211 ins->dreg = mono_alloc_ireg (cfg);
2212 ins->sreg1 = tree->dreg;
2213 MONO_ADD_INS (cfg->cbb, ins);
2214 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2217 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2218 ins->dreg = mono_alloc_freg (cfg);
2219 ins->sreg1 = tree->dreg;
2220 MONO_ADD_INS (cfg->cbb, ins);
2221 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2224 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2225 ins->dreg = mono_alloc_freg (cfg);
2226 ins->sreg1 = tree->dreg;
2227 MONO_ADD_INS (cfg->cbb, ins);
2228 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2231 g_assert_not_reached ();
2235 /*========================= End of Function ========================*/
2237 /*------------------------------------------------------------------*/
2239 /* Name - emit_sig_cookie. */
2241 /*------------------------------------------------------------------*/
2244 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2246 MonoMethodSignature *tmpSig;
2249 cfg->disable_aot = TRUE;
2251 /*----------------------------------------------------------*/
2252 /* mono_ArgIterator_Setup assumes the signature cookie is */
2253 /* passed first and all the arguments which were before it */
2254 /* passed on the stack after the signature. So compensate */
2255 /* by passing a different signature. */
2256 /*----------------------------------------------------------*/
2257 tmpSig = mono_metadata_signature_dup (call->signature);
2258 tmpSig->param_count -= call->signature->sentinelpos;
2259 tmpSig->sentinelpos = 0;
2260 if (tmpSig->param_count > 0)
2261 memcpy (tmpSig->params,
2262 call->signature->params + call->signature->sentinelpos,
2263 tmpSig->param_count * sizeof(MonoType *));
2265 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2266 sig_arg->dreg = mono_alloc_ireg (cfg);
2267 sig_arg->inst_p0 = tmpSig;
2268 MONO_ADD_INS (cfg->cbb, sig_arg);
2270 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2271 cinfo->sigCookie.offset, sig_arg->dreg);
2274 /*========================= End of Function ========================*/
2276 /*------------------------------------------------------------------*/
2278 /* Name - mono_arch_emit_call */
2280 /*------------------------------------------------------------------*/
2283 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2286 MonoMethodSignature *sig;
2288 int i, n, lParamArea;
2290 ArgInfo *ainfo = NULL;
2292 MonoMethodHeader *header;
2295 sig = call->signature;
2296 n = sig->param_count + sig->hasthis;
2297 DEBUG (g_print ("Call requires: %d parameters\n",n));
2299 cinfo = get_call_info (cfg, cfg->mempool, sig);
2301 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2302 cinfo->sz.parm_size + cinfo->sz.offset;
2303 call->stack_usage = MAX(stackSize, call->stack_usage);
2304 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2305 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2306 cfg->flags |= MONO_CFG_HAS_CALLS;
2308 if (cinfo->struct_ret) {
2309 MONO_INST_NEW (cfg, ins, OP_MOVE);
2310 ins->sreg1 = call->vret_var->dreg;
2311 ins->dreg = mono_alloc_preg (cfg);
2312 MONO_ADD_INS (cfg->cbb, ins);
2313 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2316 header = cfg->header;
2317 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2322 for (i = 0; i < n; ++i) {
2325 ainfo = cinfo->args + i;
2326 if (i >= sig->hasthis)
2327 t = sig->params [i - sig->hasthis];
2329 t = &mono_defaults.int_class->byval_arg;
2330 t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
2332 in = call->args [i];
2334 if ((sig->call_convention == MONO_CALL_VARARG) &&
2336 (i == sig->sentinelpos)) {
2337 emit_sig_cookie (cfg, call, cinfo);
2340 switch (ainfo->regtype) {
2341 case RegTypeGeneral:
2342 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2345 if (MONO_TYPE_ISSTRUCT (t)) {
2346 /* Valuetype passed in one fp register */
2347 ainfo->regtype = RegTypeStructByValInFP;
2350 if (ainfo->size == 4)
2351 ainfo->regtype = RegTypeFPR4;
2352 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2355 case RegTypeStructByVal:
2356 case RegTypeStructByAddr:
2357 case RegTypeStructByAddrOnStack: {
2361 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2362 size = sizeof (MonoTypedRef);
2363 align = sizeof (gpointer);
2367 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2370 * Other backends use mono_type_stack_size (), but that
2371 * aligns the size to 8, which is larger than the size of
2372 * the source, leading to reads of invalid memory if the
2373 * source is at the end of address space.
2375 size = mono_class_value_size (in->klass, &align);
2378 g_assert (in->klass);
2380 ainfo->offparm += cinfo->sz.offStruct;
2382 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2383 ins->sreg1 = in->dreg;
2384 ins->klass = in->klass;
2385 ins->backend.size = ainfo->size;
2386 ins->inst_p0 = call;
2387 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2388 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2390 MONO_ADD_INS (cfg->cbb, ins);
2392 if (ainfo->regtype == RegTypeStructByAddr) {
2394 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2395 * use the normal OUTARG opcodes to pass the address of the location to
2398 int treg = mono_alloc_preg (cfg);
2399 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2400 frmReg, ainfo->offparm);
2401 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2402 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2403 /* The address of the valuetype is passed on the stack */
2404 int treg = mono_alloc_preg (cfg);
2405 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2406 frmReg, ainfo->offparm);
2407 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2408 ainfo->reg, ainfo->offset, treg);
2410 if (cfg->compute_gc_maps) {
2413 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2419 if (!t->byref && t->type == MONO_TYPE_R4) {
2420 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2421 STK_BASE, ainfo->offset + 4,
2423 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2424 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2425 STK_BASE, ainfo->offset,
2428 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2429 ins->inst_destbasereg = STK_BASE;
2430 ins->inst_offset = ainfo->offset;
2431 ins->sreg1 = in->dreg;
2434 /* This is needed by MonoTypedRef->value to point to the correct data */
2435 if ((sig->call_convention == MONO_CALL_VARARG) &&
2436 (i >= sig->sentinelpos)) {
2437 switch (ainfo->size) {
2439 ins->opcode = OP_STOREI1_MEMBASE_REG;
2442 ins->opcode = OP_STOREI2_MEMBASE_REG;
2445 ins->opcode = OP_STOREI4_MEMBASE_REG;
2453 MONO_ADD_INS (cfg->cbb, ins);
2457 g_assert_not_reached ();
2463 * Handle the case where there are no implicit arguments
2465 if ((sig->call_convention == MONO_CALL_VARARG) &&
2467 (i == sig->sentinelpos)) {
2468 emit_sig_cookie (cfg, call, cinfo);
2472 /*========================= End of Function ========================*/
2474 /*------------------------------------------------------------------*/
2476 /* Name - mono_arch_emit_outarg_vt */
2478 /*------------------------------------------------------------------*/
2481 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2483 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2484 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2485 int size = ins->backend.size;
2487 if (ainfo->regtype == RegTypeStructByVal) {
2489 arg->ins.sreg1 = ainfo->reg;
2490 arg->ins.opcode = OP_OUTARG_VT;
2491 arg->size = ainfo->size;
2492 arg->offset = ainfo->offset;
2493 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2495 if (ainfo->reg != STK_BASE) {
2496 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2498 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2501 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2502 int dreg = mono_alloc_freg (cfg);
2504 if (ainfo->size == 4) {
2505 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2506 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2508 g_assert (ainfo->size == 8);
2510 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2513 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2515 MonoMethodHeader *header;
2518 header = mono_method_get_header (cfg->method);
2519 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2524 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2525 src->dreg, 0, size);
2527 if (cfg->compute_gc_maps) {
2530 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2535 /*========================= End of Function ========================*/
2537 /*------------------------------------------------------------------*/
2539 /* Name - mono_arch_emit_setret */
2541 /*------------------------------------------------------------------*/
2544 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2546 MonoType *ret = mini_type_get_underlying_type (cfg->generic_sharing_context,
2547 mono_method_signature (method)->ret);
2550 if (ret->type == MONO_TYPE_R4) {
2551 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2553 } else if (ret->type == MONO_TYPE_R8) {
2554 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2559 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2562 /*========================= End of Function ========================*/
2564 /*------------------------------------------------------------------*/
2566 /* Name - mono_arch_instrument_mem_needs */
2568 /* Function - Allow tracing to work with this interface (with */
2569 /* an optional argument). */
2571 /*------------------------------------------------------------------*/
2574 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2576 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2578 /* split prolog-epilog requirements? */
2579 *code = 50; /* max bytes needed: check this number */
2582 /*========================= End of Function ========================*/
2584 /*------------------------------------------------------------------*/
2586 /* Name - mono_arch_instrument_prolog */
2588 /* Function - Create an "instrumented" prolog. */
2590 /*------------------------------------------------------------------*/
2593 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2594 gboolean enable_arguments)
2601 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2602 if (cfg->method->save_lmf)
2603 parmOffset -= sizeof(MonoLMF);
2604 fpOffset = parmOffset + (5*sizeof(gpointer));
2607 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2608 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2609 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2610 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2611 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2612 S390_SET (code, s390_r1, func);
2613 S390_SET (code, s390_r2, cfg->method);
2614 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2615 s390_lgr (code, s390_r4, STK_BASE);
2616 s390_aghi (code, s390_r4, cfg->stack_usage);
2617 s390_basr (code, s390_r14, s390_r1);
2618 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2619 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2620 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2621 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2622 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2627 /*========================= End of Function ========================*/
2629 /*------------------------------------------------------------------*/
2631 /* Name - mono_arch_instrument_epilog */
2633 /* Function - Create an epilog that will handle the returned */
2634 /* values used in instrumentation. */
2636 /*------------------------------------------------------------------*/
2639 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2642 int save_mode = SAVE_NONE,
2645 MonoMethod *method = cfg->method;
2646 int rtype = mini_type_get_underlying_type (cfg->generic_sharing_context,
2647 mono_method_signature (method)->ret)->type;
2649 offset = code - cfg->native_code;
2650 /*-----------------------------------------*/
2651 /* We need about 128 bytes of instructions */
2652 /*-----------------------------------------*/
2653 if (offset > (cfg->code_size - 128)) {
2654 cfg->code_size *= 2;
2655 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2656 code = cfg->native_code + offset;
2659 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2660 if (method->save_lmf)
2661 saveOffset -= sizeof(MonoLMF);
2665 case MONO_TYPE_VOID:
2666 /* special case string .ctor icall */
2667 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2668 save_mode = SAVE_ONE;
2670 save_mode = SAVE_NONE;
2674 save_mode = SAVE_ONE;
2677 save_mode = SAVE_R4;
2680 save_mode = SAVE_R8;
2682 case MONO_TYPE_VALUETYPE:
2683 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2684 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2687 save_mode = SAVE_STRUCT;
2690 save_mode = SAVE_ONE;
2694 switch (save_mode) {
2696 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2697 if (enable_arguments) {
2698 s390_lgr (code, s390_r3, s390_r2);
2702 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2703 if (enable_arguments) {
2704 s390_ldebr (code, s390_f0, s390_f0);
2708 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2711 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2712 if (enable_arguments) {
2713 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2714 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2722 S390_SET (code, s390_r1, func);
2723 S390_SET (code, s390_r2, cfg->method);
2724 s390_basr (code, s390_r14, s390_r1);
2726 switch (save_mode) {
2728 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2732 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2735 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2745 /*========================= End of Function ========================*/
2747 /*------------------------------------------------------------------*/
2749 /* Name - mono_arch_peephole_pass_1 */
2751 /* Function - Form a peephole pass at the code looking for */
2752 /* simple optimizations. */
2754 /*------------------------------------------------------------------*/
2757 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2761 /*========================= End of Function ========================*/
2763 /*------------------------------------------------------------------*/
2765 /* Name - mono_arch_peephole_pass_2 */
2767 /* Function - Form a peephole pass at the code looking for */
2768 /* simple optimizations. */
2770 /*------------------------------------------------------------------*/
2773 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2777 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2778 mono_peephole_ins (bb, ins);
2782 /*========================= End of Function ========================*/
2784 /*------------------------------------------------------------------*/
2786 /* Name - mono_arch_lowering_pass. */
2788 /*------------------------------------------------------------------*/
2791 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2793 MonoInst *ins, *next;
2795 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2796 switch (ins->opcode) {
2801 case OP_IDIV_UN_IMM:
2802 case OP_IREM_UN_IMM:
2807 case OP_LOCALLOC_IMM:
2808 mono_decompose_op_imm (cfg, bb, ins);
2811 if (!s390_is_imm16 (ins->inst_imm))
2812 /* This is created by the memcpy code which ignores is_inst_imm */
2813 mono_decompose_op_imm (cfg, bb, ins);
2820 bb->max_vreg = cfg->next_vreg;
2823 /*========================= End of Function ========================*/
2825 /*------------------------------------------------------------------*/
2827 /* Name - emit_float_to_int */
2829 /* Function - Create instructions which will convert a floating */
2830 /* point value to integer. */
2832 /*------------------------------------------------------------------*/
2835 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2837 /* sreg is a float, dreg is an integer reg. */
2839 s390_cgdbr (code, dreg, 5, sreg);
2842 s390_lghi (code, s390_r0, 0);
2843 s390_lghi (code, s390_r13, 0xff);
2844 s390_ltgr (code, dreg, dreg);
2846 s390_lghi (code, s390_r0, 0x80);
2847 s390_ngr (code, dreg, s390_r13);
2848 s390_ogr (code, dreg, s390_r0);
2853 S390_SET (code, s390_r13, 0x41e0000000000000llu);
2854 s390_ldgr (code, s390_f14, s390_r13);
2855 s390_ldr (code, s390_f15, sreg);
2856 s390_cdbr (code, s390_f15, s390_f14);
2857 s390_jl (code, 0); CODEPTR (code, o[0]);
2858 S390_SET (code, s390_r13, 0x41f0000000000000llu);
2859 s390_ldgr (code, s390_f14, s390_r13);
2860 s390_sdbr (code, s390_f15, s390_f14);
2861 s390_cfdbr (code, dreg, 7, s390_f15);
2863 PTRSLOT (code, o[0]);
2864 s390_cfdbr (code, dreg, 5, sreg);
2867 s390_lghi (code, s390_r0, 0xff);
2868 s390_ngr (code, dreg, s390_r0);
2871 s390_lghi (code, s390_r0, -1);
2872 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2873 s390_ngr (code, dreg, s390_r0);
2880 /*========================= End of Function ========================*/
2882 /*------------------------------------------------------------------*/
2884 /* Name - gboolean_is_unsigned. */
2886 /* Function - Return TRUE if next opcode is checking for un- */
2889 /*------------------------------------------------------------------*/
2892 gboolean is_unsigned (MonoInst *next)
2895 (((next->opcode >= OP_IBNE_UN) &&
2896 (next->opcode <= OP_IBLT_UN)) ||
2897 ((next->opcode >= OP_LBNE_UN) &&
2898 (next->opcode <= OP_LBLT_UN)) ||
2899 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2900 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2901 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2902 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2903 ((next->opcode == OP_CLT_UN) ||
2904 (next->opcode == OP_CGT_UN)) ||
2905 ((next->opcode == OP_ICLT_UN) ||
2906 (next->opcode == OP_ICGT_UN) ||
2907 (next->opcode == OP_LCLT_UN) ||
2908 (next->opcode == OP_LCGT_UN))))
2914 /*========================= End of Function ========================*/
2916 /*------------------------------------------------------------------*/
2918 /* Name - mono_arch_output_basic_block */
2920 /* Function - Perform the "real" work of emitting instructions */
2921 /* that will do the work of in the basic block. */
2923 /*------------------------------------------------------------------*/
2926 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2931 guint8 *code = cfg->native_code + cfg->code_len;
2932 guint last_offset = 0;
2935 /* we don't align basic blocks of loops on s390 */
2937 if (cfg->verbose_level > 2)
2938 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2940 if ((cfg->prof_options & MONO_PROFILE_COVERAGE) && cfg->coverage_info) {
2941 MonoProfileCoverageInfo *cov = cfg->coverage_info;
2942 g_assert (!mono_compile_aot);
2943 cov->data [bb->dfn].cil_code = bb->cil_code;
2944 /* This is not thread save, but good enough */
2945 S390_SET (code, s390_r1, &cov->data [bb->dfn].count);
2946 s390_alsi (code, 0, s390_r1, 1);
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.
4123 case OP_GENERIC_CLASS_INIT: {
4124 static int byte_offset = -1;
4125 static guint8 bitmask;
4128 g_assert (ins->sreg1 == S390_FIRST_ARG_REG);
4130 if (byte_offset < 0)
4131 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
4133 s390_tm (code, ins->sreg1, byte_offset, bitmask);
4134 s390_jo (code, 0); CODEPTR(code, jump);
4136 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_JIT_ICALL_ADDR,
4137 "specific_trampoline_generic_class_init");
4138 S390_CALL_TEMPLATE(code, s390_r14);
4140 PTRSLOT (code, jump);
4142 ins->flags |= MONO_INST_GC_CALLSITE;
4143 ins->backend.pc_offset = code - cfg->native_code;
4147 EMIT_UNCOND_BRANCH(ins);
4150 s390_br (code, ins->sreg1);
4156 s390_lghi(code, ins->dreg, 1);
4158 s390_lghi(code, ins->dreg, 0);
4164 s390_lghi(code, ins->dreg, 1);
4166 s390_lghi(code, ins->dreg, 0);
4172 s390_lghi(code, ins->dreg, 1);
4174 s390_lghi(code, ins->dreg, 0);
4180 s390_lghi(code, ins->dreg, 1);
4182 s390_lghi(code, ins->dreg, 0);
4188 s390_lghi(code, ins->dreg, 1);
4190 s390_lghi(code, ins->dreg, 0);
4193 case OP_COND_EXC_EQ:
4194 case OP_COND_EXC_IEQ:
4195 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4197 case OP_COND_EXC_NE_UN:
4198 case OP_COND_EXC_INE_UN:
4199 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4201 case OP_COND_EXC_LT:
4202 case OP_COND_EXC_ILT:
4203 case OP_COND_EXC_LT_UN:
4204 case OP_COND_EXC_ILT_UN:
4205 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4207 case OP_COND_EXC_GT:
4208 case OP_COND_EXC_IGT:
4209 case OP_COND_EXC_GT_UN:
4210 case OP_COND_EXC_IGT_UN:
4211 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4213 case OP_COND_EXC_GE:
4214 case OP_COND_EXC_IGE:
4215 case OP_COND_EXC_GE_UN:
4216 case OP_COND_EXC_IGE_UN:
4217 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4219 case OP_COND_EXC_LE:
4220 case OP_COND_EXC_ILE:
4221 case OP_COND_EXC_LE_UN:
4222 case OP_COND_EXC_ILE_UN:
4223 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4225 case OP_COND_EXC_OV:
4226 case OP_COND_EXC_IOV:
4227 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4229 case OP_COND_EXC_NO:
4230 case OP_COND_EXC_INO:
4231 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4234 case OP_COND_EXC_IC:
4235 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4237 case OP_COND_EXC_NC:
4238 case OP_COND_EXC_INC:
4239 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4243 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4247 EMIT_COND_BRANCH (ins, S390_CC_NE);
4253 EMIT_COND_BRANCH (ins, S390_CC_LT);
4259 EMIT_COND_BRANCH (ins, S390_CC_GT);
4265 EMIT_COND_BRANCH (ins, S390_CC_GE);
4271 EMIT_COND_BRANCH (ins, S390_CC_LE);
4274 /* floating point opcodes */
4276 if (*((double *) ins->inst_p0) == 0) {
4277 s390_lzdr (code, ins->dreg);
4279 S390_SET (code, s390_r13, ins->inst_p0);
4280 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4285 if (*((float *) ins->inst_p0) == 0) {
4286 s390_lzdr (code, ins->dreg);
4288 S390_SET (code, s390_r13, ins->inst_p0);
4289 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4293 case OP_STORER8_MEMBASE_REG: {
4294 S390_LONG (code, stdy, std, ins->sreg1, 0,
4295 ins->inst_destbasereg, ins->inst_offset);
4298 case OP_LOADR8_MEMBASE: {
4299 S390_LONG (code, ldy, ld, ins->dreg, 0,
4300 ins->inst_basereg, ins->inst_offset);
4303 case OP_STORER4_MEMBASE_REG: {
4304 s390_ledbr (code, s390_f15, ins->sreg1);
4305 S390_LONG (code, stey, ste, s390_f15, 0,
4306 ins->inst_destbasereg, ins->inst_offset);
4309 case OP_LOADR4_MEMBASE: {
4310 S390_LONG (code, ldy, ld, s390_f15, 0,
4311 ins->inst_basereg, ins->inst_offset);
4312 s390_ldebr (code, ins->dreg, s390_f15);
4315 case OP_ICONV_TO_R_UN: {
4316 s390_cdfbr (code, ins->dreg, ins->sreg1);
4317 s390_ltr (code, ins->sreg1, ins->sreg1);
4319 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4320 s390_ldgr (code, s390_f15, s390_r13);
4321 s390_adbr (code, ins->dreg, s390_f15);
4324 case OP_LCONV_TO_R_UN: {
4325 s390_cdgbr (code, ins->dreg, ins->sreg1);
4326 s390_ltgr (code, ins->sreg1, ins->sreg1);
4328 S390_SET (code, s390_r13, 0x41f0000000000000llu);
4329 s390_ldgr (code, s390_f15, s390_r13);
4330 s390_adbr (code, ins->dreg, s390_f15);
4333 case OP_LCONV_TO_R4:
4334 case OP_ICONV_TO_R4: {
4335 s390_cegbr (code, ins->dreg, ins->sreg1);
4336 s390_ldebr (code, ins->dreg, ins->dreg);
4339 case OP_LCONV_TO_R8:
4340 case OP_ICONV_TO_R8: {
4341 s390_cdgbr (code, ins->dreg, ins->sreg1);
4344 case OP_FCONV_TO_I1:
4345 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4347 case OP_FCONV_TO_U1:
4348 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4350 case OP_FCONV_TO_I2:
4351 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4353 case OP_FCONV_TO_U2:
4354 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4356 case OP_FCONV_TO_I4:
4358 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4360 case OP_FCONV_TO_U4:
4362 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4364 case OP_FCONV_TO_I8:
4365 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4367 case OP_LCONV_TO_OVF_I: {
4368 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4370 s390_ltgr (code, ins->sreg2, ins->sreg2);
4371 s390_jnl (code, 0); CODEPTR(code, o[0]);
4372 s390_ltgr (code, ins->sreg1, ins->sreg1);
4373 s390_jnl (code, 0); CODEPTR(code, o[1]);
4374 s390_lhi (code, s390_r13, -1);
4375 s390_cgr (code, ins->sreg1, s390_r13);
4376 s390_jnz (code, 0); CODEPTR(code, o[2]);
4377 if (ins->dreg != ins->sreg2)
4378 s390_lgr (code, ins->dreg, ins->sreg2);
4379 s390_j (code, 0); CODEPTR(code, o[3]);
4380 PTRSLOT(code, o[0]);
4381 s390_jz (code, 0); CODEPTR(code, o[4]);
4382 PTRSLOT(code, o[1]);
4383 PTRSLOT(code, o[2]);
4384 mono_add_patch_info (cfg, code - cfg->native_code,
4385 MONO_PATCH_INFO_EXC, "OverflowException");
4386 s390_brasl (code, s390_r14, 0);
4387 PTRSLOT(code, o[3]);
4388 PTRSLOT(code, o[4]);
4392 s390_lpdbr (code, ins->dreg, ins->sreg1);
4396 s390_sqdbr (code, ins->dreg, ins->sreg1);
4401 s390_adbr (code, ins->dreg, src2);
4405 CHECK_SRCDST_NCOM_F;
4406 s390_sdbr (code, ins->dreg, src2);
4411 s390_mdbr (code, ins->dreg, src2);
4415 CHECK_SRCDST_NCOM_F;
4416 s390_ddbr (code, ins->dreg, src2);
4420 s390_lcdbr (code, ins->dreg, ins->sreg1);
4424 CHECK_SRCDST_NCOM_F;
4425 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4429 s390_cdbr (code, ins->sreg1, ins->sreg2);
4433 s390_cdbr (code, ins->sreg1, ins->sreg2);
4434 s390_lghi (code, ins->dreg, 1);
4436 s390_lghi (code, ins->dreg, 0);
4440 s390_cdbr (code, ins->sreg1, ins->sreg2);
4441 s390_lghi (code, ins->dreg, 1);
4443 s390_lghi (code, ins->dreg, 0);
4447 s390_cdbr (code, ins->sreg1, ins->sreg2);
4448 s390_lghi (code, ins->dreg, 1);
4450 s390_lghi (code, ins->dreg, 0);
4454 s390_cdbr (code, ins->sreg1, ins->sreg2);
4455 s390_lghi (code, ins->dreg, 1);
4457 s390_lghi (code, ins->dreg, 0);
4461 s390_cdbr (code, ins->sreg1, ins->sreg2);
4462 s390_lghi (code, ins->dreg, 1);
4464 s390_lghi (code, ins->dreg, 0);
4469 s390_jo (code, 0); CODEPTR(code, o);
4470 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4475 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4479 s390_jo (code, 0); CODEPTR(code, o);
4480 EMIT_COND_BRANCH (ins, S390_CC_LT);
4485 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4489 s390_jo (code, 0); CODEPTR(code, o);
4490 EMIT_COND_BRANCH (ins, S390_CC_GT);
4495 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4499 s390_jo (code, 0); CODEPTR(code, o);
4500 EMIT_COND_BRANCH (ins, S390_CC_GE);
4505 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4509 s390_jo (code, 0); CODEPTR(code, o);
4510 EMIT_COND_BRANCH (ins, S390_CC_LE);
4515 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4519 s390_lhi (code, s390_r13, 0x7f);
4520 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4521 s390_jz (code, 0); CODEPTR(code, o);
4522 mono_add_patch_info (cfg, code - cfg->native_code,
4523 MONO_PATCH_INFO_EXC, "ArithmeticException");
4524 s390_brasl (code, s390_r14,0);
4528 case OP_S390_MOVE: {
4529 if (ins->backend.size > 0) {
4530 if (ins->backend.size <= 256) {
4531 s390_mvc (code, ins->backend.size, ins->dreg,
4532 ins->inst_offset, ins->sreg1, ins->inst_imm);
4534 s390_lgr (code, s390_r0, ins->dreg);
4535 if (ins->inst_offset > 0) {
4536 if (s390_is_imm16 (ins->inst_offset)) {
4537 s390_aghi (code, s390_r0, ins->inst_offset);
4538 } else if (s390_is_imm32 (ins->inst_offset)) {
4539 s390_agfi (code, s390_r0, ins->inst_offset);
4541 S390_SET (code, s390_r13, ins->inst_offset);
4542 s390_agr (code, s390_r0, s390_r13);
4545 s390_lgr (code, s390_r12, ins->sreg1);
4546 if (ins->inst_imm > 0) {
4547 if (s390_is_imm16 (ins->inst_imm)) {
4548 s390_aghi (code, s390_r12, ins->inst_imm);
4549 } else if (s390_is_imm32 (ins->inst_imm)) {
4550 s390_agfi (code, s390_r12, ins->inst_imm);
4552 S390_SET (code, s390_r13, ins->inst_imm);
4553 s390_agr (code, s390_r12, s390_r13);
4556 if (s390_is_imm16 (ins->backend.size)) {
4557 s390_lghi (code, s390_r1, ins->backend.size);
4558 } else if (s390_is_imm32 (ins->inst_offset)) {
4559 s390_agfi (code, s390_r1, ins->backend.size);
4561 S390_SET (code, s390_r13, ins->backend.size);
4562 s390_agr (code, s390_r1, s390_r13);
4564 s390_lgr (code, s390_r13, s390_r1);
4565 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4571 case OP_ATOMIC_ADD_I8: {
4572 s390_lgr (code, s390_r1, ins->sreg2);
4573 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4574 s390_agr (code, s390_r1, s390_r0);
4575 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4576 s390_jnz (code, -10);
4577 s390_lgr (code, ins->dreg, s390_r1);
4580 case OP_ATOMIC_EXCHANGE_I8: {
4581 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4582 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4583 s390_jnz (code, -6);
4584 s390_lgr (code, ins->dreg, s390_r0);
4587 case OP_ATOMIC_ADD_I4: {
4588 s390_lgfr(code, s390_r1, ins->sreg2);
4589 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4590 s390_agr (code, s390_r1, s390_r0);
4591 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4592 s390_jnz (code, -9);
4593 s390_lgfr(code, ins->dreg, s390_r1);
4596 case OP_ATOMIC_EXCHANGE_I4: {
4597 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4598 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4599 s390_jnz (code, -4);
4600 s390_lgfr(code, ins->dreg, s390_r0);
4603 case OP_S390_BKCHAIN: {
4604 s390_lgr (code, ins->dreg, ins->sreg1);
4605 if (s390_is_imm16 (cfg->stack_offset)) {
4606 s390_aghi (code, ins->dreg, cfg->stack_offset);
4607 } else if (s390_is_imm32 (cfg->stack_offset)) {
4608 s390_agfi (code, ins->dreg, cfg->stack_offset);
4610 S390_SET (code, s390_r13, cfg->stack_offset);
4611 s390_agr (code, ins->dreg, s390_r13);
4615 case OP_MEMORY_BARRIER:
4619 case OP_GC_SAFE_POINT: {
4622 s390_chi (code, ins->sreg1, 1);
4623 s390_je (code, 0); CODEPTR(code, br);
4624 mono_add_patch_info (cfg, code- cfg->native_code, MONO_PATCH_INFO_ABS,
4625 mono_threads_state_poll);
4626 S390_CALL_TEMPLATE (code, s390_r14);
4631 case OP_GC_LIVENESS_DEF:
4632 case OP_GC_LIVENESS_USE:
4633 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4634 ins->backend.pc_offset = code - cfg->native_code;
4636 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4637 ins->backend.pc_offset = code - cfg->native_code;
4638 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4641 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4642 g_assert_not_reached ();
4645 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4646 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4647 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4648 g_assert_not_reached ();
4651 last_offset = offset;
4654 cfg->code_len = code - cfg->native_code;
4657 /*========================= End of Function ========================*/
4659 /*------------------------------------------------------------------*/
4661 /* Name - mono_arch_register_lowlevel_calls */
4663 /* Function - Register routines to help with --trace operation. */
4665 /*------------------------------------------------------------------*/
4668 mono_arch_register_lowlevel_calls (void)
4672 /*========================= End of Function ========================*/
4674 /*------------------------------------------------------------------*/
4676 /* Name - mono_arch_patch_code */
4678 /* Function - Process the patch data created during the */
4679 /* instruction build process. This resolves jumps, */
4680 /* calls, variables etc. */
4682 /*------------------------------------------------------------------*/
4685 mono_arch_patch_code (MonoCompile *cfg, MonoMethod *method, MonoDomain *domain,
4686 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4688 MonoJumpInfo *patch_info;
4690 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4691 unsigned char *ip = patch_info->ip.i + code;
4692 gconstpointer target = NULL;
4694 target = mono_resolve_patch_target (method, domain, code,
4695 patch_info, run_cctors);
4697 switch (patch_info->type) {
4698 case MONO_PATCH_INFO_IP:
4699 case MONO_PATCH_INFO_LDSTR:
4700 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4701 case MONO_PATCH_INFO_LDTOKEN:
4702 case MONO_PATCH_INFO_EXC:
4703 s390_patch_addr (ip, (guint64) target);
4705 case MONO_PATCH_INFO_METHOD:
4706 case MONO_PATCH_INFO_INTERNAL_METHOD:
4707 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4708 case MONO_PATCH_INFO_CLASS_INIT:
4709 case MONO_PATCH_INFO_RGCTX_FETCH:
4710 case MONO_PATCH_INFO_MONITOR_ENTER:
4711 case MONO_PATCH_INFO_MONITOR_ENTER_V4:
4712 case MONO_PATCH_INFO_MONITOR_EXIT:
4713 case MONO_PATCH_INFO_ABS: {
4714 S390_EMIT_CALL (ip, target);
4717 case MONO_PATCH_INFO_SWITCH:
4718 /*----------------------------------*/
4719 /* ip points at the basr r13,0/j +4 */
4720 /* instruction the vtable value */
4721 /* follows this (i.e. ip+6) */
4722 /*----------------------------------*/
4723 S390_EMIT_LOAD (ip, target);
4725 case MONO_PATCH_INFO_METHODCONST:
4726 case MONO_PATCH_INFO_CLASS:
4727 case MONO_PATCH_INFO_IMAGE:
4728 case MONO_PATCH_INFO_FIELD:
4729 case MONO_PATCH_INFO_IID:
4730 case MONO_PATCH_INFO_EXC_NAME:
4731 target = S390_RELATIVE(target, ip);
4732 s390_patch_rel (ip, (guint64) target);
4734 case MONO_PATCH_INFO_R4:
4735 case MONO_PATCH_INFO_R8:
4736 case MONO_PATCH_INFO_METHOD_REL:
4737 g_assert_not_reached ();
4740 target = S390_RELATIVE(target, ip);
4742 s390_patch_rel (ip, (guint64) target);
4747 /*========================= End of Function ========================*/
4749 /*------------------------------------------------------------------*/
4751 /* Name - emit_load_volatile_arguments */
4753 /* Function - Emit the instructions to reload parameter regist- */
4754 /* registers for use with "tail" operations. */
4756 /* The register loading operations performed here */
4757 /* are the mirror of the store operations performed */
4758 /* in mono_arch_emit_prolog and need to be kept in */
4759 /* synchronization with it. */
4761 /*------------------------------------------------------------------*/
4764 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4767 MonoMethod *method = cfg->method;
4768 MonoMethodSignature *sig = mono_method_signature(method);
4772 cinfo = get_call_info (NULL, NULL, sig);
4774 if (cinfo->struct_ret) {
4775 ArgInfo *ainfo = &cinfo->ret;
4776 inst = cfg->vret_addr;
4777 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4780 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4781 ArgInfo *ainfo = cinfo->args + i;
4782 inst = cfg->args [pos];
4784 if (inst->opcode == OP_REGVAR) {
4785 if (ainfo->regtype == RegTypeGeneral)
4786 s390_lgr (code, ainfo->reg, inst->dreg);
4787 else if (ainfo->regtype == RegTypeFP) {
4788 if (inst->dreg != ainfo->reg) {
4789 if (ainfo->size == 4) {
4790 s390_ldebr (code, ainfo->reg, inst->dreg);
4792 s390_ldr (code, ainfo->reg, inst->dreg);
4796 else if (ainfo->regtype == RegTypeBase) {
4798 g_assert_not_reached ();
4800 if (ainfo->regtype == RegTypeGeneral) {
4801 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4802 g_assert_not_reached();
4803 switch (ainfo->size) {
4805 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4808 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4811 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4814 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4817 } else if (ainfo->regtype == RegTypeBase) {
4818 } else if (ainfo->regtype == RegTypeFP) {
4819 if (ainfo->size == 8)
4820 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4821 else if (ainfo->size == 4)
4822 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4824 g_assert_not_reached ();
4825 } else if (ainfo->regtype == RegTypeStructByVal) {
4826 if (ainfo->reg != STK_BASE) {
4827 switch (ainfo->size) {
4829 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4832 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4835 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4838 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4842 } else if (ainfo->regtype == RegTypeStructByAddr) {
4843 if (ainfo->reg != STK_BASE) {
4844 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4847 g_assert_not_reached ();
4855 /*========================= End of Function ========================*/
4857 /*------------------------------------------------------------------*/
4859 /* Name - mono_arch_emit_prolog */
4861 /* Function - Create the instruction sequence for a function */
4864 /*------------------------------------------------------------------*/
4867 mono_arch_emit_prolog (MonoCompile *cfg)
4869 MonoMethod *method = cfg->method;
4871 MonoMethodSignature *sig;
4873 long alloc_size, pos, max_offset, i, cfa_offset = 0;
4880 cfg->code_size = 512;
4882 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4884 cfg->code_size += 256;
4885 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4886 cfg->code_size += 256;
4888 if (method->save_lmf)
4889 cfg->code_size += 200;
4891 cfg->native_code = code = g_malloc (cfg->code_size);
4893 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
4894 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
4895 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4896 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
4898 if (cfg->arch.bkchain_reg != -1)
4899 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4901 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4902 cfg->used_int_regs |= 1 << 11;
4905 alloc_size = cfg->stack_offset;
4907 cfg->stack_usage = cfa_offset = alloc_size;
4908 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
4909 s390_lgr (code, s390_r11, STK_BASE);
4910 if (s390_is_imm16 (alloc_size)) {
4911 s390_aghi (code, STK_BASE, -alloc_size);
4912 } else if (s390_is_imm32 (alloc_size)) {
4913 s390_agfi (code, STK_BASE, -alloc_size);
4915 int stackSize = alloc_size;
4916 while (stackSize > INT_MAX) {
4917 s390_agfi (code, STK_BASE, -INT_MAX);
4918 stackSize -= INT_MAX;
4920 s390_agfi (code, STK_BASE, -stackSize);
4922 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4924 if (cfg->frame_reg != STK_BASE)
4925 s390_lgr (code, s390_r11, STK_BASE);
4927 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
4929 /* store runtime generic context */
4930 if (cfg->rgctx_var) {
4931 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
4933 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
4934 cfg->rgctx_var->inst_basereg,
4935 cfg->rgctx_var->inst_offset);
4938 /* compute max_offset in order to use short forward jumps
4939 * we always do it on s390 because the immediate displacement
4940 * for jumps is too small
4943 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4945 bb->max_offset = max_offset;
4947 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4950 MONO_BB_FOR_EACH_INS (bb, ins)
4951 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4954 /* load arguments allocated to register from the stack */
4955 sig = mono_method_signature (method);
4958 cinfo = get_call_info (cfg, cfg->mempool, sig);
4960 if (cinfo->struct_ret) {
4961 ArgInfo *ainfo = &cinfo->ret;
4962 inst = cfg->vret_addr;
4963 inst->backend.size = ainfo->vtsize;
4964 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4967 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4968 ArgInfo *ainfo = cinfo->args + i;
4969 inst = cfg->args [pos];
4971 if (inst->opcode == OP_VTARG_ADDR)
4972 inst = inst->inst_left;
4974 if (inst->opcode == OP_REGVAR) {
4975 if (ainfo->regtype == RegTypeGeneral)
4976 s390_lgr (code, inst->dreg, ainfo->reg);
4977 else if (ainfo->regtype == RegTypeFP) {
4978 if (inst->dreg != ainfo->reg) {
4979 if (ainfo->size == 4) {
4980 s390_ledbr (code, inst->dreg, ainfo->reg);
4982 s390_ldr (code, inst->dreg, ainfo->reg);
4986 else if (ainfo->regtype == RegTypeBase) {
4987 s390_lgr (code, s390_r13, STK_BASE);
4988 s390_aghi (code, s390_r13, alloc_size);
4989 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4991 g_assert_not_reached ();
4993 if (cfg->verbose_level > 2)
4994 g_print ("Argument %d assigned to register %s\n",
4995 pos, mono_arch_regname (inst->dreg));
4997 if (ainfo->regtype == RegTypeGeneral) {
4998 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4999 g_assert_not_reached();
5000 switch (ainfo->size) {
5002 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5005 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5008 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5011 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5014 } else if (ainfo->regtype == RegTypeBase) {
5015 } else if (ainfo->regtype == RegTypeFP) {
5016 if (ainfo->size == 8)
5017 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5018 else if (ainfo->size == 4)
5019 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5021 g_assert_not_reached ();
5022 } else if (ainfo->regtype == RegTypeStructByVal) {
5023 int doffset = inst->inst_offset;
5025 if (ainfo->reg != STK_BASE)
5029 s390_lgr (code, s390_r13, STK_BASE);
5030 s390_aghi (code, s390_r13, alloc_size);
5033 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5034 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5039 if (ainfo->reg == STK_BASE)
5040 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5041 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5044 if (ainfo->reg == STK_BASE)
5045 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5046 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5049 if (ainfo->reg == STK_BASE)
5050 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5051 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5054 if (ainfo->reg == STK_BASE)
5055 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5056 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5059 } else if (ainfo->regtype == RegTypeStructByAddr) {
5060 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5061 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5063 g_assert_not_reached ();
5068 if (method->save_lmf) {
5069 /*---------------------------------------------------------------*/
5070 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5071 /*---------------------------------------------------------------*/
5072 lmfOffset = alloc_size - sizeof(MonoLMF);
5074 s390_lgr (code, s390_r13, cfg->frame_reg);
5075 s390_aghi (code, s390_r13, lmfOffset);
5077 /*---------------------------------------------------------------*/
5078 /* Preserve the parameter registers while we fix up the lmf */
5079 /*---------------------------------------------------------------*/
5080 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5081 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5083 /*---------------------------------------------------------------*/
5084 /* On return from this call r2 have the address of the &lmf */
5085 /*---------------------------------------------------------------*/
5086 if (lmf_addr_tls_offset == -1) {
5087 mono_add_patch_info (cfg, code - cfg->native_code,
5088 MONO_PATCH_INFO_INTERNAL_METHOD,
5089 (gpointer)"mono_get_lmf_addr");
5090 S390_CALL_TEMPLATE(code, s390_r1);
5092 /*-------------------------------------------------------*/
5093 /* Get LMF by getting value from thread level storage */
5094 /*-------------------------------------------------------*/
5095 s390_ear (code, s390_r1, 0);
5096 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5097 s390_ear (code, s390_r1, 1);
5098 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5101 /*---------------------------------------------------------------*/
5102 /* Set lmf.lmf_addr = jit_tls->lmf */
5103 /*---------------------------------------------------------------*/
5104 s390_stg (code, s390_r2, 0, s390_r13,
5105 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5107 /*---------------------------------------------------------------*/
5108 /* Get current lmf */
5109 /*---------------------------------------------------------------*/
5110 s390_lg (code, s390_r0, 0, s390_r2, 0);
5112 /*---------------------------------------------------------------*/
5113 /* Set our lmf as the current lmf */
5114 /*---------------------------------------------------------------*/
5115 s390_stg (code, s390_r13, 0, s390_r2, 0);
5117 /*---------------------------------------------------------------*/
5118 /* Have our lmf.previous_lmf point to the last lmf */
5119 /*---------------------------------------------------------------*/
5120 s390_stg (code, s390_r0, 0, s390_r13,
5121 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5123 /*---------------------------------------------------------------*/
5124 /* save method info */
5125 /*---------------------------------------------------------------*/
5126 S390_SET (code, s390_r1, method);
5127 s390_stg (code, s390_r1, 0, s390_r13,
5128 G_STRUCT_OFFSET(MonoLMF, method));
5130 /*---------------------------------------------------------------*/
5131 /* save the current IP */
5132 /*---------------------------------------------------------------*/
5133 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5134 s390_basr (code, s390_r1, 0);
5135 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5137 /*---------------------------------------------------------------*/
5138 /* Save general and floating point registers */
5139 /*---------------------------------------------------------------*/
5140 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5141 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5142 for (i = 0; i < 16; i++) {
5143 s390_std (code, i, 0, s390_r13,
5144 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5147 /*---------------------------------------------------------------*/
5148 /* Restore the parameter registers now that we've set up the lmf */
5149 /*---------------------------------------------------------------*/
5150 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5151 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5155 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5157 cfg->code_len = code - cfg->native_code;
5158 g_assert (cfg->code_len < cfg->code_size);
5163 /*========================= End of Function ========================*/
5165 /*------------------------------------------------------------------*/
5167 /* Name - mono_arch_emit_epilog */
5169 /* Function - Emit the instructions for a function epilog. */
5171 /*------------------------------------------------------------------*/
5174 mono_arch_emit_epilog (MonoCompile *cfg)
5176 MonoMethod *method = cfg->method;
5179 int max_epilog_size = 96;
5181 if (cfg->method->save_lmf)
5182 max_epilog_size += 128;
5184 if (mono_jit_trace_calls != NULL)
5185 max_epilog_size += 128;
5186 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5187 max_epilog_size += 128;
5189 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5190 cfg->code_size *= 2;
5191 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5192 cfg->stat_code_reallocs++;
5195 code = cfg->native_code + cfg->code_len;
5197 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5198 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5202 if (method->save_lmf)
5203 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5205 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5206 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5208 code = backUpStackPtr(cfg, code);
5210 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5211 s390_br (code, s390_r14);
5213 cfg->code_len = code - cfg->native_code;
5215 g_assert (cfg->code_len < cfg->code_size);
5219 /*========================= End of Function ========================*/
5221 /*------------------------------------------------------------------*/
5223 /* Name - mono_arch_emit_exceptions */
5225 /* Function - Emit the blocks to handle exception conditions. */
5227 /*------------------------------------------------------------------*/
5230 mono_arch_emit_exceptions (MonoCompile *cfg)
5232 MonoJumpInfo *patch_info;
5238 MonoClass *exc_classes [MAX_EXC];
5239 guint8 *exc_throw_start [MAX_EXC];
5241 for (patch_info = cfg->patch_info;
5243 patch_info = patch_info->next) {
5244 if (patch_info->type == MONO_PATCH_INFO_EXC)
5248 code_size = exc_count * 48;
5250 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5251 cfg->code_size *= 2;
5252 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5253 cfg->stat_code_reallocs++;
5256 code = cfg->native_code + cfg->code_len;
5258 /*---------------------------------------------------------------------*/
5259 /* Add code to raise exceptions */
5260 /*---------------------------------------------------------------------*/
5261 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5262 switch (patch_info->type) {
5263 case MONO_PATCH_INFO_EXC: {
5264 guint8 *ip = patch_info->ip.i + cfg->native_code;
5265 MonoClass *exc_class;
5268 /*-----------------------------------------------------*/
5269 /* Patch the branch in epilog to come here */
5270 /*-----------------------------------------------------*/
5271 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5273 exc_class = mono_class_from_name (mono_defaults.corlib,
5275 patch_info->data.name);
5276 g_assert (exc_class);
5277 throw_ip = patch_info->ip.i;
5279 for (iExc = 0; iExc < nThrows; ++iExc)
5280 if (exc_classes [iExc] == exc_class)
5283 if (iExc < nThrows) {
5284 s390_jcl (code, S390_CC_UN,
5285 (guint64) exc_throw_start [iExc]);
5286 patch_info->type = MONO_PATCH_INFO_NONE;
5289 if (nThrows < MAX_EXC) {
5290 exc_classes [nThrows] = exc_class;
5291 exc_throw_start [nThrows] = code;
5294 /*---------------------------------------------*/
5295 /* Patch the parameter passed to the handler */
5296 /*---------------------------------------------*/
5297 S390_SET (code, s390_r2, exc_class->type_token);
5298 /*---------------------------------------------*/
5299 /* Load return address & parameter register */
5300 /*---------------------------------------------*/
5301 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5302 cfg->native_code + 8), code));
5303 /*---------------------------------------------*/
5304 /* Reuse the current patch to set the jump */
5305 /*---------------------------------------------*/
5306 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5307 patch_info->data.name = "mono_arch_throw_corlib_exception";
5308 patch_info->ip.i = code - cfg->native_code;
5309 S390_BR_TEMPLATE (code, s390_r1);
5319 cfg->code_len = code - cfg->native_code;
5321 g_assert (cfg->code_len < cfg->code_size);
5325 /*========================= End of Function ========================*/
5327 /*------------------------------------------------------------------*/
5329 /* Name - mono_arch_finish_init */
5331 /* Function - Setup the JIT's Thread Level Specific Data. */
5333 /*------------------------------------------------------------------*/
5336 mono_arch_finish_init (void)
5338 appdomain_tls_offset = mono_domain_get_tls_offset();
5339 lmf_tls_offset = mono_get_lmf_tls_offset();
5340 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5343 /*========================= End of Function ========================*/
5345 /*------------------------------------------------------------------*/
5347 /* Name - mono_arch_free_jit_tls_data */
5349 /* Function - Free tls data. */
5351 /*------------------------------------------------------------------*/
5354 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5358 /*========================= End of Function ========================*/
5360 /*------------------------------------------------------------------*/
5362 /* Name - mono_arch_emit_inst_for_method */
5364 /*------------------------------------------------------------------*/
5367 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5372 /*========================= End of Function ========================*/
5374 /*------------------------------------------------------------------*/
5376 /* Name - mono_arch_decompose_opts */
5378 /* Function - Decompose opcode into a System z opcode. */
5380 /*------------------------------------------------------------------*/
5383 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5386 * Have to rename these to avoid being decomposed normally, since the normal
5387 * decomposition does not work on S390.
5389 switch (ins->opcode) {
5391 ins->opcode = OP_S390_ISUB_OVF;
5393 case OP_ISUB_OVF_UN:
5394 ins->opcode = OP_S390_ISUB_OVF_UN;
5397 ins->opcode = OP_S390_IADD_OVF;
5399 case OP_IADD_OVF_UN:
5400 ins->opcode = OP_S390_IADD_OVF_UN;
5403 ins->opcode = OP_S390_LADD_OVF;
5405 case OP_LADD_OVF_UN:
5406 ins->opcode = OP_S390_LADD_OVF_UN;
5409 ins->opcode = OP_S390_LSUB_OVF;
5411 case OP_LSUB_OVF_UN:
5412 ins->opcode = OP_S390_LSUB_OVF_UN;
5419 /*========================= End of Function ========================*/
5421 /*------------------------------------------------------------------*/
5423 /* Name - mono_arch_print_tree */
5425 /* Function - Print platform-specific opcode details. */
5427 /* Returns - 1 - opcode details have been printed */
5428 /* 0 - opcode details have not been printed */
5430 /*------------------------------------------------------------------*/
5433 mono_arch_print_tree (MonoInst *tree, int arity)
5437 switch (tree->opcode) {
5438 case OP_S390_LOADARG:
5439 case OP_S390_ARGREG:
5440 case OP_S390_ARGPTR:
5441 printf ("[0x%lx(%s)]", tree->inst_offset,
5442 mono_arch_regname (tree->inst_basereg));
5445 case OP_S390_STKARG:
5446 printf ("[0x%lx(previous_frame)]",
5451 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5452 tree->inst_offset, tree->backend.size,
5453 mono_arch_regname(tree->dreg),
5455 mono_arch_regname(tree->sreg1));
5458 case OP_S390_SETF4RET:
5459 printf ("[f%s,f%s]",
5460 mono_arch_regname (tree->dreg),
5461 mono_arch_regname (tree->sreg1));
5465 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5467 mono_arch_regname (tree->sreg1));
5470 case OP_S390_BKCHAIN:
5471 printf ("[previous_frame(%s)]",
5472 mono_arch_regname (tree->sreg1));
5480 /*========================= End of Function ========================*/
5482 /*------------------------------------------------------------------*/
5484 /* Name - mono_arch_regalloc_cost */
5486 /* Function - Determine the cost, in the number of memory */
5487 /* references, of the action of allocating the var- */
5488 /* iable VMV into a register during global register */
5491 /* Returns - Cost */
5493 /*------------------------------------------------------------------*/
5496 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5502 /*========================= End of Function ========================*/
5504 /*------------------------------------------------------------------*/
5506 /* Name - mono_arch_flush_register_windows */
5512 /*------------------------------------------------------------------*/
5515 mono_arch_flush_register_windows (void)
5519 /*========================= End of Function ========================*/
5521 /*------------------------------------------------------------------*/
5523 /* Name - mono_arch_is_inst_imm */
5525 /* Function - Determine if operand qualifies as an immediate */
5526 /* value. For s390 this is a value -32768-32768 */
5528 /* Returns - True|False - is [not] immediate value. */
5530 /*------------------------------------------------------------------*/
5533 mono_arch_is_inst_imm (gint64 imm)
5535 return s390_is_imm32 (imm);
5538 /*========================= End of Function ========================*/
5540 /*------------------------------------------------------------------*/
5542 /* Name - mono_arch_get_patch_offset */
5544 /* Function - Dummy entry point until s390x supports aot. */
5546 /* Returns - Offset for patch. */
5548 /*------------------------------------------------------------------*/
5551 mono_arch_get_patch_offset (guint8 *code)
5556 /*========================= End of Function ========================*/
5558 /*------------------------------------------------------------------*/
5560 /* Name - mono_arch_context_get_int_reg. */
5564 /* Returns - Return a register from the context. */
5566 /*------------------------------------------------------------------*/
5569 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5571 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5574 /*========================= End of Function ========================*/
5576 /*------------------------------------------------------------------*/
5578 /* Name - mono_arch_context_set_int_reg. */
5580 /* Function - Set a value in a specified register. */
5582 /*------------------------------------------------------------------*/
5585 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5587 ctx->uc_mcontext.gregs[reg] = val;
5590 /*========================= End of Function ========================*/
5592 /*------------------------------------------------------------------*/
5594 /* Name - mono_arch_get_this_arg_from_call. */
5598 /*------------------------------------------------------------------*/
5601 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5603 return (gpointer) regs [s390_r2];
5606 /*========================= End of Function ========================*/
5608 /*------------------------------------------------------------------*/
5610 /* Name - mono_arch_install_handler_block_guard */
5614 /*------------------------------------------------------------------*/
5617 mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause,
5618 MonoContext *ctx, gpointer new_value)
5621 gpointer *sp, old_value;
5624 offset = clause->exvar_offset;
5627 bp = MONO_CONTEXT_GET_BP (ctx);
5628 sp = *(gpointer*)(bp + offset);
5631 if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size))
5639 /*========================= End of Function ========================*/
5641 /*------------------------------------------------------------------*/
5643 /* Name - get_delegate_invoke_impl. */
5647 /*------------------------------------------------------------------*/
5650 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5652 guint8 *code, *start;
5657 start = code = mono_global_codeman_reserve (size);
5659 /* Replace the this argument with the target */
5660 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5661 s390_lg (code, s390_r2, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, target));
5662 s390_br (code, s390_r1);
5663 g_assert ((code - start) <= size);
5665 mono_arch_flush_icache (start, size);
5669 size = 32 + param_count * 8;
5670 start = code = mono_global_codeman_reserve (size);
5672 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5673 /* slide down the arguments */
5674 for (i = 0; i < param_count; ++i) {
5675 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5677 s390_br (code, s390_r1);
5679 g_assert ((code - start) <= size);
5681 mono_arch_flush_icache (start, size);
5684 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL);
5687 *code_len = code - start;
5692 /*========================= End of Function ========================*/
5694 /*------------------------------------------------------------------*/
5696 /* Name - mono_arch_get_delegate_invoke_impls. */
5700 /*------------------------------------------------------------------*/
5703 mono_arch_get_delegate_invoke_impls (void)
5711 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5712 res = g_slist_prepend (res, mono_tramp_info_create ("delegate_invoke_impl_has_target", code, code_len, NULL, NULL));
5714 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5715 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5716 tramp_name = g_strdup_printf ("delegate_invoke_impl_target_%d", i);
5717 res = g_slist_prepend (res, mono_tramp_info_create (tramp_name, code, code_len, NULL, NULL));
5718 g_free (tramp_name);
5724 /*========================= End of Function ========================*/
5726 /*------------------------------------------------------------------*/
5728 /* Name - mono_arch_get_delegate_invoke_impl. */
5732 /*------------------------------------------------------------------*/
5735 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5737 guint8 *code, *start;
5739 /* FIXME: Support more cases */
5740 if (MONO_TYPE_ISSTRUCT (sig->ret))
5744 static guint8* cached = NULL;
5750 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5752 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5754 mono_memory_barrier ();
5758 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5761 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5763 for (i = 0; i < sig->param_count; ++i)
5764 if (!mono_is_regsize_var (sig->params [i]))
5768 code = cache [sig->param_count];
5772 if (mono_aot_only) {
5773 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5774 start = mono_aot_get_trampoline (name);
5777 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5780 mono_memory_barrier ();
5782 cache [sig->param_count] = start;
5787 /*========================= End of Function ========================*/
5789 /*------------------------------------------------------------------*/
5791 /* Name - mono_arch_get_delegate_virtual_invoke_impl. */
5795 /*------------------------------------------------------------------*/
5798 mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method,
5799 int offset, gboolean load_imt_reg)
5801 guint8 *code, *start;
5804 start = code = mono_global_codeman_reserve (size);
5807 * Replace the "this" argument with the target
5809 s390_lgr (code, s390_r1, s390_r2);
5810 s390_lg (code, s390_r2, 0, s390_r1, MONO_STRUCT_OFFSET(MonoDelegate, target));
5813 * Load the IMT register, if needed
5816 s390_lg (code, MONO_ARCH_IMT_REG, 0, s390_r1, MONO_STRUCT_OFFSET(MonoDelegate, method));
5822 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET(MonoObject, vtable));
5824 s390_agfi(code, s390_r1, offset);
5826 s390_lg (code, s390_r1, 0, s390_r1, 0);
5827 s390_br (code, s390_r1);
5832 /*========================= End of Function ========================*/
5834 /*------------------------------------------------------------------*/
5836 /* Name - mono_arch_build_imt_thunk. */
5840 /*------------------------------------------------------------------*/
5843 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5844 MonoIMTCheckItem **imt_entries, int count,
5845 gpointer fail_tramp)
5849 guchar *code, *start;
5851 for (i = 0; i < count; ++i) {
5852 MonoIMTCheckItem *item = imt_entries [i];
5853 if (item->is_equals) {
5854 if (item->check_target_idx) {
5855 if (!item->compare_done)
5856 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5857 if (item->has_target_code)
5858 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5860 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5864 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5866 if (!item->has_target_code)
5867 item->chunk_size += LOAD_SIZE;
5869 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5870 #if ENABLE_WRONG_METHOD_CHECK
5871 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5876 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5877 imt_entries [item->check_target_idx]->compare_done = TRUE;
5879 size += item->chunk_size;
5883 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5885 code = mono_domain_code_reserve (domain, size);
5889 for (i = 0; i < count; ++i) {
5890 MonoIMTCheckItem *item = imt_entries [i];
5891 item->code_target = (guint8 *) code;
5892 if (item->is_equals) {
5893 if (item->check_target_idx) {
5894 if (!item->compare_done) {
5895 S390_SET (code, s390_r0, item->key);
5896 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5898 item->jmp_code = (guint8*) code;
5899 s390_jcl (code, S390_CC_NE, 0);
5901 if (item->has_target_code) {
5902 S390_SET (code, s390_r1, item->value.target_code);
5904 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5905 s390_lg (code, s390_r1, 0, s390_r1, 0);
5907 s390_br (code, s390_r1);
5912 S390_SET (code, s390_r0, item->key);
5913 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5914 item->jmp_code = (guint8*) code;
5915 s390_jcl (code, S390_CC_NE, 0);
5916 if (item->has_target_code) {
5917 S390_SET (code, s390_r1, item->value.target_code);
5920 S390_SET (code, s390_r1,
5921 (&(vtable->vtable [item->value.vtable_slot])));
5922 s390_lg (code, s390_r1, 0, s390_r1, 0);
5924 s390_br (code, s390_r1);
5925 target = (gint64) S390_RELATIVE(code, item->jmp_code);
5926 s390_patch_rel(item->jmp_code+2, target);
5927 S390_SET (code, s390_r1, fail_tramp);
5928 s390_br (code, s390_r1);
5929 item->jmp_code = NULL;
5931 /* enable the commented code to assert on wrong method */
5932 #if ENABLE_WRONG_METHOD_CHECK
5933 g_assert_not_reached ();
5935 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5936 s390_lg (code, s390_r1, 0, s390_r1, 0);
5937 s390_br (code, s390_r1);
5941 S390_SET (code, s390_r0, item->key);
5942 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
5943 item->jmp_code = (guint8 *) code;
5944 s390_jcl (code, S390_CC_GE, 0);
5948 * patch the branches to get to the target items
5950 for (i = 0; i < count; ++i) {
5951 MonoIMTCheckItem *item = imt_entries [i];
5952 if (item->jmp_code) {
5953 if (item->check_target_idx) {
5955 offset = (gint64) S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
5957 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
5962 mono_arch_flush_icache ((guint8*)start, (code - start));
5963 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL);
5966 mono_stats.imt_thunks_size += (code - start);
5968 g_assert (code - start <= size);
5973 /*========================= End of Function ========================*/
5975 /*------------------------------------------------------------------*/
5977 /* Name - mono_arch_find_imt_method. */
5979 /* Function - Get the method address from MONO_ARCH_IMT_REG */
5980 /* found in the save area. */
5982 /*------------------------------------------------------------------*/
5985 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
5987 return ((MonoMethod *) regs [MONO_ARCH_IMT_REG]);
5990 /*========================= End of Function ========================*/
5992 /*------------------------------------------------------------------*/
5994 /* Name - mono_arch_find_static_call_vtable */
5996 /* Function - Find the static call vtable. */
5998 /*------------------------------------------------------------------*/
6001 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
6003 mgreg_t *r = (mgreg_t*)regs;
6005 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
6008 /*========================= End of Function ========================*/
6010 /*------------------------------------------------------------------*/
6012 /* Name - mono_arch_get_cie_program */
6014 /* Function - Find the static call vtable. */
6016 /*------------------------------------------------------------------*/
6019 mono_arch_get_cie_program (void)
6023 mono_add_unwind_op_def_cfa (l, 0, 0, STK_BASE, 0);
6028 /*========================= End of Function ========================*/
6030 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6032 /*------------------------------------------------------------------*/
6034 /* Name - mono_arch_set_breakpoint. */
6036 /* Function - Set a breakpoint at the native code corresponding */
6037 /* to JI at NATIVE_OFFSET. The location should */
6038 /* contain code emitted by OP_SEQ_POINT. */
6040 /*------------------------------------------------------------------*/
6043 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6047 breakpointCode.pTrigger = bp_trigger_page;
6048 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6049 code += BREAKPOINT_SIZE;
6052 /*========================= End of Function ========================*/
6054 /*------------------------------------------------------------------*/
6056 /* Name - mono_arch_clear_breakpoint. */
6058 /* Function - Clear the breakpoint at IP. */
6060 /*------------------------------------------------------------------*/
6063 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6068 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6072 /*========================= End of Function ========================*/
6074 /*------------------------------------------------------------------*/
6076 /* Name - mono_arch_is_breakpoint_event. */
6080 /*------------------------------------------------------------------*/
6083 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6085 siginfo_t* sinfo = (siginfo_t*) info;
6088 * Sometimes the address is off by 4
6090 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6096 /*========================= End of Function ========================*/
6098 /*------------------------------------------------------------------*/
6100 /* Name - mono_arch_skip_breakpoint. */
6102 /* Function - Modify the CTX so the IP is placed after the */
6103 /* breakpoint instruction, so when we resume, the */
6104 /* instruction is not executed again. */
6106 /*------------------------------------------------------------------*/
6109 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6111 MONO_CONTEXT_SET_IP (ctx, ((guint8*)MONO_CONTEXT_GET_IP (ctx) + sizeof(RXY_Format)));
6114 /*========================= End of Function ========================*/
6116 /*------------------------------------------------------------------*/
6118 /* Name - mono_arch_start_single_stepping. */
6120 /* Function - Start single stepping. */
6122 /*------------------------------------------------------------------*/
6125 mono_arch_start_single_stepping (void)
6127 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6130 /*========================= End of Function ========================*/
6132 /*------------------------------------------------------------------*/
6134 /* Name - mono_arch_stop_single_stepping. */
6136 /* Function - Stop single stepping. */
6138 /*------------------------------------------------------------------*/
6141 mono_arch_stop_single_stepping (void)
6143 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6146 /*========================= End of Function ========================*/
6148 /*------------------------------------------------------------------*/
6150 /* Name - mono_arch_is_single_step_event. */
6152 /* Function - Return whether the machine state in sigctx cor- */
6153 /* responds to a single step event. */
6155 /*------------------------------------------------------------------*/
6158 mono_arch_is_single_step_event (void *info, void *sigctx)
6160 siginfo_t* sinfo = (siginfo_t*) info;
6163 * Sometimes the address is off by 4
6165 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6171 /*========================= End of Function ========================*/
6173 /*------------------------------------------------------------------*/
6175 /* Name - mono_arch_skip_single_step. */
6177 /* Function - Modify the ctx so the IP is placed after the */
6178 /* single step trigger instruction, so that the */
6179 /* instruction is not executed again. */
6181 /*------------------------------------------------------------------*/
6184 mono_arch_skip_single_step (MonoContext *ctx)
6186 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6189 /*========================= End of Function ========================*/
6191 /*------------------------------------------------------------------*/
6193 /* Name - mono_arch_create_seq_point_info. */
6195 /* Function - Return a pointer to a data struction which is */
6196 /* used by the sequence point implementation in */
6199 /*------------------------------------------------------------------*/
6202 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6208 /*------------------------------------------------------------------*/
6210 /* Name - mono_arch_init_lmf_ext. */
6214 /*------------------------------------------------------------------*/
6217 mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
6219 ext->lmf.previous_lmf = prev_lmf;
6220 /* Mark that this is a MonoLMFExt */
6221 ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
6222 ext->lmf.ebp = (gssize)ext;
6225 /*========================= End of Function ========================*/
6230 mono_arch_opcode_supported (int opcode)
6233 case OP_ATOMIC_ADD_I4:
6234 case OP_ATOMIC_ADD_I8:
6235 case OP_ATOMIC_EXCHANGE_I4:
6236 case OP_ATOMIC_EXCHANGE_I8: