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 (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 (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 = mini_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 klass = obj->vtable->klass;
798 printf("%p [%p] ",obj,curParm);
799 if (klass == mono_defaults.string_class) {
800 printf("[STRING:%p:%s]",
801 obj, mono_string_to_utf8 ((MonoString *) obj));
802 } else if (klass == mono_defaults.int32_class) {
803 printf("[INT32:%p:%d]",
804 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
807 klass->name_space, klass->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_arg = (gpointer *) rParm->gr[iParm];
927 obj = (MonoObject *) this_arg;
928 switch(method->klass->this_arg.type) {
929 case MONO_TYPE_VALUETYPE:
931 guint64 *value = (guint64 *) ((uintptr_t)this_arg + sizeof(MonoObject));
932 printf("this:[value:%p:%016lx], ", this_arg, *value);
934 printf ("this:[NULL], ");
936 case MONO_TYPE_STRING:
939 klass = obj->vtable->klass;
940 if (klass == 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, klass->name_space, klass->name);
948 printf("vtable:[NULL], ");
950 printf ("this:[NULL], ");
953 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this_arg);
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");
1224 case MONO_TYPE_GENERICINST: {
1225 printf("[GENERICINST]\n");
1228 case MONO_TYPE_MVAR: {
1232 case MONO_TYPE_CMOD_REQD: {
1233 printf("[CMOD_REQD]\n");
1236 case MONO_TYPE_CMOD_OPT: {
1237 printf("[CMOD_OPT]\n");
1240 case MONO_TYPE_INTERNAL: {
1241 printf("[INTERNAL]\n");
1245 printf ("(unknown return type %x)",
1246 mono_method_signature (method)->ret->type);
1249 ip = ((gint64) __builtin_extract_return_addr (__builtin_return_address (0)));
1250 printf (" ip: %p\n", (gpointer) ip);
1253 /*========================= End of Function ========================*/
1255 /*------------------------------------------------------------------*/
1257 /* Name - mono_arch_cpu_init */
1259 /* Function - Perform CPU specific initialization to execute */
1262 /*------------------------------------------------------------------*/
1265 mono_arch_cpu_init (void)
1269 /*========================= End of Function ========================*/
1271 /*------------------------------------------------------------------*/
1273 /* Name - mono_arch_init. */
1275 /* Function - Initialize architecture specific code. */
1277 /*------------------------------------------------------------------*/
1280 mono_arch_init (void)
1284 mono_mutex_init_recursive (&mini_arch_mutex);
1286 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1287 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1288 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1290 code = (guint8 *) &breakpointCode;
1291 s390_basr(code, s390_r13, 0);
1293 s390_llong(code, 0);
1294 s390_lg(code, s390_r13, 0, s390_r13, 4);
1295 s390_lg(code, s390_r0, 0, s390_r13, 0);
1298 /*========================= End of Function ========================*/
1300 /*------------------------------------------------------------------*/
1302 /* Name - mono_arch_cleanup. */
1304 /* Function - Cleanup architecture specific code . */
1306 /*------------------------------------------------------------------*/
1309 mono_arch_cleanup (void)
1311 if (ss_trigger_page)
1312 mono_vfree (ss_trigger_page, mono_pagesize ());
1313 if (bp_trigger_page)
1314 mono_vfree (bp_trigger_page, mono_pagesize ());
1315 mono_mutex_destroy (&mini_arch_mutex);
1318 /*========================= End of Function ========================*/
1320 /*------------------------------------------------------------------*/
1322 /* Name - mono_arch_cpu_optimizations */
1324 /* Function - Returns the optimizations supported on this CPU */
1326 /*------------------------------------------------------------------*/
1329 mono_arch_cpu_optimizations (guint32 *exclude_mask)
1333 /*----------------------------------------------------------*/
1334 /* No s390-specific optimizations yet */
1335 /*----------------------------------------------------------*/
1336 *exclude_mask = MONO_OPT_LINEARS;
1340 /*========================= End of Function ========================*/
1342 /*------------------------------------------------------------------*/
1344 /* Name - mono_arch_cpu_enumerate_simd_versions */
1346 /* Function - Returns the SIMD instruction sets on this CPU */
1348 /*------------------------------------------------------------------*/
1350 mono_arch_cpu_enumerate_simd_versions (void)
1352 /* SIMD is currently unimplemented */
1355 /*========================= End of Function ========================*/
1357 /*------------------------------------------------------------------*/
1359 /* Name - mono_arch_get_allocatable_int_vars */
1363 /*------------------------------------------------------------------*/
1366 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1371 for (i = 0; i < cfg->num_varinfo; i++) {
1372 MonoInst *ins = cfg->varinfo [i];
1373 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1376 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1379 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1380 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1383 /* we can only allocate 32 bit values */
1384 if (mono_is_regsize_var(ins->inst_vtype)) {
1385 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1386 g_assert (i == vmv->idx);
1387 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1394 /*========================= End of Function ========================*/
1396 /*------------------------------------------------------------------*/
1398 /* Name - mono_arch_global_int_regs */
1400 /* Function - Return a list of usable integer registers. */
1402 /*------------------------------------------------------------------*/
1405 mono_arch_get_global_int_regs (MonoCompile *cfg)
1408 MonoMethodHeader *header;
1411 header = cfg->header;
1412 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1413 cfg->frame_reg = s390_r11;
1416 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1418 for (i = 8; i < top; ++i) {
1419 if (cfg->frame_reg != i)
1420 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1426 /*========================= End of Function ========================*/
1428 /*------------------------------------------------------------------*/
1430 /* Name - mono_arch_flush_icache */
1432 /* Function - Flush the CPU icache. */
1434 /*------------------------------------------------------------------*/
1437 mono_arch_flush_icache (guint8 *code, gint size)
1441 /*========================= End of Function ========================*/
1443 /*------------------------------------------------------------------*/
1445 /* Name - add_general */
1447 /* Function - Determine code and stack size incremements for a */
1450 /*------------------------------------------------------------------*/
1453 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1455 if (*gr > S390_LAST_ARG_REG) {
1456 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1457 ainfo->offset = sz->stack_size;
1458 ainfo->reg = STK_BASE;
1459 ainfo->regtype = RegTypeBase;
1460 sz->stack_size += sizeof(long);
1461 sz->local_size += sizeof(long);
1462 sz->offStruct += sizeof(long);
1463 sz->code_size += 12;
1471 /*========================= End of Function ========================*/
1473 /*------------------------------------------------------------------*/
1475 /* Name - add_stackParm */
1477 /* Function - Determine code and stack size incremements for a */
1480 /*------------------------------------------------------------------*/
1483 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1485 if (*gr > S390_LAST_ARG_REG) {
1486 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1487 ainfo->reg = STK_BASE;
1488 ainfo->offset = sz->stack_size;
1489 ainfo->regtype = RegTypeStructByAddrOnStack;
1490 sz->stack_size += sizeof (gpointer);
1491 sz->parm_size += sizeof(gpointer);
1492 sz->offStruct += sizeof(gpointer);
1495 ainfo->offset = sz->stack_size;
1496 ainfo->regtype = RegTypeStructByAddr;
1499 ainfo->offparm = sz->offset;
1500 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1502 ainfo->vtsize = size;
1503 sz->parm_size += size;
1506 /*========================= End of Function ========================*/
1508 /*------------------------------------------------------------------*/
1510 /* Name - add_float */
1512 /* Function - Determine code and stack size incremements for a */
1513 /* float parameter. */
1515 /*------------------------------------------------------------------*/
1518 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1520 if ((*fr) <= S390_LAST_FPARG_REG) {
1521 ainfo->regtype = RegTypeFP;
1527 ainfo->offset = sz->stack_size;
1528 ainfo->reg = STK_BASE;
1529 ainfo->regtype = RegTypeBase;
1531 sz->stack_size += sizeof(double);
1532 sz->local_size += sizeof(double);
1533 sz->offStruct += sizeof(double);
1537 /*========================= End of Function ========================*/
1539 /*------------------------------------------------------------------*/
1541 /* Name - get_call_info */
1543 /* Function - Determine the amount of space required for code */
1544 /* and stack. In addition determine starting points */
1545 /* for stack-based parameters, and area for struct- */
1546 /* ures being returned on the stack. */
1548 /*------------------------------------------------------------------*/
1551 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
1553 guint i, fr, gr, size, pstart;
1554 int nParm = sig->hasthis + sig->param_count;
1556 guint32 simpleType, align;
1557 gboolean is_pinvoke = sig->pinvoke;
1562 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1564 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1569 cinfo->struct_ret = 0;
1573 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1574 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1581 /*----------------------------------------------------------*/
1582 /* We determine the size of the return code/stack in case we*/
1583 /* need to reserve a register to be used to address a stack */
1584 /* area that the callee will use. */
1585 /*----------------------------------------------------------*/
1587 ret_type = mini_get_underlying_type (sig->ret);
1588 simpleType = ret_type->type;
1590 switch (simpleType) {
1591 case MONO_TYPE_BOOLEAN:
1596 case MONO_TYPE_CHAR:
1601 case MONO_TYPE_CLASS:
1602 case MONO_TYPE_OBJECT:
1603 case MONO_TYPE_SZARRAY:
1604 case MONO_TYPE_ARRAY:
1606 case MONO_TYPE_FNPTR:
1607 case MONO_TYPE_STRING:
1608 cinfo->ret.reg = s390_r2;
1613 cinfo->ret.reg = s390_f0;
1618 cinfo->ret.reg = s390_r2;
1621 case MONO_TYPE_GENERICINST:
1622 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1623 cinfo->ret.reg = s390_r2;
1628 case MONO_TYPE_VALUETYPE: {
1629 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1630 if (klass->enumtype) {
1631 simpleType = mono_class_enum_basetype (klass)->type;
1634 size = mini_type_stack_size_full (&klass->byval_arg, NULL, sig->pinvoke);
1636 cinfo->struct_ret = 1;
1637 cinfo->ret.size = size;
1638 cinfo->ret.vtsize = size;
1641 case MONO_TYPE_TYPEDBYREF:
1642 size = sizeof (MonoTypedRef);
1643 cinfo->struct_ret = 1;
1644 cinfo->ret.size = size;
1645 cinfo->ret.vtsize = size;
1647 case MONO_TYPE_VOID:
1650 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1656 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1657 * the first argument, allowing 'this' to be always passed in the first arg reg.
1658 * Also do this if the first argument is a reference type, since virtual calls
1659 * are sometimes made using calli without sig->hasthis set, like in the delegate
1662 if (cinfo->struct_ret && !is_pinvoke &&
1664 (sig->param_count > 0 &&
1665 MONO_TYPE_IS_REFERENCE (mini_get_underlying_type (sig->params [0]))))) {
1667 cinfo->args[nParm].size = sizeof (gpointer);
1668 add_general (&gr, sz, cinfo->args + nParm);
1670 cinfo->args[nParm].size = sizeof (gpointer);
1671 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1675 cinfo->vret_arg_index = 1;
1676 cinfo->ret.reg = gr;
1681 cinfo->args[nParm].size = sizeof (gpointer);
1682 add_general (&gr, sz, cinfo->args + nParm);
1686 if (cinfo->struct_ret) {
1687 cinfo->ret.reg = gr;
1692 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1693 gr = S390_LAST_ARG_REG + 1;
1694 fr = S390_LAST_FPARG_REG + 1;
1696 /* Emit the signature cookie just before the implicit arguments */
1697 add_general (&gr, sz, &cinfo->sigCookie);
1700 /*----------------------------------------------------------*/
1701 /* We determine the size of the parameter code and stack */
1702 /* requirements by checking the types and sizes of the */
1704 /*----------------------------------------------------------*/
1706 for (i = pstart; i < sig->param_count; ++i) {
1709 /*--------------------------------------------------*/
1710 /* Handle vararg type calls. All args are put on */
1712 /*--------------------------------------------------*/
1713 if ((sig->call_convention == MONO_CALL_VARARG) &&
1714 (i == sig->sentinelpos)) {
1715 gr = S390_LAST_ARG_REG + 1;
1716 fr = S390_LAST_FPARG_REG + 1;
1717 add_general (&gr, sz, &cinfo->sigCookie);
1720 if (sig->params [i]->byref) {
1721 add_general (&gr, sz, cinfo->args+nParm);
1722 cinfo->args[nParm].size = sizeof(gpointer);
1727 ptype = mini_get_underlying_type (sig->params [i]);
1728 simpleType = ptype->type;
1729 cinfo->args[nParm].type = simpleType;
1730 switch (simpleType) {
1731 case MONO_TYPE_BOOLEAN:
1734 cinfo->args[nParm].size = sizeof(char);
1735 add_general (&gr, sz, cinfo->args+nParm);
1740 case MONO_TYPE_CHAR:
1741 cinfo->args[nParm].size = sizeof(short);
1742 add_general (&gr, sz, cinfo->args+nParm);
1747 cinfo->args[nParm].size = sizeof(int);
1748 add_general (&gr, sz, cinfo->args+nParm);
1754 case MONO_TYPE_FNPTR:
1755 case MONO_TYPE_CLASS:
1756 case MONO_TYPE_OBJECT:
1757 case MONO_TYPE_STRING:
1758 case MONO_TYPE_SZARRAY:
1759 case MONO_TYPE_ARRAY:
1760 cinfo->args[nParm].size = sizeof(gpointer);
1761 add_general (&gr, sz, cinfo->args+nParm);
1766 cinfo->args[nParm].size = sizeof(long long);
1767 add_general (&gr, sz, cinfo->args+nParm);
1771 cinfo->args[nParm].size = sizeof(float);
1772 add_float (&fr, sz, cinfo->args+nParm);
1776 cinfo->args[nParm].size = sizeof(double);
1777 add_float (&fr, sz, cinfo->args+nParm);
1780 case MONO_TYPE_GENERICINST:
1781 if (!mono_type_generic_inst_is_valuetype (ptype)) {
1782 cinfo->args[nParm].size = sizeof(gpointer);
1783 add_general (&gr, sz, cinfo->args+nParm);
1788 case MONO_TYPE_VALUETYPE: {
1789 MonoMarshalType *info;
1790 MonoClass *klass = mono_class_from_mono_type (ptype);
1793 size = mono_class_native_size(klass, NULL);
1795 size = mono_class_value_size(klass, NULL);
1797 if (simpleType != MONO_TYPE_GENERICINST) {
1798 info = mono_marshal_load_type_info(klass);
1800 if ((info->native_size == sizeof(float)) &&
1801 (info->num_fields == 1) &&
1802 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1803 cinfo->args[nParm].size = sizeof(float);
1804 add_float(&fr, sz, cinfo->args+nParm);
1809 if ((info->native_size == sizeof(double)) &&
1810 (info->num_fields == 1) &&
1811 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1812 cinfo->args[nParm].size = sizeof(double);
1813 add_float(&fr, sz, cinfo->args+nParm);
1819 cinfo->args[nParm].vtsize = 0;
1820 cinfo->args[nParm].size = 0;
1823 /*----------------------------------*/
1824 /* On S/390, structures of size 1, */
1825 /* 2, 4, and 8 bytes are passed in */
1826 /* (a) register(s). */
1827 /*----------------------------------*/
1833 add_general(&gr, sz, cinfo->args+nParm);
1834 cinfo->args[nParm].size = size;
1835 cinfo->args[nParm].regtype = RegTypeStructByVal;
1837 sz->local_size += sizeof(long);
1840 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1845 case MONO_TYPE_TYPEDBYREF: {
1846 int size = sizeof (MonoTypedRef);
1848 cinfo->args[nParm].vtsize = 0;
1849 cinfo->args[nParm].size = 0;
1852 /*----------------------------------*/
1853 /* On S/390, structures of size 1, */
1854 /* 2, 4, and 8 bytes are passed in */
1855 /* (a) register(s). */
1856 /*----------------------------------*/
1862 add_general(&gr, sz, cinfo->args+nParm);
1863 cinfo->args[nParm].size = size;
1864 cinfo->args[nParm].regtype = RegTypeStructByVal;
1866 sz->local_size += sizeof(long);
1869 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1875 g_error ("Can't trampoline 0x%x", ptype);
1879 /*----------------------------------------------------------*/
1880 /* Handle the case where there are no implicit arguments */
1881 /*----------------------------------------------------------*/
1882 if ((sig->call_convention == MONO_CALL_VARARG) &&
1885 (sig->param_count == sig->sentinelpos)) {
1886 gr = S390_LAST_ARG_REG + 1;
1887 fr = S390_LAST_FPARG_REG + 1;
1888 add_general (&gr, sz, &cinfo->sigCookie);
1891 /*----------------------------------------------------------*/
1892 /* If we are passing a structure back then if it won't be */
1893 /* in a register(s) then we make room at the end of the */
1894 /* parameters that may have been placed on the stack */
1895 /*----------------------------------------------------------*/
1896 if (cinfo->struct_ret) {
1897 cinfo->ret.offset = sz->stack_size;
1898 switch (cinfo->ret.size) {
1906 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1911 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1913 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1918 /*========================= End of Function ========================*/
1920 /*------------------------------------------------------------------*/
1922 /* Name - mono_arch_allocate_vars */
1924 /* Function - Set var information according to the calling */
1925 /* convention for S/390. The local var stuff should */
1926 /* most likely be split in another method. */
1928 /* Parameter - @m - Compile unit. */
1930 /*------------------------------------------------------------------*/
1933 mono_arch_allocate_vars (MonoCompile *cfg)
1935 MonoMethodSignature *sig;
1936 MonoMethodHeader *header;
1939 int iParm, iVar, offset, align, size, curinst;
1940 int frame_reg = STK_BASE;
1943 header = cfg->header;
1945 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1947 /*---------------------------------------------------------*/
1948 /* We use the frame register also for any method that has */
1949 /* filter clauses. This way, when the handlers are called, */
1950 /* the code will reference local variables using the frame */
1951 /* reg instead of the stack pointer: if we had to restore */
1952 /* the stack pointer, we'd corrupt the method frames that */
1953 /* are already on the stack (since filters get called */
1954 /* before stack unwinding happens) when the filter code */
1955 /* would call any method. */
1956 /*---------------------------------------------------------*/
1957 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1958 frame_reg = s390_r11;
1960 cfg->frame_reg = frame_reg;
1962 cfg->arch.bkchain_reg = -1;
1964 if (frame_reg != STK_BASE)
1965 cfg->used_int_regs |= (1 << frame_reg);
1967 if (cfg->uses_rgctx_reg)
1968 cfg->used_int_regs |= (1 << MONO_ARCH_IMT_REG);
1970 sig = mono_method_signature (cfg->method);
1972 cinfo = get_call_info (cfg, cfg->mempool, sig);
1974 if (!cinfo->struct_ret) {
1975 switch (mini_get_underlying_type (sig->ret)->type) {
1976 case MONO_TYPE_VOID:
1979 cfg->ret->opcode = OP_REGVAR;
1980 cfg->ret->dreg = s390_r2;
1985 /*--------------------------------------------------------------*/
1986 /* local vars are at a positive offset from the stack pointer */
1987 /* also note that if the function uses alloca, we use s390_r11 */
1988 /* to point at the local variables. */
1989 /* add parameter area size for called functions */
1990 /*--------------------------------------------------------------*/
1991 if (cfg->param_area == 0)
1992 offset = S390_MINIMAL_STACK_SIZE;
1994 offset = cfg->param_area;
1996 cfg->sig_cookie = 0;
1998 if (cinfo->struct_ret) {
1999 inst = cfg->vret_addr;
2000 offset = S390_ALIGN(offset, sizeof(gpointer));
2001 inst->inst_offset = offset;
2002 inst->opcode = OP_REGOFFSET;
2003 inst->inst_basereg = frame_reg;
2004 offset += sizeof(gpointer);
2005 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2006 printf ("vret_addr =");
2007 mono_print_ins (cfg->vret_addr);
2012 inst = cfg->args [0];
2013 if (inst->opcode != OP_REGVAR) {
2014 inst->opcode = OP_REGOFFSET;
2015 inst->inst_basereg = frame_reg;
2016 offset = S390_ALIGN(offset, sizeof(gpointer));
2017 inst->inst_offset = offset;
2018 offset += sizeof (gpointer);
2025 eArg = sig->param_count + sArg;
2027 if (sig->call_convention == MONO_CALL_VARARG)
2028 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2030 for (iParm = sArg; iParm < eArg; ++iParm) {
2031 inst = cfg->args [curinst];
2032 if (inst->opcode != OP_REGVAR) {
2033 switch (cinfo->args[iParm].regtype) {
2034 case RegTypeStructByAddr : {
2037 size = sizeof (gpointer);
2039 inst->opcode = OP_REGOFFSET;
2040 inst->inst_basereg = frame_reg;
2041 offset = S390_ALIGN (offset, sizeof (gpointer));
2042 inst->inst_offset = offset;
2044 /* Add a level of indirection */
2045 MONO_INST_NEW (cfg, indir, 0);
2047 inst->opcode = OP_VTARG_ADDR;
2048 inst->inst_left = indir;
2051 case RegTypeStructByAddrOnStack : {
2054 size = sizeof (gpointer);
2056 /* Similar to the == STK_BASE case below */
2057 cfg->arch.bkchain_reg = s390_r12;
2058 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2060 inst->opcode = OP_REGOFFSET;
2061 inst->dreg = mono_alloc_preg (cfg);
2062 inst->inst_basereg = cfg->arch.bkchain_reg;
2063 inst->inst_offset = cinfo->args [iParm].offset;
2065 /* Add a level of indirection */
2066 MONO_INST_NEW (cfg, indir, 0);
2068 inst->opcode = OP_VTARG_ADDR;
2069 inst->inst_left = indir;
2072 case RegTypeStructByVal :
2073 size = cinfo->args[iParm].size;
2074 offset = S390_ALIGN(offset, size);
2075 inst->opcode = OP_REGOFFSET;
2076 inst->inst_basereg = frame_reg;
2077 inst->inst_offset = offset;
2080 if (cinfo->args [iParm].reg == STK_BASE) {
2082 * These arguments are in the previous frame, so we can't
2083 * compute their offset from the current frame pointer right
2084 * now, since cfg->stack_offset is not yet known, so dedicate a
2085 * register holding the previous frame pointer.
2087 cfg->arch.bkchain_reg = s390_r12;
2088 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2090 inst->opcode = OP_REGOFFSET;
2091 inst->inst_basereg = cfg->arch.bkchain_reg;
2092 size = (cinfo->args[iParm].size < 8
2093 ? 8 - cinfo->args[iParm].size
2095 inst->inst_offset = cinfo->args [iParm].offset + size;
2096 size = sizeof (long);
2098 inst->opcode = OP_REGOFFSET;
2099 inst->inst_basereg = frame_reg;
2100 size = (cinfo->args[iParm].size < 8
2103 offset = S390_ALIGN(offset, size);
2104 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2105 inst->inst_offset = offset;
2107 inst->inst_offset = offset + (8 - size);
2112 if ((sig->call_convention == MONO_CALL_VARARG) &&
2113 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2114 (iParm < sig->sentinelpos))
2115 cfg->sig_cookie += size;
2116 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2119 offset += MAX(size, 8);
2124 cfg->locals_min_stack_offset = offset;
2126 curinst = cfg->locals_start;
2127 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2128 inst = cfg->varinfo [iVar];
2129 if ((inst->flags & MONO_INST_IS_DEAD) ||
2130 (inst->opcode == OP_REGVAR))
2133 /*--------------------------------------------------*/
2134 /* inst->backend.is_pinvoke indicates native sized */
2135 /* value typs this is used by the pinvoke wrappers */
2136 /* when they call functions returning structure */
2137 /*--------------------------------------------------*/
2138 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2139 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2140 (guint32 *) &align);
2142 size = mono_type_size (inst->inst_vtype, &align);
2144 offset = S390_ALIGN(offset, align);
2145 inst->inst_offset = offset;
2146 inst->opcode = OP_REGOFFSET;
2147 inst->inst_basereg = frame_reg;
2149 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2150 iVar, inst->inst_offset, size));
2153 cfg->locals_max_stack_offset = offset;
2155 /*------------------------------------------------------*/
2156 /* Allow space for the trace method stack area if needed*/
2157 /*------------------------------------------------------*/
2158 if ((mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2159 || (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE))
2160 offset += S390_TRACE_STACK_SIZE;
2162 /*------------------------------------------------------*/
2163 /* Reserve space to save LMF and caller saved registers */
2164 /*------------------------------------------------------*/
2165 if (cfg->method->save_lmf)
2166 offset += sizeof (MonoLMF);
2168 /*------------------------------------------------------*/
2169 /* align the offset */
2170 /*------------------------------------------------------*/
2171 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2173 /*------------------------------------------------------*/
2174 /* Fix offsets for args whose value is in parent frame */
2175 /*------------------------------------------------------*/
2176 for (iParm = sArg; iParm < eArg; ++iParm) {
2177 inst = cfg->args [iParm];
2179 if (inst->opcode == OP_S390_STKARG) {
2180 inst->opcode = OP_REGOFFSET;
2181 inst->inst_offset += cfg->stack_offset;
2186 /*========================= End of Function ========================*/
2188 /*------------------------------------------------------------------*/
2190 /* Name - mono_arch_create_vars */
2192 /*------------------------------------------------------------------*/
2195 mono_arch_create_vars (MonoCompile *cfg)
2197 MonoMethodSignature *sig;
2200 sig = mono_method_signature (cfg->method);
2202 cinfo = get_call_info (cfg, cfg->mempool, sig);
2204 if (cinfo->struct_ret) {
2205 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2206 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2207 printf ("vret_addr = ");
2208 mono_print_ins (cfg->vret_addr);
2213 /*========================= End of Function ========================*/
2215 /*------------------------------------------------------------------*/
2217 /* Name - add_outarg_reg2. */
2219 /*------------------------------------------------------------------*/
2222 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2227 case RegTypeGeneral:
2228 MONO_INST_NEW (cfg, ins, OP_MOVE);
2229 ins->dreg = mono_alloc_ireg (cfg);
2230 ins->sreg1 = tree->dreg;
2231 MONO_ADD_INS (cfg->cbb, ins);
2232 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2235 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2236 ins->dreg = mono_alloc_freg (cfg);
2237 ins->sreg1 = tree->dreg;
2238 MONO_ADD_INS (cfg->cbb, ins);
2239 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2242 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2243 ins->dreg = mono_alloc_freg (cfg);
2244 ins->sreg1 = tree->dreg;
2245 MONO_ADD_INS (cfg->cbb, ins);
2246 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2249 g_assert_not_reached ();
2253 /*========================= End of Function ========================*/
2255 /*------------------------------------------------------------------*/
2257 /* Name - emit_sig_cookie. */
2259 /*------------------------------------------------------------------*/
2262 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2264 MonoMethodSignature *tmpSig;
2267 cfg->disable_aot = TRUE;
2269 /*----------------------------------------------------------*/
2270 /* mono_ArgIterator_Setup assumes the signature cookie is */
2271 /* passed first and all the arguments which were before it */
2272 /* passed on the stack after the signature. So compensate */
2273 /* by passing a different signature. */
2274 /*----------------------------------------------------------*/
2275 tmpSig = mono_metadata_signature_dup (call->signature);
2276 tmpSig->param_count -= call->signature->sentinelpos;
2277 tmpSig->sentinelpos = 0;
2278 if (tmpSig->param_count > 0)
2279 memcpy (tmpSig->params,
2280 call->signature->params + call->signature->sentinelpos,
2281 tmpSig->param_count * sizeof(MonoType *));
2283 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2284 sig_arg->dreg = mono_alloc_ireg (cfg);
2285 sig_arg->inst_p0 = tmpSig;
2286 MONO_ADD_INS (cfg->cbb, sig_arg);
2288 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2289 cinfo->sigCookie.offset, sig_arg->dreg);
2292 /*========================= End of Function ========================*/
2294 /*------------------------------------------------------------------*/
2296 /* Name - mono_arch_emit_call */
2298 /*------------------------------------------------------------------*/
2301 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2304 MonoMethodSignature *sig;
2306 int i, n, lParamArea;
2308 ArgInfo *ainfo = NULL;
2310 MonoMethodHeader *header;
2313 sig = call->signature;
2314 n = sig->param_count + sig->hasthis;
2315 DEBUG (g_print ("Call requires: %d parameters\n",n));
2317 cinfo = get_call_info (cfg, cfg->mempool, sig);
2319 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2320 cinfo->sz.parm_size + cinfo->sz.offset;
2321 call->stack_usage = MAX(stackSize, call->stack_usage);
2322 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2323 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2324 cfg->flags |= MONO_CFG_HAS_CALLS;
2326 if (cinfo->struct_ret) {
2327 MONO_INST_NEW (cfg, ins, OP_MOVE);
2328 ins->sreg1 = call->vret_var->dreg;
2329 ins->dreg = mono_alloc_preg (cfg);
2330 MONO_ADD_INS (cfg->cbb, ins);
2331 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2334 header = cfg->header;
2335 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2340 for (i = 0; i < n; ++i) {
2343 ainfo = cinfo->args + i;
2344 if (i >= sig->hasthis)
2345 t = sig->params [i - sig->hasthis];
2347 t = &mono_defaults.int_class->byval_arg;
2348 t = mini_get_underlying_type (t);
2350 in = call->args [i];
2352 if ((sig->call_convention == MONO_CALL_VARARG) &&
2354 (i == sig->sentinelpos)) {
2355 emit_sig_cookie (cfg, call, cinfo);
2358 switch (ainfo->regtype) {
2359 case RegTypeGeneral:
2360 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2363 if (MONO_TYPE_ISSTRUCT (t)) {
2364 /* Valuetype passed in one fp register */
2365 ainfo->regtype = RegTypeStructByValInFP;
2368 if (ainfo->size == 4)
2369 ainfo->regtype = RegTypeFPR4;
2370 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2373 case RegTypeStructByVal:
2374 case RegTypeStructByAddr:
2375 case RegTypeStructByAddrOnStack: {
2379 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2380 size = sizeof (MonoTypedRef);
2381 align = sizeof (gpointer);
2385 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2388 * Other backends use mono_type_stack_size (), but that
2389 * aligns the size to 8, which is larger than the size of
2390 * the source, leading to reads of invalid memory if the
2391 * source is at the end of address space.
2393 size = mono_class_value_size (in->klass, &align);
2396 g_assert (in->klass);
2398 ainfo->offparm += cinfo->sz.offStruct;
2400 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2401 ins->sreg1 = in->dreg;
2402 ins->klass = in->klass;
2403 ins->backend.size = ainfo->size;
2404 ins->inst_p0 = call;
2405 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2406 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2408 MONO_ADD_INS (cfg->cbb, ins);
2410 if (ainfo->regtype == RegTypeStructByAddr) {
2412 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2413 * use the normal OUTARG opcodes to pass the address of the location to
2416 int treg = mono_alloc_preg (cfg);
2417 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2418 frmReg, ainfo->offparm);
2419 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2420 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2421 /* The address of the valuetype is passed on the stack */
2422 int treg = mono_alloc_preg (cfg);
2423 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2424 frmReg, ainfo->offparm);
2425 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2426 ainfo->reg, ainfo->offset, treg);
2428 if (cfg->compute_gc_maps) {
2431 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2437 if (!t->byref && t->type == MONO_TYPE_R4) {
2438 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2439 STK_BASE, ainfo->offset + 4,
2441 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2442 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2443 STK_BASE, ainfo->offset,
2446 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2447 ins->inst_destbasereg = STK_BASE;
2448 ins->inst_offset = ainfo->offset;
2449 ins->sreg1 = in->dreg;
2452 /* This is needed by MonoTypedRef->value to point to the correct data */
2453 if ((sig->call_convention == MONO_CALL_VARARG) &&
2454 (i >= sig->sentinelpos)) {
2455 switch (ainfo->size) {
2457 ins->opcode = OP_STOREI1_MEMBASE_REG;
2460 ins->opcode = OP_STOREI2_MEMBASE_REG;
2463 ins->opcode = OP_STOREI4_MEMBASE_REG;
2471 MONO_ADD_INS (cfg->cbb, ins);
2475 g_assert_not_reached ();
2481 * Handle the case where there are no implicit arguments
2483 if ((sig->call_convention == MONO_CALL_VARARG) &&
2485 (i == sig->sentinelpos)) {
2486 emit_sig_cookie (cfg, call, cinfo);
2490 /*========================= End of Function ========================*/
2492 /*------------------------------------------------------------------*/
2494 /* Name - mono_arch_emit_outarg_vt */
2496 /*------------------------------------------------------------------*/
2499 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2501 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2502 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2503 int size = ins->backend.size;
2505 if (ainfo->regtype == RegTypeStructByVal) {
2507 arg->ins.sreg1 = ainfo->reg;
2508 arg->ins.opcode = OP_OUTARG_VT;
2509 arg->size = ainfo->size;
2510 arg->offset = ainfo->offset;
2511 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2513 if (ainfo->reg != STK_BASE) {
2514 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2516 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2519 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2520 int dreg = mono_alloc_freg (cfg);
2522 if (ainfo->size == 4) {
2523 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2524 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2526 g_assert (ainfo->size == 8);
2528 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2531 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2533 MonoMethodHeader *header;
2536 header = mono_method_get_header (cfg->method);
2537 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2542 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2543 src->dreg, 0, size);
2545 if (cfg->compute_gc_maps) {
2548 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2553 /*========================= End of Function ========================*/
2555 /*------------------------------------------------------------------*/
2557 /* Name - mono_arch_emit_setret */
2559 /*------------------------------------------------------------------*/
2562 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2564 MonoType *ret = mini_get_underlying_type (mono_method_signature (method)->ret);
2567 if (ret->type == MONO_TYPE_R4) {
2568 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2570 } else if (ret->type == MONO_TYPE_R8) {
2571 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2576 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2579 /*========================= End of Function ========================*/
2581 /*------------------------------------------------------------------*/
2583 /* Name - mono_arch_instrument_mem_needs */
2585 /* Function - Allow tracing to work with this interface (with */
2586 /* an optional argument). */
2588 /*------------------------------------------------------------------*/
2591 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2593 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2595 /* split prolog-epilog requirements? */
2596 *code = 50; /* max bytes needed: check this number */
2599 /*========================= End of Function ========================*/
2601 /*------------------------------------------------------------------*/
2603 /* Name - mono_arch_instrument_prolog */
2605 /* Function - Create an "instrumented" prolog. */
2607 /*------------------------------------------------------------------*/
2610 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2611 gboolean enable_arguments)
2618 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2619 if (cfg->method->save_lmf)
2620 parmOffset -= sizeof(MonoLMF);
2621 fpOffset = parmOffset + (5*sizeof(gpointer));
2624 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2625 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2626 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2627 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2628 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2629 S390_SET (code, s390_r1, func);
2630 S390_SET (code, s390_r2, cfg->method);
2631 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2632 s390_lgr (code, s390_r4, STK_BASE);
2633 s390_aghi (code, s390_r4, cfg->stack_usage);
2634 s390_basr (code, s390_r14, s390_r1);
2635 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2636 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2637 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2638 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2639 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2644 /*========================= End of Function ========================*/
2646 /*------------------------------------------------------------------*/
2648 /* Name - mono_arch_instrument_epilog */
2650 /* Function - Create an epilog that will handle the returned */
2651 /* values used in instrumentation. */
2653 /*------------------------------------------------------------------*/
2656 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2659 int save_mode = SAVE_NONE,
2662 MonoMethod *method = cfg->method;
2663 int rtype = mini_get_underlying_type (mono_method_signature (method)->ret)->type;
2665 offset = code - cfg->native_code;
2666 /*-----------------------------------------*/
2667 /* We need about 128 bytes of instructions */
2668 /*-----------------------------------------*/
2669 if (offset > (cfg->code_size - 128)) {
2670 cfg->code_size *= 2;
2671 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2672 code = cfg->native_code + offset;
2675 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2676 if (method->save_lmf)
2677 saveOffset -= sizeof(MonoLMF);
2681 case MONO_TYPE_VOID:
2682 /* special case string .ctor icall */
2683 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2684 save_mode = SAVE_ONE;
2686 save_mode = SAVE_NONE;
2690 save_mode = SAVE_ONE;
2693 save_mode = SAVE_R4;
2696 save_mode = SAVE_R8;
2698 case MONO_TYPE_VALUETYPE:
2699 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2700 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2703 save_mode = SAVE_STRUCT;
2706 save_mode = SAVE_ONE;
2710 switch (save_mode) {
2712 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2713 if (enable_arguments) {
2714 s390_lgr (code, s390_r3, s390_r2);
2718 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2719 if (enable_arguments) {
2720 s390_ldebr (code, s390_f0, s390_f0);
2724 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2727 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2728 if (enable_arguments) {
2729 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2730 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2738 S390_SET (code, s390_r1, func);
2739 S390_SET (code, s390_r2, cfg->method);
2740 s390_basr (code, s390_r14, s390_r1);
2742 switch (save_mode) {
2744 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2748 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2751 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2761 /*========================= End of Function ========================*/
2763 /*------------------------------------------------------------------*/
2765 /* Name - mono_arch_peephole_pass_1 */
2767 /* Function - Form a peephole pass at the code looking for */
2768 /* simple optimizations. */
2770 /*------------------------------------------------------------------*/
2773 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2777 /*========================= End of Function ========================*/
2779 /*------------------------------------------------------------------*/
2781 /* Name - mono_arch_peephole_pass_2 */
2783 /* Function - Form a peephole pass at the code looking for */
2784 /* simple optimizations. */
2786 /*------------------------------------------------------------------*/
2789 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2793 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2794 mono_peephole_ins (bb, ins);
2798 /*========================= End of Function ========================*/
2800 /*------------------------------------------------------------------*/
2802 /* Name - mono_arch_lowering_pass. */
2804 /*------------------------------------------------------------------*/
2807 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2809 MonoInst *ins, *next;
2811 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2812 switch (ins->opcode) {
2817 case OP_IDIV_UN_IMM:
2818 case OP_IREM_UN_IMM:
2823 case OP_LOCALLOC_IMM:
2824 mono_decompose_op_imm (cfg, bb, ins);
2827 if (!s390_is_imm16 (ins->inst_imm))
2828 /* This is created by the memcpy code which ignores is_inst_imm */
2829 mono_decompose_op_imm (cfg, bb, ins);
2836 bb->max_vreg = cfg->next_vreg;
2839 /*========================= End of Function ========================*/
2841 /*------------------------------------------------------------------*/
2843 /* Name - emit_float_to_int */
2845 /* Function - Create instructions which will convert a floating */
2846 /* point value to integer. */
2848 /*------------------------------------------------------------------*/
2851 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2853 /* sreg is a float, dreg is an integer reg. */
2855 s390_cgdbr (code, dreg, 5, sreg);
2858 s390_ltgr (code, dreg, dreg);
2860 s390_oill (code, dreg, 0x80);
2861 s390_lghi (code, s390_r0, 0xff);
2862 s390_ngr (code, dreg, s390_r0);
2865 s390_ltgr (code, dreg, dreg);
2867 s390_oill (code, dreg, 0x8000);
2868 s390_llill(code, s390_r0, 0xffff);
2869 s390_ngr (code, dreg, s390_r0);
2874 S390_SET (code, s390_r13, 0x41e0000000000000llu);
2875 s390_ldgr (code, s390_f14, s390_r13);
2876 s390_ldr (code, s390_f15, sreg);
2877 s390_cdbr (code, s390_f15, s390_f14);
2878 s390_jl (code, 0); CODEPTR (code, o[0]);
2879 S390_SET (code, s390_r13, 0x41f0000000000000llu);
2880 s390_ldgr (code, s390_f14, s390_r13);
2881 s390_sdbr (code, s390_f15, s390_f14);
2882 s390_cfdbr (code, dreg, 7, s390_f15);
2884 PTRSLOT (code, o[0]);
2885 s390_cfdbr (code, dreg, 5, sreg);
2888 s390_lghi (code, s390_r0, 0xff);
2889 s390_ngr (code, dreg, s390_r0);
2892 s390_llill(code, s390_r0, 0xffff);
2893 s390_ngr (code, dreg, s390_r0);
2900 /*========================= End of Function ========================*/
2902 /*------------------------------------------------------------------*/
2904 /* Name - gboolean_is_unsigned. */
2906 /* Function - Return TRUE if next opcode is checking for un- */
2909 /*------------------------------------------------------------------*/
2912 gboolean is_unsigned (MonoInst *next)
2915 (((next->opcode >= OP_IBNE_UN) &&
2916 (next->opcode <= OP_IBLT_UN)) ||
2917 ((next->opcode >= OP_LBNE_UN) &&
2918 (next->opcode <= OP_LBLT_UN)) ||
2919 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2920 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2921 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2922 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2923 ((next->opcode == OP_CLT_UN) ||
2924 (next->opcode == OP_CGT_UN)) ||
2925 ((next->opcode == OP_ICLT_UN) ||
2926 (next->opcode == OP_ICGT_UN) ||
2927 (next->opcode == OP_LCLT_UN) ||
2928 (next->opcode == OP_LCGT_UN))))
2934 /*========================= End of Function ========================*/
2936 /*------------------------------------------------------------------*/
2938 /* Name - mono_arch_output_basic_block */
2940 /* Function - Perform the "real" work of emitting instructions */
2941 /* that will do the work of in the basic block. */
2943 /*------------------------------------------------------------------*/
2946 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2951 guint8 *code = cfg->native_code + cfg->code_len;
2952 guint last_offset = 0;
2955 /* we don't align basic blocks of loops on s390 */
2957 if (cfg->verbose_level > 2)
2958 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2960 if ((cfg->prof_options & MONO_PROFILE_COVERAGE) && cfg->coverage_info) {
2961 MonoProfileCoverageInfo *cov = cfg->coverage_info;
2962 g_assert (!mono_compile_aot);
2963 cov->data [bb->dfn].cil_code = bb->cil_code;
2964 /* This is not thread save, but good enough */
2965 S390_SET (code, s390_r1, &cov->data [bb->dfn].count);
2966 s390_alsi (code, 0, s390_r1, 1);
2969 MONO_BB_FOR_EACH_INS (bb, ins) {
2970 offset = code - cfg->native_code;
2972 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2974 if (offset > (cfg->code_size - max_len - 16)) {
2975 cfg->code_size *= 2;
2976 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2977 code = cfg->native_code + offset;
2980 mono_debug_record_line_number (cfg, ins, offset);
2982 switch (ins->opcode) {
2983 case OP_STOREI1_MEMBASE_IMM: {
2984 s390_lghi (code, s390_r0, ins->inst_imm);
2985 S390_LONG (code, stcy, stc, s390_r0, 0,
2986 ins->inst_destbasereg, ins->inst_offset);
2989 case OP_STOREI2_MEMBASE_IMM: {
2990 s390_lghi (code, s390_r0, ins->inst_imm);
2991 S390_LONG (code, sthy, sth, s390_r0, 0,
2992 ins->inst_destbasereg, ins->inst_offset);
2995 case OP_STOREI4_MEMBASE_IMM: {
2996 s390_lgfi (code, s390_r0, ins->inst_imm);
2997 S390_LONG (code, sty, st, s390_r0, 0,
2998 ins->inst_destbasereg, ins->inst_offset);
3001 case OP_STORE_MEMBASE_IMM:
3002 case OP_STOREI8_MEMBASE_IMM: {
3003 S390_SET (code, s390_r0, ins->inst_imm);
3004 S390_LONG (code, stg, stg, s390_r0, 0,
3005 ins->inst_destbasereg, ins->inst_offset);
3008 case OP_STOREI1_MEMBASE_REG: {
3009 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3010 ins->inst_destbasereg, ins->inst_offset);
3013 case OP_STOREI2_MEMBASE_REG: {
3014 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3015 ins->inst_destbasereg, ins->inst_offset);
3018 case OP_STOREI4_MEMBASE_REG: {
3019 S390_LONG (code, sty, st, ins->sreg1, 0,
3020 ins->inst_destbasereg, ins->inst_offset);
3023 case OP_STORE_MEMBASE_REG:
3024 case OP_STOREI8_MEMBASE_REG: {
3025 S390_LONG (code, stg, stg, ins->sreg1, 0,
3026 ins->inst_destbasereg, ins->inst_offset);
3030 g_assert_not_reached ();
3032 case OP_LOAD_MEMBASE:
3033 case OP_LOADI8_MEMBASE: {
3034 S390_LONG (code, lg, lg, ins->dreg, 0,
3035 ins->inst_basereg, ins->inst_offset);
3038 case OP_LOADI4_MEMBASE: {
3039 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3040 ins->inst_basereg, ins->inst_offset);
3043 case OP_LOADU4_MEMBASE: {
3044 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3045 ins->inst_basereg, ins->inst_offset);
3048 case OP_LOADU1_MEMBASE: {
3049 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3050 ins->inst_basereg, ins->inst_offset);
3053 case OP_LOADI1_MEMBASE: {
3054 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3055 ins->inst_basereg, ins->inst_offset);
3058 case OP_LOADU2_MEMBASE: {
3059 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3060 ins->inst_basereg, ins->inst_offset);
3063 case OP_LOADI2_MEMBASE: {
3064 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3065 ins->inst_basereg, ins->inst_offset);
3068 case OP_LCONV_TO_I1: {
3069 s390_lgbr (code, ins->dreg, ins->sreg1);
3072 case OP_LCONV_TO_I2: {
3073 s390_lghr (code, ins->dreg, ins->sreg1);
3076 case OP_LCONV_TO_U1: {
3077 s390_llgcr (code, ins->dreg, ins->sreg1);
3080 case OP_LCONV_TO_U2: {
3081 s390_llghr (code, ins->dreg, ins->sreg1);
3084 case OP_ICONV_TO_I1: {
3085 s390_lgbr (code, ins->dreg, ins->sreg1);
3088 case OP_ICONV_TO_I2: {
3089 s390_lghr (code, ins->dreg, ins->sreg1);
3092 case OP_ICONV_TO_U1: {
3093 s390_llgcr (code, ins->dreg, ins->sreg1);
3096 case OP_ICONV_TO_U2: {
3097 s390_llghr (code, ins->dreg, ins->sreg1);
3102 if (is_unsigned (ins->next))
3103 s390_clgr (code, ins->sreg1, ins->sreg2);
3105 s390_cgr (code, ins->sreg1, ins->sreg2);
3109 if (is_unsigned (ins->next))
3110 s390_clr (code, ins->sreg1, ins->sreg2);
3112 s390_cr (code, ins->sreg1, ins->sreg2);
3115 case OP_COMPARE_IMM:
3116 case OP_LCOMPARE_IMM: {
3117 S390_SET (code, s390_r0, ins->inst_imm);
3118 if (is_unsigned (ins->next))
3119 s390_clgr (code, ins->sreg1, s390_r0);
3121 s390_cgr (code, ins->sreg1, s390_r0);
3124 case OP_ICOMPARE_IMM: {
3125 S390_SET (code, s390_r0, ins->inst_imm);
3126 if (is_unsigned (ins->next))
3127 s390_clr (code, ins->sreg1, s390_r0);
3129 s390_cr (code, ins->sreg1, s390_r0);
3133 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3135 S390_CALL_TEMPLATE (code, s390_r14);
3140 s390_agr (code, ins->dreg, src2);
3145 s390_agr (code, ins->dreg, src2);
3150 s390_alcgr (code, ins->dreg, src2);
3154 if (ins->dreg != ins->sreg1) {
3155 s390_lgr (code, ins->dreg, ins->sreg1);
3157 if (s390_is_imm16 (ins->inst_imm)) {
3158 s390_aghi (code, ins->dreg, ins->inst_imm);
3159 } else if (s390_is_imm32 (ins->inst_imm)) {
3160 s390_agfi (code, ins->dreg, ins->inst_imm);
3162 S390_SET (code, s390_r0, ins->inst_imm);
3163 s390_agr (code, ins->dreg, s390_r0);
3168 if (ins->dreg != ins->sreg1) {
3169 s390_lgr (code, ins->dreg, ins->sreg1);
3171 g_assert (s390_is_imm16 (ins->inst_imm));
3172 s390_aghi (code, ins->dreg, ins->inst_imm);
3176 if (ins->dreg != ins->sreg1) {
3177 s390_lgr (code, ins->dreg, ins->sreg1);
3179 if (s390_is_imm16 (ins->inst_imm)) {
3180 s390_lghi (code, s390_r0, ins->inst_imm);
3181 s390_alcgr (code, ins->dreg, s390_r0);
3183 S390_SET (code, s390_r0, ins->inst_imm);
3184 s390_alcgr (code, ins->dreg, s390_r0);
3189 case OP_S390_IADD_OVF: {
3191 s390_ar (code, ins->dreg, src2);
3192 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3193 s390_lgfr (code, ins->dreg, ins->dreg);
3196 case OP_IADD_OVF_UN:
3197 case OP_S390_IADD_OVF_UN: {
3199 s390_algr (code, ins->dreg, src2);
3200 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3201 s390_llgfr (code, ins->dreg, ins->dreg);
3204 case OP_ADD_OVF_CARRY: {
3206 s390_lghi (code, s390_r0, 0);
3207 s390_lgr (code, s390_r1, s390_r0);
3208 s390_alcgr (code, s390_r0, s390_r1);
3209 s390_agr (code, ins->dreg, src2);
3210 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3211 s390_agr (code, ins->dreg, s390_r0);
3212 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3215 case OP_ADD_OVF_UN_CARRY: {
3217 s390_alcgr (code, ins->dreg, src2);
3218 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3223 s390_sgr (code, ins->dreg, src2);
3228 s390_sgr (code, ins->dreg, src2);
3233 s390_slbgr(code, ins->dreg, src2);
3237 if (ins->dreg != ins->sreg1) {
3238 s390_lgr (code, ins->dreg, ins->sreg1);
3240 if (s390_is_imm16 (-ins->inst_imm)) {
3241 s390_aghi (code, ins->dreg, -ins->inst_imm);
3242 } else if (s390_is_imm32 (-ins->inst_imm)) {
3243 s390_slgfi (code, ins->dreg, ins->inst_imm);
3245 S390_SET (code, s390_r0, ins->inst_imm);
3246 s390_slgr (code, ins->dreg, s390_r0);
3251 if (ins->dreg != ins->sreg1) {
3252 s390_lgr (code, ins->dreg, ins->sreg1);
3254 if (s390_is_imm16 (-ins->inst_imm)) {
3255 s390_aghi (code, ins->dreg, -ins->inst_imm);
3256 } else if (s390_is_imm32 (-ins->inst_imm)) {
3257 s390_slgfi (code, ins->dreg, ins->inst_imm);
3259 S390_SET (code, s390_r0, ins->inst_imm);
3260 s390_slgr (code, ins->dreg, s390_r0);
3265 if (ins->dreg != ins->sreg1) {
3266 s390_lgr (code, ins->dreg, ins->sreg1);
3268 if (s390_is_imm16 (-ins->inst_imm)) {
3269 s390_lghi (code, s390_r0, ins->inst_imm);
3270 s390_slbgr (code, ins->dreg, s390_r0);
3272 S390_SET (code, s390_r0, ins->inst_imm);
3273 s390_slbgr(code, ins->dreg, s390_r0);
3277 case OP_SUB_OVF_CARRY: {
3279 s390_lghi (code, s390_r0, 0);
3280 s390_lgr (code, s390_r1, s390_r0);
3281 s390_slbgr (code, s390_r0, s390_r1);
3282 s390_sgr (code, ins->dreg, src2);
3283 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3284 s390_agr (code, ins->dreg, s390_r0);
3285 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3288 case OP_SUB_OVF_UN_CARRY: {
3290 s390_slbgr (code, ins->dreg, src2);
3291 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3295 if (ins->sreg1 == ins->dreg) {
3296 s390_ngr (code, ins->dreg, ins->sreg2);
3299 if (ins->sreg2 == ins->dreg) {
3300 s390_ngr (code, ins->dreg, ins->sreg1);
3303 s390_lgr (code, ins->dreg, ins->sreg1);
3304 s390_ngr (code, ins->dreg, ins->sreg2);
3310 if (ins->dreg != ins->sreg1) {
3311 s390_lgr (code, ins->dreg, ins->sreg1);
3313 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3314 s390_ngr (code, ins->dreg, s390_r0);
3318 s390_lgr (code, s390_r1, ins->sreg1);
3319 s390_dsgr (code, s390_r0, ins->sreg2);
3320 s390_lgr (code, ins->dreg, s390_r1);
3324 s390_lgr (code, s390_r1, ins->sreg1);
3325 s390_lghi (code, s390_r0, 0);
3326 s390_dlgr (code, s390_r0, ins->sreg2);
3327 s390_lgr (code, ins->dreg, s390_r1);
3331 s390_lgr (code, s390_r1, ins->sreg1);
3332 s390_dsgr (code, s390_r0, ins->sreg2);
3333 s390_lgr (code, ins->dreg, s390_r0);
3337 if (s390_is_imm16 (ins->inst_imm)) {
3338 s390_lghi (code, s390_r13, ins->inst_imm);
3340 s390_lgfi (code, s390_r13, ins->inst_imm);
3342 s390_lgr (code, s390_r0, ins->sreg1);
3343 s390_dsgr (code, s390_r0, s390_r13);
3344 s390_lgfr (code, ins->dreg, s390_r0);
3348 s390_lgr (code, s390_r1, ins->sreg1);
3349 s390_lghi (code, s390_r0, 0);
3350 s390_dlgr (code, s390_r0, ins->sreg2);
3351 s390_lgr (code, ins->dreg, s390_r0);
3355 if (ins->sreg1 == ins->dreg) {
3356 s390_ogr (code, ins->dreg, ins->sreg2);
3359 if (ins->sreg2 == ins->dreg) {
3360 s390_ogr (code, ins->dreg, ins->sreg1);
3363 s390_lgr (code, ins->dreg, ins->sreg1);
3364 s390_ogr (code, ins->dreg, ins->sreg2);
3370 if (ins->dreg != ins->sreg1) {
3371 s390_lgr (code, ins->dreg, ins->sreg1);
3373 S390_SET_MASK(code, s390_r0, ins->inst_imm);
3374 s390_ogr (code, ins->dreg, s390_r0);
3378 if (ins->sreg1 == ins->dreg) {
3379 s390_xgr (code, ins->dreg, ins->sreg2);
3382 if (ins->sreg2 == ins->dreg) {
3383 s390_xgr (code, ins->dreg, ins->sreg1);
3386 s390_lgr (code, ins->dreg, ins->sreg1);
3387 s390_xgr (code, ins->dreg, ins->sreg2);
3393 if (ins->dreg != ins->sreg1) {
3394 s390_lgr (code, ins->dreg, ins->sreg1);
3396 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3397 s390_xgr (code, ins->dreg, s390_r0);
3402 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3407 if (ins->sreg1 != ins->dreg) {
3408 s390_lgr (code, ins->dreg, ins->sreg1);
3410 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3415 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3420 if (ins->sreg1 != ins->dreg) {
3421 s390_lgr (code, ins->dreg, ins->sreg1);
3423 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3427 case OP_LSHR_UN_IMM: {
3428 if (ins->sreg1 != ins->dreg) {
3429 s390_lgr (code, ins->dreg, ins->sreg1);
3431 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3436 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3440 if (ins->sreg1 != ins->dreg) {
3441 s390_lgr (code, ins->dreg, ins->sreg1);
3443 s390_lghi (code, s390_r0, -1);
3444 s390_xgr (code, ins->dreg, s390_r0);
3448 s390_lcgr (code, ins->dreg, ins->sreg1);
3453 s390_msgr (code, ins->dreg, src2);
3458 if (ins->dreg != ins->sreg1) {
3459 s390_lgr (code, ins->dreg, ins->sreg1);
3461 if (s390_is_imm16 (ins->inst_imm)) {
3462 s390_lghi (code, s390_r13, ins->inst_imm);
3463 } else if (s390_is_imm32 (ins->inst_imm)) {
3464 s390_lgfi (code, s390_r13, ins->inst_imm);
3466 S390_SET (code, s390_r13, ins->inst_imm);
3468 s390_msgr (code, ins->dreg, s390_r13);
3473 s390_ltgr (code, s390_r1, ins->sreg1);
3474 s390_jz (code, 0); CODEPTR(code, o[0]);
3475 s390_ltgr (code, s390_r0, ins->sreg2);
3477 s390_lghi (code, s390_r1, 0);
3478 s390_j (code, 0); CODEPTR(code, o[1]);
3479 s390_xgr (code, s390_r0, s390_r1);
3480 s390_msgr (code, s390_r1, ins->sreg2);
3481 s390_xgr (code, s390_r0, s390_r1);
3482 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3483 s390_ltgr (code, s390_r0, s390_r0);
3484 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3485 PTRSLOT (code, o[0]);
3486 PTRSLOT (code, o[1]);
3487 s390_lgr (code, ins->dreg, s390_r1);
3490 case OP_LMUL_OVF_UN: {
3491 s390_lghi (code, s390_r0, 0);
3492 s390_lgr (code, s390_r1, ins->sreg1);
3493 s390_mlgr (code, s390_r0, ins->sreg2);
3494 s390_ltgr (code, s390_r0, s390_r0);
3495 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3496 s390_lgr (code, ins->dreg, s390_r1);
3500 g_assert_not_reached ();
3502 s390_algr (code, ins->dreg, src2);
3507 s390_agr (code, ins->dreg, src2);
3511 g_assert_not_reached ();
3513 s390_alcgr (code, ins->dreg, src2);
3517 if (ins->dreg != ins->sreg1) {
3518 s390_lgfr (code, ins->dreg, ins->sreg1);
3520 if (s390_is_imm16 (ins->inst_imm)) {
3521 s390_aghi (code, ins->dreg, ins->inst_imm);
3523 s390_afi (code, ins->dreg, ins->inst_imm);
3528 if (ins->dreg != ins->sreg1) {
3529 s390_lgfr (code, ins->dreg, ins->sreg1);
3531 if (s390_is_imm16 (ins->inst_imm)) {
3532 s390_lghi (code, s390_r0, ins->inst_imm);
3533 s390_alcgr (code, ins->dreg, s390_r0);
3535 S390_SET (code, s390_r0, ins->inst_imm);
3536 s390_alcgr (code, ins->dreg, s390_r0);
3541 case OP_S390_LADD_OVF: {
3543 s390_agr (code, ins->dreg, src2);
3544 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3547 case OP_LADD_OVF_UN:
3548 case OP_S390_LADD_OVF_UN: {
3550 s390_algr (code, ins->dreg, src2);
3551 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3555 CHECK_SRCDST_NCOM_I;
3556 s390_slgr (code, ins->dreg, src2);
3560 CHECK_SRCDST_NCOM_I;
3561 s390_sgr (code, ins->dreg, src2);
3565 CHECK_SRCDST_NCOM_I;
3566 s390_slbgr (code, ins->dreg, src2);
3570 if (ins->dreg != ins->sreg1) {
3571 s390_lgfr (code, ins->dreg, ins->sreg1);
3573 if (s390_is_imm16 (-ins->inst_imm)) {
3574 s390_aghi (code, ins->dreg, -ins->inst_imm);
3576 s390_agfi (code, ins->dreg, -ins->inst_imm);
3581 S390_SET (code, s390_r0, ins->inst_imm);
3582 s390_slgfr (code, ins->dreg, s390_r0);
3586 case OP_S390_ISUB_OVF: {
3588 s390_sr (code, ins->dreg, src2);
3589 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3590 s390_lgfr (code, ins->dreg, ins->dreg);
3593 case OP_ISUB_OVF_UN:
3594 case OP_S390_ISUB_OVF_UN: {
3596 s390_slr (code, ins->dreg, src2);
3597 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3598 s390_llgfr(code, ins->dreg, ins->dreg);
3602 case OP_S390_LSUB_OVF: {
3604 s390_sgr (code, ins->dreg, src2);
3605 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3608 case OP_LSUB_OVF_UN:
3609 case OP_S390_LSUB_OVF_UN: {
3611 s390_slgr (code, ins->dreg, src2);
3612 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3616 CHECK_SRCDST_NCOM_I;
3617 s390_ngr (code, ins->dreg, src2);
3621 if (ins->dreg != ins->sreg1) {
3622 s390_lgfr (code, ins->dreg, ins->sreg1);
3624 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3625 s390_ngr (code, ins->dreg, s390_r0);
3629 s390_lgfr (code, s390_r0, ins->sreg1);
3630 s390_srda (code, s390_r0, 0, 32);
3631 s390_dr (code, s390_r0, ins->sreg2);
3632 s390_lgfr (code, ins->dreg, s390_r1);
3636 s390_lgfr (code, s390_r0, ins->sreg1);
3637 s390_srdl (code, s390_r0, 0, 32);
3638 s390_dlr (code, s390_r0, ins->sreg2);
3639 s390_lgfr (code, ins->dreg, s390_r1);
3643 if (s390_is_imm16 (ins->inst_imm)) {
3644 s390_lghi (code, s390_r13, ins->inst_imm);
3646 s390_lgfi (code, s390_r13, ins->inst_imm);
3648 s390_lgfr (code, s390_r0, ins->sreg1);
3649 s390_srda (code, s390_r0, 0, 32);
3650 s390_dr (code, s390_r0, ins->sreg2);
3651 s390_lgfr (code, ins->dreg, s390_r1);
3655 s390_lgfr (code, s390_r0, ins->sreg1);
3656 s390_srda (code, s390_r0, 0, 32);
3657 s390_dr (code, s390_r0, ins->sreg2);
3658 s390_lgfr (code, ins->dreg, s390_r0);
3661 s390_lgfr (code, s390_r0, ins->sreg1);
3662 s390_srdl (code, s390_r0, 0, 32);
3663 s390_dlr (code, s390_r0, ins->sreg2);
3664 s390_lgfr (code, ins->dreg, s390_r0);
3668 if (s390_is_imm16 (ins->inst_imm)) {
3669 s390_lghi (code, s390_r13, ins->inst_imm);
3671 s390_lgfi (code, s390_r13, ins->inst_imm);
3673 s390_lgfr (code, s390_r0, ins->sreg1);
3674 s390_srda (code, s390_r0, 0, 32);
3675 s390_dr (code, s390_r0, ins->sreg2);
3676 s390_lgfr (code, ins->dreg, s390_r0);
3681 s390_ogr (code, ins->dreg, src2);
3685 if (ins->dreg != ins->sreg1) {
3686 s390_lgfr (code, ins->dreg, ins->sreg1);
3688 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3689 s390_ogr (code, ins->dreg, s390_r0);
3694 s390_xgr (code, ins->dreg, src2);
3698 if (ins->dreg != ins->sreg1) {
3699 s390_lgfr (code, ins->dreg, ins->sreg1);
3701 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3702 s390_xgr (code, ins->dreg, s390_r0);
3707 s390_sll (code, ins->dreg, src2, 0);
3711 if (ins->sreg1 != ins->dreg) {
3712 s390_lgfr (code, ins->dreg, ins->sreg1);
3714 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3719 s390_sra (code, ins->dreg, src2, 0);
3723 if (ins->sreg1 != ins->dreg) {
3724 s390_lgfr (code, ins->dreg, ins->sreg1);
3726 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3729 case OP_ISHR_UN_IMM: {
3730 if (ins->sreg1 != ins->dreg) {
3731 s390_lgfr (code, ins->dreg, ins->sreg1);
3733 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3738 s390_srl (code, ins->dreg, src2, 0);
3742 if (ins->sreg1 != ins->dreg) {
3743 s390_lgfr (code, ins->dreg, ins->sreg1);
3745 s390_lghi (code, s390_r0, -1);
3746 s390_xgr (code, ins->dreg, s390_r0);
3750 s390_lcgr (code, ins->dreg, ins->sreg1);
3755 s390_msr (code, ins->dreg, src2);
3759 if (ins->dreg != ins->sreg1) {
3760 s390_lgfr (code, ins->dreg, ins->sreg1);
3762 if (s390_is_imm16 (ins->inst_imm)) {
3763 s390_lghi (code, s390_r0, ins->inst_imm);
3765 s390_lgfi (code, s390_r0, ins->inst_imm);
3767 s390_msr (code, ins->dreg, s390_r0);
3772 s390_ltr (code, s390_r1, ins->sreg1);
3773 s390_jz (code, 0); CODEPTR(code, o[0]);
3774 s390_ltr (code, s390_r0, ins->sreg2);
3776 s390_lhi (code, s390_r1, 0);
3777 s390_j (code, 0); CODEPTR(code, o[1]);
3778 s390_xr (code, s390_r0, s390_r1);
3779 s390_msr (code, s390_r1, ins->sreg2);
3780 s390_xr (code, s390_r0, s390_r1);
3781 s390_srl (code, s390_r0, 0, 31);
3782 s390_ltr (code, s390_r0, s390_r0);
3783 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3784 PTRSLOT (code, o[0]);
3785 PTRSLOT (code, o[1]);
3786 s390_lgfr (code, ins->dreg, s390_r1);
3789 case OP_IMUL_OVF_UN: {
3790 s390_lhi (code, s390_r0, 0);
3791 s390_lr (code, s390_r1, ins->sreg1);
3792 s390_mlr (code, s390_r0, ins->sreg2);
3793 s390_ltr (code, s390_r0, s390_r0);
3794 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3795 s390_lgfr (code, ins->dreg, s390_r1);
3800 S390_SET (code, ins->dreg, ins->inst_c0);
3804 mono_add_patch_info (cfg, code - cfg->native_code,
3805 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3806 S390_LOAD_TEMPLATE (code, ins->dreg);
3809 case OP_JUMP_TABLE: {
3810 mono_add_patch_info (cfg, code - cfg->native_code,
3811 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3812 S390_LOAD_TEMPLATE (code, ins->dreg);
3816 if (ins->dreg != ins->sreg1) {
3817 s390_lgr (code, ins->dreg, ins->sreg1);
3821 case OP_LCONV_TO_I8:
3823 s390_lgfr (code, ins->dreg, ins->sreg1);
3825 case OP_LCONV_TO_I4:
3826 s390_lgfr (code, ins->dreg, ins->sreg1);
3829 case OP_LCONV_TO_U8:
3830 case OP_LCONV_TO_U4:
3832 s390_llgfr (code, ins->dreg, ins->sreg1);
3834 case OP_LCONV_TO_OVF_U4:
3835 S390_SET (code, s390_r0, 4294967295);
3836 s390_clgr (code, ins->sreg1, s390_r0);
3837 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3838 s390_ltgr (code, ins->sreg1, ins->sreg1);
3839 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3840 s390_llgfr(code, ins->dreg, ins->sreg1);
3842 case OP_LCONV_TO_OVF_I4_UN:
3843 S390_SET (code, s390_r0, 2147483647);
3844 s390_cgr (code, ins->sreg1, s390_r0);
3845 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3846 s390_ltgr (code, ins->sreg1, ins->sreg1);
3847 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3848 s390_lgfr (code, ins->dreg, ins->sreg1);
3851 if (ins->dreg != ins->sreg1) {
3852 s390_ldr (code, ins->dreg, ins->sreg1);
3855 case OP_MOVE_F_TO_I8:
3856 s390_lgdr (code, ins->dreg, ins->sreg1);
3858 case OP_MOVE_I8_TO_F:
3859 s390_ldgr (code, ins->dreg, ins->sreg1);
3861 case OP_MOVE_F_TO_I4:
3862 s390_lgdr (code, ins->dreg, ins->sreg1);
3864 case OP_MOVE_I4_TO_F:
3865 s390_lgfr (code, s390_r0, ins->sreg1);
3866 s390_ldgr (code, ins->dreg, s390_r0);
3868 case OP_FCONV_TO_R4:
3869 s390_ledbr (code, ins->dreg, ins->sreg1);
3870 s390_ldebr (code, ins->dreg, ins->dreg);
3872 case OP_S390_SETF4RET:
3873 s390_ledbr (code, ins->dreg, ins->sreg1);
3876 if (s390_is_imm16 (ins->inst_offset)) {
3877 s390_lghi (code, s390_r13, ins->inst_offset);
3878 } else if (s390_is_imm32 (ins->inst_offset)) {
3879 s390_lgfi (code, s390_r13, ins->inst_offset);
3881 S390_SET (code, s390_r13, ins->inst_offset);
3883 s390_ear (code, s390_r1, 0);
3884 s390_sllg(code, s390_r1, s390_r1, 0, 32);
3885 s390_ear (code, s390_r1, 1);
3886 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
3890 if (cfg->method->save_lmf)
3891 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3893 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3894 code = emit_load_volatile_arguments (code, cfg);
3897 code = backUpStackPtr(cfg, code);
3898 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
3899 mono_add_patch_info (cfg, code - cfg->native_code,
3900 MONO_PATCH_INFO_METHOD_JUMP,
3902 s390_jcl (code, S390_CC_UN, 0);
3905 case OP_CHECK_THIS: {
3906 /* ensure ins->sreg1 is not NULL */
3907 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3908 s390_ltgr (code, s390_r0, s390_r0);
3909 // EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
3913 int offset = cfg->sig_cookie + cfg->stack_usage;
3915 if (s390_is_imm16 (offset)) {
3916 s390_lghi (code, s390_r0, offset);
3917 } else if (s390_is_imm32 (offset)) {
3918 s390_lgfi (code, s390_r0, offset);
3920 S390_SET (code, s390_r0, offset);
3922 s390_agr (code, s390_r0, cfg->frame_reg);
3923 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3927 call = (MonoCallInst*)ins;
3928 if (ins->flags & MONO_INST_HAS_METHOD)
3929 mono_add_patch_info (cfg, code-cfg->native_code,
3930 MONO_PATCH_INFO_METHOD,
3933 mono_add_patch_info (cfg, code-cfg->native_code,
3934 MONO_PATCH_INFO_ABS,
3936 S390_CALL_TEMPLATE (code, s390_r14);
3937 if (call->signature->ret->type == MONO_TYPE_R4)
3938 s390_ldebr (code, s390_f0, s390_f0);
3946 call = (MonoCallInst*)ins;
3947 if (ins->flags & MONO_INST_HAS_METHOD)
3948 mono_add_patch_info (cfg, code-cfg->native_code,
3949 MONO_PATCH_INFO_METHOD,
3952 mono_add_patch_info (cfg, code-cfg->native_code,
3953 MONO_PATCH_INFO_ABS,
3955 S390_CALL_TEMPLATE (code, s390_r14);
3958 case OP_FCALL_REG: {
3959 call = (MonoCallInst*)ins;
3960 s390_lgr (code, s390_r1, ins->sreg1);
3961 s390_basr (code, s390_r14, s390_r1);
3962 if (call->signature->ret->type == MONO_TYPE_R4)
3963 s390_ldebr (code, s390_f0, s390_f0);
3969 case OP_VOIDCALL_REG:
3971 s390_lgr (code, s390_r1, ins->sreg1);
3972 s390_basr (code, s390_r14, s390_r1);
3975 case OP_FCALL_MEMBASE: {
3976 call = (MonoCallInst*)ins;
3977 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3978 s390_basr (code, s390_r14, s390_r1);
3979 if (call->signature->ret->type == MONO_TYPE_R4)
3980 s390_ldebr (code, s390_f0, s390_f0);
3983 case OP_LCALL_MEMBASE:
3984 case OP_VCALL_MEMBASE:
3985 case OP_VCALL2_MEMBASE:
3986 case OP_VOIDCALL_MEMBASE:
3987 case OP_CALL_MEMBASE: {
3988 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3989 s390_basr (code, s390_r14, s390_r1);
3996 if (cfg->param_area == 0)
3997 alloca_skip = S390_MINIMAL_STACK_SIZE;
3999 alloca_skip = cfg->param_area;
4001 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4002 s390_lgr (code, s390_r1, ins->sreg1);
4003 if (ins->flags & MONO_INST_INIT)
4004 s390_lgr (code, s390_r0, ins->sreg1);
4005 s390_aghi (code, s390_r1, 14);
4006 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4007 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4008 if (cfg->method->save_lmf) {
4009 /*----------------------------------*/
4010 /* we have to adjust lmf ebp value */
4011 /*----------------------------------*/
4012 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4014 s390_lgr (code, s390_r13, cfg->frame_reg);
4015 if (s390_is_imm16(lmfOffset)) {
4016 s390_aghi (code, s390_r13, lmfOffset);
4017 } else if (s390_is_imm32(lmfOffset)) {
4018 s390_agfi (code, s390_r13, lmfOffset);
4020 S390_SET (code, s390_r13, lmfOffset);
4022 s390_lgr (code, s390_r14, STK_BASE);
4023 s390_sgr (code, s390_r14, s390_r1);
4024 s390_stg (code, s390_r14, 0, s390_r13,
4025 G_STRUCT_OFFSET(MonoLMF, ebp));
4027 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4028 s390_sgr (code, STK_BASE, s390_r1);
4029 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4030 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4031 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4032 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4033 if (ins->flags & MONO_INST_INIT) {
4034 s390_lgr (code, s390_r1, s390_r0);
4035 s390_lgr (code, s390_r0, ins->dreg);
4036 s390_lgr (code, s390_r14, s390_r12);
4037 s390_lghi (code, s390_r13, 0);
4038 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4040 s390_lgr (code, s390_r12, s390_r14);
4045 s390_lgr (code, s390_r2, ins->sreg1);
4046 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4047 (gpointer) "mono_arch_throw_exception");
4048 S390_CALL_TEMPLATE(code, s390_r14);
4052 s390_lgr (code, s390_r2, ins->sreg1);
4053 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4054 (gpointer) "mono_arch_rethrow_exception");
4055 S390_CALL_TEMPLATE(code, s390_r14);
4058 case OP_START_HANDLER: {
4059 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4061 S390_LONG (code, stg, stg, s390_r14, 0,
4062 spvar->inst_basereg,
4063 spvar->inst_offset);
4066 case OP_ENDFILTER: {
4067 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4069 if (ins->sreg1 != s390_r2)
4070 s390_lgr(code, s390_r2, ins->sreg1);
4071 S390_LONG (code, lg, lg, s390_r14, 0,
4072 spvar->inst_basereg,
4073 spvar->inst_offset);
4074 s390_br (code, s390_r14);
4077 case OP_ENDFINALLY: {
4078 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4080 S390_LONG (code, lg, lg, s390_r14, 0,
4081 spvar->inst_basereg,
4082 spvar->inst_offset);
4083 s390_br (code, s390_r14);
4086 case OP_CALL_HANDLER: {
4087 mono_add_patch_info (cfg, code-cfg->native_code,
4088 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4089 s390_brasl (code, s390_r14, 0);
4090 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4094 ins->inst_c0 = code - cfg->native_code;
4097 case OP_RELAXED_NOP:
4100 case OP_DUMMY_STORE:
4101 case OP_NOT_REACHED:
4105 case OP_IL_SEQ_POINT:
4106 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4108 case OP_SEQ_POINT: {
4111 if (cfg->compile_aot)
4115 * Read from the single stepping trigger page. This will cause a
4116 * SIGSEGV when single stepping is enabled.
4117 * We do this _before_ the breakpoint, so single stepping after
4118 * a breakpoint is hit will step to the next IL offset.
4120 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4121 breakpointCode.pTrigger = ss_trigger_page;
4122 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4123 code += BREAKPOINT_SIZE;
4126 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4129 * A placeholder for a possible breakpoint inserted by
4130 * mono_arch_set_breakpoint ().
4132 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4136 * Add an additional nop so skipping the bp doesn't cause the ip to point
4137 * to another IL offset.
4143 case OP_GENERIC_CLASS_INIT: {
4144 static int byte_offset = -1;
4145 static guint8 bitmask;
4148 g_assert (ins->sreg1 == S390_FIRST_ARG_REG);
4150 if (byte_offset < 0)
4151 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
4153 s390_tm (code, ins->sreg1, byte_offset, bitmask);
4154 s390_jo (code, 0); CODEPTR(code, jump);
4156 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4157 "mono_generic_class_init");
4158 S390_CALL_TEMPLATE(code, s390_r14);
4160 PTRSLOT (code, jump);
4162 ins->flags |= MONO_INST_GC_CALLSITE;
4163 ins->backend.pc_offset = code - cfg->native_code;
4167 EMIT_UNCOND_BRANCH(ins);
4170 s390_br (code, ins->sreg1);
4176 s390_lghi(code, ins->dreg, 1);
4178 s390_lghi(code, ins->dreg, 0);
4184 s390_lghi(code, ins->dreg, 1);
4186 s390_lghi(code, ins->dreg, 0);
4192 s390_lghi(code, ins->dreg, 1);
4194 s390_lghi(code, ins->dreg, 0);
4200 s390_lghi(code, ins->dreg, 1);
4202 s390_lghi(code, ins->dreg, 0);
4208 s390_lghi(code, ins->dreg, 1);
4210 s390_lghi(code, ins->dreg, 0);
4213 case OP_COND_EXC_EQ:
4214 case OP_COND_EXC_IEQ:
4215 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4217 case OP_COND_EXC_NE_UN:
4218 case OP_COND_EXC_INE_UN:
4219 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4221 case OP_COND_EXC_LT:
4222 case OP_COND_EXC_ILT:
4223 case OP_COND_EXC_LT_UN:
4224 case OP_COND_EXC_ILT_UN:
4225 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4227 case OP_COND_EXC_GT:
4228 case OP_COND_EXC_IGT:
4229 case OP_COND_EXC_GT_UN:
4230 case OP_COND_EXC_IGT_UN:
4231 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4233 case OP_COND_EXC_GE:
4234 case OP_COND_EXC_IGE:
4235 case OP_COND_EXC_GE_UN:
4236 case OP_COND_EXC_IGE_UN:
4237 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4239 case OP_COND_EXC_LE:
4240 case OP_COND_EXC_ILE:
4241 case OP_COND_EXC_LE_UN:
4242 case OP_COND_EXC_ILE_UN:
4243 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4245 case OP_COND_EXC_OV:
4246 case OP_COND_EXC_IOV:
4247 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4249 case OP_COND_EXC_NO:
4250 case OP_COND_EXC_INO:
4251 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4254 case OP_COND_EXC_IC:
4255 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4257 case OP_COND_EXC_NC:
4258 case OP_COND_EXC_INC:
4259 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4263 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4267 EMIT_COND_BRANCH (ins, S390_CC_NE);
4273 EMIT_COND_BRANCH (ins, S390_CC_LT);
4279 EMIT_COND_BRANCH (ins, S390_CC_GT);
4285 EMIT_COND_BRANCH (ins, S390_CC_GE);
4291 EMIT_COND_BRANCH (ins, S390_CC_LE);
4294 /* floating point opcodes */
4296 if (*((double *) ins->inst_p0) == 0) {
4297 s390_lzdr (code, ins->dreg);
4299 S390_SET (code, s390_r13, ins->inst_p0);
4300 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4305 if (*((float *) ins->inst_p0) == 0) {
4306 s390_lzdr (code, ins->dreg);
4308 S390_SET (code, s390_r13, ins->inst_p0);
4309 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4313 case OP_STORER8_MEMBASE_REG: {
4314 S390_LONG (code, stdy, std, ins->sreg1, 0,
4315 ins->inst_destbasereg, ins->inst_offset);
4318 case OP_LOADR8_MEMBASE: {
4319 S390_LONG (code, ldy, ld, ins->dreg, 0,
4320 ins->inst_basereg, ins->inst_offset);
4323 case OP_STORER4_MEMBASE_REG: {
4324 s390_ledbr (code, s390_f15, ins->sreg1);
4325 S390_LONG (code, stey, ste, s390_f15, 0,
4326 ins->inst_destbasereg, ins->inst_offset);
4329 case OP_LOADR4_MEMBASE: {
4330 S390_LONG (code, ldy, ld, s390_f15, 0,
4331 ins->inst_basereg, ins->inst_offset);
4332 s390_ldebr (code, ins->dreg, s390_f15);
4335 case OP_ICONV_TO_R_UN: {
4337 s390_cdlfbr (code, ins->dreg, 5, ins->sreg1, 0);
4339 s390_llgfr (code, s390_r0, ins->sreg1);
4340 s390_cdgbr (code, ins->dreg, s390_r0);
4344 case OP_LCONV_TO_R_UN: {
4346 s390_cdlgbr (code, ins->dreg, 5, ins->sreg1, 0);
4349 s390_cxgbr (code, s390_f12, ins->sreg1);
4350 s390_ltgr (code, ins->sreg1, ins->sreg1);
4351 s390_jnl (code, 0); CODEPTR(code, jump);
4352 S390_SET (code, s390_r13, 0x403f000000000000llu);
4353 s390_lgdr (code, s390_f13, s390_r13);
4354 s390_lzdr (code, s390_f15);
4355 s390_axbr (code, s390_f12, s390_f13);
4356 PTRSLOT(code, jump);
4357 s390_ldxbr (code, s390_f13, s390_f12);
4358 s390_ldr (code, ins->dreg, s390_f13);
4362 case OP_LCONV_TO_R4:
4363 case OP_ICONV_TO_R4: {
4364 s390_cegbr (code, ins->dreg, ins->sreg1);
4365 s390_ldebr (code, ins->dreg, ins->dreg);
4368 case OP_LCONV_TO_R8:
4369 case OP_ICONV_TO_R8: {
4370 s390_cdgbr (code, ins->dreg, ins->sreg1);
4373 case OP_FCONV_TO_I1:
4374 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4375 s390_ltgr (code, ins->dreg, ins->dreg);
4377 s390_oill (code, ins->dreg, 0x80);
4378 s390_lghi (code, s390_r0, 0xff);
4379 s390_ngr (code, ins->dreg, s390_r0);
4381 case OP_FCONV_TO_U1:
4383 s390_clgdbr (code, ins->dreg, 5, ins->sreg1, 0);
4384 s390_lghi (code, s390_r0, 0xff);
4385 s390_ngr (code, ins->dreg, s390_r0);
4387 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4390 case OP_FCONV_TO_I2:
4391 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4392 s390_ltgr (code, ins->dreg, ins->dreg);
4394 s390_oill (code, ins->dreg, 0x8000);
4395 s390_llill (code, s390_r0, 0xffff);
4396 s390_ngr (code, ins->dreg, s390_r0);
4398 case OP_FCONV_TO_U2:
4400 s390_clgdbr (code, ins->dreg, 5, ins->sreg1, 0);
4401 s390_llill (code, s390_r0, 0xffff);
4402 s390_ngr (code, ins->dreg, s390_r0);
4404 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4407 case OP_FCONV_TO_I4:
4409 s390_cfdbr (code, ins->dreg, 5, ins->sreg1);
4411 case OP_FCONV_TO_U4:
4414 s390_clfdbr (code, ins->dreg, 5, ins->sreg1, 0);
4416 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4419 case OP_FCONV_TO_I8:
4420 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4422 case OP_FCONV_TO_U8:
4424 s390_clgdbr (code, ins->dreg, 5, ins->sreg1, 0);
4426 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 8, FALSE);
4429 case OP_LCONV_TO_OVF_I: {
4430 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4432 s390_ltgr (code, ins->sreg2, ins->sreg2);
4433 s390_jnl (code, 0); CODEPTR(code, o[0]);
4434 s390_ltgr (code, ins->sreg1, ins->sreg1);
4435 s390_jnl (code, 0); CODEPTR(code, o[1]);
4436 s390_lhi (code, s390_r13, -1);
4437 s390_cgr (code, ins->sreg1, s390_r13);
4438 s390_jnz (code, 0); CODEPTR(code, o[2]);
4439 if (ins->dreg != ins->sreg2)
4440 s390_lgr (code, ins->dreg, ins->sreg2);
4441 s390_j (code, 0); CODEPTR(code, o[3]);
4442 PTRSLOT(code, o[0]);
4443 s390_jz (code, 0); CODEPTR(code, o[4]);
4444 PTRSLOT(code, o[1]);
4445 PTRSLOT(code, o[2]);
4446 mono_add_patch_info (cfg, code - cfg->native_code,
4447 MONO_PATCH_INFO_EXC, "OverflowException");
4448 s390_brasl (code, s390_r14, 0);
4449 PTRSLOT(code, o[3]);
4450 PTRSLOT(code, o[4]);
4454 s390_lpdbr (code, ins->dreg, ins->sreg1);
4458 s390_sqdbr (code, ins->dreg, ins->sreg1);
4463 s390_adbr (code, ins->dreg, src2);
4467 CHECK_SRCDST_NCOM_F;
4468 s390_sdbr (code, ins->dreg, src2);
4473 s390_mdbr (code, ins->dreg, src2);
4477 CHECK_SRCDST_NCOM_F;
4478 s390_ddbr (code, ins->dreg, src2);
4482 s390_lcdbr (code, ins->dreg, ins->sreg1);
4486 CHECK_SRCDST_NCOM_F;
4487 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4491 s390_cdbr (code, ins->sreg1, ins->sreg2);
4495 s390_cdbr (code, ins->sreg1, ins->sreg2);
4496 s390_lghi (code, ins->dreg, 1);
4498 s390_lghi (code, ins->dreg, 0);
4502 s390_cdbr (code, ins->sreg1, ins->sreg2);
4503 s390_lghi (code, ins->dreg, 1);
4505 s390_lghi (code, ins->dreg, 0);
4509 s390_cdbr (code, ins->sreg1, ins->sreg2);
4510 s390_lghi (code, ins->dreg, 1);
4512 s390_lghi (code, ins->dreg, 0);
4516 s390_cdbr (code, ins->sreg1, ins->sreg2);
4517 s390_lghi (code, ins->dreg, 1);
4519 s390_lghi (code, ins->dreg, 0);
4523 s390_cdbr (code, ins->sreg1, ins->sreg2);
4524 s390_lghi (code, ins->dreg, 1);
4526 s390_lghi (code, ins->dreg, 0);
4531 s390_jo (code, 0); CODEPTR(code, o);
4532 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4537 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4541 s390_jo (code, 0); CODEPTR(code, o);
4542 EMIT_COND_BRANCH (ins, S390_CC_LT);
4547 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4551 s390_jo (code, 0); CODEPTR(code, o);
4552 EMIT_COND_BRANCH (ins, S390_CC_GT);
4557 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4561 s390_jo (code, 0); CODEPTR(code, o);
4562 EMIT_COND_BRANCH (ins, S390_CC_GE);
4567 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4571 s390_jo (code, 0); CODEPTR(code, o);
4572 EMIT_COND_BRANCH (ins, S390_CC_LE);
4577 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4581 s390_lhi (code, s390_r13, 0x7f);
4582 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4583 s390_jz (code, 0); CODEPTR(code, o);
4584 mono_add_patch_info (cfg, code - cfg->native_code,
4585 MONO_PATCH_INFO_EXC, "ArithmeticException");
4586 s390_brasl (code, s390_r14,0);
4590 case OP_S390_MOVE: {
4591 if (ins->backend.size > 0) {
4592 if (ins->backend.size <= 256) {
4593 s390_mvc (code, ins->backend.size, ins->dreg,
4594 ins->inst_offset, ins->sreg1, ins->inst_imm);
4596 s390_lgr (code, s390_r0, ins->dreg);
4597 if (ins->inst_offset > 0) {
4598 if (s390_is_imm16 (ins->inst_offset)) {
4599 s390_aghi (code, s390_r0, ins->inst_offset);
4600 } else if (s390_is_imm32 (ins->inst_offset)) {
4601 s390_agfi (code, s390_r0, ins->inst_offset);
4603 S390_SET (code, s390_r13, ins->inst_offset);
4604 s390_agr (code, s390_r0, s390_r13);
4607 s390_lgr (code, s390_r12, ins->sreg1);
4608 if (ins->inst_imm > 0) {
4609 if (s390_is_imm16 (ins->inst_imm)) {
4610 s390_aghi (code, s390_r12, ins->inst_imm);
4611 } else if (s390_is_imm32 (ins->inst_imm)) {
4612 s390_agfi (code, s390_r12, ins->inst_imm);
4614 S390_SET (code, s390_r13, ins->inst_imm);
4615 s390_agr (code, s390_r12, s390_r13);
4618 if (s390_is_imm16 (ins->backend.size)) {
4619 s390_lghi (code, s390_r1, ins->backend.size);
4620 } else if (s390_is_imm32 (ins->inst_offset)) {
4621 s390_agfi (code, s390_r1, ins->backend.size);
4623 S390_SET (code, s390_r13, ins->backend.size);
4624 s390_agr (code, s390_r1, s390_r13);
4626 s390_lgr (code, s390_r13, s390_r1);
4627 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4633 case OP_ATOMIC_ADD_I8: {
4634 s390_lgr (code, s390_r1, ins->sreg2);
4635 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4636 s390_agr (code, s390_r1, s390_r0);
4637 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4638 s390_jnz (code, -10);
4639 s390_lgr (code, ins->dreg, s390_r1);
4642 case OP_ATOMIC_EXCHANGE_I8: {
4643 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4644 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4645 s390_jnz (code, -6);
4646 s390_lgr (code, ins->dreg, s390_r0);
4649 case OP_ATOMIC_ADD_I4: {
4650 s390_lgfr(code, s390_r1, ins->sreg2);
4651 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4652 s390_agr (code, s390_r1, s390_r0);
4653 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4654 s390_jnz (code, -9);
4655 s390_lgfr(code, ins->dreg, s390_r1);
4658 case OP_ATOMIC_EXCHANGE_I4: {
4659 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4660 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4661 s390_jnz (code, -4);
4662 s390_lgfr(code, ins->dreg, s390_r0);
4665 case OP_S390_BKCHAIN: {
4666 s390_lgr (code, ins->dreg, ins->sreg1);
4667 if (s390_is_imm16 (cfg->stack_offset)) {
4668 s390_aghi (code, ins->dreg, cfg->stack_offset);
4669 } else if (s390_is_imm32 (cfg->stack_offset)) {
4670 s390_agfi (code, ins->dreg, cfg->stack_offset);
4672 S390_SET (code, s390_r13, cfg->stack_offset);
4673 s390_agr (code, ins->dreg, s390_r13);
4677 case OP_MEMORY_BARRIER:
4681 case OP_GC_SAFE_POINT: {
4684 s390_chi (code, ins->sreg1, 1);
4685 s390_je (code, 0); CODEPTR(code, br);
4686 mono_add_patch_info (cfg, code- cfg->native_code, MONO_PATCH_INFO_ABS,
4687 mono_threads_state_poll);
4688 S390_CALL_TEMPLATE (code, s390_r14);
4693 case OP_GC_LIVENESS_DEF:
4694 case OP_GC_LIVENESS_USE:
4695 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4696 ins->backend.pc_offset = code - cfg->native_code;
4698 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4699 ins->backend.pc_offset = code - cfg->native_code;
4700 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4703 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4704 g_assert_not_reached ();
4707 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4708 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4709 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4710 g_assert_not_reached ();
4713 last_offset = offset;
4716 cfg->code_len = code - cfg->native_code;
4719 /*========================= End of Function ========================*/
4721 /*------------------------------------------------------------------*/
4723 /* Name - mono_arch_register_lowlevel_calls */
4725 /* Function - Register routines to help with --trace operation. */
4727 /*------------------------------------------------------------------*/
4730 mono_arch_register_lowlevel_calls (void)
4734 /*========================= End of Function ========================*/
4736 /*------------------------------------------------------------------*/
4738 /* Name - mono_arch_patch_code */
4740 /* Function - Process the patch data created during the */
4741 /* instruction build process. This resolves jumps, */
4742 /* calls, variables etc. */
4744 /*------------------------------------------------------------------*/
4747 mono_arch_patch_code (MonoCompile *cfg, MonoMethod *method, MonoDomain *domain,
4748 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4750 MonoJumpInfo *patch_info;
4752 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4753 unsigned char *ip = patch_info->ip.i + code;
4754 gconstpointer target = NULL;
4756 target = mono_resolve_patch_target (method, domain, code,
4757 patch_info, run_cctors);
4759 switch (patch_info->type) {
4760 case MONO_PATCH_INFO_IP:
4761 case MONO_PATCH_INFO_LDSTR:
4762 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4763 case MONO_PATCH_INFO_LDTOKEN:
4764 case MONO_PATCH_INFO_EXC:
4765 s390_patch_addr (ip, (guint64) target);
4767 case MONO_PATCH_INFO_METHOD:
4768 case MONO_PATCH_INFO_INTERNAL_METHOD:
4769 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4770 case MONO_PATCH_INFO_RGCTX_FETCH:
4771 case MONO_PATCH_INFO_MONITOR_ENTER:
4772 case MONO_PATCH_INFO_MONITOR_ENTER_V4:
4773 case MONO_PATCH_INFO_MONITOR_EXIT:
4774 case MONO_PATCH_INFO_ABS: {
4775 S390_EMIT_CALL (ip, target);
4778 case MONO_PATCH_INFO_SWITCH:
4779 /*----------------------------------*/
4780 /* ip points at the basr r13,0/j +4 */
4781 /* instruction the vtable value */
4782 /* follows this (i.e. ip+6) */
4783 /*----------------------------------*/
4784 S390_EMIT_LOAD (ip, target);
4786 case MONO_PATCH_INFO_METHODCONST:
4787 case MONO_PATCH_INFO_CLASS:
4788 case MONO_PATCH_INFO_IMAGE:
4789 case MONO_PATCH_INFO_FIELD:
4790 case MONO_PATCH_INFO_IID:
4791 case MONO_PATCH_INFO_EXC_NAME:
4792 target = S390_RELATIVE(target, ip);
4793 s390_patch_rel (ip, (guint64) target);
4795 case MONO_PATCH_INFO_R4:
4796 case MONO_PATCH_INFO_R8:
4797 case MONO_PATCH_INFO_METHOD_REL:
4798 g_assert_not_reached ();
4801 target = S390_RELATIVE(target, ip);
4803 s390_patch_rel (ip, (guint64) target);
4808 /*========================= End of Function ========================*/
4810 /*------------------------------------------------------------------*/
4812 /* Name - emit_load_volatile_arguments */
4814 /* Function - Emit the instructions to reload parameter regist- */
4815 /* registers for use with "tail" operations. */
4817 /* The register loading operations performed here */
4818 /* are the mirror of the store operations performed */
4819 /* in mono_arch_emit_prolog and need to be kept in */
4820 /* synchronization with it. */
4822 /*------------------------------------------------------------------*/
4825 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4828 MonoMethod *method = cfg->method;
4829 MonoMethodSignature *sig = mono_method_signature(method);
4833 cinfo = get_call_info (NULL, NULL, sig);
4835 if (cinfo->struct_ret) {
4836 ArgInfo *ainfo = &cinfo->ret;
4837 inst = cfg->vret_addr;
4838 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4841 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4842 ArgInfo *ainfo = cinfo->args + i;
4843 inst = cfg->args [pos];
4845 if (inst->opcode == OP_REGVAR) {
4846 if (ainfo->regtype == RegTypeGeneral)
4847 s390_lgr (code, ainfo->reg, inst->dreg);
4848 else if (ainfo->regtype == RegTypeFP) {
4849 if (inst->dreg != ainfo->reg) {
4850 if (ainfo->size == 4) {
4851 s390_ldebr (code, ainfo->reg, inst->dreg);
4853 s390_ldr (code, ainfo->reg, inst->dreg);
4857 else if (ainfo->regtype == RegTypeBase) {
4859 g_assert_not_reached ();
4861 if (ainfo->regtype == RegTypeGeneral) {
4862 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4863 g_assert_not_reached();
4864 switch (ainfo->size) {
4866 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4869 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4872 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4875 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4878 } else if (ainfo->regtype == RegTypeBase) {
4879 } else if (ainfo->regtype == RegTypeFP) {
4880 if (ainfo->size == 8)
4881 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4882 else if (ainfo->size == 4)
4883 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4885 g_assert_not_reached ();
4886 } else if (ainfo->regtype == RegTypeStructByVal) {
4887 if (ainfo->reg != STK_BASE) {
4888 switch (ainfo->size) {
4890 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4893 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4896 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4899 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4903 } else if (ainfo->regtype == RegTypeStructByAddr) {
4904 if (ainfo->reg != STK_BASE) {
4905 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4908 g_assert_not_reached ();
4916 /*========================= End of Function ========================*/
4918 /*------------------------------------------------------------------*/
4920 /* Name - mono_arch_emit_prolog */
4922 /* Function - Create the instruction sequence for a function */
4925 /*------------------------------------------------------------------*/
4928 mono_arch_emit_prolog (MonoCompile *cfg)
4930 MonoMethod *method = cfg->method;
4932 MonoMethodSignature *sig;
4934 long alloc_size, pos, max_offset, i, cfa_offset = 0;
4941 cfg->code_size = 512;
4943 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4945 cfg->code_size += 256;
4946 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4947 cfg->code_size += 256;
4949 if (method->save_lmf)
4950 cfg->code_size += 200;
4952 cfg->native_code = code = g_malloc (cfg->code_size);
4954 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
4955 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
4956 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4957 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
4959 if (cfg->arch.bkchain_reg != -1)
4960 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4962 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4963 cfg->used_int_regs |= 1 << 11;
4966 alloc_size = cfg->stack_offset;
4968 cfg->stack_usage = cfa_offset = alloc_size;
4969 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
4970 s390_lgr (code, s390_r11, STK_BASE);
4971 if (s390_is_imm16 (alloc_size)) {
4972 s390_aghi (code, STK_BASE, -alloc_size);
4973 } else if (s390_is_imm32 (alloc_size)) {
4974 s390_agfi (code, STK_BASE, -alloc_size);
4976 int stackSize = alloc_size;
4977 while (stackSize > INT_MAX) {
4978 s390_agfi (code, STK_BASE, -INT_MAX);
4979 stackSize -= INT_MAX;
4981 s390_agfi (code, STK_BASE, -stackSize);
4983 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4985 if (cfg->frame_reg != STK_BASE)
4986 s390_lgr (code, s390_r11, STK_BASE);
4988 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
4990 /* store runtime generic context */
4991 if (cfg->rgctx_var) {
4992 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
4994 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
4995 cfg->rgctx_var->inst_basereg,
4996 cfg->rgctx_var->inst_offset);
4999 /* compute max_offset in order to use short forward jumps
5000 * we always do it on s390 because the immediate displacement
5001 * for jumps is too small
5004 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5006 bb->max_offset = max_offset;
5008 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5011 MONO_BB_FOR_EACH_INS (bb, ins)
5012 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5015 /* load arguments allocated to register from the stack */
5016 sig = mono_method_signature (method);
5019 cinfo = get_call_info (cfg, cfg->mempool, sig);
5021 if (cinfo->struct_ret) {
5022 ArgInfo *ainfo = &cinfo->ret;
5023 inst = cfg->vret_addr;
5024 inst->backend.size = ainfo->vtsize;
5025 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5028 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5029 ArgInfo *ainfo = cinfo->args + i;
5030 inst = cfg->args [pos];
5032 if (inst->opcode == OP_VTARG_ADDR)
5033 inst = inst->inst_left;
5035 if (inst->opcode == OP_REGVAR) {
5036 if (ainfo->regtype == RegTypeGeneral)
5037 s390_lgr (code, inst->dreg, ainfo->reg);
5038 else if (ainfo->regtype == RegTypeFP) {
5039 if (inst->dreg != ainfo->reg) {
5040 if (ainfo->size == 4) {
5041 s390_ledbr (code, inst->dreg, ainfo->reg);
5043 s390_ldr (code, inst->dreg, ainfo->reg);
5047 else if (ainfo->regtype == RegTypeBase) {
5048 s390_lgr (code, s390_r13, STK_BASE);
5049 s390_aghi (code, s390_r13, alloc_size);
5050 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5052 g_assert_not_reached ();
5054 if (cfg->verbose_level > 2)
5055 g_print ("Argument %d assigned to register %s\n",
5056 pos, mono_arch_regname (inst->dreg));
5058 if (ainfo->regtype == RegTypeGeneral) {
5059 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5060 g_assert_not_reached();
5061 switch (ainfo->size) {
5063 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5066 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5069 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5072 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5075 } else if (ainfo->regtype == RegTypeBase) {
5076 } else if (ainfo->regtype == RegTypeFP) {
5077 if (ainfo->size == 8)
5078 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5079 else if (ainfo->size == 4)
5080 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5082 g_assert_not_reached ();
5083 } else if (ainfo->regtype == RegTypeStructByVal) {
5084 int doffset = inst->inst_offset;
5086 if (ainfo->reg != STK_BASE)
5090 s390_lgr (code, s390_r13, STK_BASE);
5091 s390_aghi (code, s390_r13, alloc_size);
5094 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5095 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5100 if (ainfo->reg == STK_BASE)
5101 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5102 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5105 if (ainfo->reg == STK_BASE)
5106 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5107 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5110 if (ainfo->reg == STK_BASE)
5111 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5112 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5115 if (ainfo->reg == STK_BASE)
5116 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5117 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5120 } else if (ainfo->regtype == RegTypeStructByAddr) {
5121 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5122 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5124 g_assert_not_reached ();
5129 if (method->save_lmf) {
5130 /*---------------------------------------------------------------*/
5131 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5132 /*---------------------------------------------------------------*/
5133 lmfOffset = alloc_size - sizeof(MonoLMF);
5135 s390_lgr (code, s390_r13, cfg->frame_reg);
5136 s390_aghi (code, s390_r13, lmfOffset);
5138 /*---------------------------------------------------------------*/
5139 /* Preserve the parameter registers while we fix up the lmf */
5140 /*---------------------------------------------------------------*/
5141 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5142 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5144 /*---------------------------------------------------------------*/
5145 /* On return from this call r2 have the address of the &lmf */
5146 /*---------------------------------------------------------------*/
5147 if (lmf_addr_tls_offset == -1) {
5148 mono_add_patch_info (cfg, code - cfg->native_code,
5149 MONO_PATCH_INFO_INTERNAL_METHOD,
5150 (gpointer)"mono_get_lmf_addr");
5151 S390_CALL_TEMPLATE(code, s390_r1);
5153 /*-------------------------------------------------------*/
5154 /* Get LMF by getting value from thread level storage */
5155 /*-------------------------------------------------------*/
5156 s390_ear (code, s390_r1, 0);
5157 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5158 s390_ear (code, s390_r1, 1);
5159 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5162 /*---------------------------------------------------------------*/
5163 /* Set lmf.lmf_addr = jit_tls->lmf */
5164 /*---------------------------------------------------------------*/
5165 s390_stg (code, s390_r2, 0, s390_r13,
5166 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5168 /*---------------------------------------------------------------*/
5169 /* Get current lmf */
5170 /*---------------------------------------------------------------*/
5171 s390_lg (code, s390_r0, 0, s390_r2, 0);
5173 /*---------------------------------------------------------------*/
5174 /* Set our lmf as the current lmf */
5175 /*---------------------------------------------------------------*/
5176 s390_stg (code, s390_r13, 0, s390_r2, 0);
5178 /*---------------------------------------------------------------*/
5179 /* Have our lmf.previous_lmf point to the last lmf */
5180 /*---------------------------------------------------------------*/
5181 s390_stg (code, s390_r0, 0, s390_r13,
5182 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5184 /*---------------------------------------------------------------*/
5185 /* save method info */
5186 /*---------------------------------------------------------------*/
5187 S390_SET (code, s390_r1, method);
5188 s390_stg (code, s390_r1, 0, s390_r13,
5189 G_STRUCT_OFFSET(MonoLMF, method));
5191 /*---------------------------------------------------------------*/
5192 /* save the current IP */
5193 /*---------------------------------------------------------------*/
5194 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5195 s390_basr (code, s390_r1, 0);
5196 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5198 /*---------------------------------------------------------------*/
5199 /* Save general and floating point registers */
5200 /*---------------------------------------------------------------*/
5201 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5202 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5203 for (i = 0; i < 16; i++) {
5204 s390_std (code, i, 0, s390_r13,
5205 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5208 /*---------------------------------------------------------------*/
5209 /* Restore the parameter registers now that we've set up the lmf */
5210 /*---------------------------------------------------------------*/
5211 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5212 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5216 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5218 cfg->code_len = code - cfg->native_code;
5219 g_assert (cfg->code_len < cfg->code_size);
5224 /*========================= End of Function ========================*/
5226 /*------------------------------------------------------------------*/
5228 /* Name - mono_arch_emit_epilog */
5230 /* Function - Emit the instructions for a function epilog. */
5232 /*------------------------------------------------------------------*/
5235 mono_arch_emit_epilog (MonoCompile *cfg)
5237 MonoMethod *method = cfg->method;
5240 int max_epilog_size = 96;
5242 if (cfg->method->save_lmf)
5243 max_epilog_size += 128;
5245 if (mono_jit_trace_calls != NULL)
5246 max_epilog_size += 128;
5247 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5248 max_epilog_size += 128;
5250 while ((cfg->code_len + max_epilog_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 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5259 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5263 if (method->save_lmf)
5264 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5266 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5267 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5269 code = backUpStackPtr(cfg, code);
5271 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5272 s390_br (code, s390_r14);
5274 cfg->code_len = code - cfg->native_code;
5276 g_assert (cfg->code_len < cfg->code_size);
5280 /*========================= End of Function ========================*/
5282 /*------------------------------------------------------------------*/
5284 /* Name - mono_arch_emit_exceptions */
5286 /* Function - Emit the blocks to handle exception conditions. */
5288 /*------------------------------------------------------------------*/
5291 mono_arch_emit_exceptions (MonoCompile *cfg)
5293 MonoJumpInfo *patch_info;
5299 MonoClass *exc_classes [MAX_EXC];
5300 guint8 *exc_throw_start [MAX_EXC];
5302 for (patch_info = cfg->patch_info;
5304 patch_info = patch_info->next) {
5305 if (patch_info->type == MONO_PATCH_INFO_EXC)
5309 code_size = exc_count * 48;
5311 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5312 cfg->code_size *= 2;
5313 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5314 cfg->stat_code_reallocs++;
5317 code = cfg->native_code + cfg->code_len;
5319 /*---------------------------------------------------------------------*/
5320 /* Add code to raise exceptions */
5321 /*---------------------------------------------------------------------*/
5322 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5323 switch (patch_info->type) {
5324 case MONO_PATCH_INFO_EXC: {
5325 guint8 *ip = patch_info->ip.i + cfg->native_code;
5326 MonoClass *exc_class;
5329 /*-----------------------------------------------------*/
5330 /* Patch the branch in epilog to come here */
5331 /*-----------------------------------------------------*/
5332 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5334 exc_class = mono_class_from_name (mono_defaults.corlib,
5336 patch_info->data.name);
5337 g_assert (exc_class);
5338 throw_ip = patch_info->ip.i;
5340 for (iExc = 0; iExc < nThrows; ++iExc)
5341 if (exc_classes [iExc] == exc_class)
5344 if (iExc < nThrows) {
5345 s390_jcl (code, S390_CC_UN,
5346 (guint64) exc_throw_start [iExc]);
5347 patch_info->type = MONO_PATCH_INFO_NONE;
5350 if (nThrows < MAX_EXC) {
5351 exc_classes [nThrows] = exc_class;
5352 exc_throw_start [nThrows] = code;
5355 /*---------------------------------------------*/
5356 /* Patch the parameter passed to the handler */
5357 /*---------------------------------------------*/
5358 S390_SET (code, s390_r2, exc_class->type_token);
5359 /*---------------------------------------------*/
5360 /* Load return address & parameter register */
5361 /*---------------------------------------------*/
5362 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5363 cfg->native_code + 8), code));
5364 /*---------------------------------------------*/
5365 /* Reuse the current patch to set the jump */
5366 /*---------------------------------------------*/
5367 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5368 patch_info->data.name = "mono_arch_throw_corlib_exception";
5369 patch_info->ip.i = code - cfg->native_code;
5370 S390_BR_TEMPLATE (code, s390_r1);
5380 cfg->code_len = code - cfg->native_code;
5382 g_assert (cfg->code_len < cfg->code_size);
5386 /*========================= End of Function ========================*/
5388 /*------------------------------------------------------------------*/
5390 /* Name - mono_arch_finish_init */
5392 /* Function - Setup the JIT's Thread Level Specific Data. */
5394 /*------------------------------------------------------------------*/
5397 mono_arch_finish_init (void)
5399 appdomain_tls_offset = mono_domain_get_tls_offset();
5400 lmf_tls_offset = mono_get_lmf_tls_offset();
5401 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5404 /*========================= End of Function ========================*/
5406 /*------------------------------------------------------------------*/
5408 /* Name - mono_arch_free_jit_tls_data */
5410 /* Function - Free tls data. */
5412 /*------------------------------------------------------------------*/
5415 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5419 /*========================= End of Function ========================*/
5421 /*------------------------------------------------------------------*/
5423 /* Name - mono_arch_emit_inst_for_method */
5425 /*------------------------------------------------------------------*/
5428 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5433 /*========================= End of Function ========================*/
5435 /*------------------------------------------------------------------*/
5437 /* Name - mono_arch_decompose_opts */
5439 /* Function - Decompose opcode into a System z opcode. */
5441 /*------------------------------------------------------------------*/
5444 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5447 * Have to rename these to avoid being decomposed normally, since the normal
5448 * decomposition does not work on S390.
5450 switch (ins->opcode) {
5452 ins->opcode = OP_S390_ISUB_OVF;
5454 case OP_ISUB_OVF_UN:
5455 ins->opcode = OP_S390_ISUB_OVF_UN;
5458 ins->opcode = OP_S390_IADD_OVF;
5460 case OP_IADD_OVF_UN:
5461 ins->opcode = OP_S390_IADD_OVF_UN;
5464 ins->opcode = OP_S390_LADD_OVF;
5466 case OP_LADD_OVF_UN:
5467 ins->opcode = OP_S390_LADD_OVF_UN;
5470 ins->opcode = OP_S390_LSUB_OVF;
5472 case OP_LSUB_OVF_UN:
5473 ins->opcode = OP_S390_LSUB_OVF_UN;
5480 /*========================= End of Function ========================*/
5482 /*------------------------------------------------------------------*/
5484 /* Name - mono_arch_print_tree */
5486 /* Function - Print platform-specific opcode details. */
5488 /* Returns - 1 - opcode details have been printed */
5489 /* 0 - opcode details have not been printed */
5491 /*------------------------------------------------------------------*/
5494 mono_arch_print_tree (MonoInst *tree, int arity)
5498 switch (tree->opcode) {
5499 case OP_S390_LOADARG:
5500 case OP_S390_ARGREG:
5501 case OP_S390_ARGPTR:
5502 printf ("[0x%lx(%s)]", tree->inst_offset,
5503 mono_arch_regname (tree->inst_basereg));
5506 case OP_S390_STKARG:
5507 printf ("[0x%lx(previous_frame)]",
5512 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5513 tree->inst_offset, tree->backend.size,
5514 mono_arch_regname(tree->dreg),
5516 mono_arch_regname(tree->sreg1));
5519 case OP_S390_SETF4RET:
5520 printf ("[f%s,f%s]",
5521 mono_arch_regname (tree->dreg),
5522 mono_arch_regname (tree->sreg1));
5526 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5528 mono_arch_regname (tree->sreg1));
5531 case OP_S390_BKCHAIN:
5532 printf ("[previous_frame(%s)]",
5533 mono_arch_regname (tree->sreg1));
5541 /*========================= End of Function ========================*/
5543 /*------------------------------------------------------------------*/
5545 /* Name - mono_arch_regalloc_cost */
5547 /* Function - Determine the cost, in the number of memory */
5548 /* references, of the action of allocating the var- */
5549 /* iable VMV into a register during global register */
5552 /* Returns - Cost */
5554 /*------------------------------------------------------------------*/
5557 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5563 /*========================= End of Function ========================*/
5565 /*------------------------------------------------------------------*/
5567 /* Name - mono_arch_flush_register_windows */
5573 /*------------------------------------------------------------------*/
5576 mono_arch_flush_register_windows (void)
5580 /*========================= End of Function ========================*/
5582 /*------------------------------------------------------------------*/
5584 /* Name - mono_arch_is_inst_imm */
5586 /* Function - Determine if operand qualifies as an immediate */
5587 /* value. For s390 this is a value -32768-32768 */
5589 /* Returns - True|False - is [not] immediate value. */
5591 /*------------------------------------------------------------------*/
5594 mono_arch_is_inst_imm (gint64 imm)
5596 return s390_is_imm32 (imm);
5599 /*========================= End of Function ========================*/
5601 /*------------------------------------------------------------------*/
5603 /* Name - mono_arch_get_patch_offset */
5605 /* Function - Dummy entry point until s390x supports aot. */
5607 /* Returns - Offset for patch. */
5609 /*------------------------------------------------------------------*/
5612 mono_arch_get_patch_offset (guint8 *code)
5617 /*========================= End of Function ========================*/
5619 /*------------------------------------------------------------------*/
5621 /* Name - mono_arch_context_get_int_reg. */
5625 /* Returns - Return a register from the context. */
5627 /*------------------------------------------------------------------*/
5630 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5632 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5635 /*========================= End of Function ========================*/
5637 /*------------------------------------------------------------------*/
5639 /* Name - mono_arch_context_set_int_reg. */
5641 /* Function - Set a value in a specified register. */
5643 /*------------------------------------------------------------------*/
5646 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5648 ctx->uc_mcontext.gregs[reg] = val;
5651 /*========================= End of Function ========================*/
5653 /*------------------------------------------------------------------*/
5655 /* Name - mono_arch_get_this_arg_from_call. */
5659 /*------------------------------------------------------------------*/
5662 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5664 return (gpointer) regs [s390_r2];
5667 /*========================= End of Function ========================*/
5669 /*------------------------------------------------------------------*/
5671 /* Name - mono_arch_install_handler_block_guard */
5675 /*------------------------------------------------------------------*/
5678 mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause,
5679 MonoContext *ctx, gpointer new_value)
5682 gpointer *sp, old_value;
5685 offset = clause->exvar_offset;
5688 bp = MONO_CONTEXT_GET_BP (ctx);
5689 sp = *(gpointer*)(bp + offset);
5692 if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size))
5700 /*========================= End of Function ========================*/
5702 /*------------------------------------------------------------------*/
5704 /* Name - get_delegate_invoke_impl. */
5708 /*------------------------------------------------------------------*/
5711 get_delegate_invoke_impl (MonoTrampInfo **info, gboolean has_target, guint32 param_count, gboolean aot)
5713 guint8 *code, *start;
5718 start = code = mono_global_codeman_reserve (size);
5720 /* Replace the this argument with the target */
5721 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5722 s390_lg (code, s390_r2, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, target));
5723 s390_br (code, s390_r1);
5724 g_assert ((code - start) <= size);
5726 mono_arch_flush_icache (start, size);
5730 size = 32 + param_count * 8;
5731 start = code = mono_global_codeman_reserve (size);
5733 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5734 /* slide down the arguments */
5735 for (i = 0; i < param_count; ++i) {
5736 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5738 s390_br (code, s390_r1);
5740 g_assert ((code - start) <= size);
5742 mono_arch_flush_icache (start, size);
5745 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL);
5748 *info = mono_tramp_info_create ("delegate_invoke_impl_has_target", start, code - start, NULL, NULL);
5750 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", param_count);
5751 *info = mono_tramp_info_create (name, start, code - start, NULL, NULL);
5758 /*========================= End of Function ========================*/
5760 /*------------------------------------------------------------------*/
5762 /* Name - mono_arch_get_delegate_invoke_impls. */
5766 /*------------------------------------------------------------------*/
5769 mono_arch_get_delegate_invoke_impls (void)
5772 MonoTrampInfo *info;
5775 get_delegate_invoke_impl (&info, TRUE, 0, TRUE);
5776 res = g_slist_prepend (res, info);
5778 for (i = 0; i <= MAX_ARCH_DELEGATE_PARAMS; ++i) {
5779 get_delegate_invoke_impl (&info, FALSE, i, TRUE);
5780 res = g_slist_prepend (res, info);
5786 /*========================= End of Function ========================*/
5788 /*------------------------------------------------------------------*/
5790 /* Name - mono_arch_get_delegate_invoke_impl. */
5794 /*------------------------------------------------------------------*/
5797 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5799 guint8 *code, *start;
5801 /* FIXME: Support more cases */
5802 if (MONO_TYPE_ISSTRUCT (sig->ret))
5806 static guint8* cached = NULL;
5811 if (mono_aot_only) {
5812 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5814 MonoTrampInfo *info;
5815 start = get_delegate_invoke_impl (&info, TRUE, 0, FALSE);
5816 mono_tramp_info_register (info, NULL);
5819 mono_memory_barrier ();
5823 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5826 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5828 for (i = 0; i < sig->param_count; ++i)
5829 if (!mono_is_regsize_var (sig->params [i]))
5833 code = cache [sig->param_count];
5837 if (mono_aot_only) {
5838 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5839 start = mono_aot_get_trampoline (name);
5842 MonoTrampInfo *info;
5843 start = get_delegate_invoke_impl (&info, FALSE, sig->param_count, FALSE);
5844 mono_tramp_info_register (info, NULL);
5847 mono_memory_barrier ();
5849 cache [sig->param_count] = start;
5854 /*========================= End of Function ========================*/
5856 /*------------------------------------------------------------------*/
5858 /* Name - mono_arch_get_delegate_virtual_invoke_impl. */
5862 /*------------------------------------------------------------------*/
5865 mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method,
5866 int offset, gboolean load_imt_reg)
5868 guint8 *code, *start;
5871 start = code = mono_global_codeman_reserve (size);
5874 * Replace the "this" argument with the target
5876 s390_lgr (code, s390_r1, s390_r2);
5877 s390_lg (code, s390_r2, 0, s390_r1, MONO_STRUCT_OFFSET(MonoDelegate, target));
5880 * Load the IMT register, if needed
5883 s390_lg (code, MONO_ARCH_IMT_REG, 0, s390_r1, MONO_STRUCT_OFFSET(MonoDelegate, method));
5889 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET(MonoObject, vtable));
5891 s390_agfi(code, s390_r1, offset);
5893 s390_lg (code, s390_r1, 0, s390_r1, 0);
5894 s390_br (code, s390_r1);
5899 /*========================= End of Function ========================*/
5901 /*------------------------------------------------------------------*/
5903 /* Name - mono_arch_build_imt_thunk. */
5907 /*------------------------------------------------------------------*/
5910 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5911 MonoIMTCheckItem **imt_entries, int count,
5912 gpointer fail_tramp)
5916 guchar *code, *start;
5918 for (i = 0; i < count; ++i) {
5919 MonoIMTCheckItem *item = imt_entries [i];
5920 if (item->is_equals) {
5921 if (item->check_target_idx) {
5922 if (!item->compare_done)
5923 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5924 if (item->has_target_code)
5925 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5927 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5931 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5933 if (!item->has_target_code)
5934 item->chunk_size += LOAD_SIZE;
5936 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5937 #if ENABLE_WRONG_METHOD_CHECK
5938 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5943 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5944 imt_entries [item->check_target_idx]->compare_done = TRUE;
5946 size += item->chunk_size;
5950 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5952 code = mono_domain_code_reserve (domain, size);
5956 for (i = 0; i < count; ++i) {
5957 MonoIMTCheckItem *item = imt_entries [i];
5958 item->code_target = (guint8 *) code;
5959 if (item->is_equals) {
5960 if (item->check_target_idx) {
5961 if (!item->compare_done) {
5962 S390_SET (code, s390_r0, item->key);
5963 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5965 item->jmp_code = (guint8*) code;
5966 s390_jcl (code, S390_CC_NE, 0);
5968 if (item->has_target_code) {
5969 S390_SET (code, s390_r1, item->value.target_code);
5971 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5972 s390_lg (code, s390_r1, 0, s390_r1, 0);
5974 s390_br (code, s390_r1);
5979 S390_SET (code, s390_r0, item->key);
5980 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5981 item->jmp_code = (guint8*) code;
5982 s390_jcl (code, S390_CC_NE, 0);
5983 if (item->has_target_code) {
5984 S390_SET (code, s390_r1, item->value.target_code);
5987 S390_SET (code, s390_r1,
5988 (&(vtable->vtable [item->value.vtable_slot])));
5989 s390_lg (code, s390_r1, 0, s390_r1, 0);
5991 s390_br (code, s390_r1);
5992 target = (gint64) S390_RELATIVE(code, item->jmp_code);
5993 s390_patch_rel(item->jmp_code+2, target);
5994 S390_SET (code, s390_r1, fail_tramp);
5995 s390_br (code, s390_r1);
5996 item->jmp_code = NULL;
5998 /* enable the commented code to assert on wrong method */
5999 #if ENABLE_WRONG_METHOD_CHECK
6000 g_assert_not_reached ();
6002 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
6003 s390_lg (code, s390_r1, 0, s390_r1, 0);
6004 s390_br (code, s390_r1);
6008 S390_SET (code, s390_r0, item->key);
6009 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6010 item->jmp_code = (guint8 *) code;
6011 s390_jcl (code, S390_CC_GE, 0);
6015 * patch the branches to get to the target items
6017 for (i = 0; i < count; ++i) {
6018 MonoIMTCheckItem *item = imt_entries [i];
6019 if (item->jmp_code) {
6020 if (item->check_target_idx) {
6022 offset = (gint64) S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6024 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6029 mono_arch_flush_icache ((guint8*)start, (code - start));
6030 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL);
6033 mono_stats.imt_thunks_size += (code - start);
6035 g_assert (code - start <= size);
6037 mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), domain);
6042 /*========================= End of Function ========================*/
6044 /*------------------------------------------------------------------*/
6046 /* Name - mono_arch_find_imt_method. */
6048 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6049 /* found in the save area. */
6051 /*------------------------------------------------------------------*/
6054 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6056 return ((MonoMethod *) regs [MONO_ARCH_IMT_REG]);
6059 /*========================= End of Function ========================*/
6061 /*------------------------------------------------------------------*/
6063 /* Name - mono_arch_find_static_call_vtable */
6065 /* Function - Find the static call vtable. */
6067 /*------------------------------------------------------------------*/
6070 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
6072 mgreg_t *r = (mgreg_t*)regs;
6074 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
6077 /*========================= End of Function ========================*/
6079 /*------------------------------------------------------------------*/
6081 /* Name - mono_arch_get_cie_program */
6083 /* Function - Find the static call vtable. */
6085 /*------------------------------------------------------------------*/
6088 mono_arch_get_cie_program (void)
6092 mono_add_unwind_op_def_cfa (l, 0, 0, STK_BASE, 0);
6097 /*========================= End of Function ========================*/
6099 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6101 /*------------------------------------------------------------------*/
6103 /* Name - mono_arch_set_breakpoint. */
6105 /* Function - Set a breakpoint at the native code corresponding */
6106 /* to JI at NATIVE_OFFSET. The location should */
6107 /* contain code emitted by OP_SEQ_POINT. */
6109 /*------------------------------------------------------------------*/
6112 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6116 breakpointCode.pTrigger = bp_trigger_page;
6117 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6118 code += BREAKPOINT_SIZE;
6121 /*========================= End of Function ========================*/
6123 /*------------------------------------------------------------------*/
6125 /* Name - mono_arch_clear_breakpoint. */
6127 /* Function - Clear the breakpoint at IP. */
6129 /*------------------------------------------------------------------*/
6132 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6137 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6141 /*========================= End of Function ========================*/
6143 /*------------------------------------------------------------------*/
6145 /* Name - mono_arch_is_breakpoint_event. */
6149 /*------------------------------------------------------------------*/
6152 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6154 siginfo_t* sinfo = (siginfo_t*) info;
6157 * Sometimes the address is off by 4
6159 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6165 /*========================= End of Function ========================*/
6167 /*------------------------------------------------------------------*/
6169 /* Name - mono_arch_skip_breakpoint. */
6171 /* Function - Modify the CTX so the IP is placed after the */
6172 /* breakpoint instruction, so when we resume, the */
6173 /* instruction is not executed again. */
6175 /*------------------------------------------------------------------*/
6178 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6180 MONO_CONTEXT_SET_IP (ctx, ((guint8*)MONO_CONTEXT_GET_IP (ctx) + sizeof(RXY_Format)));
6183 /*========================= End of Function ========================*/
6185 /*------------------------------------------------------------------*/
6187 /* Name - mono_arch_start_single_stepping. */
6189 /* Function - Start single stepping. */
6191 /*------------------------------------------------------------------*/
6194 mono_arch_start_single_stepping (void)
6196 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6199 /*========================= End of Function ========================*/
6201 /*------------------------------------------------------------------*/
6203 /* Name - mono_arch_stop_single_stepping. */
6205 /* Function - Stop single stepping. */
6207 /*------------------------------------------------------------------*/
6210 mono_arch_stop_single_stepping (void)
6212 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6215 /*========================= End of Function ========================*/
6217 /*------------------------------------------------------------------*/
6219 /* Name - mono_arch_is_single_step_event. */
6221 /* Function - Return whether the machine state in sigctx cor- */
6222 /* responds to a single step event. */
6224 /*------------------------------------------------------------------*/
6227 mono_arch_is_single_step_event (void *info, void *sigctx)
6229 siginfo_t* sinfo = (siginfo_t*) info;
6232 * Sometimes the address is off by 4
6234 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6240 /*========================= End of Function ========================*/
6242 /*------------------------------------------------------------------*/
6244 /* Name - mono_arch_skip_single_step. */
6246 /* Function - Modify the ctx so the IP is placed after the */
6247 /* single step trigger instruction, so that the */
6248 /* instruction is not executed again. */
6250 /*------------------------------------------------------------------*/
6253 mono_arch_skip_single_step (MonoContext *ctx)
6255 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6258 /*========================= End of Function ========================*/
6260 /*------------------------------------------------------------------*/
6262 /* Name - mono_arch_create_seq_point_info. */
6264 /* Function - Return a pointer to a data struction which is */
6265 /* used by the sequence point implementation in */
6268 /*------------------------------------------------------------------*/
6271 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6277 /*------------------------------------------------------------------*/
6279 /* Name - mono_arch_init_lmf_ext. */
6283 /*------------------------------------------------------------------*/
6286 mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
6288 ext->lmf.previous_lmf = prev_lmf;
6289 /* Mark that this is a MonoLMFExt */
6290 ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
6291 ext->lmf.ebp = (gssize)ext;
6294 /*========================= End of Function ========================*/
6299 mono_arch_opcode_supported (int opcode)
6302 case OP_ATOMIC_ADD_I4:
6303 case OP_ATOMIC_ADD_I8:
6304 case OP_ATOMIC_EXCHANGE_I4:
6305 case OP_ATOMIC_EXCHANGE_I8: