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(I_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() EnterCriticalSection (&mini_arch_mutex)
250 #define mono_mini_arch_unlock() LeaveCriticalSection (&mini_arch_mutex)
252 /*========================= End of Defines =========================*/
254 /*------------------------------------------------------------------*/
255 /* I n c l u d e s */
256 /*------------------------------------------------------------------*/
261 #include <mono/metadata/appdomain.h>
262 #include <mono/metadata/debug-helpers.h>
263 #include <mono/metadata/profiler-private.h>
264 #include <mono/utils/mono-math.h>
265 #include <mono/utils/mono-mmap.h>
267 #include "mini-s390x.h"
268 #include "cpu-s390x.h"
269 #include "jit-icalls.h"
273 /*========================= End of Includes ========================*/
275 /*------------------------------------------------------------------*/
276 /* T y p e d e f s */
277 /*------------------------------------------------------------------*/
289 /*------------------------------------------------------------------*/
290 /* Used by the instrument_emit_epilog */
291 /*------------------------------------------------------------------*/
302 typedef struct InstList InstList;
316 RegTypeStructByValInFP,
318 RegTypeStructByAddrOnStack
322 gint32 offset; /* offset from caller's stack */
323 gint32 offparm; /* offset from callee's stack */
324 guint16 vtsize; /* in param area */
327 guint32 size; /* Size of structure used by RegTypeStructByVal */
328 gint32 type; /* Data type of argument */
344 gint64 gr[5]; /* R2-R6 */
345 gdouble fp[3]; /* F0-F2 */
346 } __attribute__ ((packed)) RegParm;
354 } __attribute__ ((packed)) breakpoint_t;
356 /*========================= End of Typedefs ========================*/
358 /*------------------------------------------------------------------*/
359 /* P r o t o t y p e s */
360 /*------------------------------------------------------------------*/
362 static void indent (int);
363 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
364 static void decodeParm (MonoType *, void *, int);
365 static void enter_method (MonoMethod *, RegParm *, char *);
366 static void leave_method (MonoMethod *, ...);
367 static gboolean is_regsize_var (MonoType *);
368 static inline void add_general (guint *, size_data *, ArgInfo *);
369 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
370 static inline void add_float (guint *, size_data *, ArgInfo *);
371 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
372 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
373 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
374 static void catch_SIGILL(int, siginfo_t *, void *);
375 static __inline__ void emit_unwind_regs(MonoCompile *, guint8 *, int, int, long);
377 /*========================= End of Prototypes ======================*/
379 /*------------------------------------------------------------------*/
380 /* G l o b a l V a r i a b l e s */
381 /*------------------------------------------------------------------*/
383 int mono_exc_esp_offset = 0;
385 static int indent_level = 0;
389 static gint appdomain_tls_offset = -1,
391 lmf_addr_tls_offset = -1;
393 pthread_key_t lmf_addr_key;
395 gboolean lmf_addr_key_inited = FALSE;
401 extern __thread MonoDomain *tls_appdomain;
402 extern __thread MonoThread *tls_current_object;
403 extern __thread gpointer mono_lmf_addr;
408 * The code generated for sequence points reads from this location,
409 * which is made read-only when single stepping is enabled.
411 static gpointer ss_trigger_page;
414 * Enabled breakpoints read from this trigger page
416 static gpointer bp_trigger_page;
418 breakpoint_t breakpointCode;
421 * This mutex protects architecture specific caches
423 static CRITICAL_SECTION mini_arch_mutex;
425 /*====================== End of Global Variables ===================*/
427 /*------------------------------------------------------------------*/
429 /* Name - mono_arch_regname */
431 /* Function - Returns the name of the register specified by */
432 /* the input parameter. */
434 /*------------------------------------------------------------------*/
437 mono_arch_regname (int reg) {
438 static const char * rnames[] = {
439 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
440 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
441 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
445 if (reg >= 0 && reg < 16)
451 /*========================= End of Function ========================*/
453 /*------------------------------------------------------------------*/
455 /* Name - mono_arch_fregname */
457 /* Function - Returns the name of the register specified by */
458 /* the input parameter. */
460 /*------------------------------------------------------------------*/
463 mono_arch_fregname (int reg) {
464 static const char * rnames[] = {
465 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
466 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
467 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
471 if (reg >= 0 && reg < 16)
477 /*========================= End of Function ========================*/
479 /*------------------------------------------------------------------*/
481 /* Name - arch_get_argument_info */
483 /* Function - Gathers information on parameters such as size, */
484 /* alignment, and padding. arg_info should be large */
485 /* enough to hold param_count + 1 entries. */
487 /* Parameters - @csig - Method signature */
488 /* @param_count - No. of parameters to consider */
489 /* @arg_info - An array to store the result info */
491 /* Returns - Size of the activation frame */
493 /*------------------------------------------------------------------*/
496 mono_arch_get_argument_info (MonoGenericSharingContext *gsctx, MonoMethodSignature *csig,
498 MonoJitArgumentInfo *arg_info)
500 int k, frame_size = 0;
501 int size, align, pad;
504 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
505 frame_size += sizeof (gpointer);
509 arg_info [0].offset = offset;
512 frame_size += sizeof (gpointer);
516 arg_info [0].size = frame_size;
518 for (k = 0; k < param_count; k++) {
521 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
523 size = mini_type_stack_size (NULL, csig->params [k], &align);
525 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
526 arg_info [k].pad = pad;
528 arg_info [k + 1].pad = 0;
529 arg_info [k + 1].size = size;
531 arg_info [k + 1].offset = offset;
535 align = MONO_ARCH_FRAME_ALIGNMENT;
536 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
537 arg_info [k].pad = pad;
542 /*========================= End of Function ========================*/
544 /*------------------------------------------------------------------*/
546 /* Name - emit_unwind_regs. */
548 /* Function - Determines if a value can be returned in one or */
551 /*------------------------------------------------------------------*/
553 static void __inline__
554 emit_unwind_regs(MonoCompile *cfg, guint8 *code, int start, int end, long offset)
558 for (i = start; i < end; i++) {
559 mono_emit_unwind_op_offset (cfg, code, i, offset);
560 offset += sizeof(gulong);
564 /*========================= End of Function ========================*/
566 /*------------------------------------------------------------------*/
568 /* Name - retFitsInReg. */
570 /* Function - Determines if a value can be returned in one or */
573 /*------------------------------------------------------------------*/
575 static inline gboolean
576 retFitsInReg(guint32 size)
591 /*========================= End of Function ========================*/
593 /*------------------------------------------------------------------*/
595 /* Name - backStackPtr. */
597 /* Function - Restore Stack Pointer to previous frame. */
599 /*------------------------------------------------------------------*/
601 static inline guint8 *
602 backUpStackPtr(MonoCompile *cfg, guint8 *code)
604 int stackSize = cfg->stack_usage;
606 if (cfg->frame_reg != STK_BASE)
607 s390_lgr (code, STK_BASE, cfg->frame_reg);
609 if (s390_is_imm16 (stackSize)) {
610 s390_aghi (code, STK_BASE, stackSize);
612 while (stackSize > 32767) {
613 s390_aghi (code, STK_BASE, 32767);
616 s390_aghi (code, STK_BASE, stackSize);
621 /*========================= End of Function ========================*/
623 /*------------------------------------------------------------------*/
627 /* Function - Perform nice indenting to current level */
629 /*------------------------------------------------------------------*/
635 indent_level += diff;
642 indent_level += diff;
645 /*========================= End of Function ========================*/
647 /*------------------------------------------------------------------*/
649 /* Name - cvtMonoType */
651 /* Function - Convert a mono-type to a string. */
653 /*------------------------------------------------------------------*/
656 cvtMonoType(MonoTypeEnum t)
661 return "MONO_TYPE_END";
663 return "MONO_TYPE_VOID";
664 case MONO_TYPE_BOOLEAN:
665 return "MONO_TYPE_BOOLEAN";
667 return "MONO_TYPE_CHAR";
669 return "MONO_TYPE_I1";
671 return "MONO_TYPE_U1";
673 return "MONO_TYPE_I2";
675 return "MONO_TYPE_U2";
677 return "MONO_TYPE_I4";
679 return "MONO_TYPE_U4";
681 return "MONO_TYPE_I8";
683 return "MONO_TYPE_U8";
685 return "MONO_TYPE_R4";
687 return "MONO_TYPE_R8";
688 case MONO_TYPE_STRING:
689 return "MONO_TYPE_STRING";
691 return "MONO_TYPE_PTR";
692 case MONO_TYPE_BYREF:
693 return "MONO_TYPE_BYREF";
694 case MONO_TYPE_VALUETYPE:
695 return "MONO_TYPE_VALUETYPE";
696 case MONO_TYPE_CLASS:
697 return "MONO_TYPE_CLASS";
699 return "MONO_TYPE_VAR";
700 case MONO_TYPE_ARRAY:
701 return "MONO_TYPE_ARRAY";
702 case MONO_TYPE_GENERICINST:
703 return "MONO_TYPE_GENERICINST";
704 case MONO_TYPE_TYPEDBYREF:
705 return "MONO_TYPE_TYPEDBYREF";
707 return "MONO_TYPE_I";
709 return "MONO_TYPE_U";
710 case MONO_TYPE_FNPTR:
711 return "MONO_TYPE_FNPTR";
712 case MONO_TYPE_OBJECT:
713 return "MONO_TYPE_OBJECT";
714 case MONO_TYPE_SZARRAY:
715 return "MONO_TYPE_SZARRAY";
717 return "MONO_TYPE_MVAR";
718 case MONO_TYPE_CMOD_REQD:
719 return "MONO_TYPE_CMOD_REQD";
720 case MONO_TYPE_CMOD_OPT:
721 return "MONO_TYPE_CMOD_OPT";
722 case MONO_TYPE_INTERNAL:
723 return "MONO_TYPE_INTERNAL";
724 case MONO_TYPE_MODIFIER:
725 return "MONO_TYPE_MODIFIER";
726 case MONO_TYPE_SENTINEL:
727 return "MONO_TYPE_SENTINEL";
728 case MONO_TYPE_PINNED:
729 return "MONO_TYPE_PINNED";
736 /*========================= End of Function ========================*/
738 /*------------------------------------------------------------------*/
740 /* Name - decodeParm */
742 /* Function - Decode a parameter for the trace. */
744 /*------------------------------------------------------------------*/
747 decodeParm(MonoType *type, void *curParm, int size)
752 printf("[BYREF:%p], ", *((char **) curParm));
754 simpleType = mono_type_get_underlying_type(type)->type;
756 switch (simpleType) {
758 printf ("[INTPTR:%p], ", *((int **) curParm));
761 printf ("[UINTPTR:%p], ", *((int **) curParm));
763 case MONO_TYPE_BOOLEAN :
764 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
766 case MONO_TYPE_CHAR :
767 printf ("[CHAR:%c], ", *((int *) curParm));
770 printf ("[INT1:%ld], ", *((gint64 *) curParm));
773 printf ("[INT2:%ld], ", *((gint64 *) curParm));
776 printf ("[INT4:%ld], ", *((gint64 *) curParm));
779 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
782 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
785 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
788 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
790 case MONO_TYPE_STRING : {
791 MonoString *s = *((MonoString **) curParm);
793 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
794 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
796 printf("[STRING:null], ");
800 case MONO_TYPE_CLASS :
801 case MONO_TYPE_OBJECT : {
802 MonoObject *obj = *((MonoObject **) curParm);
804 if ((obj) && (obj->vtable)) {
805 printf("[CLASS/OBJ:");
806 class = obj->vtable->klass;
807 printf("%p [%p] ",obj,curParm);
808 if (class == mono_defaults.string_class) {
809 printf("[STRING:%p:%s]",
810 obj, mono_string_to_utf8 ((MonoString *) obj));
811 } else if (class == mono_defaults.int32_class) {
812 printf("[INT32:%p:%d]",
813 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
816 class->name_space, class->name, obj);
819 printf("[OBJECT:null], ");
824 printf("[PTR:%p], ", *((gpointer **) (curParm)));
826 case MONO_TYPE_FNPTR :
827 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
829 case MONO_TYPE_ARRAY :
830 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
832 case MONO_TYPE_SZARRAY :
833 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
836 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
839 printf("[FLOAT4:%g], ", *((float *) (curParm)));
842 printf("[FLOAT8:%g], ", *((double *) (curParm)));
844 case MONO_TYPE_VALUETYPE : {
846 MonoMarshalType *info;
848 if (type->data.klass->enumtype) {
849 simpleType = mono_class_enum_basetype (type->data.klass)->type;
850 printf("{VALUETYPE} - ");
854 info = mono_marshal_load_type_info (type->data.klass);
856 if ((info->native_size == sizeof(float)) &&
857 (info->num_fields == 1) &&
858 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
859 printf("[FLOAT4:%f], ", *((float *) (curParm)));
863 if ((info->native_size == sizeof(double)) &&
864 (info->num_fields == 1) &&
865 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
866 printf("[FLOAT8:%g], ", *((double *) (curParm)));
870 printf("[VALUETYPE:");
871 for (i = 0; i < size; i++)
872 printf("%02x,", *((guint8 *)curParm+i));
876 case MONO_TYPE_TYPEDBYREF: {
878 printf("[TYPEDBYREF:");
879 for (i = 0; i < size; i++)
880 printf("%02x,", *((guint8 *)curParm+i));
885 printf("[%s], ",cvtMonoType(simpleType));
890 /*========================= End of Function ========================*/
892 /*------------------------------------------------------------------*/
894 /* Name - enter_method */
896 /* Function - Perform tracing of the entry to the current */
899 /*------------------------------------------------------------------*/
902 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
904 int i, oParm = 0, iParm = 0;
907 MonoMethodSignature *sig;
914 fname = mono_method_full_name (method, TRUE);
916 printf ("ENTER: %s ", fname);
919 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
920 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
925 sig = mono_method_signature (method);
927 cinfo = get_call_info (NULL, NULL, sig);
929 if (cinfo->struct_ret) {
930 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
935 gpointer *this = (gpointer *) rParm->gr[iParm];
936 obj = (MonoObject *) this;
937 switch(method->klass->this_arg.type) {
938 case MONO_TYPE_VALUETYPE:
940 guint64 *value = (guint64 *) ((uintptr_t)this + sizeof(MonoObject));
941 printf("this:[value:%p:%016lx], ", this, *value);
943 printf ("this:[NULL], ");
945 case MONO_TYPE_STRING:
948 class = obj->vtable->klass;
949 if (class == mono_defaults.string_class) {
950 printf ("this:[STRING:%p:%s], ",
951 obj, mono_string_to_utf8 ((MonoString *)obj));
953 printf ("this:%p[%s.%s], ",
954 obj, class->name_space, class->name);
957 printf("vtable:[NULL], ");
959 printf ("this:[NULL], ");
962 printf("this[%s]: %p, ",cvtMonoType(method->klass->this_arg.type),this);
967 for (i = 0; i < sig->param_count; ++i) {
968 ainfo = &cinfo->args[i + oParm];
969 switch (ainfo->regtype) {
970 case RegTypeGeneral :
971 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
974 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
977 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
979 case RegTypeStructByVal :
980 if (ainfo->reg != STK_BASE) {
981 int offset = sizeof(glong) - ainfo->size;
982 curParm = &(rParm->gr[ainfo->reg-2])+offset;
985 curParm = sp+ainfo->offset;
987 if (retFitsInReg (ainfo->vtsize))
988 decodeParm(sig->params[i],
992 decodeParm(sig->params[i],
993 *((char **) curParm),
996 case RegTypeStructByAddr :
997 if (ainfo->reg != STK_BASE)
998 curParm = &(rParm->gr[ainfo->reg-2]);
1000 curParm = sp+ainfo->offset;
1002 decodeParm(sig->params[i],
1003 *((char **) curParm),
1015 /*========================= End of Function ========================*/
1017 /*------------------------------------------------------------------*/
1019 /* Name - leave_method */
1023 /*------------------------------------------------------------------*/
1026 leave_method (MonoMethod *method, ...)
1033 va_start(ap, method);
1035 fname = mono_method_full_name (method, TRUE);
1037 printf ("LEAVE: %s", fname);
1040 type = mono_method_signature (method)->ret;
1043 switch (type->type) {
1044 case MONO_TYPE_VOID:
1046 case MONO_TYPE_BOOLEAN: {
1047 int val = va_arg (ap, int);
1049 printf ("[TRUE:%d]", val);
1055 case MONO_TYPE_CHAR: {
1056 int val = va_arg (ap, int);
1057 printf ("[CHAR:%d]", val);
1060 case MONO_TYPE_I1: {
1061 int val = va_arg (ap, int);
1062 printf ("[INT1:%d]", val);
1065 case MONO_TYPE_U1: {
1066 int val = va_arg (ap, int);
1067 printf ("[UINT1:%d]", val);
1070 case MONO_TYPE_I2: {
1071 int val = va_arg (ap, int);
1072 printf ("[INT2:%d]", val);
1075 case MONO_TYPE_U2: {
1076 int val = va_arg (ap, int);
1077 printf ("[UINT2:%d]", val);
1080 case MONO_TYPE_I4: {
1081 int val = va_arg (ap, int);
1082 printf ("[INT4:%d]", val);
1085 case MONO_TYPE_U4: {
1086 int val = va_arg (ap, int);
1087 printf ("[UINT4:%d]", val);
1091 gint64 val = va_arg (ap, gint64);
1092 printf ("[INT:%ld]", val);
1097 gint64 val = va_arg (ap, gint64);
1098 printf ("[UINT:%lu]", val);
1102 case MONO_TYPE_STRING: {
1103 MonoString *s = va_arg (ap, MonoString *);
1106 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
1107 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
1109 printf ("[STRING:null], ");
1112 case MONO_TYPE_CLASS:
1113 case MONO_TYPE_OBJECT: {
1114 MonoObject *o = va_arg (ap, MonoObject *);
1116 if ((o) && (o->vtable)) {
1117 if (o->vtable->klass == mono_defaults.boolean_class) {
1118 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
1119 } else if (o->vtable->klass == mono_defaults.int32_class) {
1120 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
1121 } else if (o->vtable->klass == mono_defaults.int64_class) {
1122 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
1124 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
1126 printf ("[OBJECT:%p]", o);
1131 case MONO_TYPE_FNPTR:
1132 case MONO_TYPE_ARRAY:
1133 case MONO_TYPE_SZARRAY: {
1134 gpointer p = va_arg (ap, gpointer);
1135 printf ("[result=%p]", p);
1138 case MONO_TYPE_I8: {
1139 gint64 l = va_arg (ap, gint64);
1140 printf ("[LONG:%ld]", l);
1143 case MONO_TYPE_U8: {
1144 guint64 l = va_arg (ap, guint64);
1145 printf ("[ULONG:%lu]", l);
1148 case MONO_TYPE_R4: {
1149 double f = va_arg (ap, double);
1150 printf ("[FLOAT4:%g]\n", f);
1153 case MONO_TYPE_R8: {
1154 double f = va_arg (ap, double);
1155 printf ("[FLOAT8:%g]\n", f);
1158 case MONO_TYPE_VALUETYPE: {
1159 MonoMarshalType *info;
1160 if (type->data.klass->enumtype) {
1161 type = mono_class_enum_basetype (type->data.klass);
1166 info = mono_marshal_load_type_info (type->data.klass);
1168 if ((info->native_size == sizeof(float)) &&
1169 (info->num_fields == 1) &&
1170 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1171 double f = va_arg (ap, double);
1172 printf("[FLOAT4:%g]\n", (double) f);
1176 if ((info->native_size == sizeof(double)) &&
1177 (info->num_fields == 1) &&
1178 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1179 double f = va_arg (ap, double);
1180 printf("[FLOAT8:%g]\n", f);
1184 size = mono_type_size (type, &align);
1187 guint32 p = va_arg (ap, guint32);
1188 printf ("[%02x]\n",p);
1192 guint32 p = va_arg (ap, guint32);
1193 printf ("[%04x]\n",p);
1197 guint32 p = va_arg (ap, guint32);
1198 printf ("[%08x]\n",p);
1202 guint64 p = va_arg (ap, guint64);
1203 printf ("[%016lx]\n",p);
1207 gpointer p = va_arg (ap, gpointer);
1208 printf ("[VALUETYPE] %p\n",p);
1214 case MONO_TYPE_TYPEDBYREF: {
1215 guint8 *p = va_arg (ap, gpointer);
1217 size = mono_type_size (type, &align);
1224 for (j = 0; p && j < size; j++)
1225 printf ("%02x,", p [j]);
1229 printf ("[TYPEDBYREF]\n");
1234 printf ("(unknown return type %x)",
1235 mono_method_signature (method)->ret->type);
1238 ip = ((gint64) __builtin_return_address (0));
1239 printf (" ip: %p\n", (gpointer) ip);
1242 /*========================= End of Function ========================*/
1244 /*------------------------------------------------------------------*/
1246 /* Name - catch_SIGILL */
1248 /* Function - Catch SIGILL as a result of testing for long */
1249 /* displacement facility. */
1251 /*------------------------------------------------------------------*/
1254 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1260 /*========================= End of Function ========================*/
1262 /*------------------------------------------------------------------*/
1264 /* Name - mono_arch_cpu_init */
1266 /* Function - Perform CPU specific initialization to execute */
1269 /*------------------------------------------------------------------*/
1272 mono_arch_cpu_init (void)
1274 struct sigaction sa,
1278 /*--------------------------------------*/
1279 /* Set default rounding mode for FP */
1280 /*--------------------------------------*/
1281 __asm__ ("SRNM\t%0\n\t"
1284 /*--------------------------------------*/
1285 /* Determine if we have long displace- */
1286 /* ment facility on this processor */
1287 /*--------------------------------------*/
1288 sa.sa_sigaction = catch_SIGILL;
1289 sigemptyset (&sa.sa_mask);
1290 sa.sa_flags = SA_SIGINFO;
1292 sigaction (SIGILL, &sa, oldSa);
1294 /*--------------------------------------*/
1295 /* We test by executing the STY inst */
1296 /*--------------------------------------*/
1297 __asm__ ("LGHI\t0,1\n\t"
1299 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1300 : "=m" (has_ld) : : "0", "1");
1302 sigaction (SIGILL, oldSa, NULL);
1305 /*========================= End of Function ========================*/
1307 /*------------------------------------------------------------------*/
1309 /* Name - mono_arch_init. */
1311 /* Function - Initialize architecture specific code. */
1313 /*------------------------------------------------------------------*/
1316 mono_arch_init (void)
1322 * When we do an architectural level set at z9 or better
1323 * we can use the STFLE instruction to show us
1324 * what hardware facilities are available
1326 int lFacility = sizeof(facs) % 8;
1328 memset((char *) &facs, 0, sizeof(facs));
1330 __asm__ (" lgfr 0,%1\n"
1332 : "=m" (facs) : "r" (lFacility) : "0", "cc");
1335 ss_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1336 bp_trigger_page = mono_valloc (NULL, mono_pagesize (), MONO_MMAP_READ);
1337 mono_mprotect (bp_trigger_page, mono_pagesize (), 0);
1339 code = (guint8 *) &breakpointCode;
1340 s390_basr(code, s390_r13, 0);
1342 s390_llong(code, 0);
1343 s390_lg(code, s390_r13, 0, s390_r13, 4);
1344 s390_lg(code, s390_r0, 0, s390_r13, 0);
1347 /*========================= End of Function ========================*/
1349 /*------------------------------------------------------------------*/
1351 /* Name - mono_arch_cleanup. */
1353 /* Function - Cleanup architecture specific code . */
1355 /*------------------------------------------------------------------*/
1358 mono_arch_cleanup (void)
1362 /*========================= End of Function ========================*/
1364 /*------------------------------------------------------------------*/
1366 /* Name - mono_arch_cpu_optimizations */
1368 /* Function - Returns the optimizations supported on this CPU */
1370 /*------------------------------------------------------------------*/
1373 mono_arch_cpu_optimizations (guint32 *exclude_mask)
1377 /*----------------------------------------------------------*/
1378 /* No s390-specific optimizations yet */
1379 /*----------------------------------------------------------*/
1380 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1381 // *exclude_mask = MONO_OPT_INLINE;
1385 /*========================= End of Function ========================*/
1387 /*------------------------------------------------------------------*/
1389 /* Name - mono_arch_cpu_enumerate_simd_versions */
1391 /* Function - Returns the SIMD instruction sets on this CPU */
1393 /*------------------------------------------------------------------*/
1395 mono_arch_cpu_enumerate_simd_versions (void)
1397 /* SIMD is currently unimplemented */
1400 /*========================= End of Function ========================*/
1402 /*------------------------------------------------------------------*/
1408 /*------------------------------------------------------------------*/
1411 is_regsize_var (MonoType *t) {
1414 switch (mono_type_get_underlying_type (t)->type) {
1422 case MONO_TYPE_FNPTR:
1424 case MONO_TYPE_OBJECT:
1425 case MONO_TYPE_STRING:
1426 case MONO_TYPE_CLASS:
1427 case MONO_TYPE_SZARRAY:
1428 case MONO_TYPE_ARRAY:
1430 case MONO_TYPE_VALUETYPE:
1431 if (t->data.klass->enumtype)
1432 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1438 /*========================= End of Function ========================*/
1440 /*------------------------------------------------------------------*/
1442 /* Name - mono_arch_get_allocatable_int_vars */
1446 /*------------------------------------------------------------------*/
1449 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1454 for (i = 0; i < cfg->num_varinfo; i++) {
1455 MonoInst *ins = cfg->varinfo [i];
1456 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1459 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1462 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1463 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1466 /* we can only allocate 32 bit values */
1467 if (is_regsize_var (ins->inst_vtype)) {
1468 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1469 g_assert (i == vmv->idx);
1470 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1477 /*========================= End of Function ========================*/
1479 /*------------------------------------------------------------------*/
1481 /* Name - mono_arch_global_int_regs */
1483 /* Function - Return a list of usable integer registers. */
1485 /*------------------------------------------------------------------*/
1488 mono_arch_get_global_int_regs (MonoCompile *cfg)
1491 MonoMethodHeader *header;
1494 header = cfg->header;
1495 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1496 cfg->frame_reg = s390_r11;
1499 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1501 for (i = 8; i < top; ++i) {
1502 if (cfg->frame_reg != i)
1503 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1509 /*========================= End of Function ========================*/
1511 /*------------------------------------------------------------------*/
1513 /* Name - mono_arch_flush_icache */
1515 /* Function - Flush the CPU icache. */
1517 /*------------------------------------------------------------------*/
1520 mono_arch_flush_icache (guint8 *code, gint size)
1524 /*========================= End of Function ========================*/
1526 /*------------------------------------------------------------------*/
1528 /* Name - add_general */
1530 /* Function - Determine code and stack size incremements for a */
1533 /*------------------------------------------------------------------*/
1536 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1538 if (*gr > S390_LAST_ARG_REG) {
1539 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1540 ainfo->offset = sz->stack_size;
1541 ainfo->reg = STK_BASE;
1542 ainfo->regtype = RegTypeBase;
1543 sz->stack_size += sizeof(long);
1544 sz->local_size += sizeof(long);
1545 sz->offStruct += sizeof(long);
1546 sz->code_size += 12;
1554 /*========================= End of Function ========================*/
1556 /*------------------------------------------------------------------*/
1558 /* Name - add_stackParm */
1560 /* Function - Determine code and stack size incremements for a */
1563 /*------------------------------------------------------------------*/
1566 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1568 if (*gr > S390_LAST_ARG_REG) {
1569 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1570 ainfo->reg = STK_BASE;
1571 ainfo->offset = sz->stack_size;
1572 ainfo->regtype = RegTypeStructByAddrOnStack;
1573 sz->stack_size += sizeof (gpointer);
1574 sz->parm_size += sizeof(gpointer);
1575 sz->offStruct += sizeof(gpointer);
1578 ainfo->offset = sz->stack_size;
1579 ainfo->regtype = RegTypeStructByAddr;
1582 ainfo->offparm = sz->offset;
1583 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1585 ainfo->vtsize = size;
1586 sz->parm_size += size;
1589 /*========================= End of Function ========================*/
1591 /*------------------------------------------------------------------*/
1593 /* Name - add_float */
1595 /* Function - Determine code and stack size incremements for a */
1596 /* float parameter. */
1598 /*------------------------------------------------------------------*/
1601 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1603 if ((*fr) <= S390_LAST_FPARG_REG) {
1604 ainfo->regtype = RegTypeFP;
1610 ainfo->offset = sz->stack_size;
1611 ainfo->reg = STK_BASE;
1612 ainfo->regtype = RegTypeBase;
1614 sz->stack_size += sizeof(double);
1615 sz->local_size += sizeof(double);
1616 sz->offStruct += sizeof(double);
1620 /*========================= End of Function ========================*/
1622 /*------------------------------------------------------------------*/
1624 /* Name - get_call_info */
1626 /* Function - Determine the amount of space required for code */
1627 /* and stack. In addition determine starting points */
1628 /* for stack-based parameters, and area for struct- */
1629 /* ures being returned on the stack. */
1631 /*------------------------------------------------------------------*/
1634 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
1636 guint i, fr, gr, size, pstart;
1637 int nParm = sig->hasthis + sig->param_count;
1639 guint32 simpleType, align;
1640 gboolean is_pinvoke = sig->pinvoke;
1643 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1646 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1648 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1653 cinfo->struct_ret = 0;
1657 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1658 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1665 /*----------------------------------------------------------*/
1666 /* We determine the size of the return code/stack in case we*/
1667 /* need to reserve a register to be used to address a stack */
1668 /* area that the callee will use. */
1669 /*----------------------------------------------------------*/
1671 ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
1672 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1673 simpleType = ret_type->type;
1675 switch (simpleType) {
1676 case MONO_TYPE_BOOLEAN:
1681 case MONO_TYPE_CHAR:
1686 case MONO_TYPE_CLASS:
1687 case MONO_TYPE_OBJECT:
1688 case MONO_TYPE_SZARRAY:
1689 case MONO_TYPE_ARRAY:
1691 case MONO_TYPE_FNPTR:
1692 case MONO_TYPE_STRING:
1693 cinfo->ret.reg = s390_r2;
1698 cinfo->ret.reg = s390_f0;
1703 cinfo->ret.reg = s390_r2;
1706 case MONO_TYPE_GENERICINST:
1707 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1708 cinfo->ret.reg = s390_r2;
1713 case MONO_TYPE_VALUETYPE: {
1714 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1715 if (klass->enumtype) {
1716 simpleType = mono_class_enum_basetype (klass)->type;
1719 size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1721 cinfo->struct_ret = 1;
1722 cinfo->ret.size = size;
1723 cinfo->ret.vtsize = size;
1726 case MONO_TYPE_TYPEDBYREF:
1727 size = sizeof (MonoTypedRef);
1728 cinfo->struct_ret = 1;
1729 cinfo->ret.size = size;
1730 cinfo->ret.vtsize = size;
1732 case MONO_TYPE_VOID:
1735 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1741 * To simplify get_this_arg_reg () and LLVM integration, emit the vret arg after
1742 * the first argument, allowing 'this' to be always passed in the first arg reg.
1743 * Also do this if the first argument is a reference type, since virtual calls
1744 * are sometimes made using calli without sig->hasthis set, like in the delegate
1747 if (cinfo->struct_ret && !is_pinvoke &&
1749 (sig->param_count > 0 &&
1750 MONO_TYPE_IS_REFERENCE (mini_type_get_underlying_type (gsctx, sig->params [0]))))) {
1752 cinfo->args[nParm].size = sizeof (gpointer);
1753 add_general (&gr, sz, cinfo->args + nParm);
1755 cinfo->args[nParm].size = sizeof (gpointer);
1756 add_general (&gr, sz, &cinfo->args [sig->hasthis + nParm]);
1760 cinfo->vret_arg_index = 1;
1761 cinfo->ret.reg = gr;
1766 cinfo->args[nParm].size = sizeof (gpointer);
1767 add_general (&gr, sz, cinfo->args + nParm);
1771 if (cinfo->struct_ret) {
1772 cinfo->ret.reg = gr;
1777 if ((sig->call_convention == MONO_CALL_VARARG) && (sig->param_count == 0)) {
1778 gr = S390_LAST_ARG_REG + 1;
1779 fr = S390_LAST_FPARG_REG + 1;
1781 /* Emit the signature cookie just before the implicit arguments */
1782 add_general (&gr, sz, &cinfo->sigCookie);
1785 /*----------------------------------------------------------*/
1786 /* We determine the size of the parameter code and stack */
1787 /* requirements by checking the types and sizes of the */
1789 /*----------------------------------------------------------*/
1791 for (i = pstart; i < sig->param_count; ++i) {
1794 /*--------------------------------------------------*/
1795 /* Handle vararg type calls. All args are put on */
1797 /*--------------------------------------------------*/
1798 if ((sig->call_convention == MONO_CALL_VARARG) &&
1799 (i == sig->sentinelpos)) {
1800 gr = S390_LAST_ARG_REG + 1;
1801 fr = S390_LAST_FPARG_REG + 1;
1802 add_general (&gr, sz, &cinfo->sigCookie);
1805 if (sig->params [i]->byref) {
1806 add_general (&gr, sz, cinfo->args+nParm);
1807 cinfo->args[nParm].size = sizeof(gpointer);
1812 ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
1813 simpleType = ptype->type;
1814 cinfo->args[nParm].type = simpleType;
1815 switch (simpleType) {
1816 case MONO_TYPE_BOOLEAN:
1819 cinfo->args[nParm].size = sizeof(char);
1820 add_general (&gr, sz, cinfo->args+nParm);
1825 case MONO_TYPE_CHAR:
1826 cinfo->args[nParm].size = sizeof(short);
1827 add_general (&gr, sz, cinfo->args+nParm);
1832 cinfo->args[nParm].size = sizeof(int);
1833 add_general (&gr, sz, cinfo->args+nParm);
1839 case MONO_TYPE_FNPTR:
1840 case MONO_TYPE_CLASS:
1841 case MONO_TYPE_OBJECT:
1842 case MONO_TYPE_STRING:
1843 case MONO_TYPE_SZARRAY:
1844 case MONO_TYPE_ARRAY:
1845 cinfo->args[nParm].size = sizeof(gpointer);
1846 add_general (&gr, sz, cinfo->args+nParm);
1851 cinfo->args[nParm].size = sizeof(long long);
1852 add_general (&gr, sz, cinfo->args+nParm);
1856 cinfo->args[nParm].size = sizeof(float);
1857 add_float (&fr, sz, cinfo->args+nParm);
1861 cinfo->args[nParm].size = sizeof(double);
1862 add_float (&fr, sz, cinfo->args+nParm);
1865 case MONO_TYPE_GENERICINST:
1866 if (!mono_type_generic_inst_is_valuetype (ptype)) {
1867 cinfo->args[nParm].size = sizeof(gpointer);
1868 add_general (&gr, sz, cinfo->args+nParm);
1873 case MONO_TYPE_VALUETYPE: {
1874 MonoMarshalType *info;
1875 MonoClass *klass = mono_class_from_mono_type (ptype);
1877 size = mini_type_stack_size_full(gsctx, &klass->byval_arg, NULL, sig->pinvoke);
1878 if (simpleType != MONO_TYPE_GENERICINST) {
1879 info = mono_marshal_load_type_info(klass);
1881 if ((info->native_size == sizeof(float)) &&
1882 (info->num_fields == 1) &&
1883 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1884 cinfo->args[nParm].size = sizeof(float);
1885 add_float(&fr, sz, cinfo->args+nParm);
1890 if ((info->native_size == sizeof(double)) &&
1891 (info->num_fields == 1) &&
1892 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1893 cinfo->args[nParm].size = sizeof(double);
1894 add_float(&fr, sz, cinfo->args+nParm);
1900 cinfo->args[nParm].vtsize = 0;
1901 cinfo->args[nParm].size = 0;
1904 /*----------------------------------*/
1905 /* On S/390, structures of size 1, */
1906 /* 2, 4, and 8 bytes are passed in */
1907 /* (a) register(s). */
1908 /*----------------------------------*/
1914 add_general(&gr, sz, cinfo->args+nParm);
1915 cinfo->args[nParm].size = size;
1916 cinfo->args[nParm].regtype = RegTypeStructByVal;
1918 sz->local_size += sizeof(long);
1921 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1926 case MONO_TYPE_TYPEDBYREF: {
1927 int size = sizeof (MonoTypedRef);
1929 cinfo->args[nParm].vtsize = 0;
1930 cinfo->args[nParm].size = 0;
1933 /*----------------------------------*/
1934 /* On S/390, structures of size 1, */
1935 /* 2, 4, and 8 bytes are passed in */
1936 /* (a) register(s). */
1937 /*----------------------------------*/
1943 add_general(&gr, sz, cinfo->args+nParm);
1944 cinfo->args[nParm].size = size;
1945 cinfo->args[nParm].regtype = RegTypeStructByVal;
1947 sz->local_size += sizeof(long);
1950 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1956 g_error ("Can't trampoline 0x%x", ptype);
1960 /*----------------------------------------------------------*/
1961 /* Handle the case where there are no implicit arguments */
1962 /*----------------------------------------------------------*/
1963 if ((sig->call_convention == MONO_CALL_VARARG) &&
1966 (sig->param_count == sig->sentinelpos)) {
1967 gr = S390_LAST_ARG_REG + 1;
1968 fr = S390_LAST_FPARG_REG + 1;
1969 add_general (&gr, sz, &cinfo->sigCookie);
1972 /*----------------------------------------------------------*/
1973 /* If we are passing a structure back then if it won't be */
1974 /* in a register(s) then we make room at the end of the */
1975 /* parameters that may have been placed on the stack */
1976 /*----------------------------------------------------------*/
1977 if (cinfo->struct_ret) {
1978 cinfo->ret.offset = sz->stack_size;
1979 switch (cinfo->ret.size) {
1987 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1992 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1994 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1999 /*========================= End of Function ========================*/
2001 /*------------------------------------------------------------------*/
2003 /* Name - mono_arch_allocate_vars */
2005 /* Function - Set var information according to the calling */
2006 /* convention for S/390. The local var stuff should */
2007 /* most likely be split in another method. */
2009 /* Parameter - @m - Compile unit. */
2011 /*------------------------------------------------------------------*/
2014 mono_arch_allocate_vars (MonoCompile *cfg)
2016 MonoMethodSignature *sig;
2017 MonoMethodHeader *header;
2020 int iParm, iVar, offset, align, size, curinst;
2021 int frame_reg = STK_BASE;
2024 header = cfg->header;
2026 cfg->flags |= MONO_CFG_HAS_SPILLUP;
2028 /*---------------------------------------------------------*/
2029 /* We use the frame register also for any method that has */
2030 /* filter clauses. This way, when the handlers are called, */
2031 /* the code will reference local variables using the frame */
2032 /* reg instead of the stack pointer: if we had to restore */
2033 /* the stack pointer, we'd corrupt the method frames that */
2034 /* are already on the stack (since filters get called */
2035 /* before stack unwinding happens) when the filter code */
2036 /* would call any method. */
2037 /*---------------------------------------------------------*/
2038 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2039 frame_reg = s390_r11;
2041 cfg->frame_reg = frame_reg;
2043 cfg->arch.bkchain_reg = -1;
2045 if (frame_reg != STK_BASE)
2046 cfg->used_int_regs |= 1 << frame_reg;
2048 sig = mono_method_signature (cfg->method);
2050 cinfo = get_call_info (cfg, cfg->mempool, sig);
2052 if (!cinfo->struct_ret) {
2053 switch (mono_type_get_underlying_type (sig->ret)->type) {
2054 case MONO_TYPE_VOID:
2057 cfg->ret->opcode = OP_REGVAR;
2058 cfg->ret->dreg = s390_r2;
2063 /*--------------------------------------------------------------*/
2064 /* local vars are at a positive offset from the stack pointer */
2065 /* also note that if the function uses alloca, we use s390_r11 */
2066 /* to point at the local variables. */
2067 /* add parameter area size for called functions */
2068 /*--------------------------------------------------------------*/
2069 if (cfg->param_area == 0)
2070 offset = S390_MINIMAL_STACK_SIZE;
2072 offset = cfg->param_area;
2074 cfg->sig_cookie = 0;
2076 if (cinfo->struct_ret) {
2077 inst = cfg->vret_addr;
2078 offset = S390_ALIGN(offset, sizeof(gpointer));
2079 inst->inst_offset = offset;
2080 inst->opcode = OP_REGOFFSET;
2081 inst->inst_basereg = frame_reg;
2082 offset += sizeof(gpointer);
2083 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2084 printf ("vret_addr =");
2085 mono_print_ins (cfg->vret_addr);
2090 inst = cfg->args [0];
2091 if (inst->opcode != OP_REGVAR) {
2092 inst->opcode = OP_REGOFFSET;
2093 inst->inst_basereg = frame_reg;
2094 offset = S390_ALIGN(offset, sizeof(gpointer));
2095 inst->inst_offset = offset;
2096 offset += sizeof (gpointer);
2103 eArg = sig->param_count + sArg;
2105 if (sig->call_convention == MONO_CALL_VARARG)
2106 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
2108 for (iParm = sArg; iParm < eArg; ++iParm) {
2109 inst = cfg->args [curinst];
2110 if (inst->opcode != OP_REGVAR) {
2111 switch (cinfo->args[iParm].regtype) {
2112 case RegTypeStructByAddr : {
2115 size = sizeof (gpointer);
2117 inst->opcode = OP_REGOFFSET;
2118 inst->inst_basereg = frame_reg;
2119 offset = S390_ALIGN (offset, sizeof (gpointer));
2120 inst->inst_offset = offset;
2122 /* Add a level of indirection */
2123 MONO_INST_NEW (cfg, indir, 0);
2125 inst->opcode = OP_VTARG_ADDR;
2126 inst->inst_left = indir;
2129 case RegTypeStructByAddrOnStack : {
2132 size = sizeof (gpointer);
2134 /* Similar to the == STK_BASE case below */
2135 cfg->arch.bkchain_reg = s390_r12;
2136 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2138 inst->opcode = OP_REGOFFSET;
2139 inst->dreg = mono_alloc_preg (cfg);
2140 inst->inst_basereg = cfg->arch.bkchain_reg;
2141 inst->inst_offset = cinfo->args [iParm].offset;
2143 /* Add a level of indirection */
2144 MONO_INST_NEW (cfg, indir, 0);
2146 inst->opcode = OP_VTARG_ADDR;
2147 inst->inst_left = indir;
2150 case RegTypeStructByVal :
2151 size = cinfo->args[iParm].size;
2152 offset = S390_ALIGN(offset, size);
2153 inst->opcode = OP_REGOFFSET;
2154 inst->inst_basereg = frame_reg;
2155 inst->inst_offset = offset;
2158 if (cinfo->args [iParm].reg == STK_BASE) {
2160 * These arguments are in the previous frame, so we can't
2161 * compute their offset from the current frame pointer right
2162 * now, since cfg->stack_offset is not yet known, so dedicate a
2163 * register holding the previous frame pointer.
2165 cfg->arch.bkchain_reg = s390_r12;
2166 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
2168 inst->opcode = OP_REGOFFSET;
2169 inst->inst_basereg = cfg->arch.bkchain_reg;
2170 size = (cinfo->args[iParm].size < 8
2171 ? 8 - cinfo->args[iParm].size
2173 inst->inst_offset = cinfo->args [iParm].offset + size;
2174 size = sizeof (long);
2176 inst->opcode = OP_REGOFFSET;
2177 inst->inst_basereg = frame_reg;
2178 size = (cinfo->args[iParm].size < 8
2181 offset = S390_ALIGN(offset, size);
2182 if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE)
2183 inst->inst_offset = offset;
2185 inst->inst_offset = offset + (8 - size);
2190 if ((sig->call_convention == MONO_CALL_VARARG) &&
2191 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
2192 (iParm < sig->sentinelpos))
2193 cfg->sig_cookie += size;
2194 printf("%s %4d cookine %x\n",__FUNCTION__,__LINE__,cfg->sig_cookie);
2197 offset += MAX(size, 8);
2202 cfg->locals_min_stack_offset = offset;
2204 curinst = cfg->locals_start;
2205 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
2206 inst = cfg->varinfo [iVar];
2207 if ((inst->flags & MONO_INST_IS_DEAD) ||
2208 (inst->opcode == OP_REGVAR))
2211 /*--------------------------------------------------*/
2212 /* inst->backend.is_pinvoke indicates native sized */
2213 /* value typs this is used by the pinvoke wrappers */
2214 /* when they call functions returning structure */
2215 /*--------------------------------------------------*/
2216 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
2217 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
2218 (guint32 *) &align);
2220 size = mono_type_size (inst->inst_vtype, &align);
2222 offset = S390_ALIGN(offset, align);
2223 inst->inst_offset = offset;
2224 inst->opcode = OP_REGOFFSET;
2225 inst->inst_basereg = frame_reg;
2227 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
2228 iVar, inst->inst_offset, size));
2231 cfg->locals_max_stack_offset = offset;
2233 /*------------------------------------------------------*/
2234 /* Allow space for the trace method stack area if needed*/
2235 /*------------------------------------------------------*/
2236 if ((mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
2237 || (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE))
2238 offset += S390_TRACE_STACK_SIZE;
2240 /*------------------------------------------------------*/
2241 /* Reserve space to save LMF and caller saved registers */
2242 /*------------------------------------------------------*/
2243 if (cfg->method->save_lmf)
2244 offset += sizeof (MonoLMF);
2246 /*------------------------------------------------------*/
2247 /* align the offset */
2248 /*------------------------------------------------------*/
2249 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
2251 /*------------------------------------------------------*/
2252 /* Fix offsets for args whose value is in parent frame */
2253 /*------------------------------------------------------*/
2254 for (iParm = sArg; iParm < eArg; ++iParm) {
2255 inst = cfg->args [iParm];
2257 if (inst->opcode == OP_S390_STKARG) {
2258 inst->opcode = OP_REGOFFSET;
2259 inst->inst_offset += cfg->stack_offset;
2264 /*========================= End of Function ========================*/
2266 /*------------------------------------------------------------------*/
2268 /* Name - mono_arch_create_vars */
2270 /*------------------------------------------------------------------*/
2273 mono_arch_create_vars (MonoCompile *cfg)
2275 MonoMethodSignature *sig;
2278 sig = mono_method_signature (cfg->method);
2280 cinfo = get_call_info (cfg, cfg->mempool, sig);
2282 if (cinfo->struct_ret) {
2283 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2284 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2285 printf ("vret_addr = ");
2286 mono_print_ins (cfg->vret_addr);
2291 /*========================= End of Function ========================*/
2293 /*------------------------------------------------------------------*/
2295 /* Name - add_outarg_reg2. */
2297 /*------------------------------------------------------------------*/
2300 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2305 case RegTypeGeneral:
2306 MONO_INST_NEW (cfg, ins, OP_MOVE);
2307 ins->dreg = mono_alloc_ireg (cfg);
2308 ins->sreg1 = tree->dreg;
2309 MONO_ADD_INS (cfg->cbb, ins);
2310 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2313 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2314 ins->dreg = mono_alloc_freg (cfg);
2315 ins->sreg1 = tree->dreg;
2316 MONO_ADD_INS (cfg->cbb, ins);
2317 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2320 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2321 ins->dreg = mono_alloc_freg (cfg);
2322 ins->sreg1 = tree->dreg;
2323 MONO_ADD_INS (cfg->cbb, ins);
2324 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2327 g_assert_not_reached ();
2331 /*========================= End of Function ========================*/
2333 /*------------------------------------------------------------------*/
2335 /* Name - emit_sig_cookie. */
2337 /*------------------------------------------------------------------*/
2340 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2342 MonoMethodSignature *tmpSig;
2345 cfg->disable_aot = TRUE;
2347 /*----------------------------------------------------------*/
2348 /* mono_ArgIterator_Setup assumes the signature cookie is */
2349 /* passed first and all the arguments which were before it */
2350 /* passed on the stack after the signature. So compensate */
2351 /* by passing a different signature. */
2352 /*----------------------------------------------------------*/
2353 tmpSig = mono_metadata_signature_dup (call->signature);
2354 tmpSig->param_count -= call->signature->sentinelpos;
2355 tmpSig->sentinelpos = 0;
2356 if (tmpSig->param_count > 0)
2357 memcpy (tmpSig->params,
2358 call->signature->params + call->signature->sentinelpos,
2359 tmpSig->param_count * sizeof(MonoType *));
2361 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2362 sig_arg->dreg = mono_alloc_ireg (cfg);
2363 sig_arg->inst_p0 = tmpSig;
2364 MONO_ADD_INS (cfg->cbb, sig_arg);
2366 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2367 cinfo->sigCookie.offset, sig_arg->dreg);
2370 /*========================= End of Function ========================*/
2372 /*------------------------------------------------------------------*/
2374 /* Name - mono_arch_emit_call */
2376 /*------------------------------------------------------------------*/
2379 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2382 MonoMethodSignature *sig;
2384 int i, n, lParamArea;
2386 ArgInfo *ainfo = NULL;
2388 MonoMethodHeader *header;
2391 sig = call->signature;
2392 n = sig->param_count + sig->hasthis;
2393 DEBUG (g_print ("Call requires: %d parameters\n",n));
2395 cinfo = get_call_info (cfg, cfg->mempool, sig);
2397 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size +
2398 cinfo->sz.parm_size + cinfo->sz.offset;
2399 call->stack_usage = MAX(stackSize, call->stack_usage);
2400 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2401 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2402 cfg->flags |= MONO_CFG_HAS_CALLS;
2404 if (cinfo->struct_ret) {
2405 MONO_INST_NEW (cfg, ins, OP_MOVE);
2406 ins->sreg1 = call->vret_var->dreg;
2407 ins->dreg = mono_alloc_preg (cfg);
2408 MONO_ADD_INS (cfg->cbb, ins);
2409 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2412 header = cfg->header;
2413 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2418 for (i = 0; i < n; ++i) {
2421 ainfo = cinfo->args + i;
2422 if (i >= sig->hasthis)
2423 t = sig->params [i - sig->hasthis];
2425 t = &mono_defaults.int_class->byval_arg;
2426 t = mono_type_get_underlying_type (t);
2428 in = call->args [i];
2430 if ((sig->call_convention == MONO_CALL_VARARG) &&
2432 (i == sig->sentinelpos)) {
2433 emit_sig_cookie (cfg, call, cinfo);
2436 switch (ainfo->regtype) {
2437 case RegTypeGeneral:
2438 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2441 if (MONO_TYPE_ISSTRUCT (t)) {
2442 /* Valuetype passed in one fp register */
2443 ainfo->regtype = RegTypeStructByValInFP;
2446 if (ainfo->size == 4)
2447 ainfo->regtype = RegTypeFPR4;
2448 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2451 case RegTypeStructByVal:
2452 case RegTypeStructByAddr:
2453 case RegTypeStructByAddrOnStack: {
2457 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2458 size = sizeof (MonoTypedRef);
2459 align = sizeof (gpointer);
2463 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2466 * Other backends use mono_type_stack_size (), but that
2467 * aligns the size to 8, which is larger than the size of
2468 * the source, leading to reads of invalid memory if the
2469 * source is at the end of address space.
2471 size = mono_class_value_size (in->klass, &align);
2474 g_assert (in->klass);
2476 ainfo->offparm += cinfo->sz.offStruct;
2478 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2479 ins->sreg1 = in->dreg;
2480 ins->klass = in->klass;
2481 ins->backend.size = ainfo->size;
2482 ins->inst_p0 = call;
2483 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2484 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2486 MONO_ADD_INS (cfg->cbb, ins);
2488 if (ainfo->regtype == RegTypeStructByAddr) {
2490 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2491 * use the normal OUTARG opcodes to pass the address of the location to
2494 int treg = mono_alloc_preg (cfg);
2495 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2496 frmReg, ainfo->offparm);
2497 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2498 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2499 /* The address of the valuetype is passed on the stack */
2500 int treg = mono_alloc_preg (cfg);
2501 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2502 frmReg, ainfo->offparm);
2503 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2504 ainfo->reg, ainfo->offset, treg);
2506 if (cfg->compute_gc_maps) {
2509 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, t);
2515 if (!t->byref && t->type == MONO_TYPE_R4) {
2516 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2517 STK_BASE, ainfo->offset + 4,
2519 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2520 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2521 STK_BASE, ainfo->offset,
2524 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2525 ins->inst_destbasereg = STK_BASE;
2526 ins->inst_offset = ainfo->offset;
2527 ins->sreg1 = in->dreg;
2530 /* This is needed by MonoTypedRef->value to point to the correct data */
2531 if ((sig->call_convention == MONO_CALL_VARARG) &&
2532 (i >= sig->sentinelpos)) {
2533 switch (ainfo->size) {
2535 ins->opcode = OP_STOREI1_MEMBASE_REG;
2538 ins->opcode = OP_STOREI2_MEMBASE_REG;
2541 ins->opcode = OP_STOREI4_MEMBASE_REG;
2549 MONO_ADD_INS (cfg->cbb, ins);
2553 g_assert_not_reached ();
2559 * Handle the case where there are no implicit arguments
2561 if ((sig->call_convention == MONO_CALL_VARARG) &&
2563 (i == sig->sentinelpos)) {
2564 emit_sig_cookie (cfg, call, cinfo);
2568 /*========================= End of Function ========================*/
2570 /*------------------------------------------------------------------*/
2572 /* Name - mono_arch_emit_outarg_vt */
2574 /*------------------------------------------------------------------*/
2577 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2579 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2580 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2581 int size = ins->backend.size;
2583 if (ainfo->regtype == RegTypeStructByVal) {
2585 arg->ins.sreg1 = ainfo->reg;
2586 arg->ins.opcode = OP_OUTARG_VT;
2587 arg->size = ainfo->size;
2588 arg->offset = ainfo->offset;
2589 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2591 if (ainfo->reg != STK_BASE) {
2592 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2594 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2597 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2598 int dreg = mono_alloc_freg (cfg);
2600 if (ainfo->size == 4) {
2601 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2602 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2604 g_assert (ainfo->size == 8);
2606 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2609 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2611 MonoMethodHeader *header;
2614 header = mono_method_get_header (cfg->method);
2615 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
2620 MONO_EMIT_NEW_MOVE (cfg, srcReg, ainfo->offparm,
2621 src->dreg, 0, size);
2623 if (cfg->compute_gc_maps) {
2626 EMIT_NEW_GC_PARAM_SLOT_LIVENESS_DEF (cfg, def, ainfo->offset, &ins->klass->byval_arg);
2631 /*========================= End of Function ========================*/
2633 /*------------------------------------------------------------------*/
2635 /* Name - mono_arch_emit_setret */
2637 /*------------------------------------------------------------------*/
2640 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2642 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2645 if (ret->type == MONO_TYPE_R4) {
2646 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2648 } else if (ret->type == MONO_TYPE_R8) {
2649 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2654 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2657 /*========================= End of Function ========================*/
2659 /*------------------------------------------------------------------*/
2661 /* Name - mono_arch_instrument_mem_needs */
2663 /* Function - Allow tracing to work with this interface (with */
2664 /* an optional argument). */
2666 /*------------------------------------------------------------------*/
2669 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2671 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2673 /* split prolog-epilog requirements? */
2674 *code = 50; /* max bytes needed: check this number */
2677 /*========================= End of Function ========================*/
2679 /*------------------------------------------------------------------*/
2681 /* Name - mono_arch_instrument_prolog */
2683 /* Function - Create an "instrumented" prolog. */
2685 /*------------------------------------------------------------------*/
2688 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2689 gboolean enable_arguments)
2696 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2697 if (cfg->method->save_lmf)
2698 parmOffset -= sizeof(MonoLMF);
2699 fpOffset = parmOffset + (5*sizeof(gpointer));
2700 if ((!has_ld) && (fpOffset > 4096)) {
2701 s390_lgr (code, s390_r12, STK_BASE);
2703 while (fpOffset > 4096) {
2704 s390_aghi (code, baseReg, 4096);
2712 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2714 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2715 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2716 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2717 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2719 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2720 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2721 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2722 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2724 s390_basr (code, s390_r13, 0);
2726 s390_llong(code, cfg->method);
2727 s390_llong(code, func);
2728 s390_lg (code, s390_r2, 0, s390_r13, 4);
2730 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2732 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2733 s390_lgr (code, s390_r4, STK_BASE);
2734 s390_aghi (code, s390_r4, cfg->stack_usage);
2735 s390_lg (code, s390_r1, 0, s390_r13, 12);
2736 s390_basr (code, s390_r14, s390_r1);
2738 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2739 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2740 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2741 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2743 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2744 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2745 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2746 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2748 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2753 /*========================= End of Function ========================*/
2755 /*------------------------------------------------------------------*/
2757 /* Name - mono_arch_instrument_epilog */
2759 /* Function - Create an epilog that will handle the returned */
2760 /* values used in instrumentation. */
2762 /*------------------------------------------------------------------*/
2765 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2768 int save_mode = SAVE_NONE,
2771 MonoMethod *method = cfg->method;
2772 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2774 offset = code - cfg->native_code;
2775 /*-----------------------------------------*/
2776 /* We need about 128 bytes of instructions */
2777 /*-----------------------------------------*/
2778 if (offset > (cfg->code_size - 128)) {
2779 cfg->code_size *= 2;
2780 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2781 code = cfg->native_code + offset;
2784 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2785 if (method->save_lmf)
2786 saveOffset -= sizeof(MonoLMF);
2790 case MONO_TYPE_VOID:
2791 /* special case string .ctor icall */
2792 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2793 save_mode = SAVE_ONE;
2795 save_mode = SAVE_NONE;
2799 save_mode = SAVE_ONE;
2802 save_mode = SAVE_R4;
2805 save_mode = SAVE_R8;
2807 case MONO_TYPE_VALUETYPE:
2808 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2809 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2812 save_mode = SAVE_STRUCT;
2815 save_mode = SAVE_ONE;
2819 switch (save_mode) {
2821 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2822 if (enable_arguments) {
2823 s390_lgr (code, s390_r3, s390_r2);
2827 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2828 if (enable_arguments) {
2829 s390_ldebr (code, s390_f0, s390_f0);
2833 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2836 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2837 if (enable_arguments) {
2838 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2839 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2847 s390_basr (code, s390_r13, 0);
2849 s390_llong(code, cfg->method);
2850 s390_llong(code, func);
2851 s390_lg (code, s390_r2, 0, s390_r13, 4);
2852 s390_lg (code, s390_r1, 0, s390_r13, 12);
2853 s390_basr (code, s390_r14, s390_r1);
2855 switch (save_mode) {
2857 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2861 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2864 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2874 /*========================= End of Function ========================*/
2876 /*------------------------------------------------------------------*/
2878 /* Name - mono_arch_peephole_pass_1 */
2880 /* Function - Form a peephole pass at the code looking for */
2881 /* simple optimizations. */
2883 /*------------------------------------------------------------------*/
2886 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2890 /*========================= End of Function ========================*/
2892 /*------------------------------------------------------------------*/
2894 /* Name - mono_arch_peephole_pass_2 */
2896 /* Function - Form a peephole pass at the code looking for */
2897 /* simple optimizations. */
2899 /*------------------------------------------------------------------*/
2902 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2906 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2907 mono_peephole_ins (bb, ins);
2911 /*========================= End of Function ========================*/
2913 /*------------------------------------------------------------------*/
2915 /* Name - mono_arch_lowering_pass. */
2917 /*------------------------------------------------------------------*/
2920 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2922 MonoInst *ins, *next;
2924 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2925 switch (ins->opcode) {
2930 case OP_IDIV_UN_IMM:
2931 case OP_IREM_UN_IMM:
2935 case OP_LOCALLOC_IMM:
2936 mono_decompose_op_imm (cfg, bb, ins);
2939 if (!s390_is_imm16 (ins->inst_imm))
2940 /* This is created by the memcpy code which ignores is_inst_imm */
2941 mono_decompose_op_imm (cfg, bb, ins);
2948 bb->max_vreg = cfg->next_vreg;
2951 /*========================= End of Function ========================*/
2953 /*------------------------------------------------------------------*/
2955 /* Name - emit_float_to_int */
2957 /* Function - Create instructions which will convert a floating */
2958 /* point value to integer. */
2960 /*------------------------------------------------------------------*/
2963 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2965 /* sreg is a float, dreg is an integer reg. */
2967 s390_cgdbr (code, dreg, 5, sreg);
2970 s390_lghi (code, s390_r0, 0);
2971 s390_lghi (code, s390_r13, 0xff);
2972 s390_ltgr (code, dreg, dreg);
2974 s390_lghi (code, s390_r0, 0x80);
2975 s390_ngr (code, dreg, s390_r13);
2976 s390_ogr (code, dreg, s390_r0);
2981 s390_basr (code, s390_r13, 0);
2983 s390_llong (code, 0x41e0000000000000llu);
2984 s390_llong (code, 0x41f0000000000000llu);
2985 s390_ldr (code, s390_f15, sreg);
2986 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2987 s390_jl (code, 0); CODEPTR (code, o[0]);
2988 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2989 s390_cfdbr (code, dreg, 7, s390_f15);
2991 PTRSLOT (code, o[0]);
2992 s390_cfdbr (code, dreg, 5, sreg);
2995 s390_lghi (code, s390_r0, 0xff);
2996 s390_ngr (code, dreg, s390_r0);
2999 s390_lghi (code, s390_r0, -1);
3000 s390_srlg (code, s390_r0, s390_r0, 0, 16);
3001 s390_ngr (code, dreg, s390_r0);
3008 /*========================= End of Function ========================*/
3010 /*------------------------------------------------------------------*/
3012 /* Name - gboolean_is_unsigned. */
3014 /* Function - Return TRUE if next opcode is checking for un- */
3017 /*------------------------------------------------------------------*/
3020 gboolean is_unsigned (MonoInst *next)
3023 (((next->opcode >= OP_IBNE_UN) &&
3024 (next->opcode <= OP_IBLT_UN)) ||
3025 ((next->opcode >= OP_LBNE_UN) &&
3026 (next->opcode <= OP_LBLT_UN)) ||
3027 ((next->opcode >= OP_COND_EXC_NE_UN) &&
3028 (next->opcode <= OP_COND_EXC_LT_UN)) ||
3029 ((next->opcode >= OP_COND_EXC_INE_UN) &&
3030 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
3031 ((next->opcode == OP_CLT_UN) ||
3032 (next->opcode == OP_CGT_UN)) ||
3033 ((next->opcode == OP_ICLT_UN) ||
3034 (next->opcode == OP_ICGT_UN) ||
3035 (next->opcode == OP_LCLT_UN) ||
3036 (next->opcode == OP_LCGT_UN))))
3042 /*========================= End of Function ========================*/
3044 /*------------------------------------------------------------------*/
3046 /* Name - mono_arch_output_basic_block */
3048 /* Function - Perform the "real" work of emitting instructions */
3049 /* that will do the work of in the basic block. */
3051 /*------------------------------------------------------------------*/
3054 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
3059 guint8 *code = cfg->native_code + cfg->code_len;
3060 guint last_offset = 0;
3061 int max_len, cpos, src2;
3063 /* we don't align basic blocks of loops on s390 */
3065 if (cfg->verbose_level > 2)
3066 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
3068 cpos = bb->max_offset;
3070 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
3071 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
3072 //g_assert (!mono_compile_aot);
3075 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
3076 /* this is not thread save, but good enough */
3077 /* fixme: howto handle overflows? */
3078 //x86_inc_mem (code, &cov->data [bb->dfn].count);
3081 MONO_BB_FOR_EACH_INS (bb, ins) {
3082 offset = code - cfg->native_code;
3084 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
3086 if (offset > (cfg->code_size - max_len - 16)) {
3087 cfg->code_size *= 2;
3088 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
3089 code = cfg->native_code + offset;
3092 mono_debug_record_line_number (cfg, ins, offset);
3094 switch (ins->opcode) {
3095 case OP_STOREI1_MEMBASE_IMM: {
3096 s390_lghi (code, s390_r0, ins->inst_imm);
3097 S390_LONG (code, stcy, stc, s390_r0, 0,
3098 ins->inst_destbasereg, ins->inst_offset);
3101 case OP_STOREI2_MEMBASE_IMM: {
3102 s390_lghi (code, s390_r0, ins->inst_imm);
3103 S390_LONG (code, sthy, sth, s390_r0, 0,
3104 ins->inst_destbasereg, ins->inst_offset);
3107 case OP_STOREI4_MEMBASE_IMM: {
3108 if (s390_is_imm16(ins->inst_imm)) {
3109 s390_lghi (code, s390_r0, ins->inst_imm);
3111 s390_basr (code, s390_r13, 0);
3113 s390_llong(code, ins->inst_imm);
3114 s390_lg (code, s390_r0, 0, s390_r13, 4);
3116 S390_LONG (code, sty, st, s390_r0, 0,
3117 ins->inst_destbasereg, ins->inst_offset);
3120 case OP_STORE_MEMBASE_IMM:
3121 case OP_STOREI8_MEMBASE_IMM: {
3122 if (s390_is_imm16(ins->inst_imm)) {
3123 s390_lghi (code, s390_r0, ins->inst_imm);
3125 s390_basr (code, s390_r13, 0);
3127 s390_llong(code, ins->inst_imm);
3128 s390_lg (code, s390_r0, 0, s390_r13, 4);
3130 S390_LONG (code, stg, stg, s390_r0, 0,
3131 ins->inst_destbasereg, ins->inst_offset);
3134 case OP_STOREI1_MEMBASE_REG: {
3135 S390_LONG (code, stcy, stc, ins->sreg1, 0,
3136 ins->inst_destbasereg, ins->inst_offset);
3139 case OP_STOREI2_MEMBASE_REG: {
3140 S390_LONG (code, sthy, sth, ins->sreg1, 0,
3141 ins->inst_destbasereg, ins->inst_offset);
3144 case OP_STOREI4_MEMBASE_REG: {
3145 S390_LONG (code, sty, st, ins->sreg1, 0,
3146 ins->inst_destbasereg, ins->inst_offset);
3149 case OP_STORE_MEMBASE_REG:
3150 case OP_STOREI8_MEMBASE_REG: {
3151 S390_LONG (code, stg, stg, ins->sreg1, 0,
3152 ins->inst_destbasereg, ins->inst_offset);
3156 g_assert_not_reached ();
3158 case OP_LOAD_MEMBASE:
3159 case OP_LOADI8_MEMBASE: {
3160 S390_LONG (code, lg, lg, ins->dreg, 0,
3161 ins->inst_basereg, ins->inst_offset);
3164 case OP_LOADI4_MEMBASE: {
3165 S390_LONG (code, lgf, lgf, ins->dreg, 0,
3166 ins->inst_basereg, ins->inst_offset);
3169 case OP_LOADU4_MEMBASE: {
3170 S390_LONG (code, llgf, llgf, ins->dreg, 0,
3171 ins->inst_basereg, ins->inst_offset);
3174 case OP_LOADU1_MEMBASE: {
3175 S390_LONG (code, llgc, llgc, ins->dreg, 0,
3176 ins->inst_basereg, ins->inst_offset);
3179 case OP_LOADI1_MEMBASE: {
3180 S390_LONG (code, lgb, lgb, ins->dreg, 0,
3181 ins->inst_basereg, ins->inst_offset);
3184 case OP_LOADU2_MEMBASE: {
3185 S390_LONG (code, llgh, llgh, ins->dreg, 0,
3186 ins->inst_basereg, ins->inst_offset);
3189 case OP_LOADI2_MEMBASE: {
3190 S390_LONG (code, lgh, lgh, ins->dreg, 0,
3191 ins->inst_basereg, ins->inst_offset);
3194 case OP_LCONV_TO_I1: {
3196 s390_lgbr (code, ins->dreg, ins->sreg1);
3198 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
3199 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
3203 case OP_LCONV_TO_I2: {
3205 s390_lghr (code, ins->dreg, ins->sreg1);
3207 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
3208 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
3212 case OP_LCONV_TO_U1: {
3214 s390_llghr (code, ins->dreg, ins->sreg1);
3216 if (ins->dreg != ins->sreg1)
3217 s390_lgr (code, ins->dreg, ins->sreg1);
3218 s390_lghi (code, s390_r0, 0xff);
3219 s390_ngr (code, ins->dreg, s390_r0);
3223 case OP_LCONV_TO_U2: {
3225 s390_llghr (code, ins->dreg, ins->sreg1);
3227 if (ins->dreg != ins->sreg1)
3228 s390_lgr (code, ins->dreg, ins->sreg1);
3229 s390_lghi (code, s390_r0, -1);
3230 s390_srlg (code, s390_r0, s390_r0, 0, 48);
3231 s390_ngr (code, ins->dreg, s390_r0);
3235 case OP_ICONV_TO_I1: {
3237 s390_lbr (code, ins->dreg, ins->sreg1);
3239 if (ins->dreg != ins->sreg1)
3240 s390_lr (code, ins->dreg, ins->sreg1);
3241 s390_sll (code, ins->dreg, 0, 24);
3242 s390_sra (code, ins->dreg, 0, 24);
3247 case OP_ICONV_TO_I2: {
3249 s390_lhr (code, ins->dreg, ins->sreg1);
3251 if (ins->dreg != ins->sreg1)
3252 s390_lr (code, ins->dreg, ins->sreg1);
3253 s390_sll (code, ins->dreg, 0, 16);
3254 s390_sra (code, ins->dreg, 0, 16);
3258 case OP_ICONV_TO_U1: {
3260 s390_llcr (code, ins->dreg, ins->sreg1);
3262 if (ins->dreg != ins->sreg1)
3263 s390_lr (code, ins->dreg, ins->sreg1);
3264 s390_lhi (code, s390_r0, 0xff);
3265 s390_nr (code, ins->dreg, s390_r0);
3269 case OP_ICONV_TO_U2: {
3271 s390_llhr (code, ins->dreg, ins->sreg1);
3273 if (ins->dreg != ins->sreg1)
3274 s390_lr (code, ins->dreg, ins->sreg1);
3275 s390_lhi (code, s390_r0, -1);
3276 s390_srl (code, s390_r0, 0, 16);
3277 s390_nr (code, ins->dreg, s390_r0);
3283 if (is_unsigned (ins->next))
3284 s390_clgr (code, ins->sreg1, ins->sreg2);
3286 s390_cgr (code, ins->sreg1, ins->sreg2);
3290 if (is_unsigned (ins->next))
3291 s390_clr (code, ins->sreg1, ins->sreg2);
3293 s390_cr (code, ins->sreg1, ins->sreg2);
3296 case OP_COMPARE_IMM:
3297 case OP_LCOMPARE_IMM: {
3298 if (s390_is_imm16 (ins->inst_imm)) {
3299 s390_lghi (code, s390_r0, ins->inst_imm);
3300 if (is_unsigned (ins->next))
3301 s390_clgr (code, ins->sreg1, s390_r0);
3303 s390_cgr (code, ins->sreg1, s390_r0);
3305 s390_basr (code, s390_r13, 0);
3307 s390_llong(code, ins->inst_imm);
3308 if (is_unsigned (ins->next))
3309 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3311 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3315 case OP_ICOMPARE_IMM: {
3316 if (s390_is_imm16 (ins->inst_imm)) {
3317 s390_lghi (code, s390_r0, ins->inst_imm);
3318 if (is_unsigned (ins->next))
3319 s390_clr (code, ins->sreg1, s390_r0);
3321 s390_cr (code, ins->sreg1, s390_r0);
3324 s390_basr (code, s390_r13, 0);
3326 s390_word (code, ins->inst_imm);
3327 if (is_unsigned (ins->next))
3328 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
3330 s390_c (code, ins->sreg1, 0, s390_r13, 4);
3335 s390_basr (code, s390_r13, 0);
3337 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
3339 s390_llong (code, mono_break);
3340 s390_lg (code, s390_r14, 0, s390_r13, 4);
3341 s390_basr (code, s390_r14, s390_r14);
3346 s390_agr (code, ins->dreg, src2);
3351 s390_agr (code, ins->dreg, src2);
3356 s390_alcgr (code, ins->dreg, src2);
3360 if (ins->dreg != ins->sreg1) {
3361 s390_lgr (code, ins->dreg, ins->sreg1);
3363 if (s390_is_imm16 (ins->inst_imm)) {
3364 s390_aghi (code, ins->dreg, ins->inst_imm);
3366 s390_basr (code, s390_r13, 0);
3368 s390_llong(code, ins->inst_imm);
3369 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3374 if (ins->dreg != ins->sreg1) {
3375 s390_lgr (code, ins->dreg, ins->sreg1);
3377 g_assert (s390_is_imm16 (ins->inst_imm));
3378 s390_aghi (code, ins->dreg, ins->inst_imm);
3382 if (ins->dreg != ins->sreg1) {
3383 s390_lgr (code, ins->dreg, ins->sreg1);
3385 if (s390_is_imm16 (ins->inst_imm)) {
3386 s390_lghi (code, s390_r0, ins->inst_imm);
3387 s390_alcgr (code, ins->dreg, s390_r0);
3389 s390_basr (code, s390_r13, 0);
3391 s390_llong (code, ins->inst_imm);
3392 s390_lg (code, s390_r13, 0, s390_r13, 4);
3393 s390_alcgr (code, ins->dreg, s390_r13);
3398 case OP_S390_IADD_OVF: {
3400 s390_ar (code, ins->dreg, src2);
3401 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3402 s390_lgfr (code, ins->dreg, ins->dreg);
3405 case OP_IADD_OVF_UN:
3406 case OP_S390_IADD_OVF_UN: {
3408 s390_algr (code, ins->dreg, src2);
3409 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3410 s390_llgfr (code, ins->dreg, ins->dreg);
3413 case OP_ADD_OVF_CARRY: {
3415 s390_lghi (code, s390_r0, 0);
3416 s390_lgr (code, s390_r1, s390_r0);
3417 s390_alcgr (code, s390_r0, s390_r1);
3418 s390_agr (code, ins->dreg, src2);
3419 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3420 s390_agr (code, ins->dreg, s390_r0);
3421 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3424 case OP_ADD_OVF_UN_CARRY: {
3426 s390_alcgr (code, ins->dreg, src2);
3427 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3432 s390_sgr (code, ins->dreg, src2);
3437 s390_sgr (code, ins->dreg, src2);
3442 s390_slbgr(code, ins->dreg, src2);
3446 if (ins->dreg != ins->sreg1) {
3447 s390_lgr (code, ins->dreg, ins->sreg1);
3449 if (s390_is_imm16 (-ins->inst_imm)) {
3450 s390_lghi (code, s390_r0, ins->inst_imm);
3451 s390_slgr (code, ins->dreg, s390_r0);
3453 s390_basr (code, s390_r13, 0);
3455 s390_llong(code, ins->inst_imm);
3456 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3461 if (ins->dreg != ins->sreg1) {
3462 s390_lgr (code, ins->dreg, ins->sreg1);
3464 if (s390_is_imm16 (-ins->inst_imm)) {
3465 s390_lghi (code, s390_r0, ins->inst_imm);
3466 s390_slgr (code, ins->dreg, s390_r0);
3468 s390_basr (code, s390_r13, 0);
3470 s390_llong(code, ins->inst_imm);
3471 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3476 if (ins->dreg != ins->sreg1) {
3477 s390_lgr (code, ins->dreg, ins->sreg1);
3479 if (s390_is_imm16 (-ins->inst_imm)) {
3480 s390_lghi (code, s390_r0, ins->inst_imm);
3481 s390_slbgr (code, ins->dreg, s390_r0);
3483 s390_basr (code, s390_r13, 0);
3485 s390_llong(code, ins->inst_imm);
3486 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3490 case OP_SUB_OVF_CARRY: {
3492 s390_lghi (code, s390_r0, 0);
3493 s390_lgr (code, s390_r1, s390_r0);
3494 s390_slbgr (code, s390_r0, s390_r1);
3495 s390_sgr (code, ins->dreg, src2);
3496 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3497 s390_agr (code, ins->dreg, s390_r0);
3498 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3501 case OP_SUB_OVF_UN_CARRY: {
3503 s390_slbgr (code, ins->dreg, src2);
3504 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3508 if (ins->sreg1 == ins->dreg) {
3509 s390_ngr (code, ins->dreg, ins->sreg2);
3512 if (ins->sreg2 == ins->dreg) {
3513 s390_ngr (code, ins->dreg, ins->sreg1);
3516 s390_lgr (code, ins->dreg, ins->sreg1);
3517 s390_ngr (code, ins->dreg, ins->sreg2);
3523 if (ins->dreg != ins->sreg1) {
3524 s390_lgr (code, ins->dreg, ins->sreg1);
3526 if (s390_is_imm16 (ins->inst_imm)) {
3527 s390_lghi (code, s390_r0, ins->inst_imm);
3528 s390_ngr (code, ins->dreg, s390_r0);
3530 s390_basr (code, s390_r13, 0);
3532 s390_llong(code, ins->inst_imm);
3533 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3538 s390_lgr (code, s390_r1, ins->sreg1);
3539 s390_dsgr (code, s390_r0, ins->sreg2);
3540 s390_lgr (code, ins->dreg, s390_r1);
3544 s390_lgr (code, s390_r1, ins->sreg1);
3545 s390_lghi (code, s390_r0, 0);
3546 s390_dlgr (code, s390_r0, ins->sreg2);
3547 s390_lgr (code, ins->dreg, s390_r1);
3551 s390_lgr (code, s390_r1, ins->sreg1);
3552 s390_dsgr (code, s390_r0, ins->sreg2);
3553 s390_lgr (code, ins->dreg, s390_r0);
3557 s390_lgr (code, s390_r1, ins->sreg1);
3558 s390_lghi (code, s390_r0, 0);
3559 s390_dlgr (code, s390_r0, ins->sreg2);
3560 s390_lgr (code, ins->dreg, s390_r0);
3564 if (ins->sreg1 == ins->dreg) {
3565 s390_ogr (code, ins->dreg, ins->sreg2);
3568 if (ins->sreg2 == ins->dreg) {
3569 s390_ogr (code, ins->dreg, ins->sreg1);
3572 s390_lgr (code, ins->dreg, ins->sreg1);
3573 s390_ogr (code, ins->dreg, ins->sreg2);
3579 if (ins->dreg != ins->sreg1) {
3580 s390_lgr (code, ins->dreg, ins->sreg1);
3582 if (s390_is_imm16 (ins->inst_imm)) {
3583 s390_lghi (code, s390_r0, ins->inst_imm);
3584 s390_ogr (code, ins->dreg, s390_r0);
3586 s390_basr (code, s390_r13, 0);
3588 s390_llong(code, ins->inst_imm);
3589 s390_og (code, ins->dreg, 0, s390_r13, 4);
3594 if (ins->sreg1 == ins->dreg) {
3595 s390_xgr (code, ins->dreg, ins->sreg2);
3598 if (ins->sreg2 == ins->dreg) {
3599 s390_xgr (code, ins->dreg, ins->sreg1);
3602 s390_lgr (code, ins->dreg, ins->sreg1);
3603 s390_xgr (code, ins->dreg, ins->sreg2);
3609 if (ins->dreg != ins->sreg1) {
3610 s390_lgr (code, ins->dreg, ins->sreg1);
3612 if (s390_is_imm16 (ins->inst_imm)) {
3613 s390_lghi (code, s390_r0, ins->inst_imm);
3614 s390_xgr (code, ins->dreg, s390_r0);
3616 s390_basr (code, s390_r13, 0);
3618 s390_llong(code, ins->inst_imm);
3619 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3625 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3630 if (ins->sreg1 != ins->dreg) {
3631 s390_lgr (code, ins->dreg, ins->sreg1);
3633 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3638 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3643 if (ins->sreg1 != ins->dreg) {
3644 s390_lgr (code, ins->dreg, ins->sreg1);
3646 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3650 case OP_LSHR_UN_IMM: {
3651 if (ins->sreg1 != ins->dreg) {
3652 s390_lgr (code, ins->dreg, ins->sreg1);
3654 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3659 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3663 if (ins->sreg1 != ins->dreg) {
3664 s390_lgr (code, ins->dreg, ins->sreg1);
3666 s390_lghi (code, s390_r0, -1);
3667 s390_xgr (code, ins->dreg, s390_r0);
3671 s390_lcgr (code, ins->dreg, ins->sreg1);
3676 s390_msgr (code, ins->dreg, src2);
3681 if (ins->dreg != ins->sreg1) {
3682 s390_lgr (code, ins->dreg, ins->sreg1);
3684 if (s390_is_imm16 (ins->inst_imm)) {
3685 s390_lghi (code, s390_r13, ins->inst_imm);
3687 s390_basr (code, s390_r13, 0);
3689 s390_llong(code, ins->inst_imm);
3690 s390_lg (code, s390_r13, 0, s390_r13, 4);
3692 s390_msgr (code, ins->dreg, s390_r13);
3697 s390_ltgr (code, s390_r1, ins->sreg1);
3698 s390_jz (code, 0); CODEPTR(code, o[0]);
3699 s390_ltgr (code, s390_r0, ins->sreg2);
3701 s390_lghi (code, s390_r1, 0);
3702 s390_j (code, 0); CODEPTR(code, o[1]);
3703 s390_xgr (code, s390_r0, s390_r1);
3704 s390_msgr (code, s390_r1, ins->sreg2);
3705 s390_xgr (code, s390_r0, s390_r1);
3706 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3707 s390_ltgr (code, s390_r0, s390_r0);
3708 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3709 PTRSLOT (code, o[0]);
3710 PTRSLOT (code, o[1]);
3711 s390_lgr (code, ins->dreg, s390_r1);
3714 case OP_LMUL_OVF_UN: {
3715 s390_lghi (code, s390_r0, 0);
3716 s390_lgr (code, s390_r1, ins->sreg1);
3717 s390_mlgr (code, s390_r0, ins->sreg2);
3718 s390_ltgr (code, s390_r0, s390_r0);
3719 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3720 s390_lgr (code, ins->dreg, s390_r1);
3724 g_assert_not_reached ();
3726 s390_algr (code, ins->dreg, src2);
3731 s390_agr (code, ins->dreg, src2);
3735 g_assert_not_reached ();
3737 s390_alcgr (code, ins->dreg, src2);
3741 if (ins->dreg != ins->sreg1) {
3742 s390_lgfr (code, ins->dreg, ins->sreg1);
3744 if (s390_is_imm16 (ins->inst_imm)) {
3745 s390_aghi(code, ins->dreg, ins->inst_imm);
3747 s390_basr (code, s390_r13, 0);
3749 s390_word (code, ins->inst_imm);
3750 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3755 if (ins->dreg != ins->sreg1) {
3756 s390_lgfr (code, ins->dreg, ins->sreg1);
3758 if (s390_is_imm16 (ins->inst_imm)) {
3759 s390_lghi (code, s390_r0, ins->inst_imm);
3760 s390_alcgr (code, ins->dreg, s390_r0);
3762 s390_basr (code, s390_r13, 0);
3764 s390_word (code, ins->inst_imm);
3765 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3766 s390_alcgr (code, ins->dreg, s390_r13);
3771 case OP_S390_LADD_OVF: {
3773 s390_agr (code, ins->dreg, src2);
3774 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3777 case OP_LADD_OVF_UN:
3778 case OP_S390_LADD_OVF_UN: {
3780 s390_algr (code, ins->dreg, src2);
3781 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3785 CHECK_SRCDST_NCOM_I;
3786 s390_slgr (code, ins->dreg, src2);
3790 CHECK_SRCDST_NCOM_I;
3791 s390_sgr (code, ins->dreg, src2);
3795 CHECK_SRCDST_NCOM_I;
3796 s390_slbgr (code, ins->dreg, src2);
3800 if (ins->dreg != ins->sreg1) {
3801 s390_lgfr (code, ins->dreg, ins->sreg1);
3803 if (s390_is_imm16 (-ins->inst_imm)) {
3804 s390_aghi (code, ins->dreg, -ins->inst_imm);
3806 s390_basr (code, s390_r13, 0);
3808 s390_word (code, ins->inst_imm);
3809 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3814 s390_basr (code, s390_r13, 0);
3816 s390_word (code, ins->inst_imm);
3817 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3821 case OP_S390_ISUB_OVF: {
3823 s390_sr (code, ins->dreg, src2);
3824 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3825 s390_lgfr (code, ins->dreg, ins->dreg);
3828 case OP_ISUB_OVF_UN:
3829 case OP_S390_ISUB_OVF_UN: {
3831 s390_slr (code, ins->dreg, src2);
3832 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3833 s390_llgfr(code, ins->dreg, ins->dreg);
3837 case OP_S390_LSUB_OVF: {
3839 s390_sgr (code, ins->dreg, src2);
3840 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3843 case OP_LSUB_OVF_UN:
3844 case OP_S390_LSUB_OVF_UN: {
3846 s390_slgr (code, ins->dreg, src2);
3847 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3851 CHECK_SRCDST_NCOM_I;
3852 s390_ngr (code, ins->dreg, src2);
3856 if (ins->dreg != ins->sreg1) {
3857 s390_lgfr (code, ins->dreg, ins->sreg1);
3859 if (s390_is_imm16 (ins->inst_imm)) {
3860 s390_lghi (code, s390_r0, ins->inst_imm);
3861 s390_ngr (code, ins->dreg, s390_r0);
3863 s390_basr (code, s390_r13, 0);
3865 s390_llong(code, ins->inst_imm);
3866 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3871 s390_lgfr (code, s390_r0, ins->sreg1);
3872 s390_srda (code, s390_r0, 0, 32);
3873 s390_dr (code, s390_r0, ins->sreg2);
3874 s390_lgfr (code, ins->dreg, s390_r1);
3878 s390_lgfr (code, s390_r0, ins->sreg1);
3879 s390_srdl (code, s390_r0, 0, 32);
3880 s390_dlr (code, s390_r0, ins->sreg2);
3881 s390_lgfr (code, ins->dreg, s390_r1);
3885 if (s390_is_imm16 (ins->inst_imm)) {
3886 s390_lghi (code, s390_r13, ins->inst_imm);
3887 s390_lgfr (code, s390_r0, ins->sreg1);
3889 s390_basr (code, s390_r13, 0);
3891 s390_word (code, ins->inst_imm);
3892 s390_lgfr (code, s390_r0, ins->sreg1);
3893 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3895 s390_srda (code, s390_r0, 0, 32);
3896 s390_dr (code, s390_r0, ins->sreg2);
3897 s390_lgfr (code, ins->dreg, s390_r1);
3901 s390_lgfr (code, s390_r0, ins->sreg1);
3902 s390_srda (code, s390_r0, 0, 32);
3903 s390_dr (code, s390_r0, ins->sreg2);
3904 s390_lgfr (code, ins->dreg, s390_r0);
3907 s390_lgfr (code, s390_r0, ins->sreg1);
3908 s390_srdl (code, s390_r0, 0, 32);
3909 s390_dlr (code, s390_r0, ins->sreg2);
3910 s390_lgfr (code, ins->dreg, s390_r0);
3914 if (s390_is_imm16 (ins->inst_imm)) {
3915 s390_lghi (code, s390_r13, ins->inst_imm);
3916 s390_lgfr (code, s390_r0, ins->sreg1);
3918 s390_basr (code, s390_r13, 0);
3920 s390_word (code, ins->inst_imm);
3921 s390_lgfr (code, s390_r0, ins->sreg1);
3922 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3924 s390_srda (code, s390_r0, 0, 32);
3925 s390_dr (code, s390_r0, ins->sreg2);
3926 s390_lgfr (code, ins->dreg, s390_r0);
3931 s390_ogr (code, ins->dreg, src2);
3935 if (ins->dreg != ins->sreg1) {
3936 s390_lgfr (code, ins->dreg, ins->sreg1);
3938 if (s390_is_imm16 (ins->inst_imm)) {
3939 s390_lghi (code, s390_r0, ins->inst_imm);
3940 s390_ogr (code, ins->dreg, s390_r0);
3942 s390_basr (code, s390_r13, 0);
3944 s390_llong(code, ins->inst_imm);
3945 s390_og (code, ins->dreg, 0, s390_r13, 4);
3951 s390_xgr (code, ins->dreg, src2);
3955 if (ins->dreg != ins->sreg1) {
3956 s390_lgfr (code, ins->dreg, ins->sreg1);
3958 if (s390_is_imm16 (ins->inst_imm)) {
3959 s390_lghi (code, s390_r0, ins->inst_imm);
3960 s390_xgr (code, ins->dreg, s390_r0);
3962 s390_basr (code, s390_r13, 0);
3964 s390_llong(code, ins->inst_imm);
3965 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3971 s390_sll (code, ins->dreg, src2, 0);
3975 if (ins->sreg1 != ins->dreg) {
3976 s390_lgfr (code, ins->dreg, ins->sreg1);
3978 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3983 s390_sra (code, ins->dreg, src2, 0);
3987 if (ins->sreg1 != ins->dreg) {
3988 s390_lgfr (code, ins->dreg, ins->sreg1);
3990 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3993 case OP_ISHR_UN_IMM: {
3994 if (ins->sreg1 != ins->dreg) {
3995 s390_lgfr (code, ins->dreg, ins->sreg1);
3997 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
4002 s390_srl (code, ins->dreg, src2, 0);
4006 if (ins->sreg1 != ins->dreg) {
4007 s390_lgfr (code, ins->dreg, ins->sreg1);
4009 s390_lghi (code, s390_r0, -1);
4010 s390_xgr (code, ins->dreg, s390_r0);
4014 s390_lcgr (code, ins->dreg, ins->sreg1);
4019 s390_msr (code, ins->dreg, src2);
4023 if (ins->dreg != ins->sreg1) {
4024 s390_lgfr (code, ins->dreg, ins->sreg1);
4026 if (s390_is_imm16 (ins->inst_imm)) {
4027 s390_lghi (code, s390_r13, ins->inst_imm);
4029 s390_basr (code, s390_r13, 0);
4031 s390_word (code, ins->inst_imm);
4032 s390_lgf (code, s390_r13, 0, s390_r13, 4);
4034 s390_msr (code, ins->dreg, s390_r13);
4039 s390_ltr (code, s390_r1, ins->sreg1);
4040 s390_jz (code, 0); CODEPTR(code, o[0]);
4041 s390_ltr (code, s390_r0, ins->sreg2);
4043 s390_lhi (code, s390_r1, 0);
4044 s390_j (code, 0); CODEPTR(code, o[1]);
4045 s390_xr (code, s390_r0, s390_r1);
4046 s390_msr (code, s390_r1, ins->sreg2);
4047 s390_xr (code, s390_r0, s390_r1);
4048 s390_srl (code, s390_r0, 0, 31);
4049 s390_ltr (code, s390_r0, s390_r0);
4050 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4051 PTRSLOT (code, o[0]);
4052 PTRSLOT (code, o[1]);
4053 s390_lgfr (code, ins->dreg, s390_r1);
4056 case OP_IMUL_OVF_UN: {
4057 s390_lhi (code, s390_r0, 0);
4058 s390_lr (code, s390_r1, ins->sreg1);
4059 s390_mlr (code, s390_r0, ins->sreg2);
4060 s390_ltr (code, s390_r0, s390_r0);
4061 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
4062 s390_lgfr (code, ins->dreg, s390_r1);
4067 if (s390_is_imm16(ins->inst_c0)) {
4068 s390_lghi (code, ins->dreg, ins->inst_c0);
4070 s390_basr (code, s390_r13, 0);
4072 s390_llong(code, ins->inst_c0);
4073 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4078 s390_basr (code, s390_r13, 0);
4080 mono_add_patch_info (cfg, code - cfg->native_code,
4081 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4082 s390_llong(code, 0);
4083 s390_lg (code,ins->dreg, 0, s390_r13, 4);
4086 case OP_JUMP_TABLE: {
4087 mono_add_patch_info (cfg, code - cfg->native_code,
4088 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
4089 s390_basr (code, s390_r13, 0);
4091 s390_llong (code, 0);
4092 s390_lg (code, ins->dreg, 0, s390_r13, 4);
4096 if (ins->dreg != ins->sreg1) {
4097 s390_lgr (code, ins->dreg, ins->sreg1);
4101 case OP_LCONV_TO_I8:
4103 s390_lgfr (code, ins->dreg, ins->sreg1);
4105 case OP_LCONV_TO_I4:
4106 s390_lgfr (code, ins->dreg, ins->sreg1);
4109 case OP_LCONV_TO_U8:
4110 case OP_LCONV_TO_U4:
4112 s390_llgfr (code, ins->dreg, ins->sreg1);
4114 case OP_LCONV_TO_OVF_U4:
4115 s390_basr (code, s390_r13, 0);
4117 s390_llong(code, 4294967295);
4118 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
4119 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4120 s390_ltgr (code, ins->sreg1, ins->sreg1);
4121 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4122 s390_llgfr(code, ins->dreg, ins->sreg1);
4124 case OP_LCONV_TO_OVF_I4_UN:
4125 s390_basr (code, s390_r13, 0);
4127 s390_llong(code, 2147483647);
4128 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
4129 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
4130 s390_ltgr (code, ins->sreg1, ins->sreg1);
4131 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
4132 s390_lgfr (code, ins->dreg, ins->sreg1);
4135 case OP_FCONV_TO_R4: {
4136 if (ins->dreg != ins->sreg1) {
4137 s390_ldr (code, ins->dreg, ins->sreg1);
4141 case OP_S390_SETF4RET: {
4142 s390_ledbr (code, ins->dreg, ins->sreg1);
4146 if (s390_is_imm16 (ins->inst_offset)) {
4147 s390_lghi (code, s390_r13, ins->inst_offset);
4149 s390_bras (code, s390_r13, 0);
4151 s390_llong(code, ins->inst_offset);
4152 s390_lg (code, s390_r13, 0, s390_r13, 4);
4154 s390_ear (code, s390_r1, 0);
4155 s390_sllg(code, s390_r1, s390_r1, 0, 32);
4156 s390_ear (code, s390_r1, 1);
4157 s390_lg (code, ins->dreg, s390_r13, s390_r1, 0);
4161 if (cfg->method->save_lmf)
4162 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
4164 if (cfg->flags & MONO_CFG_HAS_TAIL) {
4165 code = emit_load_volatile_arguments (code, cfg);
4168 code = backUpStackPtr(cfg, code);
4169 s390_lg (code, s390_r14, 0, cfg->frame_reg, S390_RET_ADDR_OFFSET);
4170 mono_add_patch_info (cfg, code - cfg->native_code,
4171 MONO_PATCH_INFO_METHOD_JUMP,
4173 s390_jcl (code, S390_CC_UN, 0);
4176 case OP_CHECK_THIS: {
4177 /* ensure ins->sreg1 is not NULL */
4178 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
4179 s390_ltgr (code, s390_r0, s390_r0);
4180 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
4184 int offset = cfg->sig_cookie + cfg->stack_usage;
4186 if (s390_is_imm16 (offset))
4187 s390_lghi (code, s390_r0, offset);
4189 s390_basr (code, s390_r13, 0);
4191 s390_llong(code, offset);
4192 s390_lg (code, s390_r0, 0, s390_r13, 0);
4194 s390_agr (code, s390_r0, cfg->frame_reg);
4195 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
4199 s390_basr (code, s390_r13, 0);
4201 call = (MonoCallInst*)ins;
4202 if (ins->flags & MONO_INST_HAS_METHOD)
4203 mono_add_patch_info (cfg, code-cfg->native_code,
4204 MONO_PATCH_INFO_METHOD,
4207 mono_add_patch_info (cfg, code-cfg->native_code,
4208 MONO_PATCH_INFO_ABS,
4210 s390_llong(code, 0);
4211 s390_lg (code, s390_r14, 0, s390_r13, 4);
4212 s390_basr (code, s390_r14, s390_r14);
4213 if (call->signature->ret->type == MONO_TYPE_R4)
4214 s390_ldebr (code, s390_f0, s390_f0);
4222 s390_basr (code, s390_r13, 0);
4224 call = (MonoCallInst*)ins;
4225 if (ins->flags & MONO_INST_HAS_METHOD)
4226 mono_add_patch_info (cfg, code-cfg->native_code,
4227 MONO_PATCH_INFO_METHOD,
4230 mono_add_patch_info (cfg, code-cfg->native_code,
4231 MONO_PATCH_INFO_ABS,
4233 s390_llong(code, 0);
4234 s390_lg (code, s390_r14, 0, s390_r13, 4);
4235 s390_basr (code, s390_r14, s390_r14);
4238 case OP_FCALL_REG: {
4239 call = (MonoCallInst*)ins;
4240 s390_lgr (code, s390_r1, ins->sreg1);
4241 s390_basr (code, s390_r14, s390_r1);
4242 if (call->signature->ret->type == MONO_TYPE_R4)
4243 s390_ldebr (code, s390_f0, s390_f0);
4249 case OP_VOIDCALL_REG:
4251 s390_lgr (code, s390_r1, ins->sreg1);
4252 s390_basr (code, s390_r14, s390_r1);
4255 case OP_FCALL_MEMBASE: {
4256 call = (MonoCallInst*)ins;
4257 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4258 s390_basr (code, s390_r14, s390_r1);
4259 if (call->signature->ret->type == MONO_TYPE_R4)
4260 s390_ldebr (code, s390_f0, s390_f0);
4263 case OP_LCALL_MEMBASE:
4264 case OP_VCALL_MEMBASE:
4265 case OP_VCALL2_MEMBASE:
4266 case OP_VOIDCALL_MEMBASE:
4267 case OP_CALL_MEMBASE: {
4268 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
4269 s390_basr (code, s390_r14, s390_r1);
4276 if (cfg->param_area == 0)
4277 alloca_skip = S390_MINIMAL_STACK_SIZE;
4279 alloca_skip = cfg->param_area;
4281 area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
4282 s390_lgr (code, s390_r1, ins->sreg1);
4283 if (ins->flags & MONO_INST_INIT)
4284 s390_lgr (code, s390_r0, ins->sreg1);
4285 s390_aghi (code, s390_r1, 14);
4286 s390_srlg (code, s390_r1, s390_r1, 0, 3);
4287 s390_sllg (code, s390_r1, s390_r1, 0, 3);
4288 if (cfg->method->save_lmf) {
4289 /*----------------------------------*/
4290 /* we have to adjust lmf ebp value */
4291 /*----------------------------------*/
4292 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
4294 s390_lgr (code, s390_r13, cfg->frame_reg);
4295 if (s390_is_imm16(lmfOffset))
4296 s390_aghi (code, s390_r13, lmfOffset);
4298 s390_basr (code, s390_r14, 0);
4300 s390_word (code, lmfOffset);
4301 s390_agf (code, s390_r13, 0, s390_r14, 4);
4303 s390_lgr (code, s390_r14, STK_BASE);
4304 s390_sgr (code, s390_r14, s390_r1);
4305 s390_stg (code, s390_r14, 0, s390_r13,
4306 G_STRUCT_OFFSET(MonoLMF, ebp));
4308 s390_lg (code, s390_r13, 0, STK_BASE, 0);
4309 s390_sgr (code, STK_BASE, s390_r1);
4310 s390_stg (code, s390_r13, 0, STK_BASE, 0);
4311 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
4312 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
4313 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
4314 if (ins->flags & MONO_INST_INIT) {
4315 s390_lgr (code, s390_r1, s390_r0);
4316 s390_lgr (code, s390_r0, ins->dreg);
4317 s390_lgr (code, s390_r14, s390_r12);
4318 s390_lghi (code, s390_r13, 0);
4319 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4321 s390_lgr (code, s390_r12, s390_r14);
4326 s390_lgr (code, s390_r2, ins->sreg1);
4327 s390_basr (code, s390_r13, 0);
4329 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4330 (gpointer) "mono_arch_throw_exception");
4331 s390_llong(code, 0);
4332 s390_lg (code, s390_r14, 0, s390_r13, 4);
4333 s390_basr (code, s390_r14, s390_r14);
4337 s390_lgr (code, s390_r2, ins->sreg1);
4338 s390_basr (code, s390_r13, 0);
4340 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
4341 (gpointer) "mono_arch_rethrow_exception");
4342 s390_llong(code, 0);
4343 s390_lg (code, s390_r14, 0, s390_r13, 4);
4344 s390_basr (code, s390_r14, s390_r14);
4347 case OP_START_HANDLER: {
4348 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4350 S390_LONG (code, stg, stg, s390_r14, 0,
4351 spvar->inst_basereg,
4352 spvar->inst_offset);
4355 case OP_ENDFILTER: {
4356 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4358 if (ins->sreg1 != s390_r2)
4359 s390_lgr(code, s390_r2, ins->sreg1);
4360 S390_LONG (code, lg, lg, s390_r14, 0,
4361 spvar->inst_basereg,
4362 spvar->inst_offset);
4363 s390_br (code, s390_r14);
4366 case OP_ENDFINALLY: {
4367 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
4369 S390_LONG (code, lg, lg, s390_r14, 0,
4370 spvar->inst_basereg,
4371 spvar->inst_offset);
4372 s390_br (code, s390_r14);
4375 case OP_CALL_HANDLER: {
4376 mono_add_patch_info (cfg, code-cfg->native_code,
4377 MONO_PATCH_INFO_BB, ins->inst_target_bb);
4378 s390_brasl (code, s390_r14, 0);
4379 mono_cfg_add_try_hole (cfg, ins->inst_eh_block, code, bb);
4383 ins->inst_c0 = code - cfg->native_code;
4386 case OP_RELAXED_NOP:
4389 case OP_DUMMY_STORE:
4390 case OP_NOT_REACHED:
4394 case OP_SEQ_POINT: {
4397 if (cfg->compile_aot)
4401 * Read from the single stepping trigger page. This will cause a
4402 * SIGSEGV when single stepping is enabled.
4403 * We do this _before_ the breakpoint, so single stepping after
4404 * a breakpoint is hit will step to the next IL offset.
4406 if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
4407 breakpointCode.pTrigger = ss_trigger_page;
4408 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
4409 code += BREAKPOINT_SIZE;
4412 mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
4415 * A placeholder for a possible breakpoint inserted by
4416 * mono_arch_set_breakpoint ().
4418 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); ++i)
4424 EMIT_UNCOND_BRANCH(ins);
4427 s390_br (code, ins->sreg1);
4433 s390_lghi(code, ins->dreg, 1);
4435 s390_lghi(code, ins->dreg, 0);
4441 s390_lghi(code, ins->dreg, 1);
4443 s390_lghi(code, ins->dreg, 0);
4449 s390_lghi(code, ins->dreg, 1);
4451 s390_lghi(code, ins->dreg, 0);
4457 s390_lghi(code, ins->dreg, 1);
4459 s390_lghi(code, ins->dreg, 0);
4465 s390_lghi(code, ins->dreg, 1);
4467 s390_lghi(code, ins->dreg, 0);
4470 case OP_COND_EXC_EQ:
4471 case OP_COND_EXC_IEQ:
4472 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4474 case OP_COND_EXC_NE_UN:
4475 case OP_COND_EXC_INE_UN:
4476 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4478 case OP_COND_EXC_LT:
4479 case OP_COND_EXC_ILT:
4480 case OP_COND_EXC_LT_UN:
4481 case OP_COND_EXC_ILT_UN:
4482 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4484 case OP_COND_EXC_GT:
4485 case OP_COND_EXC_IGT:
4486 case OP_COND_EXC_GT_UN:
4487 case OP_COND_EXC_IGT_UN:
4488 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4490 case OP_COND_EXC_GE:
4491 case OP_COND_EXC_IGE:
4492 case OP_COND_EXC_GE_UN:
4493 case OP_COND_EXC_IGE_UN:
4494 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4496 case OP_COND_EXC_LE:
4497 case OP_COND_EXC_ILE:
4498 case OP_COND_EXC_LE_UN:
4499 case OP_COND_EXC_ILE_UN:
4500 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4502 case OP_COND_EXC_OV:
4503 case OP_COND_EXC_IOV:
4504 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4506 case OP_COND_EXC_NO:
4507 case OP_COND_EXC_INO:
4508 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4511 case OP_COND_EXC_IC:
4512 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4514 case OP_COND_EXC_NC:
4515 case OP_COND_EXC_INC:
4516 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4520 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4524 EMIT_COND_BRANCH (ins, S390_CC_NE);
4530 EMIT_COND_BRANCH (ins, S390_CC_LT);
4536 EMIT_COND_BRANCH (ins, S390_CC_GT);
4542 EMIT_COND_BRANCH (ins, S390_CC_GE);
4548 EMIT_COND_BRANCH (ins, S390_CC_LE);
4551 /* floating point opcodes */
4553 if (*((double *) ins->inst_p0) == 0) {
4554 s390_lzdr (code, ins->dreg);
4556 s390_basr (code, s390_r13, 0);
4558 s390_llong (code, ins->inst_p0);
4559 s390_lg (code, s390_r13, 0, s390_r13, 4);
4560 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4565 if (*((float *) ins->inst_p0) == 0) {
4566 s390_lzdr (code, ins->dreg);
4568 s390_basr (code, s390_r13, 0);
4570 s390_llong(code, ins->inst_p0);
4571 s390_lg (code, s390_r13, 0, s390_r13, 4);
4572 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4576 case OP_STORER8_MEMBASE_REG: {
4577 S390_LONG (code, stdy, std, ins->sreg1, 0,
4578 ins->inst_destbasereg, ins->inst_offset);
4581 case OP_LOADR8_MEMBASE: {
4582 S390_LONG (code, ldy, ld, ins->dreg, 0,
4583 ins->inst_basereg, ins->inst_offset);
4586 case OP_STORER4_MEMBASE_REG: {
4587 s390_ledbr (code, s390_f15, ins->sreg1);
4588 S390_LONG (code, stey, ste, s390_f15, 0,
4589 ins->inst_destbasereg, ins->inst_offset);
4592 case OP_LOADR4_MEMBASE: {
4593 S390_LONG (code, ldy, ld, s390_f15, 0,
4594 ins->inst_basereg, ins->inst_offset);
4595 s390_ldebr (code, ins->dreg, s390_f15);
4598 case OP_ICONV_TO_R_UN: {
4599 s390_cdfbr (code, ins->dreg, ins->sreg1);
4600 s390_ltr (code, ins->sreg1, ins->sreg1);
4601 s390_jnl (code, 12);
4602 s390_basr (code, s390_r13, 0);
4604 s390_word (code, 0x41f00000);
4605 s390_word (code, 0);
4606 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4609 case OP_LCONV_TO_R_UN: {
4610 s390_cdgbr (code, ins->dreg, ins->sreg1);
4611 s390_ltgr (code, ins->sreg1, ins->sreg1);
4612 s390_jnl (code, 12);
4613 s390_basr (code, s390_r13, 0);
4615 s390_word (code, 0x41f00000);
4616 s390_word (code, 0);
4617 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4620 case OP_LCONV_TO_R4:
4621 case OP_ICONV_TO_R4: {
4622 s390_cdgbr (code, ins->dreg, ins->sreg1);
4625 case OP_LCONV_TO_R8:
4626 case OP_ICONV_TO_R8: {
4627 s390_cdgbr (code, ins->dreg, ins->sreg1);
4630 case OP_FCONV_TO_I1:
4631 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4633 case OP_FCONV_TO_U1:
4634 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4636 case OP_FCONV_TO_I2:
4637 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4639 case OP_FCONV_TO_U2:
4640 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4642 case OP_FCONV_TO_I4:
4644 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4646 case OP_FCONV_TO_U4:
4648 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4650 case OP_FCONV_TO_I8:
4651 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4653 case OP_LCONV_TO_OVF_I: {
4654 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4656 s390_ltgr (code, ins->sreg2, ins->sreg2);
4657 s390_jnl (code, 0); CODEPTR(code, o[0]);
4658 s390_ltgr (code, ins->sreg1, ins->sreg1);
4659 s390_jnl (code, 0); CODEPTR(code, o[1]);
4660 s390_lhi (code, s390_r13, -1);
4661 s390_cgr (code, ins->sreg1, s390_r13);
4662 s390_jnz (code, 0); CODEPTR(code, o[2]);
4663 if (ins->dreg != ins->sreg2)
4664 s390_lgr (code, ins->dreg, ins->sreg2);
4665 s390_j (code, 0); CODEPTR(code, o[3]);
4666 PTRSLOT(code, o[0]);
4667 s390_jz (code, 0); CODEPTR(code, o[4]);
4668 PTRSLOT(code, o[1]);
4669 PTRSLOT(code, o[2]);
4670 mono_add_patch_info (cfg, code - cfg->native_code,
4671 MONO_PATCH_INFO_EXC, "OverflowException");
4672 s390_brasl (code, s390_r14, 0);
4673 PTRSLOT(code, o[3]);
4674 PTRSLOT(code, o[4]);
4678 s390_lpdbr (code, ins->dreg, ins->sreg1);
4682 s390_sqdbr (code, ins->dreg, ins->sreg1);
4687 s390_adbr (code, ins->dreg, src2);
4691 CHECK_SRCDST_NCOM_F;
4692 s390_sdbr (code, ins->dreg, src2);
4697 s390_mdbr (code, ins->dreg, src2);
4701 CHECK_SRCDST_NCOM_F;
4702 s390_ddbr (code, ins->dreg, src2);
4706 s390_lcdbr (code, ins->dreg, ins->sreg1);
4710 CHECK_SRCDST_NCOM_F;
4711 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4715 s390_cdbr (code, ins->sreg1, ins->sreg2);
4719 s390_cdbr (code, ins->sreg1, ins->sreg2);
4720 s390_lghi (code, ins->dreg, 1);
4722 s390_lghi (code, ins->dreg, 0);
4726 s390_cdbr (code, ins->sreg1, ins->sreg2);
4727 s390_lghi (code, ins->dreg, 1);
4729 s390_lghi (code, ins->dreg, 0);
4733 s390_cdbr (code, ins->sreg1, ins->sreg2);
4734 s390_lghi (code, ins->dreg, 1);
4736 s390_lghi (code, ins->dreg, 0);
4740 s390_cdbr (code, ins->sreg1, ins->sreg2);
4741 s390_lghi (code, ins->dreg, 1);
4743 s390_lghi (code, ins->dreg, 0);
4747 s390_cdbr (code, ins->sreg1, ins->sreg2);
4748 s390_lghi (code, ins->dreg, 1);
4750 s390_lghi (code, ins->dreg, 0);
4755 s390_jo (code, 0); CODEPTR(code, o);
4756 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4761 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4765 s390_jo (code, 0); CODEPTR(code, o);
4766 EMIT_COND_BRANCH (ins, S390_CC_LT);
4771 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4775 s390_jo (code, 0); CODEPTR(code, o);
4776 EMIT_COND_BRANCH (ins, S390_CC_GT);
4781 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4785 s390_jo (code, 0); CODEPTR(code, o);
4786 EMIT_COND_BRANCH (ins, S390_CC_GE);
4791 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4795 s390_jo (code, 0); CODEPTR(code, o);
4796 EMIT_COND_BRANCH (ins, S390_CC_LE);
4801 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4805 s390_lhi (code, s390_r13, 0x7f);
4806 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4807 s390_jz (code, 0); CODEPTR(code, o);
4808 mono_add_patch_info (cfg, code - cfg->native_code,
4809 MONO_PATCH_INFO_EXC, "ArithmeticException");
4810 s390_brasl (code, s390_r14,0);
4814 case OP_S390_MOVE: {
4815 if (ins->backend.size > 0) {
4816 if (ins->backend.size <= 256) {
4817 s390_mvc (code, ins->backend.size, ins->dreg,
4818 ins->inst_offset, ins->sreg1, ins->inst_imm);
4820 s390_lgr (code, s390_r0, ins->dreg);
4821 if (ins->inst_offset > 0) {
4822 if (s390_is_imm16 (ins->inst_offset)) {
4823 s390_aghi (code, s390_r0, ins->inst_offset);
4825 s390_basr (code, s390_r13, 0);
4827 s390_llong(code, ins->inst_offset);
4828 s390_ag (code, s390_r0, 0, s390_r13, 4);
4831 s390_lgr (code, s390_r12, ins->sreg1);
4832 if (ins->inst_imm > 0) {
4833 if (s390_is_imm16 (ins->inst_imm)) {
4834 s390_aghi (code, s390_r12, ins->inst_imm);
4836 s390_basr (code, s390_r13, 0);
4838 s390_llong(code, ins->inst_imm);
4839 s390_ag (code, s390_r12, 0, s390_r13, 4);
4842 if (s390_is_imm16 (ins->backend.size)) {
4843 s390_lghi (code, s390_r1, ins->backend.size);
4845 s390_basr (code, s390_r13, 0);
4847 s390_llong(code, ins->backend.size);
4848 s390_lg (code, s390_r1, 0, s390_r13, 4);
4850 s390_lgr (code, s390_r13, s390_r1);
4851 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4857 case OP_ATOMIC_ADD_I8: {
4858 s390_lgr (code, s390_r1, ins->sreg2);
4859 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4860 s390_agr (code, s390_r1, s390_r0);
4861 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4862 s390_jnz (code, -10);
4863 s390_lgr (code, ins->dreg, s390_r1);
4866 case OP_ATOMIC_ADD_NEW_I8: {
4867 s390_lgr (code, s390_r1, ins->sreg2);
4868 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4869 s390_agr (code, s390_r1, s390_r0);
4870 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4871 s390_jnz (code, -10);
4872 s390_lgr (code, ins->dreg, s390_r1);
4875 case OP_ATOMIC_EXCHANGE_I8: {
4876 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4877 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4878 s390_jnz (code, -6);
4879 s390_lgr (code, ins->dreg, s390_r0);
4882 case OP_ATOMIC_ADD_I4: {
4883 s390_lgfr(code, s390_r1, ins->sreg2);
4884 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4885 s390_agr (code, s390_r1, s390_r0);
4886 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4887 s390_jnz (code, -9);
4888 s390_lgfr(code, ins->dreg, s390_r1);
4891 case OP_ATOMIC_ADD_NEW_I4: {
4892 s390_lgfr(code, s390_r1, ins->sreg2);
4893 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4894 s390_agr (code, s390_r1, s390_r0);
4895 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4896 s390_jnz (code, -9);
4897 s390_lgfr(code, ins->dreg, s390_r1);
4900 case OP_ATOMIC_EXCHANGE_I4: {
4901 s390_l (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4902 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4903 s390_jnz (code, -4);
4904 s390_lgfr(code, ins->dreg, s390_r0);
4907 case OP_S390_BKCHAIN: {
4908 s390_lgr (code, ins->dreg, ins->sreg1);
4909 if (s390_is_imm16 (cfg->stack_offset)) {
4910 s390_aghi (code, ins->dreg, cfg->stack_offset);
4912 s390_basr (code, s390_r13, 0);
4914 s390_llong(code, cfg->stack_offset);
4915 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4919 case OP_MEMORY_BARRIER: {
4922 case OP_GC_LIVENESS_DEF:
4923 case OP_GC_LIVENESS_USE:
4924 case OP_GC_PARAM_SLOT_LIVENESS_DEF:
4925 ins->backend.pc_offset = code - cfg->native_code;
4927 case OP_GC_SPILL_SLOT_LIVENESS_DEF:
4928 ins->backend.pc_offset = code - cfg->native_code;
4929 bb->spill_slot_defs = g_slist_prepend_mempool (cfg->mempool, bb->spill_slot_defs, ins);
4932 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4933 g_assert_not_reached ();
4936 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4937 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4938 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4939 g_assert_not_reached ();
4944 last_offset = offset;
4947 cfg->code_len = code - cfg->native_code;
4950 /*========================= End of Function ========================*/
4952 /*------------------------------------------------------------------*/
4954 /* Name - mono_arch_register_lowlevel_calls */
4956 /* Function - Register routines to help with --trace operation. */
4958 /*------------------------------------------------------------------*/
4961 mono_arch_register_lowlevel_calls (void)
4965 /*========================= End of Function ========================*/
4967 /*------------------------------------------------------------------*/
4969 /* Name - mono_arch_patch_code */
4971 /* Function - Process the patch data created during the */
4972 /* instruction build process. This resolves jumps, */
4973 /* calls, variables etc. */
4975 /*------------------------------------------------------------------*/
4978 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4979 guint8 *code, MonoJumpInfo *ji, MonoCodeManager *dyn_code_mp, gboolean run_cctors)
4981 MonoJumpInfo *patch_info;
4983 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4984 unsigned char *ip = patch_info->ip.i + code;
4985 gconstpointer target = NULL;
4987 target = mono_resolve_patch_target (method, domain, code,
4988 patch_info, run_cctors);
4990 switch (patch_info->type) {
4991 case MONO_PATCH_INFO_IP:
4992 case MONO_PATCH_INFO_EXC_NAME:
4993 case MONO_PATCH_INFO_LDSTR:
4994 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4995 case MONO_PATCH_INFO_LDTOKEN:
4996 case MONO_PATCH_INFO_EXC:
4997 case MONO_PATCH_INFO_ABS:
4998 case MONO_PATCH_INFO_METHOD:
4999 case MONO_PATCH_INFO_RGCTX_FETCH:
5000 case MONO_PATCH_INFO_INTERNAL_METHOD:
5001 case MONO_PATCH_INFO_CLASS_INIT:
5002 case MONO_PATCH_INFO_JIT_ICALL_ADDR:
5003 case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
5004 s390_patch_addr (ip, (guint64) target);
5006 case MONO_PATCH_INFO_SWITCH:
5007 /*----------------------------------*/
5008 /* ip points at the basr r13,0/j +4 */
5009 /* instruction the vtable value */
5010 /* follows this (i.e. ip+6) */
5011 /*----------------------------------*/
5012 *((gconstpointer *)(ip+6)) = target;
5014 case MONO_PATCH_INFO_METHODCONST:
5015 case MONO_PATCH_INFO_CLASS:
5016 case MONO_PATCH_INFO_IMAGE:
5017 case MONO_PATCH_INFO_FIELD:
5018 case MONO_PATCH_INFO_IID:
5019 target = S390_RELATIVE(target, ip);
5020 s390_patch_rel (ip, (guint64) target);
5022 case MONO_PATCH_INFO_R4:
5023 case MONO_PATCH_INFO_R8:
5024 case MONO_PATCH_INFO_METHOD_REL:
5025 g_assert_not_reached ();
5028 target = S390_RELATIVE(target, ip);
5030 s390_patch_rel (ip, (guint64) target);
5035 /*========================= End of Function ========================*/
5037 /*------------------------------------------------------------------*/
5039 /* Name - emit_load_volatile_arguments */
5041 /* Function - Emit the instructions to reload parameter regist- */
5042 /* registers for use with "tail" operations. */
5044 /* The register loading operations performed here */
5045 /* are the mirror of the store operations performed */
5046 /* in mono_arch_emit_prolog and need to be kept in */
5047 /* synchronization with it. */
5049 /*------------------------------------------------------------------*/
5052 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
5055 MonoMethod *method = cfg->method;
5056 MonoMethodSignature *sig = mono_method_signature(method);
5060 cinfo = get_call_info (NULL, NULL, sig);
5062 if (cinfo->struct_ret) {
5063 ArgInfo *ainfo = &cinfo->ret;
5064 inst = cfg->vret_addr;
5065 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5068 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5069 ArgInfo *ainfo = cinfo->args + i;
5070 inst = cfg->args [pos];
5072 if (inst->opcode == OP_REGVAR) {
5073 if (ainfo->regtype == RegTypeGeneral)
5074 s390_lgr (code, ainfo->reg, inst->dreg);
5075 else if (ainfo->regtype == RegTypeFP) {
5076 if (inst->dreg != ainfo->reg) {
5077 if (ainfo->size == 4) {
5078 s390_ldebr (code, ainfo->reg, inst->dreg);
5080 s390_ldr (code, ainfo->reg, inst->dreg);
5084 else if (ainfo->regtype == RegTypeBase) {
5086 g_assert_not_reached ();
5088 if (ainfo->regtype == RegTypeGeneral) {
5089 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5090 g_assert_not_reached();
5091 switch (ainfo->size) {
5093 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5096 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5099 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5102 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5105 } else if (ainfo->regtype == RegTypeBase) {
5106 } else if (ainfo->regtype == RegTypeFP) {
5107 if (ainfo->size == 8)
5108 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5109 else if (ainfo->size == 4)
5110 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5112 g_assert_not_reached ();
5113 } else if (ainfo->regtype == RegTypeStructByVal) {
5114 if (ainfo->reg != STK_BASE) {
5115 switch (ainfo->size) {
5117 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5120 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5123 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5126 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5130 } else if (ainfo->regtype == RegTypeStructByAddr) {
5131 if (ainfo->reg != STK_BASE) {
5132 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5135 g_assert_not_reached ();
5143 /*========================= End of Function ========================*/
5145 /*------------------------------------------------------------------*/
5147 /* Name - mono_arch_emit_prolog */
5149 /* Function - Create the instruction sequence for a function */
5152 /*------------------------------------------------------------------*/
5155 mono_arch_emit_prolog (MonoCompile *cfg)
5157 MonoMethod *method = cfg->method;
5159 MonoMethodSignature *sig;
5161 long alloc_size, pos, max_offset, i, cfa_offset = 0;
5168 cfg->code_size = 512;
5170 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5172 cfg->code_size += 256;
5173 } else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5174 cfg->code_size += 256;
5176 if (method->save_lmf)
5177 cfg->code_size += 200;
5179 cfg->native_code = code = g_malloc (cfg->code_size);
5181 mono_emit_unwind_op_def_cfa (cfg, code, STK_BASE, 0);
5182 emit_unwind_regs(cfg, code, s390_r6, s390_r14, S390_REG_SAVE_OFFSET);
5183 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5184 mono_emit_unwind_op_offset (cfg, code, s390_r14, S390_RET_ADDR_OFFSET);
5186 if (cfg->arch.bkchain_reg != -1)
5187 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
5189 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5190 cfg->used_int_regs |= 1 << 11;
5193 alloc_size = cfg->stack_offset;
5195 cfg->stack_usage = cfa_offset = alloc_size;
5196 mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
5197 s390_lgr (code, s390_r11, STK_BASE);
5198 if (s390_is_imm16 (alloc_size)) {
5199 s390_aghi (code, STK_BASE, -alloc_size);
5201 int stackSize = alloc_size;
5202 while (stackSize > 32767) {
5203 s390_aghi (code, STK_BASE, -32767);
5206 s390_aghi (code, STK_BASE, -stackSize);
5208 s390_stg (code, s390_r11, 0, STK_BASE, 0);
5210 if (cfg->frame_reg != STK_BASE)
5211 s390_lgr (code, s390_r11, STK_BASE);
5213 mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
5215 /* store runtime generic context */
5216 if (cfg->rgctx_var) {
5217 g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
5219 s390_stg (code, MONO_ARCH_RGCTX_REG, 0,
5220 cfg->rgctx_var->inst_basereg,
5221 cfg->rgctx_var->inst_offset);
5224 /* compute max_offset in order to use short forward jumps
5225 * we always do it on s390 because the immediate displacement
5226 * for jumps is too small
5229 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
5231 bb->max_offset = max_offset;
5233 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
5236 MONO_BB_FOR_EACH_INS (bb, ins)
5237 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
5240 /* load arguments allocated to register from the stack */
5241 sig = mono_method_signature (method);
5244 cinfo = get_call_info (cfg, cfg->mempool, sig);
5246 if (cinfo->struct_ret) {
5247 ArgInfo *ainfo = &cinfo->ret;
5248 inst = cfg->vret_addr;
5249 inst->backend.size = ainfo->vtsize;
5250 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5253 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
5254 ArgInfo *ainfo = cinfo->args + i;
5255 inst = cfg->args [pos];
5257 if (inst->opcode == OP_VTARG_ADDR)
5258 inst = inst->inst_left;
5260 if (inst->opcode == OP_REGVAR) {
5261 if (ainfo->regtype == RegTypeGeneral)
5262 s390_lgr (code, inst->dreg, ainfo->reg);
5263 else if (ainfo->regtype == RegTypeFP) {
5264 if (inst->dreg != ainfo->reg) {
5265 if (ainfo->size == 4) {
5266 s390_ledbr (code, inst->dreg, ainfo->reg);
5268 s390_ldr (code, inst->dreg, ainfo->reg);
5272 else if (ainfo->regtype == RegTypeBase) {
5273 s390_lgr (code, s390_r13, STK_BASE);
5274 s390_aghi (code, s390_r13, alloc_size);
5275 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
5277 g_assert_not_reached ();
5279 if (cfg->verbose_level > 2)
5280 g_print ("Argument %d assigned to register %s\n",
5281 pos, mono_arch_regname (inst->dreg));
5283 if (ainfo->regtype == RegTypeGeneral) {
5284 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
5285 g_assert_not_reached();
5286 switch (ainfo->size) {
5288 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5291 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5294 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5297 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5300 } else if (ainfo->regtype == RegTypeBase) {
5301 } else if (ainfo->regtype == RegTypeFP) {
5302 if (ainfo->size == 8)
5303 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5304 else if (ainfo->size == 4)
5305 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5307 g_assert_not_reached ();
5308 } else if (ainfo->regtype == RegTypeStructByVal) {
5309 int doffset = inst->inst_offset;
5311 if (ainfo->reg != STK_BASE)
5315 s390_lgr (code, s390_r13, STK_BASE);
5316 s390_aghi (code, s390_r13, alloc_size);
5319 size = (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE
5320 ? mono_class_native_size(mono_class_from_mono_type(inst->inst_vtype), NULL)
5325 if (ainfo->reg == STK_BASE)
5326 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
5327 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
5330 if (ainfo->reg == STK_BASE)
5331 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
5332 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
5335 if (ainfo->reg == STK_BASE)
5336 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
5337 s390_st (code, reg, 0, inst->inst_basereg, doffset);
5340 if (ainfo->reg == STK_BASE)
5341 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
5342 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
5345 } else if (ainfo->regtype == RegTypeStructByAddr) {
5346 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
5347 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
5349 g_assert_not_reached ();
5354 if (method->save_lmf) {
5355 /*---------------------------------------------------------------*/
5356 /* build the MonoLMF structure on the stack - see mini-s390x.h */
5357 /*---------------------------------------------------------------*/
5358 lmfOffset = alloc_size - sizeof(MonoLMF);
5360 s390_lgr (code, s390_r13, cfg->frame_reg);
5361 s390_aghi (code, s390_r13, lmfOffset);
5363 /*---------------------------------------------------------------*/
5364 /* Preserve the parameter registers while we fix up the lmf */
5365 /*---------------------------------------------------------------*/
5366 s390_stmg (code, s390_r2, s390_r6, s390_r13,
5367 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5369 /*---------------------------------------------------------------*/
5370 /* On return from this call r2 have the address of the &lmf */
5371 /*---------------------------------------------------------------*/
5372 if (lmf_addr_tls_offset == -1) {
5373 s390_basr(code, s390_r14, 0);
5375 mono_add_patch_info (cfg, code - cfg->native_code,
5376 MONO_PATCH_INFO_INTERNAL_METHOD,
5377 (gpointer)"mono_get_lmf_addr");
5378 s390_llong(code, 0);
5379 s390_lg (code, s390_r1, 0, s390_r14, 4);
5380 s390_basr (code, s390_r14, s390_r1);
5382 /*-------------------------------------------------------*/
5383 /* Get LMF by getting value from thread level storage */
5384 /*-------------------------------------------------------*/
5385 s390_ear (code, s390_r1, 0);
5386 s390_sllg(code, s390_r1, s390_r1, 0, 32);
5387 s390_ear (code, s390_r1, 1);
5388 s390_lg (code, s390_r2, 0, s390_r1, lmf_addr_tls_offset);
5391 /*---------------------------------------------------------------*/
5392 /* Set lmf.lmf_addr = jit_tls->lmf */
5393 /*---------------------------------------------------------------*/
5394 s390_stg (code, s390_r2, 0, s390_r13,
5395 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
5397 /*---------------------------------------------------------------*/
5398 /* Get current lmf */
5399 /*---------------------------------------------------------------*/
5400 s390_lg (code, s390_r0, 0, s390_r2, 0);
5402 /*---------------------------------------------------------------*/
5403 /* Set our lmf as the current lmf */
5404 /*---------------------------------------------------------------*/
5405 s390_stg (code, s390_r13, 0, s390_r2, 0);
5407 /*---------------------------------------------------------------*/
5408 /* Have our lmf.previous_lmf point to the last lmf */
5409 /*---------------------------------------------------------------*/
5410 s390_stg (code, s390_r0, 0, s390_r13,
5411 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
5413 /*---------------------------------------------------------------*/
5414 /* save method info */
5415 /*---------------------------------------------------------------*/
5416 s390_basr (code, s390_r1, 0);
5418 s390_llong (code, method);
5419 s390_lg (code, s390_r1, 0, s390_r1, 4);
5420 s390_stg (code, s390_r1, 0, s390_r13,
5421 G_STRUCT_OFFSET(MonoLMF, method));
5423 /*---------------------------------------------------------------*/
5424 /* save the current IP */
5425 /*---------------------------------------------------------------*/
5426 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
5427 s390_basr (code, s390_r1, 0);
5428 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
5430 /*---------------------------------------------------------------*/
5431 /* Save general and floating point registers */
5432 /*---------------------------------------------------------------*/
5433 s390_stmg (code, s390_r2, s390_r12, s390_r13,
5434 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
5435 for (i = 0; i < 16; i++) {
5436 s390_std (code, i, 0, s390_r13,
5437 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
5440 /*---------------------------------------------------------------*/
5441 /* Restore the parameter registers now that we've set up the lmf */
5442 /*---------------------------------------------------------------*/
5443 s390_lmg (code, s390_r2, s390_r6, s390_r13,
5444 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
5448 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
5450 cfg->code_len = code - cfg->native_code;
5451 g_assert (cfg->code_len < cfg->code_size);
5456 /*========================= End of Function ========================*/
5458 /*------------------------------------------------------------------*/
5460 /* Name - mono_arch_emit_epilog */
5462 /* Function - Emit the instructions for a function epilog. */
5464 /*------------------------------------------------------------------*/
5467 mono_arch_emit_epilog (MonoCompile *cfg)
5469 MonoMethod *method = cfg->method;
5472 int max_epilog_size = 96;
5474 if (cfg->method->save_lmf)
5475 max_epilog_size += 128;
5477 if (mono_jit_trace_calls != NULL)
5478 max_epilog_size += 128;
5479 else if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5480 max_epilog_size += 128;
5482 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5483 cfg->code_size *= 2;
5484 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5485 cfg->stat_code_reallocs++;
5488 code = cfg->native_code + cfg->code_len;
5490 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5491 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5495 if (method->save_lmf)
5496 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5498 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
5499 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5501 code = backUpStackPtr(cfg, code);
5503 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5504 s390_br (code, s390_r14);
5506 cfg->code_len = code - cfg->native_code;
5508 g_assert (cfg->code_len < cfg->code_size);
5512 /*========================= End of Function ========================*/
5514 /*------------------------------------------------------------------*/
5516 /* Name - mono_arch_emit_exceptions */
5518 /* Function - Emit the blocks to handle exception conditions. */
5520 /*------------------------------------------------------------------*/
5523 mono_arch_emit_exceptions (MonoCompile *cfg)
5525 MonoJumpInfo *patch_info;
5531 MonoClass *exc_classes [MAX_EXC];
5532 guint8 *exc_throw_start [MAX_EXC];
5534 for (patch_info = cfg->patch_info;
5536 patch_info = patch_info->next) {
5537 if (patch_info->type == MONO_PATCH_INFO_EXC)
5541 code_size = exc_count * 48;
5543 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5544 cfg->code_size *= 2;
5545 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5546 cfg->stat_code_reallocs++;
5549 code = cfg->native_code + cfg->code_len;
5551 /*---------------------------------------------------------------------*/
5552 /* Add code to raise exceptions */
5553 /*---------------------------------------------------------------------*/
5554 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5555 switch (patch_info->type) {
5556 case MONO_PATCH_INFO_EXC: {
5557 guint8 *ip = patch_info->ip.i + cfg->native_code;
5558 MonoClass *exc_class;
5561 /*-----------------------------------------------------*/
5562 /* Patch the branch in epilog to come here */
5563 /*-----------------------------------------------------*/
5564 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5566 exc_class = mono_class_from_name (mono_defaults.corlib,
5568 patch_info->data.name);
5569 g_assert (exc_class);
5570 throw_ip = patch_info->ip.i;
5572 for (iExc = 0; iExc < nThrows; ++iExc)
5573 if (exc_classes [iExc] == exc_class)
5576 if (iExc < nThrows) {
5577 s390_jcl (code, S390_CC_UN,
5578 (guint64) exc_throw_start [iExc]);
5579 patch_info->type = MONO_PATCH_INFO_NONE;
5582 if (nThrows < MAX_EXC) {
5583 exc_classes [nThrows] = exc_class;
5584 exc_throw_start [nThrows] = code;
5587 /*---------------------------------------------*/
5588 /* Patch the parameter passed to the handler */
5589 /*---------------------------------------------*/
5590 s390_basr (code, s390_r13, 0);
5592 // s390_llong(code, patch_info->data.target);
5593 s390_llong(code, exc_class->type_token);
5594 /*---------------------------------------------*/
5595 /* Load return address & parameter register */
5596 /*---------------------------------------------*/
5597 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5598 cfg->native_code + 8), code));
5599 s390_lg (code, s390_r2, 0, s390_r13, 4);
5600 /*---------------------------------------------*/
5601 /* Reuse the current patch to set the jump */
5602 /*---------------------------------------------*/
5603 s390_basr (code, s390_r13, 0);
5605 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5606 patch_info->data.name = "mono_arch_throw_corlib_exception";
5607 patch_info->ip.i = code - cfg->native_code;
5608 s390_llong(code, 0);
5609 s390_lg (code, s390_r1, 0, s390_r13, 4);
5610 s390_br (code, s390_r1);
5620 cfg->code_len = code - cfg->native_code;
5622 g_assert (cfg->code_len < cfg->code_size);
5626 /*========================= End of Function ========================*/
5628 /*------------------------------------------------------------------*/
5630 /* Name - mono_arch_finish_init */
5632 /* Function - Setup the JIT's Thread Level Specific Data. */
5634 /*------------------------------------------------------------------*/
5637 mono_arch_finish_init (void)
5639 appdomain_tls_offset = mono_domain_get_tls_offset();
5640 lmf_tls_offset = mono_get_lmf_tls_offset();
5641 lmf_addr_tls_offset = mono_get_lmf_addr_tls_offset();
5644 /*========================= End of Function ========================*/
5646 /*------------------------------------------------------------------*/
5648 /* Name - mono_arch_free_jit_tls_data */
5650 /* Function - Free tls data. */
5652 /*------------------------------------------------------------------*/
5655 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5659 /*========================= End of Function ========================*/
5661 /*------------------------------------------------------------------*/
5663 /* Name - mono_arch_emit_inst_for_method */
5665 /*------------------------------------------------------------------*/
5668 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5673 /*========================= End of Function ========================*/
5675 /*------------------------------------------------------------------*/
5677 /* Name - mono_arch_decompose_opts */
5679 /* Function - Decompose opcode into a System z opcode. */
5681 /*------------------------------------------------------------------*/
5684 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5687 * Have to rename these to avoid being decomposed normally, since the normal
5688 * decomposition does not work on S390.
5690 switch (ins->opcode) {
5692 ins->opcode = OP_S390_ISUB_OVF;
5694 case OP_ISUB_OVF_UN:
5695 ins->opcode = OP_S390_ISUB_OVF_UN;
5698 ins->opcode = OP_S390_IADD_OVF;
5700 case OP_IADD_OVF_UN:
5701 ins->opcode = OP_S390_IADD_OVF_UN;
5704 ins->opcode = OP_S390_LADD_OVF;
5706 case OP_LADD_OVF_UN:
5707 ins->opcode = OP_S390_LADD_OVF_UN;
5710 ins->opcode = OP_S390_LSUB_OVF;
5712 case OP_LSUB_OVF_UN:
5713 ins->opcode = OP_S390_LSUB_OVF_UN;
5720 /*========================= End of Function ========================*/
5722 /*------------------------------------------------------------------*/
5724 /* Name - mono_arch_print_tree */
5726 /* Function - Print platform-specific opcode details. */
5728 /* Returns - 1 - opcode details have been printed */
5729 /* 0 - opcode details have not been printed */
5731 /*------------------------------------------------------------------*/
5734 mono_arch_print_tree (MonoInst *tree, int arity)
5738 switch (tree->opcode) {
5739 case OP_S390_LOADARG:
5740 case OP_S390_ARGREG:
5741 case OP_S390_ARGPTR:
5742 printf ("[0x%lx(%s)]", tree->inst_offset,
5743 mono_arch_regname (tree->inst_basereg));
5746 case OP_S390_STKARG:
5747 printf ("[0x%lx(previous_frame)]",
5752 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5753 tree->inst_offset, tree->backend.size,
5754 mono_arch_regname(tree->dreg),
5756 mono_arch_regname(tree->sreg1));
5759 case OP_S390_SETF4RET:
5760 printf ("[f%s,f%s]",
5761 mono_arch_regname (tree->dreg),
5762 mono_arch_regname (tree->sreg1));
5766 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5768 mono_arch_regname (tree->sreg1));
5771 case OP_S390_BKCHAIN:
5772 printf ("[previous_frame(%s)]",
5773 mono_arch_regname (tree->sreg1));
5781 /*========================= End of Function ========================*/
5783 /*------------------------------------------------------------------*/
5785 /* Name - mono_arch_regalloc_cost */
5787 /* Function - Determine the cost, in the number of memory */
5788 /* references, of the action of allocating the var- */
5789 /* iable VMV into a register during global register */
5792 /* Returns - Cost */
5794 /*------------------------------------------------------------------*/
5797 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5803 /*========================= End of Function ========================*/
5805 /*------------------------------------------------------------------*/
5807 /* Name - mono_arch_get_domain_intrinsic */
5813 /*------------------------------------------------------------------*/
5816 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5820 if (appdomain_tls_offset == -1)
5823 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5824 ins->inst_offset = appdomain_tls_offset;
5828 /*========================= End of Function ========================*/
5830 /*------------------------------------------------------------------*/
5832 /* Name - mono_arch_flush_register_windows */
5838 /*------------------------------------------------------------------*/
5841 mono_arch_flush_register_windows (void)
5845 /*========================= End of Function ========================*/
5847 /*------------------------------------------------------------------*/
5849 /* Name - mono_arch_is_inst_imm */
5851 /* Function - Determine if operand qualifies as an immediate */
5852 /* value. For s390 this is a value -32768-32768 */
5854 /* Returns - True|False - is [not] immediate value. */
5856 /*------------------------------------------------------------------*/
5859 mono_arch_is_inst_imm (gint64 imm)
5861 return s390_is_imm16 (imm);
5864 /*========================= End of Function ========================*/
5866 /*------------------------------------------------------------------*/
5868 /* Name - mono_arch_get_patch_offset */
5870 /* Function - Dummy entry point until s390x supports aot. */
5872 /* Returns - Offset for patch. */
5874 /*------------------------------------------------------------------*/
5877 mono_arch_get_patch_offset (guint8 *code)
5882 /*========================= End of Function ========================*/
5884 /*------------------------------------------------------------------*/
5886 /* Name - mono_arch_context_get_int_reg. */
5890 /* Returns - Return a register from the context. */
5892 /*------------------------------------------------------------------*/
5895 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5897 return ((mgreg_t) ctx->uc_mcontext.gregs[reg]);
5900 /*========================= End of Function ========================*/
5902 /*------------------------------------------------------------------*/
5904 /* Name - mono_arch_context_set_int_reg. */
5906 /* Function - Set a value in a specified register. */
5908 /*------------------------------------------------------------------*/
5911 mono_arch_context_set_int_reg (MonoContext *ctx, int reg, mgreg_t val)
5913 ctx->uc_mcontext.gregs[reg] = val;
5916 /*========================= End of Function ========================*/
5918 /*------------------------------------------------------------------*/
5920 /* Name - mono_arch_get_this_arg_from_call. */
5924 /*------------------------------------------------------------------*/
5927 mono_arch_get_this_arg_from_call (mgreg_t *regs, guint8 *code)
5929 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
5931 return (gpointer) lmf->gregs [s390_r2];
5934 /*========================= End of Function ========================*/
5936 /*------------------------------------------------------------------*/
5938 /* Name - get_delegate_invoke_impl. */
5942 /*------------------------------------------------------------------*/
5945 get_delegate_invoke_impl (gboolean has_target, guint32 param_count, guint32 *code_len, gboolean aot)
5947 guint8 *code, *start;
5952 start = code = mono_global_codeman_reserve (size);
5954 /* Replace the this argument with the target */
5955 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5956 s390_lg (code, s390_r2, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, target));
5957 s390_br (code, s390_r1);
5958 g_assert ((code - start) <= size);
5960 mono_arch_flush_icache (start, size);
5964 size = 32 + param_count * 8;
5965 start = code = mono_global_codeman_reserve (size);
5967 s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoDelegate, method_ptr));
5968 /* slide down the arguments */
5969 for (i = 0; i < param_count; ++i) {
5970 s390_lgr (code, (s390_r2 + i), (s390_r2 + i + 1));
5972 s390_br (code, s390_r1);
5974 g_assert ((code - start) <= size);
5976 mono_arch_flush_icache (start, size);
5980 *code_len = code - start;
5985 /*========================= End of Function ========================*/
5987 /*------------------------------------------------------------------*/
5989 /* Name - mono_arch_get_delegate_invoke_impls. */
5993 /*------------------------------------------------------------------*/
5996 mono_arch_get_delegate_invoke_impls (void)
6003 code = get_delegate_invoke_impl (TRUE, 0, &code_len, TRUE);
6004 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup ("delegate_invoke_impl_has_target"), code, code_len, NULL, NULL));
6006 for (i = 0; i < MAX_ARCH_DELEGATE_PARAMS; ++i) {
6007 code = get_delegate_invoke_impl (FALSE, i, &code_len, TRUE);
6008 res = g_slist_prepend (res, mono_tramp_info_create (g_strdup_printf ("delegate_invoke_impl_target_%d", i), code, code_len, NULL, NULL));
6014 /*========================= End of Function ========================*/
6016 /*------------------------------------------------------------------*/
6018 /* Name - mono_arch_get_delegate_invoke_impl. */
6022 /*------------------------------------------------------------------*/
6025 mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_target)
6027 guint8 *code, *start;
6029 /* FIXME: Support more cases */
6030 if (MONO_TYPE_ISSTRUCT (sig->ret))
6034 static guint8* cached = NULL;
6040 start = mono_aot_get_trampoline ("delegate_invoke_impl_has_target");
6042 start = get_delegate_invoke_impl (TRUE, 0, NULL, FALSE);
6044 mono_memory_barrier ();
6048 static guint8* cache [MAX_ARCH_DELEGATE_PARAMS + 1] = {NULL};
6051 if (sig->param_count > MAX_ARCH_DELEGATE_PARAMS)
6053 for (i = 0; i < sig->param_count; ++i)
6054 if (!mono_is_regsize_var (sig->params [i]))
6058 code = cache [sig->param_count];
6062 if (mono_aot_only) {
6063 char *name = g_strdup_printf ("delegate_invoke_impl_target_%d", sig->param_count);
6064 start = mono_aot_get_trampoline (name);
6067 start = get_delegate_invoke_impl (FALSE, sig->param_count, NULL, FALSE);
6070 mono_memory_barrier ();
6072 cache [sig->param_count] = start;
6077 /*========================= End of Function ========================*/
6079 /*------------------------------------------------------------------*/
6081 /* Name - mono_arch_build_imt_thunk. */
6085 /*------------------------------------------------------------------*/
6088 mono_arch_build_imt_thunk (MonoVTable *vtable, MonoDomain *domain,
6089 MonoIMTCheckItem **imt_entries, int count,
6090 gpointer fail_tramp)
6094 guchar *code, *start;
6096 for (i = 0; i < count; ++i) {
6097 MonoIMTCheckItem *item = imt_entries [i];
6098 if (item->is_equals) {
6099 if (item->check_target_idx) {
6100 if (!item->compare_done)
6101 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6102 if (item->has_target_code)
6103 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE;
6105 item->chunk_size += BR_SIZE + JUMP_SIZE + LOADCON_SIZE +
6109 item->chunk_size += CMP_SIZE + 2 * BR_SIZE + JUMP_SIZE +
6111 if (!item->has_target_code)
6112 item->chunk_size += LOAD_SIZE;
6114 item->chunk_size += LOADCON_SIZE + LOAD_SIZE + BR_SIZE;
6115 #if ENABLE_WRONG_METHOD_CHECK
6116 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6121 item->chunk_size += CMP_SIZE + JUMP_SIZE;
6122 imt_entries [item->check_target_idx]->compare_done = TRUE;
6124 size += item->chunk_size;
6128 code = mono_method_alloc_generic_virtual_thunk (domain, size);
6130 code = mono_domain_code_reserve (domain, size);
6134 for (i = 0; i < count; ++i) {
6135 MonoIMTCheckItem *item = imt_entries [i];
6136 item->code_target = (guint8 *) code;
6137 if (item->is_equals) {
6138 if (item->check_target_idx) {
6139 if (!item->compare_done) {
6140 s390_basr (code, s390_r13, s390_r0);
6142 s390_llong(code, item->key);
6143 s390_lg (code, s390_r0, 0, s390_r13, 4);
6144 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6146 item->jmp_code = (guint8*) code;
6147 s390_jcl (code, S390_CC_NE, 0);
6149 s390_basr (code, s390_r13, s390_r0);
6151 if (item->has_target_code) {
6152 s390_llong(code, item->value.target_code);
6153 s390_lg (code, s390_r1, 0, s390_r13, 4);
6155 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6156 s390_lg (code, s390_r1, 0, s390_r13, 4);
6157 s390_lg (code, s390_r1, 0, s390_r1, 0);
6159 s390_br (code, s390_r1);
6164 s390_basr (code, s390_r13, s390_r0);
6166 s390_llong(code, item->key);
6167 s390_lg (code, s390_r0, 0, s390_r13, 4);
6168 s390_cgr (code, s390_r0, MONO_ARCH_IMT_REG);
6169 item->jmp_code = (guint8*) code;
6170 s390_jcl (code, S390_CC_NE, 0);
6171 s390_basr (code, s390_r13, s390_r0);
6173 if (item->has_target_code) {
6174 s390_llong(code, item->value.target_code);
6175 s390_lg (code, s390_r1, 0, s390_r13, 4);
6178 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6179 s390_lg (code, s390_r1, 0, s390_r13, 4);
6180 s390_lg (code, s390_r1, 0, s390_r1, 0);
6182 s390_br (code, s390_r1);
6183 target = S390_RELATIVE(code, item->jmp_code);
6184 s390_patch_rel(item->jmp_code+2, target);
6185 s390_basr (code, s390_r13, s390_r0);
6187 s390_llong(code, fail_tramp);
6188 s390_lg (code, s390_r1, 0, s390_r13, 4);
6189 s390_br (code, s390_r1);
6190 item->jmp_code = NULL;
6192 /* enable the commented code to assert on wrong method */
6193 #if ENABLE_WRONG_METHOD_CHECK
6194 g_assert_not_reached ();
6196 s390_basr (code, s390_r13, s390_r0);
6198 s390_llong(code, (&(vtable->vtable [item->value.vtable_slot])));
6199 s390_lg (code, s390_r1, 0, s390_r13, 4);
6200 s390_lg (code, s390_r1, 0, s390_r1, 0);
6201 s390_br (code, s390_r1);
6202 #if ENABLE_WRONG_METHOD_CHECK
6203 g_assert_not_reached ();
6208 s390_basr (code, s390_r13, s390_r0);
6210 s390_llong(code, item->key);
6211 s390_lg (code, s390_r0, 0, s390_r13, 4);
6212 s390_cgr (code, MONO_ARCH_IMT_REG, s390_r0);
6213 item->jmp_code = (guint8 *) code;
6214 s390_jcl (code, S390_CC_GE, 0);
6217 /* patch the branches to get to the target items */
6218 for (i = 0; i < count; ++i) {
6219 MonoIMTCheckItem *item = imt_entries [i];
6220 if (item->jmp_code) {
6221 if (item->check_target_idx) {
6223 offset = S390_RELATIVE(imt_entries [item->check_target_idx]->code_target,
6225 s390_patch_rel ((guchar *) item->jmp_code + 2, (guint64) offset);
6230 mono_arch_flush_icache ((guint8*)start, (code - start));
6233 mono_stats.imt_thunks_size += (code - start);
6235 g_assert (code - start <= size);
6240 /*========================= End of Function ========================*/
6242 /*------------------------------------------------------------------*/
6244 /* Name - mono_arch_find_imt_method. */
6246 /* Function - Get the method address from MONO_ARCH_IMT_REG */
6247 /* found in the save area. */
6249 /*------------------------------------------------------------------*/
6252 mono_arch_find_imt_method (mgreg_t *regs, guint8 *code)
6254 MonoLMF *lmf = (MonoLMF *) ((gchar *) regs - sizeof(MonoLMF));
6256 return ((MonoMethod *) lmf->gregs [MONO_ARCH_IMT_REG]);
6259 /*========================= End of Function ========================*/
6261 /*------------------------------------------------------------------*/
6263 /* Name - mono_arch_find_static_call_vtable */
6265 /* Function - Find the static call vtable. */
6267 /*------------------------------------------------------------------*/
6270 mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
6272 mgreg_t *r = (mgreg_t*)regs;
6274 return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
6277 /*========================= End of Function ========================*/
6279 /*------------------------------------------------------------------*/
6281 /* Name - mono_arch_get_cie_program */
6283 /* Function - Find the static call vtable. */
6285 /*------------------------------------------------------------------*/
6288 mono_arch_get_cie_program (void)
6292 mono_add_unwind_op_def_cfa (l, NULL, NULL, STK_BASE, 0);
6297 /*========================= End of Function ========================*/
6299 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
6301 /*------------------------------------------------------------------*/
6303 /* Name - mono_arch_set_breakpoint. */
6305 /* Function - Set a breakpoint at the native code corresponding */
6306 /* to JI at NATIVE_OFFSET. The location should */
6307 /* contain code emitted by OP_SEQ_POINT. */
6309 /*------------------------------------------------------------------*/
6312 mono_arch_set_breakpoint (MonoJitInfo *ji, guint8 *ip)
6316 breakpointCode.pTrigger = bp_trigger_page;
6317 memcpy(code, (void *) &breakpointCode, BREAKPOINT_SIZE);
6318 code += BREAKPOINT_SIZE;
6321 /*========================= End of Function ========================*/
6323 /*------------------------------------------------------------------*/
6325 /* Name - mono_arch_clear_breakpoint. */
6327 /* Function - Clear the breakpoint at IP. */
6329 /*------------------------------------------------------------------*/
6332 mono_arch_clear_breakpoint (MonoJitInfo *ji, guint8 *ip)
6337 for (i = 0; i < (BREAKPOINT_SIZE / S390X_NOP_SIZE); i++)
6341 /*========================= End of Function ========================*/
6343 /*------------------------------------------------------------------*/
6345 /* Name - mono_arch_is_breakpoint_event. */
6349 /*------------------------------------------------------------------*/
6352 mono_arch_is_breakpoint_event (void *info, void *sigctx)
6354 siginfo_t* sinfo = (siginfo_t*) info;
6355 /* Sometimes the address is off by 4 */
6356 if (sinfo->si_addr >= bp_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)bp_trigger_page + 128)
6362 /*========================= End of Function ========================*/
6364 /*------------------------------------------------------------------*/
6366 /* Name - mono_arch_skip_breakpoint. */
6368 /* Function - Modify the CTX so the IP is placed after the */
6369 /* breakpoint instruction, so when we resume, the */
6370 /* instruction is not executed again. */
6372 /*------------------------------------------------------------------*/
6375 mono_arch_skip_breakpoint (MonoContext *ctx, MonoJitInfo *ji)
6377 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6380 /*========================= End of Function ========================*/
6382 /*------------------------------------------------------------------*/
6384 /* Name - mono_arch_start_single_stepping. */
6386 /* Function - Start single stepping. */
6388 /*------------------------------------------------------------------*/
6391 mono_arch_start_single_stepping (void)
6393 mono_mprotect (ss_trigger_page, mono_pagesize (), 0);
6396 /*========================= End of Function ========================*/
6398 /*------------------------------------------------------------------*/
6400 /* Name - mono_arch_stop_single_stepping. */
6402 /* Function - Stop single stepping. */
6404 /*------------------------------------------------------------------*/
6407 mono_arch_stop_single_stepping (void)
6409 mono_mprotect (ss_trigger_page, mono_pagesize (), MONO_MMAP_READ);
6412 /*========================= End of Function ========================*/
6414 /*------------------------------------------------------------------*/
6416 /* Name - mono_arch_is_single_step_event. */
6418 /* Function - Return whether the machine state in sigctx cor- */
6419 /* responds to a single step event. */
6421 /*------------------------------------------------------------------*/
6424 mono_arch_is_single_step_event (void *info, void *sigctx)
6426 siginfo_t* sinfo = (siginfo_t*) info;
6428 /* Sometimes the address is off by 4 */
6429 if (sinfo->si_addr >= ss_trigger_page && (guint8*)sinfo->si_addr <= (guint8*)ss_trigger_page + 128)
6435 /*========================= End of Function ========================*/
6437 /*------------------------------------------------------------------*/
6439 /* Name - mono_arch_skip_single_step. */
6441 /* Function - Modify the ctx so the IP is placed after the */
6442 /* single step trigger instruction, so that the */
6443 /* instruction is not executed again. */
6445 /*------------------------------------------------------------------*/
6448 mono_arch_skip_single_step (MonoContext *ctx)
6450 MONO_CONTEXT_SET_IP (ctx, (guint8*)MONO_CONTEXT_GET_IP (ctx) + BREAKPOINT_SIZE);
6453 /*========================= End of Function ========================*/
6455 /*------------------------------------------------------------------*/
6457 /* Name - mono_arch_create_seq_point_info. */
6459 /* Function - Return a pointer to a data struction which is */
6460 /* used by the sequence point implementation in */
6463 /*------------------------------------------------------------------*/
6466 mono_arch_get_seq_point_info (MonoDomain *domain, guint8 *code)
6472 /*========================= End of Function ========================*/