1 /*------------------------------------------------------------------*/
3 /* Name - mini-s390.c */
5 /* Function - S/390 backend for the Mono code generator. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 #define MAX_ARCH_DELEGATE_PARAMS 7
23 #define EMIT_COND_BRANCH(ins,cond) \
25 if (ins->inst_true_bb->native_offset) { \
27 displace = ((cfg->native_code + \
28 ins->inst_true_bb->native_offset) - code) / 2; \
29 if (s390_is_imm16(displace)) { \
30 s390_brc (code, cond, displace); \
32 s390_jcl (code, cond, displace); \
35 mono_add_patch_info (cfg, code - cfg->native_code, \
36 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
37 s390_jcl (code, cond, 0); \
41 #define EMIT_UNCOND_BRANCH(ins) \
43 if (ins->inst_target_bb->native_offset) { \
45 displace = ((cfg->native_code + \
46 ins->inst_target_bb->native_offset) - code) / 2; \
47 if (s390_is_imm16(displace)) { \
48 s390_brc (code, S390_CC_UN, displace); \
50 s390_jcl (code, S390_CC_UN, displace); \
53 mono_add_patch_info (cfg, code - cfg->native_code, \
54 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
55 s390_jcl (code, S390_CC_UN, 0); \
59 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
61 mono_add_patch_info (cfg, code - cfg->native_code, \
62 MONO_PATCH_INFO_EXC, exc_name); \
63 s390_jcl (code, cond, 0); \
66 #define CHECK_SRCDST_COM \
67 if (ins->dreg == ins->sreg2) { \
71 if (ins->dreg != ins->sreg1) { \
72 s390_lgr (code, ins->dreg, ins->sreg1); \
76 #define CHECK_SRCDST_NCOM \
77 if (ins->dreg == ins->sreg2) { \
79 s390_lgr (code, s390_r13, ins->sreg2); \
83 if (ins->dreg != ins->sreg1) { \
84 s390_lgr (code, ins->dreg, ins->sreg1); \
87 #define CHECK_SRCDST_COM_I \
88 if (ins->dreg == ins->sreg2) { \
92 if (ins->dreg != ins->sreg1) { \
93 s390_lgfr (code, ins->dreg, ins->sreg1); \
97 #define CHECK_SRCDST_NCOM_I \
98 if (ins->dreg == ins->sreg2) { \
100 s390_lgfr (code, s390_r13, ins->sreg2); \
104 if (ins->dreg != ins->sreg1) { \
105 s390_lgfr (code, ins->dreg, ins->sreg1); \
108 #define CHECK_SRCDST_COM_F \
109 if (ins->dreg == ins->sreg2) { \
113 if (ins->dreg != ins->sreg1) { \
114 s390_ldr (code, ins->dreg, ins->sreg1); \
118 #define CHECK_SRCDST_NCOM_F \
119 if (ins->dreg == ins->sreg2) { \
121 s390_ldr (code, s390_r13, ins->sreg2); \
125 if (ins->dreg != ins->sreg1) { \
126 s390_ldr (code, ins->dreg, ins->sreg1); \
129 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
132 MONO_INST_NEW (cfg, inst, OP_NOP); \
135 inst->inst_offset = offset; \
137 inst->inst_imm = imm; \
139 if (s390_is_uimm12(offset)) { \
141 inst->inst_offset = offset; \
143 dReg = mono_alloc_preg (cfg); \
144 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
145 dReg, dest, offset); \
147 inst->inst_offset = 0; \
149 if (s390_is_uimm12(imm)) { \
151 inst->inst_imm = imm; \
153 sReg = mono_alloc_preg (cfg); \
154 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
156 inst->sreg1 = sReg; \
157 inst->inst_imm = 0; \
160 inst->opcode = OP_S390_MOVE; \
161 inst->backend.size = size; \
162 MONO_ADD_INS (cfg->cbb, inst); \
165 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
166 int reg = mono_alloc_preg (cfg); \
169 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
172 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
176 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
180 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
184 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
188 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
191 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
195 tmpr = mono_alloc_preg (cfg); \
196 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
197 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
201 tmpr = mono_alloc_preg (cfg); \
202 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
204 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
208 tmpr = mono_alloc_preg (cfg); \
209 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
211 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
215 tmpr = mono_alloc_preg (cfg); \
216 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
218 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
222 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
228 #define DEBUG(a) if (cfg->verbose_level > 1) a
232 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
234 #define BREAKPOINT_SIZE sizeof(breakpoint_t)
235 #define S390X_NOP_SIZE sizeof(RR_Format)
237 #define MAX(a, b) ((a) > (b) ? (a) : (b))
240 * imt thunking size values
243 #define LOADCON_SIZE 20
247 #define ENABLE_WRONG_METHOD_CHECK 0
249 #define mono_mini_arch_lock() mono_mutex_lock (&mini_arch_mutex)
250 #define mono_mini_arch_unlock() mono_mutex_unlock (&mini_arch_mutex)
252 /*========================= End of Defines =========================*/
254 /*------------------------------------------------------------------*/
255 /* I n c l u d e s */
256 /*------------------------------------------------------------------*/
260 #include <sys/types.h>
263 #include <mono/metadata/abi-details.h>
264 #include <mono/metadata/appdomain.h>
265 #include <mono/metadata/debug-helpers.h>
266 #include <mono/metadata/profiler-private.h>
267 #include <mono/utils/mono-math.h>
268 #include <mono/utils/mono-mmap.h>
269 #include <mono/utils/mono-hwcap-s390x.h>
270 #include <mono/utils/mono-threads.h>
272 #include "mini-s390x.h"
273 #include "cpu-s390x.h"
274 #include "support-s390x.h"
275 #include "jit-icalls.h"
279 /*========================= End of Includes ========================*/
281 /*------------------------------------------------------------------*/
282 /* T y p e d e f s */
283 /*------------------------------------------------------------------*/
295 /*------------------------------------------------------------------*/
296 /* Used by the instrument_emit_epilog */
297 /*------------------------------------------------------------------*/
308 typedef struct InstList InstList;
322 RegTypeStructByValInFP,
324 RegTypeStructByAddrOnStack
328 gint32 offset; /* offset from caller's stack */
329 gint32 offparm; /* offset from callee's stack */
330 guint16 vtsize; /* in param area */
333 guint32 size; /* Size of structure used by RegTypeStructByVal */
334 gint32 type; /* Data type of argument */
350 gint64 gr[5]; /* R2-R6 */
351 gdouble fp[3]; /* F0-F2 */
352 } __attribute__ ((packed)) RegParm;
360 } __attribute__ ((packed)) breakpoint_t;
362 /*========================= End of Typedefs ========================*/
364 /*------------------------------------------------------------------*/
365 /* P r o t o t y p e s */
366 /*------------------------------------------------------------------*/
368 static void indent (int);
369 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
370 static void decodeParm (MonoType *, void *, int);
371 static void enter_method (MonoMethod *, RegParm *, char *);
372 static void leave_method (MonoMethod *, ...);
373 static inline void add_general (guint *, size_data *, ArgInfo *);
374 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
375 static inline void add_float (guint *, size_data *, ArgInfo *);
376 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
377 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
378 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
379 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
381 /*========================= End of Prototypes ======================*/
383 /*------------------------------------------------------------------*/
384 /* G l o b a l V a r i a b l e s */
385 /*------------------------------------------------------------------*/
387 int mono_exc_esp_offset = 0;
389 __thread int indent_level = 0;
391 static gint appdomain_tls_offset = -1,
393 lmf_addr_tls_offset = -1;
395 pthread_key_t lmf_addr_key;
397 gboolean lmf_addr_key_inited = FALSE;
402 * The code generated for sequence points reads from this location,
403 * which is made read-only when single stepping is enabled.
405 static gpointer ss_trigger_page;
408 * Enabled breakpoints read from this trigger page
410 static gpointer bp_trigger_page;
412 breakpoint_t breakpointCode;
414 static mono_mutex_t mini_arch_mutex;
416 /*====================== End of Global Variables ===================*/
418 /*------------------------------------------------------------------*/
420 /* Name - mono_arch_regname */
422 /* Function - Returns the name of the register specified by */
423 /* the input parameter. */
425 /*------------------------------------------------------------------*/
428 mono_arch_regname (int reg) {
429 static const char * rnames[] = {
430 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
431 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
432 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
436 if (reg >= 0 && reg < 16)
442 /*========================= End of Function ========================*/
444 /*------------------------------------------------------------------*/
446 /* Name - mono_arch_fregname */
448 /* Function - Returns the name of the register specified by */
449 /* the input parameter. */
451 /*------------------------------------------------------------------*/
454 mono_arch_fregname (int reg) {
455 static const char * rnames[] = {
456 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
457 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
458 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
462 if (reg >= 0 && reg < 16)
468 /*========================= End of Function ========================*/
470 /*------------------------------------------------------------------*/
472 /* Name - arch_get_argument_info */
474 /* Function - Gathers information on parameters such as size, */
475 /* alignment, and padding. arg_info should be large */
476 /* enough to hold param_count + 1 entries. */
478 /* Parameters - @csig - Method signature */
479 /* @param_count - No. of parameters to consider */
480 /* @arg_info - An array to store the result info */
482 /* Returns - Size of the activation frame */
484 /*------------------------------------------------------------------*/
487 mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig,
489 MonoJitArgumentInfo *arg_info)
491 int k, frame_size = 0;
492 int size, align, pad;
495 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
496 frame_size += sizeof (gpointer);
500 arg_info [0].offset = offset;
503 frame_size += sizeof (gpointer);
507 arg_info [0].size = frame_size;
509 for (k = 0; k < param_count; k++) {
512 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
514 size = mini_type_stack_size (NULL, csig->params [k], &align);
516 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
517 arg_info [k].pad = pad;
519 arg_info [k + 1].pad = 0;
520 arg_info [k + 1].size = size;
522 arg_info [k + 1].offset = offset;
526 align = MONO_ARCH_FRAME_ALIGNMENT;
527 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
528 arg_info [k].pad = pad;
533 /*========================= End of Function ========================*/
535 /*------------------------------------------------------------------*/
537 /* Name - emit_unwind_regs. */
539 /* Function - Determines if a value can be returned in one or */
542 /*------------------------------------------------------------------*/
544 static void __inline__
545 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
549 for (i = start; i < end; i++) {
550 mono_emit_unwind_op_offset (cfg, code, i, offset);
551 offset += sizeof(gulong);
555 /*========================= End of Function ========================*/
557 /*------------------------------------------------------------------*/
559 /* Name - retFitsInReg. */
561 /* Function - Determines if a value can be returned in one or */
564 /*------------------------------------------------------------------*/
566 static inline gboolean
567 retFitsInReg(guint32 size)
582 /*========================= End of Function ========================*/
584 /*------------------------------------------------------------------*/
586 /* Name - backStackPtr. */
588 /* Function - Restore Stack Pointer to previous frame. */
590 /*------------------------------------------------------------------*/
592 static inline guint8 *
593 backUpStackPtr(MonoCompile *cfg, guint8 *code)
595 int stackSize = cfg->stack_usage;
597 if (cfg->frame_reg != STK_BASE)
598 s390_lgr (code, STK_BASE, cfg->frame_reg);
600 if (s390_is_imm16 (stackSize)) {
601 s390_aghi (code, STK_BASE, stackSize);
603 while (stackSize > 32767) {
604 s390_aghi (code, STK_BASE, 32767);
607 s390_aghi (code, STK_BASE, stackSize);
612 /*========================= End of Function ========================*/
614 /*------------------------------------------------------------------*/
618 /* Function - Perform nice indenting to current level */
620 /*------------------------------------------------------------------*/
626 indent_level += diff;
628 printf("%p [%3d] ",(void *)pthread_self(),v);
633 indent_level += diff;
636 /*========================= End of Function ========================*/
638 /*------------------------------------------------------------------*/
640 /* Name - cvtMonoType */
642 /* Function - Convert a mono-type to a string. */
644 /*------------------------------------------------------------------*/
647 cvtMonoType(MonoTypeEnum t)
652 return "MONO_TYPE_END";
654 return "MONO_TYPE_VOID";
655 case MONO_TYPE_BOOLEAN:
656 return "MONO_TYPE_BOOLEAN";
658 return "MONO_TYPE_CHAR";
660 return "MONO_TYPE_I1";
662 return "MONO_TYPE_U1";
664 return "MONO_TYPE_I2";
666 return "MONO_TYPE_U2";
668 return "MONO_TYPE_I4";
670 return "MONO_TYPE_U4";
672 return "MONO_TYPE_I8";
674 return "MONO_TYPE_U8";
676 return "MONO_TYPE_R4";
678 return "MONO_TYPE_R8";
679 case MONO_TYPE_STRING:
680 return "MONO_TYPE_STRING";
682 return "MONO_TYPE_PTR";
683 case MONO_TYPE_BYREF:
684 return "MONO_TYPE_BYREF";
685 case MONO_TYPE_VALUETYPE:
686 return "MONO_TYPE_VALUETYPE";
687 case MONO_TYPE_CLASS:
688 return "MONO_TYPE_CLASS";
690 return "MONO_TYPE_VAR";
691 case MONO_TYPE_ARRAY:
692 return "MONO_TYPE_ARRAY";
693 case MONO_TYPE_GENERICINST:
694 return "MONO_TYPE_GENERICINST";
695 case MONO_TYPE_TYPEDBYREF:
696 return "MONO_TYPE_TYPEDBYREF";
698 return "MONO_TYPE_I";
700 return "MONO_TYPE_U";
701 case MONO_TYPE_FNPTR:
702 return "MONO_TYPE_FNPTR";
703 case MONO_TYPE_OBJECT:
704 return "MONO_TYPE_OBJECT";
705 case MONO_TYPE_SZARRAY:
706 return "MONO_TYPE_SZARRAY";
708 return "MONO_TYPE_MVAR";
709 case MONO_TYPE_CMOD_REQD:
710 return "MONO_TYPE_CMOD_REQD";
711 case MONO_TYPE_CMOD_OPT:
712 return "MONO_TYPE_CMOD_OPT";
713 case MONO_TYPE_INTERNAL:
714 return "MONO_TYPE_INTERNAL";
715 case MONO_TYPE_MODIFIER:
716 return "MONO_TYPE_MODIFIER";
717 case MONO_TYPE_SENTINEL:
718 return "MONO_TYPE_SENTINEL";
719 case MONO_TYPE_PINNED:
720 return "MONO_TYPE_PINNED";
727 /*========================= End of Function ========================*/
729 /*------------------------------------------------------------------*/
731 /* Name - decodeParm */
733 /* Function - Decode a parameter for the trace. */
735 /*------------------------------------------------------------------*/
738 decodeParm(MonoType *type, void *curParm, int size)
743 printf("[BYREF:%p], ", *((char **) curParm));
745 simpleType = mono_type_get_underlying_type(type)->type;
747 switch (simpleType) {
749 printf ("[INTPTR:%p], ", *((int **) curParm));
752 printf ("[UINTPTR:%p], ", *((int **) curParm));
754 case MONO_TYPE_BOOLEAN :
755 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
757 case MONO_TYPE_CHAR :
758 printf ("[CHAR:%c], ", *((int *) curParm));
761 printf ("[INT1:%ld], ", *((gint64 *) curParm));
764 printf ("[INT2:%ld], ", *((gint64 *) curParm));
767 printf ("[INT4:%ld], ", *((gint64 *) curParm));
770 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
773 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
776 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
779 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
781 case MONO_TYPE_STRING : {
782 MonoString *s = *((MonoString **) curParm);
784 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
785 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
787 printf("[STRING:null], ");
791 case MONO_TYPE_CLASS :
792 case MONO_TYPE_OBJECT : {
793 MonoObject *obj = *((MonoObject **) curParm);
795 if ((obj) && (obj->vtable)) {
796 printf("[CLASS/OBJ:");
797 class = obj->vtable->klass;
798 printf("%p [%p] ",obj,curParm);
799 if (class == mono_defaults.string_class) {
800 printf("[STRING:%p:%s]",
801 obj, mono_string_to_utf8 ((MonoString *) obj));
802 } else if (class == mono_defaults.int32_class) {
803 printf("[INT32:%p:%d]",
804 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
807 class->name_space, class->name, obj);
810 printf("[OBJECT:null], ");
815 printf("[PTR:%p], ", *((gpointer **) (curParm)));
817 case MONO_TYPE_FNPTR :
818 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
820 case MONO_TYPE_ARRAY :
821 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
823 case MONO_TYPE_SZARRAY :
824 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
827 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
830 printf("[FLOAT4:%g], ", *((float *) (curParm)));
833 printf("[FLOAT8:%g], ", *((double *) (curParm)));
835 case MONO_TYPE_VALUETYPE : {
837 MonoMarshalType *info;
839 if (type->data.klass->enumtype) {
840 simpleType = mono_class_enum_basetype (type->data.klass)->type;
841 printf("{VALUETYPE} - ");
845 info = mono_marshal_load_type_info (type->data.klass);
847 if ((info->native_size == sizeof(float)) &&
848 (info->num_fields == 1) &&
849 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
850 printf("[FLOAT4:%f], ", *((float *) (curParm)));
854 if ((info->native_size == sizeof(double)) &&
855 (info->num_fields == 1) &&
856 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
857 printf("[FLOAT8:%g], ", *((double *) (curParm)));
861 printf("[VALUETYPE:");
862 for (i = 0; i < size; i++)
863 printf("%02x,", *((guint8 *)curParm+i));
867 case MONO_TYPE_TYPEDBYREF: {
869 printf("[TYPEDBYREF:");
870 for (i = 0; i < size; i++)
871 printf("%02x,", *((guint8 *)curParm+i));
876 printf("[%s], ",cvtMonoType(simpleType));
881 /*========================= End of Function ========================*/
883 /*------------------------------------------------------------------*/
885 /* Name - enter_method */
887 /* Function - Perform tracing of the entry to the current */
890 /*------------------------------------------------------------------*/
893 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
895 int i, oParm = 0, iParm = 0;
898 MonoMethodSignature *sig;
905 fname = mono_method_full_name (method, TRUE);
907 printf ("ENTER: %s ", fname);
910 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
911 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
916 sig = mono_method_signature (method);
918 cinfo = get_call_info (NULL, NULL, sig);
920 if (cinfo->struct_ret) {
921 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
926 gpointer *this = (gpointer *) rParm->gr[iParm];
927 obj = (MonoObject *) this;
928 switch(method->klass->this_arg.type) {
929 case MONO_TYPE_VALUETYPE:
931 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
932 printf("this:[value:%p:%016lx], ", this, *value);
934 printf ("this:[NULL], ");
936 case MONO_TYPE_STRING:
939 class = obj->vtable->klass;
940 if (class == mono_defaults.string_class) {
941 printf ("this:[STRING:%p:%s], ",
942 obj, mono_string_to_utf8 ((MonoString *)obj));
944 printf ("this:%p[%s.%s], ",
945 obj, class->name_space, class->name);
948 printf("vtable:[NULL], ");
950 printf ("this:[NULL], ");
953 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
958 for (i = 0; i < sig->param_count; ++i) {
959 ainfo = &cinfo->args[i + oParm];
960 switch (ainfo->regtype) {
961 case RegTypeGeneral :
962 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
965 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
968 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
970 case RegTypeStructByVal :
971 if (ainfo->reg != STK_BASE) {
972 int offset = sizeof(glong) - ainfo->size;
973 curParm = &(rParm->gr[ainfo->reg-2])+offset;
976 curParm = sp+ainfo->offset;
978 if (retFitsInReg (ainfo->vtsize))
979 decodeParm(sig->params[i],
983 decodeParm(sig->params[i],
984 *((char **) curParm),
987 case RegTypeStructByAddr :
988 if (ainfo->reg != STK_BASE)
989 curParm = &(rParm->gr[ainfo->reg-2]);
991 curParm = sp+ainfo->offset;
993 decodeParm(sig->params[i],
994 *((char **) curParm),
1006 /*========================= End of Function ========================*/
1008 /*------------------------------------------------------------------*/
1010 /* Name - leave_method */
1014 /*------------------------------------------------------------------*/
1017 leave_method (MonoMethod *method, ...)
1024 va_start(ap, method);
1026 fname = mono_method_full_name (method, TRUE);
1028 printf ("LEAVE: %s", fname);
1031 type = mono_method_signature (method)->ret;
1034 switch (type->type) {
1035 case MONO_TYPE_VOID:
1037 case MONO_TYPE_BOOLEAN: {
1038 int val = va_arg (ap, int);
1040 printf ("[TRUE:%d]", val);
1046 case MONO_TYPE_CHAR: {
1047 int val = va_arg (ap, int);
1048 printf ("[CHAR:%d]", val);
1051 case MONO_TYPE_I1: {
1052 int val = va_arg (ap, int);
1053 printf ("[INT1:%d]", val);
1056 case MONO_TYPE_U1: {
1057 int val = va_arg (ap, int);
1058 printf ("[UINT1:%d]", val);
1061 case MONO_TYPE_I2: {
1062 int val = va_arg (ap, int);
1063 printf ("[INT2:%d]", val);
1066 case MONO_TYPE_U2: {
1067 int val = va_arg (ap, int);
1068 printf ("[UINT2:%d]", val);
1071 case MONO_TYPE_I4: {
1072 int val = va_arg (ap, int);
1073 printf ("[INT4:%d]", val);
1076 case MONO_TYPE_U4: {
1077 int val = va_arg (ap, int);
1078 printf ("[UINT4:%d]", val);
1082 gint64 val = va_arg (ap, gint64);
1083 printf ("[INT:%ld]", val);
1088 gint64 val = va_arg (ap, gint64);
1089 printf ("[UINT:%lu]", val);
1093 case MONO_TYPE_STRING: {
1094 MonoString *s = va_arg (ap, MonoString *);
1097 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1098 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1100 printf ("[STRING:null], ");
1103 case MONO_TYPE_CLASS:
1104 case MONO_TYPE_OBJECT: {
1105 MonoObject *o = va_arg (ap, MonoObject *);
1107 if ((o) && (o->vtable)) {
1108 if (o->vtable->klass == mono_defaults.boolean_class) {
1109 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1110 } else if (o->vtable->klass == mono_defaults.int32_class) {
1111 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1112 } else if (o->vtable->klass == mono_defaults.int64_class) {
1113 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1115 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1117 printf ("[OBJECT:%p]", o);
1122 case MONO_TYPE_FNPTR:
1123 case MONO_TYPE_ARRAY:
1124 case MONO_TYPE_SZARRAY: {
1125 gpointer p = va_arg (ap, gpointer);
1126 printf ("[result=%p]", p);
1129 case MONO_TYPE_I8: {
1130 gint64 l = va_arg (ap, gint64);
1131 printf ("[LONG:%ld]", l);
1134 case MONO_TYPE_U8: {
1135 guint64 l = va_arg (ap, guint64);
1136 printf ("[ULONG:%lu]", l);
1139 case MONO_TYPE_R4: {
1140 double f = va_arg (ap, double);
1141 printf ("[FLOAT4:%g]\n", f);
1144 case MONO_TYPE_R8: {
1145 double f = va_arg (ap, double);
1146 printf ("[FLOAT8:%g]\n", f);
1149 case MONO_TYPE_VALUETYPE: {
1150 MonoMarshalType *info;
1151 if (type->data.klass->enumtype) {
1152 type = mono_class_enum_basetype (type->data.klass);
1157 info = mono_marshal_load_type_info (type->data.klass);
1159 if ((info->native_size == sizeof(float)) &&
1160 (info->num_fields == 1) &&
1161 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1162 double f = va_arg (ap, double);
1163 printf("[FLOAT4:%g]\n", (double) f);
1167 if ((info->native_size == sizeof(double)) &&
1168 (info->num_fields == 1) &&
1169 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1170 double f = va_arg (ap, double);
1171 printf("[FLOAT8:%g]\n", f);
1175 size = mono_type_size (type, &align);
1178 guint32 p = va_arg (ap, guint32);
1179 printf ("[%02x]\n",p);
1183 guint32 p = va_arg (ap, guint32);
1184 printf ("[%04x]\n",p);
1188 guint32 p = va_arg (ap, guint32);
1189 printf ("[%08x]\n",p);
1193 guint64 p = va_arg (ap, guint64);
1194 printf ("[%016lx]\n",p);
1198 gpointer p = va_arg (ap, gpointer);
1199 printf ("[VALUETYPE] %p\n",p);
1205 case MONO_TYPE_TYPEDBYREF: {
1206 guint8 *p = va_arg (ap, gpointer);
1208 size = mono_type_size (type, &align);
1215 for (j = 0; p && j < size; j++)
1216 printf ("%02x,", p [j]);
1220 printf ("[TYPEDBYREF]\n");
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;
1560 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1563 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1565 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1570 cinfo->struct_ret = 0;
1574 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1575 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1582 /*----------------------------------------------------------*/
1583 /* We determine the size of the return code/stack in case we*/
1584 /* need to reserve a register to be used to address a stack */
1585 /* area that the callee will use. */
1586 /*----------------------------------------------------------*/
1588 ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
1589 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1590 simpleType = ret_type->type;
1592 switch (simpleType) {
1593 case MONO_TYPE_BOOLEAN:
1598 case MONO_TYPE_CHAR:
1603 case MONO_TYPE_CLASS:
1604 case MONO_TYPE_OBJECT:
1605 case MONO_TYPE_SZARRAY:
1606 case MONO_TYPE_ARRAY:
1608 case MONO_TYPE_FNPTR:
1609 case MONO_TYPE_STRING:
1610 cinfo->ret.reg = s390_r2;
1615 cinfo->ret.reg = s390_f0;
1620 cinfo->ret.reg = s390_r2;
1623 case MONO_TYPE_GENERICINST:
1624 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1625 cinfo->ret.reg = s390_r2;
1630 case MONO_TYPE_VALUETYPE: {
1631 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1632 if (klass->enumtype) {
1633 simpleType = mono_class_enum_basetype (klass)->type;
1636 size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1638 cinfo->struct_ret = 1;
1639 cinfo->ret.size = size;
1640 cinfo->ret.vtsize = size;
1643 case MONO_TYPE_TYPEDBYREF:
1644 size = sizeof (MonoTypedRef);
1645 cinfo->struct_ret = 1;
1646 cinfo->ret.size = size;
1647 cinfo->ret.vtsize = size;
1649 case MONO_TYPE_VOID:
1652 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1658 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1659 * the first argument, allowing 'this' to be always passed in the first arg reg.
1660 * Also do this if the first argument is a reference type, since virtual calls
1661 * are sometimes made using calli without sig->hasthis set, like in the delegate
1664 if (cinfo->struct_ret && !is_pinvoke &&
1666 (sig->param_count > 0 &&
1667 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1669 cinfo->args[nParm].size = sizeof (gpointer);
1670 add_general (&gr, sz, cinfo->args + nParm);
1672 cinfo->args[nParm].size = sizeof (gpointer);
1673 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1677 cinfo->vret_arg_index = 1;
1678 cinfo->ret.reg = gr;
1683 cinfo->args[nParm].size = sizeof (gpointer);
1684 add_general (&gr, sz, cinfo->args + nParm);
1688 if (cinfo->struct_ret) {
1689 cinfo->ret.reg = gr;
1694 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1695 gr = S390_LAST_ARG_REG + 1;
1696 fr = S390_LAST_FPARG_REG + 1;
1698 /* Emit the signature cookie just before the implicit arguments */
1699 add_general (&gr, sz, &cinfo->sigCookie);
1702 /*----------------------------------------------------------*/
1703 /* We determine the size of the parameter code and stack */
1704 /* requirements by checking the types and sizes of the */
1706 /*----------------------------------------------------------*/
1708 for (i = pstart; i < sig->param_count; ++i) {
1711 /*--------------------------------------------------*/
1712 /* Handle vararg type calls. All args are put on */
1714 /*--------------------------------------------------*/
1715 if ((sig->call_convention == MONO_CALL_VARARG) &&
1716 (i == sig->sentinelpos)) {
1717 gr = S390_LAST_ARG_REG + 1;
1718 fr = S390_LAST_FPARG_REG + 1;
1719 add_general (&gr, sz, &cinfo->sigCookie);
1722 if (sig->params [i]->byref) {
1723 add_general (&gr, sz, cinfo->args+nParm);
1724 cinfo->args[nParm].size = sizeof(gpointer);
1729 ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
1730 simpleType = ptype->type;
1731 cinfo->args[nParm].type = simpleType;
1732 switch (simpleType) {
1733 case MONO_TYPE_BOOLEAN:
1736 cinfo->args[nParm].size = sizeof(char);
1737 add_general (&gr, sz, cinfo->args+nParm);
1742 case MONO_TYPE_CHAR:
1743 cinfo->args[nParm].size = sizeof(short);
1744 add_general (&gr, sz, cinfo->args+nParm);
1749 cinfo->args[nParm].size = sizeof(int);
1750 add_general (&gr, sz, cinfo->args+nParm);
1756 case MONO_TYPE_FNPTR:
1757 case MONO_TYPE_CLASS:
1758 case MONO_TYPE_OBJECT:
1759 case MONO_TYPE_STRING:
1760 case MONO_TYPE_SZARRAY:
1761 case MONO_TYPE_ARRAY:
1762 cinfo->args[nParm].size = sizeof(gpointer);
1763 add_general (&gr, sz, cinfo->args+nParm);
1768 cinfo->args[nParm].size = sizeof(long long);
1769 add_general (&gr, sz, cinfo->args+nParm);
1773 cinfo->args[nParm].size = sizeof(float);
1774 add_float (&fr, sz, cinfo->args+nParm);
1778 cinfo->args[nParm].size = sizeof(double);
1779 add_float (&fr, sz, cinfo->args+nParm);
1782 case MONO_TYPE_GENERICINST:
1783 if (!mono_type_generic_inst_is_valuetype (ptype)) {
1784 cinfo->args[nParm].size = sizeof(gpointer);
1785 add_general (&gr, sz, cinfo->args+nParm);
1790 case MONO_TYPE_VALUETYPE: {
1791 MonoMarshalType *info;
1792 MonoClass *klass = mono_class_from_mono_type (ptype);
1795 size = mono_class_native_size(klass, NULL);
1797 size = mono_class_value_size(klass, NULL);
1799 if (simpleType != MONO_TYPE_GENERICINST) {
1800 info = mono_marshal_load_type_info(klass);
1802 if ((info->native_size == sizeof(float)) &&
1803 (info->num_fields == 1) &&
1804 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1805 cinfo->args[nParm].size = sizeof(float);
1806 add_float(&fr, sz, cinfo->args+nParm);
1811 if ((info->native_size == sizeof(double)) &&
1812 (info->num_fields == 1) &&
1813 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1814 cinfo->args[nParm].size = sizeof(double);
1815 add_float(&fr, sz, cinfo->args+nParm);
1821 cinfo->args[nParm].vtsize = 0;
1822 cinfo->args[nParm].size = 0;
1825 /*----------------------------------*/
1826 /* On S/390, structures of size 1, */
1827 /* 2, 4, and 8 bytes are passed in */
1828 /* (a) register(s). */
1829 /*----------------------------------*/
1835 add_general(&gr, sz, cinfo->args+nParm);
1836 cinfo->args[nParm].size = size;
1837 cinfo->args[nParm].regtype = RegTypeStructByVal;
1839 sz->local_size += sizeof(long);
1842 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1847 case MONO_TYPE_TYPEDBYREF: {
1848 int size = sizeof (MonoTypedRef);
1850 cinfo->args[nParm].vtsize = 0;
1851 cinfo->args[nParm].size = 0;
1854 /*----------------------------------*/
1855 /* On S/390, structures of size 1, */
1856 /* 2, 4, and 8 bytes are passed in */
1857 /* (a) register(s). */
1858 /*----------------------------------*/
1864 add_general(&gr, sz, cinfo->args+nParm);
1865 cinfo->args[nParm].size = size;
1866 cinfo->args[nParm].regtype = RegTypeStructByVal;
1868 sz->local_size += sizeof(long);
1871 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1877 g_error ("Can't trampoline 0x%x", ptype);
1881 /*----------------------------------------------------------*/
1882 /* Handle the case where there are no implicit arguments */
1883 /*----------------------------------------------------------*/
1884 if ((sig->call_convention == MONO_CALL_VARARG) &&
1887 (sig->param_count == sig->sentinelpos)) {
1888 gr = S390_LAST_ARG_REG + 1;
1889 fr = S390_LAST_FPARG_REG + 1;
1890 add_general (&gr, sz, &cinfo->sigCookie);
1893 /*----------------------------------------------------------*/
1894 /* If we are passing a structure back then if it won't be */
1895 /* in a register(s) then we make room at the end of the */
1896 /* parameters that may have been placed on the stack */
1897 /*----------------------------------------------------------*/
1898 if (cinfo->struct_ret) {
1899 cinfo->ret.offset = sz->stack_size;
1900 switch (cinfo->ret.size) {
1908 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1913 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1915 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1920 /*========================= End of Function ========================*/
1922 /*------------------------------------------------------------------*/
1924 /* Name - mono_arch_allocate_vars */
1926 /* Function - Set var information according to the calling */
1927 /* convention for S/390. The local var stuff should */
1928 /* most likely be split in another method. */
1930 /* Parameter - @m - Compile unit. */
1932 /*------------------------------------------------------------------*/
1935 mono_arch_allocate_vars (MonoCompile *cfg)
1937 MonoMethodSignature *sig;
1938 MonoMethodHeader *header;
1941 int iParm, iVar, offset, align, size, curinst;
1942 int frame_reg = STK_BASE;
1945 header = cfg->header;
1947 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1949 /*---------------------------------------------------------*/
1950 /* We use the frame register also for any method that has */
1951 /* filter clauses. This way, when the handlers are called, */
1952 /* the code will reference local variables using the frame */
1953 /* reg instead of the stack pointer: if we had to restore */
1954 /* the stack pointer, we'd corrupt the method frames that */
1955 /* are already on the stack (since filters get called */
1956 /* before stack unwinding happens) when the filter code */
1957 /* would call any method. */
1958 /*---------------------------------------------------------*/
1959 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1960 frame_reg = s390_r11;
1962 cfg->frame_reg = frame_reg;
1964 cfg->arch.bkchain_reg = -1;
1966 if (frame_reg != STK_BASE)
1967 cfg->used_int_regs |= (1 << frame_reg);
1969 if (cfg->uses_rgctx_reg)
1970 cfg->used_int_regs |= (1 << MONO_ARCH_IMT_REG);
1972 sig = mono_method_signature (cfg->method);
1974 cinfo = get_call_info (cfg, cfg->mempool, sig);
1976 if (!cinfo->struct_ret) {
1977 switch (mini_type_get_underlying_type (cfg->generic_sharing_context, sig->ret)->type) {
1978 case MONO_TYPE_VOID:
1981 cfg->ret->opcode = OP_REGVAR;
1982 cfg->ret->dreg = s390_r2;
1987 /*--------------------------------------------------------------*/
1988 /* local vars are at a positive offset from the stack pointer */
1989 /* also note that if the function uses alloca, we use s390_r11 */
1990 /* to point at the local variables. */
1991 /* add parameter area size for called functions */
1992 /*--------------------------------------------------------------*/
1993 if (cfg->param_area == 0)
1994 offset = S390_MINIMAL_STACK_SIZE;
1996 offset = cfg->param_area;
1998 cfg->sig_cookie = 0;
2000 if (cinfo->struct_ret) {
2001 inst = cfg->vret_addr;
2002 offset = S390_ALIGN(offset, sizeof(gpointer));
2003 inst->inst_offset = offset;
2004 inst->opcode = OP_REGOFFSET;
2005 inst->inst_basereg = frame_reg;
2006 offset += sizeof(gpointer);
2007 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2008 printf ("vret_addr =");
2009 mono_print_ins (cfg->vret_addr);
2014 inst = cfg->args [0];
2015 if (inst->opcode != OP_REGVAR) {
2016 inst->opcode = OP_REGOFFSET;
2017 inst->inst_basereg = frame_reg;
2018 offset = S390_ALIGN(offset, sizeof(gpointer));
2019 inst->inst_offset = offset;
2020 offset += sizeof (gpointer);
2027 eArg = sig->param_count + sArg;
2029 if (sig->call_convention == MONO_CALL_VARARG)
2030 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2032 for (iParm = sArg; iParm < eArg; ++iParm) {
2033 inst = cfg->args [curinst];
2034 if (inst->opcode != OP_REGVAR) {
2035 switch (cinfo->args[iParm].regtype) {
2036 case RegTypeStructByAddr : {
2039 size = sizeof (gpointer);
2041 inst->opcode = OP_REGOFFSET;
2042 inst->inst_basereg = frame_reg;
2043 offset = S390_ALIGN (offset, sizeof (gpointer));
2044 inst->inst_offset = offset;
2046 /* Add a level of indirection */
2047 MONO_INST_NEW (cfg, indir, 0);
2049 inst->opcode = OP_VTARG_ADDR;
2050 inst->inst_left = indir;
2053 case RegTypeStructByAddrOnStack : {
2056 size = sizeof (gpointer);
2058 /* Similar to the == STK_BASE case below */
2059 cfg->arch.bkchain_reg = s390_r12;
2060 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2062 inst->opcode = OP_REGOFFSET;
2063 inst->dreg = mono_alloc_preg (cfg);
2064 inst->inst_basereg = cfg->arch.bkchain_reg;
2065 inst->inst_offset = cinfo->args [iParm].offset;
2067 /* Add a level of indirection */
2068 MONO_INST_NEW (cfg, indir, 0);
2070 inst->opcode = OP_VTARG_ADDR;
2071 inst->inst_left = indir;
2074 case RegTypeStructByVal :
2075 size = cinfo->args[iParm].size;
2076 offset = S390_ALIGN(offset, size);
2077 inst->opcode = OP_REGOFFSET;
2078 inst->inst_basereg = frame_reg;
2079 inst->inst_offset = offset;
2082 if (cinfo->args [iParm].reg == STK_BASE) {
2084 * These arguments are in the previous frame, so we can't
2085 * compute their offset from the current frame pointer right
2086 * now, since cfg->stack_offset is not yet known, so dedicate a
2087 * register holding the previous frame pointer.
2089 cfg->arch.bkchain_reg = s390_r12;
2090 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2092 inst->opcode = OP_REGOFFSET;
2093 inst->inst_basereg = cfg->arch.bkchain_reg;
2094 size = (cinfo->args[iParm].size < 8
2095 ? 8 - cinfo->args[iParm].size
2097 inst->inst_offset = cinfo->args [iParm].offset + size;
2098 size = sizeof (long);
2100 inst->opcode = OP_REGOFFSET;
2101 inst->inst_basereg = frame_reg;
2102 size = (cinfo->args[iParm].size < 8
2105 offset = S390_ALIGN(offset, size);
2106 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2107 inst->inst_offset = offset;
2109 inst->inst_offset = offset + (8 - size);
2114 if ((sig->call_convention == MONO_CALL_VARARG) &&
2115 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2116 (iParm < sig->sentinelpos))
2117 cfg->sig_cookie += size;
2118 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2121 offset += MAX(size, 8);
2126 cfg->locals_min_stack_offset = offset;
2128 curinst = cfg->locals_start;
2129 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2130 inst = cfg->varinfo [iVar];
2131 if ((inst->flags & MONO_INST_IS_DEAD) ||
2132 (inst->opcode == OP_REGVAR))
2135 /*--------------------------------------------------*/
2136 /* inst->backend.is_pinvoke indicates native sized */
2137 /* value typs this is used by the pinvoke wrappers */
2138 /* when they call functions returning structure */
2139 /*--------------------------------------------------*/
2140 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2141 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2142 (guint32 *) &align);
2144 size = mono_type_size (inst->inst_vtype, &align);
2146 offset = S390_ALIGN(offset, align);
2147 inst->inst_offset = offset;
2148 inst->opcode = OP_REGOFFSET;
2149 inst->inst_basereg = frame_reg;
2151 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2152 iVar, inst->inst_offset, size));
2155 cfg->locals_max_stack_offset = offset;
2157 /*------------------------------------------------------*/
2158 /* Allow space for the trace method stack area if needed*/
2159 /*------------------------------------------------------*/
2160 if ((mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2161 || (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE))
2162 offset += S390_TRACE_STACK_SIZE;
2164 /*------------------------------------------------------*/
2165 /* Reserve space to save LMF and caller saved registers */
2166 /*------------------------------------------------------*/
2167 if (cfg->method->save_lmf)
2168 offset += sizeof (MonoLMF);
2170 /*------------------------------------------------------*/
2171 /* align the offset */
2172 /*------------------------------------------------------*/
2173 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2175 /*------------------------------------------------------*/
2176 /* Fix offsets for args whose value is in parent frame */
2177 /*------------------------------------------------------*/
2178 for (iParm = sArg; iParm < eArg; ++iParm) {
2179 inst = cfg->args [iParm];
2181 if (inst->opcode == OP_S390_STKARG) {
2182 inst->opcode = OP_REGOFFSET;
2183 inst->inst_offset += cfg->stack_offset;
2188 /*========================= End of Function ========================*/
2190 /*------------------------------------------------------------------*/
2192 /* Name - mono_arch_create_vars */
2194 /*------------------------------------------------------------------*/
2197 mono_arch_create_vars (MonoCompile *cfg)
2199 MonoMethodSignature *sig;
2202 sig = mono_method_signature (cfg->method);
2204 cinfo = get_call_info (cfg, cfg->mempool, sig);
2206 if (cinfo->struct_ret) {
2207 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2208 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2209 printf ("vret_addr = ");
2210 mono_print_ins (cfg->vret_addr);
2215 /*========================= End of Function ========================*/
2217 /*------------------------------------------------------------------*/
2219 /* Name - add_outarg_reg2. */
2221 /*------------------------------------------------------------------*/
2224 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2229 case RegTypeGeneral:
2230 MONO_INST_NEW (cfg, ins, OP_MOVE);
2231 ins->dreg = mono_alloc_ireg (cfg);
2232 ins->sreg1 = tree->dreg;
2233 MONO_ADD_INS (cfg->cbb, ins);
2234 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2237 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2238 ins->dreg = mono_alloc_freg (cfg);
2239 ins->sreg1 = tree->dreg;
2240 MONO_ADD_INS (cfg->cbb, ins);
2241 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2244 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2245 ins->dreg = mono_alloc_freg (cfg);
2246 ins->sreg1 = tree->dreg;
2247 MONO_ADD_INS (cfg->cbb, ins);
2248 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2251 g_assert_not_reached ();
2255 /*========================= End of Function ========================*/
2257 /*------------------------------------------------------------------*/
2259 /* Name - emit_sig_cookie. */
2261 /*------------------------------------------------------------------*/
2264 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2266 MonoMethodSignature *tmpSig;
2269 cfg->disable_aot = TRUE;
2271 /*----------------------------------------------------------*/
2272 /* mono_ArgIterator_Setup assumes the signature cookie is */
2273 /* passed first and all the arguments which were before it */
2274 /* passed on the stack after the signature. So compensate */
2275 /* by passing a different signature. */
2276 /*----------------------------------------------------------*/
2277 tmpSig = mono_metadata_signature_dup (call->signature);
2278 tmpSig->param_count -= call->signature->sentinelpos;
2279 tmpSig->sentinelpos = 0;
2280 if (tmpSig->param_count > 0)
2281 memcpy (tmpSig->params,
2282 call->signature->params + call->signature->sentinelpos,
2283 tmpSig->param_count * sizeof(MonoType *));
2285 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2286 sig_arg->dreg = mono_alloc_ireg (cfg);
2287 sig_arg->inst_p0 = tmpSig;
2288 MONO_ADD_INS (cfg->cbb, sig_arg);
2290 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2291 cinfo->sigCookie.offset, sig_arg->dreg);
2294 /*========================= End of Function ========================*/
2296 /*------------------------------------------------------------------*/
2298 /* Name - mono_arch_emit_call */
2300 /*------------------------------------------------------------------*/
2303 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2306 MonoMethodSignature *sig;
2308 int i, n, lParamArea;
2310 ArgInfo *ainfo = NULL;
2312 MonoMethodHeader *header;
2315 sig = call->signature;
2316 n = sig->param_count + sig->hasthis;
2317 DEBUG (g_print ("Call requires: %d parameters\n",n));
2319 cinfo = get_call_info (cfg, cfg->mempool, sig);
2321 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2322 cinfo->sz.parm_size + cinfo->sz.offset;
2323 call->stack_usage = MAX(stackSize, call->stack_usage);
2324 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2325 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2326 cfg->flags |= MONO_CFG_HAS_CALLS;
2328 if (cinfo->struct_ret) {
2329 MONO_INST_NEW (cfg, ins, OP_MOVE);
2330 ins->sreg1 = call->vret_var->dreg;
2331 ins->dreg = mono_alloc_preg (cfg);
2332 MONO_ADD_INS (cfg->cbb, ins);
2333 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2336 header = cfg->header;
2337 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2342 for (i = 0; i < n; ++i) {
2345 ainfo = cinfo->args + i;
2346 if (i >= sig->hasthis)
2347 t = sig->params [i - sig->hasthis];
2349 t = &mono_defaults.int_class->byval_arg;
2350 t = mini_type_get_underlying_type (cfg->generic_sharing_context, t);
2352 in = call->args [i];
2354 if ((sig->call_convention == MONO_CALL_VARARG) &&
2356 (i == sig->sentinelpos)) {
2357 emit_sig_cookie (cfg, call, cinfo);
2360 switch (ainfo->regtype) {
2361 case RegTypeGeneral:
2362 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2365 if (MONO_TYPE_ISSTRUCT (t)) {
2366 /* Valuetype passed in one fp register */
2367 ainfo->regtype = RegTypeStructByValInFP;
2370 if (ainfo->size == 4)
2371 ainfo->regtype = RegTypeFPR4;
2372 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2375 case RegTypeStructByVal:
2376 case RegTypeStructByAddr:
2377 case RegTypeStructByAddrOnStack: {
2381 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2382 size = sizeof (MonoTypedRef);
2383 align = sizeof (gpointer);
2387 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2390 * Other backends use mono_type_stack_size (), but that
2391 * aligns the size to 8, which is larger than the size of
2392 * the source, leading to reads of invalid memory if the
2393 * source is at the end of address space.
2395 size = mono_class_value_size (in->klass, &align);
2398 g_assert (in->klass);
2400 ainfo->offparm += cinfo->sz.offStruct;
2402 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2403 ins->sreg1 = in->dreg;
2404 ins->klass = in->klass;
2405 ins->backend.size = ainfo->size;
2406 ins->inst_p0 = call;
2407 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2408 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2410 MONO_ADD_INS (cfg->cbb, ins);
2412 if (ainfo->regtype == RegTypeStructByAddr) {
2414 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2415 * use the normal OUTARG opcodes to pass the address of the location to
2418 int treg = mono_alloc_preg (cfg);
2419 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2420 frmReg, ainfo->offparm);
2421 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2422 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2423 /* The address of the valuetype is passed on the stack */
2424 int treg = mono_alloc_preg (cfg);
2425 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2426 frmReg, ainfo->offparm);
2427 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2428 ainfo->reg, ainfo->offset, treg);
2430 if (cfg->compute_gc_maps) {
2433 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2439 if (!t->byref && t->type == MONO_TYPE_R4) {
2440 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2441 STK_BASE, ainfo->offset + 4,
2443 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2444 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2445 STK_BASE, ainfo->offset,
2448 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2449 ins->inst_destbasereg = STK_BASE;
2450 ins->inst_offset = ainfo->offset;
2451 ins->sreg1 = in->dreg;
2454 /* This is needed by MonoTypedRef->value to point to the correct data */
2455 if ((sig->call_convention == MONO_CALL_VARARG) &&
2456 (i >= sig->sentinelpos)) {
2457 switch (ainfo->size) {
2459 ins->opcode = OP_STOREI1_MEMBASE_REG;
2462 ins->opcode = OP_STOREI2_MEMBASE_REG;
2465 ins->opcode = OP_STOREI4_MEMBASE_REG;
2473 MONO_ADD_INS (cfg->cbb, ins);
2477 g_assert_not_reached ();
2483 * Handle the case where there are no implicit arguments
2485 if ((sig->call_convention == MONO_CALL_VARARG) &&
2487 (i == sig->sentinelpos)) {
2488 emit_sig_cookie (cfg, call, cinfo);
2492 /*========================= End of Function ========================*/
2494 /*------------------------------------------------------------------*/
2496 /* Name - mono_arch_emit_outarg_vt */
2498 /*------------------------------------------------------------------*/
2501 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2503 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2504 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2505 int size = ins->backend.size;
2507 if (ainfo->regtype == RegTypeStructByVal) {
2509 arg->ins.sreg1 = ainfo->reg;
2510 arg->ins.opcode = OP_OUTARG_VT;
2511 arg->size = ainfo->size;
2512 arg->offset = ainfo->offset;
2513 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2515 if (ainfo->reg != STK_BASE) {
2516 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2518 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2521 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2522 int dreg = mono_alloc_freg (cfg);
2524 if (ainfo->size == 4) {
2525 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2526 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2528 g_assert (ainfo->size == 8);
2530 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2533 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2535 MonoMethodHeader *header;
2538 header = mono_method_get_header (cfg->method);
2539 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2544 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2545 src->dreg, 0, size);
2547 if (cfg->compute_gc_maps) {
2550 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2555 /*========================= End of Function ========================*/
2557 /*------------------------------------------------------------------*/
2559 /* Name - mono_arch_emit_setret */
2561 /*------------------------------------------------------------------*/
2564 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2566 MonoType *ret = mini_type_get_underlying_type (cfg->generic_sharing_context,
2567 mono_method_signature (method)->ret);
2570 if (ret->type == MONO_TYPE_R4) {
2571 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2573 } else if (ret->type == MONO_TYPE_R8) {
2574 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2579 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2582 /*========================= End of Function ========================*/
2584 /*------------------------------------------------------------------*/
2586 /* Name - mono_arch_instrument_mem_needs */
2588 /* Function - Allow tracing to work with this interface (with */
2589 /* an optional argument). */
2591 /*------------------------------------------------------------------*/
2594 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2596 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2598 /* split prolog-epilog requirements? */
2599 *code = 50; /* max bytes needed: check this number */
2602 /*========================= End of Function ========================*/
2604 /*------------------------------------------------------------------*/
2606 /* Name - mono_arch_instrument_prolog */
2608 /* Function - Create an "instrumented" prolog. */
2610 /*------------------------------------------------------------------*/
2613 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2614 gboolean enable_arguments)
2621 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2622 if (cfg->method->save_lmf)
2623 parmOffset -= sizeof(MonoLMF);
2624 fpOffset = parmOffset + (5*sizeof(gpointer));
2627 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2628 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2629 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2630 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2631 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2632 S390_SET (code, s390_r1, func);
2633 S390_SET (code, s390_r2, cfg->method);
2634 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2635 s390_lgr (code, s390_r4, STK_BASE);
2636 s390_aghi (code, s390_r4, cfg->stack_usage);
2637 s390_basr (code, s390_r14, s390_r1);
2638 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2639 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2640 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2641 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2642 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2647 /*========================= End of Function ========================*/
2649 /*------------------------------------------------------------------*/
2651 /* Name - mono_arch_instrument_epilog */
2653 /* Function - Create an epilog that will handle the returned */
2654 /* values used in instrumentation. */
2656 /*------------------------------------------------------------------*/
2659 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2662 int save_mode = SAVE_NONE,
2665 MonoMethod *method = cfg->method;
2666 int rtype = mini_type_get_underlying_type (cfg->generic_sharing_context,
2667 mono_method_signature (method)->ret)->type;
2669 offset = code - cfg->native_code;
2670 /*-----------------------------------------*/
2671 /* We need about 128 bytes of instructions */
2672 /*-----------------------------------------*/
2673 if (offset > (cfg->code_size - 128)) {
2674 cfg->code_size *= 2;
2675 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2676 code = cfg->native_code + offset;
2679 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2680 if (method->save_lmf)
2681 saveOffset -= sizeof(MonoLMF);
2685 case MONO_TYPE_VOID:
2686 /* special case string .ctor icall */
2687 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2688 save_mode = SAVE_ONE;
2690 save_mode = SAVE_NONE;
2694 save_mode = SAVE_ONE;
2697 save_mode = SAVE_R4;
2700 save_mode = SAVE_R8;
2702 case MONO_TYPE_VALUETYPE:
2703 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2704 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2707 save_mode = SAVE_STRUCT;
2710 save_mode = SAVE_ONE;
2714 switch (save_mode) {
2716 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2717 if (enable_arguments) {
2718 s390_lgr (code, s390_r3, s390_r2);
2722 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2723 if (enable_arguments) {
2724 s390_ldebr (code, s390_f0, s390_f0);
2728 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2731 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2732 if (enable_arguments) {
2733 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2734 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2742 S390_SET (code, s390_r1, func);
2743 S390_SET (code, s390_r2, cfg->method);
2744 s390_basr (code, s390_r14, s390_r1);
2746 switch (save_mode) {
2748 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2752 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2755 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2765 /*========================= End of Function ========================*/
2767 /*------------------------------------------------------------------*/
2769 /* Name - mono_arch_peephole_pass_1 */
2771 /* Function - Form a peephole pass at the code looking for */
2772 /* simple optimizations. */
2774 /*------------------------------------------------------------------*/
2777 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2781 /*========================= End of Function ========================*/
2783 /*------------------------------------------------------------------*/
2785 /* Name - mono_arch_peephole_pass_2 */
2787 /* Function - Form a peephole pass at the code looking for */
2788 /* simple optimizations. */
2790 /*------------------------------------------------------------------*/
2793 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2797 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2798 mono_peephole_ins (bb, ins);
2802 /*========================= End of Function ========================*/
2804 /*------------------------------------------------------------------*/
2806 /* Name - mono_arch_lowering_pass. */
2808 /*------------------------------------------------------------------*/
2811 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2813 MonoInst *ins, *next;
2815 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2816 switch (ins->opcode) {
2821 case OP_IDIV_UN_IMM:
2822 case OP_IREM_UN_IMM:
2827 case OP_LOCALLOC_IMM:
2828 mono_decompose_op_imm (cfg, bb, ins);
2831 if (!s390_is_imm16 (ins->inst_imm))
2832 /* This is created by the memcpy code which ignores is_inst_imm */
2833 mono_decompose_op_imm (cfg, bb, ins);
2840 bb->max_vreg = cfg->next_vreg;
2843 /*========================= End of Function ========================*/
2845 /*------------------------------------------------------------------*/
2847 /* Name - emit_float_to_int */
2849 /* Function - Create instructions which will convert a floating */
2850 /* point value to integer. */
2852 /*------------------------------------------------------------------*/
2855 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2857 /* sreg is a float, dreg is an integer reg. */
2859 s390_cgdbr (code, dreg, 5, sreg);
2862 s390_ltgr (code, dreg, dreg);
2864 s390_oill (code, dreg, 0x80);
2865 s390_lghi (code, s390_r0, 0xff);
2866 s390_ngr (code, dreg, s390_r0);
2869 s390_ltgr (code, dreg, dreg);
2871 s390_oill (code, dreg, 0x8000);
2872 s390_llill(code, s390_r0, 0xffff);
2873 s390_ngr (code, dreg, s390_r0);
2878 S390_SET (code, s390_r13, 0x41e0000000000000llu);
2879 s390_ldgr (code, s390_f14, s390_r13);
2880 s390_ldr (code, s390_f15, sreg);
2881 s390_cdbr (code, s390_f15, s390_f14);
2882 s390_jl (code, 0); CODEPTR (code, o[0]);
2883 S390_SET (code, s390_r13, 0x41f0000000000000llu);
2884 s390_ldgr (code, s390_f14, s390_r13);
2885 s390_sdbr (code, s390_f15, s390_f14);
2886 s390_cfdbr (code, dreg, 7, s390_f15);
2888 PTRSLOT (code, o[0]);
2889 s390_cfdbr (code, dreg, 5, sreg);
2892 s390_lghi (code, s390_r0, 0xff);
2893 s390_ngr (code, dreg, s390_r0);
2896 s390_llill(code, s390_r0, 0xffff);
2897 s390_ngr (code, dreg, s390_r0);
2904 /*========================= End of Function ========================*/
2906 /*------------------------------------------------------------------*/
2908 /* Name - gboolean_is_unsigned. */
2910 /* Function - Return TRUE if next opcode is checking for un- */
2913 /*------------------------------------------------------------------*/
2916 gboolean is_unsigned (MonoInst *next)
2919 (((next->opcode >= OP_IBNE_UN) &&
2920 (next->opcode <= OP_IBLT_UN)) ||
2921 ((next->opcode >= OP_LBNE_UN) &&
2922 (next->opcode <= OP_LBLT_UN)) ||
2923 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2924 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2925 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2926 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2927 ((next->opcode == OP_CLT_UN) ||
2928 (next->opcode == OP_CGT_UN)) ||
2929 ((next->opcode == OP_ICLT_UN) ||
2930 (next->opcode == OP_ICGT_UN) ||
2931 (next->opcode == OP_LCLT_UN) ||
2932 (next->opcode == OP_LCGT_UN))))
2938 /*========================= End of Function ========================*/
2940 /*------------------------------------------------------------------*/
2942 /* Name - mono_arch_output_basic_block */
2944 /* Function - Perform the "real" work of emitting instructions */
2945 /* that will do the work of in the basic block. */
2947 /*------------------------------------------------------------------*/
2950 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2955 guint8 *code = cfg->native_code + cfg->code_len;
2956 guint last_offset = 0;
2959 /* we don't align basic blocks of loops on s390 */
2961 if (cfg->verbose_level > 2)
2962 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2964 if ((cfg->prof_options & MONO_PROFILE_COVERAGE) && cfg->coverage_info) {
2965 MonoProfileCoverageInfo *cov = cfg->coverage_info;
2966 g_assert (!mono_compile_aot);
2967 cov->data [bb->dfn].cil_code = bb->cil_code;
2968 /* This is not thread save, but good enough */
2969 S390_SET (code, s390_r1, &cov->data [bb->dfn].count);
2970 s390_alsi (code, 0, s390_r1, 1);
2973 MONO_BB_FOR_EACH_INS (bb, ins) {
2974 offset = code - cfg->native_code;
2976 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2978 if (offset > (cfg->code_size - max_len - 16)) {
2979 cfg->code_size *= 2;
2980 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2981 code = cfg->native_code + offset;
2984 mono_debug_record_line_number (cfg, ins, offset);
2986 switch (ins->opcode) {
2987 case OP_STOREI1_MEMBASE_IMM: {
2988 s390_lghi (code, s390_r0, ins->inst_imm);
2989 S390_LONG (code, stcy, stc, s390_r0, 0,
2990 ins->inst_destbasereg, ins->inst_offset);
2993 case OP_STOREI2_MEMBASE_IMM: {
2994 s390_lghi (code, s390_r0, ins->inst_imm);
2995 S390_LONG (code, sthy, sth, s390_r0, 0,
2996 ins->inst_destbasereg, ins->inst_offset);
2999 case OP_STOREI4_MEMBASE_IMM: {
3000 s390_lgfi (code, s390_r0, ins->inst_imm);
3001 S390_LONG (code, sty, st, s390_r0, 0,
3002 ins->inst_destbasereg, ins->inst_offset);
3005 case OP_STORE_MEMBASE_IMM:
3006 case OP_STOREI8_MEMBASE_IMM: {
3007 S390_SET (code, s390_r0, ins->inst_imm);
3008 S390_LONG (code, stg, stg, s390_r0, 0,
3009 ins->inst_destbasereg, ins->inst_offset);
3012 case OP_STOREI1_MEMBASE_REG: {
3013 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3014 ins->inst_destbasereg, ins->inst_offset);
3017 case OP_STOREI2_MEMBASE_REG: {
3018 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3019 ins->inst_destbasereg, ins->inst_offset);
3022 case OP_STOREI4_MEMBASE_REG: {
3023 S390_LONG (code, sty, st, ins->sreg1, 0,
3024 ins->inst_destbasereg, ins->inst_offset);
3027 case OP_STORE_MEMBASE_REG:
3028 case OP_STOREI8_MEMBASE_REG: {
3029 S390_LONG (code, stg, stg, ins->sreg1, 0,
3030 ins->inst_destbasereg, ins->inst_offset);
3034 g_assert_not_reached ();
3036 case OP_LOAD_MEMBASE:
3037 case OP_LOADI8_MEMBASE: {
3038 S390_LONG (code, lg, lg, ins->dreg, 0,
3039 ins->inst_basereg, ins->inst_offset);
3042 case OP_LOADI4_MEMBASE: {
3043 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3044 ins->inst_basereg, ins->inst_offset);
3047 case OP_LOADU4_MEMBASE: {
3048 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3049 ins->inst_basereg, ins->inst_offset);
3052 case OP_LOADU1_MEMBASE: {
3053 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3054 ins->inst_basereg, ins->inst_offset);
3057 case OP_LOADI1_MEMBASE: {
3058 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3059 ins->inst_basereg, ins->inst_offset);
3062 case OP_LOADU2_MEMBASE: {
3063 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3064 ins->inst_basereg, ins->inst_offset);
3067 case OP_LOADI2_MEMBASE: {
3068 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3069 ins->inst_basereg, ins->inst_offset);
3072 case OP_LCONV_TO_I1: {
3073 s390_lgbr (code, ins->dreg, ins->sreg1);
3076 case OP_LCONV_TO_I2: {
3077 s390_lghr (code, ins->dreg, ins->sreg1);
3080 case OP_LCONV_TO_U1: {
3081 s390_llgcr (code, ins->dreg, ins->sreg1);
3084 case OP_LCONV_TO_U2: {
3085 s390_llghr (code, ins->dreg, ins->sreg1);
3088 case OP_ICONV_TO_I1: {
3089 s390_lgbr (code, ins->dreg, ins->sreg1);
3092 case OP_ICONV_TO_I2: {
3093 s390_lghr (code, ins->dreg, ins->sreg1);
3096 case OP_ICONV_TO_U1: {
3097 s390_llgcr (code, ins->dreg, ins->sreg1);
3100 case OP_ICONV_TO_U2: {
3101 s390_llghr (code, ins->dreg, ins->sreg1);
3106 if (is_unsigned (ins->next))
3107 s390_clgr (code, ins->sreg1, ins->sreg2);
3109 s390_cgr (code, ins->sreg1, ins->sreg2);
3113 if (is_unsigned (ins->next))
3114 s390_clr (code, ins->sreg1, ins->sreg2);
3116 s390_cr (code, ins->sreg1, ins->sreg2);
3119 case OP_COMPARE_IMM:
3120 case OP_LCOMPARE_IMM: {
3121 S390_SET (code, s390_r0, ins->inst_imm);
3122 if (is_unsigned (ins->next))
3123 s390_clgr (code, ins->sreg1, s390_r0);
3125 s390_cgr (code, ins->sreg1, s390_r0);
3128 case OP_ICOMPARE_IMM: {
3129 S390_SET (code, s390_r0, ins->inst_imm);
3130 if (is_unsigned (ins->next))
3131 s390_clr (code, ins->sreg1, s390_r0);
3133 s390_cr (code, ins->sreg1, s390_r0);
3137 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3139 S390_CALL_TEMPLATE (code, s390_r14);
3144 s390_agr (code, ins->dreg, src2);
3149 s390_agr (code, ins->dreg, src2);
3154 s390_alcgr (code, ins->dreg, src2);
3158 if (ins->dreg != ins->sreg1) {
3159 s390_lgr (code, ins->dreg, ins->sreg1);
3161 if (s390_is_imm16 (ins->inst_imm)) {
3162 s390_aghi (code, ins->dreg, ins->inst_imm);
3163 } else if (s390_is_imm32 (ins->inst_imm)) {
3164 s390_agfi (code, ins->dreg, ins->inst_imm);
3166 S390_SET (code, s390_r0, ins->inst_imm);
3167 s390_agr (code, ins->dreg, s390_r0);
3172 if (ins->dreg != ins->sreg1) {
3173 s390_lgr (code, ins->dreg, ins->sreg1);
3175 g_assert (s390_is_imm16 (ins->inst_imm));
3176 s390_aghi (code, ins->dreg, ins->inst_imm);
3180 if (ins->dreg != ins->sreg1) {
3181 s390_lgr (code, ins->dreg, ins->sreg1);
3183 if (s390_is_imm16 (ins->inst_imm)) {
3184 s390_lghi (code, s390_r0, ins->inst_imm);
3185 s390_alcgr (code, ins->dreg, s390_r0);
3187 S390_SET (code, s390_r0, ins->inst_imm);
3188 s390_alcgr (code, ins->dreg, s390_r0);
3193 case OP_S390_IADD_OVF: {
3195 s390_ar (code, ins->dreg, src2);
3196 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3197 s390_lgfr (code, ins->dreg, ins->dreg);
3200 case OP_IADD_OVF_UN:
3201 case OP_S390_IADD_OVF_UN: {
3203 s390_algr (code, ins->dreg, src2);
3204 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3205 s390_llgfr (code, ins->dreg, ins->dreg);
3208 case OP_ADD_OVF_CARRY: {
3210 s390_lghi (code, s390_r0, 0);
3211 s390_lgr (code, s390_r1, s390_r0);
3212 s390_alcgr (code, s390_r0, s390_r1);
3213 s390_agr (code, ins->dreg, src2);
3214 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3215 s390_agr (code, ins->dreg, s390_r0);
3216 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3219 case OP_ADD_OVF_UN_CARRY: {
3221 s390_alcgr (code, ins->dreg, src2);
3222 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3227 s390_sgr (code, ins->dreg, src2);
3232 s390_sgr (code, ins->dreg, src2);
3237 s390_slbgr(code, ins->dreg, src2);
3241 if (ins->dreg != ins->sreg1) {
3242 s390_lgr (code, ins->dreg, ins->sreg1);
3244 if (s390_is_imm16 (-ins->inst_imm)) {
3245 s390_aghi (code, ins->dreg, -ins->inst_imm);
3246 } else if (s390_is_imm32 (-ins->inst_imm)) {
3247 s390_slgfi (code, ins->dreg, ins->inst_imm);
3249 S390_SET (code, s390_r0, ins->inst_imm);
3250 s390_slgr (code, ins->dreg, s390_r0);
3255 if (ins->dreg != ins->sreg1) {
3256 s390_lgr (code, ins->dreg, ins->sreg1);
3258 if (s390_is_imm16 (-ins->inst_imm)) {
3259 s390_aghi (code, ins->dreg, -ins->inst_imm);
3260 } else if (s390_is_imm32 (-ins->inst_imm)) {
3261 s390_slgfi (code, ins->dreg, ins->inst_imm);
3263 S390_SET (code, s390_r0, ins->inst_imm);
3264 s390_slgr (code, ins->dreg, s390_r0);
3269 if (ins->dreg != ins->sreg1) {
3270 s390_lgr (code, ins->dreg, ins->sreg1);
3272 if (s390_is_imm16 (-ins->inst_imm)) {
3273 s390_lghi (code, s390_r0, ins->inst_imm);
3274 s390_slbgr (code, ins->dreg, s390_r0);
3276 S390_SET (code, s390_r0, ins->inst_imm);
3277 s390_slbgr(code, ins->dreg, s390_r0);
3281 case OP_SUB_OVF_CARRY: {
3283 s390_lghi (code, s390_r0, 0);
3284 s390_lgr (code, s390_r1, s390_r0);
3285 s390_slbgr (code, s390_r0, s390_r1);
3286 s390_sgr (code, ins->dreg, src2);
3287 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3288 s390_agr (code, ins->dreg, s390_r0);
3289 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3292 case OP_SUB_OVF_UN_CARRY: {
3294 s390_slbgr (code, ins->dreg, src2);
3295 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3299 if (ins->sreg1 == ins->dreg) {
3300 s390_ngr (code, ins->dreg, ins->sreg2);
3303 if (ins->sreg2 == ins->dreg) {
3304 s390_ngr (code, ins->dreg, ins->sreg1);
3307 s390_lgr (code, ins->dreg, ins->sreg1);
3308 s390_ngr (code, ins->dreg, ins->sreg2);
3314 if (ins->dreg != ins->sreg1) {
3315 s390_lgr (code, ins->dreg, ins->sreg1);
3317 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3318 s390_ngr (code, ins->dreg, s390_r0);
3322 s390_lgr (code, s390_r1, ins->sreg1);
3323 s390_dsgr (code, s390_r0, ins->sreg2);
3324 s390_lgr (code, ins->dreg, s390_r1);
3328 s390_lgr (code, s390_r1, ins->sreg1);
3329 s390_lghi (code, s390_r0, 0);
3330 s390_dlgr (code, s390_r0, ins->sreg2);
3331 s390_lgr (code, ins->dreg, s390_r1);
3335 s390_lgr (code, s390_r1, ins->sreg1);
3336 s390_dsgr (code, s390_r0, ins->sreg2);
3337 s390_lgr (code, ins->dreg, s390_r0);
3341 if (s390_is_imm16 (ins->inst_imm)) {
3342 s390_lghi (code, s390_r13, ins->inst_imm);
3344 s390_lgfi (code, s390_r13, ins->inst_imm);
3346 s390_lgr (code, s390_r0, ins->sreg1);
3347 s390_dsgr (code, s390_r0, s390_r13);
3348 s390_lgfr (code, ins->dreg, s390_r0);
3352 s390_lgr (code, s390_r1, ins->sreg1);
3353 s390_lghi (code, s390_r0, 0);
3354 s390_dlgr (code, s390_r0, ins->sreg2);
3355 s390_lgr (code, ins->dreg, s390_r0);
3359 if (ins->sreg1 == ins->dreg) {
3360 s390_ogr (code, ins->dreg, ins->sreg2);
3363 if (ins->sreg2 == ins->dreg) {
3364 s390_ogr (code, ins->dreg, ins->sreg1);
3367 s390_lgr (code, ins->dreg, ins->sreg1);
3368 s390_ogr (code, ins->dreg, ins->sreg2);
3374 if (ins->dreg != ins->sreg1) {
3375 s390_lgr (code, ins->dreg, ins->sreg1);
3377 S390_SET_MASK(code, s390_r0, ins->inst_imm);
3378 s390_ogr (code, ins->dreg, s390_r0);
3382 if (ins->sreg1 == ins->dreg) {
3383 s390_xgr (code, ins->dreg, ins->sreg2);
3386 if (ins->sreg2 == ins->dreg) {
3387 s390_xgr (code, ins->dreg, ins->sreg1);
3390 s390_lgr (code, ins->dreg, ins->sreg1);
3391 s390_xgr (code, ins->dreg, ins->sreg2);
3397 if (ins->dreg != ins->sreg1) {
3398 s390_lgr (code, ins->dreg, ins->sreg1);
3400 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3401 s390_xgr (code, ins->dreg, s390_r0);
3406 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3411 if (ins->sreg1 != ins->dreg) {
3412 s390_lgr (code, ins->dreg, ins->sreg1);
3414 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3419 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3424 if (ins->sreg1 != ins->dreg) {
3425 s390_lgr (code, ins->dreg, ins->sreg1);
3427 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3431 case OP_LSHR_UN_IMM: {
3432 if (ins->sreg1 != ins->dreg) {
3433 s390_lgr (code, ins->dreg, ins->sreg1);
3435 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3440 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3444 if (ins->sreg1 != ins->dreg) {
3445 s390_lgr (code, ins->dreg, ins->sreg1);
3447 s390_lghi (code, s390_r0, -1);
3448 s390_xgr (code, ins->dreg, s390_r0);
3452 s390_lcgr (code, ins->dreg, ins->sreg1);
3457 s390_msgr (code, ins->dreg, src2);
3462 if (ins->dreg != ins->sreg1) {
3463 s390_lgr (code, ins->dreg, ins->sreg1);
3465 if (s390_is_imm16 (ins->inst_imm)) {
3466 s390_lghi (code, s390_r13, ins->inst_imm);
3467 } else if (s390_is_imm32 (ins->inst_imm)) {
3468 s390_lgfi (code, s390_r13, ins->inst_imm);
3470 S390_SET (code, s390_r13, ins->inst_imm);
3472 s390_msgr (code, ins->dreg, s390_r13);
3477 s390_ltgr (code, s390_r1, ins->sreg1);
3478 s390_jz (code, 0); CODEPTR(code, o[0]);
3479 s390_ltgr (code, s390_r0, ins->sreg2);
3481 s390_lghi (code, s390_r1, 0);
3482 s390_j (code, 0); CODEPTR(code, o[1]);
3483 s390_xgr (code, s390_r0, s390_r1);
3484 s390_msgr (code, s390_r1, ins->sreg2);
3485 s390_xgr (code, s390_r0, s390_r1);
3486 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3487 s390_ltgr (code, s390_r0, s390_r0);
3488 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3489 PTRSLOT (code, o[0]);
3490 PTRSLOT (code, o[1]);
3491 s390_lgr (code, ins->dreg, s390_r1);
3494 case OP_LMUL_OVF_UN: {
3495 s390_lghi (code, s390_r0, 0);
3496 s390_lgr (code, s390_r1, ins->sreg1);
3497 s390_mlgr (code, s390_r0, ins->sreg2);
3498 s390_ltgr (code, s390_r0, s390_r0);
3499 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3500 s390_lgr (code, ins->dreg, s390_r1);
3504 g_assert_not_reached ();
3506 s390_algr (code, ins->dreg, src2);
3511 s390_agr (code, ins->dreg, src2);
3515 g_assert_not_reached ();
3517 s390_alcgr (code, ins->dreg, src2);
3521 if (ins->dreg != ins->sreg1) {
3522 s390_lgfr (code, ins->dreg, ins->sreg1);
3524 if (s390_is_imm16 (ins->inst_imm)) {
3525 s390_aghi (code, ins->dreg, ins->inst_imm);
3527 s390_afi (code, ins->dreg, ins->inst_imm);
3532 if (ins->dreg != ins->sreg1) {
3533 s390_lgfr (code, ins->dreg, ins->sreg1);
3535 if (s390_is_imm16 (ins->inst_imm)) {
3536 s390_lghi (code, s390_r0, ins->inst_imm);
3537 s390_alcgr (code, ins->dreg, s390_r0);
3539 S390_SET (code, s390_r0, ins->inst_imm);
3540 s390_alcgr (code, ins->dreg, s390_r0);
3545 case OP_S390_LADD_OVF: {
3547 s390_agr (code, ins->dreg, src2);
3548 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3551 case OP_LADD_OVF_UN:
3552 case OP_S390_LADD_OVF_UN: {
3554 s390_algr (code, ins->dreg, src2);
3555 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3559 CHECK_SRCDST_NCOM_I;
3560 s390_slgr (code, ins->dreg, src2);
3564 CHECK_SRCDST_NCOM_I;
3565 s390_sgr (code, ins->dreg, src2);
3569 CHECK_SRCDST_NCOM_I;
3570 s390_slbgr (code, ins->dreg, src2);
3574 if (ins->dreg != ins->sreg1) {
3575 s390_lgfr (code, ins->dreg, ins->sreg1);
3577 if (s390_is_imm16 (-ins->inst_imm)) {
3578 s390_aghi (code, ins->dreg, -ins->inst_imm);
3580 s390_agfi (code, ins->dreg, -ins->inst_imm);
3585 S390_SET (code, s390_r0, ins->inst_imm);
3586 s390_slgfr (code, ins->dreg, s390_r0);
3590 case OP_S390_ISUB_OVF: {
3592 s390_sr (code, ins->dreg, src2);
3593 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3594 s390_lgfr (code, ins->dreg, ins->dreg);
3597 case OP_ISUB_OVF_UN:
3598 case OP_S390_ISUB_OVF_UN: {
3600 s390_slr (code, ins->dreg, src2);
3601 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3602 s390_llgfr(code, ins->dreg, ins->dreg);
3606 case OP_S390_LSUB_OVF: {
3608 s390_sgr (code, ins->dreg, src2);
3609 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3612 case OP_LSUB_OVF_UN:
3613 case OP_S390_LSUB_OVF_UN: {
3615 s390_slgr (code, ins->dreg, src2);
3616 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3620 CHECK_SRCDST_NCOM_I;
3621 s390_ngr (code, ins->dreg, src2);
3625 if (ins->dreg != ins->sreg1) {
3626 s390_lgfr (code, ins->dreg, ins->sreg1);
3628 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3629 s390_ngr (code, ins->dreg, s390_r0);
3633 s390_lgfr (code, s390_r0, ins->sreg1);
3634 s390_srda (code, s390_r0, 0, 32);
3635 s390_dr (code, s390_r0, ins->sreg2);
3636 s390_lgfr (code, ins->dreg, s390_r1);
3640 s390_lgfr (code, s390_r0, ins->sreg1);
3641 s390_srdl (code, s390_r0, 0, 32);
3642 s390_dlr (code, s390_r0, ins->sreg2);
3643 s390_lgfr (code, ins->dreg, s390_r1);
3647 if (s390_is_imm16 (ins->inst_imm)) {
3648 s390_lghi (code, s390_r13, ins->inst_imm);
3650 s390_lgfi (code, s390_r13, ins->inst_imm);
3652 s390_lgfr (code, s390_r0, ins->sreg1);
3653 s390_srda (code, s390_r0, 0, 32);
3654 s390_dr (code, s390_r0, ins->sreg2);
3655 s390_lgfr (code, ins->dreg, s390_r1);
3659 s390_lgfr (code, s390_r0, ins->sreg1);
3660 s390_srda (code, s390_r0, 0, 32);
3661 s390_dr (code, s390_r0, ins->sreg2);
3662 s390_lgfr (code, ins->dreg, s390_r0);
3665 s390_lgfr (code, s390_r0, ins->sreg1);
3666 s390_srdl (code, s390_r0, 0, 32);
3667 s390_dlr (code, s390_r0, ins->sreg2);
3668 s390_lgfr (code, ins->dreg, s390_r0);
3672 if (s390_is_imm16 (ins->inst_imm)) {
3673 s390_lghi (code, s390_r13, ins->inst_imm);
3675 s390_lgfi (code, s390_r13, ins->inst_imm);
3677 s390_lgfr (code, s390_r0, ins->sreg1);
3678 s390_srda (code, s390_r0, 0, 32);
3679 s390_dr (code, s390_r0, ins->sreg2);
3680 s390_lgfr (code, ins->dreg, s390_r0);
3685 s390_ogr (code, ins->dreg, src2);
3689 if (ins->dreg != ins->sreg1) {
3690 s390_lgfr (code, ins->dreg, ins->sreg1);
3692 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3693 s390_ogr (code, ins->dreg, s390_r0);
3698 s390_xgr (code, ins->dreg, src2);
3702 if (ins->dreg != ins->sreg1) {
3703 s390_lgfr (code, ins->dreg, ins->sreg1);
3705 S390_SET_MASK (code, s390_r0, ins->inst_imm);
3706 s390_xgr (code, ins->dreg, s390_r0);
3711 s390_sll (code, ins->dreg, src2, 0);
3715 if (ins->sreg1 != ins->dreg) {
3716 s390_lgfr (code, ins->dreg, ins->sreg1);
3718 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3723 s390_sra (code, ins->dreg, src2, 0);
3727 if (ins->sreg1 != ins->dreg) {
3728 s390_lgfr (code, ins->dreg, ins->sreg1);
3730 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3733 case OP_ISHR_UN_IMM: {
3734 if (ins->sreg1 != ins->dreg) {
3735 s390_lgfr (code, ins->dreg, ins->sreg1);
3737 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3742 s390_srl (code, ins->dreg, src2, 0);
3746 if (ins->sreg1 != ins->dreg) {
3747 s390_lgfr (code, ins->dreg, ins->sreg1);
3749 s390_lghi (code, s390_r0, -1);
3750 s390_xgr (code, ins->dreg, s390_r0);
3754 s390_lcgr (code, ins->dreg, ins->sreg1);
3759 s390_msr (code, ins->dreg, src2);
3763 if (ins->dreg != ins->sreg1) {
3764 s390_lgfr (code, ins->dreg, ins->sreg1);
3766 if (s390_is_imm16 (ins->inst_imm)) {
3767 s390_lghi (code, s390_r0, ins->inst_imm);
3769 s390_lgfi (code, s390_r0, ins->inst_imm);
3771 s390_msr (code, ins->dreg, s390_r0);
3776 s390_ltr (code, s390_r1, ins->sreg1);
3777 s390_jz (code, 0); CODEPTR(code, o[0]);
3778 s390_ltr (code, s390_r0, ins->sreg2);
3780 s390_lhi (code, s390_r1, 0);
3781 s390_j (code, 0); CODEPTR(code, o[1]);
3782 s390_xr (code, s390_r0, s390_r1);
3783 s390_msr (code, s390_r1, ins->sreg2);
3784 s390_xr (code, s390_r0, s390_r1);
3785 s390_srl (code, s390_r0, 0, 31);
3786 s390_ltr (code, s390_r0, s390_r0);
3787 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3788 PTRSLOT (code, o[0]);
3789 PTRSLOT (code, o[1]);
3790 s390_lgfr (code, ins->dreg, s390_r1);
3793 case OP_IMUL_OVF_UN: {
3794 s390_lhi (code, s390_r0, 0);
3795 s390_lr (code, s390_r1, ins->sreg1);
3796 s390_mlr (code, s390_r0, ins->sreg2);
3797 s390_ltr (code, s390_r0, s390_r0);
3798 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3799 s390_lgfr (code, ins->dreg, s390_r1);
3804 S390_SET (code, ins->dreg, ins->inst_c0);
3808 mono_add_patch_info (cfg, code - cfg->native_code,
3809 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3810 S390_LOAD_TEMPLATE (code, ins->dreg);
3813 case OP_JUMP_TABLE: {
3814 mono_add_patch_info (cfg, code - cfg->native_code,
3815 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3816 S390_LOAD_TEMPLATE (code, ins->dreg);
3820 if (ins->dreg != ins->sreg1) {
3821 s390_lgr (code, ins->dreg, ins->sreg1);
3825 case OP_LCONV_TO_I8:
3827 s390_lgfr (code, ins->dreg, ins->sreg1);
3829 case OP_LCONV_TO_I4:
3830 s390_lgfr (code, ins->dreg, ins->sreg1);
3833 case OP_LCONV_TO_U8:
3834 case OP_LCONV_TO_U4:
3836 s390_llgfr (code, ins->dreg, ins->sreg1);
3838 case OP_LCONV_TO_OVF_U4:
3839 S390_SET (code, s390_r0, 4294967295);
3840 s390_clgr (code, ins->sreg1, s390_r0);
3841 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3842 s390_ltgr (code, ins->sreg1, ins->sreg1);
3843 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3844 s390_llgfr(code, ins->dreg, ins->sreg1);
3846 case OP_LCONV_TO_OVF_I4_UN:
3847 S390_SET (code, s390_r0, 2147483647);
3848 s390_cgr (code, ins->sreg1, s390_r0);
3849 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3850 s390_ltgr (code, ins->sreg1, ins->sreg1);
3851 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3852 s390_lgfr (code, ins->dreg, ins->sreg1);
3855 if (ins->dreg != ins->sreg1) {
3856 s390_ldr (code, ins->dreg, ins->sreg1);
3859 case OP_MOVE_F_TO_I8:
3860 s390_lgdr (code, ins->dreg, ins->sreg1);
3862 case OP_MOVE_I8_TO_F:
3863 s390_ldgr (code, ins->dreg, ins->sreg1);
3865 case OP_MOVE_F_TO_I4:
3866 s390_lgdr (code, ins->dreg, ins->sreg1);
3868 case OP_MOVE_I4_TO_F:
3869 s390_lgfr (code, s390_r0, ins->sreg1);
3870 s390_ldgr (code, ins->dreg, s390_r0);
3872 case OP_FCONV_TO_R4:
3873 s390_ledbr (code, ins->dreg, ins->sreg1);
3874 s390_ldebr (code, ins->dreg, ins->dreg);
3876 case OP_S390_SETF4RET:
3877 s390_ledbr (code, ins->dreg, ins->sreg1);
3880 if (s390_is_imm16 (ins->inst_offset)) {
3881 s390_lghi (code, s390_r13, ins->inst_offset);
3882 } else if (s390_is_imm32 (ins->inst_offset)) {
3883 s390_lgfi (code, s390_r13, ins->inst_offset);
3885 S390_SET (code, s390_r13, ins->inst_offset);
3887 s390_ear (code, s390_r1, 0);
3888 s390_sllg(code, s390_r1, s390_r1, 0, 32);
3889 s390_ear (code, s390_r1, 1);
3890 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
3894 if (cfg->method->save_lmf)
3895 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3897 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3898 code = emit_load_volatile_arguments (code, cfg);
3901 code = backUpStackPtr(cfg, code);
3902 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
3903 mono_add_patch_info (cfg, code - cfg->native_code,
3904 MONO_PATCH_INFO_METHOD_JUMP,
3906 s390_jcl (code, S390_CC_UN, 0);
3909 case OP_CHECK_THIS: {
3910 /* ensure ins->sreg1 is not NULL */
3911 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3912 s390_ltgr (code, s390_r0, s390_r0);
3913 // EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
3917 int offset = cfg->sig_cookie + cfg->stack_usage;
3919 if (s390_is_imm16 (offset)) {
3920 s390_lghi (code, s390_r0, offset);
3921 } else if (s390_is_imm32 (offset)) {
3922 s390_lgfi (code, s390_r0, offset);
3924 S390_SET (code, s390_r0, offset);
3926 s390_agr (code, s390_r0, cfg->frame_reg);
3927 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3931 call = (MonoCallInst*)ins;
3932 if (ins->flags & MONO_INST_HAS_METHOD)
3933 mono_add_patch_info (cfg, code-cfg->native_code,
3934 MONO_PATCH_INFO_METHOD,
3937 mono_add_patch_info (cfg, code-cfg->native_code,
3938 MONO_PATCH_INFO_ABS,
3940 S390_CALL_TEMPLATE (code, s390_r14);
3941 if (call->signature->ret->type == MONO_TYPE_R4)
3942 s390_ldebr (code, s390_f0, s390_f0);
3950 call = (MonoCallInst*)ins;
3951 if (ins->flags & MONO_INST_HAS_METHOD)
3952 mono_add_patch_info (cfg, code-cfg->native_code,
3953 MONO_PATCH_INFO_METHOD,
3956 mono_add_patch_info (cfg, code-cfg->native_code,
3957 MONO_PATCH_INFO_ABS,
3959 S390_CALL_TEMPLATE (code, s390_r14);
3962 case OP_FCALL_REG: {
3963 call = (MonoCallInst*)ins;
3964 s390_lgr (code, s390_r1, ins->sreg1);
3965 s390_basr (code, s390_r14, s390_r1);
3966 if (call->signature->ret->type == MONO_TYPE_R4)
3967 s390_ldebr (code, s390_f0, s390_f0);
3973 case OP_VOIDCALL_REG:
3975 s390_lgr (code, s390_r1, ins->sreg1);
3976 s390_basr (code, s390_r14, s390_r1);
3979 case OP_FCALL_MEMBASE: {
3980 call = (MonoCallInst*)ins;
3981 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3982 s390_basr (code, s390_r14, s390_r1);
3983 if (call->signature->ret->type == MONO_TYPE_R4)
3984 s390_ldebr (code, s390_f0, s390_f0);
3987 case OP_LCALL_MEMBASE:
3988 case OP_VCALL_MEMBASE:
3989 case OP_VCALL2_MEMBASE:
3990 case OP_VOIDCALL_MEMBASE:
3991 case OP_CALL_MEMBASE: {
3992 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3993 s390_basr (code, s390_r14, s390_r1);
4000 if (cfg->param_area == 0)
4001 alloca_skip = S390_MINIMAL_STACK_SIZE;
4003 alloca_skip = cfg->param_area;
4005 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4006 s390_lgr (code, s390_r1, ins->sreg1);
4007 if (ins->flags & MONO_INST_INIT)
4008 s390_lgr (code, s390_r0, ins->sreg1);
4009 s390_aghi (code, s390_r1, 14);
4010 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4011 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4012 if (cfg->method->save_lmf) {
4013 /*----------------------------------*/
4014 /* we have to adjust lmf ebp value */
4015 /*----------------------------------*/
4016 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4018 s390_lgr (code, s390_r13, cfg->frame_reg);
4019 if (s390_is_imm16(lmfOffset)) {
4020 s390_aghi (code, s390_r13, lmfOffset);
4021 } else if (s390_is_imm32(lmfOffset)) {
4022 s390_agfi (code, s390_r13, lmfOffset);
4024 S390_SET (code, s390_r13, lmfOffset);
4026 s390_lgr (code, s390_r14, STK_BASE);
4027 s390_sgr (code, s390_r14, s390_r1);
4028 s390_stg (code, s390_r14, 0, s390_r13,
4029 G_STRUCT_OFFSET(MonoLMF, ebp));
4031 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4032 s390_sgr (code, STK_BASE, s390_r1);
4033 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4034 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4035 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4036 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4037 if (ins->flags & MONO_INST_INIT) {
4038 s390_lgr (code, s390_r1, s390_r0);
4039 s390_lgr (code, s390_r0, ins->dreg);
4040 s390_lgr (code, s390_r14, s390_r12);
4041 s390_lghi (code, s390_r13, 0);
4042 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4044 s390_lgr (code, s390_r12, s390_r14);
4049 s390_lgr (code, s390_r2, ins->sreg1);
4050 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4051 (gpointer) "mono_arch_throw_exception");
4052 S390_CALL_TEMPLATE(code, s390_r14);
4056 s390_lgr (code, s390_r2, ins->sreg1);
4057 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4058 (gpointer) "mono_arch_rethrow_exception");
4059 S390_CALL_TEMPLATE(code, s390_r14);
4062 case OP_START_HANDLER: {
4063 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4065 S390_LONG (code, stg, stg, s390_r14, 0,
4066 spvar->inst_basereg,
4067 spvar->inst_offset);
4070 case OP_ENDFILTER: {
4071 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4073 if (ins->sreg1 != s390_r2)
4074 s390_lgr(code, s390_r2, ins->sreg1);
4075 S390_LONG (code, lg, lg, s390_r14, 0,
4076 spvar->inst_basereg,
4077 spvar->inst_offset);
4078 s390_br (code, s390_r14);
4081 case OP_ENDFINALLY: {
4082 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4084 S390_LONG (code, lg, lg, s390_r14, 0,
4085 spvar->inst_basereg,
4086 spvar->inst_offset);
4087 s390_br (code, s390_r14);
4090 case OP_CALL_HANDLER: {
4091 mono_add_patch_info (cfg, code-cfg->native_code,
4092 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4093 s390_brasl (code, s390_r14, 0);
4094 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4098 ins->inst_c0 = code - cfg->native_code;
4101 case OP_RELAXED_NOP:
4104 case OP_DUMMY_STORE:
4105 case OP_NOT_REACHED:
4109 case OP_IL_SEQ_POINT:
4110 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4112 case OP_SEQ_POINT: {
4115 if (cfg->compile_aot)
4119 * Read from the single stepping trigger page. This will cause a
4120 * SIGSEGV when single stepping is enabled.
4121 * We do this _before_ the breakpoint, so single stepping after
4122 * a breakpoint is hit will step to the next IL offset.
4124 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4125 breakpointCode.pTrigger = ss_trigger_page;
4126 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4127 code += BREAKPOINT_SIZE;
4130 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4133 * A placeholder for a possible breakpoint inserted by
4134 * mono_arch_set_breakpoint ().
4136 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4140 * Add an additional nop so skipping the bp doesn't cause the ip to point
4141 * to another IL offset.
4147 case OP_GENERIC_CLASS_INIT: {
4148 static int byte_offset = -1;
4149 static guint8 bitmask;
4152 g_assert (ins->sreg1 == S390_FIRST_ARG_REG);
4154 if (byte_offset < 0)
4155 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
4157 s390_tm (code, ins->sreg1, byte_offset, bitmask);
4158 s390_jo (code, 0); CODEPTR(code, jump);
4160 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_JIT_ICALL_ADDR,
4161 "specific_trampoline_generic_class_init");
4162 S390_CALL_TEMPLATE(code, s390_r14);
4164 PTRSLOT (code, jump);
4166 ins->flags |= MONO_INST_GC_CALLSITE;
4167 ins->backend.pc_offset = code - cfg->native_code;
4171 EMIT_UNCOND_BRANCH(ins);
4174 s390_br (code, ins->sreg1);
4180 s390_lghi(code, ins->dreg, 1);
4182 s390_lghi(code, ins->dreg, 0);
4188 s390_lghi(code, ins->dreg, 1);
4190 s390_lghi(code, ins->dreg, 0);
4196 s390_lghi(code, ins->dreg, 1);
4198 s390_lghi(code, ins->dreg, 0);
4204 s390_lghi(code, ins->dreg, 1);
4206 s390_lghi(code, ins->dreg, 0);
4212 s390_lghi(code, ins->dreg, 1);
4214 s390_lghi(code, ins->dreg, 0);
4217 case OP_COND_EXC_EQ:
4218 case OP_COND_EXC_IEQ:
4219 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4221 case OP_COND_EXC_NE_UN:
4222 case OP_COND_EXC_INE_UN:
4223 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4225 case OP_COND_EXC_LT:
4226 case OP_COND_EXC_ILT:
4227 case OP_COND_EXC_LT_UN:
4228 case OP_COND_EXC_ILT_UN:
4229 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4231 case OP_COND_EXC_GT:
4232 case OP_COND_EXC_IGT:
4233 case OP_COND_EXC_GT_UN:
4234 case OP_COND_EXC_IGT_UN:
4235 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4237 case OP_COND_EXC_GE:
4238 case OP_COND_EXC_IGE:
4239 case OP_COND_EXC_GE_UN:
4240 case OP_COND_EXC_IGE_UN:
4241 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4243 case OP_COND_EXC_LE:
4244 case OP_COND_EXC_ILE:
4245 case OP_COND_EXC_LE_UN:
4246 case OP_COND_EXC_ILE_UN:
4247 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4249 case OP_COND_EXC_OV:
4250 case OP_COND_EXC_IOV:
4251 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4253 case OP_COND_EXC_NO:
4254 case OP_COND_EXC_INO:
4255 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4258 case OP_COND_EXC_IC:
4259 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4261 case OP_COND_EXC_NC:
4262 case OP_COND_EXC_INC:
4263 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4267 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4271 EMIT_COND_BRANCH (ins, S390_CC_NE);
4277 EMIT_COND_BRANCH (ins, S390_CC_LT);
4283 EMIT_COND_BRANCH (ins, S390_CC_GT);
4289 EMIT_COND_BRANCH (ins, S390_CC_GE);
4295 EMIT_COND_BRANCH (ins, S390_CC_LE);
4298 /* floating point opcodes */
4300 if (*((double *) ins->inst_p0) == 0) {
4301 s390_lzdr (code, ins->dreg);
4303 S390_SET (code, s390_r13, ins->inst_p0);
4304 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4309 if (*((float *) ins->inst_p0) == 0) {
4310 s390_lzdr (code, ins->dreg);
4312 S390_SET (code, s390_r13, ins->inst_p0);
4313 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4317 case OP_STORER8_MEMBASE_REG: {
4318 S390_LONG (code, stdy, std, ins->sreg1, 0,
4319 ins->inst_destbasereg, ins->inst_offset);
4322 case OP_LOADR8_MEMBASE: {
4323 S390_LONG (code, ldy, ld, ins->dreg, 0,
4324 ins->inst_basereg, ins->inst_offset);
4327 case OP_STORER4_MEMBASE_REG: {
4328 s390_ledbr (code, s390_f15, ins->sreg1);
4329 S390_LONG (code, stey, ste, s390_f15, 0,
4330 ins->inst_destbasereg, ins->inst_offset);
4333 case OP_LOADR4_MEMBASE: {
4334 S390_LONG (code, ldy, ld, s390_f15, 0,
4335 ins->inst_basereg, ins->inst_offset);
4336 s390_ldebr (code, ins->dreg, s390_f15);
4339 case OP_ICONV_TO_R_UN: {
4341 s390_cdlfbr (code, ins->dreg, 5, ins->sreg1, 0);
4343 s390_llgfr (code, s390_r0, ins->sreg1);
4344 s390_cdgbr (code, ins->dreg, s390_r0);
4348 case OP_LCONV_TO_R_UN: {
4350 s390_cdlgbr (code, ins->dreg, 5, ins->sreg1, 0);
4353 s390_cxgbr (code, s390_f12, ins->sreg1);
4354 s390_ltgr (code, ins->sreg1, ins->sreg1);
4355 s390_jnl (code, 0); CODEPTR(code, jump);
4356 S390_SET (code, s390_r13, 0x403f000000000000llu);
4357 s390_lgdr (code, s390_f13, s390_r13);
4358 s390_lzdr (code, s390_f15);
4359 s390_axbr (code, s390_f12, s390_f13);
4360 PTRSLOT(code, jump);
4361 s390_ldxbr (code, s390_f13, s390_f12);
4362 s390_ldr (code, ins->dreg, s390_f13);
4366 case OP_LCONV_TO_R4:
4367 case OP_ICONV_TO_R4: {
4368 s390_cegbr (code, ins->dreg, ins->sreg1);
4369 s390_ldebr (code, ins->dreg, ins->dreg);
4372 case OP_LCONV_TO_R8:
4373 case OP_ICONV_TO_R8: {
4374 s390_cdgbr (code, ins->dreg, ins->sreg1);
4377 case OP_FCONV_TO_I1:
4378 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4379 s390_ltgr (code, ins->dreg, ins->dreg);
4381 s390_oill (code, ins->dreg, 0x80);
4382 s390_lghi (code, s390_r0, 0xff);
4383 s390_ngr (code, ins->dreg, s390_r0);
4385 case OP_FCONV_TO_U1:
4387 s390_clgdbr (code, ins->dreg, 5, ins->sreg1, 0);
4388 s390_lghi (code, s390_r0, 0xff);
4389 s390_ngr (code, ins->dreg, s390_r0);
4391 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4394 case OP_FCONV_TO_I2:
4395 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4396 s390_ltgr (code, ins->dreg, ins->dreg);
4398 s390_oill (code, ins->dreg, 0x8000);
4399 s390_llill (code, s390_r0, 0xffff);
4400 s390_ngr (code, ins->dreg, s390_r0);
4402 case OP_FCONV_TO_U2:
4404 s390_clgdbr (code, ins->dreg, 5, ins->sreg1, 0);
4405 s390_llill (code, s390_r0, 0xffff);
4406 s390_ngr (code, ins->dreg, s390_r0);
4408 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4411 case OP_FCONV_TO_I4:
4413 s390_cfdbr (code, ins->dreg, 5, ins->sreg1);
4415 case OP_FCONV_TO_U4:
4418 s390_clfdbr (code, ins->dreg, 5, ins->sreg1, 0);
4420 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4423 case OP_FCONV_TO_I8:
4424 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4426 case OP_FCONV_TO_U8:
4428 s390_clgdbr (code, ins->dreg, 5, ins->sreg1, 0);
4430 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 8, FALSE);
4433 case OP_LCONV_TO_OVF_I: {
4434 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4436 s390_ltgr (code, ins->sreg2, ins->sreg2);
4437 s390_jnl (code, 0); CODEPTR(code, o[0]);
4438 s390_ltgr (code, ins->sreg1, ins->sreg1);
4439 s390_jnl (code, 0); CODEPTR(code, o[1]);
4440 s390_lhi (code, s390_r13, -1);
4441 s390_cgr (code, ins->sreg1, s390_r13);
4442 s390_jnz (code, 0); CODEPTR(code, o[2]);
4443 if (ins->dreg != ins->sreg2)
4444 s390_lgr (code, ins->dreg, ins->sreg2);
4445 s390_j (code, 0); CODEPTR(code, o[3]);
4446 PTRSLOT(code, o[0]);
4447 s390_jz (code, 0); CODEPTR(code, o[4]);
4448 PTRSLOT(code, o[1]);
4449 PTRSLOT(code, o[2]);
4450 mono_add_patch_info (cfg, code - cfg->native_code,
4451 MONO_PATCH_INFO_EXC, "OverflowException");
4452 s390_brasl (code, s390_r14, 0);
4453 PTRSLOT(code, o[3]);
4454 PTRSLOT(code, o[4]);
4458 s390_lpdbr (code, ins->dreg, ins->sreg1);
4462 s390_sqdbr (code, ins->dreg, ins->sreg1);
4467 s390_adbr (code, ins->dreg, src2);
4471 CHECK_SRCDST_NCOM_F;
4472 s390_sdbr (code, ins->dreg, src2);
4477 s390_mdbr (code, ins->dreg, src2);
4481 CHECK_SRCDST_NCOM_F;
4482 s390_ddbr (code, ins->dreg, src2);
4486 s390_lcdbr (code, ins->dreg, ins->sreg1);
4490 CHECK_SRCDST_NCOM_F;
4491 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4495 s390_cdbr (code, ins->sreg1, ins->sreg2);
4499 s390_cdbr (code, ins->sreg1, ins->sreg2);
4500 s390_lghi (code, ins->dreg, 1);
4502 s390_lghi (code, ins->dreg, 0);
4506 s390_cdbr (code, ins->sreg1, ins->sreg2);
4507 s390_lghi (code, ins->dreg, 1);
4509 s390_lghi (code, ins->dreg, 0);
4513 s390_cdbr (code, ins->sreg1, ins->sreg2);
4514 s390_lghi (code, ins->dreg, 1);
4516 s390_lghi (code, ins->dreg, 0);
4520 s390_cdbr (code, ins->sreg1, ins->sreg2);
4521 s390_lghi (code, ins->dreg, 1);
4523 s390_lghi (code, ins->dreg, 0);
4527 s390_cdbr (code, ins->sreg1, ins->sreg2);
4528 s390_lghi (code, ins->dreg, 1);
4530 s390_lghi (code, ins->dreg, 0);
4535 s390_jo (code, 0); CODEPTR(code, o);
4536 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4541 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4545 s390_jo (code, 0); CODEPTR(code, o);
4546 EMIT_COND_BRANCH (ins, S390_CC_LT);
4551 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4555 s390_jo (code, 0); CODEPTR(code, o);
4556 EMIT_COND_BRANCH (ins, S390_CC_GT);
4561 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4565 s390_jo (code, 0); CODEPTR(code, o);
4566 EMIT_COND_BRANCH (ins, S390_CC_GE);
4571 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4575 s390_jo (code, 0); CODEPTR(code, o);
4576 EMIT_COND_BRANCH (ins, S390_CC_LE);
4581 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4585 s390_lhi (code, s390_r13, 0x7f);
4586 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4587 s390_jz (code, 0); CODEPTR(code, o);
4588 mono_add_patch_info (cfg, code - cfg->native_code,
4589 MONO_PATCH_INFO_EXC, "ArithmeticException");
4590 s390_brasl (code, s390_r14,0);
4594 case OP_S390_MOVE: {
4595 if (ins->backend.size > 0) {
4596 if (ins->backend.size <= 256) {
4597 s390_mvc (code, ins->backend.size, ins->dreg,
4598 ins->inst_offset, ins->sreg1, ins->inst_imm);
4600 s390_lgr (code, s390_r0, ins->dreg);
4601 if (ins->inst_offset > 0) {
4602 if (s390_is_imm16 (ins->inst_offset)) {
4603 s390_aghi (code, s390_r0, ins->inst_offset);
4604 } else if (s390_is_imm32 (ins->inst_offset)) {
4605 s390_agfi (code, s390_r0, ins->inst_offset);
4607 S390_SET (code, s390_r13, ins->inst_offset);
4608 s390_agr (code, s390_r0, s390_r13);
4611 s390_lgr (code, s390_r12, ins->sreg1);
4612 if (ins->inst_imm > 0) {
4613 if (s390_is_imm16 (ins->inst_imm)) {
4614 s390_aghi (code, s390_r12, ins->inst_imm);
4615 } else if (s390_is_imm32 (ins->inst_imm)) {
4616 s390_agfi (code, s390_r12, ins->inst_imm);
4618 S390_SET (code, s390_r13, ins->inst_imm);
4619 s390_agr (code, s390_r12, s390_r13);
4622 if (s390_is_imm16 (ins->backend.size)) {
4623 s390_lghi (code, s390_r1, ins->backend.size);
4624 } else if (s390_is_imm32 (ins->inst_offset)) {
4625 s390_agfi (code, s390_r1, ins->backend.size);
4627 S390_SET (code, s390_r13, ins->backend.size);
4628 s390_agr (code, s390_r1, s390_r13);
4630 s390_lgr (code, s390_r13, s390_r1);
4631 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4637 case OP_ATOMIC_ADD_I8: {
4638 s390_lgr (code, s390_r1, ins->sreg2);
4639 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4640 s390_agr (code, s390_r1, s390_r0);
4641 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4642 s390_jnz (code, -10);
4643 s390_lgr (code, ins->dreg, s390_r1);
4646 case OP_ATOMIC_EXCHANGE_I8: {
4647 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4648 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4649 s390_jnz (code, -6);
4650 s390_lgr (code, ins->dreg, s390_r0);
4653 case OP_ATOMIC_ADD_I4: {
4654 s390_lgfr(code, s390_r1, ins->sreg2);
4655 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4656 s390_agr (code, s390_r1, s390_r0);
4657 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4658 s390_jnz (code, -9);
4659 s390_lgfr(code, ins->dreg, s390_r1);
4662 case OP_ATOMIC_EXCHANGE_I4: {
4663 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4664 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4665 s390_jnz (code, -4);
4666 s390_lgfr(code, ins->dreg, s390_r0);
4669 case OP_S390_BKCHAIN: {
4670 s390_lgr (code, ins->dreg, ins->sreg1);
4671 if (s390_is_imm16 (cfg->stack_offset)) {
4672 s390_aghi (code, ins->dreg, cfg->stack_offset);
4673 } else if (s390_is_imm32 (cfg->stack_offset)) {
4674 s390_agfi (code, ins->dreg, cfg->stack_offset);
4676 S390_SET (code, s390_r13, cfg->stack_offset);
4677 s390_agr (code, ins->dreg, s390_r13);
4681 case OP_MEMORY_BARRIER:
4685 case OP_GC_SAFE_POINT: {
4688 s390_chi (code, ins->sreg1, 1);
4689 s390_je (code, 0); CODEPTR(code, br);
4690 mono_add_patch_info (cfg, code- cfg->native_code, MONO_PATCH_INFO_ABS,
4691 mono_threads_state_poll);
4692 S390_CALL_TEMPLATE (code, s390_r14);
4697 case OP_GC_LIVENESS_DEF:
4698 case OP_GC_LIVENESS_USE:
4699 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4700 ins->backend.pc_offset = code - cfg->native_code;
4702 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4703 ins->backend.pc_offset = code - cfg->native_code;
4704 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4707 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4708 g_assert_not_reached ();
4711 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4712 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4713 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4714 g_assert_not_reached ();
4717 last_offset = offset;
4720 cfg->code_len = code - cfg->native_code;
4723 /*========================= End of Function ========================*/
4725 /*------------------------------------------------------------------*/
4727 /* Name - mono_arch_register_lowlevel_calls */
4729 /* Function - Register routines to help with --trace operation. */
4731 /*------------------------------------------------------------------*/
4734 mono_arch_register_lowlevel_calls (void)
4738 /*========================= End of Function ========================*/
4740 /*------------------------------------------------------------------*/
4742 /* Name - mono_arch_patch_code */
4744 /* Function - Process the patch data created during the */
4745 /* instruction build process. This resolves jumps, */
4746 /* calls, variables etc. */
4748 /*------------------------------------------------------------------*/
4751 mono_arch_patch_code (MonoCompile *cfg, MonoMethod *method, MonoDomain *domain,
4752 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4754 MonoJumpInfo *patch_info;
4756 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4757 unsigned char *ip = patch_info->ip.i + code;
4758 gconstpointer target = NULL;
4760 target = mono_resolve_patch_target (method, domain, code,
4761 patch_info, run_cctors);
4763 switch (patch_info->type) {
4764 case MONO_PATCH_INFO_IP:
4765 case MONO_PATCH_INFO_LDSTR:
4766 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4767 case MONO_PATCH_INFO_LDTOKEN:
4768 case MONO_PATCH_INFO_EXC:
4769 s390_patch_addr (ip, (guint64) target);
4771 case MONO_PATCH_INFO_METHOD:
4772 case MONO_PATCH_INFO_INTERNAL_METHOD:
4773 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
4774 case MONO_PATCH_INFO_CLASS_INIT:
4775 case MONO_PATCH_INFO_RGCTX_FETCH:
4776 case MONO_PATCH_INFO_MONITOR_ENTER:
4777 case MONO_PATCH_INFO_MONITOR_ENTER_V4:
4778 case MONO_PATCH_INFO_MONITOR_EXIT:
4779 case MONO_PATCH_INFO_ABS: {
4780 S390_EMIT_CALL (ip, target);
4783 case MONO_PATCH_INFO_SWITCH:
4784 /*----------------------------------*/
4785 /* ip points at the basr r13,0/j +4 */
4786 /* instruction the vtable value */
4787 /* follows this (i.e. ip+6) */
4788 /*----------------------------------*/
4789 S390_EMIT_LOAD (ip, target);
4791 case MONO_PATCH_INFO_METHODCONST:
4792 case MONO_PATCH_INFO_CLASS:
4793 case MONO_PATCH_INFO_IMAGE:
4794 case MONO_PATCH_INFO_FIELD:
4795 case MONO_PATCH_INFO_IID:
4796 case MONO_PATCH_INFO_EXC_NAME:
4797 target = S390_RELATIVE(target, ip);
4798 s390_patch_rel (ip, (guint64) target);
4800 case MONO_PATCH_INFO_R4:
4801 case MONO_PATCH_INFO_R8:
4802 case MONO_PATCH_INFO_METHOD_REL:
4803 g_assert_not_reached ();
4806 target = S390_RELATIVE(target, ip);
4808 s390_patch_rel (ip, (guint64) target);
4813 /*========================= End of Function ========================*/
4815 /*------------------------------------------------------------------*/
4817 /* Name - emit_load_volatile_arguments */
4819 /* Function - Emit the instructions to reload parameter regist- */
4820 /* registers for use with "tail" operations. */
4822 /* The register loading operations performed here */
4823 /* are the mirror of the store operations performed */
4824 /* in mono_arch_emit_prolog and need to be kept in */
4825 /* synchronization with it. */
4827 /*------------------------------------------------------------------*/
4830 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4833 MonoMethod *method = cfg->method;
4834 MonoMethodSignature *sig = mono_method_signature(method);
4838 cinfo = get_call_info (NULL, NULL, sig);
4840 if (cinfo->struct_ret) {
4841 ArgInfo *ainfo = &cinfo->ret;
4842 inst = cfg->vret_addr;
4843 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4846 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4847 ArgInfo *ainfo = cinfo->args + i;
4848 inst = cfg->args [pos];
4850 if (inst->opcode == OP_REGVAR) {
4851 if (ainfo->regtype == RegTypeGeneral)
4852 s390_lgr (code, ainfo->reg, inst->dreg);
4853 else if (ainfo->regtype == RegTypeFP) {
4854 if (inst->dreg != ainfo->reg) {
4855 if (ainfo->size == 4) {
4856 s390_ldebr (code, ainfo->reg, inst->dreg);
4858 s390_ldr (code, ainfo->reg, inst->dreg);
4862 else if (ainfo->regtype == RegTypeBase) {
4864 g_assert_not_reached ();
4866 if (ainfo->regtype == RegTypeGeneral) {
4867 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4868 g_assert_not_reached();
4869 switch (ainfo->size) {
4871 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4874 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4877 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4880 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4883 } else if (ainfo->regtype == RegTypeBase) {
4884 } else if (ainfo->regtype == RegTypeFP) {
4885 if (ainfo->size == 8)
4886 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4887 else if (ainfo->size == 4)
4888 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4890 g_assert_not_reached ();
4891 } else if (ainfo->regtype == RegTypeStructByVal) {
4892 if (ainfo->reg != STK_BASE) {
4893 switch (ainfo->size) {
4895 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4898 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4901 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4904 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4908 } else if (ainfo->regtype == RegTypeStructByAddr) {
4909 if (ainfo->reg != STK_BASE) {
4910 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4913 g_assert_not_reached ();
4921 /*========================= End of Function ========================*/
4923 /*------------------------------------------------------------------*/
4925 /* Name - mono_arch_emit_prolog */
4927 /* Function - Create the instruction sequence for a function */
4930 /*------------------------------------------------------------------*/
4933 mono_arch_emit_prolog (MonoCompile *cfg)
4935 MonoMethod *method = cfg->method;
4937 MonoMethodSignature *sig;
4939 long alloc_size, pos, max_offset, i, cfa_offset = 0;
4946 cfg->code_size = 512;
4948 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4950 cfg->code_size += 256;
4951 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
4952 cfg->code_size += 256;
4954 if (method->save_lmf)
4955 cfg->code_size += 200;
4957 cfg->native_code = code = g_malloc (cfg->code_size);
4959 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
4960 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
4961 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4962 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
4964 if (cfg->arch.bkchain_reg != -1)
4965 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4967 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4968 cfg->used_int_regs |= 1 << 11;
4971 alloc_size = cfg->stack_offset;
4973 cfg->stack_usage = cfa_offset = alloc_size;
4974 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
4975 s390_lgr (code, s390_r11, STK_BASE);
4976 if (s390_is_imm16 (alloc_size)) {
4977 s390_aghi (code, STK_BASE, -alloc_size);
4978 } else if (s390_is_imm32 (alloc_size)) {
4979 s390_agfi (code, STK_BASE, -alloc_size);
4981 int stackSize = alloc_size;
4982 while (stackSize > INT_MAX) {
4983 s390_agfi (code, STK_BASE, -INT_MAX);
4984 stackSize -= INT_MAX;
4986 s390_agfi (code, STK_BASE, -stackSize);
4988 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4990 if (cfg->frame_reg != STK_BASE)
4991 s390_lgr (code, s390_r11, STK_BASE);
4993 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
4995 /* store runtime generic context */
4996 if (cfg->rgctx_var) {
4997 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
4999 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
5000 cfg->rgctx_var->inst_basereg,
5001 cfg->rgctx_var->inst_offset);
5004 /* compute max_offset in order to use short forward jumps
5005 * we always do it on s390 because the immediate displacement
5006 * for jumps is too small
5009 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5011 bb->max_offset = max_offset;
5013 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5016 MONO_BB_FOR_EACH_INS (bb, ins)
5017 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5020 /* load arguments allocated to register from the stack */
5021 sig = mono_method_signature (method);
5024 cinfo = get_call_info (cfg, cfg->mempool, sig);
5026 if (cinfo->struct_ret) {
5027 ArgInfo *ainfo = &cinfo->ret;
5028 inst = cfg->vret_addr;
5029 inst->backend.size = ainfo->vtsize;
5030 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5033 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5034 ArgInfo *ainfo = cinfo->args + i;
5035 inst = cfg->args [pos];
5037 if (inst->opcode == OP_VTARG_ADDR)
5038 inst = inst->inst_left;
5040 if (inst->opcode == OP_REGVAR) {
5041 if (ainfo->regtype == RegTypeGeneral)
5042 s390_lgr (code, inst->dreg, ainfo->reg);
5043 else if (ainfo->regtype == RegTypeFP) {
5044 if (inst->dreg != ainfo->reg) {
5045 if (ainfo->size == 4) {
5046 s390_ledbr (code, inst->dreg, ainfo->reg);
5048 s390_ldr (code, inst->dreg, ainfo->reg);
5052 else if (ainfo->regtype == RegTypeBase) {
5053 s390_lgr (code, s390_r13, STK_BASE);
5054 s390_aghi (code, s390_r13, alloc_size);
5055 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5057 g_assert_not_reached ();
5059 if (cfg->verbose_level > 2)
5060 g_print ("Argument %d assigned to register %s\n",
5061 pos, mono_arch_regname (inst->dreg));
5063 if (ainfo->regtype == RegTypeGeneral) {
5064 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5065 g_assert_not_reached();
5066 switch (ainfo->size) {
5068 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5071 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5074 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5077 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5080 } else if (ainfo->regtype == RegTypeBase) {
5081 } else if (ainfo->regtype == RegTypeFP) {
5082 if (ainfo->size == 8)
5083 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5084 else if (ainfo->size == 4)
5085 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5087 g_assert_not_reached ();
5088 } else if (ainfo->regtype == RegTypeStructByVal) {
5089 int doffset = inst->inst_offset;
5091 if (ainfo->reg != STK_BASE)
5095 s390_lgr (code, s390_r13, STK_BASE);
5096 s390_aghi (code, s390_r13, alloc_size);
5099 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5100 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5105 if (ainfo->reg == STK_BASE)
5106 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5107 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5110 if (ainfo->reg == STK_BASE)
5111 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5112 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5115 if (ainfo->reg == STK_BASE)
5116 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5117 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5120 if (ainfo->reg == STK_BASE)
5121 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5122 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5125 } else if (ainfo->regtype == RegTypeStructByAddr) {
5126 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5127 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5129 g_assert_not_reached ();
5134 if (method->save_lmf) {
5135 /*---------------------------------------------------------------*/
5136 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5137 /*---------------------------------------------------------------*/
5138 lmfOffset = alloc_size - sizeof(MonoLMF);
5140 s390_lgr (code, s390_r13, cfg->frame_reg);
5141 s390_aghi (code, s390_r13, lmfOffset);
5143 /*---------------------------------------------------------------*/
5144 /* Preserve the parameter registers while we fix up the lmf */
5145 /*---------------------------------------------------------------*/
5146 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5147 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5149 /*---------------------------------------------------------------*/
5150 /* On return from this call r2 have the address of the &lmf */
5151 /*---------------------------------------------------------------*/
5152 if (lmf_addr_tls_offset == -1) {
5153 mono_add_patch_info (cfg, code - cfg->native_code,
5154 MONO_PATCH_INFO_INTERNAL_METHOD,
5155 (gpointer)"mono_get_lmf_addr");
5156 S390_CALL_TEMPLATE(code, s390_r1);
5158 /*-------------------------------------------------------*/
5159 /* Get LMF by getting value from thread level storage */
5160 /*-------------------------------------------------------*/
5161 s390_ear (code, s390_r1, 0);
5162 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5163 s390_ear (code, s390_r1, 1);
5164 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5167 /*---------------------------------------------------------------*/
5168 /* Set lmf.lmf_addr = jit_tls->lmf */
5169 /*---------------------------------------------------------------*/
5170 s390_stg (code, s390_r2, 0, s390_r13,
5171 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5173 /*---------------------------------------------------------------*/
5174 /* Get current lmf */
5175 /*---------------------------------------------------------------*/
5176 s390_lg (code, s390_r0, 0, s390_r2, 0);
5178 /*---------------------------------------------------------------*/
5179 /* Set our lmf as the current lmf */
5180 /*---------------------------------------------------------------*/
5181 s390_stg (code, s390_r13, 0, s390_r2, 0);
5183 /*---------------------------------------------------------------*/
5184 /* Have our lmf.previous_lmf point to the last lmf */
5185 /*---------------------------------------------------------------*/
5186 s390_stg (code, s390_r0, 0, s390_r13,
5187 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5189 /*---------------------------------------------------------------*/
5190 /* save method info */
5191 /*---------------------------------------------------------------*/
5192 S390_SET (code, s390_r1, method);
5193 s390_stg (code, s390_r1, 0, s390_r13,
5194 G_STRUCT_OFFSET(MonoLMF, method));
5196 /*---------------------------------------------------------------*/
5197 /* save the current IP */
5198 /*---------------------------------------------------------------*/
5199 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5200 s390_basr (code, s390_r1, 0);
5201 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5203 /*---------------------------------------------------------------*/
5204 /* Save general and floating point registers */
5205 /*---------------------------------------------------------------*/
5206 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5207 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5208 for (i = 0; i < 16; i++) {
5209 s390_std (code, i, 0, s390_r13,
5210 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5213 /*---------------------------------------------------------------*/
5214 /* Restore the parameter registers now that we've set up the lmf */
5215 /*---------------------------------------------------------------*/
5216 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5217 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5221 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5223 cfg->code_len = code - cfg->native_code;
5224 g_assert (cfg->code_len < cfg->code_size);
5229 /*========================= End of Function ========================*/
5231 /*------------------------------------------------------------------*/
5233 /* Name - mono_arch_emit_epilog */
5235 /* Function - Emit the instructions for a function epilog. */
5237 /*------------------------------------------------------------------*/
5240 mono_arch_emit_epilog (MonoCompile *cfg)
5242 MonoMethod *method = cfg->method;
5245 int max_epilog_size = 96;
5247 if (cfg->method->save_lmf)
5248 max_epilog_size += 128;
5250 if (mono_jit_trace_calls != NULL)
5251 max_epilog_size += 128;
5252 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5253 max_epilog_size += 128;
5255 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5256 cfg->code_size *= 2;
5257 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5258 cfg->stat_code_reallocs++;
5261 code = cfg->native_code + cfg->code_len;
5263 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5264 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5268 if (method->save_lmf)
5269 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5271 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5272 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5274 code = backUpStackPtr(cfg, code);
5276 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5277 s390_br (code, s390_r14);
5279 cfg->code_len = code - cfg->native_code;
5281 g_assert (cfg->code_len < cfg->code_size);
5285 /*========================= End of Function ========================*/
5287 /*------------------------------------------------------------------*/
5289 /* Name - mono_arch_emit_exceptions */
5291 /* Function - Emit the blocks to handle exception conditions. */
5293 /*------------------------------------------------------------------*/
5296 mono_arch_emit_exceptions (MonoCompile *cfg)
5298 MonoJumpInfo *patch_info;
5304 MonoClass *exc_classes [MAX_EXC];
5305 guint8 *exc_throw_start [MAX_EXC];
5307 for (patch_info = cfg->patch_info;
5309 patch_info = patch_info->next) {
5310 if (patch_info->type == MONO_PATCH_INFO_EXC)
5314 code_size = exc_count * 48;
5316 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5317 cfg->code_size *= 2;
5318 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5319 cfg->stat_code_reallocs++;
5322 code = cfg->native_code + cfg->code_len;
5324 /*---------------------------------------------------------------------*/
5325 /* Add code to raise exceptions */
5326 /*---------------------------------------------------------------------*/
5327 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5328 switch (patch_info->type) {
5329 case MONO_PATCH_INFO_EXC: {
5330 guint8 *ip = patch_info->ip.i + cfg->native_code;
5331 MonoClass *exc_class;
5334 /*-----------------------------------------------------*/
5335 /* Patch the branch in epilog to come here */
5336 /*-----------------------------------------------------*/
5337 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5339 exc_class = mono_class_from_name (mono_defaults.corlib,
5341 patch_info->data.name);
5342 g_assert (exc_class);
5343 throw_ip = patch_info->ip.i;
5345 for (iExc = 0; iExc < nThrows; ++iExc)
5346 if (exc_classes [iExc] == exc_class)
5349 if (iExc < nThrows) {
5350 s390_jcl (code, S390_CC_UN,
5351 (guint64) exc_throw_start [iExc]);
5352 patch_info->type = MONO_PATCH_INFO_NONE;
5355 if (nThrows < MAX_EXC) {
5356 exc_classes [nThrows] = exc_class;
5357 exc_throw_start [nThrows] = code;
5360 /*---------------------------------------------*/
5361 /* Patch the parameter passed to the handler */
5362 /*---------------------------------------------*/
5363 S390_SET (code, s390_r2, exc_class->type_token);
5364 /*---------------------------------------------*/
5365 /* Load return address & parameter register */
5366 /*---------------------------------------------*/
5367 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5368 cfg->native_code + 8), code));
5369 /*---------------------------------------------*/
5370 /* Reuse the current patch to set the jump */
5371 /*---------------------------------------------*/
5372 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5373 patch_info->data.name = "mono_arch_throw_corlib_exception";
5374 patch_info->ip.i = code - cfg->native_code;
5375 S390_BR_TEMPLATE (code, s390_r1);
5385 cfg->code_len = code - cfg->native_code;
5387 g_assert (cfg->code_len < cfg->code_size);
5391 /*========================= End of Function ========================*/
5393 /*------------------------------------------------------------------*/
5395 /* Name - mono_arch_finish_init */
5397 /* Function - Setup the JIT's Thread Level Specific Data. */
5399 /*------------------------------------------------------------------*/
5402 mono_arch_finish_init (void)
5404 appdomain_tls_offset = mono_domain_get_tls_offset();
5405 lmf_tls_offset = mono_get_lmf_tls_offset();
5406 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5409 /*========================= End of Function ========================*/
5411 /*------------------------------------------------------------------*/
5413 /* Name - mono_arch_free_jit_tls_data */
5415 /* Function - Free tls data. */
5417 /*------------------------------------------------------------------*/
5420 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5424 /*========================= End of Function ========================*/
5426 /*------------------------------------------------------------------*/
5428 /* Name - mono_arch_emit_inst_for_method */
5430 /*------------------------------------------------------------------*/
5433 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5438 /*========================= End of Function ========================*/
5440 /*------------------------------------------------------------------*/
5442 /* Name - mono_arch_decompose_opts */
5444 /* Function - Decompose opcode into a System z opcode. */
5446 /*------------------------------------------------------------------*/
5449 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5452 * Have to rename these to avoid being decomposed normally, since the normal
5453 * decomposition does not work on S390.
5455 switch (ins->opcode) {
5457 ins->opcode = OP_S390_ISUB_OVF;
5459 case OP_ISUB_OVF_UN:
5460 ins->opcode = OP_S390_ISUB_OVF_UN;
5463 ins->opcode = OP_S390_IADD_OVF;
5465 case OP_IADD_OVF_UN:
5466 ins->opcode = OP_S390_IADD_OVF_UN;
5469 ins->opcode = OP_S390_LADD_OVF;
5471 case OP_LADD_OVF_UN:
5472 ins->opcode = OP_S390_LADD_OVF_UN;
5475 ins->opcode = OP_S390_LSUB_OVF;
5477 case OP_LSUB_OVF_UN:
5478 ins->opcode = OP_S390_LSUB_OVF_UN;
5485 /*========================= End of Function ========================*/
5487 /*------------------------------------------------------------------*/
5489 /* Name - mono_arch_print_tree */
5491 /* Function - Print platform-specific opcode details. */
5493 /* Returns - 1 - opcode details have been printed */
5494 /* 0 - opcode details have not been printed */
5496 /*------------------------------------------------------------------*/
5499 mono_arch_print_tree (MonoInst *tree, int arity)
5503 switch (tree->opcode) {
5504 case OP_S390_LOADARG:
5505 case OP_S390_ARGREG:
5506 case OP_S390_ARGPTR:
5507 printf ("[0x%lx(%s)]", tree->inst_offset,
5508 mono_arch_regname (tree->inst_basereg));
5511 case OP_S390_STKARG:
5512 printf ("[0x%lx(previous_frame)]",
5517 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5518 tree->inst_offset, tree->backend.size,
5519 mono_arch_regname(tree->dreg),
5521 mono_arch_regname(tree->sreg1));
5524 case OP_S390_SETF4RET:
5525 printf ("[f%s,f%s]",
5526 mono_arch_regname (tree->dreg),
5527 mono_arch_regname (tree->sreg1));
5531 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5533 mono_arch_regname (tree->sreg1));
5536 case OP_S390_BKCHAIN:
5537 printf ("[previous_frame(%s)]",
5538 mono_arch_regname (tree->sreg1));
5546 /*========================= End of Function ========================*/
5548 /*------------------------------------------------------------------*/
5550 /* Name - mono_arch_regalloc_cost */
5552 /* Function - Determine the cost, in the number of memory */
5553 /* references, of the action of allocating the var- */
5554 /* iable VMV into a register during global register */
5557 /* Returns - Cost */
5559 /*------------------------------------------------------------------*/
5562 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5568 /*========================= End of Function ========================*/
5570 /*------------------------------------------------------------------*/
5572 /* Name - mono_arch_flush_register_windows */
5578 /*------------------------------------------------------------------*/
5581 mono_arch_flush_register_windows (void)
5585 /*========================= End of Function ========================*/
5587 /*------------------------------------------------------------------*/
5589 /* Name - mono_arch_is_inst_imm */
5591 /* Function - Determine if operand qualifies as an immediate */
5592 /* value. For s390 this is a value -32768-32768 */
5594 /* Returns - True|False - is [not] immediate value. */
5596 /*------------------------------------------------------------------*/
5599 mono_arch_is_inst_imm (gint64 imm)
5601 return s390_is_imm32 (imm);
5604 /*========================= End of Function ========================*/
5606 /*------------------------------------------------------------------*/
5608 /* Name - mono_arch_get_patch_offset */
5610 /* Function - Dummy entry point until s390x supports aot. */
5612 /* Returns - Offset for patch. */
5614 /*------------------------------------------------------------------*/
5617 mono_arch_get_patch_offset (guint8 *code)
5622 /*========================= End of Function ========================*/
5624 /*------------------------------------------------------------------*/
5626 /* Name - mono_arch_context_get_int_reg. */
5630 /* Returns - Return a register from the context. */
5632 /*------------------------------------------------------------------*/
5635 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5637 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5640 /*========================= End of Function ========================*/
5642 /*------------------------------------------------------------------*/
5644 /* Name - mono_arch_context_set_int_reg. */
5646 /* Function - Set a value in a specified register. */
5648 /*------------------------------------------------------------------*/
5651 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5653 ctx->uc_mcontext.gregs[reg] = val;
5656 /*========================= End of Function ========================*/
5658 /*------------------------------------------------------------------*/
5660 /* Name - mono_arch_get_this_arg_from_call. */
5664 /*------------------------------------------------------------------*/
5667 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5669 return (gpointer) regs [s390_r2];
5672 /*========================= End of Function ========================*/
5674 /*------------------------------------------------------------------*/
5676 /* Name - mono_arch_install_handler_block_guard */
5680 /*------------------------------------------------------------------*/
5683 mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause,
5684 MonoContext *ctx, gpointer new_value)
5687 gpointer *sp, old_value;
5690 offset = clause->exvar_offset;
5693 bp = MONO_CONTEXT_GET_BP (ctx);
5694 sp = *(gpointer*)(bp + offset);
5697 if (old_value < ji->code_start || (char*)old_value > ((char*)ji->code_start + ji->code_size))
5705 /*========================= End of Function ========================*/
5707 /*------------------------------------------------------------------*/
5709 /* Name - get_delegate_invoke_impl. */
5713 /*------------------------------------------------------------------*/
5716 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5718 guint8 *code, *start;
5723 start = code = mono_global_codeman_reserve (size);
5725 /* Replace the this argument with the target */
5726 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5727 s390_lg (code, s390_r2, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, target));
5728 s390_br (code, s390_r1);
5729 g_assert ((code - start) <= size);
5731 mono_arch_flush_icache (start, size);
5735 size = 32 + param_count * 8;
5736 start = code = mono_global_codeman_reserve (size);
5738 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET (MonoDelegate, method_ptr));
5739 /* slide down the arguments */
5740 for (i = 0; i < param_count; ++i) {
5741 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5743 s390_br (code, s390_r1);
5745 g_assert ((code - start) <= size);
5747 mono_arch_flush_icache (start, size);
5750 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL);
5753 *code_len = code - start;
5758 /*========================= End of Function ========================*/
5760 /*------------------------------------------------------------------*/
5762 /* Name - mono_arch_get_delegate_invoke_impls. */
5766 /*------------------------------------------------------------------*/
5769 mono_arch_get_delegate_invoke_impls (void)
5777 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
5778 res = g_slist_prepend (res, mono_tramp_info_create ("delegate_invoke_impl_has_target", code, code_len, NULL, NULL));
5780 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
5781 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
5782 tramp_name = g_strdup_printf ("delegate_invoke_impl_target_%d", i);
5783 res = g_slist_prepend (res, mono_tramp_info_create (tramp_name, code, code_len, NULL, NULL));
5784 g_free (tramp_name);
5790 /*========================= End of Function ========================*/
5792 /*------------------------------------------------------------------*/
5794 /* Name - mono_arch_get_delegate_invoke_impl. */
5798 /*------------------------------------------------------------------*/
5801 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
5803 guint8 *code, *start;
5805 /* FIXME: Support more cases */
5806 if (MONO_TYPE_ISSTRUCT (sig->ret))
5810 static guint8* cached = NULL;
5816 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
5818 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
5820 mono_memory_barrier ();
5824 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
5827 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
5829 for (i = 0; i < sig->param_count; ++i)
5830 if (!mono_is_regsize_var (sig->params [i]))
5834 code = cache [sig->param_count];
5838 if (mono_aot_only) {
5839 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
5840 start = mono_aot_get_trampoline (name);
5843 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
5846 mono_memory_barrier ();
5848 cache [sig->param_count] = start;
5853 /*========================= End of Function ========================*/
5855 /*------------------------------------------------------------------*/
5857 /* Name - mono_arch_get_delegate_virtual_invoke_impl. */
5861 /*------------------------------------------------------------------*/
5864 mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method,
5865 int offset, gboolean load_imt_reg)
5867 guint8 *code, *start;
5870 start = code = mono_global_codeman_reserve (size);
5873 * Replace the "this" argument with the target
5875 s390_lgr (code, s390_r1, s390_r2);
5876 s390_lg (code, s390_r2, 0, s390_r1, MONO_STRUCT_OFFSET(MonoDelegate, target));
5879 * Load the IMT register, if needed
5882 s390_lg (code, MONO_ARCH_IMT_REG, 0, s390_r1, MONO_STRUCT_OFFSET(MonoDelegate, method));
5888 s390_lg (code, s390_r1, 0, s390_r2, MONO_STRUCT_OFFSET(MonoObject, vtable));
5890 s390_agfi(code, s390_r1, offset);
5892 s390_lg (code, s390_r1, 0, s390_r1, 0);
5893 s390_br (code, s390_r1);
5898 /*========================= End of Function ========================*/
5900 /*------------------------------------------------------------------*/
5902 /* Name - mono_arch_build_imt_thunk. */
5906 /*------------------------------------------------------------------*/
5909 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
5910 MonoIMTCheckItem **imt_entries, int count,
5911 gpointer fail_tramp)
5915 guchar *code, *start;
5917 for (i = 0; i < count; ++i) {
5918 MonoIMTCheckItem *item = imt_entries [i];
5919 if (item->is_equals) {
5920 if (item->check_target_idx) {
5921 if (!item->compare_done)
5922 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5923 if (item->has_target_code)
5924 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
5926 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
5930 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
5932 if (!item->has_target_code)
5933 item->chunk_size += LOAD_SIZE;
5935 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
5936 #if ENABLE_WRONG_METHOD_CHECK
5937 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5942 item->chunk_size += CMP_SIZE + JUMP_SIZE;
5943 imt_entries [item->check_target_idx]->compare_done = TRUE;
5945 size += item->chunk_size;
5949 code = mono_method_alloc_generic_virtual_thunk (domain, size);
5951 code = mono_domain_code_reserve (domain, size);
5955 for (i = 0; i < count; ++i) {
5956 MonoIMTCheckItem *item = imt_entries [i];
5957 item->code_target = (guint8 *) code;
5958 if (item->is_equals) {
5959 if (item->check_target_idx) {
5960 if (!item->compare_done) {
5961 S390_SET (code, s390_r0, item->key);
5962 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5964 item->jmp_code = (guint8*) code;
5965 s390_jcl (code, S390_CC_NE, 0);
5967 if (item->has_target_code) {
5968 S390_SET (code, s390_r1, item->value.target_code);
5970 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
5971 s390_lg (code, s390_r1, 0, s390_r1, 0);
5973 s390_br (code, s390_r1);
5978 S390_SET (code, s390_r0, item->key);
5979 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
5980 item->jmp_code = (guint8*) code;
5981 s390_jcl (code, S390_CC_NE, 0);
5982 if (item->has_target_code) {
5983 S390_SET (code, s390_r1, item->value.target_code);
5986 S390_SET (code, s390_r1,
5987 (&(vtable->vtable [item->value.vtable_slot])));
5988 s390_lg (code, s390_r1, 0, s390_r1, 0);
5990 s390_br (code, s390_r1);
5991 target = (gint64) S390_RELATIVE(code, item->jmp_code);
5992 s390_patch_rel(item->jmp_code+2, target);
5993 S390_SET (code, s390_r1, fail_tramp);
5994 s390_br (code, s390_r1);
5995 item->jmp_code = NULL;
5997 /* enable the commented code to assert on wrong method */
5998 #if ENABLE_WRONG_METHOD_CHECK
5999 g_assert_not_reached ();
6001 S390_SET (code, s390_r1, (&(vtable->vtable [item->value.vtable_slot])));
6002 s390_lg (code, s390_r1, 0, s390_r1, 0);
6003 s390_br (code, s390_r1);
6007 S390_SET (code, s390_r0, item->key);
6008 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6009 item->jmp_code = (guint8 *) code;
6010 s390_jcl (code, S390_CC_GE, 0);
6014 * patch the branches to get to the target items
6016 for (i = 0; i < count; ++i) {
6017 MonoIMTCheckItem *item = imt_entries [i];
6018 if (item->jmp_code) {
6019 if (item->check_target_idx) {
6021 offset = (gint64) S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6023 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6028 mono_arch_flush_icache ((guint8*)start, (code - start));
6029 mono_profiler_code_buffer_new (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL);
6032 mono_stats.imt_thunks_size += (code - start);
6034 g_assert (code - start <= size);
6039 /*========================= End of Function ========================*/
6041 /*------------------------------------------------------------------*/
6043 /* Name - mono_arch_find_imt_method. */
6045 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6046 /* found in the save area. */
6048 /*------------------------------------------------------------------*/
6051 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6053 return ((MonoMethod *) regs [MONO_ARCH_IMT_REG]);
6056 /*========================= End of Function ========================*/
6058 /*------------------------------------------------------------------*/
6060 /* Name - mono_arch_find_static_call_vtable */
6062 /* Function - Find the static call vtable. */
6064 /*------------------------------------------------------------------*/
6067 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
6069 mgreg_t *r = (mgreg_t*)regs;
6071 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
6074 /*========================= End of Function ========================*/
6076 /*------------------------------------------------------------------*/
6078 /* Name - mono_arch_get_cie_program */
6080 /* Function - Find the static call vtable. */
6082 /*------------------------------------------------------------------*/
6085 mono_arch_get_cie_program (void)
6089 mono_add_unwind_op_def_cfa (l, 0, 0, STK_BASE, 0);
6094 /*========================= End of Function ========================*/
6096 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6098 /*------------------------------------------------------------------*/
6100 /* Name - mono_arch_set_breakpoint. */
6102 /* Function - Set a breakpoint at the native code corresponding */
6103 /* to JI at NATIVE_OFFSET. The location should */
6104 /* contain code emitted by OP_SEQ_POINT. */
6106 /*------------------------------------------------------------------*/
6109 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6113 breakpointCode.pTrigger = bp_trigger_page;
6114 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6115 code += BREAKPOINT_SIZE;
6118 /*========================= End of Function ========================*/
6120 /*------------------------------------------------------------------*/
6122 /* Name - mono_arch_clear_breakpoint. */
6124 /* Function - Clear the breakpoint at IP. */
6126 /*------------------------------------------------------------------*/
6129 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6134 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6138 /*========================= End of Function ========================*/
6140 /*------------------------------------------------------------------*/
6142 /* Name - mono_arch_is_breakpoint_event. */
6146 /*------------------------------------------------------------------*/
6149 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6151 siginfo_t* sinfo = (siginfo_t*) info;
6154 * Sometimes the address is off by 4
6156 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6162 /*========================= End of Function ========================*/
6164 /*------------------------------------------------------------------*/
6166 /* Name - mono_arch_skip_breakpoint. */
6168 /* Function - Modify the CTX so the IP is placed after the */
6169 /* breakpoint instruction, so when we resume, the */
6170 /* instruction is not executed again. */
6172 /*------------------------------------------------------------------*/
6175 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6177 MONO_CONTEXT_SET_IP (ctx, ((guint8*)MONO_CONTEXT_GET_IP (ctx) + sizeof(RXY_Format)));
6180 /*========================= End of Function ========================*/
6182 /*------------------------------------------------------------------*/
6184 /* Name - mono_arch_start_single_stepping. */
6186 /* Function - Start single stepping. */
6188 /*------------------------------------------------------------------*/
6191 mono_arch_start_single_stepping (void)
6193 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6196 /*========================= End of Function ========================*/
6198 /*------------------------------------------------------------------*/
6200 /* Name - mono_arch_stop_single_stepping. */
6202 /* Function - Stop single stepping. */
6204 /*------------------------------------------------------------------*/
6207 mono_arch_stop_single_stepping (void)
6209 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6212 /*========================= End of Function ========================*/
6214 /*------------------------------------------------------------------*/
6216 /* Name - mono_arch_is_single_step_event. */
6218 /* Function - Return whether the machine state in sigctx cor- */
6219 /* responds to a single step event. */
6221 /*------------------------------------------------------------------*/
6224 mono_arch_is_single_step_event (void *info, void *sigctx)
6226 siginfo_t* sinfo = (siginfo_t*) info;
6229 * Sometimes the address is off by 4
6231 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6237 /*========================= End of Function ========================*/
6239 /*------------------------------------------------------------------*/
6241 /* Name - mono_arch_skip_single_step. */
6243 /* Function - Modify the ctx so the IP is placed after the */
6244 /* single step trigger instruction, so that the */
6245 /* instruction is not executed again. */
6247 /*------------------------------------------------------------------*/
6250 mono_arch_skip_single_step (MonoContext *ctx)
6252 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6255 /*========================= End of Function ========================*/
6257 /*------------------------------------------------------------------*/
6259 /* Name - mono_arch_create_seq_point_info. */
6261 /* Function - Return a pointer to a data struction which is */
6262 /* used by the sequence point implementation in */
6265 /*------------------------------------------------------------------*/
6268 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6274 /*------------------------------------------------------------------*/
6276 /* Name - mono_arch_init_lmf_ext. */
6280 /*------------------------------------------------------------------*/
6283 mono_arch_init_lmf_ext (MonoLMFExt *ext, gpointer prev_lmf)
6285 ext->lmf.previous_lmf = prev_lmf;
6286 /* Mark that this is a MonoLMFExt */
6287 ext->lmf.previous_lmf = (gpointer)(((gssize)ext->lmf.previous_lmf) | 2);
6288 ext->lmf.ebp = (gssize)ext;
6291 /*========================= End of Function ========================*/
6296 mono_arch_opcode_supported (int opcode)
6299 case OP_ATOMIC_ADD_I4:
6300 case OP_ATOMIC_ADD_I8:
6301 case OP_ATOMIC_EXCHANGE_I4:
6302 case OP_ATOMIC_EXCHANGE_I8: