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 NOT_IMPLEMENTED(x) \
22 g_error ("FIXME: %s is not yet implemented.", x);
24 #define EMIT_COND_BRANCH(ins,cond) \
26 if (ins->flags & MONO_INST_BRLABEL) { \
27 if (ins->inst_i0->inst_c0) { \
29 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
30 if (s390_is_imm16(displace)) { \
31 s390_brc (code, cond, displace); \
33 s390_jcl (code, cond, displace); \
36 mono_add_patch_info (cfg, code - cfg->native_code, \
37 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
38 s390_jcl (code, cond, 0); \
41 if (ins->inst_true_bb->native_offset) { \
43 displace = ((cfg->native_code + \
44 ins->inst_true_bb->native_offset) - code) / 2; \
45 if (s390_is_imm16(displace)) { \
46 s390_brc (code, cond, displace); \
48 s390_jcl (code, cond, displace); \
51 mono_add_patch_info (cfg, code - cfg->native_code, \
52 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
53 s390_jcl (code, cond, 0); \
58 #define EMIT_UNCOND_BRANCH(ins) \
60 if (ins->flags & MONO_INST_BRLABEL) { \
61 if (ins->inst_i0->inst_c0) { \
63 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
64 if (s390_is_imm16(displace)) { \
65 s390_brc (code, S390_CC_UN, displace); \
67 s390_jcl (code, S390_CC_UN, displace); \
70 mono_add_patch_info (cfg, code - cfg->native_code, \
71 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
72 s390_jcl (code, S390_CC_UN, 0); \
75 if (ins->inst_target_bb->native_offset) { \
77 displace = ((cfg->native_code + \
78 ins->inst_target_bb->native_offset) - code) / 2; \
79 if (s390_is_imm16(displace)) { \
80 s390_brc (code, S390_CC_UN, displace); \
82 s390_jcl (code, S390_CC_UN, displace); \
85 mono_add_patch_info (cfg, code - cfg->native_code, \
86 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
87 s390_jcl (code, S390_CC_UN, 0); \
92 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
94 mono_add_patch_info (cfg, code - cfg->native_code, \
95 MONO_PATCH_INFO_EXC, exc_name); \
96 s390_jcl (code, cond, 0); \
99 #define CHECK_SRCDST_COM \
100 if (ins->dreg == ins->sreg2) { \
104 if (ins->dreg != ins->sreg1) { \
105 s390_lgr (code, ins->dreg, ins->sreg1); \
109 #define CHECK_SRCDST_NCOM \
110 if (ins->dreg == ins->sreg2) { \
112 s390_lgr (code, s390_r13, ins->sreg2); \
116 if (ins->dreg != ins->sreg1) { \
117 s390_lgr (code, ins->dreg, ins->sreg1); \
120 #define CHECK_SRCDST_COM_I \
121 if (ins->dreg == ins->sreg2) { \
125 if (ins->dreg != ins->sreg1) { \
126 s390_lgfr (code, ins->dreg, ins->sreg1); \
130 #define CHECK_SRCDST_NCOM_I \
131 if (ins->dreg == ins->sreg2) { \
133 s390_lgfr (code, s390_r13, ins->sreg2); \
137 if (ins->dreg != ins->sreg1) { \
138 s390_lgfr (code, ins->dreg, ins->sreg1); \
141 #define CHECK_SRCDST_COM_F \
142 if (ins->dreg == ins->sreg2) { \
146 if (ins->dreg != ins->sreg1) { \
147 s390_ldr (code, ins->dreg, ins->sreg1); \
151 #define CHECK_SRCDST_NCOM_F \
152 if (ins->dreg == ins->sreg2) { \
154 s390_ldr (code, s390_r13, ins->sreg2); \
158 if (ins->dreg != ins->sreg1) { \
159 s390_ldr (code, ins->dreg, ins->sreg1); \
163 #define DEBUG(a) if (cfg->verbose_level > 1) a
167 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
169 #define MAX (a, b) ((a) > (b) ? (a) : (b))
171 /*========================= End of Defines =========================*/
173 /*------------------------------------------------------------------*/
174 /* I n c l u d e s */
175 /*------------------------------------------------------------------*/
180 #include <mono/metadata/appdomain.h>
181 #include <mono/metadata/debug-helpers.h>
182 #include <mono/metadata/profiler-private.h>
183 #include <mono/utils/mono-math.h>
185 #include "mini-s390x.h"
187 #include "cpu-s390x.h"
189 /*========================= End of Includes ========================*/
191 /*------------------------------------------------------------------*/
192 /* T y p e d e f s */
193 /*------------------------------------------------------------------*/
205 /*------------------------------------------------------------------*/
206 /* Used by the instrument_emit_epilog */
207 /*------------------------------------------------------------------*/
218 typedef struct InstList InstList
;
235 gint32 offset
; /* offset from caller's stack */
236 gint32 offparm
; /* offset from callee's stack */
237 guint16 vtsize
; /* in param area */
239 guint8 regtype
; /* See RegType* */
240 guint32 size
; /* Size of structure used by RegTypeStructByVal */
241 gint32 type
; /* Data type of argument */
255 gint64 gr
[5]; /* R2-R6 */
256 gdouble fp
[3]; /* F0-F2 */
257 } __attribute__ ((packed
)) RegParm
;
259 /*========================= End of Typedefs ========================*/
261 /*------------------------------------------------------------------*/
262 /* P r o t o t y p e s */
263 /*------------------------------------------------------------------*/
265 static void indent (int);
266 static guint8
* backUpStackPtr(MonoCompile
*, guint8
*);
267 static void decodeParm (MonoType
*, void *, int);
268 static void enter_method (MonoMethod
*, RegParm
*, char *);
269 static void leave_method (MonoMethod
*, ...);
270 static gboolean
is_regsize_var (MonoType
*);
271 static inline void add_general (guint
*, size_data
*, ArgInfo
*);
272 static inline void add_stackParm (guint
*, size_data
*, ArgInfo
*, gint
);
273 static inline void add_float (guint
*, size_data
*, ArgInfo
*);
274 static CallInfo
* calculate_sizes (MonoMethodSignature
*, size_data
*, gboolean
);
275 static void peephole_pass (MonoCompile
*, MonoBasicBlock
*);
276 static guchar
* emit_float_to_int (MonoCompile
*, guchar
*, int, int, int, gboolean
);
277 static void mono_arch_break(void);
278 gpointer
mono_arch_get_lmf_addr (void);
279 static guint8
* emit_load_volatile_registers (guint8
*, MonoCompile
*);
280 static CompRelation
opcode_to_cond (int);
281 static void catch_SIGILL(int, siginfo_t
*, void *);
282 static void emit_sig_cookie (MonoCompile
*, MonoCallInst
*, CallInfo
*, int);
284 /*========================= End of Prototypes ======================*/
286 /*------------------------------------------------------------------*/
287 /* G l o b a l V a r i a b l e s */
288 /*------------------------------------------------------------------*/
290 int mono_exc_esp_offset
= 0;
292 static int indent_level
= 0;
296 static gboolean tls_offset_inited
= FALSE
;
298 static int appdomain_tls_offset
= -1,
300 thread_tls_offset
= -1;
302 pthread_key_t lmf_addr_key
;
304 gboolean lmf_addr_key_inited
= FALSE
;
308 extern __thread MonoDomain
*tls_appdomain
;
309 extern __thread MonoThread
*tls_current_object
;
310 extern __thread gpointer mono_lmf_addr
;
314 /*====================== End of Global Variables ===================*/
316 /*------------------------------------------------------------------*/
318 /* Name - mono_arch_regname */
320 /* Function - Returns the name of the register specified by */
321 /* the input parameter. */
323 /*------------------------------------------------------------------*/
326 mono_arch_regname (int reg
) {
327 static const char * rnames
[] = {
328 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
329 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
330 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
334 if (reg
>= 0 && reg
< 16)
340 /*========================= End of Function ========================*/
342 /*------------------------------------------------------------------*/
344 /* Name - mono_arch_fregname */
346 /* Function - Returns the name of the register specified by */
347 /* the input parameter. */
349 /*------------------------------------------------------------------*/
352 mono_arch_fregname (int reg
) {
353 static const char * rnames
[] = {
354 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
355 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
356 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
360 if (reg
>= 0 && reg
< 16)
366 /*========================= End of Function ========================*/
368 /*------------------------------------------------------------------*/
370 /* Name - arch_get_argument_info */
372 /* Function - Gathers information on parameters such as size, */
373 /* alignment, and padding. arg_info should be large */
374 /* enough to hold param_count + 1 entries. */
376 /* Parameters - @csig - Method signature */
377 /* @param_count - No. of parameters to consider */
378 /* @arg_info - An array to store the result info */
380 /* Returns - Size of the activation frame */
382 /*------------------------------------------------------------------*/
385 mono_arch_get_argument_info (MonoMethodSignature
*csig
,
387 MonoJitArgumentInfo
*arg_info
)
389 int k
, frame_size
= 0;
390 int size
, align
, pad
;
393 if (MONO_TYPE_ISSTRUCT (csig
->ret
)) {
394 frame_size
+= sizeof (gpointer
);
398 arg_info
[0].offset
= offset
;
401 frame_size
+= sizeof (gpointer
);
405 arg_info
[0].size
= frame_size
;
407 for (k
= 0; k
< param_count
; k
++) {
410 size
= mono_type_native_stack_size (csig
->params
[k
], &align
);
412 size
= mono_type_stack_size (csig
->params
[k
], &align
);
414 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
415 arg_info
[k
].pad
= pad
;
417 arg_info
[k
+ 1].pad
= 0;
418 arg_info
[k
+ 1].size
= size
;
420 arg_info
[k
+ 1].offset
= offset
;
424 align
= MONO_ARCH_FRAME_ALIGNMENT
;
425 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
426 arg_info
[k
].pad
= pad
;
431 /*========================= End of Function ========================*/
433 /*------------------------------------------------------------------*/
435 /* Name - retFitsInReg. */
437 /* Function - Determines if a value can be returned in one or */
440 /*------------------------------------------------------------------*/
442 static inline gboolean
443 retFitsInReg(guint32 size
)
458 /*========================= End of Function ========================*/
460 /*------------------------------------------------------------------*/
462 /* Name - backStackPtr. */
464 /* Function - Restore Stack Pointer to previous frame. */
466 /*------------------------------------------------------------------*/
468 static inline guint8
*
469 backUpStackPtr(MonoCompile
*cfg
, guint8
*code
)
471 int stackSize
= cfg
->stack_usage
;
473 if (s390_is_uimm16 (stackSize
)) {
474 s390_aghi (code
, STK_BASE
, stackSize
);
476 while (stackSize
> 32767) {
477 s390_aghi (code
, STK_BASE
, 32767);
480 s390_aghi (code
, STK_BASE
, stackSize
);
485 /*========================= End of Function ========================*/
487 /*------------------------------------------------------------------*/
491 /* Function - Perform nice indenting to current level */
493 /*------------------------------------------------------------------*/
499 indent_level
+= diff
;
506 indent_level
+= diff
;
509 /*========================= End of Function ========================*/
511 /*------------------------------------------------------------------*/
513 /* Name - decodeParm */
515 /* Function - Decode a parameter for the trace. */
517 /*------------------------------------------------------------------*/
520 decodeParm(MonoType
*type
, void *curParm
, int size
)
525 printf("[BYREF:%p], ", *((char **) curParm
));
527 simpleType
= mono_type_get_underlying_type(type
)->type
;
529 switch (simpleType
) {
531 printf ("[INTPTR:%p], ", *((int **) curParm
));
534 printf ("[UINTPTR:%p], ", *((int **) curParm
));
536 case MONO_TYPE_BOOLEAN
:
537 printf ("[BOOL:%ld], ", *((gint64
*) curParm
));
539 case MONO_TYPE_CHAR
:
540 printf ("[CHAR:%c], ", *((int *) curParm
));
543 printf ("[INT1:%ld], ", *((gint64
*) curParm
));
546 printf ("[INT2:%ld], ", *((gint64
*) curParm
));
549 printf ("[INT4:%ld], ", *((gint64
*) curParm
));
552 printf ("[UINT1:%lu], ", *((guint64
*) curParm
));
555 printf ("[UINT2:%lu], ", *((guint64
*) curParm
));
558 printf ("[UINT4:%lu], ", *((guint64
*) curParm
));
561 printf ("[UINT8:%lu], ", *((guint64
*) curParm
));
563 case MONO_TYPE_STRING
: {
564 MonoString
*s
= *((MonoString
**) curParm
);
566 g_assert (((MonoObject
*) s
)->vtable
->klass
== mono_defaults
.string_class
);
567 printf("[STRING:%p:%s], ", s
, mono_string_to_utf8(s
));
569 printf("[STRING:null], ");
573 case MONO_TYPE_CLASS
:
574 case MONO_TYPE_OBJECT
: {
575 MonoObject
*obj
= *((MonoObject
**) curParm
);
577 if ((obj
) && (obj
->vtable
)) {
578 printf("[CLASS/OBJ:");
579 class = obj
->vtable
->klass
;
580 printf("%p [%p] ",obj
,curParm
);
581 if (class == mono_defaults
.string_class
) {
582 printf("[STRING:%p:%s]",
583 obj
, mono_string_to_utf8 ((MonoString
*) obj
));
584 } else if (class == mono_defaults
.int32_class
) {
585 printf("[INT32:%p:%d]",
586 obj
, *(gint32
*)((char *)obj
+ sizeof (MonoObject
)));
589 class->name_space
, class->name
, obj
);
592 printf("[OBJECT:null], ");
597 printf("[PTR:%p], ", *((gpointer
**) (curParm
)));
599 case MONO_TYPE_FNPTR
:
600 printf("[FNPTR:%p], ", *((gpointer
**) (curParm
)));
602 case MONO_TYPE_ARRAY
:
603 printf("[ARRAY:%p], ", *((gpointer
**) (curParm
)));
605 case MONO_TYPE_SZARRAY
:
606 printf("[SZARRAY:%p], ", *((gpointer
**) (curParm
)));
609 printf("[INT8:%ld], ", *((gint64
*) (curParm
)));
612 printf("[FLOAT4:%g], ", *((float *) (curParm
)));
615 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
617 case MONO_TYPE_VALUETYPE
: {
619 MonoMarshalType
*info
;
621 if (type
->data
.klass
->enumtype
) {
622 simpleType
= type
->data
.klass
->enum_basetype
->type
;
623 printf("{VALUETYPE} - ");
627 info
= mono_marshal_load_type_info (type
->data
.klass
);
629 if ((info
->native_size
== sizeof(float)) &&
630 (info
->num_fields
== 1) &&
631 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
632 printf("[FLOAT4:%f], ", *((float *) (curParm
)));
636 if ((info
->native_size
== sizeof(double)) &&
637 (info
->num_fields
== 1) &&
638 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
639 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
643 printf("[VALUETYPE:");
644 for (i
= 0; i
< size
; i
++)
645 printf("%02x,", *((guint8
*)curParm
+i
));
649 case MONO_TYPE_TYPEDBYREF
: {
651 printf("[TYPEDBYREF:");
652 for (i
= 0; i
< size
; i
++)
653 printf("%02x,", *((guint8
*)curParm
+i
));
658 printf("[?? - %d], ",simpleType
);
663 /*========================= End of Function ========================*/
665 /*------------------------------------------------------------------*/
667 /* Name - enter_method */
669 /* Function - Perform tracing of the entry to the current */
672 /*------------------------------------------------------------------*/
675 enter_method (MonoMethod
*method
, RegParm
*rParm
, char *sp
)
677 int i
, oParm
= 0, iParm
= 0;
680 MonoMethodSignature
*sig
;
688 fname
= mono_method_full_name (method
, TRUE
);
690 printf ("ENTER: %s ", fname
);
693 ip
= (*(guint64
*) (sp
+S390_RET_ADDR_OFFSET
));
694 printf ("ip: %p sp: %p - ", (gpointer
) ip
, sp
);
699 sig
= mono_method_signature (method
);
701 cinfo
= calculate_sizes (sig
, &sz
, sig
->pinvoke
);
703 if (cinfo
->struct_ret
) {
704 printf ("[STRUCTRET:%p], ", (gpointer
) rParm
->gr
[0]);
709 gpointer
*this = (gpointer
*) rParm
->gr
[iParm
];
710 obj
= (MonoObject
*) this;
711 if (method
->klass
->valuetype
) {
713 printf("this:[value:%p:%016lx], ",
714 this, *((guint64
*)(this+sizeof(MonoObject
))));
716 printf ("this:[NULL], ");
719 class = obj
->vtable
->klass
;
720 if (class == mono_defaults
.string_class
) {
721 printf ("this:[STRING:%p:%s], ",
722 obj
, mono_string_to_utf8 ((MonoString
*)obj
));
724 printf ("this:%p[%s.%s], ",
725 obj
, class->name_space
, class->name
);
728 printf ("this:NULL, ");
733 for (i
= 0; i
< sig
->param_count
; ++i
) {
734 ainfo
= &cinfo
->args
[i
+ oParm
];
735 switch (ainfo
->regtype
) {
736 case RegTypeGeneral
:
737 decodeParm(sig
->params
[i
], &(rParm
->gr
[ainfo
->reg
-2]), ainfo
->size
);
740 decodeParm(sig
->params
[i
], &(rParm
->fp
[ainfo
->reg
]), ainfo
->size
);
743 decodeParm(sig
->params
[i
], sp
+ainfo
->offset
, ainfo
->size
);
745 case RegTypeStructByVal
:
746 if (ainfo
->reg
!= STK_BASE
) {
747 int offset
= sizeof(glong
) - ainfo
->size
;
748 curParm
= &(rParm
->gr
[ainfo
->reg
-2])+offset
;
751 curParm
= sp
+ainfo
->offset
;
753 if (retFitsInReg (ainfo
->vtsize
))
754 decodeParm(sig
->params
[i
],
758 decodeParm(sig
->params
[i
],
759 *((char **) curParm
),
762 case RegTypeStructByAddr
:
763 if (ainfo
->reg
!= STK_BASE
)
764 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
766 curParm
= sp
+ainfo
->offset
;
768 decodeParm(sig
->params
[i
],
769 *((char **) curParm
),
781 /*========================= End of Function ========================*/
783 /*------------------------------------------------------------------*/
785 /* Name - leave_method */
789 /*------------------------------------------------------------------*/
792 leave_method (MonoMethod
*method
, ...)
799 va_start(ap
, method
);
801 fname
= mono_method_full_name (method
, TRUE
);
803 printf ("LEAVE: %s", fname
);
806 type
= mono_method_signature (method
)->ret
;
809 switch (type
->type
) {
812 case MONO_TYPE_BOOLEAN
: {
813 int val
= va_arg (ap
, int);
815 printf ("[TRUE:%d]", val
);
821 case MONO_TYPE_CHAR
: {
822 int val
= va_arg (ap
, int);
823 printf ("[CHAR:%d]", val
);
827 int val
= va_arg (ap
, int);
828 printf ("[INT1:%d]", val
);
832 int val
= va_arg (ap
, int);
833 printf ("[UINT1:%d]", val
);
837 int val
= va_arg (ap
, int);
838 printf ("[INT2:%d]", val
);
842 int val
= va_arg (ap
, int);
843 printf ("[UINT2:%d]", val
);
847 int val
= va_arg (ap
, int);
848 printf ("[INT4:%d]", val
);
852 int val
= va_arg (ap
, int);
853 printf ("[UINT4:%d]", val
);
857 gint64 val
= va_arg (ap
, gint64
);
858 printf ("[INT:%ld]", val
);
863 gint64 val
= va_arg (ap
, gint64
);
864 printf ("[UINT:%lu]", val
);
868 case MONO_TYPE_STRING
: {
869 MonoString
*s
= va_arg (ap
, MonoString
*);
872 g_assert (((MonoObject
*)s
)->vtable
->klass
== mono_defaults
.string_class
);
873 printf ("[STRING:%p:%s]", s
, mono_string_to_utf8 (s
));
875 printf ("[STRING:null], ");
878 case MONO_TYPE_CLASS
:
879 case MONO_TYPE_OBJECT
: {
880 MonoObject
*o
= va_arg (ap
, MonoObject
*);
882 if ((o
) && (o
->vtable
)) {
883 if (o
->vtable
->klass
== mono_defaults
.boolean_class
) {
884 printf ("[BOOLEAN:%p:%d]", o
, *((guint8
*)o
+ sizeof (MonoObject
)));
885 } else if (o
->vtable
->klass
== mono_defaults
.int32_class
) {
886 printf ("[INT32:%p:%d]", o
, *((gint32
*)((char *)o
+ sizeof (MonoObject
))));
887 } else if (o
->vtable
->klass
== mono_defaults
.int64_class
) {
888 printf ("[INT64:%p:%ld]", o
, *((gint64
*)((char *)o
+ sizeof (MonoObject
))));
890 printf ("[%s.%s:%p]", o
->vtable
->klass
->name_space
, o
->vtable
->klass
->name
, o
);
892 printf ("[OBJECT:%p]", o
);
897 case MONO_TYPE_FNPTR
:
898 case MONO_TYPE_ARRAY
:
899 case MONO_TYPE_SZARRAY
: {
900 gpointer p
= va_arg (ap
, gpointer
);
901 printf ("[result=%p]", p
);
905 gint64 l
= va_arg (ap
, gint64
);
906 printf ("[LONG:%ld]", l
);
910 guint64 l
= va_arg (ap
, guint64
);
911 printf ("[ULONG:%lu]", l
);
915 double f
= va_arg (ap
, double);
916 printf ("[FLOAT4:%g]\n", f
);
920 double f
= va_arg (ap
, double);
921 printf ("[FLOAT8:%g]\n", f
);
924 case MONO_TYPE_VALUETYPE
: {
925 MonoMarshalType
*info
;
926 if (type
->data
.klass
->enumtype
) {
927 type
= type
->data
.klass
->enum_basetype
;
930 guint8
*p
= va_arg (ap
, gpointer
);
933 info
= mono_marshal_load_type_info (type
->data
.klass
);
935 if ((info
->native_size
== sizeof(float)) &&
936 (info
->num_fields
== 1) &&
937 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
938 double f
= va_arg (ap
, double);
939 printf("[FLOAT4:%g]\n", (double) f
);
943 if ((info
->native_size
== sizeof(double)) &&
944 (info
->num_fields
== 1) &&
945 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
946 double f
= va_arg (ap
, double);
947 printf("[FLOAT8:%g]\n", f
);
951 size
= mono_type_size (type
, &align
);
958 for (j
= 0; p
&& j
< size
; j
++)
959 printf ("%02x,", p
[j
]);
963 printf ("[VALUETYPE]\n");
968 case MONO_TYPE_TYPEDBYREF
: {
969 guint8
*p
= va_arg (ap
, gpointer
);
971 size
= mono_type_size (type
, &align
);
978 for (j
= 0; p
&& j
< size
; j
++)
979 printf ("%02x,", p
[j
]);
983 printf ("[TYPEDBYREF]\n");
988 printf ("(unknown return type %x)",
989 mono_method_signature (method
)->ret
->type
);
992 ip
= ((gint64
) __builtin_return_address (0));
993 printf (" ip: %p\n", (gpointer
) ip
);
996 /*========================= End of Function ========================*/
998 /*------------------------------------------------------------------*/
1000 /* Name - catch_SIGILL */
1002 /* Function - Catch SIGILL as a result of testing for long */
1003 /* displacement facility. */
1005 /*------------------------------------------------------------------*/
1008 catch_SIGILL(int sigNo
, siginfo_t
*info
, void *act
) {
1014 /*========================= End of Function ========================*/
1016 /*------------------------------------------------------------------*/
1018 /* Name - mono_arch_cpu_init */
1020 /* Function - Perform CPU specific initialization to execute */
1023 /*------------------------------------------------------------------*/
1026 mono_arch_cpu_init (void)
1028 struct sigaction sa
,
1032 /*--------------------------------------*/
1033 /* Set default rounding mode for FP */
1034 /*--------------------------------------*/
1035 __asm__ ("SRNM\t%0\n\t"
1038 /*--------------------------------------*/
1039 /* Determine if we have long displace- */
1040 /* ment facility on this processor */
1041 /*--------------------------------------*/
1042 sa
.sa_sigaction
= catch_SIGILL
;
1043 sigemptyset (&sa
.sa_mask
);
1044 sa
.sa_flags
= SA_SIGINFO
;
1046 sigaction (SIGILL
, &sa
, oldSa
);
1048 /*--------------------------------------*/
1049 /* We test by executing the STY inst */
1050 /*--------------------------------------*/
1051 __asm__ ("LGHI\t0,1\n\t"
1053 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1054 : "=m" (has_ld
) : : "0", "1");
1056 sigaction (SIGILL
, oldSa
, NULL
);
1059 /*========================= End of Function ========================*/
1061 /*------------------------------------------------------------------*/
1063 /* Name - mono_arch_cpu_optimizazions */
1065 /* Function - Returns the optimizations supported on this CPU */
1067 /*------------------------------------------------------------------*/
1070 mono_arch_cpu_optimizazions (guint32
*exclude_mask
)
1074 /*----------------------------------------------------------*/
1075 /* No s390-specific optimizations yet */
1076 /*----------------------------------------------------------*/
1077 *exclude_mask
= MONO_OPT_INLINE
|MONO_OPT_LINEARS
;
1078 // *exclude_mask = MONO_OPT_INLINE;
1082 /*========================= End of Function ========================*/
1084 /*------------------------------------------------------------------*/
1090 /*------------------------------------------------------------------*/
1093 is_regsize_var (MonoType
*t
) {
1096 switch (mono_type_get_underlying_type (t
)->type
) {
1104 case MONO_TYPE_FNPTR
:
1106 case MONO_TYPE_OBJECT
:
1107 case MONO_TYPE_STRING
:
1108 case MONO_TYPE_CLASS
:
1109 case MONO_TYPE_SZARRAY
:
1110 case MONO_TYPE_ARRAY
:
1112 case MONO_TYPE_VALUETYPE
:
1113 if (t
->data
.klass
->enumtype
)
1114 return is_regsize_var (t
->data
.klass
->enum_basetype
);
1120 /*========================= End of Function ========================*/
1122 /*------------------------------------------------------------------*/
1124 /* Name - mono_arch_get_allocatable_int_vars */
1128 /*------------------------------------------------------------------*/
1131 mono_arch_get_allocatable_int_vars (MonoCompile
*cfg
)
1136 for (i
= 0; i
< cfg
->num_varinfo
; i
++) {
1137 MonoInst
*ins
= cfg
->varinfo
[i
];
1138 MonoMethodVar
*vmv
= MONO_VARINFO (cfg
, i
);
1141 if (vmv
->range
.first_use
.abs_pos
>= vmv
->range
.last_use
.abs_pos
)
1144 if (ins
->flags
& (MONO_INST_VOLATILE
|MONO_INST_INDIRECT
) ||
1145 (ins
->opcode
!= OP_LOCAL
&& ins
->opcode
!= OP_ARG
))
1148 /* we can only allocate 32 bit values */
1149 if (is_regsize_var (ins
->inst_vtype
)) {
1150 g_assert (MONO_VARINFO (cfg
, i
)->reg
== -1);
1151 g_assert (i
== vmv
->idx
);
1152 vars
= mono_varlist_insert_sorted (cfg
, vars
, vmv
, FALSE
);
1159 /*========================= End of Function ========================*/
1161 /*------------------------------------------------------------------*/
1163 /* Name - mono_arch_global_int_regs */
1165 /* Function - Return a list of usable integer registers. */
1167 /*------------------------------------------------------------------*/
1170 mono_arch_get_global_int_regs (MonoCompile
*cfg
)
1173 MonoMethodHeader
*header
;
1176 header
= mono_method_get_header (cfg
->method
);
1177 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1178 cfg
->frame_reg
= s390_r11
;
1180 for (i
= 8; i
< top
; ++i
) {
1181 if (cfg
->frame_reg
!= i
)
1182 regs
= g_list_prepend (regs
, GUINT_TO_POINTER (i
));
1188 /*========================= End of Function ========================*/
1190 /*------------------------------------------------------------------*/
1192 /* Name - mono_arch_flush_icache */
1194 /* Function - Flush the CPU icache. */
1196 /*------------------------------------------------------------------*/
1199 mono_arch_flush_icache (guint8
*code
, gint size
)
1203 /*========================= End of Function ========================*/
1205 /*------------------------------------------------------------------*/
1207 /* Name - add_general */
1209 /* Function - Determine code and stack size incremements for a */
1212 /*------------------------------------------------------------------*/
1215 add_general (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
)
1217 if (*gr
> S390_LAST_ARG_REG
) {
1218 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1219 ainfo
->offset
= sz
->stack_size
;
1220 ainfo
->reg
= STK_BASE
;
1221 ainfo
->regtype
= RegTypeBase
;
1222 sz
->stack_size
+= sizeof(long);
1223 sz
->local_size
+= sizeof(long);
1224 sz
->offStruct
+= sizeof(long);
1225 sz
->code_size
+= 12;
1233 /*========================= End of Function ========================*/
1235 /*------------------------------------------------------------------*/
1237 /* Name - add_stackParm */
1239 /* Function - Determine code and stack size incremements for a */
1242 /*------------------------------------------------------------------*/
1245 add_stackParm (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gint size
)
1247 if (*gr
> S390_LAST_ARG_REG
) {
1248 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1249 ainfo
->reg
= STK_BASE
;
1250 sz
->stack_size
+= sizeof(gpointer
);
1251 sz
->offStruct
+= sizeof(gpointer
);
1256 ainfo
->offset
= sz
->stack_size
;
1257 ainfo
->offparm
= sz
->offset
;
1258 sz
->offset
= S390_ALIGN(sz
->offset
+size
, sizeof(long));
1260 ainfo
->regtype
= RegTypeStructByAddr
;
1261 ainfo
->vtsize
= size
;
1262 sz
->parm_size
+= size
;
1265 /*========================= End of Function ========================*/
1267 /*------------------------------------------------------------------*/
1269 /* Name - add_float */
1271 /* Function - Determine code and stack size incremements for a */
1272 /* float parameter. */
1274 /*------------------------------------------------------------------*/
1277 add_float (guint
*fr
, size_data
*sz
, ArgInfo
*ainfo
)
1279 if ((*fr
) <= S390_LAST_FPARG_REG
) {
1280 ainfo
->regtype
= RegTypeFP
;
1286 ainfo
->offset
= sz
->stack_size
;
1287 ainfo
->reg
= STK_BASE
;
1288 ainfo
->regtype
= RegTypeBase
;
1290 sz
->stack_size
+= sizeof(double);
1291 sz
->local_size
+= sizeof(double);
1292 sz
->offStruct
+= sizeof(double);
1296 /*========================= End of Function ========================*/
1298 /*------------------------------------------------------------------*/
1300 /* Name - calculate_sizes */
1302 /* Function - Determine the amount of space required for code */
1303 /* and stack. In addition determine starting points */
1304 /* for stack-based parameters, and area for struct- */
1305 /* ures being returned on the stack. */
1307 /*------------------------------------------------------------------*/
1310 calculate_sizes (MonoMethodSignature
*sig
, size_data
*sz
,
1311 gboolean string_ctor
)
1313 guint i
, fr
, gr
, size
;
1314 int nParm
= sig
->hasthis
+ sig
->param_count
;
1315 guint32 simpletype
, align
;
1316 CallInfo
*cinfo
= g_malloc0 (sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1321 cinfo
->struct_ret
= 0;
1324 sz
->offStruct
= S390_MINIMAL_STACK_SIZE
;
1325 sz
->stack_size
= S390_MINIMAL_STACK_SIZE
;
1330 /*----------------------------------------------------------*/
1331 /* We determine the size of the return code/stack in case we*/
1332 /* need to reserve a register to be used to address a stack */
1333 /* area that the callee will use. */
1334 /*----------------------------------------------------------*/
1336 simpletype
= mono_type_get_underlying_type (sig
->ret
)->type
;
1338 switch (simpletype
) {
1339 case MONO_TYPE_BOOLEAN
:
1344 case MONO_TYPE_CHAR
:
1349 case MONO_TYPE_CLASS
:
1350 case MONO_TYPE_OBJECT
:
1351 case MONO_TYPE_SZARRAY
:
1352 case MONO_TYPE_ARRAY
:
1354 case MONO_TYPE_FNPTR
:
1355 case MONO_TYPE_STRING
:
1356 cinfo
->ret
.reg
= s390_r2
;
1361 cinfo
->ret
.reg
= s390_f0
;
1366 cinfo
->ret
.reg
= s390_r2
;
1369 case MONO_TYPE_GENERICINST
:
1370 if (!mono_type_generic_inst_is_valuetype (sig
->ret
)) {
1371 cinfo
->ret
.reg
= s390_r2
;
1376 case MONO_TYPE_VALUETYPE
: {
1377 MonoClass
*klass
= mono_class_from_mono_type (sig
->ret
);
1378 if (klass
->enumtype
) {
1379 simpletype
= klass
->enum_basetype
->type
;
1383 size
= mono_class_native_size (klass
, &align
);
1385 size
= mono_class_value_size (klass
, &align
);
1387 cinfo
->ret
.reg
= s390_r2
;
1388 cinfo
->struct_ret
= 1;
1389 cinfo
->ret
.size
= size
;
1390 cinfo
->ret
.vtsize
= size
;
1394 case MONO_TYPE_TYPEDBYREF
:
1395 size
= sizeof (MonoTypedRef
);
1396 cinfo
->ret
.reg
= s390_r2
;
1397 cinfo
->struct_ret
= 1;
1398 cinfo
->ret
.size
= size
;
1399 cinfo
->ret
.vtsize
= size
;
1402 case MONO_TYPE_VOID
:
1405 g_error ("Can't handle as return value 0x%x", sig
->ret
->type
);
1409 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1410 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1414 /*----------------------------------------------------------*/
1415 /* We determine the size of the parameter code and stack */
1416 /* requirements by checking the types and sizes of the */
1418 /*----------------------------------------------------------*/
1420 for (i
= 0; i
< sig
->param_count
; ++i
) {
1421 /*--------------------------------------------------*/
1422 /* Handle vararg type calls. All args are put on */
1424 /*--------------------------------------------------*/
1425 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1426 (i
== sig
->sentinelpos
)) {
1427 gr
= S390_LAST_ARG_REG
+ 1;
1428 add_general (&gr
, sz
, &cinfo
->sigCookie
);
1431 if (sig
->params
[i
]->byref
) {
1432 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1433 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1438 simpletype
= mono_type_get_underlying_type(sig
->params
[i
])->type
;
1439 cinfo
->args
[nParm
].type
= simpletype
;
1440 switch (simpletype
) {
1441 case MONO_TYPE_BOOLEAN
:
1444 cinfo
->args
[nParm
].size
= sizeof(char);
1445 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1450 case MONO_TYPE_CHAR
:
1451 cinfo
->args
[nParm
].size
= sizeof(short);
1452 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1457 cinfo
->args
[nParm
].size
= sizeof(int);
1458 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1464 case MONO_TYPE_FNPTR
:
1465 case MONO_TYPE_CLASS
:
1466 case MONO_TYPE_OBJECT
:
1467 case MONO_TYPE_STRING
:
1468 case MONO_TYPE_SZARRAY
:
1469 case MONO_TYPE_ARRAY
:
1470 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1471 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1476 cinfo
->args
[nParm
].size
= sizeof(long long);
1477 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1481 cinfo
->args
[nParm
].size
= sizeof(float);
1482 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1486 cinfo
->args
[nParm
].size
= sizeof(double);
1487 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1490 case MONO_TYPE_GENERICINST
:
1491 if (!mono_type_generic_inst_is_valuetype (sig
->params
[i
])) {
1492 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1493 add_general (&gr
, sz
, cinfo
->args
+nParm
);
1498 case MONO_TYPE_VALUETYPE
: {
1499 MonoMarshalType
*info
;
1500 MonoClass
*klass
= mono_class_from_mono_type (sig
->params
[i
]);
1502 size
= mono_class_native_size (klass
, &align
);
1504 size
= mono_class_value_size (klass
, &align
);
1506 info
= mono_marshal_load_type_info (klass
);
1508 if ((info
->native_size
== sizeof(float)) &&
1509 (info
->num_fields
== 1) &&
1510 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
1511 cinfo
->args
[nParm
].size
= sizeof(float);
1512 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1516 if ((info
->native_size
== sizeof(double)) &&
1517 (info
->num_fields
== 1) &&
1518 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
1519 cinfo
->args
[nParm
].size
= sizeof(double);
1520 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1524 cinfo
->args
[nParm
].vtsize
= 0;
1525 cinfo
->args
[nParm
].size
= 0;
1528 /*----------------------------------*/
1529 /* On S/390, structures of size 1, */
1530 /* 2, 4, and 8 bytes are passed in */
1531 /* (a) register(s). */
1532 /*----------------------------------*/
1538 add_general(&gr
, sz
, cinfo
->args
+nParm
);
1539 cinfo
->args
[nParm
].size
= size
;
1540 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1542 sz
->local_size
+= sizeof(long);
1545 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1550 case MONO_TYPE_TYPEDBYREF
: {
1551 int size
= sizeof (MonoTypedRef
);
1553 cinfo
->args
[nParm
].vtsize
= 0;
1554 cinfo
->args
[nParm
].size
= 0;
1557 /*----------------------------------*/
1558 /* On S/390, structures of size 1, */
1559 /* 2, 4, and 8 bytes are passed in */
1560 /* (a) register(s). */
1561 /*----------------------------------*/
1567 add_general(&gr
, sz
, cinfo
->args
+nParm
);
1568 cinfo
->args
[nParm
].size
= size
;
1569 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1571 sz
->local_size
+= sizeof(long);
1574 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1580 g_error ("Can't trampoline 0x%x", sig
->params
[i
]->type
);
1584 /*----------------------------------------------------------*/
1585 /* Handle the case where there are no implicit arguments */
1586 /*----------------------------------------------------------*/
1587 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1588 (sig
->param_count
== sig
->sentinelpos
)) {
1589 gr
= S390_LAST_ARG_REG
+ 1;
1590 add_general (&gr
, sz
, &cinfo
->sigCookie
);
1593 /*----------------------------------------------------------*/
1594 /* If we are passing a structure back then if it won't be */
1595 /* in a register(s) then we make room at the end of the */
1596 /* parameters that may have been placed on the stack */
1597 /*----------------------------------------------------------*/
1598 if (cinfo
->struct_ret
) {
1599 cinfo
->ret
.offset
= sz
->stack_size
;
1600 switch (cinfo
->ret
.size
) {
1608 sz
->stack_size
+= S390_ALIGN(cinfo
->ret
.size
, align
);
1613 sz
->stack_size
= sz
->stack_size
+ sz
->local_size
+ sz
->parm_size
+
1615 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1620 /*========================= End of Function ========================*/
1622 /*------------------------------------------------------------------*/
1624 /* Name - mono_arch_allocate_vars */
1626 /* Function - Set var information according to the calling */
1627 /* convention for S/390. The local var stuff should */
1628 /* most likely be split in another method. */
1630 /* Parameter - @m - Compile unit. */
1632 /*------------------------------------------------------------------*/
1635 mono_arch_allocate_vars (MonoCompile
*cfg
)
1637 MonoMethodSignature
*sig
;
1638 MonoMethodHeader
*header
;
1642 int iParm
, iVar
, offset
, size
, align
, curinst
;
1643 int frame_reg
= STK_BASE
;
1646 header
= mono_method_get_header (cfg
->method
);
1648 cfg
->flags
|= MONO_CFG_HAS_SPILLUP
;
1650 /*---------------------------------------------------------*/
1651 /* We use the frame register also for any method that has */
1652 /* filter clauses. This way, when the handlers are called, */
1653 /* the code will reference local variables using the frame */
1654 /* reg instead of the stack pointer: if we had to restore */
1655 /* the stack pointer, we'd corrupt the method frames that */
1656 /* are already on the stack (since filters get called */
1657 /* before stack unwinding happens) when the filter code */
1658 /* would call any method. */
1659 /*---------------------------------------------------------*/
1660 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1661 frame_reg
= s390_r11
;
1663 cfg
->frame_reg
= frame_reg
;
1665 if (frame_reg
!= STK_BASE
)
1666 cfg
->used_int_regs
|= 1 << frame_reg
;
1668 sig
= mono_method_signature (cfg
->method
);
1670 cinfo
= calculate_sizes (sig
, &sz
, sig
->pinvoke
);
1672 if (cinfo
->struct_ret
) {
1673 cfg
->ret
->opcode
= OP_REGVAR
;
1674 cfg
->ret
->inst_c0
= s390_r2
;
1676 switch (mono_type_get_underlying_type (sig
->ret
)->type
) {
1677 case MONO_TYPE_VOID
:
1680 cfg
->ret
->opcode
= OP_REGVAR
;
1681 cfg
->ret
->dreg
= s390_r2
;
1686 /*--------------------------------------------------------------*/
1687 /* local vars are at a positive offset from the stack pointer */
1688 /* also note that if the function uses alloca, we use s390_r11 */
1689 /* to point at the local variables. */
1690 /* add parameter area size for called functions */
1691 /*--------------------------------------------------------------*/
1692 offset
= (cfg
->param_area
+ S390_MINIMAL_STACK_SIZE
);
1693 cfg
->sig_cookie
= 0;
1695 if (cinfo
->struct_ret
) {
1697 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1698 inst
->inst_offset
= offset
;
1699 inst
->opcode
= OP_REGOFFSET
;
1700 inst
->inst_basereg
= frame_reg
;
1701 offset
+= sizeof(gpointer
);
1702 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1703 (!retFitsInReg (cinfo
->ret
.size
)))
1704 cfg
->sig_cookie
+= cinfo
->ret
.size
;
1708 inst
= cfg
->varinfo
[0];
1709 if (inst
->opcode
!= OP_REGVAR
) {
1710 inst
->opcode
= OP_REGOFFSET
;
1711 inst
->inst_basereg
= frame_reg
;
1712 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1713 inst
->inst_offset
= offset
;
1714 offset
+= sizeof (gpointer
);
1721 eArg
= sig
->param_count
+ sArg
;
1723 if (sig
->call_convention
== MONO_CALL_VARARG
)
1724 cfg
->sig_cookie
+= S390_MINIMAL_STACK_SIZE
;
1726 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1727 inst
= cfg
->varinfo
[curinst
];
1728 if (inst
->opcode
!= OP_REGVAR
) {
1729 switch (cinfo
->args
[iParm
].regtype
) {
1730 case RegTypeStructByAddr
:
1731 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1732 inst
->opcode
= OP_S390_LOADARG
;
1733 inst
->inst_basereg
= frame_reg
;
1734 offset
= S390_ALIGN(offset
, sizeof(long));
1735 inst
->inst_offset
= offset
;
1736 size
= abs(cinfo
->args
[iParm
].vtsize
);
1737 inst
->backend
.arg_info
= cinfo
->args
[iParm
].offset
;
1739 inst
->opcode
= OP_S390_ARGREG
;
1740 inst
->inst_basereg
= frame_reg
;
1741 size
= sizeof(gpointer
);
1742 offset
= S390_ALIGN(offset
, size
);
1743 inst
->inst_offset
= offset
;
1744 inst
->backend
.arg_info
= cinfo
->args
[iParm
].offset
;
1747 case RegTypeStructByVal
:
1748 inst
->opcode
= OP_S390_ARGPTR
;
1749 inst
->inst_basereg
= frame_reg
;
1750 size
= cinfo
->args
[iParm
].size
;
1751 offset
= S390_ALIGN(offset
, size
);
1752 inst
->inst_offset
= offset
;
1753 inst
->backend
.arg_info
= cinfo
->args
[iParm
].offset
;
1756 if (cinfo
->args
[iParm
].reg
!= STK_BASE
) {
1757 inst
->opcode
= OP_REGOFFSET
;
1758 inst
->inst_basereg
= frame_reg
;
1759 size
= (cinfo
->args
[iParm
].size
< 8
1762 offset
= S390_ALIGN(offset
, size
);
1763 inst
->inst_offset
= offset
;
1765 inst
->opcode
= OP_S390_STKARG
;
1766 inst
->inst_basereg
= frame_reg
;
1767 size
= ((cinfo
->args
[iParm
].size
< 8)
1768 ? 8 - cinfo
->args
[iParm
].size
1770 inst
->inst_offset
= cinfo
->args
[iParm
].offset
+
1772 inst
->backend
.arg_info
= 0;
1773 size
= sizeof(long);
1776 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1777 (cinfo
->args
[iParm
].regtype
!= RegTypeGeneral
) &&
1778 (iParm
< sig
->sentinelpos
))
1779 cfg
->sig_cookie
+= size
;
1786 curinst
= cfg
->locals_start
;
1787 for (iVar
= curinst
; iVar
< cfg
->num_varinfo
; ++iVar
) {
1788 inst
= cfg
->varinfo
[iVar
];
1789 if ((inst
->flags
& MONO_INST_IS_DEAD
) ||
1790 (inst
->opcode
== OP_REGVAR
))
1793 /*--------------------------------------------------*/
1794 /* inst->backend.is_pinvoke indicates native sized value types, */
1795 /* this is used by the pinvoke wrappers when they */
1796 /* call functions returning structure */
1797 /*--------------------------------------------------*/
1798 if (inst
->backend
.is_pinvoke
&& MONO_TYPE_ISSTRUCT (inst
->inst_vtype
))
1799 size
= mono_class_native_size (mono_class_from_mono_type(inst
->inst_vtype
), &align
);
1801 size
= mono_type_size (inst
->inst_vtype
, &align
);
1803 offset
= S390_ALIGN(offset
, align
);
1804 inst
->inst_offset
= offset
;
1805 inst
->opcode
= OP_REGOFFSET
;
1806 inst
->inst_basereg
= frame_reg
;
1808 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
1809 iVar
, inst
->inst_offset
, size
));
1812 /*------------------------------------------------------*/
1813 /* Allow space for the trace method stack area if needed*/
1814 /*------------------------------------------------------*/
1815 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (cfg
->method
))
1816 offset
+= S390_TRACE_STACK_SIZE
;
1818 /*------------------------------------------------------*/
1819 /* Reserve space to save LMF and caller saved registers */
1820 /*------------------------------------------------------*/
1821 if (cfg
->method
->save_lmf
)
1822 offset
+= sizeof (MonoLMF
);
1824 /*------------------------------------------------------*/
1825 /* align the offset */
1826 /*------------------------------------------------------*/
1827 cfg
->stack_offset
= S390_ALIGN(offset
, S390_STACK_ALIGNMENT
);
1831 /*========================= End of Function ========================*/
1833 /*------------------------------------------------------------------*/
1835 /* Name - mono_arch_call_opcode */
1837 /* Function - Take the arguments and generate the arch-specific */
1838 /* instructions to properly call the function. This */
1839 /* includes pushing, moving argments to the correct */
1842 /*------------------------------------------------------------------*/
1845 mono_arch_call_opcode (MonoCompile
*cfg
, MonoBasicBlock
* bb
,
1846 MonoCallInst
*call
, int is_virtual
) {
1848 MonoCallArgParm
*arg
;
1849 MonoMethodSignature
*sig
;
1850 int i
, n
, lParamArea
;
1855 sig
= call
->signature
;
1856 n
= sig
->param_count
+ sig
->hasthis
;
1857 DEBUG (g_print ("Call requires: %d parameters\n",n
));
1859 cinfo
= calculate_sizes (sig
, &sz
, sig
->pinvoke
);
1861 call
->stack_usage
= MAX(sz
.stack_size
, call
->stack_usage
);
1862 lParamArea
= MAX((call
->stack_usage
- S390_MINIMAL_STACK_SIZE
- sz
.parm_size
), 0);
1863 cfg
->param_area
= MAX (((signed) cfg
->param_area
), lParamArea
);
1864 cfg
->flags
|= MONO_CFG_HAS_CALLS
;
1866 if (cinfo
->struct_ret
)
1867 call
->used_iregs
|= 1 << cinfo
->ret
.reg
;
1869 for (i
= 0; i
< n
; ++i
) {
1870 ainfo
= cinfo
->args
+ i
;
1872 if (!(sig
->pinvoke
) &&
1873 (sig
->call_convention
== MONO_CALL_VARARG
) &&
1874 (i
== sig
->sentinelpos
)) {
1875 emit_sig_cookie (cfg
, call
, cinfo
, ainfo
->size
);
1878 if (is_virtual
&& i
== 0) {
1879 /* the argument will be attached to the call instrucion */
1880 in
= call
->args
[i
];
1881 call
->used_iregs
|= 1 << ainfo
->reg
;
1883 MONO_INST_NEW_CALL_ARG (cfg
, arg
, OP_OUTARG
);
1884 in
= call
->args
[i
];
1885 arg
->ins
.cil_code
= in
->cil_code
;
1886 arg
->ins
.inst_left
= in
;
1887 arg
->ins
.type
= in
->type
;
1889 /* prepend, we'll need to reverse them later */
1890 arg
->ins
.next
= call
->out_args
;
1891 call
->out_args
= (MonoInst
*) arg
;
1892 arg
->ins
.inst_right
= (MonoInst
*) call
;
1893 if (ainfo
->regtype
== RegTypeGeneral
) {
1894 arg
->ins
.backend
.reg3
= ainfo
->reg
;
1895 call
->used_iregs
|= 1 << ainfo
->reg
;
1896 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
1897 call
->used_iregs
|= 1 << ainfo
->reg
;
1898 arg
->ins
.sreg1
= ainfo
->reg
;
1899 arg
->ins
.opcode
= OP_OUTARG_VT
;
1900 arg
->size
= -ainfo
->vtsize
;
1901 arg
->offset
= ainfo
->offset
;
1902 arg
->offPrm
= ainfo
->offparm
+ sz
.offStruct
;
1903 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
1904 if (ainfo
->reg
!= STK_BASE
)
1905 call
->used_iregs
|= 1 << ainfo
->reg
;
1906 arg
->ins
.sreg1
= ainfo
->reg
;
1907 arg
->ins
.opcode
= OP_OUTARG_VT
;
1908 arg
->size
= ainfo
->size
;
1909 arg
->offset
= ainfo
->offset
;
1910 arg
->offPrm
= ainfo
->offparm
+ sz
.offStruct
;
1911 } else if (ainfo
->regtype
== RegTypeBase
) {
1912 arg
->ins
.opcode
= OP_OUTARG_MEMBASE
;
1913 arg
->ins
.sreg1
= ainfo
->reg
;
1914 arg
->size
= ainfo
->size
;
1915 arg
->offset
= ainfo
->offset
;
1916 call
->used_iregs
|= 1 << ainfo
->reg
;
1917 } else if (ainfo
->regtype
== RegTypeFP
) {
1918 arg
->ins
.backend
.reg3
= ainfo
->reg
;
1919 call
->used_fregs
|= 1 << ainfo
->reg
;
1920 if (ainfo
->size
== 4)
1921 arg
->ins
.opcode
= OP_OUTARG_R4
;
1923 arg
->ins
.opcode
= OP_OUTARG_R8
;
1925 g_assert_not_reached ();
1931 * Handle the case where there are no implicit arguments
1933 if (!(sig
->pinvoke
) &&
1934 (sig
->call_convention
== MONO_CALL_VARARG
) &&
1935 (n
== sig
->sentinelpos
)) {
1936 emit_sig_cookie (cfg
, call
, cinfo
, sizeof(MonoType
*));
1940 * Reverse the call->out_args list.
1943 MonoInst
*prev
= NULL
, *list
= call
->out_args
, *next
;
1950 call
->out_args
= prev
;
1957 /*========================= End of Function ========================*/
1959 /*------------------------------------------------------------------*/
1961 /* Name - emit_sig_cookie. */
1963 /* Function - For variable length parameter lists construct a */
1964 /* signature cookie and emit it. */
1966 /*------------------------------------------------------------------*/
1969 emit_sig_cookie (MonoCompile
*cfg
, MonoCallInst
*call
,
1970 CallInfo
*cinfo
, int argSize
)
1972 MonoCallArgParm
*arg
;
1973 MonoMethodSignature
*tmpSig
;
1976 cfg
->disable_aot
= TRUE
;
1978 /*----------------------------------------------------------*/
1979 /* mono_ArgIterator_Setup assumes the signature cookie is */
1980 /* passed first and all the arguments which were before it */
1981 /* passed on the stack after the signature. So compensate */
1982 /* by passing a different signature. */
1983 /*----------------------------------------------------------*/
1984 tmpSig
= mono_metadata_signature_dup (call
->signature
);
1985 tmpSig
->param_count
-= call
->signature
->sentinelpos
;
1986 tmpSig
->sentinelpos
= 0;
1987 if (tmpSig
->param_count
> 0)
1988 memcpy (tmpSig
->params
,
1989 call
->signature
->params
+ call
->signature
->sentinelpos
,
1990 tmpSig
->param_count
* sizeof(MonoType
*));
1992 MONO_INST_NEW (cfg
, sigArg
, OP_ICONST
);
1993 sigArg
->inst_p0
= tmpSig
;
1995 MONO_INST_NEW_CALL_ARG (cfg
, arg
, OP_OUTARG_MEMBASE
);
1996 arg
->ins
.inst_left
= sigArg
;
1997 arg
->ins
.inst_right
= (MonoInst
*) call
;
1998 arg
->size
= argSize
;
1999 arg
->offset
= cinfo
->sigCookie
.offset
;
2001 /* prepend, we'll need to reverse them later */
2002 arg
->ins
.next
= call
->out_args
;
2003 call
->out_args
= (MonoInst
*) arg
;
2006 /*========================= End of Function ========================*/
2008 /*------------------------------------------------------------------*/
2010 /* Name - mono_arch_instrument_mem_needs */
2012 /* Function - Allow tracing to work with this interface (with */
2013 /* an optional argument). */
2015 /*------------------------------------------------------------------*/
2018 mono_arch_instrument_mem_needs (MonoMethod
*method
, int *stack
, int *code
)
2020 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2022 /* split prolog-epilog requirements? */
2023 *code
= 50; /* max bytes needed: check this number */
2026 /*========================= End of Function ========================*/
2028 /*------------------------------------------------------------------*/
2030 /* Name - mono_arch_instrument_prolog */
2032 /* Function - Create an "instrumented" prolog. */
2034 /*------------------------------------------------------------------*/
2037 mono_arch_instrument_prolog (MonoCompile
*cfg
, void *func
, void *p
,
2038 gboolean enable_arguments
)
2045 parmOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2046 if (cfg
->method
->save_lmf
)
2047 parmOffset
-= sizeof(MonoLMF
);
2048 fpOffset
= parmOffset
+ (5*sizeof(gpointer
));
2049 if ((!has_ld
) && (fpOffset
> 4096)) {
2050 s390_lgr (code
, s390_r12
, STK_BASE
);
2052 while (fpOffset
> 4096) {
2053 s390_aghi (code
, baseReg
, 4096);
2061 s390_stmg (code
, s390_r2
, s390_r6
, STK_BASE
, parmOffset
);
2063 s390_stdy (code
, s390_f0
, 0, STK_BASE
, fpOffset
);
2064 s390_stdy (code
, s390_f2
, 0, STK_BASE
, fpOffset
+sizeof(gdouble
));
2065 s390_stdy (code
, s390_f4
, 0, STK_BASE
, fpOffset
+2*sizeof(gdouble
));
2066 s390_stdy (code
, s390_f6
, 0, STK_BASE
, fpOffset
+3*sizeof(gdouble
));
2068 s390_std (code
, s390_f0
, 0, baseReg
, fpOffset
);
2069 s390_std (code
, s390_f2
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2070 s390_std (code
, s390_f4
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2071 s390_std (code
, s390_f6
, 0, baseReg
, fpOffset
+3*sizeof(gdouble
));
2073 s390_basr (code
, s390_r13
, 0);
2075 s390_llong(code
, cfg
->method
);
2076 s390_llong(code
, func
);
2077 s390_lg (code
, s390_r2
, 0, s390_r13
, 4);
2079 s390_lay (code
, s390_r3
, 0, STK_BASE
, parmOffset
);
2081 s390_la (code
, s390_r3
, 0, baseReg
, parmOffset
);
2082 s390_lgr (code
, s390_r4
, STK_BASE
);
2083 s390_aghi (code
, s390_r4
, cfg
->stack_usage
);
2084 s390_lg (code
, s390_r1
, 0, s390_r13
, 12);
2085 s390_basr (code
, s390_r14
, s390_r1
);
2087 s390_ldy (code
, s390_f6
, 0, STK_BASE
, fpOffset
+3*sizeof(gdouble
));
2088 s390_ldy (code
, s390_f4
, 0, STK_BASE
, fpOffset
+2*sizeof(gdouble
));
2089 s390_ldy (code
, s390_f2
, 0, STK_BASE
, fpOffset
+sizeof(gdouble
));
2090 s390_ldy (code
, s390_f0
, 0, STK_BASE
, fpOffset
);
2092 s390_ld (code
, s390_f6
, 0, baseReg
, fpOffset
+3*sizeof(gdouble
));
2093 s390_ld (code
, s390_f4
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2094 s390_ld (code
, s390_f2
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2095 s390_ld (code
, s390_f0
, 0, baseReg
, fpOffset
);
2097 s390_lmg (code
, s390_r2
, s390_r6
, STK_BASE
, parmOffset
);
2102 /*========================= End of Function ========================*/
2104 /*------------------------------------------------------------------*/
2106 /* Name - mono_arch_instrument_epilog */
2108 /* Function - Create an epilog that will handle the returned */
2109 /* values used in instrumentation. */
2111 /*------------------------------------------------------------------*/
2114 mono_arch_instrument_epilog (MonoCompile
*cfg
, void *func
, void *p
, gboolean enable_arguments
)
2117 int save_mode
= SAVE_NONE
,
2119 MonoMethod
*method
= cfg
->method
;
2120 int rtype
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
)->type
;
2122 saveOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2123 if (method
->save_lmf
)
2124 saveOffset
-= sizeof(MonoLMF
);
2128 case MONO_TYPE_VOID
:
2129 /* special case string .ctor icall */
2130 if (strcmp (".ctor", method
->name
) && method
->klass
== mono_defaults
.string_class
)
2131 save_mode
= SAVE_ONE
;
2133 save_mode
= SAVE_NONE
;
2137 save_mode
= SAVE_ONE
;
2140 save_mode
= SAVE_R4
;
2143 save_mode
= SAVE_R8
;
2145 case MONO_TYPE_VALUETYPE
:
2146 if (mono_method_signature (method
)->ret
->data
.klass
->enumtype
) {
2147 rtype
= mono_method_signature (method
)->ret
->data
.klass
->enum_basetype
->type
;
2150 save_mode
= SAVE_STRUCT
;
2153 save_mode
= SAVE_ONE
;
2157 switch (save_mode
) {
2159 s390_stg (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2160 if (enable_arguments
) {
2161 s390_lgr (code
, s390_r3
, s390_r2
);
2165 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2166 if (enable_arguments
) {
2167 s390_ldebr (code
, s390_f0
, s390_f0
);
2171 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2174 s390_stg (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2175 if (enable_arguments
) {
2176 s390_lg (code
, s390_r3
, 0, cfg
->frame_reg
,
2177 S390_MINIMAL_STACK_SIZE
+cfg
->param_area
);
2185 s390_basr (code
, s390_r13
, 0);
2187 s390_llong(code
, cfg
->method
);
2188 s390_llong(code
, func
);
2189 s390_lg (code
, s390_r2
, 0, s390_r13
, 4);
2190 s390_lg (code
, s390_r1
, 0, s390_r13
, 12);
2191 s390_basr (code
, s390_r14
, s390_r1
);
2193 switch (save_mode
) {
2195 s390_lg (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2199 s390_ld (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2202 s390_lg (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2212 /*========================= End of Function ========================*/
2214 /*------------------------------------------------------------------*/
2216 /* Name - peephole_pass */
2218 /* Function - Form a peephole pass at the code looking for */
2219 /* simple optimizations. */
2221 /*------------------------------------------------------------------*/
2224 peephole_pass (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2226 MonoInst
*ins
, *last_ins
= NULL
;
2231 switch (ins
->opcode
) {
2233 /* remove unnecessary multiplication with 1 */
2234 if (ins
->inst_imm
== 1) {
2235 if (ins
->dreg
!= ins
->sreg1
) {
2236 ins
->opcode
= OP_MOVE
;
2238 last_ins
->next
= ins
->next
;
2244 case OP_LOAD_MEMBASE
:
2245 case OP_LOADI4_MEMBASE
:
2247 * OP_STORE_MEMBASE_REG reg, offset(basereg)
2248 * OP_LOAD_MEMBASE offset(basereg), reg
2250 if (last_ins
&& (last_ins
->opcode
== OP_STOREI4_MEMBASE_REG
2251 || last_ins
->opcode
== OP_STORE_MEMBASE_REG
) &&
2252 ins
->inst_basereg
== last_ins
->inst_destbasereg
&&
2253 ins
->inst_offset
== last_ins
->inst_offset
) {
2254 if (ins
->dreg
== last_ins
->sreg1
) {
2255 last_ins
->next
= ins
->next
;
2259 ins
->opcode
= OP_MOVE
;
2260 ins
->sreg1
= last_ins
->sreg1
;
2264 * Note: reg1 must be different from the basereg in the second load
2265 * OP_LOAD_MEMBASE offset(basereg), reg1
2266 * OP_LOAD_MEMBASE offset(basereg), reg2
2268 * OP_LOAD_MEMBASE offset(basereg), reg1
2269 * OP_MOVE reg1, reg2
2271 } if (last_ins
&& (last_ins
->opcode
== OP_LOADI4_MEMBASE
2272 || last_ins
->opcode
== OP_LOAD_MEMBASE
) &&
2273 ins
->inst_basereg
!= last_ins
->dreg
&&
2274 ins
->inst_basereg
== last_ins
->inst_basereg
&&
2275 ins
->inst_offset
== last_ins
->inst_offset
) {
2277 if (ins
->dreg
== last_ins
->dreg
) {
2278 last_ins
->next
= ins
->next
;
2282 ins
->opcode
= OP_MOVE
;
2283 ins
->sreg1
= last_ins
->dreg
;
2288 case OP_LOADU1_MEMBASE
:
2289 case OP_LOADI1_MEMBASE
:
2290 if (last_ins
&& (last_ins
->opcode
== OP_STOREI1_MEMBASE_REG
) &&
2291 ins
->inst_basereg
== last_ins
->inst_destbasereg
&&
2292 ins
->inst_offset
== last_ins
->inst_offset
) {
2293 ins
->opcode
= (ins
->opcode
== OP_LOADI1_MEMBASE
) ? CEE_CONV_I1
: CEE_CONV_U1
;
2294 ins
->sreg1
= last_ins
->sreg1
;
2297 case OP_LOADU2_MEMBASE
:
2298 case OP_LOADI2_MEMBASE
:
2299 if (last_ins
&& (last_ins
->opcode
== OP_STOREI2_MEMBASE_REG
) &&
2300 ins
->inst_basereg
== last_ins
->inst_destbasereg
&&
2301 ins
->inst_offset
== last_ins
->inst_offset
) {
2302 ins
->opcode
= (ins
->opcode
== OP_LOADI2_MEMBASE
) ? CEE_CONV_I2
: CEE_CONV_U2
;
2303 ins
->sreg1
= last_ins
->sreg1
;
2312 if (ins
->dreg
== ins
->sreg1
) {
2314 last_ins
->next
= ins
->next
;
2319 * OP_MOVE sreg, dreg
2320 * OP_MOVE dreg, sreg
2322 if (last_ins
&& last_ins
->opcode
== OP_MOVE
&&
2323 ins
->sreg1
== last_ins
->dreg
&&
2324 ins
->dreg
== last_ins
->sreg1
) {
2325 last_ins
->next
= ins
->next
;
2334 bb
->last_ins
= last_ins
;
2337 /*========================= End of Function ========================*/
2339 /*------------------------------------------------------------------*/
2341 /* Name - mono_arch_local_regalloc. */
2343 /* Function - We first scan the list of instructions and we */
2344 /* save the liveness information of each register */
2345 /* (when the register is first used, when its value */
2346 /* is set etc.). We also reverse the list of instr- */
2347 /* uctions (in the InstList list) because assigning */
2348 /* registers backwards allows for more tricks to be */
2351 /*------------------------------------------------------------------*/
2354 mono_arch_local_regalloc (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2356 mono_local_regalloc(cfg
, bb
);
2359 /*========================= End of Function ========================*/
2361 /*------------------------------------------------------------------*/
2363 /* Name - emit_float_to_int */
2365 /* Function - Create instructions which will convert a floating */
2366 /* point value to integer. */
2368 /*------------------------------------------------------------------*/
2371 emit_float_to_int (MonoCompile
*cfg
, guchar
*code
, int dreg
, int sreg
, int size
, gboolean is_signed
)
2373 /* sreg is a float, dreg is an integer reg. */
2375 s390_cfdbr (code
, dreg
, 5, sreg
);
2378 s390_lghi (code
, s390_r0
, 0);
2379 s390_lghi (code
, s390_r13
, 0xff);
2380 s390_ltgr (code
, dreg
, dreg
);
2382 s390_lghi (code
, s390_r0
, 0x80);
2383 s390_ngr (code
, dreg
, s390_r13
);
2384 s390_ogr (code
, dreg
, s390_r0
);
2389 s390_basr (code
, s390_r13
, 0);
2391 s390_llong (code
, 0x41e0000000000000);
2392 s390_llong (code
, 0x41f0000000000000);
2393 s390_ldr (code
, s390_f15
, sreg
);
2394 s390_cdb (code
, s390_f15
, 0, s390_r13
, 4);
2395 s390_jl (code
, 0); CODEPTR (code
, o
[0]);
2396 s390_sdb (code
, s390_f15
, 0, s390_r13
, 12);
2397 s390_cfdbr (code
, dreg
, 7, s390_f15
);
2399 PTRSLOT (code
, o
[0]);
2400 s390_cfdbr (code
, dreg
, 5, sreg
);
2403 s390_lghi (code
, s390_r0
, 0xff);
2404 s390_ngr (code
, dreg
, s390_r0
);
2407 s390_lghi (code
, s390_r0
, -1);
2408 s390_srlg (code
, s390_r0
, s390_r0
, 0, 16);
2409 s390_ngr (code
, dreg
, s390_r0
);
2416 /*========================= End of Function ========================*/
2418 /*------------------------------------------------------------------*/
2420 /* Name - mono_arch_output_basic_block */
2422 /* Function - Perform the "real" work of emitting instructions */
2423 /* that will do the work of in the basic block. */
2425 /*------------------------------------------------------------------*/
2428 mono_arch_output_basic_block (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2433 guint8
*code
= cfg
->native_code
+ cfg
->code_len
;
2434 MonoInst
*last_ins
= NULL
;
2435 guint last_offset
= 0;
2436 int max_len
, cpos
, src2
;
2438 if (cfg
->opt
& MONO_OPT_PEEPHOLE
)
2439 peephole_pass (cfg
, bb
);
2441 /* we don't align basic blocks of loops on s390 */
2443 if (cfg
->verbose_level
> 2)
2444 g_print ("Basic block %d starting at offset 0x%x\n", bb
->block_num
, bb
->native_offset
);
2446 cpos
= bb
->max_offset
;
2448 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
) {
2449 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2450 //g_assert (!mono_compile_aot);
2453 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2454 /* this is not thread save, but good enough */
2455 /* fixme: howto handle overflows? */
2456 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2461 offset
= code
- cfg
->native_code
;
2463 max_len
= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
2465 if (offset
> (cfg
->code_size
- max_len
- 16)) {
2466 cfg
->code_size
*= 2;
2467 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
2468 code
= cfg
->native_code
+ offset
;
2471 mono_debug_record_line_number (cfg
, ins
, offset
);
2473 switch (ins
->opcode
) {
2474 case OP_STOREI1_MEMBASE_IMM
: {
2475 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2476 S390_LONG (code
, stcy
, stc
, s390_r0
, 0,
2477 ins
->inst_destbasereg
, ins
->inst_offset
);
2480 case OP_STOREI2_MEMBASE_IMM
: {
2481 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2482 S390_LONG (code
, sthy
, sth
, s390_r0
, 0,
2483 ins
->inst_destbasereg
, ins
->inst_offset
);
2486 case OP_STOREI4_MEMBASE_IMM
: {
2487 if (s390_is_imm16(ins
->inst_imm
)) {
2488 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2490 s390_basr (code
, s390_r13
, 0);
2492 s390_llong(code
, ins
->inst_imm
);
2493 s390_lg (code
, s390_r0
, 0, s390_r13
, 4);
2495 S390_LONG (code
, sty
, st
, s390_r0
, 0,
2496 ins
->inst_destbasereg
, ins
->inst_offset
);
2499 case OP_STORE_MEMBASE_IMM
:
2500 case OP_STOREI8_MEMBASE_IMM
: {
2501 if (s390_is_imm16(ins
->inst_imm
)) {
2502 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2504 s390_basr (code
, s390_r13
, 0);
2506 s390_llong(code
, ins
->inst_imm
);
2507 s390_lg (code
, s390_r0
, 0, s390_r13
, 4);
2509 S390_LONG (code
, stg
, stg
, s390_r0
, 0,
2510 ins
->inst_destbasereg
, ins
->inst_offset
);
2513 case OP_STOREI1_MEMBASE_REG
: {
2514 S390_LONG (code
, stcy
, stc
, ins
->sreg1
, 0,
2515 ins
->inst_destbasereg
, ins
->inst_offset
);
2518 case OP_STOREI2_MEMBASE_REG
: {
2519 S390_LONG (code
, sthy
, sth
, ins
->sreg1
, 0,
2520 ins
->inst_destbasereg
, ins
->inst_offset
);
2523 case OP_STOREI4_MEMBASE_REG
: {
2524 S390_LONG (code
, sty
, st
, ins
->sreg1
, 0,
2525 ins
->inst_destbasereg
, ins
->inst_offset
);
2528 case OP_STORE_MEMBASE_REG
:
2529 case OP_STOREI8_MEMBASE_REG
: {
2530 S390_LONG (code
, stg
, stg
, ins
->sreg1
, 0,
2531 ins
->inst_destbasereg
, ins
->inst_offset
);
2535 case CEE_LDIND_I4
: {
2536 s390_basr (code
, s390_r13
, 0);
2538 s390_llong(code
, ins
->inst_p0
);
2539 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
2540 s390_lgf (code
, ins
->dreg
, 0, s390_r13
, 0);
2543 case CEE_LDIND_U4
: {
2544 s390_basr (code
, s390_r13
, 0);
2546 s390_llong(code
, ins
->inst_p0
);
2547 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
2548 s390_llgf (code
, ins
->dreg
, 0, s390_r13
, 0);
2552 g_assert_not_reached ();
2554 case OP_LOAD_MEMBASE
:
2555 case OP_LOADI8_MEMBASE
: {
2556 S390_LONG (code
, lg
, lg
, ins
->dreg
, 0,
2557 ins
->inst_basereg
, ins
->inst_offset
);
2560 case OP_LOADI4_MEMBASE
: {
2561 S390_LONG (code
, lgf
, lgf
, ins
->dreg
, 0,
2562 ins
->inst_basereg
, ins
->inst_offset
);
2565 case OP_LOADU4_MEMBASE
: {
2566 S390_LONG (code
, llgf
, llgf
, ins
->dreg
, 0,
2567 ins
->inst_basereg
, ins
->inst_offset
);
2570 case OP_LOADU1_MEMBASE
: {
2571 S390_LONG (code
, llgc
, llgc
, ins
->dreg
, 0,
2572 ins
->inst_basereg
, ins
->inst_offset
);
2575 case OP_LOADI1_MEMBASE
: {
2576 S390_LONG (code
, lgb
, lgb
, ins
->dreg
, 0,
2577 ins
->inst_basereg
, ins
->inst_offset
);
2580 case OP_LOADU2_MEMBASE
: {
2581 S390_LONG (code
, llgh
, llgh
, ins
->dreg
, 0,
2582 ins
->inst_basereg
, ins
->inst_offset
);
2585 case OP_LOADI2_MEMBASE
: {
2586 S390_LONG (code
, lgh
, lgh
, ins
->dreg
, 0,
2587 ins
->inst_basereg
, ins
->inst_offset
);
2591 s390_lghi (code
, s390_r0
, 0x80);
2592 if (ins
->dreg
!= ins
->sreg1
) {
2593 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2595 s390_ngr (code
, s390_r0
, ins
->sreg1
);
2597 s390_lghi (code
, s390_r13
, -1);
2598 s390_sllg (code
, s390_r13
, s390_r13
, 0, 8);
2599 s390_ogr (code
, ins
->dreg
, s390_r13
);
2603 s390_lghi (code
, s390_r0
, 0x80);
2604 s390_sllg (code
, s390_r0
, s390_r0
, 0, 8);
2605 if (ins
->dreg
!= ins
->sreg1
) {
2606 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2608 s390_ngr (code
, s390_r0
, ins
->sreg1
);
2610 s390_lghi (code
, s390_r13
, -1);
2611 s390_sllg (code
, s390_r13
, s390_r13
, 0, 16);
2612 s390_ogr (code
, ins
->dreg
, s390_r13
);
2616 s390_lghi (code
, s390_r0
, 0xff);
2617 if (ins
->dreg
!= ins
->sreg1
) {
2618 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2620 s390_ngr (code
, ins
->dreg
, s390_r0
);
2624 s390_lghi (code
, s390_r0
, -1);
2625 s390_sllg (code
, s390_r0
, s390_r0
, 0, 16);
2626 s390_srlg (code
, s390_r0
, s390_r0
, 0, 16);
2627 if (ins
->dreg
!= ins
->sreg1
) {
2628 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2630 s390_ngr (code
, ins
->dreg
, s390_r0
);
2636 (opcode_to_cond(ins
->next
->opcode
) >= CMP_LE_UN
))
2637 s390_clgr (code
, ins
->sreg1
, ins
->sreg2
);
2639 s390_cgr (code
, ins
->sreg1
, ins
->sreg2
);
2642 case OP_COMPARE_IMM
: {
2643 if (s390_is_imm16 (ins
->inst_imm
)) {
2644 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2646 (opcode_to_cond(ins
->next
->opcode
) >= CMP_LE_UN
))
2647 s390_clgr (code
, ins
->sreg1
, s390_r0
);
2649 s390_cgr (code
, ins
->sreg1
, s390_r0
);
2652 s390_basr (code
, s390_r13
, 0);
2654 s390_llong(code
, ins
->inst_imm
);
2656 (opcode_to_cond(ins
->next
->opcode
) >= CMP_LE_UN
))
2657 s390_clg (code
, ins
->sreg1
, 0, s390_r13
, 4);
2659 s390_cg (code
, ins
->sreg1
, 0, s390_r13
, 4);
2665 (opcode_to_cond(ins
->next
->opcode
) >= CMP_LE_UN
))
2666 s390_clr (code
, ins
->sreg1
, ins
->sreg2
);
2668 s390_cr (code
, ins
->sreg1
, ins
->sreg2
);
2671 case OP_ICOMPARE_IMM
: {
2672 if (s390_is_imm16 (ins
->inst_imm
)) {
2673 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2675 (opcode_to_cond(ins
->next
->opcode
) >= CMP_LE_UN
))
2676 s390_clr (code
, ins
->sreg1
, s390_r0
);
2678 s390_cr (code
, ins
->sreg1
, s390_r0
);
2681 s390_basr (code
, s390_r13
, 0);
2683 s390_word (code
, ins
->inst_imm
);
2685 (opcode_to_cond(ins
->next
->opcode
) >= CMP_LE_UN
))
2686 s390_cl (code
, ins
->sreg1
, 0, s390_r13
, 4);
2688 s390_c (code
, ins
->sreg1
, 0, s390_r13
, 4);
2693 s390_basr (code
, s390_r13
, 0);
2695 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
,
2697 s390_llong (code
, mono_arch_break
);
2698 s390_lg (code
, s390_r14
, 0, s390_r13
, 4);
2699 s390_basr (code
, s390_r14
, s390_r14
);
2704 s390_algr (code
, ins
->dreg
, src2
);
2709 s390_agr (code
, ins
->dreg
, src2
);
2714 s390_alcgr (code
, ins
->dreg
, src2
);
2718 if (ins
->dreg
!= ins
->sreg1
) {
2719 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2721 if (s390_is_imm16 (ins
->inst_imm
)) {
2722 s390_aghi (code
, ins
->dreg
, ins
->inst_imm
);
2724 s390_basr (code
, s390_r13
, 0);
2726 s390_llong(code
, ins
->inst_imm
);
2727 s390_ag (code
, ins
->dreg
, 0, s390_r13
, 4);
2732 if (ins
->dreg
!= ins
->sreg1
) {
2733 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2735 if (s390_is_imm16 (ins
->inst_imm
)) {
2736 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2737 s390_alcgr (code
, ins
->dreg
, s390_r0
);
2739 s390_basr (code
, s390_r13
, 0);
2741 s390_llong (code
, ins
->inst_imm
);
2742 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
2743 s390_alcgr (code
, ins
->dreg
, s390_r13
);
2749 s390_agr (code
, ins
->dreg
, src2
);
2750 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
2753 case OP_LADD_OVF_UN
: {
2755 s390_algr (code
, ins
->dreg
, src2
);
2756 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
2759 case OP_ADD_OVF_CARRY
: {
2761 s390_lghi (code
, s390_r0
, 0);
2762 s390_lgr (code
, s390_r1
, s390_r0
);
2763 s390_alcgr (code
, s390_r0
, s390_r1
);
2764 s390_agr (code
, ins
->dreg
, src2
);
2765 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
2766 s390_agr (code
, ins
->dreg
, s390_r0
);
2767 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
2770 case OP_ADD_OVF_UN_CARRY
: {
2772 s390_alcgr (code
, ins
->dreg
, src2
);
2773 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
2778 s390_slgr (code
, ins
->dreg
, src2
);
2783 s390_sgr (code
, ins
->dreg
, src2
);
2788 s390_slbgr(code
, ins
->dreg
, src2
);
2792 if (ins
->dreg
!= ins
->sreg1
) {
2793 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2795 if (s390_is_imm16 (-ins
->inst_imm
)) {
2796 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2797 s390_slgr (code
, ins
->dreg
, s390_r0
);
2799 s390_basr (code
, s390_r13
, 0);
2801 s390_llong(code
, ins
->inst_imm
);
2802 s390_slg (code
, ins
->dreg
, 0, s390_r13
, 4);
2807 if (ins
->dreg
!= ins
->sreg1
) {
2808 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2810 if (s390_is_imm16 (-ins
->inst_imm
)) {
2811 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2812 s390_slbgr (code
, ins
->dreg
, s390_r0
);
2814 s390_basr (code
, s390_r13
, 0);
2816 s390_llong(code
, ins
->inst_imm
);
2817 s390_slbg (code
, ins
->dreg
, 0, s390_r13
, 4);
2823 s390_sgr (code
, ins
->dreg
, src2
);
2824 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
2827 case OP_LSUB_OVF_UN
: {
2829 s390_slgr (code
, ins
->dreg
, src2
);
2830 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
2833 case OP_SUB_OVF_CARRY
: {
2835 s390_lghi (code
, s390_r0
, 0);
2836 s390_lgr (code
, s390_r1
, s390_r0
);
2837 s390_slbgr (code
, s390_r0
, s390_r1
);
2838 s390_sgr (code
, ins
->dreg
, src2
);
2839 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
2840 s390_agr (code
, ins
->dreg
, s390_r0
);
2841 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
2844 case OP_SUB_OVF_UN_CARRY
: {
2846 s390_slbgr (code
, ins
->dreg
, src2
);
2847 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
2851 if (ins
->sreg1
== ins
->dreg
) {
2852 s390_ngr (code
, ins
->dreg
, ins
->sreg2
);
2855 if (ins
->sreg2
== ins
->dreg
) {
2856 s390_ngr (code
, ins
->dreg
, ins
->sreg1
);
2859 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2860 s390_ngr (code
, ins
->dreg
, ins
->sreg2
);
2866 if (ins
->dreg
!= ins
->sreg1
) {
2867 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2869 if (s390_is_imm16 (ins
->inst_imm
)) {
2870 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2871 s390_ngr (code
, ins
->dreg
, s390_r0
);
2873 s390_basr (code
, s390_r13
, 0);
2875 s390_llong(code
, ins
->inst_imm
);
2876 s390_ng (code
, ins
->dreg
, 0, s390_r13
, 4);
2881 s390_lgr (code
, s390_r1
, ins
->sreg1
);
2882 s390_dsgr (code
, s390_r0
, ins
->sreg2
);
2883 s390_lgr (code
, ins
->dreg
, s390_r1
);
2887 s390_lgr (code
, s390_r1
, ins
->sreg1
);
2888 s390_lghi (code
, s390_r0
, 0);
2889 s390_dlgr (code
, s390_r0
, ins
->sreg2
);
2890 s390_lgr (code
, ins
->dreg
, s390_r1
);
2894 if (s390_is_imm16 (ins
->inst_imm
)) {
2895 s390_lghi (code
, s390_r13
, ins
->inst_imm
);
2896 s390_lgr (code
, s390_r1
, ins
->sreg1
);
2898 s390_basr (code
, s390_r13
, 0);
2900 s390_llong(code
, ins
->inst_imm
);
2901 s390_lgr (code
, s390_r1
, ins
->sreg1
);
2902 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
2904 s390_dsgr (code
, s390_r0
, s390_r13
);
2905 s390_lgr (code
, ins
->dreg
, s390_r1
);
2909 s390_lgr (code
, s390_r1
, ins
->sreg1
);
2910 s390_dsgr (code
, s390_r0
, ins
->sreg2
);
2911 s390_lgr (code
, ins
->dreg
, s390_r0
);
2915 s390_lgr (code
, s390_r1
, ins
->sreg1
);
2916 s390_lghi (code
, s390_r0
, 0);
2917 s390_dlgr (code
, s390_r0
, ins
->sreg2
);
2918 s390_lgr (code
, ins
->dreg
, s390_r0
);
2922 if (s390_is_imm16 (ins
->inst_imm
)) {
2923 s390_lghi (code
, s390_r13
, ins
->inst_imm
);
2924 s390_lgr (code
, s390_r0
, ins
->sreg1
);
2926 s390_basr (code
, s390_r13
, 0);
2928 s390_llong(code
, ins
->inst_imm
);
2929 s390_lgr (code
, s390_r0
, ins
->sreg1
);
2930 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
2932 s390_dsgr(code
, s390_r0
, s390_r13
);
2933 s390_lgr (code
, ins
->dreg
, s390_r0
);
2937 if (ins
->sreg1
== ins
->dreg
) {
2938 s390_ogr (code
, ins
->dreg
, ins
->sreg2
);
2941 if (ins
->sreg2
== ins
->dreg
) {
2942 s390_ogr (code
, ins
->dreg
, ins
->sreg1
);
2945 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2946 s390_ogr (code
, ins
->dreg
, ins
->sreg2
);
2952 if (ins
->dreg
!= ins
->sreg1
) {
2953 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2955 if (s390_is_imm16 (ins
->inst_imm
)) {
2956 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2957 s390_ogr (code
, ins
->dreg
, s390_r0
);
2959 s390_basr (code
, s390_r13
, 0);
2961 s390_llong(code
, ins
->inst_imm
);
2962 s390_og (code
, ins
->dreg
, 0, s390_r13
, 4);
2967 if (ins
->sreg1
== ins
->dreg
) {
2968 s390_xgr (code
, ins
->dreg
, ins
->sreg2
);
2971 if (ins
->sreg2
== ins
->dreg
) {
2972 s390_xgr (code
, ins
->dreg
, ins
->sreg1
);
2975 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2976 s390_xgr (code
, ins
->dreg
, ins
->sreg2
);
2982 if (ins
->dreg
!= ins
->sreg1
) {
2983 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
2985 if (s390_is_imm16 (ins
->inst_imm
)) {
2986 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
2987 s390_xgr (code
, ins
->dreg
, s390_r0
);
2989 s390_basr (code
, s390_r13
, 0);
2991 s390_llong(code
, ins
->inst_imm
);
2992 s390_xg (code
, ins
->dreg
, 0, s390_r13
, 4);
2999 s390_sllg (code
, ins
->dreg
, ins
->dreg
, src2
, 0);
3004 if (ins
->sreg1
!= ins
->dreg
) {
3005 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
3007 s390_sllg (code
, ins
->dreg
, ins
->dreg
, 0, (ins
->inst_imm
& 0x3f));
3013 s390_srag (code
, ins
->dreg
, ins
->dreg
, src2
, 0);
3018 if (ins
->sreg1
!= ins
->dreg
) {
3019 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
3021 s390_srag (code
, ins
->dreg
, ins
->dreg
, 0, (ins
->inst_imm
& 0x3f));
3025 case OP_LSHR_UN_IMM
: {
3026 if (ins
->sreg1
!= ins
->dreg
) {
3027 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
3029 s390_srlg (code
, ins
->dreg
, ins
->dreg
, 0, (ins
->inst_imm
& 0x3f));
3035 s390_srlg (code
, ins
->dreg
, ins
->dreg
, src2
, 0);
3039 if (ins
->sreg1
!= ins
->dreg
) {
3040 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
3042 s390_lghi (code
, s390_r0
, -1);
3043 s390_xgr (code
, ins
->dreg
, s390_r0
);
3047 s390_lcgr (code
, ins
->dreg
, ins
->sreg1
);
3053 s390_msgr (code
, ins
->dreg
, src2
);
3058 if (ins
->dreg
!= ins
->sreg1
) {
3059 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
3061 if (s390_is_imm16 (ins
->inst_imm
)) {
3062 s390_lghi (code
, s390_r13
, ins
->inst_imm
);
3064 s390_basr (code
, s390_r13
, 0);
3066 s390_llong(code
, ins
->inst_imm
);
3067 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
3069 s390_msgr (code
, ins
->dreg
, s390_r13
);
3075 s390_ltgr (code
, s390_r1
, ins
->sreg1
);
3076 s390_jz (code
, 0); CODEPTR(code
, o
[0]);
3077 s390_ltgr (code
, s390_r0
, ins
->sreg2
);
3079 s390_lghi (code
, s390_r1
, 0);
3080 s390_j (code
, 0); CODEPTR(code
, o
[1]);
3081 s390_xgr (code
, s390_r0
, s390_r1
);
3082 s390_msgr (code
, s390_r1
, ins
->sreg2
);
3083 s390_xgr (code
, s390_r0
, s390_r1
);
3084 s390_srlg (code
, s390_r0
, s390_r0
, 0, 63);
3085 s390_ltgr (code
, s390_r0
, s390_r0
);
3086 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3087 PTRSLOT (code
, o
[0]);
3088 PTRSLOT (code
, o
[1]);
3089 s390_lgr (code
, ins
->dreg
, s390_r1
);
3092 case OP_LMUL_OVF_UN
:
3093 case CEE_MUL_OVF_UN
: {
3094 s390_lghi (code
, s390_r0
, 0);
3095 s390_lgr (code
, s390_r1
, ins
->sreg1
);
3096 s390_mlgr (code
, s390_r0
, ins
->sreg2
);
3097 s390_ltgr (code
, s390_r0
, s390_r0
);
3098 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3099 s390_lgr (code
, ins
->dreg
, s390_r1
);
3103 g_assert_not_reached ();
3105 s390_algr (code
, ins
->dreg
, src2
);
3110 s390_agr (code
, ins
->dreg
, src2
);
3114 g_assert_not_reached ();
3116 s390_alcgr (code
, ins
->dreg
, src2
);
3120 if (ins
->dreg
!= ins
->sreg1
) {
3121 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3123 if (s390_is_imm16 (ins
->inst_imm
)) {
3124 s390_aghi(code
, ins
->dreg
, ins
->inst_imm
);
3126 s390_basr (code
, s390_r13
, 0);
3128 s390_word (code
, ins
->inst_imm
);
3129 s390_agf (code
, ins
->dreg
, 0, s390_r13
, 4);
3134 if (ins
->dreg
!= ins
->sreg1
) {
3135 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3137 if (s390_is_imm16 (ins
->inst_imm
)) {
3138 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
3139 s390_alcgr (code
, ins
->dreg
, s390_r0
);
3141 s390_basr (code
, s390_r13
, 0);
3143 s390_word (code
, ins
->inst_imm
);
3144 s390_lgf (code
, s390_r13
, 0, s390_r13
, 4);
3145 s390_alcgr (code
, ins
->dreg
, s390_r13
);
3151 s390_ar (code
, ins
->dreg
, src2
);
3152 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3153 s390_lgfr (code
, ins
->dreg
, ins
->dreg
);
3156 case CEE_ADD_OVF_UN
: {
3158 s390_algr (code
, ins
->dreg
, src2
);
3159 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3160 s390_llgfr (code
, ins
->dreg
, ins
->dreg
);
3164 CHECK_SRCDST_NCOM_I
;
3165 s390_slgr (code
, ins
->dreg
, src2
);
3169 CHECK_SRCDST_NCOM_I
;
3170 s390_sgr (code
, ins
->dreg
, src2
);
3174 CHECK_SRCDST_NCOM_I
;
3175 s390_slbgr (code
, ins
->dreg
, src2
);
3179 if (ins
->dreg
!= ins
->sreg1
) {
3180 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3182 if (s390_is_imm16 (-ins
->inst_imm
)) {
3183 s390_aghi (code
, ins
->dreg
, -ins
->inst_imm
);
3185 s390_basr (code
, s390_r13
, 0);
3187 s390_word (code
, ins
->inst_imm
);
3188 s390_sgf (code
, ins
->dreg
, 0, s390_r13
, 4);
3193 s390_basr (code
, s390_r13
, 0);
3195 s390_word (code
, ins
->inst_imm
);
3196 s390_slgf (code
, ins
->dreg
, 0, s390_r13
, 4);
3201 s390_sr (code
, ins
->dreg
, src2
);
3202 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3203 s390_lgfr (code
, ins
->dreg
, ins
->dreg
);
3206 case CEE_SUB_OVF_UN
: {
3208 s390_slr (code
, ins
->dreg
, src2
);
3209 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3210 s390_llgfr(code
, ins
->dreg
, ins
->dreg
);
3214 CHECK_SRCDST_NCOM_I
;
3215 s390_ngr (code
, ins
->dreg
, src2
);
3219 if (ins
->dreg
!= ins
->sreg1
) {
3220 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3222 if (s390_is_imm16 (ins
->inst_imm
)) {
3223 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
3224 s390_ngr (code
, ins
->dreg
, s390_r0
);
3226 s390_basr (code
, s390_r13
, 0);
3228 s390_llong(code
, ins
->inst_imm
);
3229 s390_ng (code
, ins
->dreg
, 0, s390_r13
, 4);
3234 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3235 s390_srda (code
, s390_r0
, 0, 32);
3236 s390_dr (code
, s390_r0
, ins
->sreg2
);
3237 s390_lgfr (code
, ins
->dreg
, s390_r1
);
3241 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3242 s390_srdl (code
, s390_r0
, 0, 32);
3243 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3244 s390_lgfr (code
, ins
->dreg
, s390_r1
);
3248 if (s390_is_imm16 (ins
->inst_imm
)) {
3249 s390_lghi (code
, s390_r13
, ins
->inst_imm
);
3250 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3252 s390_basr (code
, s390_r13
, 0);
3254 s390_word (code
, ins
->inst_imm
);
3255 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3256 s390_lgf (code
, s390_r13
, 0, s390_r13
, 4);
3258 s390_srda (code
, s390_r0
, 0, 32);
3259 s390_dr (code
, s390_r0
, ins
->sreg2
);
3260 s390_lgfr (code
, ins
->dreg
, s390_r1
);
3264 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3265 s390_srda (code
, s390_r0
, 0, 32);
3266 s390_dr (code
, s390_r0
, ins
->sreg2
);
3267 s390_lgfr (code
, ins
->dreg
, s390_r0
);
3270 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3271 s390_srdl (code
, s390_r0
, 0, 32);
3272 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3273 s390_lgfr (code
, ins
->dreg
, s390_r0
);
3277 if (s390_is_imm16 (ins
->inst_imm
)) {
3278 s390_lghi (code
, s390_r13
, ins
->inst_imm
);
3279 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3281 s390_basr (code
, s390_r13
, 0);
3283 s390_word (code
, ins
->inst_imm
);
3284 s390_lgfr (code
, s390_r0
, ins
->sreg1
);
3285 s390_lgf (code
, s390_r13
, 0, s390_r13
, 4);
3287 s390_srda (code
, s390_r0
, 0, 32);
3288 s390_dr (code
, s390_r0
, ins
->sreg2
);
3289 s390_lgfr (code
, ins
->dreg
, s390_r0
);
3294 s390_ogr (code
, ins
->dreg
, src2
);
3298 if (ins
->dreg
!= ins
->sreg1
) {
3299 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3301 if (s390_is_imm16 (ins
->inst_imm
)) {
3302 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
3303 s390_ogr (code
, ins
->dreg
, s390_r0
);
3305 s390_basr (code
, s390_r13
, 0);
3307 s390_llong(code
, ins
->inst_imm
);
3308 s390_og (code
, ins
->dreg
, 0, s390_r13
, 4);
3314 s390_xgr (code
, ins
->dreg
, src2
);
3318 if (ins
->dreg
!= ins
->sreg1
) {
3319 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3321 if (s390_is_imm16 (ins
->inst_imm
)) {
3322 s390_lghi (code
, s390_r0
, ins
->inst_imm
);
3323 s390_xgr (code
, ins
->dreg
, s390_r0
);
3325 s390_basr (code
, s390_r13
, 0);
3327 s390_llong(code
, ins
->inst_imm
);
3328 s390_xg (code
, ins
->dreg
, 0, s390_r13
, 4);
3333 if (ins
->sreg1
!= ins
->dreg
) {
3334 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3336 s390_sll (code
, ins
->dreg
, ins
->sreg2
, 0);
3340 if (ins
->sreg1
!= ins
->dreg
) {
3341 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3343 s390_sll (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3347 if (ins
->sreg1
!= ins
->dreg
) {
3348 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3350 s390_sra (code
, ins
->dreg
, ins
->sreg2
, 0);
3354 if (ins
->sreg1
!= ins
->dreg
) {
3355 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3357 s390_sra (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3360 case OP_ISHR_UN_IMM
: {
3361 if (ins
->sreg1
!= ins
->dreg
) {
3362 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3364 s390_srl (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3368 if (ins
->sreg1
!= ins
->dreg
) {
3369 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3371 s390_srl (code
, ins
->dreg
, ins
->sreg2
, 0);
3375 if (ins
->sreg1
!= ins
->dreg
) {
3376 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3378 s390_lghi (code
, s390_r0
, -1);
3379 s390_xgr (code
, ins
->dreg
, s390_r0
);
3383 s390_lcgr (code
, ins
->dreg
, ins
->sreg1
);
3388 s390_msr (code
, ins
->dreg
, src2
);
3392 if (ins
->dreg
!= ins
->sreg1
) {
3393 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3395 if (s390_is_imm16 (ins
->inst_imm
)) {
3396 s390_lghi (code
, s390_r13
, ins
->inst_imm
);
3398 s390_basr (code
, s390_r13
, 0);
3400 s390_word (code
, ins
->inst_imm
);
3401 s390_lgf (code
, s390_r13
, 0, s390_r13
, 4);
3403 s390_msr (code
, ins
->dreg
, s390_r13
);
3408 s390_ltr (code
, s390_r1
, ins
->sreg1
);
3409 s390_jz (code
, 0); CODEPTR(code
, o
[0]);
3410 s390_ltr (code
, s390_r0
, ins
->sreg2
);
3412 s390_lhi (code
, s390_r1
, 0);
3413 s390_j (code
, 0); CODEPTR(code
, o
[1]);
3414 s390_xr (code
, s390_r0
, s390_r1
);
3415 s390_msr (code
, s390_r1
, ins
->sreg2
);
3416 s390_xr (code
, s390_r0
, s390_r1
);
3417 s390_srl (code
, s390_r0
, 0, 31);
3418 s390_ltr (code
, s390_r0
, s390_r0
);
3419 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3420 PTRSLOT (code
, o
[0]);
3421 PTRSLOT (code
, o
[1]);
3422 s390_lgfr (code
, ins
->dreg
, s390_r1
);
3425 case OP_IMUL_OVF_UN
: {
3426 s390_lhi (code
, s390_r0
, 0);
3427 s390_lr (code
, s390_r1
, ins
->sreg1
);
3428 s390_mlr (code
, s390_r0
, ins
->sreg2
);
3429 s390_ltr (code
, s390_r0
, s390_r0
);
3430 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3431 s390_lgfr (code
, ins
->dreg
, s390_r1
);
3436 case OP_SETREGIMM
: {
3437 if (s390_is_imm16(ins
->inst_c0
)) {
3438 s390_lghi (code
, ins
->dreg
, ins
->inst_c0
);
3440 s390_basr (code
, s390_r13
, 0);
3442 s390_llong(code
, ins
->inst_c0
);
3443 s390_lg (code
, ins
->dreg
, 0, s390_r13
, 4);
3448 s390_basr (code
, s390_r13
, 0);
3450 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3451 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3452 s390_llong(code
, 0);
3453 s390_lg (code
,ins
->dreg
, 0, s390_r13
, 4);
3460 if (ins
->dreg
!= ins
->sreg1
) {
3461 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
3466 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3471 s390_llgfr (code
, ins
->dreg
, ins
->sreg1
);
3473 case CEE_CONV_OVF_U4
:
3474 s390_basr (code
, s390_r13
, 0);
3476 s390_llong(code
, 4294967295);
3477 s390_clg (code
, ins
->sreg1
, 0, s390_r13
, 4);
3478 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT
, "OverflowException");
3479 s390_ltgr (code
, ins
->sreg1
, ins
->sreg1
);
3480 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, "OverflowException");
3481 s390_llgfr(code
, ins
->dreg
, ins
->sreg1
);
3483 case CEE_CONV_OVF_I4_UN
:
3484 s390_basr (code
, s390_r13
, 0);
3486 s390_llong(code
, 2147483647);
3487 s390_cg (code
, ins
->sreg1
, 0, s390_r13
, 4);
3488 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT
, "OverflowException");
3489 s390_ltgr (code
, ins
->sreg1
, ins
->sreg1
);
3490 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, "OverflowException");
3491 s390_lgfr (code
, ins
->dreg
, ins
->sreg1
);
3495 if (ins
->dreg
!= ins
->sreg1
) {
3496 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3500 case OP_S390_SETF4RET
: {
3501 s390_ledbr (code
, ins
->dreg
, ins
->sreg1
);
3504 case OP_FCONV_TO_R4
: {
3505 g_error ("Shouldn't be reached");
3507 (ins
->next
->opcode
!= OP_FMOVE
) &&
3508 (ins
->next
->opcode
!= OP_STORER4_MEMBASE_REG
))
3509 s390_ledbr (code
, ins
->dreg
, ins
->sreg1
);
3513 if (cfg
->method
->save_lmf
)
3514 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
3516 if (cfg
->flags
& MONO_CFG_HAS_TAIL
) {
3517 code
= emit_load_volatile_registers(code
, cfg
);
3520 code
= backUpStackPtr(cfg
, code
);
3521 s390_lg (code
, s390_r14
, 0, STK_BASE
, S390_RET_ADDR_OFFSET
);
3522 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3523 MONO_PATCH_INFO_METHOD_JUMP
,
3525 s390_jcl (code
, S390_CC_UN
, 0);
3528 case OP_CHECK_THIS
: {
3529 /* ensure ins->sreg1 is not NULL */
3530 s390_lg (code
, s390_r0
, 0, ins
->sreg1
, 0);
3531 s390_ltgr (code
, s390_r0
, s390_r0
);
3535 int offset
= cfg
->sig_cookie
+ cfg
->stack_usage
;
3537 if (s390_is_imm16 (offset
))
3538 s390_lghi (code
, s390_r0
, offset
);
3540 s390_basr (code
, s390_r13
, 0);
3542 s390_llong(code
, offset
);
3543 s390_lg (code
, s390_r0
, 0, s390_r13
, 0);
3545 s390_agr (code
, s390_r0
, cfg
->frame_reg
);
3546 s390_stg (code
, s390_r0
, 0, ins
->sreg1
, 0);
3550 s390_basr (code
, s390_r13
, 0);
3552 call
= (MonoCallInst
*)ins
;
3553 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3554 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3555 MONO_PATCH_INFO_METHOD
,
3558 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3559 MONO_PATCH_INFO_ABS
,
3561 s390_llong(code
, 0);
3562 s390_lg (code
, s390_r14
, 0, s390_r13
, 4);
3563 s390_basr (code
, s390_r14
, s390_r14
);
3564 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3565 s390_ldebr (code
, s390_f0
, s390_f0
);
3572 s390_basr (code
, s390_r13
, 0);
3574 call
= (MonoCallInst
*)ins
;
3575 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3576 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3577 MONO_PATCH_INFO_METHOD
,
3580 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3581 MONO_PATCH_INFO_ABS
,
3583 s390_llong(code
, 0);
3584 s390_lg (code
, s390_r14
, 0, s390_r13
, 4);
3585 s390_basr (code
, s390_r14
, s390_r14
);
3588 case OP_FCALL_REG
: {
3589 call
= (MonoCallInst
*)ins
;
3590 s390_lgr (code
, s390_r1
, ins
->sreg1
);
3591 s390_basr (code
, s390_r14
, s390_r1
);
3592 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3593 s390_ldebr (code
, s390_f0
, s390_f0
);
3598 case OP_VOIDCALL_REG
:
3600 s390_lgr (code
, s390_r1
, ins
->sreg1
);
3601 s390_basr (code
, s390_r14
, s390_r1
);
3604 case OP_FCALL_MEMBASE
: {
3605 call
= (MonoCallInst
*)ins
;
3606 s390_lg (code
, s390_r1
, 0, ins
->sreg1
, ins
->inst_offset
);
3607 s390_basr (code
, s390_r14
, s390_r1
);
3608 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3609 s390_ldebr (code
, s390_f0
, s390_f0
);
3612 case OP_LCALL_MEMBASE
:
3613 case OP_VCALL_MEMBASE
:
3614 case OP_VOIDCALL_MEMBASE
:
3615 case OP_CALL_MEMBASE
: {
3616 s390_lg (code
, s390_r1
, 0, ins
->sreg1
, ins
->inst_offset
);
3617 s390_basr (code
, s390_r14
, s390_r1
);
3621 g_assert_not_reached ();
3624 int alloca_skip
= S390_MINIMAL_STACK_SIZE
+ cfg
->param_area
;
3625 int area_offset
= S390_ALIGN(alloca_skip
, S390_STACK_ALIGNMENT
);
3626 s390_lgr (code
, s390_r1
, ins
->sreg1
);
3627 if (ins
->flags
& MONO_INST_INIT
)
3628 s390_lgr (code
, s390_r0
, ins
->sreg1
);
3629 s390_aghi (code
, s390_r1
, 14);
3630 s390_srlg (code
, s390_r1
, s390_r1
, 0, 3);
3631 s390_sllg (code
, s390_r1
, s390_r1
, 0, 3);
3632 if (cfg
->method
->save_lmf
) {
3633 /*----------------------------------*/
3634 /* we have to adjust lmf ebp value */
3635 /*----------------------------------*/
3636 int lmfOffset
= cfg
->stack_usage
- sizeof(MonoLMF
);
3638 s390_lgr (code
, s390_r13
, cfg
->frame_reg
);
3639 if (s390_is_uimm16(lmfOffset
))
3640 s390_aghi (code
, s390_r13
, lmfOffset
);
3642 s390_basr (code
, s390_r14
, 0);
3644 s390_word (code
, lmfOffset
);
3645 s390_agf (code
, s390_r13
, 0, s390_r14
, 4);
3647 s390_lgr (code
, s390_r14
, STK_BASE
);
3648 s390_sgr (code
, s390_r14
, s390_r1
);
3649 s390_stg (code
, s390_r14
, 0, s390_r13
,
3650 G_STRUCT_OFFSET(MonoLMF
, ebp
));
3652 s390_lg (code
, s390_r13
, 0, STK_BASE
, 0);
3653 s390_sgr (code
, STK_BASE
, s390_r1
);
3654 s390_stg (code
, s390_r13
, 0, STK_BASE
, 0);
3655 s390_la (code
, ins
->dreg
, 0, STK_BASE
, area_offset
);
3656 s390_srlg (code
, ins
->dreg
, ins
->dreg
, 0, 3);
3657 s390_sllg (code
, ins
->dreg
, ins
->dreg
, 0, 3);
3658 if (ins
->flags
& MONO_INST_INIT
) {
3659 s390_lgr (code
, s390_r1
, s390_r0
);
3660 s390_lgr (code
, s390_r0
, ins
->dreg
);
3661 s390_lgr (code
, s390_r14
, s390_r12
);
3662 s390_lghi (code
, s390_r13
, 0);
3663 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
3665 s390_lgr (code
, s390_r12
, s390_r14
);
3670 s390_br (code
, s390_r14
);
3674 s390_lgr (code
, s390_r2
, ins
->sreg1
);
3675 s390_basr (code
, s390_r13
, 0);
3677 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3678 (gpointer
) "mono_arch_throw_exception");
3679 s390_llong(code
, 0);
3680 s390_lg (code
, s390_r14
, 0, s390_r13
, 4);
3681 s390_basr (code
, s390_r14
, s390_r14
);
3685 s390_lgr (code
, s390_r2
, ins
->sreg1
);
3686 s390_basr (code
, s390_r13
, 0);
3688 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3689 (gpointer
) "mono_arch_rethrow_exception");
3690 s390_llong(code
, 0);
3691 s390_lg (code
, s390_r14
, 0, s390_r13
, 4);
3692 s390_basr (code
, s390_r14
, s390_r14
);
3695 case OP_START_HANDLER
: {
3696 S390_LONG (code
, stg
, stg
, s390_r14
, 0,
3697 ins
->inst_left
->inst_basereg
,
3698 ins
->inst_left
->inst_offset
);
3701 case OP_ENDFILTER
: {
3702 if (ins
->sreg1
!= s390_r2
)
3703 s390_lgr(code
, s390_r2
, ins
->sreg1
);
3704 S390_LONG (code
, lg
, lg
, s390_r14
, 0,
3705 ins
->inst_left
->inst_basereg
,
3706 ins
->inst_left
->inst_offset
);
3707 s390_br (code
, s390_r14
);
3710 case CEE_ENDFINALLY
: {
3711 S390_LONG (code
, lg
, lg
, s390_r14
, 0,
3712 ins
->inst_left
->inst_basereg
,
3713 ins
->inst_left
->inst_offset
);
3714 s390_br (code
, s390_r14
);
3717 case OP_CALL_HANDLER
: {
3718 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3719 MONO_PATCH_INFO_BB
, ins
->inst_target_bb
);
3720 s390_brasl (code
, s390_r14
, 0);
3724 ins
->inst_c0
= code
- cfg
->native_code
;
3728 EMIT_UNCOND_BRANCH(ins
);
3731 s390_br (code
, ins
->sreg1
);
3736 s390_lghi(code
, ins
->dreg
, 1);
3738 s390_lghi(code
, ins
->dreg
, 0);
3743 s390_lghi(code
, ins
->dreg
, 1);
3745 s390_lghi(code
, ins
->dreg
, 0);
3750 s390_lghi(code
, ins
->dreg
, 1);
3752 s390_lghi(code
, ins
->dreg
, 0);
3757 s390_lghi(code
, ins
->dreg
, 1);
3759 s390_lghi(code
, ins
->dreg
, 0);
3764 s390_lghi(code
, ins
->dreg
, 1);
3766 s390_lghi(code
, ins
->dreg
, 0);
3769 case OP_COND_EXC_EQ
:
3770 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ
, ins
->inst_p1
);
3772 case OP_COND_EXC_NE_UN
:
3773 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE
, ins
->inst_p1
);
3775 case OP_COND_EXC_LT
:
3776 case OP_COND_EXC_LT_UN
:
3777 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, ins
->inst_p1
);
3779 case OP_COND_EXC_GT
:
3780 case OP_COND_EXC_GT_UN
:
3781 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT
, ins
->inst_p1
);
3783 case OP_COND_EXC_GE
:
3784 case OP_COND_EXC_GE_UN
:
3785 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE
, ins
->inst_p1
);
3787 case OP_COND_EXC_LE
:
3788 case OP_COND_EXC_LE_UN
:
3789 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE
, ins
->inst_p1
);
3791 case OP_COND_EXC_OV
:
3792 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, ins
->inst_p1
);
3794 case OP_COND_EXC_NO
:
3795 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO
, ins
->inst_p1
);
3798 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, ins
->inst_p1
);
3800 case OP_COND_EXC_NC
:
3801 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, ins
->inst_p1
);
3805 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
3809 EMIT_COND_BRANCH (ins
, S390_CC_NE
);
3815 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
3821 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
3827 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
3833 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
3836 /* floating point opcodes */
3838 if (*((float *) ins
->inst_p0
) == 0) {
3839 s390_lzdr (code
, ins
->dreg
);
3841 s390_basr (code
, s390_r13
, 0);
3843 s390_llong (code
, ins
->inst_p0
);
3844 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
3845 s390_ld (code
, ins
->dreg
, 0, s390_r13
, 0);
3850 if (*((float *) ins
->inst_p0
) == 0) {
3851 s390_lzdr (code
, ins
->dreg
);
3853 s390_basr (code
, s390_r13
, 0);
3855 s390_llong(code
, ins
->inst_p0
);
3856 s390_lg (code
, s390_r13
, 0, s390_r13
, 4);
3857 s390_ldeb (code
, ins
->dreg
, 0, s390_r13
, 0);
3861 case OP_STORER8_MEMBASE_REG
: {
3862 S390_LONG (code
, stdy
, std
, ins
->sreg1
, 0,
3863 ins
->inst_destbasereg
, ins
->inst_offset
);
3866 case OP_LOADR8_MEMBASE
: {
3867 S390_LONG (code
, ldy
, ld
, ins
->dreg
, 0,
3868 ins
->inst_basereg
, ins
->inst_offset
);
3871 case OP_STORER4_MEMBASE_REG
: {
3872 s390_ledbr (code
, s390_f15
, ins
->sreg1
);
3873 S390_LONG (code
, stey
, ste
, s390_f15
, 0,
3874 ins
->inst_destbasereg
, ins
->inst_offset
);
3877 case OP_LOADR4_MEMBASE
: {
3878 S390_LONG (code
, ldy
, ld
, s390_f15
, 0,
3879 ins
->inst_basereg
, ins
->inst_offset
);
3880 s390_ldebr (code
, ins
->dreg
, s390_f15
);
3883 case CEE_CONV_R_UN
: {
3884 s390_cdgbr (code
, ins
->dreg
, ins
->sreg1
);
3885 s390_ltgr (code
, ins
->sreg1
, ins
->sreg1
);
3886 s390_jnl (code
, 12);
3887 s390_basr (code
, s390_r13
, 0);
3889 s390_word (code
, 0x41f00000);
3890 s390_word (code
, 0);
3891 s390_adb (code
, ins
->dreg
, 0, s390_r13
, 4);
3894 case OP_LCONV_TO_R4
:
3896 s390_cdgbr (code
, ins
->dreg
, ins
->sreg1
);
3899 case OP_LCONV_TO_R8
:
3901 s390_cdgbr (code
, ins
->dreg
, ins
->sreg1
);
3904 case OP_FCONV_TO_I1
:
3905 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, TRUE
);
3907 case OP_FCONV_TO_U1
:
3908 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, FALSE
);
3910 case OP_FCONV_TO_I2
:
3911 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, TRUE
);
3913 case OP_FCONV_TO_U2
:
3914 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, FALSE
);
3916 case OP_FCONV_TO_I4
:
3918 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, TRUE
);
3920 case OP_FCONV_TO_U4
:
3922 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, FALSE
);
3924 case OP_FCONV_TO_I8
:
3925 s390_cgdbr (code
, ins
->dreg
, 5, ins
->sreg1
);
3927 case OP_FCONV_TO_U8
:
3928 g_assert_not_reached ();
3929 /* Implemented as helper calls */
3931 case OP_LCONV_TO_R_UN
:
3932 g_assert_not_reached ();
3933 /* Implemented as helper calls */
3935 case OP_LCONV_TO_OVF_I
: {
3936 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
3938 s390_ltgr (code
, ins
->sreg2
, ins
->sreg2
);
3939 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
3940 s390_ltgr (code
, ins
->sreg1
, ins
->sreg1
);
3941 s390_jnl (code
, 0); CODEPTR(code
, o
[1]);
3942 s390_lhi (code
, s390_r13
, -1);
3943 s390_cgr (code
, ins
->sreg1
, s390_r13
);
3944 s390_jnz (code
, 0); CODEPTR(code
, o
[2]);
3945 if (ins
->dreg
!= ins
->sreg2
)
3946 s390_lgr (code
, ins
->dreg
, ins
->sreg2
);
3947 s390_j (code
, 0); CODEPTR(code
, o
[3]);
3948 PTRSLOT(code
, o
[0]);
3949 s390_jz (code
, 0); CODEPTR(code
, o
[4]);
3950 PTRSLOT(code
, o
[1]);
3951 PTRSLOT(code
, o
[2]);
3952 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3953 MONO_PATCH_INFO_EXC
, "OverflowException");
3954 s390_brasl (code
, s390_r14
, 0);
3955 PTRSLOT(code
, o
[3]);
3956 PTRSLOT(code
, o
[4]);
3960 s390_lpdbr (code
, ins
->dreg
, ins
->sreg1
);
3964 s390_sqdbr (code
, ins
->dreg
, ins
->sreg1
);
3969 s390_adbr (code
, ins
->dreg
, src2
);
3973 CHECK_SRCDST_NCOM_F
;
3974 s390_sdbr (code
, ins
->dreg
, src2
);
3979 s390_mdbr (code
, ins
->dreg
, src2
);
3983 CHECK_SRCDST_NCOM_F
;
3984 s390_ddbr (code
, ins
->dreg
, src2
);
3988 s390_lcdbr (code
, ins
->dreg
, ins
->sreg1
);
3992 CHECK_SRCDST_NCOM_F
;
3993 s390_didbr (code
, ins
->dreg
, src2
, 5, s390_f15
);
3997 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4001 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4002 s390_lghi (code
, ins
->dreg
, 1);
4004 s390_lghi (code
, ins
->dreg
, 0);
4008 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4009 s390_lghi (code
, ins
->dreg
, 1);
4011 s390_lghi (code
, ins
->dreg
, 0);
4015 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4016 s390_lghi (code
, ins
->dreg
, 1);
4018 s390_lghi (code
, ins
->dreg
, 0);
4022 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4023 s390_lghi (code
, ins
->dreg
, 1);
4025 s390_lghi (code
, ins
->dreg
, 0);
4029 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4030 s390_lghi (code
, ins
->dreg
, 1);
4032 s390_lghi (code
, ins
->dreg
, 0);
4037 s390_jo (code
, 0); CODEPTR(code
, o
);
4038 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
4043 EMIT_COND_BRANCH (ins
, S390_CC_NE
|S390_CC_OV
);
4047 s390_jo (code
, 0); CODEPTR(code
, o
);
4048 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
4053 EMIT_COND_BRANCH (ins
, S390_CC_LT
|S390_CC_OV
);
4057 s390_jo (code
, 0); CODEPTR(code
, o
);
4058 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
4063 EMIT_COND_BRANCH (ins
, S390_CC_GT
|S390_CC_OV
);
4067 s390_jo (code
, 0); CODEPTR(code
, o
);
4068 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
4073 EMIT_COND_BRANCH (ins
, S390_CC_GE
|S390_CC_OV
);
4077 s390_jo (code
, 0); CODEPTR(code
, o
);
4078 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
4083 EMIT_COND_BRANCH (ins
, S390_CC_LE
|S390_CC_OV
);
4085 case CEE_CKFINITE
: {
4087 s390_lhi (code
, s390_r13
, 0x7f);
4088 s390_tcdb (code
, ins
->sreg1
, 0, s390_r13
, 0);
4089 s390_jz (code
, 0); CODEPTR(code
, o
);
4090 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4091 MONO_PATCH_INFO_EXC
, "ArithmeticException");
4092 s390_brasl (code
, s390_r14
,0);
4096 case OP_S390_MOVE
: {
4097 if (ins
->backend
.size
> 0) {
4098 if (ins
->backend
.size
<= 256) {
4099 s390_mvc (code
, ins
->backend
.size
, ins
->dreg
,
4100 ins
->inst_offset
, ins
->sreg1
, ins
->inst_imm
);
4102 s390_lgr (code
, s390_r0
, ins
->dreg
);
4103 if (s390_is_imm16 (ins
->inst_offset
)) {
4104 s390_aghi (code
, s390_r0
, ins
->inst_offset
);
4106 s390_basr (code
, s390_r13
, 0);
4108 s390_llong(code
, ins
->inst_offset
);
4109 s390_a (code
, s390_r0
, 0, s390_r13
, 4);
4111 s390_lgr (code
, s390_r12
, ins
->sreg1
);
4112 if (s390_is_imm16 (ins
->inst_imm
)) {
4113 s390_aghi (code
, s390_r12
, ins
->inst_imm
);
4115 s390_basr (code
, s390_r13
, 0);
4117 s390_llong(code
, ins
->inst_imm
);
4118 s390_ag (code
, s390_r12
, 0, s390_r13
, 4);
4120 s390_lgr (code
, s390_r1
, ins
->sreg1
);
4121 s390_lgr (code
, s390_r13
, s390_r1
);
4122 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
4128 case OP_ATOMIC_ADD_I8
: {
4129 s390_lgr (code
, s390_r1
, ins
->sreg2
);
4130 s390_lg (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4131 s390_agr (code
, s390_r1
, s390_r0
);
4132 s390_csg (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4133 s390_jnz (code
, -10);
4134 s390_lgr (code
, ins
->dreg
, s390_r1
);
4137 case OP_ATOMIC_ADD_NEW_I8
: {
4138 s390_lgr (code
, s390_r1
, ins
->sreg2
);
4139 s390_lg (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4140 s390_agr (code
, s390_r1
, s390_r0
);
4141 s390_csg (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4142 s390_jnz (code
, -10);
4143 s390_lgr (code
, ins
->dreg
, s390_r1
);
4146 case OP_ATOMIC_EXCHANGE_I8
: {
4147 s390_lg (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4148 s390_csg (code
, s390_r0
, ins
->sreg2
, ins
->inst_basereg
, ins
->inst_offset
);
4149 s390_jnz (code
, -6);
4150 s390_lgr (code
, ins
->dreg
, s390_r0
);
4153 case OP_ATOMIC_ADD_I4
: {
4154 s390_lgfr(code
, s390_r1
, ins
->sreg2
);
4155 s390_lgf (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4156 s390_agr (code
, s390_r1
, s390_r0
);
4157 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4158 s390_jnz (code
, -9);
4159 s390_lgfr(code
, ins
->dreg
, s390_r1
);
4162 case OP_ATOMIC_ADD_NEW_I4
: {
4163 s390_lgfr(code
, s390_r1
, ins
->sreg2
);
4164 s390_lgf (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4165 s390_agr (code
, s390_r1
, s390_r0
);
4166 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4167 s390_jnz (code
, -9);
4168 s390_lgfr(code
, ins
->dreg
, s390_r1
);
4171 case OP_ATOMIC_EXCHANGE_I4
: {
4172 s390_lg (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4173 s390_cs (code
, s390_r0
, ins
->sreg2
, ins
->inst_basereg
, ins
->inst_offset
);
4174 s390_jnz (code
, -4);
4175 s390_lgfr(code
, ins
->dreg
, s390_r0
);
4178 case OP_S390_BKCHAIN
: {
4179 s390_lgr (code
, ins
->dreg
, ins
->sreg1
);
4180 if (s390_is_imm16 (cfg
->stack_offset
)) {
4181 s390_aghi (code
, ins
->dreg
, cfg
->stack_offset
);
4183 s390_basr (code
, s390_r13
, 0);
4185 s390_llong(code
, cfg
->stack_offset
);
4186 s390_ag (code
, ins
->dreg
, 0, s390_r13
, 4);
4190 case OP_MEMORY_BARRIER
: {
4194 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins
->opcode
), __FUNCTION__
);
4195 g_assert_not_reached ();
4198 if ((cfg
->opt
& MONO_OPT_BRANCH
) && ((code
- cfg
->native_code
- offset
) > max_len
)) {
4199 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4200 mono_inst_name (ins
->opcode
), max_len
, code
- cfg
->native_code
- offset
);
4201 g_assert_not_reached ();
4207 last_offset
= offset
;
4212 cfg
->code_len
= code
- cfg
->native_code
;
4215 /*========================= End of Function ========================*/
4217 /*------------------------------------------------------------------*/
4219 /* Name - mono_arch_register_lowlevel_calls */
4221 /* Function - Register routines to help with --trace operation. */
4223 /*------------------------------------------------------------------*/
4226 mono_arch_register_lowlevel_calls (void)
4228 mono_register_jit_icall (mono_arch_break
, "mono_arch_break", NULL
, TRUE
);
4229 mono_register_jit_icall (mono_arch_get_lmf_addr
, "mono_arch_get_lmf_addr", NULL
, TRUE
);
4232 /*========================= End of Function ========================*/
4234 /*------------------------------------------------------------------*/
4236 /* Name - mono_arch_break */
4238 /* Function - Process a "break" operation for debugging. */
4240 /*------------------------------------------------------------------*/
4243 mono_arch_break(void) {
4246 /*========================= End of Function ========================*/
4248 /*------------------------------------------------------------------*/
4250 /* Name - mono_arch_patch_code */
4252 /* Function - Process the patch data created during the */
4253 /* instruction build process. This resolves jumps, */
4254 /* calls, variables etc. */
4256 /*------------------------------------------------------------------*/
4259 mono_arch_patch_code (MonoMethod
*method
, MonoDomain
*domain
,
4260 guint8
*code
, MonoJumpInfo
*ji
, gboolean run_cctors
)
4262 MonoJumpInfo
*patch_info
;
4264 for (patch_info
= ji
; patch_info
; patch_info
= patch_info
->next
) {
4265 unsigned char *ip
= patch_info
->ip
.i
+ code
;
4266 gconstpointer target
= NULL
;
4268 target
= mono_resolve_patch_target (method
, domain
, code
,
4269 patch_info
, run_cctors
);
4271 switch (patch_info
->type
) {
4272 case MONO_PATCH_INFO_IP
:
4273 case MONO_PATCH_INFO_EXC_NAME
:
4274 case MONO_PATCH_INFO_LDSTR
:
4275 case MONO_PATCH_INFO_TYPE_FROM_HANDLE
:
4276 case MONO_PATCH_INFO_LDTOKEN
:
4277 case MONO_PATCH_INFO_EXC
:
4278 case MONO_PATCH_INFO_ABS
:
4279 case MONO_PATCH_INFO_METHOD
:
4280 case MONO_PATCH_INFO_INTERNAL_METHOD
:
4281 case MONO_PATCH_INFO_CLASS_INIT
:
4282 s390_patch_addr (ip
, (guint64
) target
);
4284 case MONO_PATCH_INFO_SWITCH
:
4285 /*----------------------------------*/
4286 /* ip points at the basr r13,0/j +4 */
4287 /* instruction the vtable value */
4288 /* follows this (i.e. ip+6) */
4289 /*----------------------------------*/
4290 *((gconstpointer
*)(ip
+6)) = target
;
4292 case MONO_PATCH_INFO_METHODCONST
:
4293 case MONO_PATCH_INFO_CLASS
:
4294 case MONO_PATCH_INFO_IMAGE
:
4295 case MONO_PATCH_INFO_FIELD
:
4296 case MONO_PATCH_INFO_IID
:
4297 target
= S390_RELATIVE(target
, ip
);
4298 s390_patch_rel (ip
, (guint64
) target
);
4300 case MONO_PATCH_INFO_R4
:
4301 case MONO_PATCH_INFO_R8
:
4302 case MONO_PATCH_INFO_METHOD_REL
:
4303 g_assert_not_reached ();
4306 target
= S390_RELATIVE(target
, ip
);
4308 s390_patch_rel (ip
, (guint64
) target
);
4313 /*========================= End of Function ========================*/
4315 /*------------------------------------------------------------------*/
4317 /* Name - emit_load_volatile_registers */
4319 /* Function - Emit the instructions to reload parameter regist- */
4320 /* registers for use with "tail" operations. */
4322 /* The register loading operations performed here */
4323 /* are the mirror of the store operations performed */
4324 /* in mono_arch_emit_prolog and need to be kept in */
4325 /* synchronization with it. */
4327 /*------------------------------------------------------------------*/
4330 emit_load_volatile_registers (guint8
*code
, MonoCompile
*cfg
)
4333 MonoMethod
*method
= cfg
->method
;
4334 MonoMethodSignature
*sig
= mono_method_signature(method
);
4339 cinfo
= calculate_sizes (sig
, &sz
, sig
->pinvoke
);
4341 if (cinfo
->struct_ret
) {
4342 ArgInfo
*ainfo
= &cinfo
->ret
;
4344 s390_lg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4347 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4348 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4349 inst
= cfg
->varinfo
[pos
];
4351 if (inst
->opcode
== OP_REGVAR
) {
4352 if (ainfo
->regtype
== RegTypeGeneral
)
4353 s390_lgr (code
, ainfo
->reg
, inst
->dreg
);
4354 else if (ainfo
->regtype
== RegTypeFP
) {
4355 if (inst
->dreg
!= ainfo
->reg
) {
4356 if (ainfo
->size
== 4) {
4357 s390_ldebr (code
, ainfo
->reg
, inst
->dreg
);
4359 s390_ldr (code
, ainfo
->reg
, inst
->dreg
);
4363 else if (ainfo
->regtype
== RegTypeBase
) {
4365 g_assert_not_reached ();
4367 if (ainfo
->regtype
== RegTypeGeneral
) {
4368 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4369 g_assert_not_reached();
4370 switch (ainfo
->size
) {
4372 s390_llgc (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4375 s390_lgh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4378 s390_lgf (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4381 s390_lg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4384 } else if (ainfo
->regtype
== RegTypeBase
) {
4385 } else if (ainfo
->regtype
== RegTypeFP
) {
4386 if (ainfo
->size
== 8)
4387 s390_ld (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4388 else if (ainfo
->size
== 4)
4389 s390_le (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4391 g_assert_not_reached ();
4392 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4393 if (ainfo
->reg
!= STK_BASE
) {
4394 switch (ainfo
->size
) {
4396 s390_llgc (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4399 s390_lgh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4402 s390_lgf (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4405 s390_lg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4409 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4410 if (ainfo
->reg
!= STK_BASE
) {
4411 s390_lg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4414 g_assert_not_reached ();
4424 /*========================= End of Function ========================*/
4426 /*------------------------------------------------------------------*/
4428 /* Name - mono_arch_emit_prolog */
4430 /* Function - Create the instruction sequence for a function */
4433 /*------------------------------------------------------------------*/
4436 mono_arch_emit_prolog (MonoCompile
*cfg
)
4438 MonoMethod
*method
= cfg
->method
;
4440 MonoMethodSignature
*sig
;
4442 int alloc_size
, pos
, max_offset
, i
;
4449 cfg
->code_size
= 512;
4451 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
)) {
4453 cfg
->code_size
+= 256;
4456 if (method
->save_lmf
)
4457 cfg
->code_size
+= 200;
4459 cfg
->native_code
= code
= g_malloc (cfg
->code_size
);
4461 s390_stmg (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4463 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
) {
4464 cfg
->used_int_regs
|= 1 << 11;
4467 alloc_size
= cfg
->stack_offset
;
4469 cfg
->stack_usage
= alloc_size
;
4470 s390_lgr (code
, s390_r11
, STK_BASE
);
4471 if (s390_is_uimm16 (alloc_size
)) {
4472 s390_aghi (code
, STK_BASE
, -alloc_size
);
4474 int stackSize
= alloc_size
;
4475 while (stackSize
> 32767) {
4476 s390_aghi (code
, STK_BASE
, -32767);
4479 s390_aghi (code
, STK_BASE
, -stackSize
);
4481 s390_stg (code
, s390_r11
, 0, STK_BASE
, 0);
4483 if (cfg
->frame_reg
!= STK_BASE
)
4484 s390_lgr (code
, s390_r11
, STK_BASE
);
4486 /* compute max_offset in order to use short forward jumps
4487 * we always do it on s390 because the immediate displacement
4488 * for jumps is too small
4491 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
4492 MonoInst
*ins
= bb
->code
;
4493 bb
->max_offset
= max_offset
;
4495 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
)
4499 max_offset
+= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
4504 /* load arguments allocated to register from the stack */
4505 sig
= mono_method_signature (method
);
4508 cinfo
= calculate_sizes (sig
, &sz
, sig
->pinvoke
);
4510 if (cinfo
->struct_ret
) {
4511 ArgInfo
*ainfo
= &cinfo
->ret
;
4513 inst
->backend
.size
= ainfo
->vtsize
;
4514 s390_stg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4517 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4518 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4519 inst
= cfg
->varinfo
[pos
];
4521 if (inst
->opcode
== OP_REGVAR
) {
4522 if (ainfo
->regtype
== RegTypeGeneral
)
4523 s390_lgr (code
, inst
->dreg
, ainfo
->reg
);
4524 else if (ainfo
->regtype
== RegTypeFP
) {
4525 if (inst
->dreg
!= ainfo
->reg
) {
4526 if (ainfo
->size
== 4) {
4527 s390_ledbr (code
, inst
->dreg
, ainfo
->reg
);
4529 s390_ldr (code
, inst
->dreg
, ainfo
->reg
);
4533 else if (ainfo
->regtype
== RegTypeBase
) {
4534 s390_lgr (code
, s390_r13
, STK_BASE
);
4535 s390_aghi (code
, s390_r13
, alloc_size
);
4536 s390_lg (code
, inst
->dreg
, 0, s390_r13
, ainfo
->offset
);
4538 g_assert_not_reached ();
4540 if (cfg
->verbose_level
> 2)
4541 g_print ("Argument %d assigned to register %s\n",
4542 pos
, mono_arch_regname (inst
->dreg
));
4544 if (ainfo
->regtype
== RegTypeGeneral
) {
4545 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4546 g_assert_not_reached();
4547 switch (ainfo
->size
) {
4549 s390_stc (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4552 s390_sth (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4555 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4558 s390_stg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4561 } else if (ainfo
->regtype
== RegTypeBase
) {
4562 } else if (ainfo
->regtype
== RegTypeFP
) {
4563 if (ainfo
->size
== 8)
4564 s390_std (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4565 else if (ainfo
->size
== 4)
4566 s390_ste (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4568 g_assert_not_reached ();
4569 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4570 int doffset
= inst
->inst_offset
;
4572 if (ainfo
->reg
!= STK_BASE
)
4576 s390_lgr (code
, s390_r13
, STK_BASE
);
4577 s390_aghi (code
, s390_r13
, alloc_size
);
4579 switch (ainfo
->size
) {
4581 if (ainfo
->reg
== STK_BASE
)
4582 s390_ic (code
, reg
, 0, s390_r13
, ainfo
->offset
+7);
4583 s390_stc (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4586 if (ainfo
->reg
== STK_BASE
)
4587 s390_lh (code
, reg
, 0, s390_r13
, ainfo
->offset
+6);
4588 s390_sth (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4591 if (ainfo
->reg
== STK_BASE
)
4592 s390_l (code
, reg
, 0, s390_r13
, ainfo
->offset
+4);
4593 s390_st (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4596 if (ainfo
->reg
== STK_BASE
)
4597 s390_lg (code
, reg
, 0, s390_r13
, ainfo
->offset
);
4598 s390_stg (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4601 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4602 s390_stg (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4604 g_assert_not_reached ();
4609 if (method
->save_lmf
) {
4610 /*---------------------------------------------------------------*/
4611 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4612 /*---------------------------------------------------------------*/
4613 lmfOffset
= alloc_size
- sizeof(MonoLMF
);
4615 s390_lgr (code
, s390_r13
, cfg
->frame_reg
);
4616 s390_aghi (code
, s390_r13
, lmfOffset
);
4618 /*---------------------------------------------------------------*/
4619 /* Preserve the parameter registers while we fix up the lmf */
4620 /*---------------------------------------------------------------*/
4621 s390_stmg (code
, s390_r2
, s390_r6
, s390_r13
,
4622 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4624 /*---------------------------------------------------------------*/
4625 /* On return from this call r2 have the address of the &lmf */
4626 /*---------------------------------------------------------------*/
4627 s390_basr(code
, s390_r10
, 0);
4629 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4630 MONO_PATCH_INFO_INTERNAL_METHOD
,
4631 (gpointer
)"mono_get_lmf_addr");
4632 s390_llong(code
, 0);
4633 s390_lg (code
, s390_r1
, 0, s390_r10
, 4);
4634 s390_basr (code
, s390_r14
, s390_r1
);
4636 /*---------------------------------------------------------------*/
4637 /* Set lmf.lmf_addr = jit_tls->lmf */
4638 /*---------------------------------------------------------------*/
4639 s390_stg (code
, s390_r2
, 0, s390_r13
,
4640 G_STRUCT_OFFSET(MonoLMF
, lmf_addr
));
4642 /*---------------------------------------------------------------*/
4643 /* Get current lmf */
4644 /*---------------------------------------------------------------*/
4645 s390_lg (code
, s390_r0
, 0, s390_r2
, 0);
4647 /*---------------------------------------------------------------*/
4648 /* Set our lmf as the current lmf */
4649 /*---------------------------------------------------------------*/
4650 s390_stg (code
, s390_r13
, 0, s390_r2
, 0);
4652 /*---------------------------------------------------------------*/
4653 /* Have our lmf.previous_lmf point to the last lmf */
4654 /*---------------------------------------------------------------*/
4655 s390_stg (code
, s390_r0
, 0, s390_r13
,
4656 G_STRUCT_OFFSET(MonoLMF
, previous_lmf
));
4658 /*---------------------------------------------------------------*/
4659 /* save method info */
4660 /*---------------------------------------------------------------*/
4661 s390_basr (code
, s390_r1
, 0);
4663 s390_llong (code
, method
);
4664 s390_lg (code
, s390_r1
, 0, s390_r1
, 4);
4665 s390_stg (code
, s390_r1
, 0, s390_r13
,
4666 G_STRUCT_OFFSET(MonoLMF
, method
));
4668 /*---------------------------------------------------------------*/
4669 /* save the current IP */
4670 /*---------------------------------------------------------------*/
4671 s390_stg (code
, STK_BASE
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, ebp
));
4672 s390_basr (code
, s390_r1
, 0);
4673 s390_stg (code
, s390_r1
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, eip
));
4675 /*---------------------------------------------------------------*/
4676 /* Save general and floating point registers */
4677 /*---------------------------------------------------------------*/
4678 s390_stmg (code
, s390_r2
, s390_r12
, s390_r13
,
4679 G_STRUCT_OFFSET(MonoLMF
, gregs
[2]));
4680 for (i
= 0; i
< 16; i
++) {
4681 s390_std (code
, i
, 0, s390_r13
,
4682 G_STRUCT_OFFSET(MonoLMF
, fregs
[i
]));
4685 /*---------------------------------------------------------------*/
4686 /* Restore the parameter registers now that we've set up the lmf */
4687 /*---------------------------------------------------------------*/
4688 s390_lmg (code
, s390_r2
, s390_r6
, s390_r13
,
4689 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4693 code
= mono_arch_instrument_prolog(cfg
, enter_method
, code
, TRUE
);
4695 cfg
->code_len
= code
- cfg
->native_code
;
4696 g_assert (cfg
->code_len
< cfg
->code_size
);
4703 /*========================= End of Function ========================*/
4705 /*------------------------------------------------------------------*/
4707 /* Name - mono_arch_emit_epilog */
4709 /* Function - Emit the instructions for a function epilog. */
4711 /*------------------------------------------------------------------*/
4714 mono_arch_emit_epilog (MonoCompile
*cfg
)
4716 MonoMethod
*method
= cfg
->method
;
4719 int max_epilog_size
= 96;
4721 if (cfg
->method
->save_lmf
)
4722 max_epilog_size
+= 128;
4724 if (mono_jit_trace_calls
!= NULL
)
4725 max_epilog_size
+= 128;
4727 if (cfg
->prof_options
& MONO_PROFILE_ENTER_LEAVE
)
4728 max_epilog_size
+= 128;
4730 while ((cfg
->code_len
+ max_epilog_size
) > (cfg
->code_size
- 16)) {
4731 cfg
->code_size
*= 2;
4732 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4733 mono_jit_stats
.code_reallocs
++;
4736 code
= cfg
->native_code
+ cfg
->code_len
;
4738 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
)) {
4739 code
= mono_arch_instrument_epilog (cfg
, leave_method
, code
, TRUE
);
4743 if (method
->save_lmf
)
4744 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
4746 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
)
4747 s390_lg (code
, STK_BASE
, 0, STK_BASE
, 0);
4749 code
= backUpStackPtr(cfg
, code
);
4751 s390_lmg (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4752 s390_br (code
, s390_r14
);
4754 cfg
->code_len
= code
- cfg
->native_code
;
4756 g_assert (cfg
->code_len
< cfg
->code_size
);
4760 /*========================= End of Function ========================*/
4762 /*------------------------------------------------------------------*/
4764 /* Name - mono_arch_emit_exceptions */
4766 /* Function - Emit the blocks to handle exception conditions. */
4768 /*------------------------------------------------------------------*/
4771 mono_arch_emit_exceptions (MonoCompile
*cfg
)
4773 MonoJumpInfo
*patch_info
;
4779 MonoClass
*exc_classes
[MAX_EXC
];
4780 guint8
*exc_throw_start
[MAX_EXC
];
4782 for (patch_info
= cfg
->patch_info
;
4784 patch_info
= patch_info
->next
) {
4785 if (patch_info
->type
== MONO_PATCH_INFO_EXC
)
4789 code_size
= exc_count
* 48;
4791 while ((cfg
->code_len
+ code_size
) > (cfg
->code_size
- 16)) {
4792 cfg
->code_size
*= 2;
4793 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4794 mono_jit_stats
.code_reallocs
++;
4797 code
= cfg
->native_code
+ cfg
->code_len
;
4799 /*---------------------------------------------------------------------*/
4800 /* Add code to raise exceptions */
4801 /*---------------------------------------------------------------------*/
4802 for (patch_info
= cfg
->patch_info
; patch_info
; patch_info
= patch_info
->next
) {
4803 switch (patch_info
->type
) {
4804 case MONO_PATCH_INFO_EXC
: {
4805 guint8
*ip
= patch_info
->ip
.i
+ cfg
->native_code
;
4806 MonoClass
*exc_class
;
4809 /*-----------------------------------------------------*/
4810 /* Patch the branch in epilog to come here */
4811 /*-----------------------------------------------------*/
4812 s390_patch_rel (ip
+ 2, (guint64
) S390_RELATIVE(code
,ip
));
4814 exc_class
= mono_class_from_name (mono_defaults
.corlib
,
4816 patch_info
->data
.name
);
4817 g_assert (exc_class
);
4818 throw_ip
= patch_info
->ip
.i
;
4820 for (iExc
= 0; iExc
< nThrows
; ++iExc
)
4821 if (exc_classes
[iExc
] == exc_class
)
4824 if (iExc
< nThrows
) {
4825 s390_jcl (code
, S390_CC_UN
,
4826 (guint64
) exc_throw_start
[iExc
]);
4827 patch_info
->type
= MONO_PATCH_INFO_NONE
;
4830 if (nThrows
< MAX_EXC
) {
4831 exc_classes
[nThrows
] = exc_class
;
4832 exc_throw_start
[nThrows
] = code
;
4835 /*---------------------------------------------*/
4836 /* Patch the parameter passed to the handler */
4837 /*---------------------------------------------*/
4838 s390_basr (code
, s390_r13
, 0);
4840 s390_llong(code
, patch_info
->data
.target
);
4841 /*---------------------------------------------*/
4842 /* Load return address & parameter register */
4843 /*---------------------------------------------*/
4844 s390_larl (code
, s390_r14
, S390_RELATIVE((patch_info
->ip
.i
+
4845 cfg
->native_code
+ 8), code
));
4846 s390_lg (code
, s390_r2
, 0, s390_r13
, 4);
4847 /*---------------------------------------------*/
4848 /* Reuse the current patch to set the jump */
4849 /*---------------------------------------------*/
4850 s390_basr (code
, s390_r13
, 0);
4852 patch_info
->type
= MONO_PATCH_INFO_INTERNAL_METHOD
;
4853 patch_info
->data
.name
= "mono_arch_throw_exception_by_name";
4854 patch_info
->ip
.i
= code
- cfg
->native_code
;
4855 s390_llong(code
, 0);
4856 s390_lg (code
, s390_r1
, 0, s390_r13
, 4);
4857 s390_br (code
, s390_r1
);
4867 cfg
->code_len
= code
- cfg
->native_code
;
4869 g_assert (cfg
->code_len
< cfg
->code_size
);
4873 /*========================= End of Function ========================*/
4875 /*------------------------------------------------------------------*/
4877 /* Name - mono_arch_setup_jit_tls_data */
4879 /* Function - Setup the JIT's Thread Level Specific Data. */
4881 /*------------------------------------------------------------------*/
4884 mono_arch_setup_jit_tls_data (MonoJitTlsData
*tls
)
4886 if (!tls_offset_inited
) {
4887 tls_offset_inited
= TRUE
;
4891 __asm__ ("\tear\t%r1,0\n"
4898 : "=r" (appdomain_tls_offset
),
4899 "=r" (thread_tls_offset
),
4900 "=r" (lmf_tls_offset
)
4901 : "r" (&tls_appdomain
),
4902 "r" (&tls_current_object
),
4903 "r" (&mono_lmf_addr
)
4909 if (!lmf_addr_key_inited
) {
4910 lmf_addr_key_inited
= TRUE
;
4911 pthread_key_create (&lmf_addr_key
, NULL
);
4913 pthread_setspecific (lmf_addr_key
, &tls
->lmf
);
4917 /*========================= End of Function ========================*/
4919 /*------------------------------------------------------------------*/
4921 /* Name - mono_arch_free_jit_tls_data */
4923 /* Function - Free tls data. */
4925 /*------------------------------------------------------------------*/
4928 mono_arch_free_jit_tls_data (MonoJitTlsData
*tls
)
4933 /*========================= End of Function ========================*/
4935 /*------------------------------------------------------------------*/
4937 /* Name - mono_arch_emit_this_vret_args */
4941 /*------------------------------------------------------------------*/
4944 mono_arch_emit_this_vret_args (MonoCompile
*cfg
, MonoCallInst
*inst
, int this_reg
, int this_type
, int vt_reg
)
4946 int this_dreg
= s390_r2
;
4949 this_dreg
= s390_r3
;
4951 /* add the this argument */
4952 if (this_reg
!= -1) {
4954 MONO_INST_NEW (cfg
, this, OP_SETREG
);
4955 this->type
= this_type
;
4956 this->sreg1
= this_reg
;
4957 this->dreg
= mono_regstate_next_int (cfg
->rs
);
4958 mono_bblock_add_inst (cfg
->cbb
, this);
4959 mono_call_inst_add_outarg_reg (cfg
, inst
, this->dreg
, this_dreg
, FALSE
);
4964 MONO_INST_NEW (cfg
, vtarg
, OP_SETREG
);
4965 vtarg
->type
= STACK_MP
;
4966 vtarg
->sreg1
= vt_reg
;
4967 vtarg
->dreg
= mono_regstate_next_int (cfg
->rs
);
4968 mono_bblock_add_inst (cfg
->cbb
, vtarg
);
4969 mono_call_inst_add_outarg_reg (cfg
, inst
, vtarg
->dreg
, s390_r2
, FALSE
);
4973 /*========================= End of Function ========================*/
4975 /*------------------------------------------------------------------*/
4977 /* Name - mono_arch_get_inst_for_method */
4979 /* Function - Check for opcodes we can handle directly in */
4982 /*------------------------------------------------------------------*/
4985 mono_arch_get_inst_for_method (MonoCompile
*cfg
, MonoMethod
*cmethod
,
4986 MonoMethodSignature
*fsig
, MonoInst
**args
)
4988 MonoInst
*ins
= NULL
;
4990 if (cmethod
->klass
== mono_defaults
.math_class
) {
4991 if (strcmp (cmethod
->name
, "Sqrt") == 0) {
4992 MONO_INST_NEW (cfg
, ins
, OP_SQRT
);
4993 ins
->inst_i0
= args
[0];
4995 // if (strcmp (cmethod->name, "Abs") == 0) {
4996 // MONO_INST_NEW (cfg, ins, OP_ABS);
4997 // ins->inst_i0 = args [0];
4999 } else if (cmethod
->klass
== mono_defaults
.thread_class
&&
5000 strcmp (cmethod
->name
, "MemoryBarrier") == 0) {
5001 MONO_INST_NEW (cfg
, ins
, OP_MEMORY_BARRIER
);
5002 } else if(cmethod
->klass
->image
== mono_defaults
.corlib
&&
5003 (strcmp (cmethod
->klass
->name_space
, "System.Threading") == 0) &&
5004 (strcmp (cmethod
->klass
->name
, "Interlocked") == 0)) {
5006 if (strcmp (cmethod
->name
, "Increment") == 0) {
5007 MonoInst
*ins_iconst
;
5010 if (fsig
->params
[0]->type
== MONO_TYPE_I4
)
5011 opcode
= OP_ATOMIC_ADD_NEW_I4
;
5012 else if (fsig
->params
[0]->type
== MONO_TYPE_I8
)
5013 opcode
= OP_ATOMIC_ADD_NEW_I8
;
5015 g_assert_not_reached ();
5017 MONO_INST_NEW (cfg
, ins
, opcode
);
5018 MONO_INST_NEW (cfg
, ins_iconst
, OP_ICONST
);
5019 ins_iconst
->inst_c0
= 1;
5021 ins
->inst_i0
= args
[0];
5022 ins
->inst_i1
= ins_iconst
;
5023 } else if (strcmp (cmethod
->name
, "Decrement") == 0) {
5024 MonoInst
*ins_iconst
;
5027 if (fsig
->params
[0]->type
== MONO_TYPE_I4
)
5028 opcode
= OP_ATOMIC_ADD_NEW_I4
;
5029 else if (fsig
->params
[0]->type
== MONO_TYPE_I8
)
5030 opcode
= OP_ATOMIC_ADD_NEW_I8
;
5032 g_assert_not_reached ();
5033 MONO_INST_NEW (cfg
, ins
, opcode
);
5034 MONO_INST_NEW (cfg
, ins_iconst
, OP_ICONST
);
5035 ins_iconst
->inst_c0
= -1;
5037 ins
->inst_i0
= args
[0];
5038 ins
->inst_i1
= ins_iconst
;
5040 } else if (strcmp (cmethod
->name
, "Exchange") == 0) {
5043 if (fsig
->params
[0]->type
== MONO_TYPE_I4
)
5044 opcode
= OP_ATOMIC_EXCHANGE_I4
;
5045 else if ((fsig
->params
[0]->type
== MONO_TYPE_I8
) ||
5046 (fsig
->params
[0]->type
== MONO_TYPE_I
) ||
5047 (fsig
->params
[0]->type
== MONO_TYPE_OBJECT
))
5048 opcode
= OP_ATOMIC_EXCHANGE_I8
;
5052 MONO_INST_NEW (cfg
, ins
, opcode
);
5054 ins
->inst_i0
= args
[0];
5055 ins
->inst_i1
= args
[1];
5056 } else if (strcmp (cmethod
->name
, "Add") == 0) {
5059 if (fsig
->params
[0]->type
== MONO_TYPE_I4
)
5060 opcode
= OP_ATOMIC_ADD_I4
;
5061 else if (fsig
->params
[0]->type
== MONO_TYPE_I8
)
5062 opcode
= OP_ATOMIC_ADD_I8
;
5064 g_assert_not_reached ();
5066 MONO_INST_NEW (cfg
, ins
, opcode
);
5068 ins
->inst_i0
= args
[0];
5069 ins
->inst_i1
= args
[1];
5070 } else if ((strcmp (cmethod
->name
, "Read") == 0 &&
5071 (fsig
->params
[0]->type
== MONO_TYPE_I8
))) {
5072 MONO_INST_NEW (cfg
, ins
, CEE_LDIND_I8
);
5073 ins
->inst_i0
= args
[0];
5079 /*========================= End of Function ========================*/
5081 /*------------------------------------------------------------------*/
5083 /* Name - mono_arch_print_tree */
5085 /* Function - Print platform-specific opcode details. */
5087 /* Returns - 1 - opcode details have been printed */
5088 /* 0 - opcode details have not been printed */
5090 /*------------------------------------------------------------------*/
5093 mono_arch_print_tree (MonoInst
*tree
, int arity
)
5097 switch (tree
->opcode
) {
5098 case OP_S390_LOADARG
:
5099 case OP_S390_ARGREG
:
5100 case OP_S390_ARGPTR
:
5101 printf ("[0x%lx(%s)]", tree
->inst_offset
,
5102 mono_arch_regname (tree
->inst_basereg
));
5105 case OP_S390_STKARG
:
5106 printf ("[0x%lx(previous_frame)]",
5111 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5112 tree
->inst_offset
, tree
->backend
.size
,
5113 mono_arch_regname(tree
->dreg
),
5115 mono_arch_regname(tree
->sreg1
));
5118 case OP_S390_SETF4RET
:
5119 printf ("[f%s,f%s]",
5120 mono_arch_regname (tree
->dreg
),
5121 mono_arch_regname (tree
->sreg1
));
5125 printf ("[0x%lx(0x%lx,%s)]", tree
->inst_offset
,
5127 mono_arch_regname (tree
->sreg1
));
5130 case OP_S390_BKCHAIN
:
5131 printf ("[previous_frame(%s)]",
5132 mono_arch_regname (tree
->sreg1
));
5140 /*========================= End of Function ========================*/
5142 /*------------------------------------------------------------------*/
5144 /* Name - mono_arch_regalloc_cost */
5146 /* Function - Determine the cost, in the number of memory */
5147 /* references, of the action of allocating the var- */
5148 /* iable VMV into a register during global register */
5151 /* Returns - Cost */
5153 /*------------------------------------------------------------------*/
5156 mono_arch_regalloc_cost (MonoCompile
*cfg
, MonoMethodVar
*vmv
)
5162 /*========================= End of Function ========================*/
5164 /*------------------------------------------------------------------*/
5166 /* Name - mono_arch_get_domain_intrinsic */
5172 /*------------------------------------------------------------------*/
5175 mono_arch_get_domain_intrinsic (MonoCompile
* cfg
)
5179 if (appdomain_tls_offset
== -1)
5182 MONO_INST_NEW (cfg
, ins
, OP_TLS_GET
);
5183 ins
->inst_offset
= appdomain_tls_offset
;
5187 /*========================= End of Function ========================*/
5189 /*------------------------------------------------------------------*/
5191 /* Name - mono_arch_get_thread_intrinsic */
5197 /*------------------------------------------------------------------*/
5200 mono_arch_get_thread_intrinsic (MonoCompile
* cfg
)
5204 if (thread_tls_offset
== -1)
5207 MONO_INST_NEW (cfg
, ins
, OP_TLS_GET
);
5208 ins
->inst_offset
= thread_tls_offset
;
5212 /*========================= End of Function ========================*/
5214 /*------------------------------------------------------------------*/
5216 /* Name - mono_arch_flush_register_windows */
5222 /*------------------------------------------------------------------*/
5225 mono_arch_flush_register_windows (void)
5229 /*========================= End of Function ========================*/
5231 /*------------------------------------------------------------------*/
5233 /* Name - mono_arch_get_lmf_addr */
5239 /*------------------------------------------------------------------*/
5242 mono_arch_get_lmf_addr (void)
5244 return pthread_getspecific (lmf_addr_key
);
5247 /*========================= End of Function ========================*/
5249 /*------------------------------------------------------------------*/
5251 /* Name - mono_arch_is_inst_imm */
5253 /* Function - Determine if operand qualifies as an immediate */
5254 /* value. For s390 this is a value -32768-32768 */
5256 /* Returns - True|False - is [not] immediate value. */
5258 /*------------------------------------------------------------------*/
5261 mono_arch_is_inst_imm (gint64 imm
)
5263 return s390_is_imm16 (imm
);
5266 /*========================= End of Function ========================*/
5268 /*------------------------------------------------------------------*/
5270 /* Name - opcode_to_cond */
5272 /* Function - Simplify the branch on condition opcode from */
5273 /* more than 20 to just a handful for easy manipu- */
5274 /* lation within the instruction emitting code. */
5276 /* Returns - CMP_xxx - this simplified condition type. */
5278 /*------------------------------------------------------------------*/
5281 opcode_to_cond (int opcode
)
5290 case OP_COND_EXC_EQ
:
5293 case OP_COND_EXC_NE_UN
:
5306 case OP_COND_EXC_LT
:
5314 case OP_COND_EXC_GT
:
5323 case OP_COND_EXC_LE_UN
:
5337 case OP_COND_EXC_LT_UN
:
5340 case OP_COND_EXC_GT_UN
:
5348 printf ("%s\n", mono_inst_name (opcode
));
5349 g_error("Not implemented\n");
5354 /*========================= End of Function ========================*/
5356 /*------------------------------------------------------------------*/
5358 /* Name - mono_arch_get_patch_offset */
5360 /* Function - Dummy entry point until s390x supports aot. */
5362 /* Returns - Offset for patch. */
5364 /*------------------------------------------------------------------*/
5367 mono_arch_get_patch_offset (guint8
*code
)
5372 /*========================= End of Function ========================*/