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 int appdomain_tls_offset
= -1,
339 thread_tls_offset
= -1;
341 pthread_key_t lmf_addr_key
;
343 gboolean lmf_addr_key_inited
= FALSE
;
347 extern __thread MonoDomain
*tls_appdomain
;
348 extern __thread MonoThread
*tls_current_object
;
349 extern __thread gpointer mono_lmf_addr
;
353 /*====================== End of Global Variables ===================*/
355 /*------------------------------------------------------------------*/
357 /* Name - mono_arch_regname */
359 /* Function - Returns the name of the register specified by */
360 /* the input parameter. */
362 /*------------------------------------------------------------------*/
365 mono_arch_regname (int reg
) {
366 static const char * rnames
[] = {
367 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
368 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
369 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
373 if (reg
>= 0 && reg
< 16)
379 /*========================= End of Function ========================*/
381 /*------------------------------------------------------------------*/
383 /* Name - mono_arch_fregname */
385 /* Function - Returns the name of the register specified by */
386 /* the input parameter. */
388 /*------------------------------------------------------------------*/
391 mono_arch_fregname (int reg
) {
392 static const char * rnames
[] = {
393 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
394 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
395 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
399 if (reg
>= 0 && reg
< 16)
405 /*========================= End of Function ========================*/
407 /*------------------------------------------------------------------*/
409 /* Name - arch_get_argument_info */
411 /* Function - Gathers information on parameters such as size, */
412 /* alignment, and padding. arg_info should be large */
413 /* enough to hold param_count + 1 entries. */
415 /* Parameters - @csig - Method signature */
416 /* @param_count - No. of parameters to consider */
417 /* @arg_info - An array to store the result info */
419 /* Returns - Size of the activation frame */
421 /*------------------------------------------------------------------*/
424 mono_arch_get_argument_info (MonoGenericSharingContext
*gsctx
, MonoMethodSignature
*csig
,
426 MonoJitArgumentInfo
*arg_info
)
428 int k
, frame_size
= 0;
429 int size
, align
, pad
;
432 if (MONO_TYPE_ISSTRUCT (csig
->ret
)) {
433 frame_size
+= sizeof (gpointer
);
437 arg_info
[0].offset
= offset
;
440 frame_size
+= sizeof (gpointer
);
444 arg_info
[0].size
= frame_size
;
446 for (k
= 0; k
< param_count
; k
++) {
449 size
= mono_type_native_stack_size (csig
->params
[k
], &align
);
451 size
= mini_type_stack_size (NULL
, csig
->params
[k
], &align
);
453 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
454 arg_info
[k
].pad
= pad
;
456 arg_info
[k
+ 1].pad
= 0;
457 arg_info
[k
+ 1].size
= size
;
459 arg_info
[k
+ 1].offset
= offset
;
463 align
= MONO_ARCH_FRAME_ALIGNMENT
;
464 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
465 arg_info
[k
].pad
= pad
;
470 /*========================= End of Function ========================*/
472 /*------------------------------------------------------------------*/
474 /* Name - retFitsInReg. */
476 /* Function - Determines if a value can be returned in one or */
479 /*------------------------------------------------------------------*/
481 static inline gboolean
482 retFitsInReg(guint32 size
)
497 /*========================= End of Function ========================*/
499 /*------------------------------------------------------------------*/
501 /* Name - backStackPtr. */
503 /* Function - Restore Stack Pointer to previous frame. */
505 /*------------------------------------------------------------------*/
507 static inline guint8
*
508 backUpStackPtr(MonoCompile
*cfg
, guint8
*code
, gint framePtr
)
510 int stackSize
= cfg
->stack_usage
;
512 if (s390_is_uimm16 (cfg
->stack_usage
)) {
513 s390_ahi (code
, framePtr
, cfg
->stack_usage
);
515 while (stackSize
> 32767) {
516 s390_ahi (code
, framePtr
, 32767);
519 s390_ahi (code
, framePtr
, stackSize
);
524 /*========================= End of Function ========================*/
526 /*------------------------------------------------------------------*/
530 /* Function - Perform nice indenting to current level */
532 /*------------------------------------------------------------------*/
538 indent_level
+= diff
;
545 indent_level
+= diff
;
548 /*========================= End of Function ========================*/
550 /*------------------------------------------------------------------*/
552 /* Name - decodeParm */
554 /* Function - Decode a parameter for the trace. */
556 /*------------------------------------------------------------------*/
559 decodeParm(MonoType
*type
, void *curParm
, int size
)
564 printf("[BYREF:%p], ", *((char **) curParm
));
566 simpleType
= mono_type_get_underlying_type(type
)->type
;
568 switch (simpleType
) {
570 printf ("[INTPTR:%p], ", *((int **) curParm
));
573 printf ("[UINTPTR:%p], ", *((int **) curParm
));
575 case MONO_TYPE_BOOLEAN
:
576 printf ("[BOOL:%d], ", *((int *) curParm
));
578 case MONO_TYPE_CHAR
:
579 printf ("[CHAR:%c], ", *((int *) curParm
));
582 printf ("[INT1:%d], ", *((int *) curParm
));
585 printf ("[INT2:%d], ", *((int *) curParm
));
588 printf ("[INT4:%d], ", *((int *) curParm
));
591 printf ("[UINT1:%u], ", *((unsigned int *) curParm
));
594 printf ("[UINT2:%u], ", *((guint16
*) curParm
));
597 printf ("[UINT4:%u], ", *((guint32
*) curParm
));
600 printf ("[UINT8:%llu], ", *((guint64
*) curParm
));
602 case MONO_TYPE_STRING
: {
603 MonoString
*s
= *((MonoString
**) curParm
);
605 g_assert (((MonoObject
*) s
)->vtable
->klass
== mono_defaults
.string_class
);
606 printf("[STRING:%p:%s], ", s
, mono_string_to_utf8(s
));
608 printf("[STRING:null], ");
612 case MONO_TYPE_CLASS
:
613 case MONO_TYPE_OBJECT
: {
614 MonoObject
*obj
= *((MonoObject
**) curParm
);
616 if ((obj
) && (obj
->vtable
)) {
617 printf("[CLASS/OBJ:");
618 class = obj
->vtable
->klass
;
619 printf("%p [%p] ",obj
,curParm
);
620 // if (class == mono_defaults.string_class) {
621 // printf("[STRING:%p:%s]",
622 // *obj, mono_string_to_utf8 (obj));
623 // } else if (class == mono_defaults.int32_class) {
624 // printf("[INT32:%p:%d]",
625 // obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
627 // printf("[%s.%s:%p]",
628 // class->name_space, class->name, obj);
631 printf("[OBJECT:null], ");
636 printf("[PTR:%p], ", *((gpointer
**) (curParm
)));
638 case MONO_TYPE_FNPTR
:
639 printf("[FNPTR:%p], ", *((gpointer
**) (curParm
)));
641 case MONO_TYPE_ARRAY
:
642 printf("[ARRAY:%p], ", *((gpointer
**) (curParm
)));
644 case MONO_TYPE_SZARRAY
:
645 printf("[SZARRAY:%p], ", *((gpointer
**) (curParm
)));
648 printf("[INT8:%lld], ", *((gint64
*) (curParm
)));
651 printf("[FLOAT4:%g], ", *((double *) (curParm
)));
654 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
656 case MONO_TYPE_VALUETYPE
: {
658 MonoMarshalType
*info
;
660 if (type
->data
.klass
->enumtype
) {
661 simpleType
= mono_class_enum_basetype (type
->data
.klass
)->type
;
662 printf("{VALUETYPE} - ");
666 info
= mono_marshal_load_type_info (type
->data
.klass
);
668 if ((info
->native_size
== sizeof(float)) &&
669 (info
->num_fields
== 1) &&
670 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
671 printf("[FLOAT4:%f], ", *((float *) (curParm
)));
675 if ((info
->native_size
== sizeof(double)) &&
676 (info
->num_fields
== 1) &&
677 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
678 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
682 printf("[VALUETYPE:");
683 for (i
= 0; i
< size
; i
++)
684 printf("%02x,", *((guint8
*)curParm
+i
));
688 case MONO_TYPE_TYPEDBYREF
: {
690 printf("[TYPEDBYREF:");
691 for (i
= 0; i
< size
; i
++)
692 printf("%02x,", *((guint8
*)curParm
+i
));
697 printf("[?? - %d], ",simpleType
);
702 /*========================= End of Function ========================*/
706 /*------------------------------------------------------------------*/
708 /* Name - enter_method */
710 /* Function - Perform tracing of the entry to the current */
713 /*------------------------------------------------------------------*/
716 enter_method (MonoMethod
*method
, RegParm
*rParm
, char *sp
)
718 int i
, oParm
= 0, iParm
= 0;
720 MonoMethodSignature
*sig
;
727 fname
= mono_method_full_name (method
, TRUE
);
729 printf ("ENTER: %s(", fname
);
732 ip
= (*(guint32
*) (sp
+S390_RET_ADDR_OFFSET
)) & 0x7fffffff;
733 printf (") ip: %p sp: %p - ", (gpointer
) ip
, sp
);
738 sig
= mono_method_signature (method
);
740 cinfo
= get_call_info (NULL
, NULL
, sig
, sig
->pinvoke
);
742 if (cinfo
->struct_ret
) {
743 printf ("[STRUCTRET:%p], ", (gpointer
) rParm
->gr
[0]);
748 gpointer
*this = (gpointer
*) rParm
->gr
[iParm
];
749 obj
= (MonoObject
*) this;
750 if (method
->klass
->valuetype
) {
752 printf("this:[value:%p:%08x], ",
753 this, *((guint32
*)(this+sizeof(MonoObject
))));
755 printf ("this:[NULL], ");
758 // class = obj->vtable->klass;
759 // if (class == mono_defaults.string_class) {
760 // printf ("this:[STRING:%p:%s], ",
761 // obj, mono_string_to_utf8 ((MonoString *)obj));
763 // printf ("this:%p[%s.%s], ",
764 // obj, class->name_space, class->name);
766 printf("this:%p, ",obj
);
768 printf ("this:NULL, ");
773 for (i
= 0; i
< sig
->param_count
; ++i
) {
774 ainfo
= &cinfo
->args
[i
+ oParm
];
775 switch (ainfo
->regtype
) {
776 case RegTypeGeneral
:
777 decodeParm(sig
->params
[i
], &(rParm
->gr
[ainfo
->reg
-2]), ainfo
->size
);
780 decodeParm(sig
->params
[i
], &(rParm
->fp
[ainfo
->reg
]), ainfo
->size
);
783 decodeParm(sig
->params
[i
], sp
+ainfo
->offset
, ainfo
->size
);
785 case RegTypeStructByVal
:
786 if (ainfo
->reg
!= STK_BASE
)
787 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
789 curParm
= sp
+ainfo
->offset
;
791 if (retFitsInReg (ainfo
->vtsize
))
792 decodeParm(sig
->params
[i
],
796 decodeParm(sig
->params
[i
],
797 *((char **) curParm
),
800 case RegTypeStructByAddr
:
801 if (ainfo
->reg
!= STK_BASE
)
802 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
804 curParm
= sp
+ainfo
->offset
;
806 decodeParm(sig
->params
[i
],
807 *((char **) curParm
),
819 /*========================= End of Function ========================*/
821 /*------------------------------------------------------------------*/
823 /* Name - leave_method */
827 /*------------------------------------------------------------------*/
830 leave_method (MonoMethod
*method
, ...)
837 va_start(ap
, method
);
839 fname
= mono_method_full_name (method
, TRUE
);
841 printf ("LEAVE: %s", fname
);
844 type
= mono_method_signature (method
)->ret
;
847 switch (type
->type
) {
850 case MONO_TYPE_BOOLEAN
: {
851 int val
= va_arg (ap
, int);
853 printf ("[TRUE:%d]", val
);
859 case MONO_TYPE_CHAR
: {
860 int val
= va_arg (ap
, int);
861 printf ("[CHAR:%d]", val
);
865 int val
= va_arg (ap
, int);
866 printf ("[INT1:%d]", val
);
870 int val
= va_arg (ap
, int);
871 printf ("[UINT1:%d]", val
);
875 int val
= va_arg (ap
, int);
876 printf ("[INT2:%d]", val
);
880 int val
= va_arg (ap
, int);
881 printf ("[UINT2:%d]", val
);
885 int val
= va_arg (ap
, int);
886 printf ("[INT4:%d]", val
);
890 int val
= va_arg (ap
, int);
891 printf ("[UINT4:%d]", val
);
895 int val
= va_arg (ap
, int);
896 printf ("[INT:%d]", val
);
901 int val
= va_arg (ap
, int);
902 printf ("[UINT:%d]", val
);
906 case MONO_TYPE_STRING
: {
907 MonoString
*s
= va_arg (ap
, MonoString
*);
910 g_assert (((MonoObject
*)s
)->vtable
->klass
== mono_defaults
.string_class
);
911 printf ("[STRING:%p:%s]", s
, mono_string_to_utf8 (s
));
913 printf ("[STRING:null], ");
916 case MONO_TYPE_CLASS
:
917 case MONO_TYPE_OBJECT
: {
918 MonoObject
*o
= va_arg (ap
, MonoObject
*);
920 // if ((o) && (o->vtable)) {
921 // if (o->vtable->klass == mono_defaults.boolean_class) {
922 // printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
923 // } else if (o->vtable->klass == mono_defaults.int32_class) {
924 // printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
925 // } else if (o->vtable->klass == mono_defaults.int64_class) {
926 // printf ("[INT64:%p:%lld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
928 // printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
930 printf ("[OBJECT:%p]", o
);
935 case MONO_TYPE_FNPTR
:
936 case MONO_TYPE_ARRAY
:
937 case MONO_TYPE_SZARRAY
: {
938 gpointer p
= va_arg (ap
, gpointer
);
939 printf ("[result=%p]", p
);
943 gint64 l
= va_arg (ap
, gint64
);
944 printf ("[LONG:%lld]", l
);
948 guint64 l
= va_arg (ap
, guint64
);
949 printf ("[ULONG:%llu]", l
);
954 f
= va_arg (ap
, double);
955 printf ("[FLOAT4:%g]\n", f
);
959 double f
= va_arg (ap
, double);
960 printf ("[FLOAT8:%g]\n", f
);
963 case MONO_TYPE_VALUETYPE
: {
964 MonoMarshalType
*info
;
965 if (type
->data
.klass
->enumtype
) {
966 type
= mono_class_enum_basetype (type
->data
.klass
);
969 guint8
*p
= va_arg (ap
, gpointer
);
972 info
= mono_marshal_load_type_info (type
->data
.klass
);
974 if ((info
->native_size
== sizeof(float)) &&
975 (info
->num_fields
== 1) &&
976 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
977 double f
= va_arg (ap
, double);
978 printf("[FLOAT4:%g]\n", (double) f
);
982 if ((info
->native_size
== sizeof(double)) &&
983 (info
->num_fields
== 1) &&
984 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
985 double f
= va_arg (ap
, double);
986 printf("[FLOAT8:%g]\n", f
);
990 size
= mono_type_size (type
, &align
);
997 for (j
= 0; p
&& j
< size
; j
++)
998 printf ("%02x,", p
[j
]);
1002 printf ("[VALUERET]\n");
1007 case MONO_TYPE_TYPEDBYREF
: {
1008 guint8
*p
= va_arg (ap
, gpointer
);
1010 size
= mono_type_size (type
, &align
);
1017 for (j
= 0; p
&& j
< size
; j
++)
1018 printf ("%02x,", p
[j
]);
1022 printf ("[TYPEDBYREF]\n");
1027 printf ("(unknown return type %x)",
1028 mono_method_signature (method
)->ret
->type
);
1031 ip
= ((gint32
) __builtin_return_address (0)) & 0x7fffffff;
1032 printf (" ip: %p\n", (gpointer
) ip
);
1035 /*========================= End of Function ========================*/
1037 /*------------------------------------------------------------------*/
1039 /* Name - mono_arch_cpu_init */
1041 /* Function - Perform CPU specific initialization to execute */
1044 /*------------------------------------------------------------------*/
1047 mono_arch_cpu_init (void)
1051 /*--------------------------------------*/
1052 /* Set default rounding mode for FP */
1053 /*--------------------------------------*/
1054 __asm__ ("SRNM\t%0\n\t"
1058 /*========================= End of Function ========================*/
1062 * Initialize architecture specific code.
1065 mono_arch_init (void)
1070 * Cleanup architecture specific code.
1073 mono_arch_cleanup (void)
1077 /*------------------------------------------------------------------*/
1079 /* Name - mono_arch_cpu_optimizations */
1081 /* Function - Returns the optimizations supported on this CPU */
1083 /*------------------------------------------------------------------*/
1086 mono_arch_cpu_optimizations (guint32
*exclude_mask
)
1090 /*----------------------------------------------------------*/
1091 /* no s390-specific optimizations yet */
1092 /*----------------------------------------------------------*/
1093 *exclude_mask
= MONO_OPT_INLINE
|MONO_OPT_LINEARS
;
1094 // *exclude_mask = MONO_OPT_INLINE;
1098 /*========================= End of Function ========================*/
1100 /*------------------------------------------------------------------*/
1102 /* Name - mono_arch_cpu_enumerate_simd_versions */
1104 /* Function - Returns the SIMD instruction sets on this CPU */
1106 /*------------------------------------------------------------------*/
1108 mono_arch_cpu_enumerate_simd_versions (void)
1110 /* SIMD is currently unimplemented */
1113 /*========================= End of Function ========================*/
1115 /*------------------------------------------------------------------*/
1121 /*------------------------------------------------------------------*/
1124 is_regsize_var (MonoType
*t
) {
1127 switch (mono_type_get_underlying_type (t
)->type
) {
1133 case MONO_TYPE_FNPTR
:
1135 case MONO_TYPE_OBJECT
:
1136 case MONO_TYPE_STRING
:
1137 case MONO_TYPE_CLASS
:
1138 case MONO_TYPE_SZARRAY
:
1139 case MONO_TYPE_ARRAY
:
1141 case MONO_TYPE_VALUETYPE
:
1142 if (t
->data
.klass
->enumtype
)
1143 return is_regsize_var (mono_class_enum_basetype (t
->data
.klass
));
1149 /*========================= End of Function ========================*/
1151 /*------------------------------------------------------------------*/
1153 /* Name - mono_arch_get_allocatable_int_vars */
1157 /*------------------------------------------------------------------*/
1160 mono_arch_get_allocatable_int_vars (MonoCompile
*cfg
)
1165 for (i
= 0; i
< cfg
->num_varinfo
; i
++) {
1166 MonoInst
*ins
= cfg
->varinfo
[i
];
1167 MonoMethodVar
*vmv
= MONO_VARINFO (cfg
, i
);
1170 if (vmv
->range
.first_use
.abs_pos
>= vmv
->range
.last_use
.abs_pos
)
1173 if (ins
->flags
& (MONO_INST_VOLATILE
|MONO_INST_INDIRECT
) ||
1174 (ins
->opcode
!= OP_LOCAL
&& ins
->opcode
!= OP_ARG
))
1177 /* we can only allocate 32 bit values */
1178 if (is_regsize_var (ins
->inst_vtype
)) {
1179 g_assert (MONO_VARINFO (cfg
, i
)->reg
== -1);
1180 g_assert (i
== vmv
->idx
);
1181 vars
= mono_varlist_insert_sorted (cfg
, vars
, vmv
, FALSE
);
1188 /*========================= End of Function ========================*/
1190 /*------------------------------------------------------------------*/
1192 /* Name - mono_arch_global_int_regs */
1194 /* Function - Return a list of usable integer registers. */
1196 /*------------------------------------------------------------------*/
1199 mono_arch_get_global_int_regs (MonoCompile
*cfg
)
1202 MonoMethodHeader
*header
;
1205 header
= cfg
->header
;
1206 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1207 cfg
->frame_reg
= s390_r11
;
1209 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1211 for (i
= 8; i
< top
; ++i
) {
1212 if (cfg
->frame_reg
!= i
)
1213 regs
= g_list_prepend (regs
, GUINT_TO_POINTER (i
));
1219 /*========================= End of Function ========================*/
1221 /*------------------------------------------------------------------*/
1223 /* Name - mono_arch_flush_icache */
1225 /* Function - Flush the CPU icache. */
1227 /*------------------------------------------------------------------*/
1230 mono_arch_flush_icache (guint8
*code
, gint size
)
1234 /*========================= End of Function ========================*/
1236 /*------------------------------------------------------------------*/
1238 /* Name - mono_arch_is_inst_imm */
1240 /*------------------------------------------------------------------*/
1243 mono_arch_is_inst_imm (gint64 imm
)
1245 /* The lowering pass will take care of it */
1249 /*========================= End of Function ========================*/
1251 /*------------------------------------------------------------------*/
1253 /* Name - add_general */
1255 /* Function - Determine code and stack size incremements for a */
1258 /*------------------------------------------------------------------*/
1261 add_general (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gboolean simple
)
1266 if (*gr
> S390_LAST_ARG_REG
) {
1267 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1268 ainfo
->offset
= sz
->stack_size
;
1269 ainfo
->reg
= STK_BASE
;
1270 ainfo
->regtype
= RegTypeBase
;
1271 sz
->stack_size
+= sizeof(int);
1272 sz
->local_size
+= sizeof(int);
1273 sz
->offStruct
+= sizeof(int);
1274 sz
->code_size
+= 12;
1280 if (*gr
> S390_LAST_ARG_REG
- 1) {
1281 disp
= sz
->stack_size
;
1282 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, S390_STACK_ALIGNMENT
);
1283 disp
= sz
->stack_size
- disp
;
1284 ainfo
->offset
= sz
->stack_size
;
1285 ainfo
->reg
= STK_BASE
;
1286 ainfo
->regtype
= RegTypeBase
;
1287 sz
->stack_size
+= sizeof(long long);
1288 sz
->local_size
+= (sizeof(long long) + disp
);
1289 sz
->offStruct
+= (sizeof(long long) + disp
);
1290 sz
->code_size
+= 10;
1300 /*========================= End of Function ========================*/
1302 /*------------------------------------------------------------------*/
1304 /* Name - add_stackParm */
1306 /* Function - Determine code and stack size incremements for a */
1309 /*------------------------------------------------------------------*/
1312 add_stackParm (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gint size
)
1314 if (*gr
> S390_LAST_ARG_REG
) {
1315 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1316 ainfo
->reg
= STK_BASE
;
1317 ainfo
->offset
= sz
->stack_size
;
1318 sz
->stack_size
+= sizeof (gpointer
);
1319 sz
->parm_size
+= sizeof(gpointer
);
1320 sz
->offStruct
+= sizeof(gpointer
);
1323 ainfo
->offset
= sz
->stack_size
;
1326 ainfo
->offparm
= sz
->offset
;
1327 sz
->offset
= S390_ALIGN(sz
->offset
+size
, sizeof(long));
1329 ainfo
->regtype
= RegTypeStructByAddr
;
1330 ainfo
->vtsize
= size
;
1331 sz
->parm_size
+= size
;
1334 /*========================= End of Function ========================*/
1336 /*------------------------------------------------------------------*/
1338 /* Name - add_float */
1340 /* Function - Determine code and stack size incremements for a */
1341 /* float parameter. */
1343 /*------------------------------------------------------------------*/
1346 add_float (guint
*fr
, size_data
*sz
, ArgInfo
*ainfo
)
1348 if ((*fr
) <= S390_LAST_FPARG_REG
) {
1349 ainfo
->regtype
= RegTypeFP
;
1355 ainfo
->offset
= sz
->stack_size
;
1356 ainfo
->reg
= STK_BASE
;
1357 ainfo
->regtype
= RegTypeBase
;
1359 sz
->stack_size
+= ainfo
->size
;
1360 sz
->local_size
+= ainfo
->size
;
1361 sz
->offStruct
+= ainfo
->size
;
1365 /*========================= End of Function ========================*/
1367 /*------------------------------------------------------------------*/
1369 /* Name - get_call_info */
1371 /* Function - Determine the amount of space required for code */
1372 /* and stack. In addition determine starting points */
1373 /* for stack-based parameters, and area for struct- */
1374 /* ures being returned on the stack. */
1376 /*------------------------------------------------------------------*/
1379 get_call_info (MonoCompile
*cfg
, MonoMemPool
*mp
, MonoMethodSignature
*sig
, gboolean is_pinvoke
)
1381 guint i
, fr
, gr
, size
;
1382 int nParm
= sig
->hasthis
+ sig
->param_count
;
1384 guint32 simpletype
, align
;
1387 MonoGenericSharingContext
*gsctx
= cfg
? cfg
->generic_sharing_context
: NULL
;
1390 cinfo
= mono_mempool_alloc0 (mp
, sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1392 cinfo
= g_malloc0 (sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1397 cinfo
->struct_ret
= 0;
1400 sz
->offStruct
= S390_MINIMAL_STACK_SIZE
;
1402 sz
->stack_size
= S390_MINIMAL_STACK_SIZE
;
1407 /*----------------------------------------------------------*/
1408 /* We determine the size of the return code/stack in case we*/
1409 /* need to reserve a register to be used to address a stack */
1410 /* area that the callee will use. */
1411 /*----------------------------------------------------------*/
1413 ret_type
= mono_type_get_underlying_type (sig
->ret
);
1414 ret_type
= mini_get_basic_type_from_generic (gsctx
, ret_type
);
1415 simpletype
= ret_type
->type
;
1417 switch (simpletype
) {
1418 case MONO_TYPE_BOOLEAN
:
1423 case MONO_TYPE_CHAR
:
1428 case MONO_TYPE_CLASS
:
1429 case MONO_TYPE_OBJECT
:
1430 case MONO_TYPE_SZARRAY
:
1431 case MONO_TYPE_ARRAY
:
1433 case MONO_TYPE_FNPTR
:
1434 case MONO_TYPE_STRING
:
1435 cinfo
->ret
.reg
= s390_r2
;
1440 cinfo
->ret
.reg
= s390_f0
;
1445 cinfo
->ret
.reg
= s390_r2
;
1448 case MONO_TYPE_GENERICINST
:
1449 if (!mono_type_generic_inst_is_valuetype (ret_type
)) {
1450 cinfo
->ret
.reg
= s390_r2
;
1455 case MONO_TYPE_VALUETYPE
: {
1456 MonoClass
*klass
= mono_class_from_mono_type (sig
->ret
);
1457 if (klass
->enumtype
) {
1458 simpletype
= mono_class_enum_basetype (klass
)->type
;
1462 size
= mono_class_native_size (klass
, &align
);
1464 size
= mono_class_value_size (klass
, &align
);
1466 cinfo
->ret
.reg
= s390_r2
;
1467 cinfo
->struct_ret
= 1;
1468 cinfo
->ret
.size
= size
;
1469 cinfo
->ret
.vtsize
= size
;
1473 case MONO_TYPE_TYPEDBYREF
:
1474 size
= sizeof (MonoTypedRef
);
1475 cinfo
->ret
.reg
= s390_r2
;
1476 cinfo
->struct_ret
= 1;
1477 cinfo
->ret
.size
= size
;
1478 cinfo
->ret
.vtsize
= size
;
1481 case MONO_TYPE_VOID
:
1484 g_error ("mini-s390: cannot handle as return value 0x%x (0x%x)", sig
->ret
->type
,simpletype
);
1488 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1489 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1493 /*----------------------------------------------------------*/
1494 /* We determine the size of the parameter code and stack */
1495 /* requirements by checking the types and sizes of the */
1497 /*----------------------------------------------------------*/
1499 for (i
= 0; i
< sig
->param_count
; ++i
) {
1502 /*--------------------------------------------------*/
1503 /* Handle vararg type calls. All args are put on */
1505 /*--------------------------------------------------*/
1506 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1507 (i
== sig
->sentinelpos
)) {
1508 gr
= S390_LAST_ARG_REG
+ 1;
1509 add_general (&gr
, sz
, &cinfo
->sigCookie
, TRUE
);
1512 if (sig
->params
[i
]->byref
) {
1513 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1514 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1519 ptype
= mono_type_get_underlying_type (sig
->params
[i
]);
1520 ptype
= mini_get_basic_type_from_generic (gsctx
, ptype
);
1521 simpletype
= ptype
->type
;
1522 switch (simpletype
) {
1523 case MONO_TYPE_BOOLEAN
:
1526 cinfo
->args
[nParm
].size
= sizeof(char);
1527 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1532 case MONO_TYPE_CHAR
:
1533 cinfo
->args
[nParm
].size
= sizeof(short);
1534 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1539 cinfo
->args
[nParm
].size
= sizeof(int);
1540 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1546 case MONO_TYPE_FNPTR
:
1547 case MONO_TYPE_CLASS
:
1548 case MONO_TYPE_OBJECT
:
1549 case MONO_TYPE_STRING
:
1550 case MONO_TYPE_SZARRAY
:
1551 case MONO_TYPE_ARRAY
:
1552 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1553 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1558 cinfo
->args
[nParm
].size
= sizeof(long long);
1559 add_general (&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1563 cinfo
->args
[nParm
].size
= sizeof(float);
1564 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1568 cinfo
->args
[nParm
].size
= sizeof(double);
1569 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1572 case MONO_TYPE_GENERICINST
:
1573 if (!mono_type_generic_inst_is_valuetype (ptype
)) {
1574 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1575 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1580 case MONO_TYPE_VALUETYPE
: {
1581 MonoMarshalType
*info
;
1582 MonoClass
*klass
= mono_class_from_mono_type (sig
->params
[i
]);
1584 size
= mono_class_native_size (klass
, &align
);
1586 size
= mono_class_value_size (klass
, &align
);
1588 info
= mono_marshal_load_type_info (klass
);
1590 if ((info
->native_size
== sizeof(float)) &&
1591 (info
->num_fields
== 1) &&
1592 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
1593 cinfo
->args
[nParm
].size
= sizeof(float);
1594 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1599 if ((info
->native_size
== sizeof(double)) &&
1600 (info
->num_fields
== 1) &&
1601 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
1602 cinfo
->args
[nParm
].size
= sizeof(double);
1603 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1608 cinfo
->args
[nParm
].vtsize
= 0;
1609 cinfo
->args
[nParm
].size
= 0;
1612 /*----------------------------------*/
1613 /* On S/390, structures of size 1, */
1614 /* 2, 4, and 8 bytes are passed in */
1615 /* (a) register(s). */
1616 /*----------------------------------*/
1621 add_general(&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1622 cinfo
->args
[nParm
].size
= size
;
1623 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1625 sz
->local_size
+= sizeof(long);
1628 add_general(&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1629 cinfo
->args
[nParm
].size
= sizeof(long long);
1630 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1632 sz
->local_size
+= sizeof(long long);
1635 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1640 case MONO_TYPE_TYPEDBYREF
: {
1641 int size
= sizeof (MonoTypedRef
);
1643 cinfo
->args
[nParm
].vtsize
= 0;
1644 cinfo
->args
[nParm
].size
= 0;
1647 /*----------------------------------*/
1648 /* On S/390, structures of size 1, */
1649 /* 2, 4, and 8 bytes are passed in */
1650 /* (a) register(s). */
1651 /*----------------------------------*/
1656 add_general(&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1657 cinfo
->args
[nParm
].size
= size
;
1658 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1660 sz
->local_size
+= sizeof(long);
1663 add_general(&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1664 cinfo
->args
[nParm
].size
= sizeof(long long);
1665 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1667 sz
->local_size
+= sizeof(long long);
1670 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1676 g_error ("Can't trampoline 0x%x", sig
->params
[i
]->type
);
1680 /*----------------------------------------------------------*/
1681 /* If we are passing a structure back then if it won't be */
1682 /* in a register(s) then we make room at the end of the */
1683 /* parameters that may have been placed on the stack */
1684 /*----------------------------------------------------------*/
1685 if (cinfo
->struct_ret
) {
1686 cinfo
->ret
.offset
= sz
->stack_size
;
1687 switch (cinfo
->ret
.size
) {
1695 sz
->stack_size
+= S390_ALIGN(cinfo
->ret
.size
, align
);
1699 /*----------------------------------------------------------*/
1700 /* Handle the case where there are no implicit arguments */
1701 /*----------------------------------------------------------*/
1702 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1703 (sig
->param_count
== sig
->sentinelpos
)) {
1704 gr
= S390_LAST_ARG_REG
+ 1;
1705 add_general (&gr
, sz
, &cinfo
->sigCookie
, TRUE
);
1709 sz
->stack_size
= sz
->stack_size
+ sz
->local_size
+ sz
->parm_size
+
1711 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1716 /*========================= End of Function ========================*/
1718 /*------------------------------------------------------------------*/
1720 /* Name - mono_arch_allocate_vars */
1722 /* Function - Set var information according to the calling */
1723 /* convention for S/390. The local var stuff should */
1724 /* most likely be split in another method. */
1726 /* Parameter - @m - Compile unit. */
1728 /*------------------------------------------------------------------*/
1731 mono_arch_allocate_vars (MonoCompile
*cfg
)
1733 MonoMethodSignature
*sig
;
1734 MonoMethodHeader
*header
;
1737 int iParm
, iVar
, offset
, size
, align
, curinst
;
1738 int frame_reg
= STK_BASE
;
1741 header
= cfg
->header
;
1743 cfg
->flags
|= MONO_CFG_HAS_SPILLUP
;
1745 sig
= mono_method_signature (cfg
->method
);
1747 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1749 /*---------------------------------------------------------*/
1750 /* We use the frame register also for any method that has */
1751 /* filter clauses. This way, when the handlers are called, */
1752 /* the code will reference local variables using the frame */
1753 /* reg instead of the stack pointer: if we had to restore */
1754 /* the stack pointer, we'd corrupt the method frames that */
1755 /* are already on the stack (since filters get called */
1756 /* before stack unwinding happens) when the filter code */
1757 /* would call any method. */
1758 /*---------------------------------------------------------*/
1759 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1760 frame_reg
= s390_r11
;
1762 cfg
->frame_reg
= frame_reg
;
1764 cfg
->arch
.bkchain_reg
= -1;
1766 if (frame_reg
!= STK_BASE
)
1767 cfg
->used_int_regs
|= 1 << frame_reg
;
1769 sig
= mono_method_signature (cfg
->method
);
1771 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1773 if (!cinfo
->struct_ret
) {
1774 switch (mono_type_get_underlying_type (sig
->ret
)->type
) {
1775 case MONO_TYPE_VOID
:
1778 cfg
->ret
->opcode
= OP_REGVAR
;
1779 cfg
->ret
->dreg
= s390_r2
;
1784 /*--------------------------------------------------------------*/
1785 /* local vars are at a positive offset from the stack pointer */
1786 /* also note that if the function uses alloca, we use s390_r11 */
1787 /* to point at the local variables. */
1788 /* add parameter area size for called functions */
1789 /*--------------------------------------------------------------*/
1790 offset
= (cfg
->param_area
+ S390_MINIMAL_STACK_SIZE
);
1791 cfg
->sig_cookie
= 0;
1793 if (cinfo
->struct_ret
) {
1794 inst
= cfg
->vret_addr
;
1795 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1796 inst
->inst_offset
= offset
;
1797 inst
->opcode
= OP_REGOFFSET
;
1798 inst
->inst_basereg
= frame_reg
;
1799 offset
+= sizeof(gpointer
);
1800 if (G_UNLIKELY (cfg
->verbose_level
> 1)) {
1801 printf ("vret_addr =");
1802 mono_print_ins (cfg
->vret_addr
);
1807 inst
= cfg
->args
[0];
1808 if (inst
->opcode
!= OP_REGVAR
) {
1809 inst
->opcode
= OP_REGOFFSET
;
1810 inst
->inst_basereg
= frame_reg
;
1811 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1812 inst
->inst_offset
= offset
;
1813 offset
+= sizeof (gpointer
);
1820 eArg
= sig
->param_count
+ sArg
;
1822 if (sig
->call_convention
== MONO_CALL_VARARG
)
1823 cfg
->sig_cookie
+= S390_MINIMAL_STACK_SIZE
;
1825 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1826 inst
= cfg
->args
[curinst
];
1827 if (inst
->opcode
!= OP_REGVAR
) {
1828 switch (cinfo
->args
[iParm
].regtype
) {
1829 case RegTypeStructByAddr
: {
1832 size
= sizeof (gpointer
);
1834 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1835 cfg
->arch
.bkchain_reg
= s390_r12
;
1836 cfg
->used_int_regs
|= 1 << cfg
->arch
.bkchain_reg
;
1838 inst
->opcode
= OP_REGOFFSET
;
1839 inst
->inst_basereg
= cfg
->arch
.bkchain_reg
;
1840 inst
->inst_offset
= cinfo
->args
[iParm
].offset
;
1842 inst
->opcode
= OP_REGOFFSET
;
1843 inst
->inst_basereg
= frame_reg
;
1844 inst
->inst_offset
= S390_ALIGN(offset
, sizeof (gpointer
));
1847 /* Add a level of indirection */
1848 MONO_INST_NEW (cfg
, indir
, 0);
1850 inst
->opcode
= OP_VTARG_ADDR
;
1851 inst
->inst_left
= indir
;
1854 case RegTypeStructByVal
:
1855 size
= cinfo
->args
[iParm
].size
;
1856 offset
= S390_ALIGN(offset
, size
);
1857 inst
->opcode
= OP_REGOFFSET
;
1858 inst
->inst_basereg
= frame_reg
;
1859 inst
->inst_offset
= S390_ALIGN (offset
, size
);
1862 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1864 * These arguments are in the previous frame, so we can't
1865 * compute their offset from the current frame pointer right
1866 * now, since cfg->stack_offset is not yet known, so dedicate a
1867 * register holding the previous frame pointer.
1869 cfg
->arch
.bkchain_reg
= s390_r12
;
1870 cfg
->used_int_regs
|= 1 << cfg
->arch
.bkchain_reg
;
1872 inst
->opcode
= OP_REGOFFSET
;
1873 inst
->inst_basereg
= cfg
->arch
.bkchain_reg
;
1874 size
= (cinfo
->args
[iParm
].size
< 4
1875 ? 4 - cinfo
->args
[iParm
].size
1877 inst
->inst_offset
= cinfo
->args
[iParm
].offset
+ size
;
1878 size
= sizeof (long);
1880 inst
->opcode
= OP_REGOFFSET
;
1881 inst
->inst_basereg
= frame_reg
;
1882 size
= (cinfo
->args
[iParm
].size
< 8
1884 : sizeof(long long));
1885 offset
= S390_ALIGN(offset
, size
);
1886 inst
->inst_offset
= offset
;
1889 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1890 (cinfo
->args
[iParm
].regtype
!= RegTypeGeneral
) &&
1891 (iParm
< sig
->sentinelpos
))
1892 cfg
->sig_cookie
+= size
;
1899 curinst
= cfg
->locals_start
;
1900 for (iVar
= curinst
; iVar
< cfg
->num_varinfo
; ++iVar
) {
1901 inst
= cfg
->varinfo
[iVar
];
1902 if ((inst
->flags
& MONO_INST_IS_DEAD
) ||
1903 (inst
->opcode
== OP_REGVAR
))
1906 /*--------------------------------------------------*/
1907 /* inst->backend.is_pinvoke indicates native sized value types, */
1908 /* this is used by the pinvoke wrappers when they */
1909 /* call functions returning structure */
1910 /*--------------------------------------------------*/
1911 if (inst
->backend
.is_pinvoke
&& MONO_TYPE_ISSTRUCT (inst
->inst_vtype
))
1912 size
= mono_class_native_size (mono_class_from_mono_type(inst
->inst_vtype
), &align
);
1914 size
= mono_type_size (inst
->inst_vtype
, &align
);
1916 offset
= S390_ALIGN(offset
, align
);
1917 inst
->inst_offset
= offset
;
1918 inst
->opcode
= OP_REGOFFSET
;
1919 inst
->inst_basereg
= frame_reg
;
1921 DEBUG (g_print("allocating local %d to %ld\n", iVar
, inst
->inst_offset
));
1924 /*------------------------------------------------------*/
1925 /* Allow space for the trace method stack area if needed*/
1926 /*------------------------------------------------------*/
1927 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (cfg
->method
)) {
1928 offset
+= S390_TRACE_STACK_SIZE
;
1931 /*------------------------------------------------------*/
1932 /* Reserve space to save LMF and caller saved registers */
1933 /*------------------------------------------------------*/
1934 if (cfg
->method
->save_lmf
)
1935 offset
+= sizeof (MonoLMF
);
1937 /*------------------------------------------------------*/
1938 /* align the offset */
1939 /*------------------------------------------------------*/
1940 cfg
->stack_offset
= S390_ALIGN(offset
, S390_STACK_ALIGNMENT
);
1942 /* Fix up offsets for arguments whose value is in the parent frame */
1943 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1944 inst
= cfg
->args
[iParm
];
1946 if (inst
->opcode
== OP_S390_STKARG
) {
1947 inst
->opcode
= OP_REGOFFSET
;
1948 inst
->inst_offset
+= cfg
->stack_offset
;
1953 /*========================= End of Function ========================*/
1955 /*------------------------------------------------------------------*/
1957 /* Name - mono_arch_create_vars */
1959 /*------------------------------------------------------------------*/
1962 mono_arch_create_vars (MonoCompile
*cfg
)
1964 MonoMethodSignature
*sig
;
1967 sig
= mono_method_signature (cfg
->method
);
1969 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1971 if (cinfo
->struct_ret
) {
1972 cfg
->vret_addr
= mono_compile_create_var (cfg
, &mono_defaults
.int_class
->byval_arg
, OP_ARG
);
1973 if (G_UNLIKELY (cfg
->verbose_level
> 1)) {
1974 printf ("vret_addr = ");
1975 mono_print_ins (cfg
->vret_addr
);
1980 /*========================= End of Function ========================*/
1983 add_outarg_reg2 (MonoCompile
*cfg
, MonoCallInst
*call
, ArgStorage storage
, int reg
, MonoInst
*tree
)
1988 case RegTypeGeneral
:
1989 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
1990 ins
->dreg
= mono_alloc_ireg (cfg
);
1991 ins
->sreg1
= tree
->dreg
;
1992 MONO_ADD_INS (cfg
->cbb
, ins
);
1993 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, FALSE
);
1996 MONO_INST_NEW (cfg
, ins
, OP_FMOVE
);
1997 ins
->dreg
= mono_alloc_freg (cfg
);
1998 ins
->sreg1
= tree
->dreg
;
1999 MONO_ADD_INS (cfg
->cbb
, ins
);
2000 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, TRUE
);
2003 MONO_INST_NEW (cfg
, ins
, OP_S390_SETF4RET
);
2004 ins
->dreg
= mono_alloc_freg (cfg
);
2005 ins
->sreg1
= tree
->dreg
;
2006 MONO_ADD_INS (cfg
->cbb
, ins
);
2007 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, TRUE
);
2010 g_assert_not_reached ();
2015 emit_sig_cookie (MonoCompile
*cfg
, MonoCallInst
*call
, CallInfo
*cinfo
)
2017 MonoMethodSignature
*tmpSig
;
2020 cfg
->disable_aot
= TRUE
;
2022 /*----------------------------------------------------------*/
2023 /* mono_ArgIterator_Setup assumes the signature cookie is */
2024 /* passed first and all the arguments which were before it */
2025 /* passed on the stack after the signature. So compensate */
2026 /* by passing a different signature. */
2027 /*----------------------------------------------------------*/
2028 tmpSig
= mono_metadata_signature_dup (call
->signature
);
2029 tmpSig
->param_count
-= call
->signature
->sentinelpos
;
2030 tmpSig
->sentinelpos
= 0;
2031 if (tmpSig
->param_count
> 0)
2032 memcpy (tmpSig
->params
,
2033 call
->signature
->params
+ call
->signature
->sentinelpos
,
2034 tmpSig
->param_count
* sizeof(MonoType
*));
2036 MONO_INST_NEW (cfg
, sig_arg
, OP_ICONST
);
2037 sig_arg
->dreg
= mono_alloc_ireg (cfg
);
2038 sig_arg
->inst_p0
= tmpSig
;
2039 MONO_ADD_INS (cfg
->cbb
, sig_arg
);
2041 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORE_MEMBASE_REG
, STK_BASE
,
2042 cinfo
->sigCookie
.offset
, sig_arg
->dreg
);
2045 /*------------------------------------------------------------------*/
2047 /* Name - mono_arch_emit_call */
2049 /*------------------------------------------------------------------*/
2052 mono_arch_emit_call (MonoCompile
*cfg
, MonoCallInst
*call
)
2055 MonoMethodSignature
*sig
;
2057 int i
, n
, lParamArea
;
2059 ArgInfo
*ainfo
= NULL
;
2062 sig
= call
->signature
;
2063 n
= sig
->param_count
+ sig
->hasthis
;
2064 DEBUG (g_print ("Call requires: %d parameters\n",n
));
2066 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
2068 stackSize
= cinfo
->sz
.stack_size
+ cinfo
->sz
.local_size
+ cinfo
->sz
.parm_size
+ cinfo
->sz
.offset
;
2069 call
->stack_usage
= MAX(stackSize
, call
->stack_usage
);
2070 lParamArea
= MAX((call
->stack_usage
-S390_MINIMAL_STACK_SIZE
-cinfo
->sz
.parm_size
), 0);
2071 cfg
->param_area
= MAX(((signed) cfg
->param_area
), lParamArea
);
2072 cfg
->flags
|= MONO_CFG_HAS_CALLS
;
2074 if (cinfo
->struct_ret
) {
2075 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2076 ins
->sreg1
= call
->vret_var
->dreg
;
2077 ins
->dreg
= mono_alloc_preg (cfg
);
2078 MONO_ADD_INS (cfg
->cbb
, ins
);
2079 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, cinfo
->ret
.reg
, FALSE
);
2082 for (i
= 0; i
< n
; ++i
) {
2083 ainfo
= cinfo
->args
+ i
;
2086 if (i
>= sig
->hasthis
)
2087 t
= sig
->params
[i
- sig
->hasthis
];
2089 t
= &mono_defaults
.int_class
->byval_arg
;
2090 t
= mono_type_get_underlying_type (t
);
2092 in
= call
->args
[i
];
2094 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
2095 (i
== sig
->sentinelpos
)) {
2096 emit_sig_cookie (cfg
, call
, cinfo
);
2099 switch (ainfo
->regtype
) {
2100 case RegTypeGeneral
:
2101 if (!t
->byref
&& (t
->type
== MONO_TYPE_I8
|| t
->type
== MONO_TYPE_U8
)) {
2102 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2103 ins
->dreg
= mono_alloc_ireg (cfg
);
2104 ins
->sreg1
= in
->dreg
+ 2;
2105 MONO_ADD_INS (cfg
->cbb
, ins
);
2106 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, ainfo
->reg
, FALSE
);
2107 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2108 ins
->dreg
= mono_alloc_ireg (cfg
);
2109 ins
->sreg1
= in
->dreg
+ 1;
2110 MONO_ADD_INS (cfg
->cbb
, ins
);
2111 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, ainfo
->reg
+ 1, FALSE
);
2113 add_outarg_reg2 (cfg
, call
, ainfo
->regtype
, ainfo
->reg
, in
);
2117 if (MONO_TYPE_ISSTRUCT (t
)) {
2118 /* Valuetype passed in one fp register */
2119 ainfo
->regtype
= RegTypeStructByValInFP
;
2122 if (ainfo
->size
== 4)
2123 ainfo
->regtype
= RegTypeFPR4
;
2124 add_outarg_reg2 (cfg
, call
, ainfo
->regtype
, ainfo
->reg
, in
);
2127 case RegTypeStructByVal
:
2128 case RegTypeStructByAddr
: {
2132 if (sig
->params
[i
- sig
->hasthis
]->type
== MONO_TYPE_TYPEDBYREF
) {
2133 size
= sizeof (MonoTypedRef
);
2134 align
= sizeof (gpointer
);
2138 size
= mono_type_native_stack_size (&in
->klass
->byval_arg
, &align
);
2141 * Other backends use mono_type_stack_size (), but that
2142 * aligns the size to 8, which is larger than the size of
2143 * the source, leading to reads of invalid memory if the
2144 * source is at the end of address space.
2146 size
= mono_class_value_size (in
->klass
, &align
);
2149 g_assert (in
->klass
);
2151 ainfo
->offparm
+= cinfo
->sz
.offStruct
;
2153 MONO_INST_NEW (cfg
, ins
, OP_OUTARG_VT
);
2154 ins
->sreg1
= in
->dreg
;
2155 ins
->klass
= in
->klass
;
2156 ins
->backend
.size
= ainfo
->size
;
2157 ins
->inst_p0
= call
;
2158 ins
->inst_p1
= mono_mempool_alloc (cfg
->mempool
, sizeof (ArgInfo
));
2159 memcpy (ins
->inst_p1
, ainfo
, sizeof (ArgInfo
));
2161 MONO_ADD_INS (cfg
->cbb
, ins
);
2163 if (ainfo
->regtype
== RegTypeStructByAddr
) {
2165 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2166 * use the normal OUTARG opcodes to pass the address of the location to
2169 int treg
= mono_alloc_preg (cfg
);
2170 MONO_EMIT_NEW_BIALU_IMM (cfg
, OP_ADD_IMM
, treg
,
2171 STK_BASE
, ainfo
->offparm
);
2172 if (ainfo
->reg
== STK_BASE
) {
2173 /* The address is passed on the stack */
2174 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2175 ins
->inst_destbasereg
= STK_BASE
;
2176 ins
->inst_offset
= ainfo
->offset
;
2178 MONO_ADD_INS (cfg
->cbb
, ins
);
2180 mono_call_inst_add_outarg_reg (cfg
, call
, treg
, ainfo
->reg
, FALSE
);
2186 if (!t
->byref
&& t
->type
== MONO_TYPE_R4
) {
2187 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORER4_MEMBASE_REG
,
2188 STK_BASE
, ainfo
->offset
,
2190 } else if (!t
->byref
&& (t
->type
== MONO_TYPE_R8
)) {
2191 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORER8_MEMBASE_REG
,
2192 STK_BASE
, ainfo
->offset
,
2194 } else if (!t
->byref
&& (t
->type
== MONO_TYPE_I8
|| t
->type
== MONO_TYPE_U8
)) {
2195 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2196 ins
->inst_destbasereg
= STK_BASE
;
2197 ins
->inst_offset
= ainfo
->offset
+ MINI_LS_WORD_OFFSET
;
2198 ins
->sreg1
= in
->dreg
+ 1;
2199 MONO_ADD_INS (cfg
->cbb
, ins
);
2201 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2202 ins
->inst_destbasereg
= STK_BASE
;
2203 ins
->inst_offset
= ainfo
->offset
+ MINI_MS_WORD_OFFSET
;
2204 ins
->sreg1
= in
->dreg
+ 2;
2205 MONO_ADD_INS (cfg
->cbb
, ins
);
2207 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2208 ins
->inst_destbasereg
= STK_BASE
;
2209 ins
->inst_offset
= ainfo
->offset
;
2210 ins
->sreg1
= in
->dreg
;
2211 MONO_ADD_INS (cfg
->cbb
, ins
);
2215 g_assert_not_reached ();
2221 * Handle the case where there are no implicit arguments
2223 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
2224 (i
== sig
->sentinelpos
)) {
2225 emit_sig_cookie (cfg
, call
, cinfo
);
2229 /*========================= End of Function ========================*/
2231 /*------------------------------------------------------------------*/
2233 /* Name - mono_arch_emit_outarg_vt */
2235 /*------------------------------------------------------------------*/
2238 mono_arch_emit_outarg_vt (MonoCompile
*cfg
, MonoInst
*ins
, MonoInst
*src
)
2240 MonoCallInst
*call
= (MonoCallInst
*)ins
->inst_p0
;
2241 ArgInfo
*ainfo
= (ArgInfo
*)ins
->inst_p1
;
2242 int size
= ins
->backend
.size
;
2244 if (ainfo
->regtype
== RegTypeStructByVal
) {
2246 arg->ins.sreg1 = ainfo->reg;
2247 arg->ins.opcode = OP_OUTARG_VT;
2248 arg->size = ainfo->size;
2249 arg->offset = ainfo->offset;
2250 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2252 if (ainfo
->reg
!= STK_BASE
) {
2253 MONO_OUTPUT_VTR (cfg
, size
, ainfo
->reg
, src
->dreg
, 0);
2255 MONO_OUTPUT_VTS (cfg
, size
, ainfo
->reg
, ainfo
->offset
,
2258 } else if (ainfo
->regtype
== RegTypeStructByValInFP
) {
2259 int dreg
= mono_alloc_freg (cfg
);
2261 if (ainfo
->size
== 4) {
2262 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg
, OP_LOADR4_MEMBASE
, dreg
, src
->dreg
, 0);
2263 MONO_EMIT_NEW_UNALU (cfg
, OP_S390_SETF4RET
, dreg
, dreg
);
2265 g_assert (ainfo
->size
== 8);
2267 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg
, OP_LOADR8_MEMBASE
, dreg
, src
->dreg
, 0);
2270 mono_call_inst_add_outarg_reg (cfg
, call
, dreg
, ainfo
->reg
, TRUE
);
2272 MONO_EMIT_NEW_MOVE (cfg
, STK_BASE
, ainfo
->offparm
,
2273 src
->dreg
, 0, size
);
2277 /*------------------------------------------------------------------*/
2279 /* Name - mono_arch_emit_setret */
2281 /*------------------------------------------------------------------*/
2284 mono_arch_emit_setret (MonoCompile
*cfg
, MonoMethod
*method
, MonoInst
*val
)
2286 MonoType
*ret
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
);
2289 if (ret
->type
== MONO_TYPE_R4
) {
2290 MONO_EMIT_NEW_UNALU (cfg
, OP_S390_SETF4RET
, s390_f0
, val
->dreg
);
2292 } else if (ret
->type
== MONO_TYPE_R8
) {
2293 MONO_EMIT_NEW_UNALU (cfg
, OP_FMOVE
, s390_f0
, val
->dreg
);
2295 } else if (ret
->type
== MONO_TYPE_I8
|| ret
->type
== MONO_TYPE_U8
) {
2296 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r3
, val
->dreg
+ 1);
2297 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r2
, val
->dreg
+ 2);
2302 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, cfg
->ret
->dreg
, val
->dreg
);
2305 /*========================= End of Function ========================*/
2307 /*------------------------------------------------------------------*/
2309 /* Name - mono_arch_instrument_mem_needs */
2311 /* Function - Allow tracing to work with this interface (with */
2312 /* an optional argument). */
2314 /*------------------------------------------------------------------*/
2317 mono_arch_instrument_mem_needs (MonoMethod
*method
, int *stack
, int *code
)
2319 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2321 /* split prolog-epilog requirements? */
2322 *code
= 50; /* max bytes needed: check this number */
2325 /*========================= End of Function ========================*/
2327 /*------------------------------------------------------------------*/
2329 /* Name - mono_arch_instrument_prolog */
2331 /* Function - Create an "instrumented" prolog. */
2333 /*------------------------------------------------------------------*/
2336 mono_arch_instrument_prolog (MonoCompile
*cfg
, void *func
, void *p
,
2337 gboolean enable_arguments
)
2344 parmOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2345 if (cfg
->method
->save_lmf
)
2346 parmOffset
-= sizeof(MonoLMF
);
2347 fpOffset
= parmOffset
+ (5*sizeof(gint32
));
2348 if (fpOffset
> 4096) {
2349 s390_lr (code
, s390_r12
, STK_BASE
);
2351 while (fpOffset
> 4096) {
2352 s390_ahi (code
, baseReg
, 4096);
2360 s390_stm (code
, s390_r2
, s390_r6
, baseReg
, parmOffset
);
2361 s390_std (code
, s390_f0
, 0, baseReg
, fpOffset
);
2362 s390_std (code
, s390_f1
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2363 s390_std (code
, s390_f2
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2364 s390_basr (code
, s390_r13
, 0);
2366 s390_word (code
, cfg
->method
);
2367 s390_word (code
, func
);
2368 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
2369 s390_la (code
, s390_r3
, 0, baseReg
, parmOffset
);
2370 s390_lr (code
, s390_r4
, STK_BASE
);
2371 s390_ahi (code
, s390_r4
, cfg
->stack_usage
);
2372 s390_l (code
, s390_r1
, 0, s390_r13
, 8);
2373 s390_basr (code
, s390_r14
, s390_r1
);
2374 s390_ld (code
, s390_f2
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2375 s390_ld (code
, s390_f1
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2376 s390_ld (code
, s390_f0
, 0, baseReg
, fpOffset
);
2377 s390_lm (code
, s390_r2
, s390_r6
, baseReg
, parmOffset
);
2382 /*========================= End of Function ========================*/
2384 /*------------------------------------------------------------------*/
2386 /* Name - mono_arch_instrument_epilog */
2388 /* Function - Create an epilog that will handle the returned */
2389 /* values used in instrumentation. */
2391 /*------------------------------------------------------------------*/
2394 mono_arch_instrument_epilog_full (MonoCompile
*cfg
, void *func
, void *p
, gboolean enable_arguments
, gboolean preserve_argument_registers
)
2397 int save_mode
= SAVE_NONE
,
2399 MonoMethod
*method
= cfg
->method
;
2400 int rtype
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
)->type
;
2402 saveOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2403 if (method
->save_lmf
)
2404 saveOffset
-= sizeof(MonoLMF
);
2408 case MONO_TYPE_VOID
:
2409 /* special case string .ctor icall */
2410 if (strcmp (".ctor", method
->name
) && method
->klass
== mono_defaults
.string_class
)
2411 save_mode
= SAVE_ONE
;
2413 save_mode
= SAVE_NONE
;
2417 save_mode
= SAVE_TWO
;
2420 save_mode
= SAVE_R4
;
2423 save_mode
= SAVE_R8
;
2425 case MONO_TYPE_VALUETYPE
:
2426 if (mono_method_signature (method
)->ret
->data
.klass
->enumtype
) {
2427 rtype
= mono_class_enum_basetype (mono_method_signature (method
)->ret
->data
.klass
)->type
;
2430 save_mode
= SAVE_STRUCT
;
2433 save_mode
= SAVE_ONE
;
2437 switch (save_mode
) {
2439 s390_stm (code
, s390_r2
, s390_r3
, cfg
->frame_reg
, saveOffset
);
2440 if (enable_arguments
) {
2441 s390_lr (code
, s390_r4
, s390_r3
);
2442 s390_lr (code
, s390_r3
, s390_r2
);
2446 s390_st (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2447 if (enable_arguments
) {
2448 s390_lr (code
, s390_r3
, s390_r2
);
2452 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2453 if (enable_arguments
) {
2454 s390_ldebr (code
, s390_f0
, s390_f0
);
2458 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2461 s390_st (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2462 if (enable_arguments
) {
2463 s390_l (code
, s390_r3
, 0, cfg
->frame_reg
,
2464 S390_MINIMAL_STACK_SIZE
+cfg
->param_area
);
2472 s390_basr (code
, s390_r13
, 0);
2474 s390_word (code
, cfg
->method
);
2475 s390_word (code
, func
);
2476 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
2477 s390_l (code
, s390_r1
, 0, s390_r13
, 8);
2478 s390_basr (code
, s390_r14
, s390_r1
);
2480 switch (save_mode
) {
2482 s390_lm (code
, s390_r2
, s390_r3
, cfg
->frame_reg
, saveOffset
);
2485 s390_l (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2489 s390_ld (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2492 s390_l (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2502 /*========================= End of Function ========================*/
2505 mono_arch_peephole_pass_1 (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2509 /*------------------------------------------------------------------*/
2511 /* Name - mono_arch_peephole_pass */
2513 /* Function - Form a peephole pass at the code looking for */
2514 /* simple optimizations. */
2516 /*------------------------------------------------------------------*/
2519 mono_arch_peephole_pass_2 (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2523 MONO_BB_FOR_EACH_INS_SAFE (bb
, n
, ins
) {
2524 mono_peephole_ins (bb
, ins
);
2528 /*========================= End of Function ========================*/
2531 mono_arch_lowering_pass (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2533 MonoInst
*ins
, *next
;
2535 MONO_BB_FOR_EACH_INS_SAFE (bb
, next
, ins
) {
2536 switch (ins
->opcode
) {
2541 case OP_IDIV_UN_IMM
:
2542 case OP_IREM_UN_IMM
:
2543 case OP_LOCALLOC_IMM
:
2544 mono_decompose_op_imm (cfg
, bb
, ins
);
2551 bb
->max_vreg
= cfg
->next_vreg
;
2554 /*========================= End of Function ========================*/
2556 /*------------------------------------------------------------------*/
2558 /* Name - emit_float_to_int */
2560 /* Function - Create instructions which will convert a floating */
2561 /* point value to integer. */
2563 /*------------------------------------------------------------------*/
2566 emit_float_to_int (MonoCompile
*cfg
, guchar
*code
, int dreg
, int sreg
, int size
, gboolean is_signed
)
2568 /* sreg is a float, dreg is an integer reg. */
2570 s390_cfdbr (code
, dreg
, 5, sreg
);
2573 s390_lhi (code
, s390_r0
, 0);
2574 s390_lhi (code
, s390_r13
, 0xff);
2575 s390_ltr (code
, dreg
, dreg
);
2577 s390_lhi (code
, s390_r0
, 0x80);
2578 s390_nr (code
, dreg
, s390_r13
);
2579 s390_or (code
, dreg
, s390_r0
);
2584 s390_basr (code
, s390_r13
, 0);
2586 s390_llong (code
, 0x41e0000000000000LL
);
2587 s390_llong (code
, 0x41f0000000000000LL
);
2588 s390_ldr (code
, s390_f15
, sreg
);
2589 s390_cdb (code
, s390_f15
, 0, s390_r13
, 4);
2590 s390_jl (code
, 0); CODEPTR(code
, o
[0]);
2591 s390_sdb (code
, s390_f15
, 0, s390_r13
, 12);
2592 s390_cfdbr (code
, dreg
, 7, s390_f15
);
2594 PTRSLOT(code
, o
[0]);
2595 s390_cfdbr (code
, dreg
, 5, sreg
);
2598 s390_lhi (code
, s390_r0
, 0xff);
2599 s390_nr (code
, dreg
, s390_r0
);
2602 s390_lhi (code
, s390_r0
, -1);
2603 s390_srl (code
, s390_r0
, 0, 16);
2604 s390_nr (code
, dreg
, s390_r0
);
2611 /*========================= End of Function ========================*/
2613 /*------------------------------------------------------------------*/
2615 /* Name - mono_arch_output_basic_block */
2617 /* Function - Perform the "real" work of emitting instructions */
2618 /* that will do the work of in the basic block. */
2620 /*------------------------------------------------------------------*/
2623 mono_arch_output_basic_block (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2628 guint8
*code
= cfg
->native_code
+ cfg
->code_len
;
2629 MonoInst
*last_ins
= NULL
;
2630 guint last_offset
= 0;
2631 int max_len
, cpos
, src2
;
2633 /* we don't align basic blocks of loops on s390 */
2635 if (cfg
->verbose_level
> 2)
2636 g_print ("Basic block %d starting at offset 0x%x\n", bb
->block_num
, bb
->native_offset
);
2638 cpos
= bb
->max_offset
;
2640 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
) {
2641 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2642 //g_assert (!mono_compile_aot);
2645 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2646 /* this is not thread save, but good enough */
2647 /* fixme: howto handle overflows? */
2648 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2651 MONO_BB_FOR_EACH_INS (bb
, ins
) {
2652 offset
= code
- cfg
->native_code
;
2654 max_len
= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
2656 if (offset
> (cfg
->code_size
- max_len
- 16)) {
2657 cfg
->code_size
*= 2;
2658 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
2659 code
= cfg
->native_code
+ offset
;
2662 mono_debug_record_line_number (cfg
, ins
, offset
);
2664 switch (ins
->opcode
) {
2665 case OP_STOREI1_MEMBASE_IMM
: {
2666 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2667 if (s390_is_uimm12(ins
->inst_offset
))
2668 s390_stc (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_stc (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2678 case OP_STOREI2_MEMBASE_IMM
: {
2679 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2680 if (s390_is_uimm12(ins
->inst_offset
)) {
2681 s390_sth (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2683 s390_basr (code
, s390_r13
, 0);
2685 s390_word (code
, ins
->inst_offset
);
2686 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2687 s390_sth (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2691 case OP_STORE_MEMBASE_IMM
:
2692 case OP_STOREI4_MEMBASE_IMM
: {
2693 if (s390_is_imm16(ins
->inst_imm
)) {
2694 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2696 s390_basr (code
, s390_r13
, 0);
2698 s390_word (code
, ins
->inst_imm
);
2699 s390_l (code
, s390_r0
, 0, s390_r13
, 4);
2701 if (s390_is_uimm12(ins
->inst_offset
)) {
2702 s390_st (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2704 s390_basr (code
, s390_r13
, 0);
2706 s390_word (code
, ins
->inst_offset
);
2707 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2708 s390_st (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2712 case OP_STOREI1_MEMBASE_REG
: {
2713 if (s390_is_uimm12(ins
->inst_offset
)) {
2714 s390_stc (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2716 s390_basr (code
, s390_r13
, 0);
2718 s390_word (code
, ins
->inst_offset
);
2719 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2720 s390_stc (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2724 case OP_STOREI2_MEMBASE_REG
: {
2725 if (s390_is_uimm12(ins
->inst_offset
)) {
2726 s390_sth (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_sth (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2736 case OP_STORE_MEMBASE_REG
:
2737 case OP_STOREI4_MEMBASE_REG
: {
2738 if (s390_is_uimm12(ins
->inst_offset
)) {
2739 s390_st (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2741 s390_basr (code
, s390_r13
, 0);
2743 s390_word (code
, ins
->inst_offset
);
2744 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2745 s390_st (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2750 g_assert_not_reached ();
2752 case OP_LOAD_MEMBASE
:
2753 case OP_LOADI4_MEMBASE
:
2754 case OP_LOADU4_MEMBASE
: {
2755 if (s390_is_uimm12(ins
->inst_offset
))
2756 s390_l (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2758 if (s390_is_imm16(ins
->inst_offset
)) {
2759 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
2760 s390_l (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
2762 s390_basr (code
, s390_r13
, 0);
2764 s390_word (code
, ins
->inst_offset
);
2765 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2766 s390_l (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
2771 case OP_LOADU1_MEMBASE
: {
2772 s390_lhi (code
, s390_r0
, 0);
2773 if (s390_is_uimm12(ins
->inst_offset
))
2774 s390_ic (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2776 s390_basr (code
, s390_r13
, 0);
2778 s390_word (code
, ins
->inst_offset
);
2779 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2780 s390_ic (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2782 s390_lr (code
, ins
->dreg
, s390_r0
);
2785 case OP_LOADI1_MEMBASE
: {
2786 s390_lhi (code
, s390_r0
, 0);
2787 if (s390_is_uimm12(ins
->inst_offset
))
2788 s390_ic (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2790 s390_basr (code
, s390_r13
, 0);
2792 s390_word (code
, ins
->inst_offset
);
2793 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2794 s390_ic (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2796 s390_lhi (code
, s390_r13
, 0x80);
2797 s390_nr (code
, s390_r13
, s390_r0
);
2799 s390_lhi (code
, s390_r13
, 0xff00);
2800 s390_or (code
, s390_r0
, s390_r13
);
2801 s390_lr (code
, ins
->dreg
, s390_r0
);
2804 case OP_LOADU2_MEMBASE
: {
2805 s390_lhi (code
, s390_r0
, 0);
2806 if (s390_is_uimm12(ins
->inst_offset
))
2807 s390_icm (code
, s390_r0
, 3, ins
->inst_basereg
, ins
->inst_offset
);
2809 s390_basr (code
, s390_r13
, 0);
2811 s390_word (code
, ins
->inst_offset
);
2812 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2813 s390_ar (code
, s390_r13
, ins
->inst_basereg
);
2814 s390_icm (code
, s390_r0
, 3, s390_r13
, 0);
2816 s390_lr (code
, ins
->dreg
, s390_r0
);
2819 case OP_LOADI2_MEMBASE
: {
2820 s390_lhi (code
, s390_r0
, 0);
2821 if (s390_is_uimm12(ins
->inst_offset
))
2822 s390_lh (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2824 s390_basr (code
, s390_r13
, 0);
2826 s390_word (code
, ins
->inst_offset
);
2827 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2828 s390_lh (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2830 s390_lr (code
, ins
->dreg
, s390_r0
);
2834 case OP_ICONV_TO_I1
: {
2835 if (ins
->dreg
!= ins
->sreg1
)
2836 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2837 s390_sll (code
, ins
->dreg
, 0, 24);
2838 s390_sra (code
, ins
->dreg
, 0, 24);
2841 case OP_ICONV_TO_I2
: {
2842 if (ins
->dreg
!= ins
->sreg1
)
2843 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2844 s390_sll (code
, ins
->dreg
, 0, 16);
2845 s390_sra (code
, ins
->dreg
, 0, 16);
2848 case OP_ICONV_TO_U1
: {
2849 s390_lhi (code
, s390_r0
, 0xff);
2850 if (ins
->dreg
!= ins
->sreg1
) {
2851 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2853 s390_nr (code
, ins
->dreg
, s390_r0
);
2856 case OP_ICONV_TO_U2
: {
2857 s390_lhi (code
, s390_r0
, -1);
2858 s390_sll (code
, s390_r0
, 0, 16);
2859 s390_srl (code
, s390_r0
, 0, 16);
2860 if (ins
->dreg
!= ins
->sreg1
) {
2861 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2863 s390_nr (code
, ins
->dreg
, s390_r0
);
2868 gboolean un
= FALSE
;
2869 MonoInst
*next
= ins
->next
;
2872 (((next
->opcode
>= OP_IBNE_UN
) &&
2873 (next
->opcode
<= OP_IBLT_UN
)) ||
2874 ((next
->opcode
>= OP_COND_EXC_NE_UN
) &&
2875 (next
->opcode
<= OP_COND_EXC_LT_UN
)) ||
2876 ((next
->opcode
>= OP_COND_EXC_INE_UN
) &&
2877 (next
->opcode
<= OP_COND_EXC_ILT_UN
)) ||
2878 ((next
->opcode
== OP_CLT_UN
) ||
2879 (next
->opcode
== OP_CGT_UN
)) ||
2880 ((next
->opcode
== OP_ICLT_UN
) ||
2881 (next
->opcode
== OP_ICGT_UN
))))
2885 s390_clr (code
, ins
->sreg1
, ins
->sreg2
);
2887 s390_cr (code
, ins
->sreg1
, ins
->sreg2
);
2890 case OP_COMPARE_IMM
:
2891 case OP_ICOMPARE_IMM
: {
2892 gboolean un
= FALSE
;
2893 MonoInst
*next
= ins
->next
;
2896 (((next
->opcode
>= OP_IBNE_UN
) &&
2897 (next
->opcode
<= OP_IBLT_UN
)) ||
2898 ((next
->opcode
>= OP_COND_EXC_NE_UN
) &&
2899 (next
->opcode
<= OP_COND_EXC_LT_UN
)) ||
2900 ((next
->opcode
>= OP_COND_EXC_INE_UN
) &&
2901 (next
->opcode
<= OP_COND_EXC_ILT_UN
)) ||
2902 ((next
->opcode
== OP_CLT_UN
) ||
2903 (next
->opcode
== OP_CGT_UN
)) ||
2904 ((next
->opcode
== OP_ICLT_UN
) ||
2905 (next
->opcode
== OP_ICGT_UN
))))
2908 if (s390_is_imm16 (ins
->inst_imm
)) {
2909 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2911 s390_clr (code
, ins
->sreg1
, s390_r0
);
2913 s390_cr (code
, ins
->sreg1
, s390_r0
);
2916 s390_basr (code
, s390_r13
, 0);
2918 s390_word (code
, ins
->inst_imm
);
2920 s390_cl (code
, ins
->sreg1
, 0, s390_r13
, 4);
2922 s390_c (code
, ins
->sreg1
, 0, s390_r13
, 4);
2927 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
, mono_break
);
2928 s390_brasl (code
, s390_r14
, 0);
2934 s390_alr (code
, ins
->dreg
, src2
);
2939 s390_ar (code
, ins
->dreg
, src2
);
2945 s390_alcr (code
, ins
->dreg
, src2
);
2950 if (ins
->dreg
!= ins
->sreg1
) {
2951 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2954 (ins
->next
->opcode
== OP_ADC_IMM
)) {
2955 s390_basr (code
, s390_r13
, 0);
2957 s390_word (code
, ins
->inst_imm
);
2958 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
2960 if (s390_is_imm16 (ins
->inst_imm
)) {
2961 s390_ahi (code
, ins
->dreg
, ins
->inst_imm
);
2963 s390_basr (code
, s390_r13
, 0);
2965 s390_word (code
, ins
->inst_imm
);
2966 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
2971 case OP_ADDCC_IMM
: {
2973 (ins
->next
->opcode
== OP_ADC_IMM
)) {
2974 s390_basr (code
, s390_r13
, 0);
2976 s390_word (code
, ins
->inst_imm
);
2977 if (ins
->dreg
!= ins
->sreg1
) {
2978 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2980 s390_al (code
, ins
->dreg
, 0, s390_r13
, 4);
2982 if (s390_is_imm16 (ins
->inst_imm
)) {
2983 if (ins
->dreg
!= ins
->sreg1
) {
2984 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2986 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2987 s390_alcr (code
, ins
->dreg
, s390_r0
);
2989 s390_basr (code
, s390_r13
, 0);
2991 s390_word (code
, ins
->inst_imm
);
2992 if (ins
->dreg
!= ins
->sreg1
) {
2993 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2995 s390_al (code
, ins
->dreg
, 0, s390_r13
, 4);
3001 if (s390_is_imm16 (ins
->inst_imm
)) {
3002 if (ins
->dreg
!= ins
->sreg1
) {
3003 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3005 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3006 s390_alcr (code
, ins
->dreg
, s390_r0
);
3008 s390_basr (code
, s390_r13
, 0);
3010 s390_word (code
, ins
->inst_imm
);
3011 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3012 s390_alcr (code
, ins
->dreg
, s390_r13
);
3017 case OP_S390_IADD_OVF
: {
3019 s390_ar (code
, ins
->dreg
, src2
);
3020 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3023 case OP_IADD_OVF_UN
:
3024 case OP_S390_IADD_OVF_UN
: {
3026 s390_alr (code
, ins
->dreg
, src2
);
3027 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3031 case OP_S390_LADD
: {
3032 s390_alr (code
, s390_r0
, ins
->sreg1
);
3034 s390_ahi (code
, s390_r1
, 1);
3035 s390_ar (code
, s390_r1
, ins
->sreg2
);
3036 s390_lr (code
, ins
->dreg
, s390_r0
);
3037 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3041 case OP_S390_LADD_OVF
: {
3043 s390_alr (code
, s390_r0
, ins
->sreg1
);
3044 s390_jnc (code
, 0); CODEPTR(code
, o
[0]);
3045 s390_ahi (code
, s390_r1
, 1);
3046 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3047 PTRSLOT (code
, o
[0]);
3048 s390_ar (code
, s390_r1
, ins
->sreg2
);
3049 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3050 s390_lr (code
, ins
->dreg
, s390_r0
);
3051 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3054 case OP_LADD_OVF_UN
:
3055 case OP_S390_LADD_OVF_UN
: {
3056 s390_alr (code
, s390_r0
, ins
->sreg1
);
3057 s390_alcr (code
, s390_r1
, ins
->sreg2
);
3058 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3059 s390_lr (code
, ins
->dreg
, s390_r0
);
3060 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3063 case OP_ADD_OVF_CARRY
: {
3065 s390_lhi (code
, s390_r0
, 0);
3066 s390_lr (code
, s390_r1
, s390_r0
);
3067 s390_alcr (code
, s390_r0
, s390_r1
);
3068 s390_ar (code
, ins
->dreg
, src2
);
3069 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3070 s390_ar (code
, ins
->dreg
, s390_r0
);
3071 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3074 case OP_ADD_OVF_UN_CARRY
: {
3076 s390_alcr (code
, ins
->dreg
, src2
);
3077 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3083 s390_slr (code
, ins
->dreg
, src2
);
3088 s390_sr (code
, ins
->dreg
, src2
);
3094 s390_slbr (code
, ins
->dreg
, src2
);
3097 case OP_SUBCC_IMM
: {
3098 if (s390_is_imm16 (-ins
->inst_imm
)) {
3099 if (ins
->dreg
!= ins
->sreg1
) {
3100 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3102 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3103 s390_slr (code
, ins
->dreg
, s390_r0
);
3105 s390_basr (code
, s390_r13
, 0);
3107 s390_word (code
, ins
->inst_imm
);
3108 if (ins
->dreg
!= ins
->sreg1
) {
3109 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3111 s390_sl (code
, ins
->dreg
, 0, s390_r13
, 4);
3117 if (s390_is_imm16 (-ins
->inst_imm
)) {
3118 if (ins
->dreg
!= ins
->sreg1
) {
3119 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3121 s390_ahi (code
, ins
->dreg
, -ins
->inst_imm
);
3123 s390_basr (code
, s390_r13
, 0);
3125 s390_word (code
, ins
->inst_imm
);
3126 if (ins
->dreg
!= ins
->sreg1
) {
3127 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3129 s390_s (code
, ins
->dreg
, 0, s390_r13
, 4);
3134 if (ins
->dreg
!= ins
->sreg1
) {
3135 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3137 if (s390_is_imm16 (-ins
->inst_imm
)) {
3138 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3139 s390_slbr (code
, ins
->dreg
, s390_r0
);
3141 s390_basr (code
, s390_r13
, 0);
3143 s390_word (code
, ins
->inst_imm
);
3144 s390_slb (code
, ins
->dreg
, 0, s390_r13
, 4);
3149 case OP_S390_ISUB_OVF
: {
3151 s390_sr (code
, ins
->dreg
, src2
);
3152 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3155 case OP_ISUB_OVF_UN
:
3156 case OP_S390_ISUB_OVF_UN
: {
3158 s390_slr (code
, ins
->dreg
, src2
);
3159 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3163 case OP_S390_LSUB
: {
3164 s390_lr (code
, s390_r14
, ins
->sreg2
);
3165 s390_slr (code
, s390_r0
, ins
->sreg1
);
3167 s390_ahi (code
, s390_r14
, 1);
3168 s390_sr (code
, s390_r1
, s390_r14
);
3169 s390_lr (code
, ins
->dreg
, s390_r0
);
3170 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3174 case OP_S390_LSUB_OVF
: {
3176 s390_lr (code
, s390_r14
, ins
->sreg2
);
3177 s390_slr (code
, s390_r0
, ins
->sreg1
);
3178 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
3179 s390_ahi (code
, s390_r14
, 1);
3180 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3181 PTRSLOT (code
, o
[0]);
3182 s390_sr (code
, s390_r1
, s390_r14
);
3183 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3184 s390_lr (code
, ins
->dreg
, s390_r0
);
3185 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3188 case OP_LSUB_OVF_UN
:
3189 case OP_S390_LSUB_OVF_UN
: {
3190 s390_slr (code
, s390_r0
, ins
->sreg1
);
3191 s390_slbr (code
, s390_r1
, ins
->sreg2
);
3192 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, "OverflowException");
3193 s390_lr (code
, ins
->dreg
, s390_r0
);
3194 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3197 case OP_SUB_OVF_CARRY
: {
3199 s390_lhi (code
, s390_r0
, 0);
3200 s390_lr (code
, s390_r1
, s390_r0
);
3201 s390_slbr (code
, s390_r0
, s390_r1
);
3202 s390_sr (code
, ins
->dreg
, src2
);
3203 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3204 s390_ar (code
, ins
->dreg
, s390_r0
);
3205 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3208 case OP_SUB_OVF_UN_CARRY
: {
3210 s390_slbr (code
, ins
->dreg
, src2
);
3211 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3215 if (ins
->sreg1
== ins
->dreg
) {
3216 s390_nr (code
, ins
->dreg
, ins
->sreg2
);
3219 if (ins
->sreg2
== ins
->dreg
) {
3220 s390_nr (code
, ins
->dreg
, ins
->sreg1
);
3223 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3224 s390_nr (code
, ins
->dreg
, ins
->sreg2
);
3231 if (s390_is_imm16 (ins
->inst_imm
)) {
3232 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3233 if (ins
->dreg
!= ins
->sreg1
) {
3234 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3236 s390_nr (code
, ins
->dreg
, s390_r0
);
3238 s390_basr (code
, s390_r13
, 0);
3240 s390_word (code
, ins
->inst_imm
);
3241 if (ins
->dreg
!= ins
->sreg1
) {
3242 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3244 s390_n (code
, ins
->dreg
, 0, s390_r13
, 4);
3249 s390_lr (code
, s390_r0
, ins
->sreg1
);
3250 s390_srda (code
, s390_r0
, 0, 32);
3251 s390_dr (code
, s390_r0
, ins
->sreg2
);
3252 s390_lr (code
, ins
->dreg
, s390_r1
);
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_r1
);
3263 s390_lr (code
, s390_r0
, ins
->sreg1
);
3264 s390_srda (code
, s390_r0
, 0, 32);
3265 s390_dr (code
, s390_r0
, ins
->sreg2
);
3266 s390_lr (code
, ins
->dreg
, s390_r0
);
3269 s390_lr (code
, s390_r0
, ins
->sreg1
);
3270 s390_srdl (code
, s390_r0
, 0, 32);
3271 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3272 s390_lr (code
, ins
->dreg
, s390_r0
);
3276 if (ins
->sreg1
== ins
->dreg
) {
3277 s390_or (code
, ins
->dreg
, ins
->sreg2
);
3280 if (ins
->sreg2
== ins
->dreg
) {
3281 s390_or (code
, ins
->dreg
, ins
->sreg1
);
3284 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3285 s390_or (code
, ins
->dreg
, ins
->sreg2
);
3292 if (s390_is_imm16 (ins
->inst_imm
)) {
3293 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3294 if (ins
->dreg
!= ins
->sreg1
) {
3295 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3297 s390_or (code
, ins
->dreg
, s390_r0
);
3299 s390_basr (code
, s390_r13
, 0);
3301 s390_word (code
, ins
->inst_imm
);
3302 if (ins
->dreg
!= ins
->sreg1
) {
3303 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3305 s390_o (code
, ins
->dreg
, 0, s390_r13
, 4);
3310 if (ins
->sreg1
== ins
->dreg
) {
3311 s390_xr (code
, ins
->dreg
, ins
->sreg2
);
3314 if (ins
->sreg2
== ins
->dreg
) {
3315 s390_xr (code
, ins
->dreg
, ins
->sreg1
);
3318 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3319 s390_xr (code
, ins
->dreg
, ins
->sreg2
);
3326 if (s390_is_imm16 (ins
->inst_imm
)) {
3327 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3328 if (ins
->dreg
!= ins
->sreg1
) {
3329 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3331 s390_xr (code
, ins
->dreg
, s390_r0
);
3333 s390_basr (code
, s390_r13
, 0);
3335 s390_word (code
, ins
->inst_imm
);
3336 if (ins
->dreg
!= ins
->sreg1
) {
3337 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3339 s390_x (code
, ins
->dreg
, 0, s390_r13
, 4);
3345 s390_sll (code
, ins
->dreg
, src2
, 0);
3350 if (ins
->sreg1
!= ins
->dreg
) {
3351 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3353 s390_sll (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3358 s390_sra (code
, ins
->dreg
, src2
, 0);
3363 if (ins
->sreg1
!= ins
->dreg
) {
3364 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3366 s390_sra (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3370 case OP_ISHR_UN_IMM
: {
3371 if (ins
->sreg1
!= ins
->dreg
) {
3372 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3374 s390_srl (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3379 s390_srl (code
, ins
->dreg
, src2
, 0);
3383 if (ins
->sreg1
!= ins
->dreg
) {
3384 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3386 s390_lhi (code
, s390_r0
, -1);
3387 s390_xr (code
, ins
->dreg
, s390_r0
);
3391 s390_lcr (code
, ins
->dreg
, ins
->sreg1
);
3394 case OP_S390_LNEG
: {
3396 g_assert (ins
->dreg
+ 1 != ins
->sreg1
);
3397 s390_lcr (code
, ins
->dreg
+ 1, ins
->sreg2
);
3398 s390_lcr (code
, ins
->dreg
, ins
->sreg1
);
3400 s390_bctr (code
, ins
->dreg
+ 1, 0);
3404 if (ins
->sreg1
== ins
->dreg
) {
3405 s390_msr (code
, ins
->dreg
, ins
->sreg2
);
3408 if (ins
->sreg2
== ins
->dreg
) {
3409 s390_msr (code
, ins
->dreg
, ins
->sreg1
);
3412 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3413 s390_msr (code
, ins
->dreg
, ins
->sreg2
);
3420 if (s390_is_imm16 (ins
->inst_imm
)) {
3421 s390_lhi (code
, s390_r13
, ins
->inst_imm
);
3423 s390_basr (code
, s390_r13
, 0);
3425 s390_word (code
, ins
->inst_imm
);
3426 // if (ins->dreg != ins->sreg1) {
3427 // s390_lr (code, ins->dreg, ins->sreg1);
3429 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3431 if (ins
->dreg
!= ins
->sreg1
) {
3432 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3434 s390_msr (code
, ins
->dreg
, s390_r13
);
3439 s390_ltr (code
, s390_r1
, ins
->sreg1
);
3440 s390_jz (code
, 0); CODEPTR(code
, o
[0]);
3441 s390_ltr (code
, s390_r0
, ins
->sreg2
);
3443 s390_lhi (code
, s390_r1
, 0);
3444 s390_j (code
, 0); CODEPTR(code
, o
[1]);
3445 s390_xr (code
, s390_r0
, s390_r1
);
3446 s390_msr (code
, s390_r1
, ins
->sreg2
);
3447 s390_xr (code
, s390_r0
, s390_r1
);
3448 s390_srl (code
, s390_r0
, 0, 31);
3449 s390_ltr (code
, s390_r0
, s390_r0
);
3450 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3451 PTRSLOT (code
, o
[0]);
3452 PTRSLOT (code
, o
[1]);
3453 s390_lr (code
, ins
->dreg
, s390_r1
);
3456 case OP_IMUL_OVF_UN
: {
3457 s390_lhi (code
, s390_r0
, 0);
3458 s390_lr (code
, s390_r1
, ins
->sreg1
);
3459 s390_mlr (code
, s390_r0
, ins
->sreg2
);
3460 s390_ltr (code
, s390_r0
, s390_r0
);
3461 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3462 s390_lr (code
, ins
->dreg
, s390_r1
);
3466 s390_l (code
, s390_r0
, 0, ins
->sreg1
, 4);
3467 s390_srda (code
, s390_r0
, 0, 32);
3468 s390_m (code
, s390_r0
, 0, ins
->sreg2
, 4);
3469 s390_l (code
, s390_r0
, 0, ins
->sreg1
, 4);
3470 s390_srl (code
, s390_r0
, 0, 31);
3471 s390_a (code
, s390_r0
, 0, ins
->sreg1
, 0);
3472 s390_l (code
, s390_r13
, 0, ins
->sreg2
, 0);
3473 s390_srl (code
, s390_r13
, 0, 31);
3474 s390_ms (code
, s390_r13
, 0, ins
->sreg1
, 4);
3475 s390_ar (code
, s390_r0
, s390_r13
);
3476 s390_st (code
, s390_r0
, 0, ins
->dreg
, 0);
3477 s390_st (code
, s390_r1
, 0, ins
->dreg
, 4);
3481 if (s390_is_imm16(ins
->inst_c0
)) {
3482 s390_lhi (code
, ins
->dreg
, ins
->inst_c0
);
3484 s390_basr (code
, s390_r13
, 0);
3486 s390_word (code
, ins
->inst_c0
);
3487 s390_l (code
, ins
->dreg
, 0, s390_r13
, 4);
3492 s390_basr (code
, s390_r13
, 0);
3494 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3495 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3496 s390_word (code
, 0);
3497 s390_l (code
,ins
->dreg
, 0, s390_r13
, 4);
3500 case OP_JUMP_TABLE
: {
3501 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3502 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3503 s390_basr (code
, s390_r13
, 0);
3505 s390_word (code
, 0);
3506 s390_l (code
, ins
->dreg
, 0, s390_r13
, 4);
3509 case OP_ICONV_TO_I4
:
3510 case OP_ICONV_TO_U4
:
3512 if (ins
->dreg
!= ins
->sreg1
) {
3513 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3518 int saved
= ins
->sreg1
;
3519 if (ins
->sreg1
== s390_r2
) {
3520 s390_lr (code
, s390_r0
, ins
->sreg1
);
3523 if (ins
->sreg2
!= s390_r2
)
3524 s390_lr (code
, s390_r2
, ins
->sreg2
);
3525 if (saved
!= s390_r3
)
3526 s390_lr (code
, s390_r3
, saved
);
3530 if (ins
->dreg
!= ins
->sreg1
) {
3531 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3535 case OP_S390_SETF4RET
: {
3536 s390_ledbr (code
, ins
->dreg
, ins
->sreg1
);
3540 if (s390_is_imm16 (ins
->inst_offset
)) {
3541 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
3543 s390_bras (code
, s390_r13
, 0);
3545 s390_word (code
, ins
->inst_offset
);
3546 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3548 s390_ear (code
, s390_r1
, 0);
3549 s390_l (code
, ins
->dreg
, s390_r13
, s390_r1
, 0);
3552 case OP_FCONV_TO_R4
: {
3554 if (ins
->dreg
!= ins
->sreg1
) {
3555 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3560 (ins->next->opcode != OP_FMOVE) &&
3561 (ins->next->opcode != OP_STORER4_MEMBASE_REG))
3562 s390_ledbr (code, ins->dreg, ins->sreg1);
3567 if (cfg
->method
->save_lmf
)
3568 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
3570 if (cfg
->flags
& MONO_CFG_HAS_TAIL
) {
3571 code
= emit_load_volatile_registers(code
, cfg
);
3574 code
= backUpStackPtr(cfg
, code
, STK_BASE
);
3575 s390_l (code
, s390_r14
, 0, STK_BASE
, S390_RET_ADDR_OFFSET
);
3576 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3577 MONO_PATCH_INFO_METHOD_JUMP
,
3579 s390_jcl (code
, S390_CC_UN
, 0);
3582 case OP_CHECK_THIS
: {
3583 /* ensure ins->sreg1 is not NULL */
3584 s390_icm (code
, s390_r0
, 15, ins
->sreg1
, 0);
3588 int offset
= cfg
->sig_cookie
+ cfg
->stack_usage
;
3590 if (s390_is_imm16 (offset
))
3591 s390_lhi (code
, s390_r0
, offset
);
3593 s390_basr (code
, s390_r13
, 0);
3595 s390_word (code
, offset
);
3596 s390_l (code
, s390_r0
, 0, s390_r13
, 0);
3598 s390_ar (code
, s390_r0
, cfg
->frame_reg
);
3599 s390_st (code
, s390_r0
, 0, ins
->sreg1
, 0);
3603 call
= (MonoCallInst
*)ins
;
3604 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3605 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_METHOD
,
3608 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
,
3610 s390_brasl (code
, s390_r14
, 0);
3611 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3612 s390_ldebr (code
, s390_f0
, s390_f0
);
3620 call
= (MonoCallInst
*)ins
;
3621 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3622 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_METHOD
, call
->method
);
3624 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
, call
->fptr
);
3625 s390_brasl (code
, s390_r14
, 0);
3628 case OP_FCALL_REG
: {
3629 call
= (MonoCallInst
*)ins
;
3630 s390_lr (code
, s390_r1
, ins
->sreg1
);
3631 s390_basr (code
, s390_r14
, s390_r1
);
3632 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3633 s390_ldebr (code
, s390_f0
, s390_f0
);
3639 case OP_VOIDCALL_REG
:
3641 s390_lr (code
, s390_r1
, ins
->sreg1
);
3642 s390_basr (code
, s390_r14
, s390_r1
);
3645 case OP_LCALL_MEMBASE
:
3646 case OP_VCALL_MEMBASE
:
3647 case OP_VCALL2_MEMBASE
:
3648 case OP_VOIDCALL_MEMBASE
:
3649 case OP_FCALL_MEMBASE
:
3650 case OP_CALL_MEMBASE
: {
3651 call
= (MonoCallInst
*)ins
;
3652 if (s390_is_uimm12(ins
->inst_offset
))
3653 s390_l (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3655 if (s390_is_imm16(ins
->inst_offset
)) {
3656 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
3657 s390_l (code
, s390_r1
, s390_r13
, ins
->inst_basereg
, 0);
3659 s390_basr (code
, s390_r13
, 0);
3661 s390_word (code
, ins
->inst_offset
);
3662 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3663 s390_l (code
, s390_r1
, s390_r13
, ins
->inst_basereg
, 0);
3666 s390_basr (code
, s390_r14
, s390_r1
);
3667 if (ins
->opcode
== OP_FCALL_MEMBASE
&& call
->signature
->ret
->type
== MONO_TYPE_R4
)
3668 s390_ldebr (code
, s390_f0
, s390_f0
);
3672 /*------------------------------------------*/
3673 /* To allocate space on the stack we have */
3674 /* to allow room for parameters passed in */
3675 /* calls, the backchain pointer and round */
3676 /* it to our stack alignment requirements */
3677 /*------------------------------------------*/
3678 int alloca_skip
= S390_MINIMAL_STACK_SIZE
+ cfg
->param_area
;
3679 int area_offset
= S390_ALIGN(alloca_skip
, S390_STACK_ALIGNMENT
);
3680 s390_lr (code
, s390_r1
, ins
->sreg1
);
3681 if (ins
->flags
& MONO_INST_INIT
)
3682 s390_lr (code
, s390_r0
, ins
->sreg1
);
3683 s390_ahi (code
, s390_r1
, 14);
3684 s390_srl (code
, s390_r1
, 0, 3);
3685 s390_sll (code
, s390_r1
, 0, 3);
3686 if (cfg
->method
->save_lmf
) {
3687 /*----------------------------------*/
3688 /* we have to adjust lmf ebp value */
3689 /*----------------------------------*/
3690 int lmfOffset
= cfg
->stack_usage
- sizeof(MonoLMF
);
3692 s390_lr (code
, s390_r13
, cfg
->frame_reg
);
3693 if (s390_is_uimm16(lmfOffset
))
3694 s390_ahi (code
, s390_r13
, lmfOffset
);
3696 s390_basr (code
, s390_r14
, 0);
3698 s390_word (code
, lmfOffset
);
3699 s390_a (code
, s390_r13
, 0, s390_r14
, 4);
3701 s390_lr (code
, s390_r14
, STK_BASE
);
3702 s390_sr (code
, s390_r14
, s390_r1
);
3703 s390_st (code
, s390_r14
, 0, s390_r13
,
3704 G_STRUCT_OFFSET(MonoLMF
, ebp
));
3706 s390_l (code
, s390_r13
, 0, STK_BASE
, 0);
3707 s390_sr (code
, STK_BASE
, s390_r1
);
3708 s390_st (code
, s390_r13
, 0, STK_BASE
, 0);
3709 s390_la (code
, ins
->dreg
, 0, STK_BASE
, area_offset
);
3710 s390_srl (code
, ins
->dreg
, 0, 3);
3711 s390_sll (code
, ins
->dreg
, 0, 3);
3712 if (ins
->flags
& MONO_INST_INIT
) {
3713 s390_lr (code
, s390_r1
, s390_r0
);
3714 s390_lr (code
, s390_r0
, ins
->dreg
);
3715 s390_lr (code
, s390_r14
, s390_r12
);
3716 s390_lhi (code
, s390_r13
, 0);
3717 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
3719 s390_lr (code
, s390_r12
, s390_r14
);
3724 s390_lr (code
, s390_r2
, ins
->sreg1
);
3725 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3726 (gpointer
)"mono_arch_throw_exception");
3727 s390_brasl (code
, s390_r14
, 0);
3731 s390_lr (code
, s390_r2
, ins
->sreg1
);
3732 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3733 (gpointer
)"mono_arch_rethrow_exception");
3734 s390_brasl (code
, s390_r14
, 0);
3737 case OP_START_HANDLER
: {
3738 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3739 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3740 s390_st (code
, s390_r14
, 0,
3741 spvar
->inst_basereg
,
3742 spvar
->inst_offset
);
3744 s390_basr (code
, s390_r13
, 0);
3746 s390_word (code
, spvar
->inst_offset
);
3747 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3748 s390_st (code
, s390_r14
, s390_r13
,
3749 spvar
->inst_basereg
, 0);
3753 case OP_ENDFILTER
: {
3754 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3755 if (ins
->sreg1
!= s390_r2
)
3756 s390_lr (code
, s390_r2
, ins
->sreg1
);
3757 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3758 s390_l (code
, s390_r14
, 0, spvar
->inst_basereg
,
3759 spvar
->inst_offset
);
3761 s390_basr (code
, s390_r13
, 0);
3763 s390_word (code
, spvar
->inst_offset
);
3764 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3765 s390_l (code
, s390_r14
, s390_r13
,
3766 spvar
->inst_basereg
, 0);
3768 s390_br (code
, s390_r14
);
3771 case OP_ENDFINALLY
: {
3772 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3773 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3774 s390_l (code
, s390_r14
, 0, spvar
->inst_basereg
,
3775 spvar
->inst_offset
);
3777 s390_basr (code
, s390_r13
, 0);
3779 s390_word (code
, spvar
->inst_offset
);
3780 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3781 s390_l (code
, s390_r14
, s390_r13
,
3782 spvar
->inst_basereg
, 0);
3784 s390_br (code
, s390_r14
);
3787 case OP_CALL_HANDLER
: {
3788 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3789 MONO_PATCH_INFO_BB
, ins
->inst_target_bb
);
3790 s390_brasl (code
, s390_r14
, 0);
3791 mono_cfg_add_try_hole (cfg
, ins
->inst_eh_block
, code
, bb
);
3795 ins
->inst_c0
= code
- cfg
->native_code
;
3798 case OP_RELAXED_NOP
:
3801 case OP_DUMMY_STORE
:
3802 case OP_NOT_REACHED
:
3807 EMIT_UNCOND_BRANCH(ins
);
3810 s390_br (code
, ins
->sreg1
);
3815 s390_lhi (code
, ins
->dreg
, 1);
3817 s390_lhi (code
, ins
->dreg
, 0);
3822 s390_lhi (code
, ins
->dreg
, 1);
3824 s390_lhi (code
, ins
->dreg
, 0);
3829 s390_lhi (code
, ins
->dreg
, 1);
3831 s390_lhi (code
, ins
->dreg
, 0);
3836 s390_lhi (code
, ins
->dreg
, 1);
3838 s390_lhi (code
, ins
->dreg
, 0);
3843 s390_lhi (code
, ins
->dreg
, 1);
3845 s390_lhi (code
, ins
->dreg
, 0);
3848 case OP_COND_EXC_EQ
:
3849 case OP_COND_EXC_IEQ
:
3850 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ
, ins
->inst_p1
);
3852 case OP_COND_EXC_NE_UN
:
3853 case OP_COND_EXC_INE_UN
:
3854 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE
, ins
->inst_p1
);
3856 case OP_COND_EXC_LT
:
3857 case OP_COND_EXC_ILT
:
3858 case OP_COND_EXC_LT_UN
:
3859 case OP_COND_EXC_ILT_UN
:
3860 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, ins
->inst_p1
);
3862 case OP_COND_EXC_GT
:
3863 case OP_COND_EXC_IGT
:
3864 case OP_COND_EXC_GT_UN
:
3865 case OP_COND_EXC_IGT_UN
:
3866 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT
, ins
->inst_p1
);
3868 case OP_COND_EXC_GE
:
3869 case OP_COND_EXC_IGE
:
3870 case OP_COND_EXC_GE_UN
:
3871 case OP_COND_EXC_IGE_UN
:
3872 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE
, ins
->inst_p1
);
3874 case OP_COND_EXC_LE
:
3875 case OP_COND_EXC_ILE
:
3876 case OP_COND_EXC_LE_UN
:
3877 case OP_COND_EXC_ILE_UN
:
3878 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE
, ins
->inst_p1
);
3880 case OP_COND_EXC_OV
:
3881 case OP_COND_EXC_IOV
:
3882 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, ins
->inst_p1
);
3884 case OP_COND_EXC_NO
:
3885 case OP_COND_EXC_INO
:
3886 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO
, ins
->inst_p1
);
3889 case OP_COND_EXC_IC
:
3890 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, ins
->inst_p1
);
3892 case OP_COND_EXC_NC
:
3893 case OP_COND_EXC_INC
:
3894 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, ins
->inst_p1
);
3897 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
3900 EMIT_COND_BRANCH (ins
, S390_CC_NE
);
3904 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
3908 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
3912 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
3916 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
3919 /* floating point opcodes */
3921 if (*((float *) ins
->inst_p0
) == 0) {
3922 s390_lzdr (code
, ins
->dreg
);
3924 s390_basr (code
, s390_r13
, 0);
3926 s390_word (code
, ins
->inst_p0
);
3927 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3928 s390_ld (code
, ins
->dreg
, 0, s390_r13
, 0);
3933 if (*((float *) ins
->inst_p0
) == 0) {
3934 s390_lzdr (code
, ins
->dreg
);
3936 s390_basr (code
, s390_r13
, 0);
3938 s390_word (code
, ins
->inst_p0
);
3939 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3940 s390_ldeb (code
, ins
->dreg
, 0, s390_r13
, 0);
3944 case OP_STORER8_MEMBASE_REG
: {
3945 if (s390_is_uimm12(ins
->inst_offset
)) {
3946 s390_std (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
3948 s390_basr (code
, s390_r13
, 0);
3950 s390_word (code
, ins
->inst_offset
);
3951 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3952 s390_std (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
3956 case OP_LOADR8_MEMBASE
: {
3957 if (s390_is_uimm12(ins
->inst_offset
)) {
3958 s390_ld (code
, ins
->dreg
, 0, ins
->inst_basereg
, 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_ld (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
3968 case OP_STORER4_MEMBASE_REG
: {
3969 if (s390_is_uimm12(ins
->inst_offset
)) {
3970 s390_ledbr(code
, s390_f15
, ins
->sreg1
);
3971 s390_ste (code
, s390_f15
, 0, ins
->inst_destbasereg
, 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_ledbr(code
, s390_f15
, ins
->sreg1
);
3978 s390_ste (code
, s390_f15
, s390_r13
, ins
->inst_destbasereg
, 0);
3982 case OP_LOADR4_MEMBASE
: {
3983 if (s390_is_uimm12(ins
->inst_offset
)) {
3984 s390_ldeb (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3986 s390_basr (code
, s390_r13
, 0);
3988 s390_word (code
, ins
->inst_offset
);
3989 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3990 s390_ldeb (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
3994 case OP_ICONV_TO_R_UN
: {
3995 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
3996 s390_ltr (code
, ins
->sreg1
, ins
->sreg1
);
3997 s390_jnl (code
, 12);
3998 s390_basr (code
, s390_r13
, 0);
4000 s390_word (code
, 0x41f00000);
4001 s390_word (code
, 0);
4002 s390_adb (code
, ins
->dreg
, 0, s390_r13
, 4);
4005 case OP_ICONV_TO_R4
: {
4006 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
4009 case OP_ICONV_TO_R8
: {
4010 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
4013 case OP_FCONV_TO_I1
:
4014 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, TRUE
);
4016 case OP_FCONV_TO_U1
:
4017 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, FALSE
);
4019 case OP_FCONV_TO_I2
:
4020 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, TRUE
);
4022 case OP_FCONV_TO_U2
:
4023 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, FALSE
);
4025 case OP_FCONV_TO_I4
:
4027 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, TRUE
);
4029 case OP_FCONV_TO_U4
:
4031 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, FALSE
);
4033 case OP_FCONV_TO_I8
:
4034 case OP_FCONV_TO_U8
:
4035 g_assert_not_reached ();
4036 /* Implemented as helper calls */
4038 case OP_LCONV_TO_R_UN
:
4039 g_assert_not_reached ();
4040 /* Implemented as helper calls */
4042 case OP_LCONV_TO_OVF_I
:
4043 case OP_LCONV_TO_OVF_I4_2
: {
4044 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4046 s390_ltr (code
, ins
->sreg1
, ins
->sreg1
);
4047 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
4048 s390_ltr (code
, ins
->sreg2
, ins
->sreg2
);
4049 s390_jnl (code
, 0); CODEPTR(code
, o
[1]);
4050 s390_lhi (code
, s390_r13
, -1);
4051 s390_cr (code
, ins
->sreg2
, s390_r13
);
4052 s390_jnz (code
, 0); CODEPTR(code
, o
[2]);
4053 s390_j (code
, 0); CODEPTR(code
, o
[3]);
4054 PTRSLOT(code
, o
[0]);
4055 s390_ltr (code
, ins
->sreg2
, ins
->sreg2
);
4056 s390_jz (code
, 0); CODEPTR(code
, o
[4]);
4057 PTRSLOT(code
, o
[1]);
4058 PTRSLOT(code
, o
[2]);
4059 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4060 MONO_PATCH_INFO_EXC
, "OverflowException");
4061 s390_brasl (code
, s390_r14
, 0);
4062 PTRSLOT(code
, o
[3]);
4063 PTRSLOT(code
, o
[4]);
4064 if (ins
->dreg
!= ins
->sreg1
)
4065 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
4069 s390_sqdbr (code
, ins
->dreg
, ins
->sreg1
);
4074 s390_adbr (code
, ins
->dreg
, src2
);
4078 CHECK_SRCDST_NCOM_F
;
4079 s390_sdbr (code
, ins
->dreg
, src2
);
4084 s390_mdbr (code
, ins
->dreg
, src2
);
4088 CHECK_SRCDST_NCOM_F
;
4089 s390_ddbr (code
, ins
->dreg
, src2
);
4093 s390_lcdbr (code
, ins
->dreg
, ins
->sreg1
);
4097 CHECK_SRCDST_NCOM_F
;
4098 s390_didbr (code
, ins
->dreg
, src2
, 5, s390_f15
);
4102 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4106 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4107 s390_lhi (code
, ins
->dreg
, 1);
4109 s390_lhi (code
, ins
->dreg
, 0);
4113 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4114 s390_lhi (code
, ins
->dreg
, 1);
4116 s390_lhi (code
, ins
->dreg
, 0);
4120 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4121 s390_lhi (code
, ins
->dreg
, 1);
4123 s390_lhi (code
, ins
->dreg
, 0);
4127 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4128 s390_lhi (code
, ins
->dreg
, 1);
4130 s390_lhi (code
, ins
->dreg
, 0);
4134 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4135 s390_lhi (code
, ins
->dreg
, 1);
4137 s390_lhi (code
, ins
->dreg
, 0);
4142 s390_jo (code
, 0); CODEPTR(code
, o
);
4143 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
4148 EMIT_COND_BRANCH (ins
, S390_CC_NE
|S390_CC_OV
);
4152 s390_jo (code
, 0); CODEPTR(code
, o
);
4153 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
4158 EMIT_COND_BRANCH (ins
, S390_CC_LT
|S390_CC_OV
);
4162 s390_jo (code
, 0); CODEPTR(code
, o
);
4163 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
4168 EMIT_COND_BRANCH (ins
, S390_CC_GT
|S390_CC_OV
);
4172 s390_jo (code
, 0); CODEPTR(code
, o
);
4173 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
4178 EMIT_COND_BRANCH (ins
, S390_CC_GE
|S390_CC_OV
);
4182 s390_jo (code
, 0); CODEPTR(code
, o
);
4183 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
4188 EMIT_COND_BRANCH (ins
, S390_CC_LE
|S390_CC_OV
);
4192 s390_lhi (code
, s390_r13
, 0x7f);
4193 s390_tcdb (code
, ins
->sreg1
, 0, s390_r13
, 0);
4194 s390_jz (code
, 0); CODEPTR(code
, o
);
4195 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4196 MONO_PATCH_INFO_EXC
, "ArithmeticException");
4197 s390_brasl (code
, s390_r14
,0);
4201 case OP_S390_MOVE
: {
4202 if (ins
->backend
.size
> 0) {
4203 if (ins
->backend
.size
<= 256) {
4204 s390_mvc (code
, ins
->backend
.size
, ins
->dreg
,
4205 ins
->inst_offset
, ins
->sreg1
, ins
->inst_imm
);
4207 s390_lr (code
, s390_r0
, ins
->dreg
);
4208 if (s390_is_imm16 (ins
->inst_offset
)) {
4209 s390_ahi (code
, s390_r0
, ins
->inst_offset
);
4211 s390_basr (code
, s390_r13
, 0);
4213 s390_long (code
, ins
->inst_offset
);
4214 s390_a (code
, s390_r0
, 0, s390_r13
, 4);
4216 s390_lr (code
, s390_r12
, ins
->sreg1
);
4217 if (s390_is_imm16 (ins
->inst_imm
)) {
4218 s390_ahi (code
, s390_r12
, ins
->inst_imm
);
4220 s390_basr (code
, s390_r13
, 0);
4222 s390_long (code
, ins
->inst_imm
);
4223 s390_a (code
, s390_r12
, 0, s390_r13
, 4);
4225 if (s390_is_imm16 (ins
->backend
.size
)) {
4226 s390x_lhi (code
, s390_r1
, ins
->backend
.size
);
4228 s390_basr (code
, s390_r13
, 0);
4230 s390_long (code
, ins
->backend
.size
);
4231 s390_l (code
, s390_r1
, 0, s390_r13
, 4);
4233 s390_lr (code
, s390_r1
, ins
->backend
.size
);
4234 s390_lr (code
, s390_r13
, s390_r1
);
4235 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
4240 case OP_ATOMIC_ADD_I4
: {
4241 s390_lr (code
, s390_r1
, ins
->sreg2
);
4242 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4243 s390_a (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4244 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4245 s390_jnz (code
, -7);
4246 s390_lr (code
, ins
->dreg
, s390_r1
);
4249 case OP_ATOMIC_ADD_NEW_I4
: {
4250 s390_lr (code
, s390_r1
, ins
->sreg2
);
4251 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4252 s390_a (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4253 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4254 s390_jnz (code
, -7);
4255 s390_lr (code
, ins
->dreg
, s390_r1
);
4258 case OP_ATOMIC_EXCHANGE_I4
: {
4259 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4260 s390_cs (code
, s390_r0
, ins
->sreg2
, ins
->inst_basereg
, ins
->inst_offset
);
4261 s390_jnz (code
, -4);
4262 s390_lr (code
, ins
->dreg
, s390_r0
);
4265 case OP_S390_BKCHAIN
: {
4266 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
4267 if (s390_is_imm16 (cfg
->stack_offset
)) {
4268 s390_ahi (code
, ins
->dreg
, cfg
->stack_offset
);
4270 s390_basr (code
, s390_r13
, 0);
4272 s390_word (code
, cfg
->stack_offset
);
4273 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
4276 case OP_MEMORY_BARRIER
: {
4280 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins
->opcode
), __FUNCTION__
);
4281 g_assert_not_reached ();
4284 if ((cfg
->opt
& MONO_OPT_BRANCH
) && ((code
- cfg
->native_code
- offset
) > max_len
)) {
4285 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
4286 mono_inst_name (ins
->opcode
), max_len
, code
- cfg
->native_code
- offset
);
4287 g_assert_not_reached ();
4293 last_offset
= offset
;
4296 cfg
->code_len
= code
- cfg
->native_code
;
4299 /*========================= End of Function ========================*/
4301 /*------------------------------------------------------------------*/
4303 /* Name - mono_arch_register_lowlevel_calls */
4305 /* Function - Register routines to help with --trace operation. */
4307 /*------------------------------------------------------------------*/
4310 mono_arch_register_lowlevel_calls (void)
4312 mono_register_jit_icall (mono_arch_get_lmf_addr
, "mono_arch_get_lmf_addr", NULL
, TRUE
);
4315 /*========================= End of Function ========================*/
4317 /*------------------------------------------------------------------*/
4319 /* Name - mono_arch_patch_code */
4321 /* Function - Process the patch data created during the */
4322 /* instruction build process. This resolves jumps, */
4323 /* calls, variables etc. */
4325 /*------------------------------------------------------------------*/
4328 mono_arch_patch_code (MonoMethod
*method
, MonoDomain
*domain
,
4329 guint8
*code
, MonoJumpInfo
*ji
, MonoCodeManager
*dyn_code_mp
, gboolean run_cctors
)
4331 MonoJumpInfo
*patch_info
;
4333 for (patch_info
= ji
; patch_info
; patch_info
= patch_info
->next
) {
4334 unsigned char *ip
= patch_info
->ip
.i
+ code
;
4335 gconstpointer target
= NULL
;
4337 target
= mono_resolve_patch_target (method
, domain
, code
,
4338 patch_info
, run_cctors
);
4340 switch (patch_info
->type
) {
4341 case MONO_PATCH_INFO_IP
:
4342 case MONO_PATCH_INFO_EXC_NAME
:
4343 case MONO_PATCH_INFO_LDSTR
:
4344 case MONO_PATCH_INFO_TYPE_FROM_HANDLE
:
4345 case MONO_PATCH_INFO_LDTOKEN
:
4346 case MONO_PATCH_INFO_EXC
:
4348 case MONO_PATCH_INFO_SWITCH
:
4349 /*----------------------------------*/
4350 /* ip points at the basr r13,0/j +4 */
4351 /* instruction the vtable value */
4352 /* follows this (i.e. ip+6) */
4353 /*----------------------------------*/
4354 *((gconstpointer
*)(ip
+6)) = target
;
4357 case MONO_PATCH_INFO_METHODCONST
:
4358 case MONO_PATCH_INFO_CLASS
:
4359 case MONO_PATCH_INFO_IMAGE
:
4360 case MONO_PATCH_INFO_FIELD
:
4361 case MONO_PATCH_INFO_IID
:
4362 target
= S390_RELATIVE(target
, ip
);
4364 case MONO_PATCH_INFO_R4
:
4365 case MONO_PATCH_INFO_R8
:
4366 case MONO_PATCH_INFO_METHOD_REL
:
4367 g_assert_not_reached ();
4370 target
= S390_RELATIVE(target
, ip
);
4373 s390_patch (ip
, (guint32
) target
);
4377 /*========================= End of Function ========================*/
4379 /*------------------------------------------------------------------*/
4381 /* Name - emit_load_volatile_registers */
4383 /* Function - Create the instruction sequence for loading the */
4384 /* parameter registers for use with the 'tail' op. */
4386 /* The register loading operations performed here */
4387 /* are the mirror of the store operations performed */
4388 /* in mono_arch_emit_prolog and need to be kept in */
4389 /* synchronization with it. */
4391 /*------------------------------------------------------------------*/
4394 emit_load_volatile_registers (guint8
* code
, MonoCompile
*cfg
)
4396 MonoMethod
*method
= cfg
->method
;
4397 MonoMethodSignature
*sig
;
4402 sig
= mono_method_signature (method
);
4405 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
4407 if (cinfo
->struct_ret
) {
4408 ArgInfo
*ainfo
= &cinfo
->ret
;
4409 inst
= cfg
->vret_addr
;
4410 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4413 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4414 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4415 inst
= cfg
->args
[pos
];
4417 if (inst
->opcode
== OP_REGVAR
) {
4418 if (ainfo
->regtype
== RegTypeGeneral
)
4419 s390_lr (code
, ainfo
->reg
, inst
->dreg
);
4420 else if (ainfo
->regtype
== RegTypeFP
) {
4421 if (inst
->dreg
!= ainfo
->reg
) {
4422 if (ainfo
->size
== 4) {
4423 s390_ldebr (code
, ainfo
->reg
, inst
->dreg
);
4425 s390_ldr (code
, ainfo
->reg
, inst
->dreg
);
4429 else if (ainfo
->regtype
== RegTypeBase
) {
4431 g_assert_not_reached ();
4433 if (ainfo
->regtype
== RegTypeGeneral
) {
4434 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4435 g_assert_not_reached();
4436 switch (ainfo
->size
) {
4438 s390_ic (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4441 s390_lh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4444 s390_lm (code
, ainfo
->reg
, ainfo
->reg
+ 1,
4445 inst
->inst_basereg
, inst
->inst_offset
);
4448 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4450 } else if (ainfo
->regtype
== RegTypeBase
) {
4451 } else if (ainfo
->regtype
== RegTypeFP
) {
4452 if (ainfo
->size
== 8)
4453 s390_ld (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4454 else if (ainfo
->size
== 4)
4455 s390_le (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4457 g_assert_not_reached ();
4458 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4459 if (ainfo
->reg
!= STK_BASE
) {
4460 switch (ainfo
->size
) {
4462 s390_ic (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4465 s390_lh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4468 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4471 s390_lm (code
, ainfo
->reg
, ainfo
->reg
+1, inst
->inst_basereg
, inst
->inst_offset
);
4475 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4476 if (ainfo
->reg
!= STK_BASE
) {
4477 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4480 g_assert_not_reached ();
4488 /*========================= End of Function ========================*/
4490 /*------------------------------------------------------------------*/
4492 /* Name - mono_arch_emit_prolog */
4494 /* Function - Create the instruction sequence for a function */
4497 /*------------------------------------------------------------------*/
4500 mono_arch_emit_prolog (MonoCompile
*cfg
)
4502 MonoMethod
*method
= cfg
->method
;
4504 MonoMethodSignature
*sig
;
4506 int alloc_size
, pos
, max_offset
, i
;
4512 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
))
4515 cfg
->code_size
= 1024;
4516 cfg
->native_code
= code
= g_malloc (cfg
->code_size
);
4518 s390_stm (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4520 if (cfg
->arch
.bkchain_reg
!= -1)
4521 s390_lr (code
, cfg
->arch
.bkchain_reg
, STK_BASE
);
4523 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
) {
4524 cfg
->used_int_regs
|= 1 << 11;
4527 alloc_size
= cfg
->stack_offset
;
4529 cfg
->stack_usage
= alloc_size
;
4530 s390_lr (code
, s390_r11
, STK_BASE
);
4531 if (s390_is_uimm16 (alloc_size
)) {
4532 s390_ahi (code
, STK_BASE
, -alloc_size
);
4534 int stackSize
= alloc_size
;
4535 while (stackSize
> 32767) {
4536 s390_ahi (code
, STK_BASE
, -32767);
4539 s390_ahi (code
, STK_BASE
, -stackSize
);
4541 s390_st (code
, s390_r11
, 0, STK_BASE
, 0);
4543 if (cfg
->frame_reg
!= STK_BASE
)
4544 s390_lr (code
, s390_r11
, STK_BASE
);
4546 /* compute max_offset in order to use short forward jumps
4547 * we always do it on s390 because the immediate displacement
4548 * for jumps is too small
4551 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
4552 MonoInst
*ins
= bb
->code
;
4553 bb
->max_offset
= max_offset
;
4555 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
)
4558 MONO_BB_FOR_EACH_INS (bb
, ins
)
4559 max_offset
+= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
4562 /* load arguments allocated to register from the stack */
4563 sig
= mono_method_signature (method
);
4566 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
4568 if (cinfo
->struct_ret
) {
4569 ArgInfo
*ainfo
= &cinfo
->ret
;
4570 inst
= cfg
->vret_addr
;
4571 inst
->backend
.size
= ainfo
->vtsize
;
4572 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4575 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4576 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4577 inst
= cfg
->args
[pos
];
4579 if (inst
->opcode
== OP_VTARG_ADDR
)
4580 inst
= inst
->inst_left
;
4582 if (inst
->opcode
== OP_REGVAR
) {
4583 if (ainfo
->regtype
== RegTypeGeneral
)
4584 s390_lr (code
, inst
->dreg
, ainfo
->reg
);
4585 else if (ainfo
->regtype
== RegTypeFP
) {
4586 if (inst
->dreg
!= ainfo
->reg
) {
4587 if (ainfo
->size
== 4) {
4588 s390_ledbr (code
, inst
->dreg
, ainfo
->reg
);
4590 s390_ldr (code
, inst
->dreg
, ainfo
->reg
);
4594 else if (ainfo
->regtype
== RegTypeBase
) {
4595 s390_lr (code
, s390_r13
, STK_BASE
);
4596 s390_ahi (code
, s390_r13
, alloc_size
);
4597 s390_l (code
, inst
->dreg
, 0, s390_r13
, ainfo
->offset
);
4599 g_assert_not_reached ();
4601 if (cfg
->verbose_level
> 2)
4602 g_print ("Argument %d assigned to register %s\n",
4603 pos
, mono_arch_regname (inst
->dreg
));
4605 if (ainfo
->regtype
== RegTypeGeneral
) {
4606 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4607 g_assert_not_reached();
4608 switch (ainfo
->size
) {
4610 s390_stc (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4613 s390_sth (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4616 s390_stm (code
, ainfo
->reg
, ainfo
->reg
+ 1,
4617 inst
->inst_basereg
, inst
->inst_offset
);
4620 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4622 } else if (ainfo
->regtype
== RegTypeBase
) {
4623 } else if (ainfo
->regtype
== RegTypeFP
) {
4624 if (ainfo
->size
== 8)
4625 s390_std (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4626 else if (ainfo
->size
== 4)
4627 s390_ste (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4629 g_assert_not_reached ();
4630 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4631 int doffset
= inst
->inst_offset
;
4633 if (ainfo
->reg
!= STK_BASE
)
4637 s390_lr (code
, s390_r13
, STK_BASE
);
4638 s390_ahi (code
, s390_r13
, alloc_size
);
4640 switch (ainfo
->size
) {
4642 if (ainfo
->reg
== STK_BASE
)
4643 s390_ic (code
, reg
, 0, s390_r13
, ainfo
->offset
+3);
4644 s390_stc (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4647 if (ainfo
->reg
== STK_BASE
)
4648 s390_lh (code
, reg
, 0, s390_r13
, ainfo
->offset
+2);
4649 s390_sth (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4652 if (ainfo
->reg
== STK_BASE
)
4653 s390_l (code
, reg
, 0, s390_r13
, ainfo
->offset
);
4654 s390_st (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4657 if (ainfo
->reg
== STK_BASE
)
4658 s390_lm (code
, s390_r0
, s390_r1
, s390_r13
, ainfo
->offset
);
4659 s390_stm (code
, reg
, reg
+1, inst
->inst_basereg
, doffset
);
4662 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4663 if (ainfo
->reg
!= STK_BASE
)
4664 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4666 g_assert_not_reached ();
4671 if (method
->save_lmf
) {
4672 /*---------------------------------------------------------------*/
4673 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4674 /*---------------------------------------------------------------*/
4675 lmfOffset
= alloc_size
- sizeof(MonoLMF
);
4677 s390_lr (code
, s390_r13
, cfg
->frame_reg
);
4678 if (s390_is_uimm16(lmfOffset
))
4679 s390_ahi (code
, s390_r13
, lmfOffset
);
4681 s390_basr (code
, s390_r14
, 0);
4683 s390_word (code
, lmfOffset
);
4684 s390_a (code
, s390_r13
, 0, s390_r14
, 4);
4687 /*---------------------------------------------------------------*/
4688 /* Preserve the parameter registers while we fix up the lmf */
4689 /*---------------------------------------------------------------*/
4690 s390_stm (code
, s390_r2
, s390_r6
, s390_r13
,
4691 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4693 /*---------------------------------------------------------------*/
4694 /* On return from this call r2 have the address of the &lmf */
4695 /*---------------------------------------------------------------*/
4696 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4697 MONO_PATCH_INFO_INTERNAL_METHOD
,
4698 (gpointer
)"mono_get_lmf_addr");
4699 s390_brasl (code
, s390_r14
, 0);
4701 /*---------------------------------------------------------------*/
4702 /* Set lmf.lmf_addr = jit_tls->lmf */
4703 /*---------------------------------------------------------------*/
4704 s390_st (code
, s390_r2
, 0, s390_r13
,
4705 G_STRUCT_OFFSET(MonoLMF
, lmf_addr
));
4707 /*---------------------------------------------------------------*/
4708 /* Get current lmf */
4709 /*---------------------------------------------------------------*/
4710 s390_l (code
, s390_r0
, 0, s390_r2
, 0);
4712 /*---------------------------------------------------------------*/
4713 /* Set our lmf as the current lmf */
4714 /*---------------------------------------------------------------*/
4715 s390_st (code
, s390_r13
, 0, s390_r2
, 0);
4717 /*---------------------------------------------------------------*/
4718 /* Have our lmf.previous_lmf point to the last lmf */
4719 /*---------------------------------------------------------------*/
4720 s390_st (code
, s390_r0
, 0, s390_r13
,
4721 G_STRUCT_OFFSET(MonoLMF
, previous_lmf
));
4723 /*---------------------------------------------------------------*/
4724 /* save method info */
4725 /*---------------------------------------------------------------*/
4726 s390_basr (code
, s390_r1
, 0);
4728 s390_word (code
, method
);
4729 s390_l (code
, s390_r1
, 0, s390_r1
, 4);
4730 s390_st (code
, s390_r1
, 0, s390_r13
,
4731 G_STRUCT_OFFSET(MonoLMF
, method
));
4733 /*---------------------------------------------------------------*/
4734 /* save the current IP */
4735 /*---------------------------------------------------------------*/
4736 s390_st (code
, STK_BASE
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, ebp
));
4737 s390_basr (code
, s390_r1
, 0);
4738 s390_la (code
, s390_r1
, 0, s390_r1
, 0);
4739 s390_st (code
, s390_r1
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, eip
));
4741 /*---------------------------------------------------------------*/
4742 /* Save general and floating point registers */
4743 /*---------------------------------------------------------------*/
4744 s390_stm (code
, s390_r2
, s390_r12
, s390_r13
,
4745 G_STRUCT_OFFSET(MonoLMF
, gregs
[2]));
4746 for (i
= 0; i
< 16; i
++) {
4747 s390_std (code
, i
, 0, s390_r13
,
4748 G_STRUCT_OFFSET(MonoLMF
, fregs
[i
]));
4751 /*---------------------------------------------------------------*/
4752 /* Restore the parameter registers now that we've set up the lmf */
4753 /*---------------------------------------------------------------*/
4754 s390_lm (code
, s390_r2
, s390_r6
, s390_r13
,
4755 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4759 code
= mono_arch_instrument_prolog(cfg
, enter_method
, code
, TRUE
);
4761 cfg
->code_len
= code
- cfg
->native_code
;
4763 g_assert (cfg
->code_len
< cfg
->code_size
);
4768 /*========================= End of Function ========================*/
4770 /*------------------------------------------------------------------*/
4772 /* Name - mono_arch_emit_epilog */
4774 /* Function - Emit the instructions for a function epilog. */
4776 /*------------------------------------------------------------------*/
4779 mono_arch_emit_epilog (MonoCompile
*cfg
)
4781 MonoMethod
*method
= cfg
->method
;
4784 int max_epilog_size
= 96;
4786 if (cfg
->method
->save_lmf
)
4787 max_epilog_size
+= 128;
4789 if (mono_jit_trace_calls
!= NULL
)
4790 max_epilog_size
+= 128;
4792 if (cfg
->prof_options
& MONO_PROFILE_ENTER_LEAVE
)
4793 max_epilog_size
+= 128;
4795 while ((cfg
->code_len
+ max_epilog_size
) > (cfg
->code_size
- 16)) {
4796 cfg
->code_size
*= 2;
4797 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4798 cfg
->stat_code_reallocs
++;
4801 code
= cfg
->native_code
+ cfg
->code_len
;
4803 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
)) {
4804 code
= mono_arch_instrument_epilog (cfg
, leave_method
, code
, TRUE
);
4808 if (method
->save_lmf
)
4809 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
4811 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
)
4812 s390_l (code
, STK_BASE
, 0, STK_BASE
, 0);
4814 code
= backUpStackPtr(cfg
, code
, STK_BASE
);
4816 s390_lm (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4817 s390_br (code
, s390_r14
);
4819 cfg
->code_len
= code
- cfg
->native_code
;
4821 g_assert (cfg
->code_len
< cfg
->code_size
);
4825 /*========================= End of Function ========================*/
4827 /*------------------------------------------------------------------*/
4829 /* Name - mono_arch_emit_exceptions */
4831 /* Function - Emit the blocks to handle exception conditions. */
4833 /*------------------------------------------------------------------*/
4836 mono_arch_emit_exceptions (MonoCompile
*cfg
)
4838 MonoJumpInfo
*patch_info
;
4844 MonoClass
*exc_classes
[MAX_EXC
];
4845 guint8
*exc_throw_start
[MAX_EXC
];
4847 for (patch_info
= cfg
->patch_info
;
4849 patch_info
= patch_info
->next
) {
4850 if (patch_info
->type
== MONO_PATCH_INFO_EXC
)
4854 code_size
= exc_count
* 26;
4856 while ((cfg
->code_len
+ code_size
) > (cfg
->code_size
- 16)) {
4857 cfg
->code_size
*= 2;
4858 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4859 cfg
->stat_code_reallocs
++;
4862 code
= cfg
->native_code
+ cfg
->code_len
;
4864 /*---------------------------------------------------------------------*/
4865 /* Add code to raise exceptions */
4866 /*---------------------------------------------------------------------*/
4867 for (patch_info
= cfg
->patch_info
; patch_info
; patch_info
= patch_info
->next
) {
4868 switch (patch_info
->type
) {
4869 case MONO_PATCH_INFO_EXC
: {
4870 guint8
*ip
= patch_info
->ip
.i
+ cfg
->native_code
;
4871 MonoClass
*exc_class
;
4874 /*-----------------------------------------------------*/
4875 /* Patch the branch in epilog to come here */
4876 /*-----------------------------------------------------*/
4877 s390_patch (ip
+ 2, (guint32
) (S390_RELATIVE(code
,ip
)));
4879 exc_class
= mono_class_from_name (mono_defaults
.corlib
,
4881 patch_info
->data
.name
);
4882 g_assert (exc_class
);
4883 throw_ip
= patch_info
->ip
.i
;
4885 for (iExc
= 0; iExc
< nThrows
; ++iExc
)
4886 if (exc_classes
[iExc
] == exc_class
)
4889 if (iExc
< nThrows
) {
4890 s390_jcl (code
, S390_CC_UN
, (guint32
) exc_throw_start
[iExc
]);
4891 patch_info
->type
= MONO_PATCH_INFO_NONE
;
4894 if (nThrows
< MAX_EXC
) {
4895 exc_classes
[nThrows
] = exc_class
;
4896 exc_throw_start
[nThrows
] = code
;
4899 /*---------------------------------------------*/
4900 /* Patch the parameter passed to the handler */
4901 /*---------------------------------------------*/
4902 s390_basr (code
, s390_r13
, 0);
4904 s390_word (code
, patch_info
->data
.target
);
4905 /*---------------------------------------------*/
4906 /* Load return address & parameter register */
4907 /*---------------------------------------------*/
4908 s390_larl (code
, s390_r14
, (gsize
)S390_RELATIVE((patch_info
->ip
.i
+
4909 cfg
->native_code
+ 8), code
));
4910 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
4911 /*---------------------------------------------*/
4912 /* Reuse the current patch to set the jump */
4913 /*---------------------------------------------*/
4914 patch_info
->type
= MONO_PATCH_INFO_INTERNAL_METHOD
;
4915 patch_info
->data
.name
= "mono_arch_throw_exception_by_name";
4916 patch_info
->ip
.i
= code
- cfg
->native_code
;
4917 s390_jcl (code
, S390_CC_UN
, 0);
4927 cfg
->code_len
= code
- cfg
->native_code
;
4929 g_assert (cfg
->code_len
< cfg
->code_size
);
4933 /*========================= End of Function ========================*/
4935 /*------------------------------------------------------------------*/
4937 /* Name - mono_arch_finish_init */
4939 /* Function - Setup the JIT's Thread Level Specific Data. */
4941 /*------------------------------------------------------------------*/
4944 mono_arch_finish_init (void)
4948 __asm__ ("\tear\t%r1,0\n"
4955 : "=r" (appdomain_tls_offset
),
4956 "=r" (thread_tls_offset
),
4957 "=r" (lmf_tls_offset
)
4958 : "r" (&tls_appdomain
),
4959 "r" (&tls_current_object
),
4960 "r" (&mono_lmf_addr
)
4965 if (!lmf_addr_key_inited
) {
4966 lmf_addr_key_inited
= TRUE
;
4967 pthread_key_create (&lmf_addr_key
, NULL
);
4969 pthread_setspecific (lmf_addr_key
, &tls
->lmf
);
4973 /*========================= End of Function ========================*/
4975 /*------------------------------------------------------------------*/
4977 /* Name - mono_arch_free_jit_tls_data */
4979 /* Function - Free tls data. */
4981 /*------------------------------------------------------------------*/
4984 mono_arch_free_jit_tls_data (MonoJitTlsData
*tls
)
4988 /*========================= End of Function ========================*/
4990 /*------------------------------------------------------------------*/
4992 /* Name - mono_arch_emit_inst_for_method */
4994 /*------------------------------------------------------------------*/
4997 mono_arch_emit_inst_for_method (MonoCompile
*cfg
, MonoMethod
*cmethod
, MonoMethodSignature
*fsig
, MonoInst
**args
)
5002 /*========================= End of Function ========================*/
5004 /*------------------------------------------------------------------*/
5006 /* Name - mono_arch_decompose_opts */
5008 /*------------------------------------------------------------------*/
5011 mono_arch_decompose_opts (MonoCompile
*cfg
, MonoInst
*ins
)
5013 switch (ins
->opcode
) {
5015 ins
->opcode
= OP_S390_ISUB_OVF
;
5017 case OP_ISUB_OVF_UN
:
5018 ins
->opcode
= OP_S390_ISUB_OVF_UN
;
5021 ins
->opcode
= OP_S390_IADD_OVF
;
5023 case OP_IADD_OVF_UN
:
5024 ins
->opcode
= OP_S390_IADD_OVF_UN
;
5031 /*========================= End of Function ========================*/
5033 /*------------------------------------------------------------------*/
5035 /* Name - mono_arch_decompose_long_opts */
5037 /*------------------------------------------------------------------*/
5040 mono_arch_decompose_long_opts (MonoCompile
*cfg
, MonoInst
*ins
)
5042 // The generic code seems to work for OP_LSUB fine on s390, why is a different
5043 // implementation needed ? gcc also seems to use the different implementation.
5044 // FIXME: What about the other OP_L opcodes below ?
5046 switch (ins
->opcode
) {
5048 case OP_LADD_OVF_UN
:
5050 case OP_LSUB_OVF_UN
: {
5053 switch (ins
->opcode
) {
5055 opcode
= OP_S390_LADD
;
5058 opcode
= OP_S390_LADD_OVF
;
5060 case OP_LADD_OVF_UN
:
5061 opcode
= OP_S390_LADD_OVF_UN
;
5064 opcode
= OP_S390_LSUB
;
5067 opcode
= OP_S390_LSUB_OVF
;
5069 case OP_LSUB_OVF_UN
:
5070 opcode
= OP_S390_LSUB_OVF_UN
;
5073 g_assert_not_reached ();
5076 /* These hard regs make ssa crazy */
5077 cfg
->disable_ssa
= TRUE
;
5078 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r0
, ins
->sreg1
+ 1);
5079 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r1
, ins
->sreg1
+ 2);
5080 MONO_EMIT_NEW_BIALU (cfg
, opcode
, ins
->dreg
, ins
->sreg2
+ 1, ins
->sreg2
+ 2);
5085 int dreg
= mono_alloc_dreg (cfg
, STACK_I8
);
5086 MONO_EMIT_NEW_I8CONST (cfg
, dreg
, ins
->inst_l
);
5087 MONO_EMIT_NEW_BIALU (cfg
, OP_LADD
, ins
->dreg
, ins
->sreg1
, dreg
);
5092 int dreg
= mono_alloc_dreg (cfg
, STACK_I8
);
5093 MONO_EMIT_NEW_I8CONST (cfg
, dreg
, ins
->inst_l
);
5094 MONO_EMIT_NEW_BIALU (cfg
, OP_LSUB
, ins
->dreg
, ins
->sreg1
, dreg
);
5099 MONO_EMIT_NEW_BIALU (cfg
, OP_S390_LNEG
, ins
->dreg
, ins
->sreg1
+ 1, ins
->sreg1
+ 2);
5104 ins
->opcode
= OP_S390_ISUB_OVF
;
5106 case OP_ISUB_OVF_UN
:
5107 ins
->opcode
= OP_S390_ISUB_OVF_UN
;
5114 /*========================= End of Function ========================*/
5116 /*------------------------------------------------------------------*/
5118 /* Name - mono_arch_print_tree */
5120 /* Function - Print platform-specific opcode details. */
5122 /* Returns - 1 - opcode details have been printed */
5123 /* 0 - opcode details have not been printed */
5125 /*------------------------------------------------------------------*/
5128 mono_arch_print_tree (MonoInst
*tree
, int arity
)
5132 switch (tree
->opcode
) {
5133 case OP_S390_LOADARG
:
5134 case OP_S390_ARGREG
:
5135 case OP_S390_ARGPTR
:
5136 printf ("[0x%lx(%s)]", tree
->inst_offset
,
5137 mono_arch_regname (tree
->inst_basereg
));
5140 case OP_S390_STKARG
:
5141 printf ("[0x%lx(previous_frame)]",
5146 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5147 tree
->inst_offset
, tree
->backend
.size
,
5148 mono_arch_regname(tree
->dreg
), tree
->inst_imm
,
5149 mono_arch_regname(tree
->sreg1
));
5152 case OP_S390_SETF4RET
:
5154 mono_arch_fregname (tree
->dreg
),
5155 mono_arch_fregname (tree
->sreg1
));
5159 printf ("[0x%lx(0x%lx,%s)]", tree
->inst_offset
,
5161 mono_arch_regname (tree
->sreg1
));
5164 case OP_S390_BKCHAIN
:
5165 printf ("[previous_frame(%s)]",
5166 mono_arch_regname (tree
->sreg1
));
5175 /*========================= End of Function ========================*/
5177 /*------------------------------------------------------------------*/
5179 /* Name - mono_arch_regalloc_cost */
5181 /* Function - Determine the cost, in the number of memory */
5182 /* references, of the action of allocating the var- */
5183 /* iable VMV into a register during global register */
5186 /* Returns - Cost */
5188 /*------------------------------------------------------------------*/
5191 mono_arch_regalloc_cost (MonoCompile
*cfg
, MonoMethodVar
*vmv
)
5197 /*========================= End of Function ========================*/
5199 /*------------------------------------------------------------------*/
5201 /* Name - mono_arch_get_domain_intrinsic */
5207 /*------------------------------------------------------------------*/
5210 mono_arch_get_domain_intrinsic (MonoCompile
* cfg
)
5214 if (appdomain_tls_offset
== -1)
5217 MONO_INST_NEW (cfg
, ins
, OP_TLS_GET
);
5218 ins
->inst_offset
= appdomain_tls_offset
;
5222 /*========================= End of Function ========================*/
5224 /*------------------------------------------------------------------*/
5226 /* Name - mono_arch_flush_register_windows */
5232 /*------------------------------------------------------------------*/
5235 mono_arch_flush_register_windows (void)
5239 /*========================= End of Function ========================*/
5241 /*------------------------------------------------------------------*/
5243 /* Name - mono_arch_get_lmf_addr */
5249 /*------------------------------------------------------------------*/
5252 mono_arch_get_lmf_addr (void)
5254 return pthread_getspecific (lmf_addr_key
);
5258 /*========================= End of Function ========================*/
5260 /*------------------------------------------------------------------*/
5262 /* Name - mono_arch_get_patch_offset */
5264 /* Function - Dummy entry point until s390x supports aot. */
5266 /* Returns - Offset for patch. */
5268 /*------------------------------------------------------------------*/
5271 mono_arch_get_patch_offset (guint8
*code
)
5276 /*========================= End of Function ========================*/
5278 /*------------------------------------------------------------------*/
5280 /* Name - mono_arch_context_get_int_reg. */
5282 /* Function - Dummy entry point until s390x supports aot. */
5284 /* Returns - Pointer to intreg. */
5286 /*------------------------------------------------------------------*/
5289 mono_arch_context_get_int_reg (MonoContext
*ctx
, int reg
)
5291 /* FIXME: implement */
5292 g_assert_not_reached ();
5296 /*========================= End of Function ========================*/