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 EMIT_COND_BRANCH(ins,cond) \
23 if (ins->inst_true_bb->native_offset) { \
25 displace = ((cfg->native_code + \
26 ins->inst_true_bb->native_offset) - code) / 2; \
27 if (s390_is_imm16(displace)) { \
28 s390_brc (code, cond, displace); \
30 s390_jcl (code, cond, displace); \
33 mono_add_patch_info (cfg, code - cfg->native_code, \
34 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
35 s390_jcl (code, cond, 0); \
39 #define EMIT_UNCOND_BRANCH(ins) \
41 if (ins->inst_target_bb->native_offset) { \
43 displace = ((cfg->native_code + \
44 ins->inst_target_bb->native_offset) - code) / 2; \
45 if (s390_is_imm16(displace)) { \
46 s390_brc (code, S390_CC_UN, displace); \
48 s390_jcl (code, S390_CC_UN, displace); \
51 mono_add_patch_info (cfg, code - cfg->native_code, \
52 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
53 s390_jcl (code, S390_CC_UN, 0); \
57 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
59 mono_add_patch_info (cfg, code - cfg->native_code, \
60 MONO_PATCH_INFO_EXC, exc_name); \
61 s390_jcl (code, cond, 0); \
64 #define CHECK_SRCDST_COM \
65 if (ins->dreg == ins->sreg2) { \
69 if (ins->dreg != ins->sreg1) { \
70 s390_lr (code, ins->dreg, ins->sreg1); \
74 #define CHECK_SRCDST_NCOM \
75 if (ins->dreg == ins->sreg2) { \
77 s390_lr (code, s390_r13, ins->sreg2); \
81 if (ins->dreg != ins->sreg1) { \
82 s390_lr (code, ins->dreg, ins->sreg1); \
85 #define CHECK_SRCDST_COM_F \
86 if (ins->dreg == ins->sreg2) { \
90 if (ins->dreg != ins->sreg1) { \
91 s390_ldr (code, ins->dreg, ins->sreg1); \
95 #define CHECK_SRCDST_NCOM_F \
96 if (ins->dreg == ins->sreg2) { \
98 s390_ldr (code, s390_r13, ins->sreg2); \
102 if (ins->dreg != ins->sreg1) { \
103 s390_ldr (code, ins->dreg, ins->sreg1); \
106 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
110 MONO_INST_NEW (cfg, inst, OP_NOP); \
113 inst->inst_offset = offset; \
115 inst->inst_imm = imm; \
117 if (s390_is_uimm12(offset)) { \
119 inst->inst_offset = offset; \
121 dReg = mono_alloc_preg (cfg); \
122 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
123 dReg, dest, offset); \
125 inst->inst_offset = 0; \
127 if (s390_is_uimm12(imm)) { \
129 inst->inst_imm = imm; \
131 sReg = mono_alloc_preg (cfg); \
132 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
134 inst->sreg1 = sReg; \
135 inst->inst_imm = 0; \
138 inst->opcode = OP_S390_MOVE; \
139 inst->backend.size = size; \
140 MONO_ADD_INS (cfg->cbb, inst); \
143 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
144 int reg = mono_alloc_preg (cfg); \
147 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
148 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
151 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
153 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
156 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
158 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
161 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
163 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
166 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
168 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
169 reg = mono_alloc_preg (cfg); \
170 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
171 reg, sr, so + sizeof (guint32)); \
172 mono_call_inst_add_outarg_reg(cfg, call, reg, dr + 1, FALSE); \
177 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
181 tmpr = mono_alloc_preg (cfg); \
182 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
183 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
187 tmpr = mono_alloc_preg (cfg); \
188 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
190 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
194 tmpr = mono_alloc_preg (cfg); \
195 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
197 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
202 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
208 #define DEBUG(a) if (cfg->verbose_level > 1) a
212 #define S390_TRACE_STACK_SIZE (5*sizeof(gint32)+3*sizeof(gdouble))
214 #define MAX (a, b) ((a) > (b) ? (a) : (b))
216 /*========================= End of Defines =========================*/
218 /*------------------------------------------------------------------*/
219 /* I n c l u d e s */
220 /*------------------------------------------------------------------*/
225 #include <mono/metadata/appdomain.h>
226 #include <mono/metadata/debug-helpers.h>
227 #include <mono/metadata/profiler-private.h>
228 #include <mono/utils/mono-math.h>
230 #include "mini-s390.h"
231 #include "cpu-s390.h"
232 #include "jit-icalls.h"
235 /*========================= End of Includes ========================*/
237 /*------------------------------------------------------------------*/
238 /* T y p e d e f s */
239 /*------------------------------------------------------------------*/
251 /*------------------------------------------------------------------*/
252 /* Used by the instrument_emit_epilog */
253 /*------------------------------------------------------------------*/
264 typedef struct InstList InstList
;
278 RegTypeStructByValInFP
,
283 gint32 offset
; /* offset from caller's stack */
284 gint32 offparm
; /* offset from callee's stack */
285 guint16 vtsize
; /* in param area */
287 ArgStorage regtype
; /* See RegType* */
288 guint32 size
; /* Size of structure used by RegTypeStructByVal */
303 gint32 gr
[5]; /* R2-R6 */
304 gdouble fp
[3]; /* F0-F2 */
305 } __attribute__ ((packed
)) RegParm
;
307 /*========================= End of Typedefs ========================*/
309 /*------------------------------------------------------------------*/
310 /* P r o t o t y p e s */
311 /*------------------------------------------------------------------*/
313 static void indent (int);
314 static guint8
* backUpStackPtr(MonoCompile
*, guint8
*, gint
);
315 static void decodeParm (MonoType
*, void *, int);
316 static void enter_method (MonoMethod
*, RegParm
*, char *);
317 static void leave_method (MonoMethod
*, ...);
318 static gboolean
is_regsize_var (MonoType
*);
319 static inline void add_general (guint
*, size_data
*, ArgInfo
*, gboolean
);
320 static inline void add_stackParm (guint
*, size_data
*, ArgInfo
*, gint
);
321 static inline void add_float (guint
*, size_data
*, ArgInfo
*);
322 static CallInfo
* get_call_info (MonoCompile
*, MonoMemPool
*, MonoMethodSignature
*, gboolean
);
323 static guchar
* emit_float_to_int (MonoCompile
*, guchar
*, int, int, int, gboolean
);
324 gpointer
mono_arch_get_lmf_addr (void);
325 static guint8
* emit_load_volatile_registers(guint8
*, MonoCompile
*);
326 static void emit_sig_cookie (MonoCompile
*, MonoCallInst
*, CallInfo
*);
328 /*========================= End of Prototypes ======================*/
330 /*------------------------------------------------------------------*/
331 /* G l o b a l V a r i a b l e s */
332 /*------------------------------------------------------------------*/
334 int mono_exc_esp_offset
= 0;
336 static int indent_level
= 0;
338 static gboolean tls_offset_inited
= FALSE
;
340 static int appdomain_tls_offset
= -1,
341 thread_tls_offset
= -1;
343 pthread_key_t lmf_addr_key
;
345 gboolean lmf_addr_key_inited
= FALSE
;
349 extern __thread MonoDomain
*tls_appdomain
;
350 extern __thread MonoThread
*tls_current_object
;
351 extern __thread gpointer mono_lmf_addr
;
355 /*====================== End of Global Variables ===================*/
357 /*------------------------------------------------------------------*/
359 /* Name - mono_arch_regname */
361 /* Function - Returns the name of the register specified by */
362 /* the input parameter. */
364 /*------------------------------------------------------------------*/
367 mono_arch_regname (int reg
) {
368 static const char * rnames
[] = {
369 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
370 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
371 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
375 if (reg
>= 0 && reg
< 16)
381 /*========================= End of Function ========================*/
383 /*------------------------------------------------------------------*/
385 /* Name - mono_arch_fregname */
387 /* Function - Returns the name of the register specified by */
388 /* the input parameter. */
390 /*------------------------------------------------------------------*/
393 mono_arch_fregname (int reg
) {
394 static const char * rnames
[] = {
395 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
396 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
397 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
401 if (reg
>= 0 && reg
< 16)
407 /*========================= End of Function ========================*/
409 /*------------------------------------------------------------------*/
411 /* Name - arch_get_argument_info */
413 /* Function - Gathers information on parameters such as size, */
414 /* alignment, and padding. arg_info should be large */
415 /* enough to hold param_count + 1 entries. */
417 /* Parameters - @csig - Method signature */
418 /* @param_count - No. of parameters to consider */
419 /* @arg_info - An array to store the result info */
421 /* Returns - Size of the activation frame */
423 /*------------------------------------------------------------------*/
426 mono_arch_get_argument_info (MonoMethodSignature
*csig
,
428 MonoJitArgumentInfo
*arg_info
)
430 int k
, frame_size
= 0;
431 int size
, align
, pad
;
434 if (MONO_TYPE_ISSTRUCT (csig
->ret
)) {
435 frame_size
+= sizeof (gpointer
);
439 arg_info
[0].offset
= offset
;
442 frame_size
+= sizeof (gpointer
);
446 arg_info
[0].size
= frame_size
;
448 for (k
= 0; k
< param_count
; k
++) {
451 size
= mono_type_native_stack_size (csig
->params
[k
], &align
);
453 size
= mini_type_stack_size (NULL
, csig
->params
[k
], &align
);
455 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
456 arg_info
[k
].pad
= pad
;
458 arg_info
[k
+ 1].pad
= 0;
459 arg_info
[k
+ 1].size
= size
;
461 arg_info
[k
+ 1].offset
= offset
;
465 align
= MONO_ARCH_FRAME_ALIGNMENT
;
466 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
467 arg_info
[k
].pad
= pad
;
472 /*========================= End of Function ========================*/
474 /*------------------------------------------------------------------*/
476 /* Name - retFitsInReg. */
478 /* Function - Determines if a value can be returned in one or */
481 /*------------------------------------------------------------------*/
483 static inline gboolean
484 retFitsInReg(guint32 size
)
499 /*========================= End of Function ========================*/
501 /*------------------------------------------------------------------*/
503 /* Name - backStackPtr. */
505 /* Function - Restore Stack Pointer to previous frame. */
507 /*------------------------------------------------------------------*/
509 static inline guint8
*
510 backUpStackPtr(MonoCompile
*cfg
, guint8
*code
, gint framePtr
)
512 int stackSize
= cfg
->stack_usage
;
514 if (s390_is_uimm16 (cfg
->stack_usage
)) {
515 s390_ahi (code
, framePtr
, cfg
->stack_usage
);
517 while (stackSize
> 32767) {
518 s390_ahi (code
, framePtr
, 32767);
521 s390_ahi (code
, framePtr
, stackSize
);
526 /*========================= End of Function ========================*/
528 /*------------------------------------------------------------------*/
532 /* Function - Perform nice indenting to current level */
534 /*------------------------------------------------------------------*/
540 indent_level
+= diff
;
547 indent_level
+= diff
;
550 /*========================= End of Function ========================*/
552 /*------------------------------------------------------------------*/
554 /* Name - decodeParm */
556 /* Function - Decode a parameter for the trace. */
558 /*------------------------------------------------------------------*/
561 decodeParm(MonoType
*type
, void *curParm
, int size
)
566 printf("[BYREF:%p], ", *((char **) curParm
));
568 simpleType
= mono_type_get_underlying_type(type
)->type
;
570 switch (simpleType
) {
572 printf ("[INTPTR:%p], ", *((int **) curParm
));
575 printf ("[UINTPTR:%p], ", *((int **) curParm
));
577 case MONO_TYPE_BOOLEAN
:
578 printf ("[BOOL:%d], ", *((int *) curParm
));
580 case MONO_TYPE_CHAR
:
581 printf ("[CHAR:%c], ", *((int *) curParm
));
584 printf ("[INT1:%d], ", *((int *) curParm
));
587 printf ("[INT2:%d], ", *((int *) curParm
));
590 printf ("[INT4:%d], ", *((int *) curParm
));
593 printf ("[UINT1:%u], ", *((unsigned int *) curParm
));
596 printf ("[UINT2:%u], ", *((guint16
*) curParm
));
599 printf ("[UINT4:%u], ", *((guint32
*) curParm
));
602 printf ("[UINT8:%llu], ", *((guint64
*) curParm
));
604 case MONO_TYPE_STRING
: {
605 MonoString
*s
= *((MonoString
**) curParm
);
607 g_assert (((MonoObject
*) s
)->vtable
->klass
== mono_defaults
.string_class
);
608 printf("[STRING:%p:%s], ", s
, mono_string_to_utf8(s
));
610 printf("[STRING:null], ");
614 case MONO_TYPE_CLASS
:
615 case MONO_TYPE_OBJECT
: {
616 MonoObject
*obj
= *((MonoObject
**) curParm
);
618 if ((obj
) && (obj
->vtable
)) {
619 printf("[CLASS/OBJ:");
620 class = obj
->vtable
->klass
;
621 printf("%p [%p] ",obj
,curParm
);
622 // if (class == mono_defaults.string_class) {
623 // printf("[STRING:%p:%s]",
624 // *obj, mono_string_to_utf8 (obj));
625 // } else if (class == mono_defaults.int32_class) {
626 // printf("[INT32:%p:%d]",
627 // obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
629 // printf("[%s.%s:%p]",
630 // class->name_space, class->name, obj);
633 printf("[OBJECT:null], ");
638 printf("[PTR:%p], ", *((gpointer
**) (curParm
)));
640 case MONO_TYPE_FNPTR
:
641 printf("[FNPTR:%p], ", *((gpointer
**) (curParm
)));
643 case MONO_TYPE_ARRAY
:
644 printf("[ARRAY:%p], ", *((gpointer
**) (curParm
)));
646 case MONO_TYPE_SZARRAY
:
647 printf("[SZARRAY:%p], ", *((gpointer
**) (curParm
)));
650 printf("[INT8:%lld], ", *((gint64
*) (curParm
)));
653 printf("[FLOAT4:%g], ", *((double *) (curParm
)));
656 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
658 case MONO_TYPE_VALUETYPE
: {
660 MonoMarshalType
*info
;
662 if (type
->data
.klass
->enumtype
) {
663 simpleType
= mono_class_enum_basetype (type
->data
.klass
)->type
;
664 printf("{VALUETYPE} - ");
668 info
= mono_marshal_load_type_info (type
->data
.klass
);
670 if ((info
->native_size
== sizeof(float)) &&
671 (info
->num_fields
== 1) &&
672 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
673 printf("[FLOAT4:%f], ", *((float *) (curParm
)));
677 if ((info
->native_size
== sizeof(double)) &&
678 (info
->num_fields
== 1) &&
679 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
680 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
684 printf("[VALUETYPE:");
685 for (i
= 0; i
< size
; i
++)
686 printf("%02x,", *((guint8
*)curParm
+i
));
690 case MONO_TYPE_TYPEDBYREF
: {
692 printf("[TYPEDBYREF:");
693 for (i
= 0; i
< size
; i
++)
694 printf("%02x,", *((guint8
*)curParm
+i
));
699 printf("[?? - %d], ",simpleType
);
704 /*========================= End of Function ========================*/
708 /*------------------------------------------------------------------*/
710 /* Name - enter_method */
712 /* Function - Perform tracing of the entry to the current */
715 /*------------------------------------------------------------------*/
718 enter_method (MonoMethod
*method
, RegParm
*rParm
, char *sp
)
720 int i
, oParm
= 0, iParm
= 0;
722 MonoMethodSignature
*sig
;
729 fname
= mono_method_full_name (method
, TRUE
);
731 printf ("ENTER: %s(", fname
);
734 ip
= (*(guint32
*) (sp
+S390_RET_ADDR_OFFSET
)) & 0x7fffffff;
735 printf (") ip: %p sp: %p - ", (gpointer
) ip
, sp
);
740 sig
= mono_method_signature (method
);
742 cinfo
= get_call_info (NULL
, NULL
, sig
, sig
->pinvoke
);
744 if (cinfo
->struct_ret
) {
745 printf ("[STRUCTRET:%p], ", (gpointer
) rParm
->gr
[0]);
750 gpointer
*this = (gpointer
*) rParm
->gr
[iParm
];
751 obj
= (MonoObject
*) this;
752 if (method
->klass
->valuetype
) {
754 printf("this:[value:%p:%08x], ",
755 this, *((guint32
*)(this+sizeof(MonoObject
))));
757 printf ("this:[NULL], ");
760 // class = obj->vtable->klass;
761 // if (class == mono_defaults.string_class) {
762 // printf ("this:[STRING:%p:%s], ",
763 // obj, mono_string_to_utf8 ((MonoString *)obj));
765 // printf ("this:%p[%s.%s], ",
766 // obj, class->name_space, class->name);
768 printf("this:%p, ",obj
);
770 printf ("this:NULL, ");
775 for (i
= 0; i
< sig
->param_count
; ++i
) {
776 ainfo
= &cinfo
->args
[i
+ oParm
];
777 switch (ainfo
->regtype
) {
778 case RegTypeGeneral
:
779 decodeParm(sig
->params
[i
], &(rParm
->gr
[ainfo
->reg
-2]), ainfo
->size
);
782 decodeParm(sig
->params
[i
], &(rParm
->fp
[ainfo
->reg
]), ainfo
->size
);
785 decodeParm(sig
->params
[i
], sp
+ainfo
->offset
, ainfo
->size
);
787 case RegTypeStructByVal
:
788 if (ainfo
->reg
!= STK_BASE
)
789 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
791 curParm
= sp
+ainfo
->offset
;
793 if (retFitsInReg (ainfo
->vtsize
))
794 decodeParm(sig
->params
[i
],
798 decodeParm(sig
->params
[i
],
799 *((char **) curParm
),
802 case RegTypeStructByAddr
:
803 if (ainfo
->reg
!= STK_BASE
)
804 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
806 curParm
= sp
+ainfo
->offset
;
808 decodeParm(sig
->params
[i
],
809 *((char **) curParm
),
821 /*========================= End of Function ========================*/
823 /*------------------------------------------------------------------*/
825 /* Name - leave_method */
829 /*------------------------------------------------------------------*/
832 leave_method (MonoMethod
*method
, ...)
839 va_start(ap
, method
);
841 fname
= mono_method_full_name (method
, TRUE
);
843 printf ("LEAVE: %s", fname
);
846 type
= mono_method_signature (method
)->ret
;
849 switch (type
->type
) {
852 case MONO_TYPE_BOOLEAN
: {
853 int val
= va_arg (ap
, int);
855 printf ("[TRUE:%d]", val
);
861 case MONO_TYPE_CHAR
: {
862 int val
= va_arg (ap
, int);
863 printf ("[CHAR:%d]", val
);
867 int val
= va_arg (ap
, int);
868 printf ("[INT1:%d]", val
);
872 int val
= va_arg (ap
, int);
873 printf ("[UINT1:%d]", val
);
877 int val
= va_arg (ap
, int);
878 printf ("[INT2:%d]", val
);
882 int val
= va_arg (ap
, int);
883 printf ("[UINT2:%d]", val
);
887 int val
= va_arg (ap
, int);
888 printf ("[INT4:%d]", val
);
892 int val
= va_arg (ap
, int);
893 printf ("[UINT4:%d]", val
);
897 int val
= va_arg (ap
, int);
898 printf ("[INT:%d]", val
);
903 int val
= va_arg (ap
, int);
904 printf ("[UINT:%d]", val
);
908 case MONO_TYPE_STRING
: {
909 MonoString
*s
= va_arg (ap
, MonoString
*);
912 g_assert (((MonoObject
*)s
)->vtable
->klass
== mono_defaults
.string_class
);
913 printf ("[STRING:%p:%s]", s
, mono_string_to_utf8 (s
));
915 printf ("[STRING:null], ");
918 case MONO_TYPE_CLASS
:
919 case MONO_TYPE_OBJECT
: {
920 MonoObject
*o
= va_arg (ap
, MonoObject
*);
922 // if ((o) && (o->vtable)) {
923 // if (o->vtable->klass == mono_defaults.boolean_class) {
924 // printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
925 // } else if (o->vtable->klass == mono_defaults.int32_class) {
926 // printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
927 // } else if (o->vtable->klass == mono_defaults.int64_class) {
928 // printf ("[INT64:%p:%lld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
930 // printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
932 printf ("[OBJECT:%p]", o
);
937 case MONO_TYPE_FNPTR
:
938 case MONO_TYPE_ARRAY
:
939 case MONO_TYPE_SZARRAY
: {
940 gpointer p
= va_arg (ap
, gpointer
);
941 printf ("[result=%p]", p
);
945 gint64 l
= va_arg (ap
, gint64
);
946 printf ("[LONG:%lld]", l
);
950 guint64 l
= va_arg (ap
, guint64
);
951 printf ("[ULONG:%llu]", l
);
956 f
= va_arg (ap
, double);
957 printf ("[FLOAT4:%g]\n", f
);
961 double f
= va_arg (ap
, double);
962 printf ("[FLOAT8:%g]\n", f
);
965 case MONO_TYPE_VALUETYPE
: {
966 MonoMarshalType
*info
;
967 if (type
->data
.klass
->enumtype
) {
968 type
= mono_class_enum_basetype (type
->data
.klass
);
971 guint8
*p
= va_arg (ap
, gpointer
);
974 info
= mono_marshal_load_type_info (type
->data
.klass
);
976 if ((info
->native_size
== sizeof(float)) &&
977 (info
->num_fields
== 1) &&
978 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
979 double f
= va_arg (ap
, double);
980 printf("[FLOAT4:%g]\n", (double) f
);
984 if ((info
->native_size
== sizeof(double)) &&
985 (info
->num_fields
== 1) &&
986 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
987 double f
= va_arg (ap
, double);
988 printf("[FLOAT8:%g]\n", f
);
992 size
= mono_type_size (type
, &align
);
999 for (j
= 0; p
&& j
< size
; j
++)
1000 printf ("%02x,", p
[j
]);
1004 printf ("[VALUERET]\n");
1009 case MONO_TYPE_TYPEDBYREF
: {
1010 guint8
*p
= va_arg (ap
, gpointer
);
1012 size
= mono_type_size (type
, &align
);
1019 for (j
= 0; p
&& j
< size
; j
++)
1020 printf ("%02x,", p
[j
]);
1024 printf ("[TYPEDBYREF]\n");
1029 printf ("(unknown return type %x)",
1030 mono_method_signature (method
)->ret
->type
);
1033 ip
= ((gint32
) __builtin_return_address (0)) & 0x7fffffff;
1034 printf (" ip: %p\n", (gpointer
) ip
);
1037 /*========================= End of Function ========================*/
1039 /*------------------------------------------------------------------*/
1041 /* Name - mono_arch_cpu_init */
1043 /* Function - Perform CPU specific initialization to execute */
1046 /*------------------------------------------------------------------*/
1049 mono_arch_cpu_init (void)
1053 /*--------------------------------------*/
1054 /* Set default rounding mode for FP */
1055 /*--------------------------------------*/
1056 __asm__ ("SRNM\t%0\n\t"
1060 /*========================= End of Function ========================*/
1064 * Initialize architecture specific code.
1067 mono_arch_init (void)
1072 * Cleanup architecture specific code.
1075 mono_arch_cleanup (void)
1079 /*------------------------------------------------------------------*/
1081 /* Name - mono_arch_cpu_optimizazions */
1083 /* Function - Returns the optimizations supported on this CPU */
1085 /*------------------------------------------------------------------*/
1088 mono_arch_cpu_optimizazions (guint32
*exclude_mask
)
1092 /*----------------------------------------------------------*/
1093 /* no s390-specific optimizations yet */
1094 /*----------------------------------------------------------*/
1095 *exclude_mask
= MONO_OPT_INLINE
|MONO_OPT_LINEARS
;
1096 // *exclude_mask = MONO_OPT_INLINE;
1100 /*========================= End of Function ========================*/
1102 /*------------------------------------------------------------------*/
1108 /*------------------------------------------------------------------*/
1111 is_regsize_var (MonoType
*t
) {
1114 switch (mono_type_get_underlying_type (t
)->type
) {
1120 case MONO_TYPE_FNPTR
:
1122 case MONO_TYPE_OBJECT
:
1123 case MONO_TYPE_STRING
:
1124 case MONO_TYPE_CLASS
:
1125 case MONO_TYPE_SZARRAY
:
1126 case MONO_TYPE_ARRAY
:
1128 case MONO_TYPE_VALUETYPE
:
1129 if (t
->data
.klass
->enumtype
)
1130 return is_regsize_var (mono_class_enum_basetype (t
->data
.klass
));
1136 /*========================= End of Function ========================*/
1138 /*------------------------------------------------------------------*/
1140 /* Name - mono_arch_get_allocatable_int_vars */
1144 /*------------------------------------------------------------------*/
1147 mono_arch_get_allocatable_int_vars (MonoCompile
*cfg
)
1152 for (i
= 0; i
< cfg
->num_varinfo
; i
++) {
1153 MonoInst
*ins
= cfg
->varinfo
[i
];
1154 MonoMethodVar
*vmv
= MONO_VARINFO (cfg
, i
);
1157 if (vmv
->range
.first_use
.abs_pos
>= vmv
->range
.last_use
.abs_pos
)
1160 if (ins
->flags
& (MONO_INST_VOLATILE
|MONO_INST_INDIRECT
) ||
1161 (ins
->opcode
!= OP_LOCAL
&& ins
->opcode
!= OP_ARG
))
1164 /* we can only allocate 32 bit values */
1165 if (is_regsize_var (ins
->inst_vtype
)) {
1166 g_assert (MONO_VARINFO (cfg
, i
)->reg
== -1);
1167 g_assert (i
== vmv
->idx
);
1168 vars
= mono_varlist_insert_sorted (cfg
, vars
, vmv
, FALSE
);
1175 /*========================= End of Function ========================*/
1177 /*------------------------------------------------------------------*/
1179 /* Name - mono_arch_global_int_regs */
1181 /* Function - Return a list of usable integer registers. */
1183 /*------------------------------------------------------------------*/
1186 mono_arch_get_global_int_regs (MonoCompile
*cfg
)
1189 MonoMethodHeader
*header
;
1192 header
= cfg
->header
;
1193 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1194 cfg
->frame_reg
= s390_r11
;
1196 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1198 for (i
= 8; i
< top
; ++i
) {
1199 if (cfg
->frame_reg
!= i
)
1200 regs
= g_list_prepend (regs
, GUINT_TO_POINTER (i
));
1206 /*========================= End of Function ========================*/
1208 /*------------------------------------------------------------------*/
1210 /* Name - mono_arch_flush_icache */
1212 /* Function - Flush the CPU icache. */
1214 /*------------------------------------------------------------------*/
1217 mono_arch_flush_icache (guint8
*code
, gint size
)
1221 /*========================= End of Function ========================*/
1223 /*------------------------------------------------------------------*/
1225 /* Name - mono_arch_is_inst_imm */
1227 /*------------------------------------------------------------------*/
1230 mono_arch_is_inst_imm (gint64 imm
)
1232 /* The lowering pass will take care of it */
1236 /*========================= End of Function ========================*/
1238 /*------------------------------------------------------------------*/
1240 /* Name - add_general */
1242 /* Function - Determine code and stack size incremements for a */
1245 /*------------------------------------------------------------------*/
1248 add_general (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gboolean simple
)
1253 if (*gr
> S390_LAST_ARG_REG
) {
1254 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1255 ainfo
->offset
= sz
->stack_size
;
1256 ainfo
->reg
= STK_BASE
;
1257 ainfo
->regtype
= RegTypeBase
;
1258 sz
->stack_size
+= sizeof(int);
1259 sz
->local_size
+= sizeof(int);
1260 sz
->offStruct
+= sizeof(int);
1261 sz
->code_size
+= 12;
1267 if (*gr
> S390_LAST_ARG_REG
- 1) {
1268 disp
= sz
->stack_size
;
1269 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, S390_STACK_ALIGNMENT
);
1270 disp
= sz
->stack_size
- disp
;
1271 ainfo
->offset
= sz
->stack_size
;
1272 ainfo
->reg
= STK_BASE
;
1273 ainfo
->regtype
= RegTypeBase
;
1274 sz
->stack_size
+= sizeof(long long);
1275 sz
->local_size
+= (sizeof(long long) + disp
);
1276 sz
->offStruct
+= (sizeof(long long) + disp
);
1277 sz
->code_size
+= 10;
1287 /*========================= End of Function ========================*/
1289 /*------------------------------------------------------------------*/
1291 /* Name - add_stackParm */
1293 /* Function - Determine code and stack size incremements for a */
1296 /*------------------------------------------------------------------*/
1299 add_stackParm (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gint size
)
1301 if (*gr
> S390_LAST_ARG_REG
) {
1302 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1303 ainfo
->reg
= STK_BASE
;
1304 ainfo
->offset
= sz
->stack_size
;
1305 sz
->stack_size
+= sizeof (gpointer
);
1306 sz
->parm_size
+= sizeof(gpointer
);
1307 sz
->offStruct
+= sizeof(gpointer
);
1310 ainfo
->offset
= sz
->stack_size
;
1313 ainfo
->offparm
= sz
->offset
;
1314 sz
->offset
= S390_ALIGN(sz
->offset
+size
, sizeof(long));
1316 ainfo
->regtype
= RegTypeStructByAddr
;
1317 ainfo
->vtsize
= size
;
1318 sz
->parm_size
+= size
;
1321 /*========================= End of Function ========================*/
1323 /*------------------------------------------------------------------*/
1325 /* Name - add_float */
1327 /* Function - Determine code and stack size incremements for a */
1328 /* float parameter. */
1330 /*------------------------------------------------------------------*/
1333 add_float (guint
*fr
, size_data
*sz
, ArgInfo
*ainfo
)
1335 if ((*fr
) <= S390_LAST_FPARG_REG
) {
1336 ainfo
->regtype
= RegTypeFP
;
1342 ainfo
->offset
= sz
->stack_size
;
1343 ainfo
->reg
= STK_BASE
;
1344 ainfo
->regtype
= RegTypeBase
;
1346 sz
->stack_size
+= ainfo
->size
;
1347 sz
->local_size
+= ainfo
->size
;
1348 sz
->offStruct
+= ainfo
->size
;
1352 /*========================= End of Function ========================*/
1354 /*------------------------------------------------------------------*/
1356 /* Name - get_call_info */
1358 /* Function - Determine the amount of space required for code */
1359 /* and stack. In addition determine starting points */
1360 /* for stack-based parameters, and area for struct- */
1361 /* ures being returned on the stack. */
1363 /*------------------------------------------------------------------*/
1366 get_call_info (MonoCompile
*cfg
, MonoMemPool
*mp
, MonoMethodSignature
*sig
, gboolean is_pinvoke
)
1368 guint i
, fr
, gr
, size
;
1369 int nParm
= sig
->hasthis
+ sig
->param_count
;
1371 guint32 simpletype
, align
;
1374 MonoGenericSharingContext
*gsctx
= cfg
? cfg
->generic_sharing_context
: NULL
;
1377 cinfo
= mono_mempool_alloc0 (mp
, sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1379 cinfo
= g_malloc0 (sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1384 cinfo
->struct_ret
= 0;
1387 sz
->offStruct
= S390_MINIMAL_STACK_SIZE
;
1389 sz
->stack_size
= S390_MINIMAL_STACK_SIZE
;
1394 /*----------------------------------------------------------*/
1395 /* We determine the size of the return code/stack in case we*/
1396 /* need to reserve a register to be used to address a stack */
1397 /* area that the callee will use. */
1398 /*----------------------------------------------------------*/
1400 ret_type
= mono_type_get_underlying_type (sig
->ret
);
1401 ret_type
= mini_get_basic_type_from_generic (gsctx
, ret_type
);
1402 simpletype
= ret_type
->type
;
1404 switch (simpletype
) {
1405 case MONO_TYPE_BOOLEAN
:
1410 case MONO_TYPE_CHAR
:
1415 case MONO_TYPE_CLASS
:
1416 case MONO_TYPE_OBJECT
:
1417 case MONO_TYPE_SZARRAY
:
1418 case MONO_TYPE_ARRAY
:
1420 case MONO_TYPE_FNPTR
:
1421 case MONO_TYPE_STRING
:
1422 cinfo
->ret
.reg
= s390_r2
;
1427 cinfo
->ret
.reg
= s390_f0
;
1432 cinfo
->ret
.reg
= s390_r2
;
1435 case MONO_TYPE_GENERICINST
:
1436 if (!mono_type_generic_inst_is_valuetype (ret_type
)) {
1437 cinfo
->ret
.reg
= s390_r2
;
1442 case MONO_TYPE_VALUETYPE
: {
1443 MonoClass
*klass
= mono_class_from_mono_type (sig
->ret
);
1444 if (klass
->enumtype
) {
1445 simpletype
= mono_class_enum_basetype (klass
)->type
;
1449 size
= mono_class_native_size (klass
, &align
);
1451 size
= mono_class_value_size (klass
, &align
);
1453 cinfo
->ret
.reg
= s390_r2
;
1454 cinfo
->struct_ret
= 1;
1455 cinfo
->ret
.size
= size
;
1456 cinfo
->ret
.vtsize
= size
;
1460 case MONO_TYPE_TYPEDBYREF
:
1461 size
= sizeof (MonoTypedRef
);
1462 cinfo
->ret
.reg
= s390_r2
;
1463 cinfo
->struct_ret
= 1;
1464 cinfo
->ret
.size
= size
;
1465 cinfo
->ret
.vtsize
= size
;
1468 case MONO_TYPE_VOID
:
1471 g_error ("mini-s390: cannot handle as return value 0x%x (0x%x)", sig
->ret
->type
,simpletype
);
1475 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1476 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1480 /*----------------------------------------------------------*/
1481 /* We determine the size of the parameter code and stack */
1482 /* requirements by checking the types and sizes of the */
1484 /*----------------------------------------------------------*/
1486 for (i
= 0; i
< sig
->param_count
; ++i
) {
1489 /*--------------------------------------------------*/
1490 /* Handle vararg type calls. All args are put on */
1492 /*--------------------------------------------------*/
1493 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1494 (i
== sig
->sentinelpos
)) {
1495 gr
= S390_LAST_ARG_REG
+ 1;
1496 add_general (&gr
, sz
, &cinfo
->sigCookie
, TRUE
);
1499 if (sig
->params
[i
]->byref
) {
1500 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1501 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1506 ptype
= mono_type_get_underlying_type (sig
->params
[i
]);
1507 ptype
= mini_get_basic_type_from_generic (gsctx
, ptype
);
1508 simpletype
= ptype
->type
;
1509 switch (simpletype
) {
1510 case MONO_TYPE_BOOLEAN
:
1513 cinfo
->args
[nParm
].size
= sizeof(char);
1514 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1519 case MONO_TYPE_CHAR
:
1520 cinfo
->args
[nParm
].size
= sizeof(short);
1521 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1526 cinfo
->args
[nParm
].size
= sizeof(int);
1527 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1533 case MONO_TYPE_FNPTR
:
1534 case MONO_TYPE_CLASS
:
1535 case MONO_TYPE_OBJECT
:
1536 case MONO_TYPE_STRING
:
1537 case MONO_TYPE_SZARRAY
:
1538 case MONO_TYPE_ARRAY
:
1539 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1540 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1545 cinfo
->args
[nParm
].size
= sizeof(long long);
1546 add_general (&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1550 cinfo
->args
[nParm
].size
= sizeof(float);
1551 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1555 cinfo
->args
[nParm
].size
= sizeof(double);
1556 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1559 case MONO_TYPE_GENERICINST
:
1560 if (!mono_type_generic_inst_is_valuetype (ptype
)) {
1561 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1562 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1567 case MONO_TYPE_VALUETYPE
: {
1568 MonoMarshalType
*info
;
1569 MonoClass
*klass
= mono_class_from_mono_type (sig
->params
[i
]);
1571 size
= mono_class_native_size (klass
, &align
);
1573 size
= mono_class_value_size (klass
, &align
);
1575 info
= mono_marshal_load_type_info (klass
);
1577 if ((info
->native_size
== sizeof(float)) &&
1578 (info
->num_fields
== 1) &&
1579 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
1580 cinfo
->args
[nParm
].size
= sizeof(float);
1581 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1586 if ((info
->native_size
== sizeof(double)) &&
1587 (info
->num_fields
== 1) &&
1588 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
1589 cinfo
->args
[nParm
].size
= sizeof(double);
1590 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1595 cinfo
->args
[nParm
].vtsize
= 0;
1596 cinfo
->args
[nParm
].size
= 0;
1599 /*----------------------------------*/
1600 /* On S/390, structures of size 1, */
1601 /* 2, 4, and 8 bytes are passed in */
1602 /* (a) register(s). */
1603 /*----------------------------------*/
1608 add_general(&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1609 cinfo
->args
[nParm
].size
= size
;
1610 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1612 sz
->local_size
+= sizeof(long);
1615 add_general(&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1616 cinfo
->args
[nParm
].size
= sizeof(long long);
1617 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1619 sz
->local_size
+= sizeof(long long);
1622 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1627 case MONO_TYPE_TYPEDBYREF
: {
1628 int size
= sizeof (MonoTypedRef
);
1630 cinfo
->args
[nParm
].vtsize
= 0;
1631 cinfo
->args
[nParm
].size
= 0;
1634 /*----------------------------------*/
1635 /* On S/390, structures of size 1, */
1636 /* 2, 4, and 8 bytes are passed in */
1637 /* (a) register(s). */
1638 /*----------------------------------*/
1643 add_general(&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1644 cinfo
->args
[nParm
].size
= size
;
1645 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1647 sz
->local_size
+= sizeof(long);
1650 add_general(&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1651 cinfo
->args
[nParm
].size
= sizeof(long long);
1652 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1654 sz
->local_size
+= sizeof(long long);
1657 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1663 g_error ("Can't trampoline 0x%x", sig
->params
[i
]->type
);
1667 /*----------------------------------------------------------*/
1668 /* If we are passing a structure back then if it won't be */
1669 /* in a register(s) then we make room at the end of the */
1670 /* parameters that may have been placed on the stack */
1671 /*----------------------------------------------------------*/
1672 if (cinfo
->struct_ret
) {
1673 cinfo
->ret
.offset
= sz
->stack_size
;
1674 switch (cinfo
->ret
.size
) {
1682 sz
->stack_size
+= S390_ALIGN(cinfo
->ret
.size
, align
);
1686 /*----------------------------------------------------------*/
1687 /* Handle the case where there are no implicit arguments */
1688 /*----------------------------------------------------------*/
1689 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1690 (sig
->param_count
== sig
->sentinelpos
)) {
1691 gr
= S390_LAST_ARG_REG
+ 1;
1692 add_general (&gr
, sz
, &cinfo
->sigCookie
, TRUE
);
1696 sz
->stack_size
= sz
->stack_size
+ sz
->local_size
+ sz
->parm_size
+
1698 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1703 /*========================= End of Function ========================*/
1705 /*------------------------------------------------------------------*/
1707 /* Name - mono_arch_allocate_vars */
1709 /* Function - Set var information according to the calling */
1710 /* convention for S/390. The local var stuff should */
1711 /* most likely be split in another method. */
1713 /* Parameter - @m - Compile unit. */
1715 /*------------------------------------------------------------------*/
1718 mono_arch_allocate_vars (MonoCompile
*cfg
)
1720 MonoMethodSignature
*sig
;
1721 MonoMethodHeader
*header
;
1724 int iParm
, iVar
, offset
, size
, align
, curinst
;
1725 int frame_reg
= STK_BASE
;
1728 header
= cfg
->header
;
1730 cfg
->flags
|= MONO_CFG_HAS_SPILLUP
;
1732 sig
= mono_method_signature (cfg
->method
);
1734 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1736 /*---------------------------------------------------------*/
1737 /* We use the frame register also for any method that has */
1738 /* filter clauses. This way, when the handlers are called, */
1739 /* the code will reference local variables using the frame */
1740 /* reg instead of the stack pointer: if we had to restore */
1741 /* the stack pointer, we'd corrupt the method frames that */
1742 /* are already on the stack (since filters get called */
1743 /* before stack unwinding happens) when the filter code */
1744 /* would call any method. */
1745 /*---------------------------------------------------------*/
1746 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1747 frame_reg
= s390_r11
;
1749 cfg
->frame_reg
= frame_reg
;
1751 cfg
->arch
.bkchain_reg
= -1;
1753 if (frame_reg
!= STK_BASE
)
1754 cfg
->used_int_regs
|= 1 << frame_reg
;
1756 sig
= mono_method_signature (cfg
->method
);
1758 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1760 if (!cinfo
->struct_ret
) {
1761 switch (mono_type_get_underlying_type (sig
->ret
)->type
) {
1762 case MONO_TYPE_VOID
:
1765 cfg
->ret
->opcode
= OP_REGVAR
;
1766 cfg
->ret
->dreg
= s390_r2
;
1771 /*--------------------------------------------------------------*/
1772 /* local vars are at a positive offset from the stack pointer */
1773 /* also note that if the function uses alloca, we use s390_r11 */
1774 /* to point at the local variables. */
1775 /* add parameter area size for called functions */
1776 /*--------------------------------------------------------------*/
1777 offset
= (cfg
->param_area
+ S390_MINIMAL_STACK_SIZE
);
1778 cfg
->sig_cookie
= 0;
1780 if (cinfo
->struct_ret
) {
1781 inst
= cfg
->vret_addr
;
1782 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1783 inst
->inst_offset
= offset
;
1784 inst
->opcode
= OP_REGOFFSET
;
1785 inst
->inst_basereg
= frame_reg
;
1786 offset
+= sizeof(gpointer
);
1787 if (G_UNLIKELY (cfg
->verbose_level
> 1)) {
1788 printf ("vret_addr =");
1789 mono_print_ins (cfg
->vret_addr
);
1794 inst
= cfg
->args
[0];
1795 if (inst
->opcode
!= OP_REGVAR
) {
1796 inst
->opcode
= OP_REGOFFSET
;
1797 inst
->inst_basereg
= frame_reg
;
1798 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1799 inst
->inst_offset
= offset
;
1800 offset
+= sizeof (gpointer
);
1807 eArg
= sig
->param_count
+ sArg
;
1809 if (sig
->call_convention
== MONO_CALL_VARARG
)
1810 cfg
->sig_cookie
+= S390_MINIMAL_STACK_SIZE
;
1812 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1813 inst
= cfg
->args
[curinst
];
1814 if (inst
->opcode
!= OP_REGVAR
) {
1815 switch (cinfo
->args
[iParm
].regtype
) {
1816 case RegTypeStructByAddr
: {
1819 size
= sizeof (gpointer
);
1821 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1822 cfg
->arch
.bkchain_reg
= s390_r12
;
1823 cfg
->used_int_regs
|= 1 << cfg
->arch
.bkchain_reg
;
1825 inst
->opcode
= OP_REGOFFSET
;
1826 inst
->inst_basereg
= cfg
->arch
.bkchain_reg
;
1827 inst
->inst_offset
= cinfo
->args
[iParm
].offset
;
1829 inst
->opcode
= OP_REGOFFSET
;
1830 inst
->inst_basereg
= frame_reg
;
1831 inst
->inst_offset
= S390_ALIGN(offset
, sizeof (gpointer
));
1834 /* Add a level of indirection */
1835 MONO_INST_NEW (cfg
, indir
, 0);
1837 inst
->opcode
= OP_VTARG_ADDR
;
1838 inst
->inst_left
= indir
;
1841 case RegTypeStructByVal
:
1842 size
= cinfo
->args
[iParm
].size
;
1843 offset
= S390_ALIGN(offset
, size
);
1844 inst
->opcode
= OP_REGOFFSET
;
1845 inst
->inst_basereg
= frame_reg
;
1846 inst
->inst_offset
= S390_ALIGN (offset
, size
);
1849 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1851 * These arguments are in the previous frame, so we can't
1852 * compute their offset from the current frame pointer right
1853 * now, since cfg->stack_offset is not yet known, so dedicate a
1854 * register holding the previous frame pointer.
1856 cfg
->arch
.bkchain_reg
= s390_r12
;
1857 cfg
->used_int_regs
|= 1 << cfg
->arch
.bkchain_reg
;
1859 inst
->opcode
= OP_REGOFFSET
;
1860 inst
->inst_basereg
= cfg
->arch
.bkchain_reg
;
1861 size
= (cinfo
->args
[iParm
].size
< 4
1862 ? 4 - cinfo
->args
[iParm
].size
1864 inst
->inst_offset
= cinfo
->args
[iParm
].offset
+ size
;
1865 size
= sizeof (long);
1867 inst
->opcode
= OP_REGOFFSET
;
1868 inst
->inst_basereg
= frame_reg
;
1869 size
= (cinfo
->args
[iParm
].size
< 8
1871 : sizeof(long long));
1872 offset
= S390_ALIGN(offset
, size
);
1873 inst
->inst_offset
= offset
;
1876 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1877 (cinfo
->args
[iParm
].regtype
!= RegTypeGeneral
) &&
1878 (iParm
< sig
->sentinelpos
))
1879 cfg
->sig_cookie
+= size
;
1886 curinst
= cfg
->locals_start
;
1887 for (iVar
= curinst
; iVar
< cfg
->num_varinfo
; ++iVar
) {
1888 inst
= cfg
->varinfo
[iVar
];
1889 if ((inst
->flags
& MONO_INST_IS_DEAD
) ||
1890 (inst
->opcode
== OP_REGVAR
))
1893 /*--------------------------------------------------*/
1894 /* inst->backend.is_pinvoke indicates native sized value types, */
1895 /* this is used by the pinvoke wrappers when they */
1896 /* call functions returning structure */
1897 /*--------------------------------------------------*/
1898 if (inst
->backend
.is_pinvoke
&& MONO_TYPE_ISSTRUCT (inst
->inst_vtype
))
1899 size
= mono_class_native_size (mono_class_from_mono_type(inst
->inst_vtype
), &align
);
1901 size
= mono_type_size (inst
->inst_vtype
, &align
);
1903 offset
= S390_ALIGN(offset
, align
);
1904 inst
->inst_offset
= offset
;
1905 inst
->opcode
= OP_REGOFFSET
;
1906 inst
->inst_basereg
= frame_reg
;
1908 DEBUG (g_print("allocating local %d to %ld\n", iVar
, inst
->inst_offset
));
1911 /*------------------------------------------------------*/
1912 /* Allow space for the trace method stack area if needed*/
1913 /*------------------------------------------------------*/
1914 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (cfg
->method
)) {
1915 offset
+= S390_TRACE_STACK_SIZE
;
1918 /*------------------------------------------------------*/
1919 /* Reserve space to save LMF and caller saved registers */
1920 /*------------------------------------------------------*/
1921 if (cfg
->method
->save_lmf
)
1922 offset
+= sizeof (MonoLMF
);
1924 /*------------------------------------------------------*/
1925 /* align the offset */
1926 /*------------------------------------------------------*/
1927 cfg
->stack_offset
= S390_ALIGN(offset
, S390_STACK_ALIGNMENT
);
1929 /* Fix up offsets for arguments whose value is in the parent frame */
1930 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1931 inst
= cfg
->args
[iParm
];
1933 if (inst
->opcode
== OP_S390_STKARG
) {
1934 inst
->opcode
= OP_REGOFFSET
;
1935 inst
->inst_offset
+= cfg
->stack_offset
;
1940 /*========================= End of Function ========================*/
1942 /*------------------------------------------------------------------*/
1944 /* Name - mono_arch_create_vars */
1946 /*------------------------------------------------------------------*/
1949 mono_arch_create_vars (MonoCompile
*cfg
)
1951 MonoMethodSignature
*sig
;
1954 sig
= mono_method_signature (cfg
->method
);
1956 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1958 if (cinfo
->struct_ret
) {
1959 cfg
->vret_addr
= mono_compile_create_var (cfg
, &mono_defaults
.int_class
->byval_arg
, OP_ARG
);
1960 if (G_UNLIKELY (cfg
->verbose_level
> 1)) {
1961 printf ("vret_addr = ");
1962 mono_print_ins (cfg
->vret_addr
);
1967 /*========================= End of Function ========================*/
1970 add_outarg_reg2 (MonoCompile
*cfg
, MonoCallInst
*call
, ArgStorage storage
, int reg
, MonoInst
*tree
)
1975 case RegTypeGeneral
:
1976 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
1977 ins
->dreg
= mono_alloc_ireg (cfg
);
1978 ins
->sreg1
= tree
->dreg
;
1979 MONO_ADD_INS (cfg
->cbb
, ins
);
1980 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, FALSE
);
1983 MONO_INST_NEW (cfg
, ins
, OP_FMOVE
);
1984 ins
->dreg
= mono_alloc_freg (cfg
);
1985 ins
->sreg1
= tree
->dreg
;
1986 MONO_ADD_INS (cfg
->cbb
, ins
);
1987 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, TRUE
);
1990 MONO_INST_NEW (cfg
, ins
, OP_S390_SETF4RET
);
1991 ins
->dreg
= mono_alloc_freg (cfg
);
1992 ins
->sreg1
= tree
->dreg
;
1993 MONO_ADD_INS (cfg
->cbb
, ins
);
1994 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, TRUE
);
1997 g_assert_not_reached ();
2002 emit_sig_cookie (MonoCompile
*cfg
, MonoCallInst
*call
, CallInfo
*cinfo
)
2004 MonoMethodSignature
*tmpSig
;
2007 cfg
->disable_aot
= TRUE
;
2009 /*----------------------------------------------------------*/
2010 /* mono_ArgIterator_Setup assumes the signature cookie is */
2011 /* passed first and all the arguments which were before it */
2012 /* passed on the stack after the signature. So compensate */
2013 /* by passing a different signature. */
2014 /*----------------------------------------------------------*/
2015 tmpSig
= mono_metadata_signature_dup (call
->signature
);
2016 tmpSig
->param_count
-= call
->signature
->sentinelpos
;
2017 tmpSig
->sentinelpos
= 0;
2018 if (tmpSig
->param_count
> 0)
2019 memcpy (tmpSig
->params
,
2020 call
->signature
->params
+ call
->signature
->sentinelpos
,
2021 tmpSig
->param_count
* sizeof(MonoType
*));
2023 MONO_INST_NEW (cfg
, sig_arg
, OP_ICONST
);
2024 sig_arg
->dreg
= mono_alloc_ireg (cfg
);
2025 sig_arg
->inst_p0
= tmpSig
;
2026 MONO_ADD_INS (cfg
->cbb
, sig_arg
);
2028 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORE_MEMBASE_REG
, STK_BASE
,
2029 cinfo
->sigCookie
.offset
, sig_arg
->dreg
);
2032 /*------------------------------------------------------------------*/
2034 /* Name - mono_arch_emit_call */
2036 /*------------------------------------------------------------------*/
2039 mono_arch_emit_call (MonoCompile
*cfg
, MonoCallInst
*call
)
2042 MonoMethodSignature
*sig
;
2044 int i
, n
, lParamArea
;
2046 ArgInfo
*ainfo
= NULL
;
2049 sig
= call
->signature
;
2050 n
= sig
->param_count
+ sig
->hasthis
;
2051 DEBUG (g_print ("Call requires: %d parameters\n",n
));
2053 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
2055 stackSize
= cinfo
->sz
.stack_size
+ cinfo
->sz
.local_size
+ cinfo
->sz
.parm_size
+ cinfo
->sz
.offset
;
2056 call
->stack_usage
= MAX(stackSize
, call
->stack_usage
);
2057 lParamArea
= MAX((call
->stack_usage
-S390_MINIMAL_STACK_SIZE
-cinfo
->sz
.parm_size
), 0);
2058 cfg
->param_area
= MAX(((signed) cfg
->param_area
), lParamArea
);
2059 cfg
->flags
|= MONO_CFG_HAS_CALLS
;
2061 if (cinfo
->struct_ret
) {
2062 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2063 ins
->sreg1
= call
->vret_var
->dreg
;
2064 ins
->dreg
= mono_alloc_preg (cfg
);
2065 MONO_ADD_INS (cfg
->cbb
, ins
);
2066 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, cinfo
->ret
.reg
, FALSE
);
2069 for (i
= 0; i
< n
; ++i
) {
2070 ainfo
= cinfo
->args
+ i
;
2073 if (i
>= sig
->hasthis
)
2074 t
= sig
->params
[i
- sig
->hasthis
];
2076 t
= &mono_defaults
.int_class
->byval_arg
;
2077 t
= mono_type_get_underlying_type (t
);
2079 in
= call
->args
[i
];
2081 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
2082 (i
== sig
->sentinelpos
)) {
2083 emit_sig_cookie (cfg
, call
, cinfo
);
2086 switch (ainfo
->regtype
) {
2087 case RegTypeGeneral
:
2088 if (!t
->byref
&& (t
->type
== MONO_TYPE_I8
|| t
->type
== MONO_TYPE_U8
)) {
2089 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2090 ins
->dreg
= mono_alloc_ireg (cfg
);
2091 ins
->sreg1
= in
->dreg
+ 2;
2092 MONO_ADD_INS (cfg
->cbb
, ins
);
2093 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, ainfo
->reg
, FALSE
);
2094 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2095 ins
->dreg
= mono_alloc_ireg (cfg
);
2096 ins
->sreg1
= in
->dreg
+ 1;
2097 MONO_ADD_INS (cfg
->cbb
, ins
);
2098 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, ainfo
->reg
+ 1, FALSE
);
2100 add_outarg_reg2 (cfg
, call
, ainfo
->regtype
, ainfo
->reg
, in
);
2104 if (MONO_TYPE_ISSTRUCT (t
)) {
2105 /* Valuetype passed in one fp register */
2106 ainfo
->regtype
= RegTypeStructByValInFP
;
2109 if (ainfo
->size
== 4)
2110 ainfo
->regtype
= RegTypeFPR4
;
2111 add_outarg_reg2 (cfg
, call
, ainfo
->regtype
, ainfo
->reg
, in
);
2114 case RegTypeStructByVal
:
2115 case RegTypeStructByAddr
: {
2119 if (sig
->params
[i
- sig
->hasthis
]->type
== MONO_TYPE_TYPEDBYREF
) {
2120 size
= sizeof (MonoTypedRef
);
2121 align
= sizeof (gpointer
);
2125 size
= mono_type_native_stack_size (&in
->klass
->byval_arg
, &align
);
2128 * Other backends use mono_type_stack_size (), but that
2129 * aligns the size to 8, which is larger than the size of
2130 * the source, leading to reads of invalid memory if the
2131 * source is at the end of address space.
2133 size
= mono_class_value_size (in
->klass
, &align
);
2136 g_assert (in
->klass
);
2138 ainfo
->offparm
+= cinfo
->sz
.offStruct
;
2140 MONO_INST_NEW (cfg
, ins
, OP_OUTARG_VT
);
2141 ins
->sreg1
= in
->dreg
;
2142 ins
->klass
= in
->klass
;
2143 ins
->backend
.size
= ainfo
->size
;
2144 ins
->inst_p0
= call
;
2145 ins
->inst_p1
= mono_mempool_alloc (cfg
->mempool
, sizeof (ArgInfo
));
2146 memcpy (ins
->inst_p1
, ainfo
, sizeof (ArgInfo
));
2148 MONO_ADD_INS (cfg
->cbb
, ins
);
2150 if (ainfo
->regtype
== RegTypeStructByAddr
) {
2152 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2153 * use the normal OUTARG opcodes to pass the address of the location to
2156 int treg
= mono_alloc_preg (cfg
);
2157 MONO_EMIT_NEW_BIALU_IMM (cfg
, OP_ADD_IMM
, treg
,
2158 STK_BASE
, ainfo
->offparm
);
2159 if (ainfo
->reg
== STK_BASE
) {
2160 /* The address is passed on the stack */
2161 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2162 ins
->inst_destbasereg
= STK_BASE
;
2163 ins
->inst_offset
= ainfo
->offset
;
2165 MONO_ADD_INS (cfg
->cbb
, ins
);
2167 mono_call_inst_add_outarg_reg (cfg
, call
, treg
, ainfo
->reg
, FALSE
);
2173 if (!t
->byref
&& t
->type
== MONO_TYPE_R4
) {
2174 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORER4_MEMBASE_REG
,
2175 STK_BASE
, ainfo
->offset
,
2177 } else if (!t
->byref
&& (t
->type
== MONO_TYPE_R8
)) {
2178 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORER8_MEMBASE_REG
,
2179 STK_BASE
, ainfo
->offset
,
2181 } else if (!t
->byref
&& (t
->type
== MONO_TYPE_I8
|| t
->type
== MONO_TYPE_U8
)) {
2182 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2183 ins
->inst_destbasereg
= STK_BASE
;
2184 ins
->inst_offset
= ainfo
->offset
+ MINI_LS_WORD_OFFSET
;
2185 ins
->sreg1
= in
->dreg
+ 1;
2186 MONO_ADD_INS (cfg
->cbb
, ins
);
2188 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2189 ins
->inst_destbasereg
= STK_BASE
;
2190 ins
->inst_offset
= ainfo
->offset
+ MINI_MS_WORD_OFFSET
;
2191 ins
->sreg1
= in
->dreg
+ 2;
2192 MONO_ADD_INS (cfg
->cbb
, ins
);
2194 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2195 ins
->inst_destbasereg
= STK_BASE
;
2196 ins
->inst_offset
= ainfo
->offset
;
2197 ins
->sreg1
= in
->dreg
;
2198 MONO_ADD_INS (cfg
->cbb
, ins
);
2202 g_assert_not_reached ();
2208 * Handle the case where there are no implicit arguments
2210 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
2211 (i
== sig
->sentinelpos
)) {
2212 emit_sig_cookie (cfg
, call
, cinfo
);
2216 /*========================= End of Function ========================*/
2218 /*------------------------------------------------------------------*/
2220 /* Name - mono_arch_emit_outarg_vt */
2222 /*------------------------------------------------------------------*/
2225 mono_arch_emit_outarg_vt (MonoCompile
*cfg
, MonoInst
*ins
, MonoInst
*src
)
2227 MonoCallInst
*call
= (MonoCallInst
*)ins
->inst_p0
;
2228 ArgInfo
*ainfo
= (ArgInfo
*)ins
->inst_p1
;
2229 int size
= ins
->backend
.size
;
2231 if (ainfo
->regtype
== RegTypeStructByVal
) {
2233 arg->ins.sreg1 = ainfo->reg;
2234 arg->ins.opcode = OP_OUTARG_VT;
2235 arg->size = ainfo->size;
2236 arg->offset = ainfo->offset;
2237 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2239 if (ainfo
->reg
!= STK_BASE
) {
2240 MONO_OUTPUT_VTR (cfg
, size
, ainfo
->reg
, src
->dreg
, 0);
2242 MONO_OUTPUT_VTS (cfg
, size
, ainfo
->reg
, ainfo
->offset
,
2245 } else if (ainfo
->regtype
== RegTypeStructByValInFP
) {
2246 int dreg
= mono_alloc_freg (cfg
);
2248 if (ainfo
->size
== 4) {
2249 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg
, OP_LOADR4_MEMBASE
, dreg
, src
->dreg
, 0);
2250 MONO_EMIT_NEW_UNALU (cfg
, OP_S390_SETF4RET
, dreg
, dreg
);
2252 g_assert (ainfo
->size
== 8);
2254 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg
, OP_LOADR8_MEMBASE
, dreg
, src
->dreg
, 0);
2257 mono_call_inst_add_outarg_reg (cfg
, call
, dreg
, ainfo
->reg
, TRUE
);
2259 MONO_EMIT_NEW_MOVE (cfg
, STK_BASE
, ainfo
->offparm
,
2260 src
->dreg
, 0, size
);
2264 /*------------------------------------------------------------------*/
2266 /* Name - mono_arch_emit_setret */
2268 /*------------------------------------------------------------------*/
2271 mono_arch_emit_setret (MonoCompile
*cfg
, MonoMethod
*method
, MonoInst
*val
)
2273 MonoType
*ret
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
);
2276 if (ret
->type
== MONO_TYPE_R4
) {
2277 MONO_EMIT_NEW_UNALU (cfg
, OP_S390_SETF4RET
, s390_f0
, val
->dreg
);
2279 } else if (ret
->type
== MONO_TYPE_R8
) {
2280 MONO_EMIT_NEW_UNALU (cfg
, OP_FMOVE
, s390_f0
, val
->dreg
);
2282 } else if (ret
->type
== MONO_TYPE_I8
|| ret
->type
== MONO_TYPE_U8
) {
2283 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r3
, val
->dreg
+ 1);
2284 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r2
, val
->dreg
+ 2);
2289 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, cfg
->ret
->dreg
, val
->dreg
);
2292 /*========================= End of Function ========================*/
2294 /*------------------------------------------------------------------*/
2296 /* Name - mono_arch_instrument_mem_needs */
2298 /* Function - Allow tracing to work with this interface (with */
2299 /* an optional argument). */
2301 /*------------------------------------------------------------------*/
2304 mono_arch_instrument_mem_needs (MonoMethod
*method
, int *stack
, int *code
)
2306 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2308 /* split prolog-epilog requirements? */
2309 *code
= 50; /* max bytes needed: check this number */
2312 /*========================= End of Function ========================*/
2314 /*------------------------------------------------------------------*/
2316 /* Name - mono_arch_instrument_prolog */
2318 /* Function - Create an "instrumented" prolog. */
2320 /*------------------------------------------------------------------*/
2323 mono_arch_instrument_prolog (MonoCompile
*cfg
, void *func
, void *p
,
2324 gboolean enable_arguments
)
2331 parmOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2332 if (cfg
->method
->save_lmf
)
2333 parmOffset
-= sizeof(MonoLMF
);
2334 fpOffset
= parmOffset
+ (5*sizeof(gint32
));
2335 if (fpOffset
> 4096) {
2336 s390_lr (code
, s390_r12
, STK_BASE
);
2338 while (fpOffset
> 4096) {
2339 s390_ahi (code
, baseReg
, 4096);
2347 s390_stm (code
, s390_r2
, s390_r6
, baseReg
, parmOffset
);
2348 s390_std (code
, s390_f0
, 0, baseReg
, fpOffset
);
2349 s390_std (code
, s390_f1
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2350 s390_std (code
, s390_f2
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2351 s390_basr (code
, s390_r13
, 0);
2353 s390_word (code
, cfg
->method
);
2354 s390_word (code
, func
);
2355 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
2356 s390_la (code
, s390_r3
, 0, baseReg
, parmOffset
);
2357 s390_lr (code
, s390_r4
, STK_BASE
);
2358 s390_ahi (code
, s390_r4
, cfg
->stack_usage
);
2359 s390_l (code
, s390_r1
, 0, s390_r13
, 8);
2360 s390_basr (code
, s390_r14
, s390_r1
);
2361 s390_ld (code
, s390_f2
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2362 s390_ld (code
, s390_f1
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2363 s390_ld (code
, s390_f0
, 0, baseReg
, fpOffset
);
2364 s390_lm (code
, s390_r2
, s390_r6
, baseReg
, parmOffset
);
2369 /*========================= End of Function ========================*/
2371 /*------------------------------------------------------------------*/
2373 /* Name - mono_arch_instrument_epilog */
2375 /* Function - Create an epilog that will handle the returned */
2376 /* values used in instrumentation. */
2378 /*------------------------------------------------------------------*/
2381 mono_arch_instrument_epilog_full (MonoCompile
*cfg
, void *func
, void *p
, gboolean enable_arguments
, gboolean preserve_argument_registers
)
2384 int save_mode
= SAVE_NONE
,
2386 MonoMethod
*method
= cfg
->method
;
2387 int rtype
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
)->type
;
2389 saveOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2390 if (method
->save_lmf
)
2391 saveOffset
-= sizeof(MonoLMF
);
2395 case MONO_TYPE_VOID
:
2396 /* special case string .ctor icall */
2397 if (strcmp (".ctor", method
->name
) && method
->klass
== mono_defaults
.string_class
)
2398 save_mode
= SAVE_ONE
;
2400 save_mode
= SAVE_NONE
;
2404 save_mode
= SAVE_TWO
;
2407 save_mode
= SAVE_R4
;
2410 save_mode
= SAVE_R8
;
2412 case MONO_TYPE_VALUETYPE
:
2413 if (mono_method_signature (method
)->ret
->data
.klass
->enumtype
) {
2414 rtype
= mono_class_enum_basetype (mono_method_signature (method
)->ret
->data
.klass
)->type
;
2417 save_mode
= SAVE_STRUCT
;
2420 save_mode
= SAVE_ONE
;
2424 switch (save_mode
) {
2426 s390_stm (code
, s390_r2
, s390_r3
, cfg
->frame_reg
, saveOffset
);
2427 if (enable_arguments
) {
2428 s390_lr (code
, s390_r4
, s390_r3
);
2429 s390_lr (code
, s390_r3
, s390_r2
);
2433 s390_st (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2434 if (enable_arguments
) {
2435 s390_lr (code
, s390_r3
, s390_r2
);
2439 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2440 if (enable_arguments
) {
2441 s390_ldebr (code
, s390_f0
, s390_f0
);
2445 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2448 s390_st (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2449 if (enable_arguments
) {
2450 s390_l (code
, s390_r3
, 0, cfg
->frame_reg
,
2451 S390_MINIMAL_STACK_SIZE
+cfg
->param_area
);
2459 s390_basr (code
, s390_r13
, 0);
2461 s390_word (code
, cfg
->method
);
2462 s390_word (code
, func
);
2463 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
2464 s390_l (code
, s390_r1
, 0, s390_r13
, 8);
2465 s390_basr (code
, s390_r14
, s390_r1
);
2467 switch (save_mode
) {
2469 s390_lm (code
, s390_r2
, s390_r3
, cfg
->frame_reg
, saveOffset
);
2472 s390_l (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2476 s390_ld (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2479 s390_l (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2489 /*========================= End of Function ========================*/
2492 mono_arch_peephole_pass_1 (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2496 /*------------------------------------------------------------------*/
2498 /* Name - mono_arch_peephole_pass */
2500 /* Function - Form a peephole pass at the code looking for */
2501 /* simple optimizations. */
2503 /*------------------------------------------------------------------*/
2506 mono_arch_peephole_pass_2 (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2510 MONO_BB_FOR_EACH_INS_SAFE (bb
, n
, ins
) {
2511 mono_peephole_ins (bb
, ins
);
2515 /*========================= End of Function ========================*/
2518 mono_arch_lowering_pass (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2520 MonoInst
*ins
, *next
;
2522 MONO_BB_FOR_EACH_INS_SAFE (bb
, next
, ins
) {
2523 switch (ins
->opcode
) {
2528 case OP_IDIV_UN_IMM
:
2529 case OP_IREM_UN_IMM
:
2530 case OP_LOCALLOC_IMM
:
2531 mono_decompose_op_imm (cfg
, bb
, ins
);
2538 bb
->max_vreg
= cfg
->next_vreg
;
2541 /*========================= End of Function ========================*/
2543 /*------------------------------------------------------------------*/
2545 /* Name - emit_float_to_int */
2547 /* Function - Create instructions which will convert a floating */
2548 /* point value to integer. */
2550 /*------------------------------------------------------------------*/
2553 emit_float_to_int (MonoCompile
*cfg
, guchar
*code
, int dreg
, int sreg
, int size
, gboolean is_signed
)
2555 /* sreg is a float, dreg is an integer reg. */
2557 s390_cfdbr (code
, dreg
, 5, sreg
);
2560 s390_lhi (code
, s390_r0
, 0);
2561 s390_lhi (code
, s390_r13
, 0xff);
2562 s390_ltr (code
, dreg
, dreg
);
2564 s390_lhi (code
, s390_r0
, 0x80);
2565 s390_nr (code
, dreg
, s390_r13
);
2566 s390_or (code
, dreg
, s390_r0
);
2571 s390_basr (code
, s390_r13
, 0);
2573 s390_llong (code
, 0x41e0000000000000LL
);
2574 s390_llong (code
, 0x41f0000000000000LL
);
2575 s390_ldr (code
, s390_f15
, sreg
);
2576 s390_cdb (code
, s390_f15
, 0, s390_r13
, 4);
2577 s390_jl (code
, 0); CODEPTR(code
, o
[0]);
2578 s390_sdb (code
, s390_f15
, 0, s390_r13
, 12);
2579 s390_cfdbr (code
, dreg
, 7, s390_f15
);
2581 PTRSLOT(code
, o
[0]);
2582 s390_cfdbr (code
, dreg
, 5, sreg
);
2585 s390_lhi (code
, s390_r0
, 0xff);
2586 s390_nr (code
, dreg
, s390_r0
);
2589 s390_lhi (code
, s390_r0
, -1);
2590 s390_srl (code
, s390_r0
, 0, 16);
2591 s390_nr (code
, dreg
, s390_r0
);
2598 /*========================= End of Function ========================*/
2600 /*------------------------------------------------------------------*/
2602 /* Name - mono_arch_output_basic_block */
2604 /* Function - Perform the "real" work of emitting instructions */
2605 /* that will do the work of in the basic block. */
2607 /*------------------------------------------------------------------*/
2610 mono_arch_output_basic_block (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2615 guint8
*code
= cfg
->native_code
+ cfg
->code_len
;
2616 MonoInst
*last_ins
= NULL
;
2617 guint last_offset
= 0;
2618 int max_len
, cpos
, src2
;
2620 /* we don't align basic blocks of loops on s390 */
2622 if (cfg
->verbose_level
> 2)
2623 g_print ("Basic block %d starting at offset 0x%x\n", bb
->block_num
, bb
->native_offset
);
2625 cpos
= bb
->max_offset
;
2627 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
) {
2628 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2629 //g_assert (!mono_compile_aot);
2632 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2633 /* this is not thread save, but good enough */
2634 /* fixme: howto handle overflows? */
2635 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2638 MONO_BB_FOR_EACH_INS (bb
, ins
) {
2639 offset
= code
- cfg
->native_code
;
2641 max_len
= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
2643 if (offset
> (cfg
->code_size
- max_len
- 16)) {
2644 cfg
->code_size
*= 2;
2645 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
2646 code
= cfg
->native_code
+ offset
;
2649 mono_debug_record_line_number (cfg
, ins
, offset
);
2651 switch (ins
->opcode
) {
2652 case OP_STOREI1_MEMBASE_IMM
: {
2653 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2654 if (s390_is_uimm12(ins
->inst_offset
))
2655 s390_stc (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2657 s390_basr (code
, s390_r13
, 0);
2659 s390_word (code
, ins
->inst_offset
);
2660 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2661 s390_stc (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2665 case OP_STOREI2_MEMBASE_IMM
: {
2666 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2667 if (s390_is_uimm12(ins
->inst_offset
)) {
2668 s390_sth (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2670 s390_basr (code
, s390_r13
, 0);
2672 s390_word (code
, ins
->inst_offset
);
2673 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2674 s390_sth (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2678 case OP_STORE_MEMBASE_IMM
:
2679 case OP_STOREI4_MEMBASE_IMM
: {
2680 if (s390_is_imm16(ins
->inst_imm
)) {
2681 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2683 s390_basr (code
, s390_r13
, 0);
2685 s390_word (code
, ins
->inst_imm
);
2686 s390_l (code
, s390_r0
, 0, s390_r13
, 4);
2688 if (s390_is_uimm12(ins
->inst_offset
)) {
2689 s390_st (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2691 s390_basr (code
, s390_r13
, 0);
2693 s390_word (code
, ins
->inst_offset
);
2694 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2695 s390_st (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2699 case OP_STOREI1_MEMBASE_REG
: {
2700 if (s390_is_uimm12(ins
->inst_offset
)) {
2701 s390_stc (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2703 s390_basr (code
, s390_r13
, 0);
2705 s390_word (code
, ins
->inst_offset
);
2706 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2707 s390_stc (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2711 case OP_STOREI2_MEMBASE_REG
: {
2712 if (s390_is_uimm12(ins
->inst_offset
)) {
2713 s390_sth (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2715 s390_basr (code
, s390_r13
, 0);
2717 s390_word (code
, ins
->inst_offset
);
2718 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2719 s390_sth (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2723 case OP_STORE_MEMBASE_REG
:
2724 case OP_STOREI4_MEMBASE_REG
: {
2725 if (s390_is_uimm12(ins
->inst_offset
)) {
2726 s390_st (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2728 s390_basr (code
, s390_r13
, 0);
2730 s390_word (code
, ins
->inst_offset
);
2731 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2732 s390_st (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2737 g_assert_not_reached ();
2739 case OP_LOAD_MEMBASE
:
2740 case OP_LOADI4_MEMBASE
:
2741 case OP_LOADU4_MEMBASE
: {
2742 if (s390_is_uimm12(ins
->inst_offset
))
2743 s390_l (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2745 if (s390_is_imm16(ins
->inst_offset
)) {
2746 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
2747 s390_l (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
2749 s390_basr (code
, s390_r13
, 0);
2751 s390_word (code
, ins
->inst_offset
);
2752 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2753 s390_l (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
2758 case OP_LOADU1_MEMBASE
: {
2759 s390_lhi (code
, s390_r0
, 0);
2760 if (s390_is_uimm12(ins
->inst_offset
))
2761 s390_ic (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2763 s390_basr (code
, s390_r13
, 0);
2765 s390_word (code
, ins
->inst_offset
);
2766 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2767 s390_ic (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2769 s390_lr (code
, ins
->dreg
, s390_r0
);
2772 case OP_LOADI1_MEMBASE
: {
2773 s390_lhi (code
, s390_r0
, 0);
2774 if (s390_is_uimm12(ins
->inst_offset
))
2775 s390_ic (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2777 s390_basr (code
, s390_r13
, 0);
2779 s390_word (code
, ins
->inst_offset
);
2780 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2781 s390_ic (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2783 s390_lhi (code
, s390_r13
, 0x80);
2784 s390_nr (code
, s390_r13
, s390_r0
);
2786 s390_lhi (code
, s390_r13
, 0xff00);
2787 s390_or (code
, s390_r0
, s390_r13
);
2788 s390_lr (code
, ins
->dreg
, s390_r0
);
2791 case OP_LOADU2_MEMBASE
: {
2792 s390_lhi (code
, s390_r0
, 0);
2793 if (s390_is_uimm12(ins
->inst_offset
))
2794 s390_icm (code
, s390_r0
, 3, ins
->inst_basereg
, ins
->inst_offset
);
2796 s390_basr (code
, s390_r13
, 0);
2798 s390_word (code
, ins
->inst_offset
);
2799 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2800 s390_ar (code
, s390_r13
, ins
->inst_basereg
);
2801 s390_icm (code
, s390_r0
, 3, s390_r13
, 0);
2803 s390_lr (code
, ins
->dreg
, s390_r0
);
2806 case OP_LOADI2_MEMBASE
: {
2807 s390_lhi (code
, s390_r0
, 0);
2808 if (s390_is_uimm12(ins
->inst_offset
))
2809 s390_lh (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2811 s390_basr (code
, s390_r13
, 0);
2813 s390_word (code
, ins
->inst_offset
);
2814 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2815 s390_lh (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2817 s390_lr (code
, ins
->dreg
, s390_r0
);
2821 case OP_ICONV_TO_I1
: {
2822 if (ins
->dreg
!= ins
->sreg1
)
2823 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2824 s390_sll (code
, ins
->dreg
, 0, 24);
2825 s390_sra (code
, ins
->dreg
, 0, 24);
2828 case OP_ICONV_TO_I2
: {
2829 if (ins
->dreg
!= ins
->sreg1
)
2830 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2831 s390_sll (code
, ins
->dreg
, 0, 16);
2832 s390_sra (code
, ins
->dreg
, 0, 16);
2835 case OP_ICONV_TO_U1
: {
2836 s390_lhi (code
, s390_r0
, 0xff);
2837 if (ins
->dreg
!= ins
->sreg1
) {
2838 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2840 s390_nr (code
, ins
->dreg
, s390_r0
);
2843 case OP_ICONV_TO_U2
: {
2844 s390_lhi (code
, s390_r0
, -1);
2845 s390_sll (code
, s390_r0
, 0, 16);
2846 s390_srl (code
, s390_r0
, 0, 16);
2847 if (ins
->dreg
!= ins
->sreg1
) {
2848 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2850 s390_nr (code
, ins
->dreg
, s390_r0
);
2855 gboolean un
= FALSE
;
2856 MonoInst
*next
= ins
->next
;
2859 (((next
->opcode
>= OP_IBNE_UN
) &&
2860 (next
->opcode
<= OP_IBLT_UN
)) ||
2861 ((next
->opcode
>= OP_COND_EXC_NE_UN
) &&
2862 (next
->opcode
<= OP_COND_EXC_LT_UN
)) ||
2863 ((next
->opcode
>= OP_COND_EXC_INE_UN
) &&
2864 (next
->opcode
<= OP_COND_EXC_ILT_UN
)) ||
2865 ((next
->opcode
== OP_CLT_UN
) ||
2866 (next
->opcode
== OP_CGT_UN
)) ||
2867 ((next
->opcode
== OP_ICLT_UN
) ||
2868 (next
->opcode
== OP_ICGT_UN
))))
2872 s390_clr (code
, ins
->sreg1
, ins
->sreg2
);
2874 s390_cr (code
, ins
->sreg1
, ins
->sreg2
);
2877 case OP_COMPARE_IMM
:
2878 case OP_ICOMPARE_IMM
: {
2879 gboolean un
= FALSE
;
2880 MonoInst
*next
= ins
->next
;
2883 (((next
->opcode
>= OP_IBNE_UN
) &&
2884 (next
->opcode
<= OP_IBLT_UN
)) ||
2885 ((next
->opcode
>= OP_COND_EXC_NE_UN
) &&
2886 (next
->opcode
<= OP_COND_EXC_LT_UN
)) ||
2887 ((next
->opcode
>= OP_COND_EXC_INE_UN
) &&
2888 (next
->opcode
<= OP_COND_EXC_ILT_UN
)) ||
2889 ((next
->opcode
== OP_CLT_UN
) ||
2890 (next
->opcode
== OP_CGT_UN
)) ||
2891 ((next
->opcode
== OP_ICLT_UN
) ||
2892 (next
->opcode
== OP_ICGT_UN
))))
2895 if (s390_is_imm16 (ins
->inst_imm
)) {
2896 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2898 s390_clr (code
, ins
->sreg1
, s390_r0
);
2900 s390_cr (code
, ins
->sreg1
, s390_r0
);
2903 s390_basr (code
, s390_r13
, 0);
2905 s390_word (code
, ins
->inst_imm
);
2907 s390_cl (code
, ins
->sreg1
, 0, s390_r13
, 4);
2909 s390_c (code
, ins
->sreg1
, 0, s390_r13
, 4);
2914 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
, mono_break
);
2915 s390_brasl (code
, s390_r14
, 0);
2921 s390_alr (code
, ins
->dreg
, src2
);
2926 s390_ar (code
, ins
->dreg
, src2
);
2932 s390_alcr (code
, ins
->dreg
, src2
);
2937 if (ins
->dreg
!= ins
->sreg1
) {
2938 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2941 (ins
->next
->opcode
== OP_ADC_IMM
)) {
2942 s390_basr (code
, s390_r13
, 0);
2944 s390_word (code
, ins
->inst_imm
);
2945 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
2947 if (s390_is_imm16 (ins
->inst_imm
)) {
2948 s390_ahi (code
, ins
->dreg
, ins
->inst_imm
);
2950 s390_basr (code
, s390_r13
, 0);
2952 s390_word (code
, ins
->inst_imm
);
2953 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
2958 case OP_ADDCC_IMM
: {
2960 (ins
->next
->opcode
== OP_ADC_IMM
)) {
2961 s390_basr (code
, s390_r13
, 0);
2963 s390_word (code
, ins
->inst_imm
);
2964 if (ins
->dreg
!= ins
->sreg1
) {
2965 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2967 s390_al (code
, ins
->dreg
, 0, s390_r13
, 4);
2969 if (s390_is_imm16 (ins
->inst_imm
)) {
2970 if (ins
->dreg
!= ins
->sreg1
) {
2971 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2973 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2974 s390_alcr (code
, ins
->dreg
, s390_r0
);
2976 s390_basr (code
, s390_r13
, 0);
2978 s390_word (code
, ins
->inst_imm
);
2979 if (ins
->dreg
!= ins
->sreg1
) {
2980 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2982 s390_al (code
, ins
->dreg
, 0, s390_r13
, 4);
2988 if (s390_is_imm16 (ins
->inst_imm
)) {
2989 if (ins
->dreg
!= ins
->sreg1
) {
2990 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2992 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2993 s390_alcr (code
, ins
->dreg
, s390_r0
);
2995 s390_basr (code
, s390_r13
, 0);
2997 s390_word (code
, ins
->inst_imm
);
2998 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2999 s390_alcr (code
, ins
->dreg
, s390_r13
);
3004 case OP_S390_IADD_OVF
: {
3006 s390_ar (code
, ins
->dreg
, src2
);
3007 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3010 case OP_IADD_OVF_UN
:
3011 case OP_S390_IADD_OVF_UN
: {
3013 s390_alr (code
, ins
->dreg
, src2
);
3014 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3018 case OP_S390_LADD
: {
3019 s390_alr (code
, s390_r0
, ins
->sreg1
);
3021 s390_ahi (code
, s390_r1
, 1);
3022 s390_ar (code
, s390_r1
, ins
->sreg2
);
3023 s390_lr (code
, ins
->dreg
, s390_r0
);
3024 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3028 case OP_S390_LADD_OVF
: {
3030 s390_alr (code
, s390_r0
, ins
->sreg1
);
3031 s390_jnc (code
, 0); CODEPTR(code
, o
[0]);
3032 s390_ahi (code
, s390_r1
, 1);
3033 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3034 PTRSLOT (code
, o
[0]);
3035 s390_ar (code
, s390_r1
, ins
->sreg2
);
3036 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3037 s390_lr (code
, ins
->dreg
, s390_r0
);
3038 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3041 case OP_LADD_OVF_UN
:
3042 case OP_S390_LADD_OVF_UN
: {
3043 s390_alr (code
, s390_r0
, ins
->sreg1
);
3044 s390_alcr (code
, s390_r1
, ins
->sreg2
);
3045 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3046 s390_lr (code
, ins
->dreg
, s390_r0
);
3047 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3050 case OP_ADD_OVF_CARRY
: {
3052 s390_lhi (code
, s390_r0
, 0);
3053 s390_lr (code
, s390_r1
, s390_r0
);
3054 s390_alcr (code
, s390_r0
, s390_r1
);
3055 s390_ar (code
, ins
->dreg
, src2
);
3056 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3057 s390_ar (code
, ins
->dreg
, s390_r0
);
3058 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3061 case OP_ADD_OVF_UN_CARRY
: {
3063 s390_alcr (code
, ins
->dreg
, src2
);
3064 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3070 s390_slr (code
, ins
->dreg
, src2
);
3075 s390_sr (code
, ins
->dreg
, src2
);
3081 s390_slbr (code
, ins
->dreg
, src2
);
3084 case OP_SUBCC_IMM
: {
3085 if (s390_is_imm16 (-ins
->inst_imm
)) {
3086 if (ins
->dreg
!= ins
->sreg1
) {
3087 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3089 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3090 s390_slr (code
, ins
->dreg
, s390_r0
);
3092 s390_basr (code
, s390_r13
, 0);
3094 s390_word (code
, ins
->inst_imm
);
3095 if (ins
->dreg
!= ins
->sreg1
) {
3096 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3098 s390_sl (code
, ins
->dreg
, 0, s390_r13
, 4);
3104 if (s390_is_imm16 (-ins
->inst_imm
)) {
3105 if (ins
->dreg
!= ins
->sreg1
) {
3106 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3108 s390_ahi (code
, ins
->dreg
, -ins
->inst_imm
);
3110 s390_basr (code
, s390_r13
, 0);
3112 s390_word (code
, ins
->inst_imm
);
3113 if (ins
->dreg
!= ins
->sreg1
) {
3114 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3116 s390_s (code
, ins
->dreg
, 0, s390_r13
, 4);
3121 if (ins
->dreg
!= ins
->sreg1
) {
3122 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3124 if (s390_is_imm16 (-ins
->inst_imm
)) {
3125 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3126 s390_slbr (code
, ins
->dreg
, s390_r0
);
3128 s390_basr (code
, s390_r13
, 0);
3130 s390_word (code
, ins
->inst_imm
);
3131 s390_slb (code
, ins
->dreg
, 0, s390_r13
, 4);
3136 case OP_S390_ISUB_OVF
: {
3138 s390_sr (code
, ins
->dreg
, src2
);
3139 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3142 case OP_ISUB_OVF_UN
:
3143 case OP_S390_ISUB_OVF_UN
: {
3145 s390_slr (code
, ins
->dreg
, src2
);
3146 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3150 case OP_S390_LSUB
: {
3151 s390_lr (code
, s390_r14
, ins
->sreg2
);
3152 s390_slr (code
, s390_r0
, ins
->sreg1
);
3154 s390_ahi (code
, s390_r14
, 1);
3155 s390_sr (code
, s390_r1
, s390_r14
);
3156 s390_lr (code
, ins
->dreg
, s390_r0
);
3157 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3161 case OP_S390_LSUB_OVF
: {
3163 s390_lr (code
, s390_r14
, ins
->sreg2
);
3164 s390_slr (code
, s390_r0
, ins
->sreg1
);
3165 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
3166 s390_ahi (code
, s390_r14
, 1);
3167 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3168 PTRSLOT (code
, o
[0]);
3169 s390_sr (code
, s390_r1
, s390_r14
);
3170 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3171 s390_lr (code
, ins
->dreg
, s390_r0
);
3172 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3175 case OP_LSUB_OVF_UN
:
3176 case OP_S390_LSUB_OVF_UN
: {
3177 s390_slr (code
, s390_r0
, ins
->sreg1
);
3178 s390_slbr (code
, s390_r1
, ins
->sreg2
);
3179 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, "OverflowException");
3180 s390_lr (code
, ins
->dreg
, s390_r0
);
3181 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3184 case OP_SUB_OVF_CARRY
: {
3186 s390_lhi (code
, s390_r0
, 0);
3187 s390_lr (code
, s390_r1
, s390_r0
);
3188 s390_slbr (code
, s390_r0
, s390_r1
);
3189 s390_sr (code
, ins
->dreg
, src2
);
3190 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3191 s390_ar (code
, ins
->dreg
, s390_r0
);
3192 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3195 case OP_SUB_OVF_UN_CARRY
: {
3197 s390_slbr (code
, ins
->dreg
, src2
);
3198 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3202 if (ins
->sreg1
== ins
->dreg
) {
3203 s390_nr (code
, ins
->dreg
, ins
->sreg2
);
3206 if (ins
->sreg2
== ins
->dreg
) {
3207 s390_nr (code
, ins
->dreg
, ins
->sreg1
);
3210 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3211 s390_nr (code
, ins
->dreg
, ins
->sreg2
);
3218 if (s390_is_imm16 (ins
->inst_imm
)) {
3219 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3220 if (ins
->dreg
!= ins
->sreg1
) {
3221 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3223 s390_nr (code
, ins
->dreg
, s390_r0
);
3225 s390_basr (code
, s390_r13
, 0);
3227 s390_word (code
, ins
->inst_imm
);
3228 if (ins
->dreg
!= ins
->sreg1
) {
3229 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3231 s390_n (code
, ins
->dreg
, 0, s390_r13
, 4);
3236 s390_lr (code
, s390_r0
, ins
->sreg1
);
3237 s390_srda (code
, s390_r0
, 0, 32);
3238 s390_dr (code
, s390_r0
, ins
->sreg2
);
3239 s390_lr (code
, ins
->dreg
, s390_r1
);
3243 s390_lr (code
, s390_r0
, ins
->sreg1
);
3244 s390_srdl (code
, s390_r0
, 0, 32);
3245 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3246 s390_lr (code
, ins
->dreg
, s390_r1
);
3250 s390_lr (code
, s390_r0
, ins
->sreg1
);
3251 s390_srda (code
, s390_r0
, 0, 32);
3252 s390_dr (code
, s390_r0
, ins
->sreg2
);
3253 s390_lr (code
, ins
->dreg
, s390_r0
);
3256 s390_lr (code
, s390_r0
, ins
->sreg1
);
3257 s390_srdl (code
, s390_r0
, 0, 32);
3258 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3259 s390_lr (code
, ins
->dreg
, s390_r0
);
3263 if (ins
->sreg1
== ins
->dreg
) {
3264 s390_or (code
, ins
->dreg
, ins
->sreg2
);
3267 if (ins
->sreg2
== ins
->dreg
) {
3268 s390_or (code
, ins
->dreg
, ins
->sreg1
);
3271 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3272 s390_or (code
, ins
->dreg
, ins
->sreg2
);
3279 if (s390_is_imm16 (ins
->inst_imm
)) {
3280 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3281 if (ins
->dreg
!= ins
->sreg1
) {
3282 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3284 s390_or (code
, ins
->dreg
, s390_r0
);
3286 s390_basr (code
, s390_r13
, 0);
3288 s390_word (code
, ins
->inst_imm
);
3289 if (ins
->dreg
!= ins
->sreg1
) {
3290 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3292 s390_o (code
, ins
->dreg
, 0, s390_r13
, 4);
3297 if (ins
->sreg1
== ins
->dreg
) {
3298 s390_xr (code
, ins
->dreg
, ins
->sreg2
);
3301 if (ins
->sreg2
== ins
->dreg
) {
3302 s390_xr (code
, ins
->dreg
, ins
->sreg1
);
3305 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3306 s390_xr (code
, ins
->dreg
, ins
->sreg2
);
3313 if (s390_is_imm16 (ins
->inst_imm
)) {
3314 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3315 if (ins
->dreg
!= ins
->sreg1
) {
3316 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3318 s390_xr (code
, ins
->dreg
, s390_r0
);
3320 s390_basr (code
, s390_r13
, 0);
3322 s390_word (code
, ins
->inst_imm
);
3323 if (ins
->dreg
!= ins
->sreg1
) {
3324 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3326 s390_x (code
, ins
->dreg
, 0, s390_r13
, 4);
3332 s390_sll (code
, ins
->dreg
, src2
, 0);
3337 if (ins
->sreg1
!= ins
->dreg
) {
3338 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3340 s390_sll (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3345 s390_sra (code
, ins
->dreg
, src2
, 0);
3350 if (ins
->sreg1
!= ins
->dreg
) {
3351 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3353 s390_sra (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3357 case OP_ISHR_UN_IMM
: {
3358 if (ins
->sreg1
!= ins
->dreg
) {
3359 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3361 s390_srl (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3366 s390_srl (code
, ins
->dreg
, src2
, 0);
3370 if (ins
->sreg1
!= ins
->dreg
) {
3371 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3373 s390_lhi (code
, s390_r0
, -1);
3374 s390_xr (code
, ins
->dreg
, s390_r0
);
3378 s390_lcr (code
, ins
->dreg
, ins
->sreg1
);
3381 case OP_S390_LNEG
: {
3383 g_assert (ins
->dreg
+ 1 != ins
->sreg1
);
3384 s390_lcr (code
, ins
->dreg
+ 1, ins
->sreg2
);
3385 s390_lcr (code
, ins
->dreg
, ins
->sreg1
);
3387 s390_bctr (code
, ins
->dreg
+ 1, 0);
3391 if (ins
->sreg1
== ins
->dreg
) {
3392 s390_msr (code
, ins
->dreg
, ins
->sreg2
);
3395 if (ins
->sreg2
== ins
->dreg
) {
3396 s390_msr (code
, ins
->dreg
, ins
->sreg1
);
3399 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3400 s390_msr (code
, ins
->dreg
, ins
->sreg2
);
3407 if (s390_is_imm16 (ins
->inst_imm
)) {
3408 s390_lhi (code
, s390_r13
, ins
->inst_imm
);
3410 s390_basr (code
, s390_r13
, 0);
3412 s390_word (code
, ins
->inst_imm
);
3413 // if (ins->dreg != ins->sreg1) {
3414 // s390_lr (code, ins->dreg, ins->sreg1);
3416 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3418 if (ins
->dreg
!= ins
->sreg1
) {
3419 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3421 s390_msr (code
, ins
->dreg
, s390_r13
);
3426 s390_ltr (code
, s390_r1
, ins
->sreg1
);
3427 s390_jz (code
, 0); CODEPTR(code
, o
[0]);
3428 s390_ltr (code
, s390_r0
, ins
->sreg2
);
3430 s390_lhi (code
, s390_r1
, 0);
3431 s390_j (code
, 0); CODEPTR(code
, o
[1]);
3432 s390_xr (code
, s390_r0
, s390_r1
);
3433 s390_msr (code
, s390_r1
, ins
->sreg2
);
3434 s390_xr (code
, s390_r0
, s390_r1
);
3435 s390_srl (code
, s390_r0
, 0, 31);
3436 s390_ltr (code
, s390_r0
, s390_r0
);
3437 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3438 PTRSLOT (code
, o
[0]);
3439 PTRSLOT (code
, o
[1]);
3440 s390_lr (code
, ins
->dreg
, s390_r1
);
3443 case OP_IMUL_OVF_UN
: {
3444 s390_lhi (code
, s390_r0
, 0);
3445 s390_lr (code
, s390_r1
, ins
->sreg1
);
3446 s390_mlr (code
, s390_r0
, ins
->sreg2
);
3447 s390_ltr (code
, s390_r0
, s390_r0
);
3448 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3449 s390_lr (code
, ins
->dreg
, s390_r1
);
3453 s390_l (code
, s390_r0
, 0, ins
->sreg1
, 4);
3454 s390_srda (code
, s390_r0
, 0, 32);
3455 s390_m (code
, s390_r0
, 0, ins
->sreg2
, 4);
3456 s390_l (code
, s390_r0
, 0, ins
->sreg1
, 4);
3457 s390_srl (code
, s390_r0
, 0, 31);
3458 s390_a (code
, s390_r0
, 0, ins
->sreg1
, 0);
3459 s390_l (code
, s390_r13
, 0, ins
->sreg2
, 0);
3460 s390_srl (code
, s390_r13
, 0, 31);
3461 s390_ms (code
, s390_r13
, 0, ins
->sreg1
, 4);
3462 s390_ar (code
, s390_r0
, s390_r13
);
3463 s390_st (code
, s390_r0
, 0, ins
->dreg
, 0);
3464 s390_st (code
, s390_r1
, 0, ins
->dreg
, 4);
3468 if (s390_is_imm16(ins
->inst_c0
)) {
3469 s390_lhi (code
, ins
->dreg
, ins
->inst_c0
);
3471 s390_basr (code
, s390_r13
, 0);
3473 s390_word (code
, ins
->inst_c0
);
3474 s390_l (code
, ins
->dreg
, 0, s390_r13
, 4);
3479 s390_basr (code
, s390_r13
, 0);
3481 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3482 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3483 s390_word (code
, 0);
3484 s390_l (code
,ins
->dreg
, 0, s390_r13
, 4);
3487 case OP_JUMP_TABLE
: {
3488 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3489 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3490 s390_basr (code
, s390_r13
, 0);
3492 s390_word (code
, 0);
3493 s390_l (code
, ins
->dreg
, 0, s390_r13
, 4);
3496 case OP_ICONV_TO_I4
:
3497 case OP_ICONV_TO_U4
:
3499 if (ins
->dreg
!= ins
->sreg1
) {
3500 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3505 int saved
= ins
->sreg1
;
3506 if (ins
->sreg1
== s390_r2
) {
3507 s390_lr (code
, s390_r0
, ins
->sreg1
);
3510 if (ins
->sreg2
!= s390_r2
)
3511 s390_lr (code
, s390_r2
, ins
->sreg2
);
3512 if (saved
!= s390_r3
)
3513 s390_lr (code
, s390_r3
, saved
);
3517 if (ins
->dreg
!= ins
->sreg1
) {
3518 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3522 case OP_S390_SETF4RET
: {
3523 s390_ledbr (code
, ins
->dreg
, ins
->sreg1
);
3527 if (s390_is_imm16 (ins
->inst_offset
)) {
3528 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
3530 s390_bras (code
, s390_r13
, 0);
3532 s390_word (code
, ins
->inst_offset
);
3533 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3535 s390_ear (code
, s390_r1
, 0);
3536 s390_l (code
, ins
->dreg
, s390_r13
, s390_r1
, 0);
3539 case OP_FCONV_TO_R4
: {
3541 if (ins
->dreg
!= ins
->sreg1
) {
3542 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3547 (ins->next->opcode != OP_FMOVE) &&
3548 (ins->next->opcode != OP_STORER4_MEMBASE_REG))
3549 s390_ledbr (code, ins->dreg, ins->sreg1);
3554 if (cfg
->method
->save_lmf
)
3555 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
3557 if (cfg
->flags
& MONO_CFG_HAS_TAIL
) {
3558 code
= emit_load_volatile_registers(code
, cfg
);
3561 code
= backUpStackPtr(cfg
, code
, STK_BASE
);
3562 s390_l (code
, s390_r14
, 0, STK_BASE
, S390_RET_ADDR_OFFSET
);
3563 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3564 MONO_PATCH_INFO_METHOD_JUMP
,
3566 s390_jcl (code
, S390_CC_UN
, 0);
3569 case OP_CHECK_THIS
: {
3570 /* ensure ins->sreg1 is not NULL */
3571 s390_icm (code
, s390_r0
, 15, ins
->sreg1
, 0);
3575 int offset
= cfg
->sig_cookie
+ cfg
->stack_usage
;
3577 if (s390_is_imm16 (offset
))
3578 s390_lhi (code
, s390_r0
, offset
);
3580 s390_basr (code
, s390_r13
, 0);
3582 s390_word (code
, offset
);
3583 s390_l (code
, s390_r0
, 0, s390_r13
, 0);
3585 s390_ar (code
, s390_r0
, cfg
->frame_reg
);
3586 s390_st (code
, s390_r0
, 0, ins
->sreg1
, 0);
3590 call
= (MonoCallInst
*)ins
;
3591 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3592 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_METHOD
,
3595 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
,
3597 s390_brasl (code
, s390_r14
, 0);
3598 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3599 s390_ldebr (code
, s390_f0
, s390_f0
);
3607 call
= (MonoCallInst
*)ins
;
3608 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3609 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_METHOD
, call
->method
);
3611 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
, call
->fptr
);
3612 s390_brasl (code
, s390_r14
, 0);
3615 case OP_FCALL_REG
: {
3616 call
= (MonoCallInst
*)ins
;
3617 s390_lr (code
, s390_r1
, ins
->sreg1
);
3618 s390_basr (code
, s390_r14
, s390_r1
);
3619 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3620 s390_ldebr (code
, s390_f0
, s390_f0
);
3626 case OP_VOIDCALL_REG
:
3628 s390_lr (code
, s390_r1
, ins
->sreg1
);
3629 s390_basr (code
, s390_r14
, s390_r1
);
3632 case OP_LCALL_MEMBASE
:
3633 case OP_VCALL_MEMBASE
:
3634 case OP_VCALL2_MEMBASE
:
3635 case OP_VOIDCALL_MEMBASE
:
3636 case OP_FCALL_MEMBASE
:
3637 case OP_CALL_MEMBASE
: {
3638 call
= (MonoCallInst
*)ins
;
3639 if (s390_is_uimm12(ins
->inst_offset
))
3640 s390_l (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3642 if (s390_is_imm16(ins
->inst_offset
)) {
3643 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
3644 s390_l (code
, s390_r1
, s390_r13
, ins
->inst_basereg
, 0);
3646 s390_basr (code
, s390_r13
, 0);
3648 s390_word (code
, ins
->inst_offset
);
3649 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3650 s390_l (code
, s390_r1
, s390_r13
, ins
->inst_basereg
, 0);
3653 s390_basr (code
, s390_r14
, s390_r1
);
3654 if (ins
->opcode
== OP_FCALL_MEMBASE
&& call
->signature
->ret
->type
== MONO_TYPE_R4
)
3655 s390_ldebr (code
, s390_f0
, s390_f0
);
3659 /*------------------------------------------*/
3660 /* To allocate space on the stack we have */
3661 /* to allow room for parameters passed in */
3662 /* calls, the backchain pointer and round */
3663 /* it to our stack alignment requirements */
3664 /*------------------------------------------*/
3665 int alloca_skip
= S390_MINIMAL_STACK_SIZE
+ cfg
->param_area
;
3666 int area_offset
= S390_ALIGN(alloca_skip
, S390_STACK_ALIGNMENT
);
3667 s390_lr (code
, s390_r1
, ins
->sreg1
);
3668 if (ins
->flags
& MONO_INST_INIT
)
3669 s390_lr (code
, s390_r0
, ins
->sreg1
);
3670 s390_ahi (code
, s390_r1
, 14);
3671 s390_srl (code
, s390_r1
, 0, 3);
3672 s390_sll (code
, s390_r1
, 0, 3);
3673 if (cfg
->method
->save_lmf
) {
3674 /*----------------------------------*/
3675 /* we have to adjust lmf ebp value */
3676 /*----------------------------------*/
3677 int lmfOffset
= cfg
->stack_usage
- sizeof(MonoLMF
);
3679 s390_lr (code
, s390_r13
, cfg
->frame_reg
);
3680 if (s390_is_uimm16(lmfOffset
))
3681 s390_ahi (code
, s390_r13
, lmfOffset
);
3683 s390_basr (code
, s390_r14
, 0);
3685 s390_word (code
, lmfOffset
);
3686 s390_a (code
, s390_r13
, 0, s390_r14
, 4);
3688 s390_lr (code
, s390_r14
, STK_BASE
);
3689 s390_sr (code
, s390_r14
, s390_r1
);
3690 s390_st (code
, s390_r14
, 0, s390_r13
,
3691 G_STRUCT_OFFSET(MonoLMF
, ebp
));
3693 s390_l (code
, s390_r13
, 0, STK_BASE
, 0);
3694 s390_sr (code
, STK_BASE
, s390_r1
);
3695 s390_st (code
, s390_r13
, 0, STK_BASE
, 0);
3696 s390_la (code
, ins
->dreg
, 0, STK_BASE
, area_offset
);
3697 s390_srl (code
, ins
->dreg
, 0, 3);
3698 s390_sll (code
, ins
->dreg
, 0, 3);
3699 if (ins
->flags
& MONO_INST_INIT
) {
3700 s390_lr (code
, s390_r1
, s390_r0
);
3701 s390_lr (code
, s390_r0
, ins
->dreg
);
3702 s390_lr (code
, s390_r14
, s390_r12
);
3703 s390_lhi (code
, s390_r13
, 0);
3704 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
3706 s390_lr (code
, s390_r12
, s390_r14
);
3711 s390_lr (code
, s390_r2
, ins
->sreg1
);
3712 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3713 (gpointer
)"mono_arch_throw_exception");
3714 s390_brasl (code
, s390_r14
, 0);
3718 s390_lr (code
, s390_r2
, ins
->sreg1
);
3719 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3720 (gpointer
)"mono_arch_rethrow_exception");
3721 s390_brasl (code
, s390_r14
, 0);
3724 case OP_START_HANDLER
: {
3725 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3726 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3727 s390_st (code
, s390_r14
, 0,
3728 spvar
->inst_basereg
,
3729 spvar
->inst_offset
);
3731 s390_basr (code
, s390_r13
, 0);
3733 s390_word (code
, spvar
->inst_offset
);
3734 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3735 s390_st (code
, s390_r14
, s390_r13
,
3736 spvar
->inst_basereg
, 0);
3740 case OP_ENDFILTER
: {
3741 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3742 if (ins
->sreg1
!= s390_r2
)
3743 s390_lr (code
, s390_r2
, ins
->sreg1
);
3744 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3745 s390_l (code
, s390_r14
, 0, spvar
->inst_basereg
,
3746 spvar
->inst_offset
);
3748 s390_basr (code
, s390_r13
, 0);
3750 s390_word (code
, spvar
->inst_offset
);
3751 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3752 s390_l (code
, s390_r14
, s390_r13
,
3753 spvar
->inst_basereg
, 0);
3755 s390_br (code
, s390_r14
);
3758 case OP_ENDFINALLY
: {
3759 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3760 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3761 s390_l (code
, s390_r14
, 0, spvar
->inst_basereg
,
3762 spvar
->inst_offset
);
3764 s390_basr (code
, s390_r13
, 0);
3766 s390_word (code
, spvar
->inst_offset
);
3767 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3768 s390_l (code
, s390_r14
, s390_r13
,
3769 spvar
->inst_basereg
, 0);
3771 s390_br (code
, s390_r14
);
3774 case OP_CALL_HANDLER
: {
3775 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3776 MONO_PATCH_INFO_BB
, ins
->inst_target_bb
);
3777 s390_brasl (code
, s390_r14
, 0);
3778 mono_cfg_add_try_hole (cfg
, ins
->inst_eh_block
, code
, bb
);
3782 ins
->inst_c0
= code
- cfg
->native_code
;
3785 case OP_RELAXED_NOP
:
3788 case OP_DUMMY_STORE
:
3789 case OP_NOT_REACHED
:
3794 EMIT_UNCOND_BRANCH(ins
);
3797 s390_br (code
, ins
->sreg1
);
3802 s390_lhi (code
, ins
->dreg
, 1);
3804 s390_lhi (code
, ins
->dreg
, 0);
3809 s390_lhi (code
, ins
->dreg
, 1);
3811 s390_lhi (code
, ins
->dreg
, 0);
3816 s390_lhi (code
, ins
->dreg
, 1);
3818 s390_lhi (code
, ins
->dreg
, 0);
3823 s390_lhi (code
, ins
->dreg
, 1);
3825 s390_lhi (code
, ins
->dreg
, 0);
3830 s390_lhi (code
, ins
->dreg
, 1);
3832 s390_lhi (code
, ins
->dreg
, 0);
3835 case OP_COND_EXC_EQ
:
3836 case OP_COND_EXC_IEQ
:
3837 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ
, ins
->inst_p1
);
3839 case OP_COND_EXC_NE_UN
:
3840 case OP_COND_EXC_INE_UN
:
3841 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE
, ins
->inst_p1
);
3843 case OP_COND_EXC_LT
:
3844 case OP_COND_EXC_ILT
:
3845 case OP_COND_EXC_LT_UN
:
3846 case OP_COND_EXC_ILT_UN
:
3847 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, ins
->inst_p1
);
3849 case OP_COND_EXC_GT
:
3850 case OP_COND_EXC_IGT
:
3851 case OP_COND_EXC_GT_UN
:
3852 case OP_COND_EXC_IGT_UN
:
3853 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT
, ins
->inst_p1
);
3855 case OP_COND_EXC_GE
:
3856 case OP_COND_EXC_IGE
:
3857 case OP_COND_EXC_GE_UN
:
3858 case OP_COND_EXC_IGE_UN
:
3859 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE
, ins
->inst_p1
);
3861 case OP_COND_EXC_LE
:
3862 case OP_COND_EXC_ILE
:
3863 case OP_COND_EXC_LE_UN
:
3864 case OP_COND_EXC_ILE_UN
:
3865 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE
, ins
->inst_p1
);
3867 case OP_COND_EXC_OV
:
3868 case OP_COND_EXC_IOV
:
3869 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, ins
->inst_p1
);
3871 case OP_COND_EXC_NO
:
3872 case OP_COND_EXC_INO
:
3873 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO
, ins
->inst_p1
);
3876 case OP_COND_EXC_IC
:
3877 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, ins
->inst_p1
);
3879 case OP_COND_EXC_NC
:
3880 case OP_COND_EXC_INC
:
3881 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, ins
->inst_p1
);
3884 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
3887 EMIT_COND_BRANCH (ins
, S390_CC_NE
);
3891 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
3895 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
3899 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
3903 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
3906 /* floating point opcodes */
3908 if (*((float *) ins
->inst_p0
) == 0) {
3909 s390_lzdr (code
, ins
->dreg
);
3911 s390_basr (code
, s390_r13
, 0);
3913 s390_word (code
, ins
->inst_p0
);
3914 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3915 s390_ld (code
, ins
->dreg
, 0, s390_r13
, 0);
3920 if (*((float *) ins
->inst_p0
) == 0) {
3921 s390_lzdr (code
, ins
->dreg
);
3923 s390_basr (code
, s390_r13
, 0);
3925 s390_word (code
, ins
->inst_p0
);
3926 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3927 s390_ldeb (code
, ins
->dreg
, 0, s390_r13
, 0);
3931 case OP_STORER8_MEMBASE_REG
: {
3932 if (s390_is_uimm12(ins
->inst_offset
)) {
3933 s390_std (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
3935 s390_basr (code
, s390_r13
, 0);
3937 s390_word (code
, ins
->inst_offset
);
3938 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3939 s390_std (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
3943 case OP_LOADR8_MEMBASE
: {
3944 if (s390_is_uimm12(ins
->inst_offset
)) {
3945 s390_ld (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3947 s390_basr (code
, s390_r13
, 0);
3949 s390_word (code
, ins
->inst_offset
);
3950 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3951 s390_ld (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
3955 case OP_STORER4_MEMBASE_REG
: {
3956 if (s390_is_uimm12(ins
->inst_offset
)) {
3957 s390_ledbr(code
, s390_f15
, ins
->sreg1
);
3958 s390_ste (code
, s390_f15
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
3960 s390_basr (code
, s390_r13
, 0);
3962 s390_word (code
, ins
->inst_offset
);
3963 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3964 s390_ledbr(code
, s390_f15
, ins
->sreg1
);
3965 s390_ste (code
, s390_f15
, s390_r13
, ins
->inst_destbasereg
, 0);
3969 case OP_LOADR4_MEMBASE
: {
3970 if (s390_is_uimm12(ins
->inst_offset
)) {
3971 s390_ldeb (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3973 s390_basr (code
, s390_r13
, 0);
3975 s390_word (code
, ins
->inst_offset
);
3976 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3977 s390_ldeb (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
3981 case OP_ICONV_TO_R_UN
: {
3982 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
3983 s390_ltr (code
, ins
->sreg1
, ins
->sreg1
);
3984 s390_jnl (code
, 12);
3985 s390_basr (code
, s390_r13
, 0);
3987 s390_word (code
, 0x41f00000);
3988 s390_word (code
, 0);
3989 s390_adb (code
, ins
->dreg
, 0, s390_r13
, 4);
3992 case OP_ICONV_TO_R4
: {
3993 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
3996 case OP_ICONV_TO_R8
: {
3997 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
4000 case OP_FCONV_TO_I1
:
4001 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, TRUE
);
4003 case OP_FCONV_TO_U1
:
4004 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, FALSE
);
4006 case OP_FCONV_TO_I2
:
4007 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, TRUE
);
4009 case OP_FCONV_TO_U2
:
4010 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, FALSE
);
4012 case OP_FCONV_TO_I4
:
4014 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, TRUE
);
4016 case OP_FCONV_TO_U4
:
4018 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, FALSE
);
4020 case OP_FCONV_TO_I8
:
4021 case OP_FCONV_TO_U8
:
4022 g_assert_not_reached ();
4023 /* Implemented as helper calls */
4025 case OP_LCONV_TO_R_UN
:
4026 g_assert_not_reached ();
4027 /* Implemented as helper calls */
4029 case OP_LCONV_TO_OVF_I
:
4030 case OP_LCONV_TO_OVF_I4_2
: {
4031 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4033 s390_ltr (code
, ins
->sreg1
, ins
->sreg1
);
4034 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
4035 s390_ltr (code
, ins
->sreg2
, ins
->sreg2
);
4036 s390_jnl (code
, 0); CODEPTR(code
, o
[1]);
4037 s390_lhi (code
, s390_r13
, -1);
4038 s390_cr (code
, ins
->sreg2
, s390_r13
);
4039 s390_jnz (code
, 0); CODEPTR(code
, o
[2]);
4040 s390_j (code
, 0); CODEPTR(code
, o
[3]);
4041 PTRSLOT(code
, o
[0]);
4042 s390_ltr (code
, ins
->sreg2
, ins
->sreg2
);
4043 s390_jz (code
, 0); CODEPTR(code
, o
[4]);
4044 PTRSLOT(code
, o
[1]);
4045 PTRSLOT(code
, o
[2]);
4046 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4047 MONO_PATCH_INFO_EXC
, "OverflowException");
4048 s390_brasl (code
, s390_r14
, 0);
4049 PTRSLOT(code
, o
[3]);
4050 PTRSLOT(code
, o
[4]);
4051 if (ins
->dreg
!= ins
->sreg1
)
4052 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
4056 s390_sqdbr (code
, ins
->dreg
, ins
->sreg1
);
4061 s390_adbr (code
, ins
->dreg
, src2
);
4065 CHECK_SRCDST_NCOM_F
;
4066 s390_sdbr (code
, ins
->dreg
, src2
);
4071 s390_mdbr (code
, ins
->dreg
, src2
);
4075 CHECK_SRCDST_NCOM_F
;
4076 s390_ddbr (code
, ins
->dreg
, src2
);
4080 s390_lcdbr (code
, ins
->dreg
, ins
->sreg1
);
4084 CHECK_SRCDST_NCOM_F
;
4085 s390_didbr (code
, ins
->dreg
, src2
, 5, s390_f15
);
4089 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4093 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4094 s390_lhi (code
, ins
->dreg
, 1);
4096 s390_lhi (code
, ins
->dreg
, 0);
4100 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4101 s390_lhi (code
, ins
->dreg
, 1);
4103 s390_lhi (code
, ins
->dreg
, 0);
4107 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4108 s390_lhi (code
, ins
->dreg
, 1);
4110 s390_lhi (code
, ins
->dreg
, 0);
4114 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4115 s390_lhi (code
, ins
->dreg
, 1);
4117 s390_lhi (code
, ins
->dreg
, 0);
4121 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4122 s390_lhi (code
, ins
->dreg
, 1);
4124 s390_lhi (code
, ins
->dreg
, 0);
4129 s390_jo (code
, 0); CODEPTR(code
, o
);
4130 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
4135 EMIT_COND_BRANCH (ins
, S390_CC_NE
|S390_CC_OV
);
4139 s390_jo (code
, 0); CODEPTR(code
, o
);
4140 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
4145 EMIT_COND_BRANCH (ins
, S390_CC_LT
|S390_CC_OV
);
4149 s390_jo (code
, 0); CODEPTR(code
, o
);
4150 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
4155 EMIT_COND_BRANCH (ins
, S390_CC_GT
|S390_CC_OV
);
4159 s390_jo (code
, 0); CODEPTR(code
, o
);
4160 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
4165 EMIT_COND_BRANCH (ins
, S390_CC_GE
|S390_CC_OV
);
4169 s390_jo (code
, 0); CODEPTR(code
, o
);
4170 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
4175 EMIT_COND_BRANCH (ins
, S390_CC_LE
|S390_CC_OV
);
4179 s390_lhi (code
, s390_r13
, 0x7f);
4180 s390_tcdb (code
, ins
->sreg1
, 0, s390_r13
, 0);
4181 s390_jz (code
, 0); CODEPTR(code
, o
);
4182 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4183 MONO_PATCH_INFO_EXC
, "ArithmeticException");
4184 s390_brasl (code
, s390_r14
,0);
4188 case OP_S390_MOVE
: {
4189 if (ins
->backend
.size
> 0) {
4190 if (ins
->backend
.size
<= 256) {
4191 s390_mvc (code
, ins
->backend
.size
, ins
->dreg
,
4192 ins
->inst_offset
, ins
->sreg1
, ins
->inst_imm
);
4194 s390_lr (code
, s390_r0
, ins
->dreg
);
4195 if (s390_is_imm16 (ins
->inst_offset
)) {
4196 s390_ahi (code
, s390_r0
, ins
->inst_offset
);
4198 s390_basr (code
, s390_r13
, 0);
4200 s390_long (code
, ins
->inst_offset
);
4201 s390_a (code
, s390_r0
, 0, s390_r13
, 4);
4203 s390_lr (code
, s390_r12
, ins
->sreg1
);
4204 if (s390_is_imm16 (ins
->inst_imm
)) {
4205 s390_ahi (code
, s390_r12
, ins
->inst_imm
);
4207 s390_basr (code
, s390_r13
, 0);
4209 s390_long (code
, ins
->inst_imm
);
4210 s390_a (code
, s390_r12
, 0, s390_r13
, 4);
4212 if (s390_is_imm16 (ins
->backend
.size
)) {
4213 s390x_lhi (code
, s390_r1
, ins
->backend
.size
);
4215 s390_basr (code
, s390_r13
, 0);
4217 s390_long (code
, ins
->backend
.size
);
4218 s390_l (code
, s390_r1
, 0, s390_r13
, 4);
4220 s390_lr (code
, s390_r1
, ins
->backend
.size
);
4221 s390_lr (code
, s390_r13
, s390_r1
);
4222 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
4227 case OP_ATOMIC_ADD_I4
: {
4228 s390_lr (code
, s390_r1
, ins
->sreg2
);
4229 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4230 s390_a (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4231 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4232 s390_jnz (code
, -7);
4233 s390_lr (code
, ins
->dreg
, s390_r1
);
4236 case OP_ATOMIC_ADD_NEW_I4
: {
4237 s390_lr (code
, s390_r1
, ins
->sreg2
);
4238 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4239 s390_a (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4240 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4241 s390_jnz (code
, -7);
4242 s390_lr (code
, ins
->dreg
, s390_r1
);
4245 case OP_ATOMIC_EXCHANGE_I4
: {
4246 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4247 s390_cs (code
, s390_r0
, ins
->sreg2
, ins
->inst_basereg
, ins
->inst_offset
);
4248 s390_jnz (code
, -4);
4249 s390_lr (code
, ins
->dreg
, s390_r0
);
4252 case OP_S390_BKCHAIN
: {
4253 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
4254 if (s390_is_imm16 (cfg
->stack_offset
)) {
4255 s390_ahi (code
, ins
->dreg
, cfg
->stack_offset
);
4257 s390_basr (code
, s390_r13
, 0);
4259 s390_word (code
, cfg
->stack_offset
);
4260 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
4263 case OP_MEMORY_BARRIER
: {
4267 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins
->opcode
), __FUNCTION__
);
4268 g_assert_not_reached ();
4271 if ((cfg
->opt
& MONO_OPT_BRANCH
) && ((code
- cfg
->native_code
- offset
) > max_len
)) {
4272 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
4273 mono_inst_name (ins
->opcode
), max_len
, code
- cfg
->native_code
- offset
);
4274 g_assert_not_reached ();
4280 last_offset
= offset
;
4283 cfg
->code_len
= code
- cfg
->native_code
;
4286 /*========================= End of Function ========================*/
4288 /*------------------------------------------------------------------*/
4290 /* Name - mono_arch_register_lowlevel_calls */
4292 /* Function - Register routines to help with --trace operation. */
4294 /*------------------------------------------------------------------*/
4297 mono_arch_register_lowlevel_calls (void)
4299 mono_register_jit_icall (mono_arch_get_lmf_addr
, "mono_arch_get_lmf_addr", NULL
, TRUE
);
4302 /*========================= End of Function ========================*/
4304 /*------------------------------------------------------------------*/
4306 /* Name - mono_arch_patch_code */
4308 /* Function - Process the patch data created during the */
4309 /* instruction build process. This resolves jumps, */
4310 /* calls, variables etc. */
4312 /*------------------------------------------------------------------*/
4315 mono_arch_patch_code (MonoMethod
*method
, MonoDomain
*domain
,
4316 guint8
*code
, MonoJumpInfo
*ji
, gboolean run_cctors
)
4318 MonoJumpInfo
*patch_info
;
4320 for (patch_info
= ji
; patch_info
; patch_info
= patch_info
->next
) {
4321 unsigned char *ip
= patch_info
->ip
.i
+ code
;
4322 gconstpointer target
= NULL
;
4324 target
= mono_resolve_patch_target (method
, domain
, code
,
4325 patch_info
, run_cctors
);
4327 switch (patch_info
->type
) {
4328 case MONO_PATCH_INFO_IP
:
4329 case MONO_PATCH_INFO_EXC_NAME
:
4330 case MONO_PATCH_INFO_LDSTR
:
4331 case MONO_PATCH_INFO_TYPE_FROM_HANDLE
:
4332 case MONO_PATCH_INFO_LDTOKEN
:
4333 case MONO_PATCH_INFO_EXC
:
4335 case MONO_PATCH_INFO_SWITCH
:
4336 /*----------------------------------*/
4337 /* ip points at the basr r13,0/j +4 */
4338 /* instruction the vtable value */
4339 /* follows this (i.e. ip+6) */
4340 /*----------------------------------*/
4341 *((gconstpointer
*)(ip
+6)) = target
;
4344 case MONO_PATCH_INFO_METHODCONST
:
4345 case MONO_PATCH_INFO_CLASS
:
4346 case MONO_PATCH_INFO_IMAGE
:
4347 case MONO_PATCH_INFO_FIELD
:
4348 case MONO_PATCH_INFO_IID
:
4349 target
= S390_RELATIVE(target
, ip
);
4351 case MONO_PATCH_INFO_R4
:
4352 case MONO_PATCH_INFO_R8
:
4353 case MONO_PATCH_INFO_METHOD_REL
:
4354 g_assert_not_reached ();
4357 target
= S390_RELATIVE(target
, ip
);
4360 s390_patch (ip
, (guint32
) target
);
4364 /*========================= End of Function ========================*/
4366 /*------------------------------------------------------------------*/
4368 /* Name - emit_load_volatile_registers */
4370 /* Function - Create the instruction sequence for loading the */
4371 /* parameter registers for use with the 'tail' op. */
4373 /* The register loading operations performed here */
4374 /* are the mirror of the store operations performed */
4375 /* in mono_arch_emit_prolog and need to be kept in */
4376 /* synchronization with it. */
4378 /*------------------------------------------------------------------*/
4381 emit_load_volatile_registers (guint8
* code
, MonoCompile
*cfg
)
4383 MonoMethod
*method
= cfg
->method
;
4384 MonoMethodSignature
*sig
;
4389 sig
= mono_method_signature (method
);
4392 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
4394 if (cinfo
->struct_ret
) {
4395 ArgInfo
*ainfo
= &cinfo
->ret
;
4396 inst
= cfg
->vret_addr
;
4397 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4400 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4401 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4402 inst
= cfg
->args
[pos
];
4404 if (inst
->opcode
== OP_REGVAR
) {
4405 if (ainfo
->regtype
== RegTypeGeneral
)
4406 s390_lr (code
, ainfo
->reg
, inst
->dreg
);
4407 else if (ainfo
->regtype
== RegTypeFP
) {
4408 if (inst
->dreg
!= ainfo
->reg
) {
4409 if (ainfo
->size
== 4) {
4410 s390_ldebr (code
, ainfo
->reg
, inst
->dreg
);
4412 s390_ldr (code
, ainfo
->reg
, inst
->dreg
);
4416 else if (ainfo
->regtype
== RegTypeBase
) {
4418 g_assert_not_reached ();
4420 if (ainfo
->regtype
== RegTypeGeneral
) {
4421 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4422 g_assert_not_reached();
4423 switch (ainfo
->size
) {
4425 s390_ic (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4428 s390_lh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4431 s390_lm (code
, ainfo
->reg
, ainfo
->reg
+ 1,
4432 inst
->inst_basereg
, inst
->inst_offset
);
4435 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4437 } else if (ainfo
->regtype
== RegTypeBase
) {
4438 } else if (ainfo
->regtype
== RegTypeFP
) {
4439 if (ainfo
->size
== 8)
4440 s390_ld (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4441 else if (ainfo
->size
== 4)
4442 s390_le (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4444 g_assert_not_reached ();
4445 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4446 if (ainfo
->reg
!= STK_BASE
) {
4447 switch (ainfo
->size
) {
4449 s390_ic (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4452 s390_lh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4455 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4458 s390_lm (code
, ainfo
->reg
, ainfo
->reg
+1, inst
->inst_basereg
, inst
->inst_offset
);
4462 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4463 if (ainfo
->reg
!= STK_BASE
) {
4464 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4467 g_assert_not_reached ();
4475 /*========================= End of Function ========================*/
4477 /*------------------------------------------------------------------*/
4479 /* Name - mono_arch_emit_prolog */
4481 /* Function - Create the instruction sequence for a function */
4484 /*------------------------------------------------------------------*/
4487 mono_arch_emit_prolog (MonoCompile
*cfg
)
4489 MonoMethod
*method
= cfg
->method
;
4491 MonoMethodSignature
*sig
;
4493 int alloc_size
, pos
, max_offset
, i
;
4499 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
))
4502 cfg
->code_size
= 1024;
4503 cfg
->native_code
= code
= g_malloc (cfg
->code_size
);
4505 s390_stm (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4507 if (cfg
->arch
.bkchain_reg
!= -1)
4508 s390_lr (code
, cfg
->arch
.bkchain_reg
, STK_BASE
);
4510 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
) {
4511 cfg
->used_int_regs
|= 1 << 11;
4514 alloc_size
= cfg
->stack_offset
;
4516 cfg
->stack_usage
= alloc_size
;
4517 s390_lr (code
, s390_r11
, STK_BASE
);
4518 if (s390_is_uimm16 (alloc_size
)) {
4519 s390_ahi (code
, STK_BASE
, -alloc_size
);
4521 int stackSize
= alloc_size
;
4522 while (stackSize
> 32767) {
4523 s390_ahi (code
, STK_BASE
, -32767);
4526 s390_ahi (code
, STK_BASE
, -stackSize
);
4528 s390_st (code
, s390_r11
, 0, STK_BASE
, 0);
4530 if (cfg
->frame_reg
!= STK_BASE
)
4531 s390_lr (code
, s390_r11
, STK_BASE
);
4533 /* compute max_offset in order to use short forward jumps
4534 * we always do it on s390 because the immediate displacement
4535 * for jumps is too small
4538 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
4539 MonoInst
*ins
= bb
->code
;
4540 bb
->max_offset
= max_offset
;
4542 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
)
4545 MONO_BB_FOR_EACH_INS (bb
, ins
)
4546 max_offset
+= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
4549 /* load arguments allocated to register from the stack */
4550 sig
= mono_method_signature (method
);
4553 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
4555 if (cinfo
->struct_ret
) {
4556 ArgInfo
*ainfo
= &cinfo
->ret
;
4557 inst
= cfg
->vret_addr
;
4558 inst
->backend
.size
= ainfo
->vtsize
;
4559 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4562 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4563 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4564 inst
= cfg
->args
[pos
];
4566 if (inst
->opcode
== OP_VTARG_ADDR
)
4567 inst
= inst
->inst_left
;
4569 if (inst
->opcode
== OP_REGVAR
) {
4570 if (ainfo
->regtype
== RegTypeGeneral
)
4571 s390_lr (code
, inst
->dreg
, ainfo
->reg
);
4572 else if (ainfo
->regtype
== RegTypeFP
) {
4573 if (inst
->dreg
!= ainfo
->reg
) {
4574 if (ainfo
->size
== 4) {
4575 s390_ledbr (code
, inst
->dreg
, ainfo
->reg
);
4577 s390_ldr (code
, inst
->dreg
, ainfo
->reg
);
4581 else if (ainfo
->regtype
== RegTypeBase
) {
4582 s390_lr (code
, s390_r13
, STK_BASE
);
4583 s390_ahi (code
, s390_r13
, alloc_size
);
4584 s390_l (code
, inst
->dreg
, 0, s390_r13
, ainfo
->offset
);
4586 g_assert_not_reached ();
4588 if (cfg
->verbose_level
> 2)
4589 g_print ("Argument %d assigned to register %s\n",
4590 pos
, mono_arch_regname (inst
->dreg
));
4592 if (ainfo
->regtype
== RegTypeGeneral
) {
4593 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4594 g_assert_not_reached();
4595 switch (ainfo
->size
) {
4597 s390_stc (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4600 s390_sth (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4603 s390_stm (code
, ainfo
->reg
, ainfo
->reg
+ 1,
4604 inst
->inst_basereg
, inst
->inst_offset
);
4607 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4609 } else if (ainfo
->regtype
== RegTypeBase
) {
4610 } else if (ainfo
->regtype
== RegTypeFP
) {
4611 if (ainfo
->size
== 8)
4612 s390_std (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4613 else if (ainfo
->size
== 4)
4614 s390_ste (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4616 g_assert_not_reached ();
4617 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4618 int doffset
= inst
->inst_offset
;
4620 if (ainfo
->reg
!= STK_BASE
)
4624 s390_lr (code
, s390_r13
, STK_BASE
);
4625 s390_ahi (code
, s390_r13
, alloc_size
);
4627 switch (ainfo
->size
) {
4629 if (ainfo
->reg
== STK_BASE
)
4630 s390_ic (code
, reg
, 0, s390_r13
, ainfo
->offset
+3);
4631 s390_stc (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4634 if (ainfo
->reg
== STK_BASE
)
4635 s390_lh (code
, reg
, 0, s390_r13
, ainfo
->offset
+2);
4636 s390_sth (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4639 if (ainfo
->reg
== STK_BASE
)
4640 s390_l (code
, reg
, 0, s390_r13
, ainfo
->offset
);
4641 s390_st (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4644 if (ainfo
->reg
== STK_BASE
)
4645 s390_lm (code
, s390_r0
, s390_r1
, s390_r13
, ainfo
->offset
);
4646 s390_stm (code
, reg
, reg
+1, inst
->inst_basereg
, doffset
);
4649 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4650 if (ainfo
->reg
!= STK_BASE
)
4651 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4653 g_assert_not_reached ();
4658 if (method
->save_lmf
) {
4659 /*---------------------------------------------------------------*/
4660 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4661 /*---------------------------------------------------------------*/
4662 lmfOffset
= alloc_size
- sizeof(MonoLMF
);
4664 s390_lr (code
, s390_r13
, cfg
->frame_reg
);
4665 if (s390_is_uimm16(lmfOffset
))
4666 s390_ahi (code
, s390_r13
, lmfOffset
);
4668 s390_basr (code
, s390_r14
, 0);
4670 s390_word (code
, lmfOffset
);
4671 s390_a (code
, s390_r13
, 0, s390_r14
, 4);
4674 /*---------------------------------------------------------------*/
4675 /* Preserve the parameter registers while we fix up the lmf */
4676 /*---------------------------------------------------------------*/
4677 s390_stm (code
, s390_r2
, s390_r6
, s390_r13
,
4678 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4680 /*---------------------------------------------------------------*/
4681 /* On return from this call r2 have the address of the &lmf */
4682 /*---------------------------------------------------------------*/
4683 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4684 MONO_PATCH_INFO_INTERNAL_METHOD
,
4685 (gpointer
)"mono_get_lmf_addr");
4686 s390_brasl (code
, s390_r14
, 0);
4688 /*---------------------------------------------------------------*/
4689 /* Set lmf.lmf_addr = jit_tls->lmf */
4690 /*---------------------------------------------------------------*/
4691 s390_st (code
, s390_r2
, 0, s390_r13
,
4692 G_STRUCT_OFFSET(MonoLMF
, lmf_addr
));
4694 /*---------------------------------------------------------------*/
4695 /* Get current lmf */
4696 /*---------------------------------------------------------------*/
4697 s390_l (code
, s390_r0
, 0, s390_r2
, 0);
4699 /*---------------------------------------------------------------*/
4700 /* Set our lmf as the current lmf */
4701 /*---------------------------------------------------------------*/
4702 s390_st (code
, s390_r13
, 0, s390_r2
, 0);
4704 /*---------------------------------------------------------------*/
4705 /* Have our lmf.previous_lmf point to the last lmf */
4706 /*---------------------------------------------------------------*/
4707 s390_st (code
, s390_r0
, 0, s390_r13
,
4708 G_STRUCT_OFFSET(MonoLMF
, previous_lmf
));
4710 /*---------------------------------------------------------------*/
4711 /* save method info */
4712 /*---------------------------------------------------------------*/
4713 s390_basr (code
, s390_r1
, 0);
4715 s390_word (code
, method
);
4716 s390_l (code
, s390_r1
, 0, s390_r1
, 4);
4717 s390_st (code
, s390_r1
, 0, s390_r13
,
4718 G_STRUCT_OFFSET(MonoLMF
, method
));
4720 /*---------------------------------------------------------------*/
4721 /* save the current IP */
4722 /*---------------------------------------------------------------*/
4723 s390_st (code
, STK_BASE
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, ebp
));
4724 s390_basr (code
, s390_r1
, 0);
4725 s390_la (code
, s390_r1
, 0, s390_r1
, 0);
4726 s390_st (code
, s390_r1
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, eip
));
4728 /*---------------------------------------------------------------*/
4729 /* Save general and floating point registers */
4730 /*---------------------------------------------------------------*/
4731 s390_stm (code
, s390_r2
, s390_r12
, s390_r13
,
4732 G_STRUCT_OFFSET(MonoLMF
, gregs
[2]));
4733 for (i
= 0; i
< 16; i
++) {
4734 s390_std (code
, i
, 0, s390_r13
,
4735 G_STRUCT_OFFSET(MonoLMF
, fregs
[i
]));
4738 /*---------------------------------------------------------------*/
4739 /* Restore the parameter registers now that we've set up the lmf */
4740 /*---------------------------------------------------------------*/
4741 s390_lm (code
, s390_r2
, s390_r6
, s390_r13
,
4742 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4746 code
= mono_arch_instrument_prolog(cfg
, enter_method
, code
, TRUE
);
4748 cfg
->code_len
= code
- cfg
->native_code
;
4750 g_assert (cfg
->code_len
< cfg
->code_size
);
4755 /*========================= End of Function ========================*/
4757 /*------------------------------------------------------------------*/
4759 /* Name - mono_arch_emit_epilog */
4761 /* Function - Emit the instructions for a function epilog. */
4763 /*------------------------------------------------------------------*/
4766 mono_arch_emit_epilog (MonoCompile
*cfg
)
4768 MonoMethod
*method
= cfg
->method
;
4771 int max_epilog_size
= 96;
4773 if (cfg
->method
->save_lmf
)
4774 max_epilog_size
+= 128;
4776 if (mono_jit_trace_calls
!= NULL
)
4777 max_epilog_size
+= 128;
4779 if (cfg
->prof_options
& MONO_PROFILE_ENTER_LEAVE
)
4780 max_epilog_size
+= 128;
4782 while ((cfg
->code_len
+ max_epilog_size
) > (cfg
->code_size
- 16)) {
4783 cfg
->code_size
*= 2;
4784 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4785 mono_jit_stats
.code_reallocs
++;
4788 code
= cfg
->native_code
+ cfg
->code_len
;
4790 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
)) {
4791 code
= mono_arch_instrument_epilog (cfg
, leave_method
, code
, TRUE
);
4795 if (method
->save_lmf
)
4796 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
4798 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
)
4799 s390_l (code
, STK_BASE
, 0, STK_BASE
, 0);
4801 code
= backUpStackPtr(cfg
, code
, STK_BASE
);
4803 s390_lm (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4804 s390_br (code
, s390_r14
);
4806 cfg
->code_len
= code
- cfg
->native_code
;
4808 g_assert (cfg
->code_len
< cfg
->code_size
);
4812 /*========================= End of Function ========================*/
4814 /*------------------------------------------------------------------*/
4816 /* Name - mono_arch_emit_exceptions */
4818 /* Function - Emit the blocks to handle exception conditions. */
4820 /*------------------------------------------------------------------*/
4823 mono_arch_emit_exceptions (MonoCompile
*cfg
)
4825 MonoJumpInfo
*patch_info
;
4831 MonoClass
*exc_classes
[MAX_EXC
];
4832 guint8
*exc_throw_start
[MAX_EXC
];
4834 for (patch_info
= cfg
->patch_info
;
4836 patch_info
= patch_info
->next
) {
4837 if (patch_info
->type
== MONO_PATCH_INFO_EXC
)
4841 code_size
= exc_count
* 26;
4843 while ((cfg
->code_len
+ code_size
) > (cfg
->code_size
- 16)) {
4844 cfg
->code_size
*= 2;
4845 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4846 mono_jit_stats
.code_reallocs
++;
4849 code
= cfg
->native_code
+ cfg
->code_len
;
4851 /*---------------------------------------------------------------------*/
4852 /* Add code to raise exceptions */
4853 /*---------------------------------------------------------------------*/
4854 for (patch_info
= cfg
->patch_info
; patch_info
; patch_info
= patch_info
->next
) {
4855 switch (patch_info
->type
) {
4856 case MONO_PATCH_INFO_EXC
: {
4857 guint8
*ip
= patch_info
->ip
.i
+ cfg
->native_code
;
4858 MonoClass
*exc_class
;
4861 /*-----------------------------------------------------*/
4862 /* Patch the branch in epilog to come here */
4863 /*-----------------------------------------------------*/
4864 s390_patch (ip
+ 2, (guint32
) (S390_RELATIVE(code
,ip
)));
4866 exc_class
= mono_class_from_name (mono_defaults
.corlib
,
4868 patch_info
->data
.name
);
4869 g_assert (exc_class
);
4870 throw_ip
= patch_info
->ip
.i
;
4872 for (iExc
= 0; iExc
< nThrows
; ++iExc
)
4873 if (exc_classes
[iExc
] == exc_class
)
4876 if (iExc
< nThrows
) {
4877 s390_jcl (code
, S390_CC_UN
, (guint32
) exc_throw_start
[iExc
]);
4878 patch_info
->type
= MONO_PATCH_INFO_NONE
;
4881 if (nThrows
< MAX_EXC
) {
4882 exc_classes
[nThrows
] = exc_class
;
4883 exc_throw_start
[nThrows
] = code
;
4886 /*---------------------------------------------*/
4887 /* Patch the parameter passed to the handler */
4888 /*---------------------------------------------*/
4889 s390_basr (code
, s390_r13
, 0);
4891 s390_word (code
, patch_info
->data
.target
);
4892 /*---------------------------------------------*/
4893 /* Load return address & parameter register */
4894 /*---------------------------------------------*/
4895 s390_larl (code
, s390_r14
, (gsize
)S390_RELATIVE((patch_info
->ip
.i
+
4896 cfg
->native_code
+ 8), code
));
4897 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
4898 /*---------------------------------------------*/
4899 /* Reuse the current patch to set the jump */
4900 /*---------------------------------------------*/
4901 patch_info
->type
= MONO_PATCH_INFO_INTERNAL_METHOD
;
4902 patch_info
->data
.name
= "mono_arch_throw_exception_by_name";
4903 patch_info
->ip
.i
= code
- cfg
->native_code
;
4904 s390_jcl (code
, S390_CC_UN
, 0);
4914 cfg
->code_len
= code
- cfg
->native_code
;
4916 g_assert (cfg
->code_len
< cfg
->code_size
);
4920 /*========================= End of Function ========================*/
4922 /*------------------------------------------------------------------*/
4924 /* Name - mono_arch_setup_jit_tls_data */
4926 /* Function - Setup the JIT's Thread Level Specific Data. */
4928 /*------------------------------------------------------------------*/
4931 mono_arch_setup_jit_tls_data (MonoJitTlsData
*tls
)
4934 if (!tls_offset_inited
) {
4935 tls_offset_inited
= TRUE
;
4939 __asm__ ("\tear\t%r1,0\n"
4946 : "=r" (appdomain_tls_offset
),
4947 "=r" (thread_tls_offset
),
4948 "=r" (lmf_tls_offset
)
4949 : "r" (&tls_appdomain
),
4950 "r" (&tls_current_object
),
4951 "r" (&mono_lmf_addr
)
4957 if (!lmf_addr_key_inited
) {
4958 lmf_addr_key_inited
= TRUE
;
4959 pthread_key_create (&lmf_addr_key
, NULL
);
4961 pthread_setspecific (lmf_addr_key
, &tls
->lmf
);
4965 /*========================= End of Function ========================*/
4967 /*------------------------------------------------------------------*/
4969 /* Name - mono_arch_free_jit_tls_data */
4971 /* Function - Free tls data. */
4973 /*------------------------------------------------------------------*/
4976 mono_arch_free_jit_tls_data (MonoJitTlsData
*tls
)
4980 /*========================= End of Function ========================*/
4982 /*------------------------------------------------------------------*/
4984 /* Name - mono_arch_emit_inst_for_method */
4986 /*------------------------------------------------------------------*/
4989 mono_arch_emit_inst_for_method (MonoCompile
*cfg
, MonoMethod
*cmethod
, MonoMethodSignature
*fsig
, MonoInst
**args
)
4994 /*========================= End of Function ========================*/
4996 /*------------------------------------------------------------------*/
4998 /* Name - mono_arch_decompose_opts */
5000 /*------------------------------------------------------------------*/
5003 mono_arch_decompose_opts (MonoCompile
*cfg
, MonoInst
*ins
)
5005 switch (ins
->opcode
) {
5007 ins
->opcode
= OP_S390_ISUB_OVF
;
5009 case OP_ISUB_OVF_UN
:
5010 ins
->opcode
= OP_S390_ISUB_OVF_UN
;
5013 ins
->opcode
= OP_S390_IADD_OVF
;
5015 case OP_IADD_OVF_UN
:
5016 ins
->opcode
= OP_S390_IADD_OVF_UN
;
5023 /*========================= End of Function ========================*/
5025 /*------------------------------------------------------------------*/
5027 /* Name - mono_arch_decompose_long_opts */
5029 /*------------------------------------------------------------------*/
5032 mono_arch_decompose_long_opts (MonoCompile
*cfg
, MonoInst
*ins
)
5034 // The generic code seems to work for OP_LSUB fine on s390, why is a different
5035 // implementation needed ? gcc also seems to use the different implementation.
5036 // FIXME: What about the other OP_L opcodes below ?
5038 switch (ins
->opcode
) {
5040 case OP_LADD_OVF_UN
:
5042 case OP_LSUB_OVF_UN
: {
5045 switch (ins
->opcode
) {
5047 opcode
= OP_S390_LADD
;
5050 opcode
= OP_S390_LADD_OVF
;
5052 case OP_LADD_OVF_UN
:
5053 opcode
= OP_S390_LADD_OVF_UN
;
5056 opcode
= OP_S390_LSUB
;
5059 opcode
= OP_S390_LSUB_OVF
;
5061 case OP_LSUB_OVF_UN
:
5062 opcode
= OP_S390_LSUB_OVF_UN
;
5065 g_assert_not_reached ();
5068 /* These hard regs make ssa crazy */
5069 cfg
->disable_ssa
= TRUE
;
5070 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r0
, ins
->sreg1
+ 1);
5071 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r1
, ins
->sreg1
+ 2);
5072 MONO_EMIT_NEW_BIALU (cfg
, opcode
, ins
->dreg
, ins
->sreg2
+ 1, ins
->sreg2
+ 2);
5077 int dreg
= mono_alloc_dreg (cfg
, STACK_I8
);
5078 MONO_EMIT_NEW_I8CONST (cfg
, dreg
, ins
->inst_l
);
5079 MONO_EMIT_NEW_BIALU (cfg
, OP_LADD
, ins
->dreg
, ins
->sreg1
, dreg
);
5084 int dreg
= mono_alloc_dreg (cfg
, STACK_I8
);
5085 MONO_EMIT_NEW_I8CONST (cfg
, dreg
, ins
->inst_l
);
5086 MONO_EMIT_NEW_BIALU (cfg
, OP_LSUB
, ins
->dreg
, ins
->sreg1
, dreg
);
5091 MONO_EMIT_NEW_BIALU (cfg
, OP_S390_LNEG
, ins
->dreg
, ins
->sreg1
+ 1, ins
->sreg1
+ 2);
5096 ins
->opcode
= OP_S390_ISUB_OVF
;
5098 case OP_ISUB_OVF_UN
:
5099 ins
->opcode
= OP_S390_ISUB_OVF_UN
;
5106 /*========================= End of Function ========================*/
5108 /*------------------------------------------------------------------*/
5110 /* Name - mono_arch_print_tree */
5112 /* Function - Print platform-specific opcode details. */
5114 /* Returns - 1 - opcode details have been printed */
5115 /* 0 - opcode details have not been printed */
5117 /*------------------------------------------------------------------*/
5120 mono_arch_print_tree (MonoInst
*tree
, int arity
)
5124 switch (tree
->opcode
) {
5125 case OP_S390_LOADARG
:
5126 case OP_S390_ARGREG
:
5127 case OP_S390_ARGPTR
:
5128 printf ("[0x%lx(%s)]", tree
->inst_offset
,
5129 mono_arch_regname (tree
->inst_basereg
));
5132 case OP_S390_STKARG
:
5133 printf ("[0x%lx(previous_frame)]",
5138 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5139 tree
->inst_offset
, tree
->backend
.size
,
5140 mono_arch_regname(tree
->dreg
), tree
->inst_imm
,
5141 mono_arch_regname(tree
->sreg1
));
5144 case OP_S390_SETF4RET
:
5146 mono_arch_fregname (tree
->dreg
),
5147 mono_arch_fregname (tree
->sreg1
));
5151 printf ("[0x%lx(0x%lx,%s)]", tree
->inst_offset
,
5153 mono_arch_regname (tree
->sreg1
));
5156 case OP_S390_BKCHAIN
:
5157 printf ("[previous_frame(%s)]",
5158 mono_arch_regname (tree
->sreg1
));
5167 /*========================= End of Function ========================*/
5169 /*------------------------------------------------------------------*/
5171 /* Name - mono_arch_regalloc_cost */
5173 /* Function - Determine the cost, in the number of memory */
5174 /* references, of the action of allocating the var- */
5175 /* iable VMV into a register during global register */
5178 /* Returns - Cost */
5180 /*------------------------------------------------------------------*/
5183 mono_arch_regalloc_cost (MonoCompile
*cfg
, MonoMethodVar
*vmv
)
5189 /*========================= End of Function ========================*/
5191 /*------------------------------------------------------------------*/
5193 /* Name - mono_arch_get_domain_intrinsic */
5199 /*------------------------------------------------------------------*/
5202 mono_arch_get_domain_intrinsic (MonoCompile
* cfg
)
5206 if (appdomain_tls_offset
== -1)
5209 MONO_INST_NEW (cfg
, ins
, OP_TLS_GET
);
5210 ins
->inst_offset
= appdomain_tls_offset
;
5214 /*========================= End of Function ========================*/
5216 /*------------------------------------------------------------------*/
5218 /* Name - mono_arch_flush_register_windows */
5224 /*------------------------------------------------------------------*/
5227 mono_arch_flush_register_windows (void)
5231 /*========================= End of Function ========================*/
5233 /*------------------------------------------------------------------*/
5235 /* Name - mono_arch_get_lmf_addr */
5241 /*------------------------------------------------------------------*/
5244 mono_arch_get_lmf_addr (void)
5246 return pthread_getspecific (lmf_addr_key
);
5250 /*========================= End of Function ========================*/
5252 /*------------------------------------------------------------------*/
5254 /* Name - mono_arch_get_patch_offset */
5256 /* Function - Dummy entry point until s390x supports aot. */
5258 /* Returns - Offset for patch. */
5260 /*------------------------------------------------------------------*/
5263 mono_arch_get_patch_offset (guint8
*code
)
5268 /*========================= End of Function ========================*/
5270 /*------------------------------------------------------------------*/
5272 /* Name - mono_arch_context_get_int_reg. */
5274 /* Function - Dummy entry point until s390x supports aot. */
5276 /* Returns - Pointer to intreg. */
5278 /*------------------------------------------------------------------*/
5281 mono_arch_context_get_int_reg (MonoContext
*ctx
, int reg
)
5283 /* FIXME: implement */
5284 g_assert_not_reached ();
5288 /*========================= End of Function ========================*/