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->flags & MONO_INST_BRLABEL) { \
24 if (ins->inst_i0->inst_c0) { \
26 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - 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_LABEL, ins->inst_i0); \
35 s390_jcl (code, cond, 0); \
38 if (ins->inst_true_bb->native_offset) { \
40 displace = ((cfg->native_code + \
41 ins->inst_true_bb->native_offset) - code) / 2; \
42 if (s390_is_imm16(displace)) { \
43 s390_brc (code, cond, displace); \
45 s390_jcl (code, cond, displace); \
48 mono_add_patch_info (cfg, code - cfg->native_code, \
49 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
50 s390_jcl (code, cond, 0); \
55 #define EMIT_UNCOND_BRANCH(ins) \
57 if (ins->flags & MONO_INST_BRLABEL) { \
58 if (ins->inst_i0->inst_c0) { \
60 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
61 if (s390_is_imm16(displace)) { \
62 s390_brc (code, S390_CC_UN, displace); \
64 s390_jcl (code, S390_CC_UN, displace); \
67 mono_add_patch_info (cfg, code - cfg->native_code, \
68 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
69 s390_jcl (code, S390_CC_UN, 0); \
72 if (ins->inst_target_bb->native_offset) { \
74 displace = ((cfg->native_code + \
75 ins->inst_target_bb->native_offset) - code) / 2; \
76 if (s390_is_imm16(displace)) { \
77 s390_brc (code, S390_CC_UN, displace); \
79 s390_jcl (code, S390_CC_UN, displace); \
82 mono_add_patch_info (cfg, code - cfg->native_code, \
83 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
84 s390_jcl (code, S390_CC_UN, 0); \
89 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
91 mono_add_patch_info (cfg, code - cfg->native_code, \
92 MONO_PATCH_INFO_EXC, exc_name); \
93 s390_jcl (code, cond, 0); \
96 #define CHECK_SRCDST_COM \
97 if (ins->dreg == ins->sreg2) { \
101 if (ins->dreg != ins->sreg1) { \
102 s390_lr (code, ins->dreg, ins->sreg1); \
106 #define CHECK_SRCDST_NCOM \
107 if (ins->dreg == ins->sreg2) { \
109 s390_lr (code, s390_r13, ins->sreg2); \
113 if (ins->dreg != ins->sreg1) { \
114 s390_lr (code, ins->dreg, ins->sreg1); \
117 #define CHECK_SRCDST_COM_F \
118 if (ins->dreg == ins->sreg2) { \
122 if (ins->dreg != ins->sreg1) { \
123 s390_ldr (code, ins->dreg, ins->sreg1); \
127 #define CHECK_SRCDST_NCOM_F \
128 if (ins->dreg == ins->sreg2) { \
130 s390_ldr (code, s390_r13, ins->sreg2); \
134 if (ins->dreg != ins->sreg1) { \
135 s390_ldr (code, ins->dreg, ins->sreg1); \
138 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
142 MONO_INST_NEW (cfg, inst, OP_NOP); \
144 tmpr = mono_alloc_preg (cfg); \
145 MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
147 inst->inst_offset = offset; \
149 inst->inst_imm = imm; \
150 inst->sreg2 = tmpr; \
152 if (s390_is_uimm12(offset)) { \
154 inst->inst_offset = offset; \
156 dReg = mono_alloc_preg (cfg); \
157 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
158 dReg, dest, offset); \
160 inst->inst_offset = 0; \
162 if (s390_is_uimm12(imm)) { \
164 inst->inst_imm = imm; \
166 sReg = mono_alloc_preg (cfg); \
167 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
169 inst->sreg1 = sReg; \
170 inst->inst_imm = 0; \
173 inst->opcode = OP_S390_MOVE; \
174 inst->backend.size = size; \
175 MONO_ADD_INS (cfg->cbb, inst); \
178 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
179 int reg = mono_alloc_preg (cfg); \
182 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
183 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
186 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
188 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
191 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
193 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
196 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
198 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
201 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
203 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
204 reg = mono_alloc_preg (cfg); \
205 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
206 reg, sr, so + sizeof (guint32)); \
207 mono_call_inst_add_outarg_reg(cfg, call, reg, dr + 1, FALSE); \
212 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
216 tmpr = mono_alloc_preg (cfg); \
217 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
218 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
222 tmpr = mono_alloc_preg (cfg); \
223 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
225 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
229 tmpr = mono_alloc_preg (cfg); \
230 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
232 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
237 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
243 #define DEBUG(a) if (cfg->verbose_level > 1) a
247 #define S390_TRACE_STACK_SIZE (5*sizeof(gint32)+3*sizeof(gdouble))
249 #define MAX (a, b) ((a) > (b) ? (a) : (b))
251 /*========================= End of Defines =========================*/
253 /*------------------------------------------------------------------*/
254 /* I n c l u d e s */
255 /*------------------------------------------------------------------*/
260 #include <mono/metadata/appdomain.h>
261 #include <mono/metadata/debug-helpers.h>
262 #include <mono/metadata/profiler-private.h>
263 #include <mono/utils/mono-math.h>
265 #include "mini-s390.h"
266 #include "cpu-s390.h"
267 #include "jit-icalls.h"
270 /*========================= End of Includes ========================*/
272 /*------------------------------------------------------------------*/
273 /* T y p e d e f s */
274 /*------------------------------------------------------------------*/
286 /*------------------------------------------------------------------*/
287 /* Used by the instrument_emit_epilog */
288 /*------------------------------------------------------------------*/
299 typedef struct InstList InstList
;
313 RegTypeStructByValInFP
,
318 gint32 offset
; /* offset from caller's stack */
319 gint32 offparm
; /* offset from callee's stack */
320 guint16 vtsize
; /* in param area */
322 ArgStorage regtype
; /* See RegType* */
323 guint32 size
; /* Size of structure used by RegTypeStructByVal */
338 gint32 gr
[5]; /* R2-R6 */
339 gdouble fp
[3]; /* F0-F2 */
340 } __attribute__ ((packed
)) RegParm
;
342 /*========================= End of Typedefs ========================*/
344 /*------------------------------------------------------------------*/
345 /* P r o t o t y p e s */
346 /*------------------------------------------------------------------*/
348 static void indent (int);
349 static guint8
* backUpStackPtr(MonoCompile
*, guint8
*, gint
);
350 static void decodeParm (MonoType
*, void *, int);
351 static void enter_method (MonoMethod
*, RegParm
*, char *);
352 static void leave_method (MonoMethod
*, ...);
353 static gboolean
is_regsize_var (MonoType
*);
354 static inline void add_general (guint
*, size_data
*, ArgInfo
*, gboolean
);
355 static inline void add_stackParm (guint
*, size_data
*, ArgInfo
*, gint
);
356 static inline void add_float (guint
*, size_data
*, ArgInfo
*);
357 static CallInfo
* get_call_info (MonoCompile
*, MonoMemPool
*, MonoMethodSignature
*, gboolean
);
358 static guchar
* emit_float_to_int (MonoCompile
*, guchar
*, int, int, int, gboolean
);
359 gpointer
mono_arch_get_lmf_addr (void);
360 static guint8
* emit_load_volatile_registers(guint8
*, MonoCompile
*);
361 static void emit_sig_cookie (MonoCompile
*, MonoCallInst
*, CallInfo
*);
363 /*========================= End of Prototypes ======================*/
365 /*------------------------------------------------------------------*/
366 /* G l o b a l V a r i a b l e s */
367 /*------------------------------------------------------------------*/
369 int mono_exc_esp_offset
= 0;
371 static int indent_level
= 0;
373 static gboolean tls_offset_inited
= FALSE
;
375 static int appdomain_tls_offset
= -1,
376 thread_tls_offset
= -1;
378 pthread_key_t lmf_addr_key
;
380 gboolean lmf_addr_key_inited
= FALSE
;
384 extern __thread MonoDomain
*tls_appdomain
;
385 extern __thread MonoThread
*tls_current_object
;
386 extern __thread gpointer mono_lmf_addr
;
390 /*====================== End of Global Variables ===================*/
392 /*------------------------------------------------------------------*/
394 /* Name - mono_arch_regname */
396 /* Function - Returns the name of the register specified by */
397 /* the input parameter. */
399 /*------------------------------------------------------------------*/
402 mono_arch_regname (int reg
) {
403 static const char * rnames
[] = {
404 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
405 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
406 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
410 if (reg
>= 0 && reg
< 16)
416 /*========================= End of Function ========================*/
418 /*------------------------------------------------------------------*/
420 /* Name - mono_arch_fregname */
422 /* Function - Returns the name of the register specified by */
423 /* the input parameter. */
425 /*------------------------------------------------------------------*/
428 mono_arch_fregname (int reg
) {
429 static const char * rnames
[] = {
430 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
431 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
432 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
436 if (reg
>= 0 && reg
< 16)
442 /*========================= End of Function ========================*/
444 /*------------------------------------------------------------------*/
446 /* Name - arch_get_argument_info */
448 /* Function - Gathers information on parameters such as size, */
449 /* alignment, and padding. arg_info should be large */
450 /* enough to hold param_count + 1 entries. */
452 /* Parameters - @csig - Method signature */
453 /* @param_count - No. of parameters to consider */
454 /* @arg_info - An array to store the result info */
456 /* Returns - Size of the activation frame */
458 /*------------------------------------------------------------------*/
461 mono_arch_get_argument_info (MonoMethodSignature
*csig
,
463 MonoJitArgumentInfo
*arg_info
)
465 int k
, frame_size
= 0;
466 int size
, align
, pad
;
469 if (MONO_TYPE_ISSTRUCT (csig
->ret
)) {
470 frame_size
+= sizeof (gpointer
);
474 arg_info
[0].offset
= offset
;
477 frame_size
+= sizeof (gpointer
);
481 arg_info
[0].size
= frame_size
;
483 for (k
= 0; k
< param_count
; k
++) {
486 size
= mono_type_native_stack_size (csig
->params
[k
], &align
);
488 size
= mini_type_stack_size (NULL
, csig
->params
[k
], &align
);
490 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
491 arg_info
[k
].pad
= pad
;
493 arg_info
[k
+ 1].pad
= 0;
494 arg_info
[k
+ 1].size
= size
;
496 arg_info
[k
+ 1].offset
= offset
;
500 align
= MONO_ARCH_FRAME_ALIGNMENT
;
501 frame_size
+= pad
= (align
- (frame_size
& (align
- 1))) & (align
- 1);
502 arg_info
[k
].pad
= pad
;
507 /*========================= End of Function ========================*/
509 /*------------------------------------------------------------------*/
511 /* Name - retFitsInReg. */
513 /* Function - Determines if a value can be returned in one or */
516 /*------------------------------------------------------------------*/
518 static inline gboolean
519 retFitsInReg(guint32 size
)
534 /*========================= End of Function ========================*/
536 /*------------------------------------------------------------------*/
538 /* Name - backStackPtr. */
540 /* Function - Restore Stack Pointer to previous frame. */
542 /*------------------------------------------------------------------*/
544 static inline guint8
*
545 backUpStackPtr(MonoCompile
*cfg
, guint8
*code
, gint framePtr
)
547 int stackSize
= cfg
->stack_usage
;
549 if (s390_is_uimm16 (cfg
->stack_usage
)) {
550 s390_ahi (code
, framePtr
, cfg
->stack_usage
);
552 while (stackSize
> 32767) {
553 s390_ahi (code
, framePtr
, 32767);
556 s390_ahi (code
, framePtr
, stackSize
);
561 /*========================= End of Function ========================*/
563 /*------------------------------------------------------------------*/
567 /* Function - Perform nice indenting to current level */
569 /*------------------------------------------------------------------*/
575 indent_level
+= diff
;
582 indent_level
+= diff
;
585 /*========================= End of Function ========================*/
587 /*------------------------------------------------------------------*/
589 /* Name - decodeParm */
591 /* Function - Decode a parameter for the trace. */
593 /*------------------------------------------------------------------*/
596 decodeParm(MonoType
*type
, void *curParm
, int size
)
601 printf("[BYREF:%p], ", *((char **) curParm
));
603 simpleType
= mono_type_get_underlying_type(type
)->type
;
605 switch (simpleType
) {
607 printf ("[INTPTR:%p], ", *((int **) curParm
));
610 printf ("[UINTPTR:%p], ", *((int **) curParm
));
612 case MONO_TYPE_BOOLEAN
:
613 printf ("[BOOL:%d], ", *((int *) curParm
));
615 case MONO_TYPE_CHAR
:
616 printf ("[CHAR:%c], ", *((int *) curParm
));
619 printf ("[INT1:%d], ", *((int *) curParm
));
622 printf ("[INT2:%d], ", *((int *) curParm
));
625 printf ("[INT4:%d], ", *((int *) curParm
));
628 printf ("[UINT1:%u], ", *((unsigned int *) curParm
));
631 printf ("[UINT2:%u], ", *((guint16
*) curParm
));
634 printf ("[UINT4:%u], ", *((guint32
*) curParm
));
637 printf ("[UINT8:%llu], ", *((guint64
*) curParm
));
639 case MONO_TYPE_STRING
: {
640 MonoString
*s
= *((MonoString
**) curParm
);
642 g_assert (((MonoObject
*) s
)->vtable
->klass
== mono_defaults
.string_class
);
643 printf("[STRING:%p:%s], ", s
, mono_string_to_utf8(s
));
645 printf("[STRING:null], ");
649 case MONO_TYPE_CLASS
:
650 case MONO_TYPE_OBJECT
: {
651 MonoObject
*obj
= *((MonoObject
**) curParm
);
653 if ((obj
) && (obj
->vtable
)) {
654 printf("[CLASS/OBJ:");
655 class = obj
->vtable
->klass
;
656 printf("%p [%p] ",obj
,curParm
);
657 // if (class == mono_defaults.string_class) {
658 // printf("[STRING:%p:%s]",
659 // *obj, mono_string_to_utf8 (obj));
660 // } else if (class == mono_defaults.int32_class) {
661 // printf("[INT32:%p:%d]",
662 // obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
664 // printf("[%s.%s:%p]",
665 // class->name_space, class->name, obj);
668 printf("[OBJECT:null], ");
673 printf("[PTR:%p], ", *((gpointer
**) (curParm
)));
675 case MONO_TYPE_FNPTR
:
676 printf("[FNPTR:%p], ", *((gpointer
**) (curParm
)));
678 case MONO_TYPE_ARRAY
:
679 printf("[ARRAY:%p], ", *((gpointer
**) (curParm
)));
681 case MONO_TYPE_SZARRAY
:
682 printf("[SZARRAY:%p], ", *((gpointer
**) (curParm
)));
685 printf("[INT8:%lld], ", *((gint64
*) (curParm
)));
688 printf("[FLOAT4:%g], ", *((double *) (curParm
)));
691 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
693 case MONO_TYPE_VALUETYPE
: {
695 MonoMarshalType
*info
;
697 if (type
->data
.klass
->enumtype
) {
698 simpleType
= mono_class_enum_basetype (type
->data
.klass
)->type
;
699 printf("{VALUETYPE} - ");
703 info
= mono_marshal_load_type_info (type
->data
.klass
);
705 if ((info
->native_size
== sizeof(float)) &&
706 (info
->num_fields
== 1) &&
707 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
708 printf("[FLOAT4:%f], ", *((float *) (curParm
)));
712 if ((info
->native_size
== sizeof(double)) &&
713 (info
->num_fields
== 1) &&
714 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
715 printf("[FLOAT8:%g], ", *((double *) (curParm
)));
719 printf("[VALUETYPE:");
720 for (i
= 0; i
< size
; i
++)
721 printf("%02x,", *((guint8
*)curParm
+i
));
725 case MONO_TYPE_TYPEDBYREF
: {
727 printf("[TYPEDBYREF:");
728 for (i
= 0; i
< size
; i
++)
729 printf("%02x,", *((guint8
*)curParm
+i
));
734 printf("[?? - %d], ",simpleType
);
739 /*========================= End of Function ========================*/
743 /*------------------------------------------------------------------*/
745 /* Name - enter_method */
747 /* Function - Perform tracing of the entry to the current */
750 /*------------------------------------------------------------------*/
753 enter_method (MonoMethod
*method
, RegParm
*rParm
, char *sp
)
755 int i
, oParm
= 0, iParm
= 0;
757 MonoMethodSignature
*sig
;
764 fname
= mono_method_full_name (method
, TRUE
);
766 printf ("ENTER: %s(", fname
);
769 ip
= (*(guint32
*) (sp
+S390_RET_ADDR_OFFSET
)) & 0x7fffffff;
770 printf (") ip: %p sp: %p - ", (gpointer
) ip
, sp
);
775 sig
= mono_method_signature (method
);
777 cinfo
= get_call_info (NULL
, NULL
, sig
, sig
->pinvoke
);
779 if (cinfo
->struct_ret
) {
780 printf ("[STRUCTRET:%p], ", (gpointer
) rParm
->gr
[0]);
785 gpointer
*this = (gpointer
*) rParm
->gr
[iParm
];
786 obj
= (MonoObject
*) this;
787 if (method
->klass
->valuetype
) {
789 printf("this:[value:%p:%08x], ",
790 this, *((guint32
*)(this+sizeof(MonoObject
))));
792 printf ("this:[NULL], ");
795 // class = obj->vtable->klass;
796 // if (class == mono_defaults.string_class) {
797 // printf ("this:[STRING:%p:%s], ",
798 // obj, mono_string_to_utf8 ((MonoString *)obj));
800 // printf ("this:%p[%s.%s], ",
801 // obj, class->name_space, class->name);
803 printf("this:%p, ",obj
);
805 printf ("this:NULL, ");
810 for (i
= 0; i
< sig
->param_count
; ++i
) {
811 ainfo
= &cinfo
->args
[i
+ oParm
];
812 switch (ainfo
->regtype
) {
813 case RegTypeGeneral
:
814 decodeParm(sig
->params
[i
], &(rParm
->gr
[ainfo
->reg
-2]), ainfo
->size
);
817 decodeParm(sig
->params
[i
], &(rParm
->fp
[ainfo
->reg
]), ainfo
->size
);
820 decodeParm(sig
->params
[i
], sp
+ainfo
->offset
, ainfo
->size
);
822 case RegTypeStructByVal
:
823 if (ainfo
->reg
!= STK_BASE
)
824 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
826 curParm
= sp
+ainfo
->offset
;
828 if (retFitsInReg (ainfo
->vtsize
))
829 decodeParm(sig
->params
[i
],
833 decodeParm(sig
->params
[i
],
834 *((char **) curParm
),
837 case RegTypeStructByAddr
:
838 if (ainfo
->reg
!= STK_BASE
)
839 curParm
= &(rParm
->gr
[ainfo
->reg
-2]);
841 curParm
= sp
+ainfo
->offset
;
843 decodeParm(sig
->params
[i
],
844 *((char **) curParm
),
856 /*========================= End of Function ========================*/
858 /*------------------------------------------------------------------*/
860 /* Name - leave_method */
864 /*------------------------------------------------------------------*/
867 leave_method (MonoMethod
*method
, ...)
874 va_start(ap
, method
);
876 fname
= mono_method_full_name (method
, TRUE
);
878 printf ("LEAVE: %s", fname
);
881 type
= mono_method_signature (method
)->ret
;
884 switch (type
->type
) {
887 case MONO_TYPE_BOOLEAN
: {
888 int val
= va_arg (ap
, int);
890 printf ("[TRUE:%d]", val
);
896 case MONO_TYPE_CHAR
: {
897 int val
= va_arg (ap
, int);
898 printf ("[CHAR:%d]", val
);
902 int val
= va_arg (ap
, int);
903 printf ("[INT1:%d]", val
);
907 int val
= va_arg (ap
, int);
908 printf ("[UINT1:%d]", val
);
912 int val
= va_arg (ap
, int);
913 printf ("[INT2:%d]", val
);
917 int val
= va_arg (ap
, int);
918 printf ("[UINT2:%d]", val
);
922 int val
= va_arg (ap
, int);
923 printf ("[INT4:%d]", val
);
927 int val
= va_arg (ap
, int);
928 printf ("[UINT4:%d]", val
);
932 int val
= va_arg (ap
, int);
933 printf ("[INT:%d]", val
);
938 int val
= va_arg (ap
, int);
939 printf ("[UINT:%d]", val
);
943 case MONO_TYPE_STRING
: {
944 MonoString
*s
= va_arg (ap
, MonoString
*);
947 g_assert (((MonoObject
*)s
)->vtable
->klass
== mono_defaults
.string_class
);
948 printf ("[STRING:%p:%s]", s
, mono_string_to_utf8 (s
));
950 printf ("[STRING:null], ");
953 case MONO_TYPE_CLASS
:
954 case MONO_TYPE_OBJECT
: {
955 MonoObject
*o
= va_arg (ap
, MonoObject
*);
957 // if ((o) && (o->vtable)) {
958 // if (o->vtable->klass == mono_defaults.boolean_class) {
959 // printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
960 // } else if (o->vtable->klass == mono_defaults.int32_class) {
961 // printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
962 // } else if (o->vtable->klass == mono_defaults.int64_class) {
963 // printf ("[INT64:%p:%lld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
965 // printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
967 printf ("[OBJECT:%p]", o
);
972 case MONO_TYPE_FNPTR
:
973 case MONO_TYPE_ARRAY
:
974 case MONO_TYPE_SZARRAY
: {
975 gpointer p
= va_arg (ap
, gpointer
);
976 printf ("[result=%p]", p
);
980 gint64 l
= va_arg (ap
, gint64
);
981 printf ("[LONG:%lld]", l
);
985 guint64 l
= va_arg (ap
, guint64
);
986 printf ("[ULONG:%llu]", l
);
991 f
= va_arg (ap
, double);
992 printf ("[FLOAT4:%g]\n", f
);
996 double f
= va_arg (ap
, double);
997 printf ("[FLOAT8:%g]\n", f
);
1000 case MONO_TYPE_VALUETYPE
: {
1001 MonoMarshalType
*info
;
1002 if (type
->data
.klass
->enumtype
) {
1003 type
= mono_class_enum_basetype (type
->data
.klass
);
1006 guint8
*p
= va_arg (ap
, gpointer
);
1009 info
= mono_marshal_load_type_info (type
->data
.klass
);
1011 if ((info
->native_size
== sizeof(float)) &&
1012 (info
->num_fields
== 1) &&
1013 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
1014 double f
= va_arg (ap
, double);
1015 printf("[FLOAT4:%g]\n", (double) f
);
1019 if ((info
->native_size
== sizeof(double)) &&
1020 (info
->num_fields
== 1) &&
1021 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
1022 double f
= va_arg (ap
, double);
1023 printf("[FLOAT8:%g]\n", f
);
1027 size
= mono_type_size (type
, &align
);
1034 for (j
= 0; p
&& j
< size
; j
++)
1035 printf ("%02x,", p
[j
]);
1039 printf ("[VALUERET]\n");
1044 case MONO_TYPE_TYPEDBYREF
: {
1045 guint8
*p
= va_arg (ap
, gpointer
);
1047 size
= mono_type_size (type
, &align
);
1054 for (j
= 0; p
&& j
< size
; j
++)
1055 printf ("%02x,", p
[j
]);
1059 printf ("[TYPEDBYREF]\n");
1064 printf ("(unknown return type %x)",
1065 mono_method_signature (method
)->ret
->type
);
1068 ip
= ((gint32
) __builtin_return_address (0)) & 0x7fffffff;
1069 printf (" ip: %p\n", (gpointer
) ip
);
1072 /*========================= End of Function ========================*/
1074 /*------------------------------------------------------------------*/
1076 /* Name - mono_arch_cpu_init */
1078 /* Function - Perform CPU specific initialization to execute */
1081 /*------------------------------------------------------------------*/
1084 mono_arch_cpu_init (void)
1088 /*--------------------------------------*/
1089 /* Set default rounding mode for FP */
1090 /*--------------------------------------*/
1091 __asm__ ("SRNM\t%0\n\t"
1095 /*========================= End of Function ========================*/
1099 * Initialize architecture specific code.
1102 mono_arch_init (void)
1107 * Cleanup architecture specific code.
1110 mono_arch_cleanup (void)
1114 /*------------------------------------------------------------------*/
1116 /* Name - mono_arch_cpu_optimizazions */
1118 /* Function - Returns the optimizations supported on this CPU */
1120 /*------------------------------------------------------------------*/
1123 mono_arch_cpu_optimizazions (guint32
*exclude_mask
)
1127 /*----------------------------------------------------------*/
1128 /* no s390-specific optimizations yet */
1129 /*----------------------------------------------------------*/
1130 *exclude_mask
= MONO_OPT_INLINE
|MONO_OPT_LINEARS
;
1131 // *exclude_mask = MONO_OPT_INLINE;
1135 /*========================= End of Function ========================*/
1137 /*------------------------------------------------------------------*/
1143 /*------------------------------------------------------------------*/
1146 is_regsize_var (MonoType
*t
) {
1149 switch (mono_type_get_underlying_type (t
)->type
) {
1155 case MONO_TYPE_FNPTR
:
1157 case MONO_TYPE_OBJECT
:
1158 case MONO_TYPE_STRING
:
1159 case MONO_TYPE_CLASS
:
1160 case MONO_TYPE_SZARRAY
:
1161 case MONO_TYPE_ARRAY
:
1163 case MONO_TYPE_VALUETYPE
:
1164 if (t
->data
.klass
->enumtype
)
1165 return is_regsize_var (mono_class_enum_basetype (t
->data
.klass
));
1171 /*========================= End of Function ========================*/
1173 /*------------------------------------------------------------------*/
1175 /* Name - mono_arch_get_allocatable_int_vars */
1179 /*------------------------------------------------------------------*/
1182 mono_arch_get_allocatable_int_vars (MonoCompile
*cfg
)
1187 for (i
= 0; i
< cfg
->num_varinfo
; i
++) {
1188 MonoInst
*ins
= cfg
->varinfo
[i
];
1189 MonoMethodVar
*vmv
= MONO_VARINFO (cfg
, i
);
1192 if (vmv
->range
.first_use
.abs_pos
>= vmv
->range
.last_use
.abs_pos
)
1195 if (ins
->flags
& (MONO_INST_VOLATILE
|MONO_INST_INDIRECT
) ||
1196 (ins
->opcode
!= OP_LOCAL
&& ins
->opcode
!= OP_ARG
))
1199 /* we can only allocate 32 bit values */
1200 if (is_regsize_var (ins
->inst_vtype
)) {
1201 g_assert (MONO_VARINFO (cfg
, i
)->reg
== -1);
1202 g_assert (i
== vmv
->idx
);
1203 vars
= mono_varlist_insert_sorted (cfg
, vars
, vmv
, FALSE
);
1210 /*========================= End of Function ========================*/
1212 /*------------------------------------------------------------------*/
1214 /* Name - mono_arch_global_int_regs */
1216 /* Function - Return a list of usable integer registers. */
1218 /*------------------------------------------------------------------*/
1221 mono_arch_get_global_int_regs (MonoCompile
*cfg
)
1224 MonoMethodHeader
*header
;
1227 header
= mono_method_get_header (cfg
->method
);
1228 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1229 cfg
->frame_reg
= s390_r11
;
1231 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1233 for (i
= 8; i
< top
; ++i
) {
1234 if (cfg
->frame_reg
!= i
)
1235 regs
= g_list_prepend (regs
, GUINT_TO_POINTER (i
));
1241 /*========================= End of Function ========================*/
1243 /*------------------------------------------------------------------*/
1245 /* Name - mono_arch_flush_icache */
1247 /* Function - Flush the CPU icache. */
1249 /*------------------------------------------------------------------*/
1252 mono_arch_flush_icache (guint8
*code
, gint size
)
1256 /*========================= End of Function ========================*/
1258 /*------------------------------------------------------------------*/
1260 /* Name - mono_arch_is_inst_imm */
1262 /*------------------------------------------------------------------*/
1265 mono_arch_is_inst_imm (gint64 imm
)
1267 /* The lowering pass will take care of it */
1271 /*========================= End of Function ========================*/
1273 /*------------------------------------------------------------------*/
1275 /* Name - add_general */
1277 /* Function - Determine code and stack size incremements for a */
1280 /*------------------------------------------------------------------*/
1283 add_general (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gboolean simple
)
1288 if (*gr
> S390_LAST_ARG_REG
) {
1289 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1290 ainfo
->offset
= sz
->stack_size
;
1291 ainfo
->reg
= STK_BASE
;
1292 ainfo
->regtype
= RegTypeBase
;
1293 sz
->stack_size
+= sizeof(int);
1294 sz
->local_size
+= sizeof(int);
1295 sz
->offStruct
+= sizeof(int);
1296 sz
->code_size
+= 12;
1302 if (*gr
> S390_LAST_ARG_REG
- 1) {
1303 disp
= sz
->stack_size
;
1304 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, S390_STACK_ALIGNMENT
);
1305 disp
= sz
->stack_size
- disp
;
1306 ainfo
->offset
= sz
->stack_size
;
1307 ainfo
->reg
= STK_BASE
;
1308 ainfo
->regtype
= RegTypeBase
;
1309 sz
->stack_size
+= sizeof(long long);
1310 sz
->local_size
+= (sizeof(long long) + disp
);
1311 sz
->offStruct
+= (sizeof(long long) + disp
);
1312 sz
->code_size
+= 10;
1322 /*========================= End of Function ========================*/
1324 /*------------------------------------------------------------------*/
1326 /* Name - add_stackParm */
1328 /* Function - Determine code and stack size incremements for a */
1331 /*------------------------------------------------------------------*/
1334 add_stackParm (guint
*gr
, size_data
*sz
, ArgInfo
*ainfo
, gint size
)
1336 if (*gr
> S390_LAST_ARG_REG
) {
1337 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1338 ainfo
->reg
= STK_BASE
;
1339 ainfo
->offset
= sz
->stack_size
;
1340 sz
->stack_size
+= sizeof (gpointer
);
1341 sz
->parm_size
+= sizeof(gpointer
);
1342 sz
->offStruct
+= sizeof(gpointer
);
1345 ainfo
->offset
= sz
->stack_size
;
1348 ainfo
->offparm
= sz
->offset
;
1349 sz
->offset
= S390_ALIGN(sz
->offset
+size
, sizeof(long));
1351 ainfo
->regtype
= RegTypeStructByAddr
;
1352 ainfo
->vtsize
= size
;
1353 sz
->parm_size
+= size
;
1356 /*========================= End of Function ========================*/
1358 /*------------------------------------------------------------------*/
1360 /* Name - add_float */
1362 /* Function - Determine code and stack size incremements for a */
1363 /* float parameter. */
1365 /*------------------------------------------------------------------*/
1368 add_float (guint
*fr
, size_data
*sz
, ArgInfo
*ainfo
)
1370 if ((*fr
) <= S390_LAST_FPARG_REG
) {
1371 ainfo
->regtype
= RegTypeFP
;
1377 ainfo
->offset
= sz
->stack_size
;
1378 ainfo
->reg
= STK_BASE
;
1379 ainfo
->regtype
= RegTypeBase
;
1381 sz
->stack_size
+= ainfo
->size
;
1382 sz
->local_size
+= ainfo
->size
;
1383 sz
->offStruct
+= ainfo
->size
;
1387 /*========================= End of Function ========================*/
1389 /*------------------------------------------------------------------*/
1391 /* Name - get_call_info */
1393 /* Function - Determine the amount of space required for code */
1394 /* and stack. In addition determine starting points */
1395 /* for stack-based parameters, and area for struct- */
1396 /* ures being returned on the stack. */
1398 /*------------------------------------------------------------------*/
1401 get_call_info (MonoCompile
*cfg
, MonoMemPool
*mp
, MonoMethodSignature
*sig
, gboolean is_pinvoke
)
1403 guint i
, fr
, gr
, size
;
1404 int nParm
= sig
->hasthis
+ sig
->param_count
;
1406 guint32 simpletype
, align
;
1409 MonoGenericSharingContext
*gsctx
= cfg
? cfg
->generic_sharing_context
: NULL
;
1412 cinfo
= mono_mempool_alloc0 (mp
, sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1414 cinfo
= g_malloc0 (sizeof (CallInfo
) + sizeof (ArgInfo
) * nParm
);
1419 cinfo
->struct_ret
= 0;
1422 sz
->offStruct
= S390_MINIMAL_STACK_SIZE
;
1424 sz
->stack_size
= S390_MINIMAL_STACK_SIZE
;
1429 /*----------------------------------------------------------*/
1430 /* We determine the size of the return code/stack in case we*/
1431 /* need to reserve a register to be used to address a stack */
1432 /* area that the callee will use. */
1433 /*----------------------------------------------------------*/
1435 ret_type
= mono_type_get_underlying_type (sig
->ret
);
1436 ret_type
= mini_get_basic_type_from_generic (gsctx
, ret_type
);
1437 simpletype
= ret_type
->type
;
1439 switch (simpletype
) {
1440 case MONO_TYPE_BOOLEAN
:
1445 case MONO_TYPE_CHAR
:
1450 case MONO_TYPE_CLASS
:
1451 case MONO_TYPE_OBJECT
:
1452 case MONO_TYPE_SZARRAY
:
1453 case MONO_TYPE_ARRAY
:
1455 case MONO_TYPE_FNPTR
:
1456 case MONO_TYPE_STRING
:
1457 cinfo
->ret
.reg
= s390_r2
;
1462 cinfo
->ret
.reg
= s390_f0
;
1467 cinfo
->ret
.reg
= s390_r2
;
1470 case MONO_TYPE_GENERICINST
:
1471 if (!mono_type_generic_inst_is_valuetype (sig
->ret
)) {
1472 cinfo
->ret
.reg
= s390_r2
;
1477 case MONO_TYPE_VALUETYPE
: {
1478 MonoClass
*klass
= mono_class_from_mono_type (sig
->ret
);
1479 if (klass
->enumtype
) {
1480 simpletype
= mono_class_enum_basetype (klass
)->type
;
1484 size
= mono_class_native_size (klass
, &align
);
1486 size
= mono_class_value_size (klass
, &align
);
1488 cinfo
->ret
.reg
= s390_r2
;
1489 cinfo
->struct_ret
= 1;
1490 cinfo
->ret
.size
= size
;
1491 cinfo
->ret
.vtsize
= size
;
1495 case MONO_TYPE_TYPEDBYREF
:
1496 size
= sizeof (MonoTypedRef
);
1497 cinfo
->ret
.reg
= s390_r2
;
1498 cinfo
->struct_ret
= 1;
1499 cinfo
->ret
.size
= size
;
1500 cinfo
->ret
.vtsize
= size
;
1503 case MONO_TYPE_VOID
:
1506 g_error ("mini-s390: cannot handle as return value 0x%x (0x%x)", sig
->ret
->type
,simpletype
);
1510 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1511 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1515 /*----------------------------------------------------------*/
1516 /* We determine the size of the parameter code and stack */
1517 /* requirements by checking the types and sizes of the */
1519 /*----------------------------------------------------------*/
1521 for (i
= 0; i
< sig
->param_count
; ++i
) {
1524 /*--------------------------------------------------*/
1525 /* Handle vararg type calls. All args are put on */
1527 /*--------------------------------------------------*/
1528 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1529 (i
== sig
->sentinelpos
)) {
1530 gr
= S390_LAST_ARG_REG
+ 1;
1531 add_general (&gr
, sz
, &cinfo
->sigCookie
, TRUE
);
1534 if (sig
->params
[i
]->byref
) {
1535 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1536 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1541 ptype
= mono_type_get_underlying_type (sig
->params
[i
]);
1542 ptype
= mini_get_basic_type_from_generic (gsctx
, ptype
);
1543 simpletype
= ptype
->type
;
1544 switch (simpletype
) {
1545 case MONO_TYPE_BOOLEAN
:
1548 cinfo
->args
[nParm
].size
= sizeof(char);
1549 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1554 case MONO_TYPE_CHAR
:
1555 cinfo
->args
[nParm
].size
= sizeof(short);
1556 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1561 cinfo
->args
[nParm
].size
= sizeof(int);
1562 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1568 case MONO_TYPE_FNPTR
:
1569 case MONO_TYPE_CLASS
:
1570 case MONO_TYPE_OBJECT
:
1571 case MONO_TYPE_STRING
:
1572 case MONO_TYPE_SZARRAY
:
1573 case MONO_TYPE_ARRAY
:
1574 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1575 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1580 cinfo
->args
[nParm
].size
= sizeof(long long);
1581 add_general (&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1585 cinfo
->args
[nParm
].size
= sizeof(float);
1586 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1590 cinfo
->args
[nParm
].size
= sizeof(double);
1591 add_float (&fr
, sz
, cinfo
->args
+nParm
);
1594 case MONO_TYPE_GENERICINST
:
1595 if (!mono_type_generic_inst_is_valuetype (sig
->params
[i
])) {
1596 cinfo
->args
[nParm
].size
= sizeof(gpointer
);
1597 add_general (&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1602 case MONO_TYPE_VALUETYPE
: {
1603 MonoMarshalType
*info
;
1604 MonoClass
*klass
= mono_class_from_mono_type (sig
->params
[i
]);
1606 size
= mono_class_native_size (klass
, &align
);
1608 size
= mono_class_value_size (klass
, &align
);
1610 info
= mono_marshal_load_type_info (klass
);
1612 if ((info
->native_size
== sizeof(float)) &&
1613 (info
->num_fields
== 1) &&
1614 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R4
)) {
1615 cinfo
->args
[nParm
].size
= sizeof(float);
1616 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1621 if ((info
->native_size
== sizeof(double)) &&
1622 (info
->num_fields
== 1) &&
1623 (info
->fields
[0].field
->type
->type
== MONO_TYPE_R8
)) {
1624 cinfo
->args
[nParm
].size
= sizeof(double);
1625 add_float(&fr
, sz
, cinfo
->args
+nParm
);
1630 cinfo
->args
[nParm
].vtsize
= 0;
1631 cinfo
->args
[nParm
].size
= 0;
1634 /*----------------------------------*/
1635 /* On S/390, structures of size 1, */
1636 /* 2, 4, and 8 bytes are passed in */
1637 /* (a) register(s). */
1638 /*----------------------------------*/
1643 add_general(&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1644 cinfo
->args
[nParm
].size
= size
;
1645 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1647 sz
->local_size
+= sizeof(long);
1650 add_general(&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1651 cinfo
->args
[nParm
].size
= sizeof(long long);
1652 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1654 sz
->local_size
+= sizeof(long long);
1657 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1662 case MONO_TYPE_TYPEDBYREF
: {
1663 int size
= sizeof (MonoTypedRef
);
1665 cinfo
->args
[nParm
].vtsize
= 0;
1666 cinfo
->args
[nParm
].size
= 0;
1669 /*----------------------------------*/
1670 /* On S/390, structures of size 1, */
1671 /* 2, 4, and 8 bytes are passed in */
1672 /* (a) register(s). */
1673 /*----------------------------------*/
1678 add_general(&gr
, sz
, cinfo
->args
+nParm
, TRUE
);
1679 cinfo
->args
[nParm
].size
= size
;
1680 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1682 sz
->local_size
+= sizeof(long);
1685 add_general(&gr
, sz
, cinfo
->args
+nParm
, FALSE
);
1686 cinfo
->args
[nParm
].size
= sizeof(long long);
1687 cinfo
->args
[nParm
].regtype
= RegTypeStructByVal
;
1689 sz
->local_size
+= sizeof(long long);
1692 add_stackParm(&gr
, sz
, cinfo
->args
+nParm
, size
);
1698 g_error ("Can't trampoline 0x%x", sig
->params
[i
]->type
);
1702 /*----------------------------------------------------------*/
1703 /* If we are passing a structure back then if it won't be */
1704 /* in a register(s) then we make room at the end of the */
1705 /* parameters that may have been placed on the stack */
1706 /*----------------------------------------------------------*/
1707 if (cinfo
->struct_ret
) {
1708 cinfo
->ret
.offset
= sz
->stack_size
;
1709 switch (cinfo
->ret
.size
) {
1717 sz
->stack_size
+= S390_ALIGN(cinfo
->ret
.size
, align
);
1721 /*----------------------------------------------------------*/
1722 /* Handle the case where there are no implicit arguments */
1723 /*----------------------------------------------------------*/
1724 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1725 (sig
->param_count
== sig
->sentinelpos
)) {
1726 gr
= S390_LAST_ARG_REG
+ 1;
1727 add_general (&gr
, sz
, &cinfo
->sigCookie
, TRUE
);
1731 sz
->stack_size
= sz
->stack_size
+ sz
->local_size
+ sz
->parm_size
+
1733 sz
->stack_size
= S390_ALIGN(sz
->stack_size
, sizeof(long));
1738 /*========================= End of Function ========================*/
1740 /*------------------------------------------------------------------*/
1742 /* Name - mono_arch_allocate_vars */
1744 /* Function - Set var information according to the calling */
1745 /* convention for S/390. The local var stuff should */
1746 /* most likely be split in another method. */
1748 /* Parameter - @m - Compile unit. */
1750 /*------------------------------------------------------------------*/
1753 mono_arch_allocate_vars (MonoCompile
*cfg
)
1755 MonoMethodSignature
*sig
;
1756 MonoMethodHeader
*header
;
1759 int iParm
, iVar
, offset
, size
, align
, curinst
;
1760 int frame_reg
= STK_BASE
;
1763 header
= mono_method_get_header (cfg
->method
);
1765 cfg
->flags
|= MONO_CFG_HAS_SPILLUP
;
1767 sig
= mono_method_signature (cfg
->method
);
1769 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1771 /*---------------------------------------------------------*/
1772 /* We use the frame register also for any method that has */
1773 /* filter clauses. This way, when the handlers are called, */
1774 /* the code will reference local variables using the frame */
1775 /* reg instead of the stack pointer: if we had to restore */
1776 /* the stack pointer, we'd corrupt the method frames that */
1777 /* are already on the stack (since filters get called */
1778 /* before stack unwinding happens) when the filter code */
1779 /* would call any method. */
1780 /*---------------------------------------------------------*/
1781 if ((cfg
->flags
& MONO_CFG_HAS_ALLOCA
) || header
->num_clauses
)
1782 frame_reg
= s390_r11
;
1784 cfg
->frame_reg
= frame_reg
;
1786 cfg
->arch
.bkchain_reg
= -1;
1788 if (frame_reg
!= STK_BASE
)
1789 cfg
->used_int_regs
|= 1 << frame_reg
;
1791 sig
= mono_method_signature (cfg
->method
);
1793 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1795 if (!cinfo
->struct_ret
) {
1796 switch (mono_type_get_underlying_type (sig
->ret
)->type
) {
1797 case MONO_TYPE_VOID
:
1800 cfg
->ret
->opcode
= OP_REGVAR
;
1801 cfg
->ret
->dreg
= s390_r2
;
1806 /*--------------------------------------------------------------*/
1807 /* local vars are at a positive offset from the stack pointer */
1808 /* also note that if the function uses alloca, we use s390_r11 */
1809 /* to point at the local variables. */
1810 /* add parameter area size for called functions */
1811 /*--------------------------------------------------------------*/
1812 offset
= (cfg
->param_area
+ S390_MINIMAL_STACK_SIZE
);
1813 cfg
->sig_cookie
= 0;
1815 if (cinfo
->struct_ret
) {
1816 inst
= cfg
->vret_addr
;
1817 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1818 inst
->inst_offset
= offset
;
1819 inst
->opcode
= OP_REGOFFSET
;
1820 inst
->inst_basereg
= frame_reg
;
1821 offset
+= sizeof(gpointer
);
1822 if (G_UNLIKELY (cfg
->verbose_level
> 1)) {
1823 printf ("vret_addr =");
1824 mono_print_ins (cfg
->vret_addr
);
1829 inst
= cfg
->args
[0];
1830 if (inst
->opcode
!= OP_REGVAR
) {
1831 inst
->opcode
= OP_REGOFFSET
;
1832 inst
->inst_basereg
= frame_reg
;
1833 offset
= S390_ALIGN(offset
, sizeof(gpointer
));
1834 inst
->inst_offset
= offset
;
1835 offset
+= sizeof (gpointer
);
1842 eArg
= sig
->param_count
+ sArg
;
1844 if (sig
->call_convention
== MONO_CALL_VARARG
)
1845 cfg
->sig_cookie
+= S390_MINIMAL_STACK_SIZE
;
1847 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1848 inst
= cfg
->args
[curinst
];
1849 if (inst
->opcode
!= OP_REGVAR
) {
1850 switch (cinfo
->args
[iParm
].regtype
) {
1851 case RegTypeStructByAddr
: {
1854 size
= sizeof (gpointer
);
1856 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1857 cfg
->arch
.bkchain_reg
= s390_r12
;
1858 cfg
->used_int_regs
|= 1 << cfg
->arch
.bkchain_reg
;
1860 inst
->opcode
= OP_REGOFFSET
;
1861 inst
->inst_basereg
= cfg
->arch
.bkchain_reg
;
1862 inst
->inst_offset
= cinfo
->args
[iParm
].offset
;
1864 inst
->opcode
= OP_REGOFFSET
;
1865 inst
->inst_basereg
= frame_reg
;
1866 inst
->inst_offset
= S390_ALIGN(offset
, sizeof (gpointer
));
1869 /* Add a level of indirection */
1870 MONO_INST_NEW (cfg
, indir
, 0);
1872 inst
->opcode
= OP_VTARG_ADDR
;
1873 inst
->inst_left
= indir
;
1876 case RegTypeStructByVal
:
1877 size
= cinfo
->args
[iParm
].size
;
1878 offset
= S390_ALIGN(offset
, size
);
1879 inst
->opcode
= OP_REGOFFSET
;
1880 inst
->inst_basereg
= frame_reg
;
1881 inst
->inst_offset
= S390_ALIGN (offset
, size
);
1884 if (cinfo
->args
[iParm
].reg
== STK_BASE
) {
1886 * These arguments are in the previous frame, so we can't
1887 * compute their offset from the current frame pointer right
1888 * now, since cfg->stack_offset is not yet known, so dedicate a
1889 * register holding the previous frame pointer.
1891 cfg
->arch
.bkchain_reg
= s390_r12
;
1892 cfg
->used_int_regs
|= 1 << cfg
->arch
.bkchain_reg
;
1894 inst
->opcode
= OP_REGOFFSET
;
1895 inst
->inst_basereg
= cfg
->arch
.bkchain_reg
;
1896 size
= (cinfo
->args
[iParm
].size
< 4
1897 ? 4 - cinfo
->args
[iParm
].size
1899 inst
->inst_offset
= cinfo
->args
[iParm
].offset
+ size
;
1900 size
= sizeof (long);
1902 inst
->opcode
= OP_REGOFFSET
;
1903 inst
->inst_basereg
= frame_reg
;
1904 size
= (cinfo
->args
[iParm
].size
< 8
1906 : sizeof(long long));
1907 offset
= S390_ALIGN(offset
, size
);
1908 inst
->inst_offset
= offset
;
1911 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
1912 (cinfo
->args
[iParm
].regtype
!= RegTypeGeneral
) &&
1913 (iParm
< sig
->sentinelpos
))
1914 cfg
->sig_cookie
+= size
;
1921 curinst
= cfg
->locals_start
;
1922 for (iVar
= curinst
; iVar
< cfg
->num_varinfo
; ++iVar
) {
1923 inst
= cfg
->varinfo
[iVar
];
1924 if ((inst
->flags
& MONO_INST_IS_DEAD
) ||
1925 (inst
->opcode
== OP_REGVAR
))
1928 /*--------------------------------------------------*/
1929 /* inst->backend.is_pinvoke indicates native sized value types, */
1930 /* this is used by the pinvoke wrappers when they */
1931 /* call functions returning structure */
1932 /*--------------------------------------------------*/
1933 if (inst
->backend
.is_pinvoke
&& MONO_TYPE_ISSTRUCT (inst
->inst_vtype
))
1934 size
= mono_class_native_size (mono_class_from_mono_type(inst
->inst_vtype
), &align
);
1936 size
= mono_type_size (inst
->inst_vtype
, &align
);
1938 offset
= S390_ALIGN(offset
, align
);
1939 inst
->inst_offset
= offset
;
1940 inst
->opcode
= OP_REGOFFSET
;
1941 inst
->inst_basereg
= frame_reg
;
1943 DEBUG (g_print("allocating local %d to %ld\n", iVar
, inst
->inst_offset
));
1946 /*------------------------------------------------------*/
1947 /* Allow space for the trace method stack area if needed*/
1948 /*------------------------------------------------------*/
1949 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (cfg
->method
)) {
1950 offset
+= S390_TRACE_STACK_SIZE
;
1953 /*------------------------------------------------------*/
1954 /* Reserve space to save LMF and caller saved registers */
1955 /*------------------------------------------------------*/
1956 if (cfg
->method
->save_lmf
)
1957 offset
+= sizeof (MonoLMF
);
1959 /*------------------------------------------------------*/
1960 /* align the offset */
1961 /*------------------------------------------------------*/
1962 cfg
->stack_offset
= S390_ALIGN(offset
, S390_STACK_ALIGNMENT
);
1964 /* Fix up offsets for arguments whose value is in the parent frame */
1965 for (iParm
= sArg
; iParm
< eArg
; ++iParm
) {
1966 inst
= cfg
->args
[iParm
];
1968 if (inst
->opcode
== OP_S390_STKARG
) {
1969 inst
->opcode
= OP_REGOFFSET
;
1970 inst
->inst_offset
+= cfg
->stack_offset
;
1975 /*========================= End of Function ========================*/
1977 /*------------------------------------------------------------------*/
1979 /* Name - mono_arch_create_vars */
1981 /*------------------------------------------------------------------*/
1984 mono_arch_create_vars (MonoCompile
*cfg
)
1986 MonoMethodSignature
*sig
;
1989 sig
= mono_method_signature (cfg
->method
);
1991 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
1993 if (cinfo
->struct_ret
) {
1994 cfg
->vret_addr
= mono_compile_create_var (cfg
, &mono_defaults
.int_class
->byval_arg
, OP_ARG
);
1995 if (G_UNLIKELY (cfg
->verbose_level
> 1)) {
1996 printf ("vret_addr = ");
1997 mono_print_ins (cfg
->vret_addr
);
2002 /*========================= End of Function ========================*/
2005 add_outarg_reg2 (MonoCompile
*cfg
, MonoCallInst
*call
, ArgStorage storage
, int reg
, MonoInst
*tree
)
2010 case RegTypeGeneral
:
2011 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2012 ins
->dreg
= mono_alloc_ireg (cfg
);
2013 ins
->sreg1
= tree
->dreg
;
2014 MONO_ADD_INS (cfg
->cbb
, ins
);
2015 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, FALSE
);
2018 MONO_INST_NEW (cfg
, ins
, OP_FMOVE
);
2019 ins
->dreg
= mono_alloc_freg (cfg
);
2020 ins
->sreg1
= tree
->dreg
;
2021 MONO_ADD_INS (cfg
->cbb
, ins
);
2022 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, TRUE
);
2025 MONO_INST_NEW (cfg
, ins
, OP_S390_SETF4RET
);
2026 ins
->dreg
= mono_alloc_freg (cfg
);
2027 ins
->sreg1
= tree
->dreg
;
2028 MONO_ADD_INS (cfg
->cbb
, ins
);
2029 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, reg
, TRUE
);
2032 g_assert_not_reached ();
2037 emit_sig_cookie (MonoCompile
*cfg
, MonoCallInst
*call
, CallInfo
*cinfo
)
2039 MonoMethodSignature
*tmpSig
;
2042 cfg
->disable_aot
= TRUE
;
2044 /*----------------------------------------------------------*/
2045 /* mono_ArgIterator_Setup assumes the signature cookie is */
2046 /* passed first and all the arguments which were before it */
2047 /* passed on the stack after the signature. So compensate */
2048 /* by passing a different signature. */
2049 /*----------------------------------------------------------*/
2050 tmpSig
= mono_metadata_signature_dup (call
->signature
);
2051 tmpSig
->param_count
-= call
->signature
->sentinelpos
;
2052 tmpSig
->sentinelpos
= 0;
2053 if (tmpSig
->param_count
> 0)
2054 memcpy (tmpSig
->params
,
2055 call
->signature
->params
+ call
->signature
->sentinelpos
,
2056 tmpSig
->param_count
* sizeof(MonoType
*));
2058 MONO_INST_NEW (cfg
, sig_arg
, OP_ICONST
);
2059 sig_arg
->dreg
= mono_alloc_ireg (cfg
);
2060 sig_arg
->inst_p0
= tmpSig
;
2061 MONO_ADD_INS (cfg
->cbb
, sig_arg
);
2063 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORE_MEMBASE_REG
, STK_BASE
,
2064 cinfo
->sigCookie
.offset
, sig_arg
->dreg
);
2067 /*------------------------------------------------------------------*/
2069 /* Name - mono_arch_emit_call */
2071 /*------------------------------------------------------------------*/
2074 mono_arch_emit_call (MonoCompile
*cfg
, MonoCallInst
*call
)
2077 MonoMethodSignature
*sig
;
2079 int i
, n
, lParamArea
;
2081 ArgInfo
*ainfo
= NULL
;
2084 sig
= call
->signature
;
2085 n
= sig
->param_count
+ sig
->hasthis
;
2086 DEBUG (g_print ("Call requires: %d parameters\n",n
));
2088 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
2090 stackSize
= cinfo
->sz
.stack_size
+ cinfo
->sz
.local_size
+ cinfo
->sz
.parm_size
+ cinfo
->sz
.offset
;
2091 call
->stack_usage
= MAX(stackSize
, call
->stack_usage
);
2092 lParamArea
= MAX((call
->stack_usage
-S390_MINIMAL_STACK_SIZE
-cinfo
->sz
.parm_size
), 0);
2093 cfg
->param_area
= MAX(((signed) cfg
->param_area
), lParamArea
);
2094 cfg
->flags
|= MONO_CFG_HAS_CALLS
;
2096 if (cinfo
->struct_ret
) {
2097 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2098 ins
->sreg1
= call
->vret_var
->dreg
;
2099 ins
->dreg
= mono_alloc_preg (cfg
);
2100 MONO_ADD_INS (cfg
->cbb
, ins
);
2101 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, cinfo
->ret
.reg
, FALSE
);
2104 for (i
= 0; i
< n
; ++i
) {
2105 ainfo
= cinfo
->args
+ i
;
2108 if (i
>= sig
->hasthis
)
2109 t
= sig
->params
[i
- sig
->hasthis
];
2111 t
= &mono_defaults
.int_class
->byval_arg
;
2112 t
= mono_type_get_underlying_type (t
);
2114 in
= call
->args
[i
];
2116 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
2117 (i
== sig
->sentinelpos
)) {
2118 emit_sig_cookie (cfg
, call
, cinfo
);
2121 switch (ainfo
->regtype
) {
2122 case RegTypeGeneral
:
2123 if (!t
->byref
&& (t
->type
== MONO_TYPE_I8
|| t
->type
== MONO_TYPE_U8
)) {
2124 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2125 ins
->dreg
= mono_alloc_ireg (cfg
);
2126 ins
->sreg1
= in
->dreg
+ 2;
2127 MONO_ADD_INS (cfg
->cbb
, ins
);
2128 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, ainfo
->reg
, FALSE
);
2129 MONO_INST_NEW (cfg
, ins
, OP_MOVE
);
2130 ins
->dreg
= mono_alloc_ireg (cfg
);
2131 ins
->sreg1
= in
->dreg
+ 1;
2132 MONO_ADD_INS (cfg
->cbb
, ins
);
2133 mono_call_inst_add_outarg_reg (cfg
, call
, ins
->dreg
, ainfo
->reg
+ 1, FALSE
);
2135 add_outarg_reg2 (cfg
, call
, ainfo
->regtype
, ainfo
->reg
, in
);
2139 if (MONO_TYPE_ISSTRUCT (t
)) {
2140 /* Valuetype passed in one fp register */
2141 ainfo
->regtype
= RegTypeStructByValInFP
;
2144 if (ainfo
->size
== 4)
2145 ainfo
->regtype
= RegTypeFPR4
;
2146 add_outarg_reg2 (cfg
, call
, ainfo
->regtype
, ainfo
->reg
, in
);
2149 case RegTypeStructByVal
:
2150 case RegTypeStructByAddr
: {
2154 if (sig
->params
[i
- sig
->hasthis
]->type
== MONO_TYPE_TYPEDBYREF
) {
2155 size
= sizeof (MonoTypedRef
);
2156 align
= sizeof (gpointer
);
2160 size
= mono_type_native_stack_size (&in
->klass
->byval_arg
, &align
);
2163 * Other backends use mono_type_stack_size (), but that
2164 * aligns the size to 8, which is larger than the size of
2165 * the source, leading to reads of invalid memory if the
2166 * source is at the end of address space.
2168 size
= mono_class_value_size (in
->klass
, &align
);
2171 g_assert (in
->klass
);
2173 ainfo
->offparm
+= cinfo
->sz
.offStruct
;
2175 MONO_INST_NEW (cfg
, ins
, OP_OUTARG_VT
);
2176 ins
->sreg1
= in
->dreg
;
2177 ins
->klass
= in
->klass
;
2178 ins
->backend
.size
= ainfo
->size
;
2179 ins
->inst_p0
= call
;
2180 ins
->inst_p1
= mono_mempool_alloc (cfg
->mempool
, sizeof (ArgInfo
));
2181 memcpy (ins
->inst_p1
, ainfo
, sizeof (ArgInfo
));
2183 MONO_ADD_INS (cfg
->cbb
, ins
);
2185 if (ainfo
->regtype
== RegTypeStructByAddr
) {
2187 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2188 * use the normal OUTARG opcodes to pass the address of the location to
2191 int treg
= mono_alloc_preg (cfg
);
2192 MONO_EMIT_NEW_BIALU_IMM (cfg
, OP_ADD_IMM
, treg
,
2193 STK_BASE
, ainfo
->offparm
);
2194 if (ainfo
->reg
== STK_BASE
) {
2195 /* The address is passed on the stack */
2196 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2197 ins
->inst_destbasereg
= STK_BASE
;
2198 ins
->inst_offset
= ainfo
->offset
;
2200 MONO_ADD_INS (cfg
->cbb
, ins
);
2202 mono_call_inst_add_outarg_reg (cfg
, call
, treg
, ainfo
->reg
, FALSE
);
2208 if (!t
->byref
&& t
->type
== MONO_TYPE_R4
) {
2209 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORER4_MEMBASE_REG
,
2210 STK_BASE
, ainfo
->offset
,
2212 } else if (!t
->byref
&& (t
->type
== MONO_TYPE_R8
)) {
2213 MONO_EMIT_NEW_STORE_MEMBASE (cfg
, OP_STORER8_MEMBASE_REG
,
2214 STK_BASE
, ainfo
->offset
,
2216 } else if (!t
->byref
&& (t
->type
== MONO_TYPE_I8
|| t
->type
== MONO_TYPE_U8
)) {
2217 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2218 ins
->inst_destbasereg
= STK_BASE
;
2219 ins
->inst_offset
= ainfo
->offset
+ MINI_LS_WORD_OFFSET
;
2220 ins
->sreg1
= in
->dreg
+ 1;
2221 MONO_ADD_INS (cfg
->cbb
, ins
);
2223 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2224 ins
->inst_destbasereg
= STK_BASE
;
2225 ins
->inst_offset
= ainfo
->offset
+ MINI_MS_WORD_OFFSET
;
2226 ins
->sreg1
= in
->dreg
+ 2;
2227 MONO_ADD_INS (cfg
->cbb
, ins
);
2229 MONO_INST_NEW (cfg
, ins
, OP_STORE_MEMBASE_REG
);
2230 ins
->inst_destbasereg
= STK_BASE
;
2231 ins
->inst_offset
= ainfo
->offset
;
2232 ins
->sreg1
= in
->dreg
;
2233 MONO_ADD_INS (cfg
->cbb
, ins
);
2237 g_assert_not_reached ();
2243 * Handle the case where there are no implicit arguments
2245 if ((sig
->call_convention
== MONO_CALL_VARARG
) &&
2246 (i
== sig
->sentinelpos
)) {
2247 emit_sig_cookie (cfg
, call
, cinfo
);
2251 /*========================= End of Function ========================*/
2253 /*------------------------------------------------------------------*/
2255 /* Name - mono_arch_emit_outarg_vt */
2257 /*------------------------------------------------------------------*/
2260 mono_arch_emit_outarg_vt (MonoCompile
*cfg
, MonoInst
*ins
, MonoInst
*src
)
2262 MonoCallInst
*call
= (MonoCallInst
*)ins
->inst_p0
;
2263 ArgInfo
*ainfo
= (ArgInfo
*)ins
->inst_p1
;
2264 int size
= ins
->backend
.size
;
2266 if (ainfo
->regtype
== RegTypeStructByVal
) {
2268 arg->ins.sreg1 = ainfo->reg;
2269 arg->ins.opcode = OP_OUTARG_VT;
2270 arg->size = ainfo->size;
2271 arg->offset = ainfo->offset;
2272 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2274 if (ainfo
->reg
!= STK_BASE
) {
2275 MONO_OUTPUT_VTR (cfg
, size
, ainfo
->reg
, src
->dreg
, 0);
2277 MONO_OUTPUT_VTS (cfg
, size
, ainfo
->reg
, ainfo
->offset
,
2280 } else if (ainfo
->regtype
== RegTypeStructByValInFP
) {
2281 int dreg
= mono_alloc_freg (cfg
);
2283 if (ainfo
->size
== 4) {
2284 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg
, OP_LOADR4_MEMBASE
, dreg
, src
->dreg
, 0);
2285 MONO_EMIT_NEW_UNALU (cfg
, OP_S390_SETF4RET
, dreg
, dreg
);
2287 g_assert (ainfo
->size
== 8);
2289 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg
, OP_LOADR8_MEMBASE
, dreg
, src
->dreg
, 0);
2292 mono_call_inst_add_outarg_reg (cfg
, call
, dreg
, ainfo
->reg
, TRUE
);
2294 MONO_EMIT_NEW_MOVE (cfg
, STK_BASE
, ainfo
->offparm
,
2295 src
->dreg
, 0, size
);
2299 /*------------------------------------------------------------------*/
2301 /* Name - mono_arch_emit_setret */
2303 /*------------------------------------------------------------------*/
2306 mono_arch_emit_setret (MonoCompile
*cfg
, MonoMethod
*method
, MonoInst
*val
)
2308 MonoType
*ret
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
);
2311 if (ret
->type
== MONO_TYPE_R4
) {
2312 MONO_EMIT_NEW_UNALU (cfg
, OP_S390_SETF4RET
, s390_f0
, val
->dreg
);
2314 } else if (ret
->type
== MONO_TYPE_R8
) {
2315 MONO_EMIT_NEW_UNALU (cfg
, OP_FMOVE
, s390_f0
, val
->dreg
);
2317 } else if (ret
->type
== MONO_TYPE_I8
|| ret
->type
== MONO_TYPE_U8
) {
2318 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r3
, val
->dreg
+ 1);
2319 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r2
, val
->dreg
+ 2);
2324 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, cfg
->ret
->dreg
, val
->dreg
);
2327 /*========================= End of Function ========================*/
2329 /*------------------------------------------------------------------*/
2331 /* Name - mono_arch_instrument_mem_needs */
2333 /* Function - Allow tracing to work with this interface (with */
2334 /* an optional argument). */
2336 /*------------------------------------------------------------------*/
2339 mono_arch_instrument_mem_needs (MonoMethod
*method
, int *stack
, int *code
)
2341 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2343 /* split prolog-epilog requirements? */
2344 *code
= 50; /* max bytes needed: check this number */
2347 /*========================= End of Function ========================*/
2349 /*------------------------------------------------------------------*/
2351 /* Name - mono_arch_instrument_prolog */
2353 /* Function - Create an "instrumented" prolog. */
2355 /*------------------------------------------------------------------*/
2358 mono_arch_instrument_prolog (MonoCompile
*cfg
, void *func
, void *p
,
2359 gboolean enable_arguments
)
2366 parmOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2367 if (cfg
->method
->save_lmf
)
2368 parmOffset
-= sizeof(MonoLMF
);
2369 fpOffset
= parmOffset
+ (5*sizeof(gint32
));
2370 if (fpOffset
> 4096) {
2371 s390_lr (code
, s390_r12
, STK_BASE
);
2373 while (fpOffset
> 4096) {
2374 s390_ahi (code
, baseReg
, 4096);
2382 s390_stm (code
, s390_r2
, s390_r6
, baseReg
, parmOffset
);
2383 s390_std (code
, s390_f0
, 0, baseReg
, fpOffset
);
2384 s390_std (code
, s390_f1
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2385 s390_std (code
, s390_f2
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2386 s390_basr (code
, s390_r13
, 0);
2388 s390_word (code
, cfg
->method
);
2389 s390_word (code
, func
);
2390 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
2391 s390_la (code
, s390_r3
, 0, baseReg
, parmOffset
);
2392 s390_lr (code
, s390_r4
, STK_BASE
);
2393 s390_ahi (code
, s390_r4
, cfg
->stack_usage
);
2394 s390_l (code
, s390_r1
, 0, s390_r13
, 8);
2395 s390_basr (code
, s390_r14
, s390_r1
);
2396 s390_ld (code
, s390_f2
, 0, baseReg
, fpOffset
+2*sizeof(gdouble
));
2397 s390_ld (code
, s390_f1
, 0, baseReg
, fpOffset
+sizeof(gdouble
));
2398 s390_ld (code
, s390_f0
, 0, baseReg
, fpOffset
);
2399 s390_lm (code
, s390_r2
, s390_r6
, baseReg
, parmOffset
);
2404 /*========================= End of Function ========================*/
2406 /*------------------------------------------------------------------*/
2408 /* Name - mono_arch_instrument_epilog */
2410 /* Function - Create an epilog that will handle the returned */
2411 /* values used in instrumentation. */
2413 /*------------------------------------------------------------------*/
2416 mono_arch_instrument_epilog (MonoCompile
*cfg
, void *func
, void *p
, gboolean enable_arguments
)
2419 int save_mode
= SAVE_NONE
,
2421 MonoMethod
*method
= cfg
->method
;
2422 int rtype
= mono_type_get_underlying_type (mono_method_signature (method
)->ret
)->type
;
2424 saveOffset
= cfg
->stack_usage
- S390_TRACE_STACK_SIZE
;
2425 if (method
->save_lmf
)
2426 saveOffset
-= sizeof(MonoLMF
);
2430 case MONO_TYPE_VOID
:
2431 /* special case string .ctor icall */
2432 if (strcmp (".ctor", method
->name
) && method
->klass
== mono_defaults
.string_class
)
2433 save_mode
= SAVE_ONE
;
2435 save_mode
= SAVE_NONE
;
2439 save_mode
= SAVE_TWO
;
2442 save_mode
= SAVE_R4
;
2445 save_mode
= SAVE_R8
;
2447 case MONO_TYPE_VALUETYPE
:
2448 if (mono_method_signature (method
)->ret
->data
.klass
->enumtype
) {
2449 rtype
= mono_class_enum_basetype (mono_method_signature (method
)->ret
->data
.klass
)->type
;
2452 save_mode
= SAVE_STRUCT
;
2455 save_mode
= SAVE_ONE
;
2459 switch (save_mode
) {
2461 s390_stm (code
, s390_r2
, s390_r3
, cfg
->frame_reg
, saveOffset
);
2462 if (enable_arguments
) {
2463 s390_lr (code
, s390_r4
, s390_r3
);
2464 s390_lr (code
, s390_r3
, s390_r2
);
2468 s390_st (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2469 if (enable_arguments
) {
2470 s390_lr (code
, s390_r3
, s390_r2
);
2474 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2475 if (enable_arguments
) {
2476 s390_ldebr (code
, s390_f0
, s390_f0
);
2480 s390_std (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2483 s390_st (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2484 if (enable_arguments
) {
2485 s390_l (code
, s390_r3
, 0, cfg
->frame_reg
,
2486 S390_MINIMAL_STACK_SIZE
+cfg
->param_area
);
2494 s390_basr (code
, s390_r13
, 0);
2496 s390_word (code
, cfg
->method
);
2497 s390_word (code
, func
);
2498 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
2499 s390_l (code
, s390_r1
, 0, s390_r13
, 8);
2500 s390_basr (code
, s390_r14
, s390_r1
);
2502 switch (save_mode
) {
2504 s390_lm (code
, s390_r2
, s390_r3
, cfg
->frame_reg
, saveOffset
);
2507 s390_l (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2511 s390_ld (code
, s390_f0
, 0, cfg
->frame_reg
, saveOffset
);
2514 s390_l (code
, s390_r2
, 0, cfg
->frame_reg
, saveOffset
);
2524 /*========================= End of Function ========================*/
2527 mono_arch_peephole_pass_1 (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2531 /*------------------------------------------------------------------*/
2533 /* Name - mono_arch_peephole_pass */
2535 /* Function - Form a peephole pass at the code looking for */
2536 /* simple optimizations. */
2538 /*------------------------------------------------------------------*/
2541 mono_arch_peephole_pass_2 (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2545 MONO_BB_FOR_EACH_INS_SAFE (bb
, n
, ins
) {
2546 mono_peephole_ins (bb
, ins
);
2550 /*========================= End of Function ========================*/
2553 mono_arch_lowering_pass (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2555 MonoInst
*ins
, *next
;
2557 MONO_BB_FOR_EACH_INS_SAFE (bb
, next
, ins
) {
2558 switch (ins
->opcode
) {
2563 case OP_IDIV_UN_IMM
:
2564 case OP_IREM_UN_IMM
:
2565 case OP_LOCALLOC_IMM
:
2566 mono_decompose_op_imm (cfg
, bb
, ins
);
2573 bb
->max_vreg
= cfg
->next_vreg
;
2576 /*========================= End of Function ========================*/
2578 /*------------------------------------------------------------------*/
2580 /* Name - emit_float_to_int */
2582 /* Function - Create instructions which will convert a floating */
2583 /* point value to integer. */
2585 /*------------------------------------------------------------------*/
2588 emit_float_to_int (MonoCompile
*cfg
, guchar
*code
, int dreg
, int sreg
, int size
, gboolean is_signed
)
2590 /* sreg is a float, dreg is an integer reg. */
2592 s390_cfdbr (code
, dreg
, 5, sreg
);
2595 s390_lhi (code
, s390_r0
, 0);
2596 s390_lhi (code
, s390_r13
, 0xff);
2597 s390_ltr (code
, dreg
, dreg
);
2599 s390_lhi (code
, s390_r0
, 0x80);
2600 s390_nr (code
, dreg
, s390_r13
);
2601 s390_or (code
, dreg
, s390_r0
);
2606 s390_basr (code
, s390_r13
, 0);
2608 s390_llong (code
, 0x41e0000000000000LL
);
2609 s390_llong (code
, 0x41f0000000000000LL
);
2610 s390_ldr (code
, s390_f15
, sreg
);
2611 s390_cdb (code
, s390_f15
, 0, s390_r13
, 4);
2612 s390_jl (code
, 0); CODEPTR(code
, o
[0]);
2613 s390_sdb (code
, s390_f15
, 0, s390_r13
, 12);
2614 s390_cfdbr (code
, dreg
, 7, s390_f15
);
2616 PTRSLOT(code
, o
[0]);
2617 s390_cfdbr (code
, dreg
, 5, sreg
);
2620 s390_lhi (code
, s390_r0
, 0xff);
2621 s390_nr (code
, dreg
, s390_r0
);
2624 s390_lhi (code
, s390_r0
, -1);
2625 s390_srl (code
, s390_r0
, 0, 16);
2626 s390_nr (code
, dreg
, s390_r0
);
2633 /*========================= End of Function ========================*/
2635 /*------------------------------------------------------------------*/
2637 /* Name - mono_arch_output_basic_block */
2639 /* Function - Perform the "real" work of emitting instructions */
2640 /* that will do the work of in the basic block. */
2642 /*------------------------------------------------------------------*/
2645 mono_arch_output_basic_block (MonoCompile
*cfg
, MonoBasicBlock
*bb
)
2650 guint8
*code
= cfg
->native_code
+ cfg
->code_len
;
2651 MonoInst
*last_ins
= NULL
;
2652 guint last_offset
= 0;
2653 int max_len
, cpos
, src2
;
2655 /* we don't align basic blocks of loops on s390 */
2657 if (cfg
->verbose_level
> 2)
2658 g_print ("Basic block %d starting at offset 0x%x\n", bb
->block_num
, bb
->native_offset
);
2660 cpos
= bb
->max_offset
;
2662 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
) {
2663 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2664 //g_assert (!mono_compile_aot);
2667 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2668 /* this is not thread save, but good enough */
2669 /* fixme: howto handle overflows? */
2670 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2673 MONO_BB_FOR_EACH_INS (bb
, ins
) {
2674 offset
= code
- cfg
->native_code
;
2676 max_len
= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
2678 if (offset
> (cfg
->code_size
- max_len
- 16)) {
2679 cfg
->code_size
*= 2;
2680 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
2681 code
= cfg
->native_code
+ offset
;
2684 mono_debug_record_line_number (cfg
, ins
, offset
);
2686 switch (ins
->opcode
) {
2687 case OP_STOREI1_MEMBASE_IMM
: {
2688 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2689 if (s390_is_uimm12(ins
->inst_offset
))
2690 s390_stc (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2692 s390_basr (code
, s390_r13
, 0);
2694 s390_word (code
, ins
->inst_offset
);
2695 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2696 s390_stc (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2700 case OP_STOREI2_MEMBASE_IMM
: {
2701 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2702 if (s390_is_uimm12(ins
->inst_offset
)) {
2703 s390_sth (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2705 s390_basr (code
, s390_r13
, 0);
2707 s390_word (code
, ins
->inst_offset
);
2708 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2709 s390_sth (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2713 case OP_STORE_MEMBASE_IMM
:
2714 case OP_STOREI4_MEMBASE_IMM
: {
2715 if (s390_is_imm16(ins
->inst_imm
)) {
2716 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2718 s390_basr (code
, s390_r13
, 0);
2720 s390_word (code
, ins
->inst_imm
);
2721 s390_l (code
, s390_r0
, 0, s390_r13
, 4);
2723 if (s390_is_uimm12(ins
->inst_offset
)) {
2724 s390_st (code
, s390_r0
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2726 s390_basr (code
, s390_r13
, 0);
2728 s390_word (code
, ins
->inst_offset
);
2729 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2730 s390_st (code
, s390_r0
, s390_r13
, ins
->inst_destbasereg
, 0);
2734 case OP_STOREI1_MEMBASE_REG
: {
2735 if (s390_is_uimm12(ins
->inst_offset
)) {
2736 s390_stc (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2738 s390_basr (code
, s390_r13
, 0);
2740 s390_word (code
, ins
->inst_offset
);
2741 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2742 s390_stc (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2746 case OP_STOREI2_MEMBASE_REG
: {
2747 if (s390_is_uimm12(ins
->inst_offset
)) {
2748 s390_sth (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2750 s390_basr (code
, s390_r13
, 0);
2752 s390_word (code
, ins
->inst_offset
);
2753 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2754 s390_sth (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2758 case OP_STORE_MEMBASE_REG
:
2759 case OP_STOREI4_MEMBASE_REG
: {
2760 if (s390_is_uimm12(ins
->inst_offset
)) {
2761 s390_st (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
2763 s390_basr (code
, s390_r13
, 0);
2765 s390_word (code
, ins
->inst_offset
);
2766 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2767 s390_st (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
2772 g_assert_not_reached ();
2774 case OP_LOAD_MEMBASE
:
2775 case OP_LOADI4_MEMBASE
:
2776 case OP_LOADU4_MEMBASE
: {
2777 if (s390_is_uimm12(ins
->inst_offset
))
2778 s390_l (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2780 if (s390_is_imm16(ins
->inst_offset
)) {
2781 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
2782 s390_l (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
2784 s390_basr (code
, s390_r13
, 0);
2786 s390_word (code
, ins
->inst_offset
);
2787 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2788 s390_l (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
2793 case OP_LOADU1_MEMBASE
: {
2794 s390_lhi (code
, s390_r0
, 0);
2795 if (s390_is_uimm12(ins
->inst_offset
))
2796 s390_ic (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2798 s390_basr (code
, s390_r13
, 0);
2800 s390_word (code
, ins
->inst_offset
);
2801 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2802 s390_ic (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2804 s390_lr (code
, ins
->dreg
, s390_r0
);
2807 case OP_LOADI1_MEMBASE
: {
2808 s390_lhi (code
, s390_r0
, 0);
2809 if (s390_is_uimm12(ins
->inst_offset
))
2810 s390_ic (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2812 s390_basr (code
, s390_r13
, 0);
2814 s390_word (code
, ins
->inst_offset
);
2815 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2816 s390_ic (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2818 s390_lhi (code
, s390_r13
, 0x80);
2819 s390_nr (code
, s390_r13
, s390_r0
);
2821 s390_lhi (code
, s390_r13
, 0xff00);
2822 s390_or (code
, s390_r0
, s390_r13
);
2823 s390_lr (code
, ins
->dreg
, s390_r0
);
2826 case OP_LOADU2_MEMBASE
: {
2827 s390_lhi (code
, s390_r0
, 0);
2828 if (s390_is_uimm12(ins
->inst_offset
))
2829 s390_icm (code
, s390_r0
, 3, ins
->inst_basereg
, ins
->inst_offset
);
2831 s390_basr (code
, s390_r13
, 0);
2833 s390_word (code
, ins
->inst_offset
);
2834 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2835 s390_ar (code
, s390_r13
, ins
->inst_basereg
);
2836 s390_icm (code
, s390_r0
, 3, s390_r13
, 0);
2838 s390_lr (code
, ins
->dreg
, s390_r0
);
2841 case OP_LOADI2_MEMBASE
: {
2842 s390_lhi (code
, s390_r0
, 0);
2843 if (s390_is_uimm12(ins
->inst_offset
))
2844 s390_lh (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
2846 s390_basr (code
, s390_r13
, 0);
2848 s390_word (code
, ins
->inst_offset
);
2849 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
2850 s390_lh (code
, s390_r0
, s390_r13
, ins
->inst_basereg
, 0);
2852 s390_lr (code
, ins
->dreg
, s390_r0
);
2856 case OP_ICONV_TO_I1
: {
2857 if (ins
->dreg
!= ins
->sreg1
)
2858 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2859 s390_sll (code
, ins
->dreg
, 0, 24);
2860 s390_sra (code
, ins
->dreg
, 0, 24);
2863 case OP_ICONV_TO_I2
: {
2864 if (ins
->dreg
!= ins
->sreg1
)
2865 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2866 s390_sll (code
, ins
->dreg
, 0, 16);
2867 s390_sra (code
, ins
->dreg
, 0, 16);
2870 case OP_ICONV_TO_U1
: {
2871 s390_lhi (code
, s390_r0
, 0xff);
2872 if (ins
->dreg
!= ins
->sreg1
) {
2873 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2875 s390_nr (code
, ins
->dreg
, s390_r0
);
2878 case OP_ICONV_TO_U2
: {
2879 s390_lhi (code
, s390_r0
, -1);
2880 s390_sll (code
, s390_r0
, 0, 16);
2881 s390_srl (code
, s390_r0
, 0, 16);
2882 if (ins
->dreg
!= ins
->sreg1
) {
2883 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2885 s390_nr (code
, ins
->dreg
, s390_r0
);
2890 gboolean un
= FALSE
;
2891 MonoInst
*next
= ins
->next
;
2894 (((next
->opcode
>= OP_IBNE_UN
) &&
2895 (next
->opcode
<= OP_IBLT_UN
)) ||
2896 ((next
->opcode
>= OP_COND_EXC_NE_UN
) &&
2897 (next
->opcode
<= OP_COND_EXC_LT_UN
)) ||
2898 ((next
->opcode
>= OP_COND_EXC_INE_UN
) &&
2899 (next
->opcode
<= OP_COND_EXC_ILT_UN
)) ||
2900 ((next
->opcode
== OP_CLT_UN
) ||
2901 (next
->opcode
== OP_CGT_UN
)) ||
2902 ((next
->opcode
== OP_ICLT_UN
) ||
2903 (next
->opcode
== OP_ICGT_UN
))))
2907 s390_clr (code
, ins
->sreg1
, ins
->sreg2
);
2909 s390_cr (code
, ins
->sreg1
, ins
->sreg2
);
2912 case OP_COMPARE_IMM
:
2913 case OP_ICOMPARE_IMM
: {
2914 gboolean un
= FALSE
;
2915 MonoInst
*next
= ins
->next
;
2918 (((next
->opcode
>= OP_IBNE_UN
) &&
2919 (next
->opcode
<= OP_IBLT_UN
)) ||
2920 ((next
->opcode
>= OP_COND_EXC_NE_UN
) &&
2921 (next
->opcode
<= OP_COND_EXC_LT_UN
)) ||
2922 ((next
->opcode
>= OP_COND_EXC_INE_UN
) &&
2923 (next
->opcode
<= OP_COND_EXC_ILT_UN
)) ||
2924 ((next
->opcode
== OP_CLT_UN
) ||
2925 (next
->opcode
== OP_CGT_UN
)) ||
2926 ((next
->opcode
== OP_ICLT_UN
) ||
2927 (next
->opcode
== OP_ICGT_UN
))))
2930 if (s390_is_imm16 (ins
->inst_imm
)) {
2931 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
2933 s390_clr (code
, ins
->sreg1
, s390_r0
);
2935 s390_cr (code
, ins
->sreg1
, s390_r0
);
2938 s390_basr (code
, s390_r13
, 0);
2940 s390_word (code
, ins
->inst_imm
);
2942 s390_cl (code
, ins
->sreg1
, 0, s390_r13
, 4);
2944 s390_c (code
, ins
->sreg1
, 0, s390_r13
, 4);
2949 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
, mono_break
);
2950 s390_brasl (code
, s390_r14
, 0);
2956 s390_alr (code
, ins
->dreg
, src2
);
2961 s390_ar (code
, ins
->dreg
, src2
);
2967 s390_alcr (code
, ins
->dreg
, src2
);
2972 if (ins
->dreg
!= ins
->sreg1
) {
2973 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
2976 (ins
->next
->opcode
== OP_ADC_IMM
)) {
2977 s390_basr (code
, s390_r13
, 0);
2979 s390_word (code
, ins
->inst_imm
);
2980 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
2982 if (s390_is_imm16 (ins
->inst_imm
)) {
2983 s390_ahi (code
, ins
->dreg
, ins
->inst_imm
);
2985 s390_basr (code
, s390_r13
, 0);
2987 s390_word (code
, ins
->inst_imm
);
2988 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
2993 case OP_ADDCC_IMM
: {
2995 (ins
->next
->opcode
== OP_ADC_IMM
)) {
2996 s390_basr (code
, s390_r13
, 0);
2998 s390_word (code
, ins
->inst_imm
);
2999 if (ins
->dreg
!= ins
->sreg1
) {
3000 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3002 s390_al (code
, ins
->dreg
, 0, s390_r13
, 4);
3004 if (s390_is_imm16 (ins
->inst_imm
)) {
3005 if (ins
->dreg
!= ins
->sreg1
) {
3006 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3008 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3009 s390_alcr (code
, ins
->dreg
, s390_r0
);
3011 s390_basr (code
, s390_r13
, 0);
3013 s390_word (code
, ins
->inst_imm
);
3014 if (ins
->dreg
!= ins
->sreg1
) {
3015 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3017 s390_al (code
, ins
->dreg
, 0, s390_r13
, 4);
3023 if (s390_is_imm16 (ins
->inst_imm
)) {
3024 if (ins
->dreg
!= ins
->sreg1
) {
3025 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3027 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3028 s390_alcr (code
, ins
->dreg
, s390_r0
);
3030 s390_basr (code
, s390_r13
, 0);
3032 s390_word (code
, ins
->inst_imm
);
3033 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3034 s390_alcr (code
, ins
->dreg
, s390_r13
);
3039 case OP_S390_IADD_OVF
: {
3041 s390_ar (code
, ins
->dreg
, src2
);
3042 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3045 case OP_IADD_OVF_UN
:
3046 case OP_S390_IADD_OVF_UN
: {
3048 s390_alr (code
, ins
->dreg
, src2
);
3049 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3053 case OP_S390_LADD
: {
3054 s390_alr (code
, s390_r0
, ins
->sreg1
);
3056 s390_ahi (code
, s390_r1
, 1);
3057 s390_ar (code
, s390_r1
, ins
->sreg2
);
3058 s390_lr (code
, ins
->dreg
, s390_r0
);
3059 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3063 case OP_S390_LADD_OVF
: {
3065 s390_alr (code
, s390_r0
, ins
->sreg1
);
3066 s390_jnc (code
, 0); CODEPTR(code
, o
[0]);
3067 s390_ahi (code
, s390_r1
, 1);
3068 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3069 PTRSLOT (code
, o
[0]);
3070 s390_ar (code
, s390_r1
, ins
->sreg2
);
3071 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3072 s390_lr (code
, ins
->dreg
, s390_r0
);
3073 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3076 case OP_LADD_OVF_UN
:
3077 case OP_S390_LADD_OVF_UN
: {
3078 s390_alr (code
, s390_r0
, ins
->sreg1
);
3079 s390_alcr (code
, s390_r1
, ins
->sreg2
);
3080 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3081 s390_lr (code
, ins
->dreg
, s390_r0
);
3082 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3085 case OP_ADD_OVF_CARRY
: {
3087 s390_lhi (code
, s390_r0
, 0);
3088 s390_lr (code
, s390_r1
, s390_r0
);
3089 s390_alcr (code
, s390_r0
, s390_r1
);
3090 s390_ar (code
, ins
->dreg
, src2
);
3091 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3092 s390_ar (code
, ins
->dreg
, s390_r0
);
3093 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3096 case OP_ADD_OVF_UN_CARRY
: {
3098 s390_alcr (code
, ins
->dreg
, src2
);
3099 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, "OverflowException");
3105 s390_slr (code
, ins
->dreg
, src2
);
3110 s390_sr (code
, ins
->dreg
, src2
);
3116 s390_slbr (code
, ins
->dreg
, src2
);
3119 case OP_SUBCC_IMM
: {
3120 if (s390_is_imm16 (-ins
->inst_imm
)) {
3121 if (ins
->dreg
!= ins
->sreg1
) {
3122 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3124 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3125 s390_slr (code
, ins
->dreg
, s390_r0
);
3127 s390_basr (code
, s390_r13
, 0);
3129 s390_word (code
, ins
->inst_imm
);
3130 if (ins
->dreg
!= ins
->sreg1
) {
3131 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3133 s390_sl (code
, ins
->dreg
, 0, s390_r13
, 4);
3139 if (s390_is_imm16 (-ins
->inst_imm
)) {
3140 if (ins
->dreg
!= ins
->sreg1
) {
3141 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3143 s390_ahi (code
, ins
->dreg
, -ins
->inst_imm
);
3145 s390_basr (code
, s390_r13
, 0);
3147 s390_word (code
, ins
->inst_imm
);
3148 if (ins
->dreg
!= ins
->sreg1
) {
3149 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3151 s390_s (code
, ins
->dreg
, 0, s390_r13
, 4);
3156 if (ins
->dreg
!= ins
->sreg1
) {
3157 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3159 if (s390_is_imm16 (-ins
->inst_imm
)) {
3160 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3161 s390_slbr (code
, ins
->dreg
, s390_r0
);
3163 s390_basr (code
, s390_r13
, 0);
3165 s390_word (code
, ins
->inst_imm
);
3166 s390_slb (code
, ins
->dreg
, 0, s390_r13
, 4);
3171 case OP_S390_ISUB_OVF
: {
3173 s390_sr (code
, ins
->dreg
, src2
);
3174 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3177 case OP_ISUB_OVF_UN
:
3178 case OP_S390_ISUB_OVF_UN
: {
3180 s390_slr (code
, ins
->dreg
, src2
);
3181 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3185 case OP_S390_LSUB
: {
3186 s390_lr (code
, s390_r14
, ins
->sreg2
);
3187 s390_slr (code
, s390_r0
, ins
->sreg1
);
3189 s390_ahi (code
, s390_r14
, 1);
3190 s390_sr (code
, s390_r1
, s390_r14
);
3191 s390_lr (code
, ins
->dreg
, s390_r0
);
3192 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3196 case OP_S390_LSUB_OVF
: {
3198 s390_lr (code
, s390_r14
, ins
->sreg2
);
3199 s390_slr (code
, s390_r0
, ins
->sreg1
);
3200 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
3201 s390_ahi (code
, s390_r14
, 1);
3202 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3203 PTRSLOT (code
, o
[0]);
3204 s390_sr (code
, s390_r1
, s390_r14
);
3205 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3206 s390_lr (code
, ins
->dreg
, s390_r0
);
3207 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3210 case OP_LSUB_OVF_UN
:
3211 case OP_S390_LSUB_OVF_UN
: {
3212 s390_slr (code
, s390_r0
, ins
->sreg1
);
3213 s390_slbr (code
, s390_r1
, ins
->sreg2
);
3214 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, "OverflowException");
3215 s390_lr (code
, ins
->dreg
, s390_r0
);
3216 s390_lr (code
, ins
->dreg
+1, s390_r1
);
3219 case OP_SUB_OVF_CARRY
: {
3221 s390_lhi (code
, s390_r0
, 0);
3222 s390_lr (code
, s390_r1
, s390_r0
);
3223 s390_slbr (code
, s390_r0
, s390_r1
);
3224 s390_sr (code
, ins
->dreg
, src2
);
3225 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3226 s390_ar (code
, ins
->dreg
, s390_r0
);
3227 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, "OverflowException");
3230 case OP_SUB_OVF_UN_CARRY
: {
3232 s390_slbr (code
, ins
->dreg
, src2
);
3233 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, "OverflowException");
3237 if (ins
->sreg1
== ins
->dreg
) {
3238 s390_nr (code
, ins
->dreg
, ins
->sreg2
);
3241 if (ins
->sreg2
== ins
->dreg
) {
3242 s390_nr (code
, ins
->dreg
, ins
->sreg1
);
3245 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3246 s390_nr (code
, ins
->dreg
, ins
->sreg2
);
3253 if (s390_is_imm16 (ins
->inst_imm
)) {
3254 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3255 if (ins
->dreg
!= ins
->sreg1
) {
3256 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3258 s390_nr (code
, ins
->dreg
, s390_r0
);
3260 s390_basr (code
, s390_r13
, 0);
3262 s390_word (code
, ins
->inst_imm
);
3263 if (ins
->dreg
!= ins
->sreg1
) {
3264 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3266 s390_n (code
, ins
->dreg
, 0, s390_r13
, 4);
3271 s390_lr (code
, s390_r0
, ins
->sreg1
);
3272 s390_srda (code
, s390_r0
, 0, 32);
3273 s390_dr (code
, s390_r0
, ins
->sreg2
);
3274 s390_lr (code
, ins
->dreg
, s390_r1
);
3278 s390_lr (code
, s390_r0
, ins
->sreg1
);
3279 s390_srdl (code
, s390_r0
, 0, 32);
3280 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3281 s390_lr (code
, ins
->dreg
, s390_r1
);
3285 s390_lr (code
, s390_r0
, ins
->sreg1
);
3286 s390_srda (code
, s390_r0
, 0, 32);
3287 s390_dr (code
, s390_r0
, ins
->sreg2
);
3288 s390_lr (code
, ins
->dreg
, s390_r0
);
3291 s390_lr (code
, s390_r0
, ins
->sreg1
);
3292 s390_srdl (code
, s390_r0
, 0, 32);
3293 s390_dlr (code
, s390_r0
, ins
->sreg2
);
3294 s390_lr (code
, ins
->dreg
, s390_r0
);
3298 if (ins
->sreg1
== ins
->dreg
) {
3299 s390_or (code
, ins
->dreg
, ins
->sreg2
);
3302 if (ins
->sreg2
== ins
->dreg
) {
3303 s390_or (code
, ins
->dreg
, ins
->sreg1
);
3306 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3307 s390_or (code
, ins
->dreg
, ins
->sreg2
);
3314 if (s390_is_imm16 (ins
->inst_imm
)) {
3315 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3316 if (ins
->dreg
!= ins
->sreg1
) {
3317 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3319 s390_or (code
, ins
->dreg
, s390_r0
);
3321 s390_basr (code
, s390_r13
, 0);
3323 s390_word (code
, ins
->inst_imm
);
3324 if (ins
->dreg
!= ins
->sreg1
) {
3325 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3327 s390_o (code
, ins
->dreg
, 0, s390_r13
, 4);
3332 if (ins
->sreg1
== ins
->dreg
) {
3333 s390_xr (code
, ins
->dreg
, ins
->sreg2
);
3336 if (ins
->sreg2
== ins
->dreg
) {
3337 s390_xr (code
, ins
->dreg
, ins
->sreg1
);
3340 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3341 s390_xr (code
, ins
->dreg
, ins
->sreg2
);
3348 if (s390_is_imm16 (ins
->inst_imm
)) {
3349 s390_lhi (code
, s390_r0
, ins
->inst_imm
);
3350 if (ins
->dreg
!= ins
->sreg1
) {
3351 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3353 s390_xr (code
, ins
->dreg
, s390_r0
);
3355 s390_basr (code
, s390_r13
, 0);
3357 s390_word (code
, ins
->inst_imm
);
3358 if (ins
->dreg
!= ins
->sreg1
) {
3359 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3361 s390_x (code
, ins
->dreg
, 0, s390_r13
, 4);
3367 s390_sll (code
, ins
->dreg
, src2
, 0);
3372 if (ins
->sreg1
!= ins
->dreg
) {
3373 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3375 s390_sll (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3380 s390_sra (code
, ins
->dreg
, src2
, 0);
3385 if (ins
->sreg1
!= ins
->dreg
) {
3386 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3388 s390_sra (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3392 case OP_ISHR_UN_IMM
: {
3393 if (ins
->sreg1
!= ins
->dreg
) {
3394 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3396 s390_srl (code
, ins
->dreg
, 0, (ins
->inst_imm
& 0x1f));
3401 s390_srl (code
, ins
->dreg
, src2
, 0);
3405 if (ins
->sreg1
!= ins
->dreg
) {
3406 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3408 s390_lhi (code
, s390_r0
, -1);
3409 s390_xr (code
, ins
->dreg
, s390_r0
);
3413 s390_lcr (code
, ins
->dreg
, ins
->sreg1
);
3416 case OP_S390_LNEG
: {
3418 g_assert (ins
->dreg
+ 1 != ins
->sreg1
);
3419 s390_lcr (code
, ins
->dreg
+ 1, ins
->sreg2
);
3420 s390_lcr (code
, ins
->dreg
, ins
->sreg1
);
3422 s390_bctr (code
, ins
->dreg
+ 1, 0);
3426 if (ins
->sreg1
== ins
->dreg
) {
3427 s390_msr (code
, ins
->dreg
, ins
->sreg2
);
3430 if (ins
->sreg2
== ins
->dreg
) {
3431 s390_msr (code
, ins
->dreg
, ins
->sreg1
);
3434 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3435 s390_msr (code
, ins
->dreg
, ins
->sreg2
);
3442 if (s390_is_imm16 (ins
->inst_imm
)) {
3443 s390_lhi (code
, s390_r13
, ins
->inst_imm
);
3445 s390_basr (code
, s390_r13
, 0);
3447 s390_word (code
, ins
->inst_imm
);
3448 // if (ins->dreg != ins->sreg1) {
3449 // s390_lr (code, ins->dreg, ins->sreg1);
3451 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3453 if (ins
->dreg
!= ins
->sreg1
) {
3454 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3456 s390_msr (code
, ins
->dreg
, s390_r13
);
3461 s390_ltr (code
, s390_r1
, ins
->sreg1
);
3462 s390_jz (code
, 0); CODEPTR(code
, o
[0]);
3463 s390_ltr (code
, s390_r0
, ins
->sreg2
);
3465 s390_lhi (code
, s390_r1
, 0);
3466 s390_j (code
, 0); CODEPTR(code
, o
[1]);
3467 s390_xr (code
, s390_r0
, s390_r1
);
3468 s390_msr (code
, s390_r1
, ins
->sreg2
);
3469 s390_xr (code
, s390_r0
, s390_r1
);
3470 s390_srl (code
, s390_r0
, 0, 31);
3471 s390_ltr (code
, s390_r0
, s390_r0
);
3472 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3473 PTRSLOT (code
, o
[0]);
3474 PTRSLOT (code
, o
[1]);
3475 s390_lr (code
, ins
->dreg
, s390_r1
);
3478 case OP_IMUL_OVF_UN
: {
3479 s390_lhi (code
, s390_r0
, 0);
3480 s390_lr (code
, s390_r1
, ins
->sreg1
);
3481 s390_mlr (code
, s390_r0
, ins
->sreg2
);
3482 s390_ltr (code
, s390_r0
, s390_r0
);
3483 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ
, "OverflowException");
3484 s390_lr (code
, ins
->dreg
, s390_r1
);
3488 s390_l (code
, s390_r0
, 0, ins
->sreg1
, 4);
3489 s390_srda (code
, s390_r0
, 0, 32);
3490 s390_m (code
, s390_r0
, 0, ins
->sreg2
, 4);
3491 s390_l (code
, s390_r0
, 0, ins
->sreg1
, 4);
3492 s390_srl (code
, s390_r0
, 0, 31);
3493 s390_a (code
, s390_r0
, 0, ins
->sreg1
, 0);
3494 s390_l (code
, s390_r13
, 0, ins
->sreg2
, 0);
3495 s390_srl (code
, s390_r13
, 0, 31);
3496 s390_ms (code
, s390_r13
, 0, ins
->sreg1
, 4);
3497 s390_ar (code
, s390_r0
, s390_r13
);
3498 s390_st (code
, s390_r0
, 0, ins
->dreg
, 0);
3499 s390_st (code
, s390_r1
, 0, ins
->dreg
, 4);
3503 if (s390_is_imm16(ins
->inst_c0
)) {
3504 s390_lhi (code
, ins
->dreg
, ins
->inst_c0
);
3506 s390_basr (code
, s390_r13
, 0);
3508 s390_word (code
, ins
->inst_c0
);
3509 s390_l (code
, ins
->dreg
, 0, s390_r13
, 4);
3514 s390_basr (code
, s390_r13
, 0);
3516 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3517 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3518 s390_word (code
, 0);
3519 s390_l (code
,ins
->dreg
, 0, s390_r13
, 4);
3522 case OP_JUMP_TABLE
: {
3523 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3524 (MonoJumpInfoType
)ins
->inst_i1
, ins
->inst_p0
);
3525 s390_basr (code
, s390_r13
, 0);
3527 s390_word (code
, 0);
3528 s390_l (code
, ins
->dreg
, 0, s390_r13
, 4);
3531 case OP_ICONV_TO_I4
:
3532 case OP_ICONV_TO_U4
:
3534 if (ins
->dreg
!= ins
->sreg1
) {
3535 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
3540 int saved
= ins
->sreg1
;
3541 if (ins
->sreg1
== s390_r2
) {
3542 s390_lr (code
, s390_r0
, ins
->sreg1
);
3545 if (ins
->sreg2
!= s390_r2
)
3546 s390_lr (code
, s390_r2
, ins
->sreg2
);
3547 if (saved
!= s390_r3
)
3548 s390_lr (code
, s390_r3
, saved
);
3552 if (ins
->dreg
!= ins
->sreg1
) {
3553 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3557 case OP_S390_SETF4RET
: {
3558 s390_ledbr (code
, ins
->dreg
, ins
->sreg1
);
3562 if (s390_is_imm16 (ins
->inst_offset
)) {
3563 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
3565 s390_bras (code
, s390_r13
, 0);
3567 s390_word (code
, ins
->inst_offset
);
3568 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3570 s390_ear (code
, s390_r1
, 0);
3571 s390_l (code
, ins
->dreg
, s390_r13
, s390_r1
, 0);
3574 case OP_FCONV_TO_R4
: {
3576 if (ins
->dreg
!= ins
->sreg1
) {
3577 s390_ldr (code
, ins
->dreg
, ins
->sreg1
);
3582 (ins->next->opcode != OP_FMOVE) &&
3583 (ins->next->opcode != OP_STORER4_MEMBASE_REG))
3584 s390_ledbr (code, ins->dreg, ins->sreg1);
3589 if (cfg
->method
->save_lmf
)
3590 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
3592 if (cfg
->flags
& MONO_CFG_HAS_TAIL
) {
3593 code
= emit_load_volatile_registers(code
, cfg
);
3596 code
= backUpStackPtr(cfg
, code
, STK_BASE
);
3597 s390_l (code
, s390_r14
, 0, STK_BASE
, S390_RET_ADDR_OFFSET
);
3598 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
3599 MONO_PATCH_INFO_METHOD_JUMP
,
3601 s390_jcl (code
, S390_CC_UN
, 0);
3604 case OP_CHECK_THIS
: {
3605 /* ensure ins->sreg1 is not NULL */
3606 s390_icm (code
, s390_r0
, 15, ins
->sreg1
, 0);
3610 int offset
= cfg
->sig_cookie
+ cfg
->stack_usage
;
3612 if (s390_is_imm16 (offset
))
3613 s390_lhi (code
, s390_r0
, offset
);
3615 s390_basr (code
, s390_r13
, 0);
3617 s390_word (code
, offset
);
3618 s390_l (code
, s390_r0
, 0, s390_r13
, 0);
3620 s390_ar (code
, s390_r0
, cfg
->frame_reg
);
3621 s390_st (code
, s390_r0
, 0, ins
->sreg1
, 0);
3625 call
= (MonoCallInst
*)ins
;
3626 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3627 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_METHOD
,
3630 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
,
3632 s390_brasl (code
, s390_r14
, 0);
3633 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3634 s390_ldebr (code
, s390_f0
, s390_f0
);
3642 call
= (MonoCallInst
*)ins
;
3643 if (ins
->flags
& MONO_INST_HAS_METHOD
)
3644 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_METHOD
, call
->method
);
3646 mono_add_patch_info (cfg
, offset
, MONO_PATCH_INFO_ABS
, call
->fptr
);
3647 s390_brasl (code
, s390_r14
, 0);
3650 case OP_FCALL_REG
: {
3651 call
= (MonoCallInst
*)ins
;
3652 s390_lr (code
, s390_r1
, ins
->sreg1
);
3653 s390_basr (code
, s390_r14
, s390_r1
);
3654 if (call
->signature
->ret
->type
== MONO_TYPE_R4
)
3655 s390_ldebr (code
, s390_f0
, s390_f0
);
3661 case OP_VOIDCALL_REG
:
3663 s390_lr (code
, s390_r1
, ins
->sreg1
);
3664 s390_basr (code
, s390_r14
, s390_r1
);
3667 case OP_LCALL_MEMBASE
:
3668 case OP_VCALL_MEMBASE
:
3669 case OP_VCALL2_MEMBASE
:
3670 case OP_VOIDCALL_MEMBASE
:
3671 case OP_FCALL_MEMBASE
:
3672 case OP_CALL_MEMBASE
: {
3673 call
= (MonoCallInst
*)ins
;
3674 if (s390_is_uimm12(ins
->inst_offset
))
3675 s390_l (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3677 if (s390_is_imm16(ins
->inst_offset
)) {
3678 s390_lhi (code
, s390_r13
, ins
->inst_offset
);
3679 s390_l (code
, s390_r1
, s390_r13
, ins
->inst_basereg
, 0);
3681 s390_basr (code
, s390_r13
, 0);
3683 s390_word (code
, ins
->inst_offset
);
3684 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3685 s390_l (code
, s390_r1
, s390_r13
, ins
->inst_basereg
, 0);
3688 s390_basr (code
, s390_r14
, s390_r1
);
3689 if (ins
->opcode
== OP_FCALL_MEMBASE
&& call
->signature
->ret
->type
== MONO_TYPE_R4
)
3690 s390_ldebr (code
, s390_f0
, s390_f0
);
3694 /*------------------------------------------*/
3695 /* To allocate space on the stack we have */
3696 /* to allow room for parameters passed in */
3697 /* calls, the backchain pointer and round */
3698 /* it to our stack alignment requirements */
3699 /*------------------------------------------*/
3700 int alloca_skip
= S390_MINIMAL_STACK_SIZE
+ cfg
->param_area
;
3701 int area_offset
= S390_ALIGN(alloca_skip
, S390_STACK_ALIGNMENT
);
3702 s390_lr (code
, s390_r1
, ins
->sreg1
);
3703 if (ins
->flags
& MONO_INST_INIT
)
3704 s390_lr (code
, s390_r0
, ins
->sreg1
);
3705 s390_ahi (code
, s390_r1
, 14);
3706 s390_srl (code
, s390_r1
, 0, 3);
3707 s390_sll (code
, s390_r1
, 0, 3);
3708 if (cfg
->method
->save_lmf
) {
3709 /*----------------------------------*/
3710 /* we have to adjust lmf ebp value */
3711 /*----------------------------------*/
3712 int lmfOffset
= cfg
->stack_usage
- sizeof(MonoLMF
);
3714 s390_lr (code
, s390_r13
, cfg
->frame_reg
);
3715 if (s390_is_uimm16(lmfOffset
))
3716 s390_ahi (code
, s390_r13
, lmfOffset
);
3718 s390_basr (code
, s390_r14
, 0);
3720 s390_word (code
, lmfOffset
);
3721 s390_a (code
, s390_r13
, 0, s390_r14
, 4);
3723 s390_lr (code
, s390_r14
, STK_BASE
);
3724 s390_sr (code
, s390_r14
, s390_r1
);
3725 s390_st (code
, s390_r14
, 0, s390_r13
,
3726 G_STRUCT_OFFSET(MonoLMF
, ebp
));
3728 s390_l (code
, s390_r13
, 0, STK_BASE
, 0);
3729 s390_sr (code
, STK_BASE
, s390_r1
);
3730 s390_st (code
, s390_r13
, 0, STK_BASE
, 0);
3731 s390_la (code
, ins
->dreg
, 0, STK_BASE
, area_offset
);
3732 s390_srl (code
, ins
->dreg
, 0, 3);
3733 s390_sll (code
, ins
->dreg
, 0, 3);
3734 if (ins
->flags
& MONO_INST_INIT
) {
3735 s390_lr (code
, s390_r1
, s390_r0
);
3736 s390_lr (code
, s390_r0
, ins
->dreg
);
3737 s390_lr (code
, s390_r14
, s390_r12
);
3738 s390_lhi (code
, s390_r13
, 0);
3739 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
3741 s390_lr (code
, s390_r12
, s390_r14
);
3746 s390_lr (code
, s390_r2
, ins
->sreg1
);
3747 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3748 (gpointer
)"mono_arch_throw_exception");
3749 s390_brasl (code
, s390_r14
, 0);
3753 s390_lr (code
, s390_r2
, ins
->sreg1
);
3754 mono_add_patch_info (cfg
, code
-cfg
->native_code
, MONO_PATCH_INFO_INTERNAL_METHOD
,
3755 (gpointer
)"mono_arch_rethrow_exception");
3756 s390_brasl (code
, s390_r14
, 0);
3759 case OP_START_HANDLER
: {
3760 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3761 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3762 s390_st (code
, s390_r14
, 0,
3763 spvar
->inst_basereg
,
3764 spvar
->inst_offset
);
3766 s390_basr (code
, s390_r13
, 0);
3768 s390_word (code
, spvar
->inst_offset
);
3769 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3770 s390_st (code
, s390_r14
, s390_r13
,
3771 spvar
->inst_basereg
, 0);
3775 case OP_ENDFILTER
: {
3776 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3777 if (ins
->sreg1
!= s390_r2
)
3778 s390_lr (code
, s390_r2
, ins
->sreg1
);
3779 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3780 s390_l (code
, s390_r14
, 0, spvar
->inst_basereg
,
3781 spvar
->inst_offset
);
3783 s390_basr (code
, s390_r13
, 0);
3785 s390_word (code
, spvar
->inst_offset
);
3786 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3787 s390_l (code
, s390_r14
, s390_r13
,
3788 spvar
->inst_basereg
, 0);
3790 s390_br (code
, s390_r14
);
3793 case OP_ENDFINALLY
: {
3794 MonoInst
*spvar
= mono_find_spvar_for_region (cfg
, bb
->region
);
3795 if (s390_is_uimm12 (spvar
->inst_offset
)) {
3796 s390_l (code
, s390_r14
, 0, spvar
->inst_basereg
,
3797 spvar
->inst_offset
);
3799 s390_basr (code
, s390_r13
, 0);
3801 s390_word (code
, spvar
->inst_offset
);
3802 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3803 s390_l (code
, s390_r14
, s390_r13
,
3804 spvar
->inst_basereg
, 0);
3806 s390_br (code
, s390_r14
);
3809 case OP_CALL_HANDLER
: {
3810 mono_add_patch_info (cfg
, code
-cfg
->native_code
,
3811 MONO_PATCH_INFO_BB
, ins
->inst_target_bb
);
3812 s390_brasl (code
, s390_r14
, 0);
3816 ins
->inst_c0
= code
- cfg
->native_code
;
3819 case OP_RELAXED_NOP
:
3822 case OP_DUMMY_STORE
:
3823 case OP_NOT_REACHED
:
3828 EMIT_UNCOND_BRANCH(ins
);
3831 s390_br (code
, ins
->sreg1
);
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);
3850 s390_lhi (code
, ins
->dreg
, 1);
3852 s390_lhi (code
, ins
->dreg
, 0);
3857 s390_lhi (code
, ins
->dreg
, 1);
3859 s390_lhi (code
, ins
->dreg
, 0);
3864 s390_lhi (code
, ins
->dreg
, 1);
3866 s390_lhi (code
, ins
->dreg
, 0);
3869 case OP_COND_EXC_EQ
:
3870 case OP_COND_EXC_IEQ
:
3871 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ
, ins
->inst_p1
);
3873 case OP_COND_EXC_NE_UN
:
3874 case OP_COND_EXC_INE_UN
:
3875 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE
, ins
->inst_p1
);
3877 case OP_COND_EXC_LT
:
3878 case OP_COND_EXC_ILT
:
3879 case OP_COND_EXC_LT_UN
:
3880 case OP_COND_EXC_ILT_UN
:
3881 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT
, ins
->inst_p1
);
3883 case OP_COND_EXC_GT
:
3884 case OP_COND_EXC_IGT
:
3885 case OP_COND_EXC_GT_UN
:
3886 case OP_COND_EXC_IGT_UN
:
3887 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT
, ins
->inst_p1
);
3889 case OP_COND_EXC_GE
:
3890 case OP_COND_EXC_IGE
:
3891 case OP_COND_EXC_GE_UN
:
3892 case OP_COND_EXC_IGE_UN
:
3893 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE
, ins
->inst_p1
);
3895 case OP_COND_EXC_LE
:
3896 case OP_COND_EXC_ILE
:
3897 case OP_COND_EXC_LE_UN
:
3898 case OP_COND_EXC_ILE_UN
:
3899 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE
, ins
->inst_p1
);
3901 case OP_COND_EXC_OV
:
3902 case OP_COND_EXC_IOV
:
3903 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV
, ins
->inst_p1
);
3905 case OP_COND_EXC_NO
:
3906 case OP_COND_EXC_INO
:
3907 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO
, ins
->inst_p1
);
3910 case OP_COND_EXC_IC
:
3911 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY
, ins
->inst_p1
);
3913 case OP_COND_EXC_NC
:
3914 case OP_COND_EXC_INC
:
3915 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC
, ins
->inst_p1
);
3918 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
3921 EMIT_COND_BRANCH (ins
, S390_CC_NE
);
3925 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
3929 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
3933 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
3937 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
3940 /* floating point opcodes */
3942 if (*((float *) ins
->inst_p0
) == 0) {
3943 s390_lzdr (code
, ins
->dreg
);
3945 s390_basr (code
, s390_r13
, 0);
3947 s390_word (code
, ins
->inst_p0
);
3948 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3949 s390_ld (code
, ins
->dreg
, 0, s390_r13
, 0);
3954 if (*((float *) ins
->inst_p0
) == 0) {
3955 s390_lzdr (code
, ins
->dreg
);
3957 s390_basr (code
, s390_r13
, 0);
3959 s390_word (code
, ins
->inst_p0
);
3960 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3961 s390_ldeb (code
, ins
->dreg
, 0, s390_r13
, 0);
3965 case OP_STORER8_MEMBASE_REG
: {
3966 if (s390_is_uimm12(ins
->inst_offset
)) {
3967 s390_std (code
, ins
->sreg1
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
3969 s390_basr (code
, s390_r13
, 0);
3971 s390_word (code
, ins
->inst_offset
);
3972 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3973 s390_std (code
, ins
->sreg1
, s390_r13
, ins
->inst_destbasereg
, 0);
3977 case OP_LOADR8_MEMBASE
: {
3978 if (s390_is_uimm12(ins
->inst_offset
)) {
3979 s390_ld (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
3981 s390_basr (code
, s390_r13
, 0);
3983 s390_word (code
, ins
->inst_offset
);
3984 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3985 s390_ld (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
3989 case OP_STORER4_MEMBASE_REG
: {
3990 if (s390_is_uimm12(ins
->inst_offset
)) {
3991 s390_ledbr(code
, s390_f15
, ins
->sreg1
);
3992 s390_ste (code
, s390_f15
, 0, ins
->inst_destbasereg
, ins
->inst_offset
);
3994 s390_basr (code
, s390_r13
, 0);
3996 s390_word (code
, ins
->inst_offset
);
3997 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
3998 s390_ledbr(code
, s390_f15
, ins
->sreg1
);
3999 s390_ste (code
, s390_f15
, s390_r13
, ins
->inst_destbasereg
, 0);
4003 case OP_LOADR4_MEMBASE
: {
4004 if (s390_is_uimm12(ins
->inst_offset
)) {
4005 s390_ldeb (code
, ins
->dreg
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4007 s390_basr (code
, s390_r13
, 0);
4009 s390_word (code
, ins
->inst_offset
);
4010 s390_l (code
, s390_r13
, 0, s390_r13
, 4);
4011 s390_ldeb (code
, ins
->dreg
, s390_r13
, ins
->inst_basereg
, 0);
4015 case OP_ICONV_TO_R_UN
: {
4016 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
4017 s390_ltr (code
, ins
->sreg1
, ins
->sreg1
);
4018 s390_jnl (code
, 12);
4019 s390_basr (code
, s390_r13
, 0);
4021 s390_word (code
, 0x41f00000);
4022 s390_word (code
, 0);
4023 s390_adb (code
, ins
->dreg
, 0, s390_r13
, 4);
4026 case OP_ICONV_TO_R4
: {
4027 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
4030 case OP_ICONV_TO_R8
: {
4031 s390_cdfbr (code
, ins
->dreg
, ins
->sreg1
);
4034 case OP_FCONV_TO_I1
:
4035 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, TRUE
);
4037 case OP_FCONV_TO_U1
:
4038 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 1, FALSE
);
4040 case OP_FCONV_TO_I2
:
4041 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, TRUE
);
4043 case OP_FCONV_TO_U2
:
4044 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 2, FALSE
);
4046 case OP_FCONV_TO_I4
:
4048 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, TRUE
);
4050 case OP_FCONV_TO_U4
:
4052 code
= emit_float_to_int (cfg
, code
, ins
->dreg
, ins
->sreg1
, 4, FALSE
);
4054 case OP_FCONV_TO_I8
:
4055 case OP_FCONV_TO_U8
:
4056 g_assert_not_reached ();
4057 /* Implemented as helper calls */
4059 case OP_LCONV_TO_R_UN
:
4060 g_assert_not_reached ();
4061 /* Implemented as helper calls */
4063 case OP_LCONV_TO_OVF_I
:
4064 case OP_LCONV_TO_OVF_I4_2
: {
4065 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4067 s390_ltr (code
, ins
->sreg1
, ins
->sreg1
);
4068 s390_jnl (code
, 0); CODEPTR(code
, o
[0]);
4069 s390_ltr (code
, ins
->sreg2
, ins
->sreg2
);
4070 s390_jnl (code
, 0); CODEPTR(code
, o
[1]);
4071 s390_lhi (code
, s390_r13
, -1);
4072 s390_cr (code
, ins
->sreg2
, s390_r13
);
4073 s390_jnz (code
, 0); CODEPTR(code
, o
[2]);
4074 s390_j (code
, 0); CODEPTR(code
, o
[3]);
4075 PTRSLOT(code
, o
[0]);
4076 s390_ltr (code
, ins
->sreg2
, ins
->sreg2
);
4077 s390_jz (code
, 0); CODEPTR(code
, o
[4]);
4078 PTRSLOT(code
, o
[1]);
4079 PTRSLOT(code
, o
[2]);
4080 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4081 MONO_PATCH_INFO_EXC
, "OverflowException");
4082 s390_brasl (code
, s390_r14
, 0);
4083 PTRSLOT(code
, o
[3]);
4084 PTRSLOT(code
, o
[4]);
4085 if (ins
->dreg
!= ins
->sreg1
)
4086 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
4090 s390_sqdbr (code
, ins
->dreg
, ins
->sreg1
);
4095 s390_adbr (code
, ins
->dreg
, src2
);
4099 CHECK_SRCDST_NCOM_F
;
4100 s390_sdbr (code
, ins
->dreg
, src2
);
4105 s390_mdbr (code
, ins
->dreg
, src2
);
4109 CHECK_SRCDST_NCOM_F
;
4110 s390_ddbr (code
, ins
->dreg
, src2
);
4114 s390_lcdbr (code
, ins
->dreg
, ins
->sreg1
);
4118 CHECK_SRCDST_NCOM_F
;
4119 s390_didbr (code
, ins
->dreg
, src2
, 5, s390_f15
);
4123 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
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);
4141 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4142 s390_lhi (code
, ins
->dreg
, 1);
4144 s390_lhi (code
, ins
->dreg
, 0);
4148 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4149 s390_lhi (code
, ins
->dreg
, 1);
4151 s390_lhi (code
, ins
->dreg
, 0);
4155 s390_cdbr (code
, ins
->sreg1
, ins
->sreg2
);
4156 s390_lhi (code
, ins
->dreg
, 1);
4158 s390_lhi (code
, ins
->dreg
, 0);
4163 s390_jo (code
, 0); CODEPTR(code
, o
);
4164 EMIT_COND_BRANCH (ins
, S390_CC_EQ
);
4169 EMIT_COND_BRANCH (ins
, S390_CC_NE
|S390_CC_OV
);
4173 s390_jo (code
, 0); CODEPTR(code
, o
);
4174 EMIT_COND_BRANCH (ins
, S390_CC_LT
);
4179 EMIT_COND_BRANCH (ins
, S390_CC_LT
|S390_CC_OV
);
4183 s390_jo (code
, 0); CODEPTR(code
, o
);
4184 EMIT_COND_BRANCH (ins
, S390_CC_GT
);
4189 EMIT_COND_BRANCH (ins
, S390_CC_GT
|S390_CC_OV
);
4193 s390_jo (code
, 0); CODEPTR(code
, o
);
4194 EMIT_COND_BRANCH (ins
, S390_CC_GE
);
4199 EMIT_COND_BRANCH (ins
, S390_CC_GE
|S390_CC_OV
);
4203 s390_jo (code
, 0); CODEPTR(code
, o
);
4204 EMIT_COND_BRANCH (ins
, S390_CC_LE
);
4209 EMIT_COND_BRANCH (ins
, S390_CC_LE
|S390_CC_OV
);
4213 s390_lhi (code
, s390_r13
, 0x7f);
4214 s390_tcdb (code
, ins
->sreg1
, 0, s390_r13
, 0);
4215 s390_jz (code
, 0); CODEPTR(code
, o
);
4216 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4217 MONO_PATCH_INFO_EXC
, "ArithmeticException");
4218 s390_brasl (code
, s390_r14
,0);
4222 case OP_S390_MOVE
: {
4223 if (ins
->backend
.size
> 0) {
4224 if (ins
->backend
.size
<= 256) {
4225 s390_mvc (code
, ins
->backend
.size
, ins
->dreg
,
4226 ins
->inst_offset
, ins
->sreg1
, ins
->inst_imm
);
4228 s390_lr (code
, s390_r0
, ins
->dreg
);
4229 if (s390_is_imm16 (ins
->inst_offset
)) {
4230 s390_ahi (code
, s390_r0
, ins
->inst_offset
);
4232 s390_basr (code
, s390_r13
, 0);
4234 s390_word (code
, ins
->inst_offset
);
4235 s390_a (code
, s390_r0
, 0, s390_r13
, 4);
4237 s390_lr (code
, s390_r14
, s390_r12
);
4238 s390_lr (code
, s390_r12
, ins
->sreg1
);
4239 if (s390_is_imm16 (ins
->inst_imm
)) {
4240 s390_ahi (code
, s390_r12
, ins
->inst_imm
);
4242 s390_basr (code
, s390_r13
, 0);
4244 s390_word (code
, ins
->inst_imm
);
4245 s390_a (code
, s390_r12
, 0, s390_r13
, 4);
4247 s390_lr (code
, s390_r1
, ins
->sreg1
);
4248 s390_lr (code
, s390_r13
, s390_r1
);
4249 s390_mvcle(code
, s390_r0
, s390_r12
, 0, 0);
4251 s390_lr (code
, s390_r12
, s390_r14
);
4256 case OP_ATOMIC_ADD_I4
: {
4257 s390_lr (code
, s390_r1
, ins
->sreg2
);
4258 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4259 s390_a (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4260 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4261 s390_jnz (code
, -7);
4262 s390_lr (code
, ins
->dreg
, s390_r1
);
4265 case OP_ATOMIC_ADD_NEW_I4
: {
4266 s390_lr (code
, s390_r1
, ins
->sreg2
);
4267 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4268 s390_a (code
, s390_r1
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4269 s390_cs (code
, s390_r0
, s390_r1
, ins
->inst_basereg
, ins
->inst_offset
);
4270 s390_jnz (code
, -7);
4271 s390_lr (code
, ins
->dreg
, s390_r1
);
4274 case OP_ATOMIC_EXCHANGE_I4
: {
4275 s390_l (code
, s390_r0
, 0, ins
->inst_basereg
, ins
->inst_offset
);
4276 s390_cs (code
, s390_r0
, ins
->sreg2
, ins
->inst_basereg
, ins
->inst_offset
);
4277 s390_jnz (code
, -4);
4278 s390_lr (code
, ins
->dreg
, s390_r0
);
4281 case OP_S390_BKCHAIN
: {
4282 s390_lr (code
, ins
->dreg
, ins
->sreg1
);
4283 if (s390_is_imm16 (cfg
->stack_offset
)) {
4284 s390_ahi (code
, ins
->dreg
, cfg
->stack_offset
);
4286 s390_basr (code
, s390_r13
, 0);
4288 s390_word (code
, cfg
->stack_offset
);
4289 s390_a (code
, ins
->dreg
, 0, s390_r13
, 4);
4292 case OP_MEMORY_BARRIER
: {
4296 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins
->opcode
), __FUNCTION__
);
4297 g_assert_not_reached ();
4300 if ((cfg
->opt
& MONO_OPT_BRANCH
) && ((code
- cfg
->native_code
- offset
) > max_len
)) {
4301 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
4302 mono_inst_name (ins
->opcode
), max_len
, code
- cfg
->native_code
- offset
);
4303 g_assert_not_reached ();
4309 last_offset
= offset
;
4312 cfg
->code_len
= code
- cfg
->native_code
;
4315 /*========================= End of Function ========================*/
4317 /*------------------------------------------------------------------*/
4319 /* Name - mono_arch_register_lowlevel_calls */
4321 /* Function - Register routines to help with --trace operation. */
4323 /*------------------------------------------------------------------*/
4326 mono_arch_register_lowlevel_calls (void)
4328 mono_register_jit_icall (mono_arch_get_lmf_addr
, "mono_arch_get_lmf_addr", NULL
, TRUE
);
4331 /*========================= End of Function ========================*/
4333 /*------------------------------------------------------------------*/
4335 /* Name - mono_arch_patch_code */
4337 /* Function - Process the patch data created during the */
4338 /* instruction build process. This resolves jumps, */
4339 /* calls, variables etc. */
4341 /*------------------------------------------------------------------*/
4344 mono_arch_patch_code (MonoMethod
*method
, MonoDomain
*domain
,
4345 guint8
*code
, MonoJumpInfo
*ji
, gboolean run_cctors
)
4347 MonoJumpInfo
*patch_info
;
4349 for (patch_info
= ji
; patch_info
; patch_info
= patch_info
->next
) {
4350 unsigned char *ip
= patch_info
->ip
.i
+ code
;
4351 gconstpointer target
= NULL
;
4353 target
= mono_resolve_patch_target (method
, domain
, code
,
4354 patch_info
, run_cctors
);
4356 switch (patch_info
->type
) {
4357 case MONO_PATCH_INFO_IP
:
4358 case MONO_PATCH_INFO_EXC_NAME
:
4359 case MONO_PATCH_INFO_LDSTR
:
4360 case MONO_PATCH_INFO_TYPE_FROM_HANDLE
:
4361 case MONO_PATCH_INFO_LDTOKEN
:
4362 case MONO_PATCH_INFO_EXC
:
4364 case MONO_PATCH_INFO_SWITCH
:
4365 /*----------------------------------*/
4366 /* ip points at the basr r13,0/j +4 */
4367 /* instruction the vtable value */
4368 /* follows this (i.e. ip+6) */
4369 /*----------------------------------*/
4370 *((gconstpointer
*)(ip
+6)) = target
;
4373 case MONO_PATCH_INFO_METHODCONST
:
4374 case MONO_PATCH_INFO_CLASS
:
4375 case MONO_PATCH_INFO_IMAGE
:
4376 case MONO_PATCH_INFO_FIELD
:
4377 case MONO_PATCH_INFO_IID
:
4378 target
= S390_RELATIVE(target
, ip
);
4380 case MONO_PATCH_INFO_R4
:
4381 case MONO_PATCH_INFO_R8
:
4382 case MONO_PATCH_INFO_METHOD_REL
:
4383 g_assert_not_reached ();
4386 target
= S390_RELATIVE(target
, ip
);
4389 s390_patch (ip
, (guint32
) target
);
4393 /*========================= End of Function ========================*/
4395 /*------------------------------------------------------------------*/
4397 /* Name - emit_load_volatile_registers */
4399 /* Function - Create the instruction sequence for loading the */
4400 /* parameter registers for use with the 'tail' op. */
4402 /* The register loading operations performed here */
4403 /* are the mirror of the store operations performed */
4404 /* in mono_arch_emit_prolog and need to be kept in */
4405 /* synchronization with it. */
4407 /*------------------------------------------------------------------*/
4410 emit_load_volatile_registers (guint8
* code
, MonoCompile
*cfg
)
4412 MonoMethod
*method
= cfg
->method
;
4413 MonoMethodSignature
*sig
;
4418 sig
= mono_method_signature (method
);
4421 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
4423 if (cinfo
->struct_ret
) {
4424 ArgInfo
*ainfo
= &cinfo
->ret
;
4425 inst
= cfg
->vret_addr
;
4426 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4429 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4430 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4431 inst
= cfg
->args
[pos
];
4433 if (inst
->opcode
== OP_REGVAR
) {
4434 if (ainfo
->regtype
== RegTypeGeneral
)
4435 s390_lr (code
, ainfo
->reg
, inst
->dreg
);
4436 else if (ainfo
->regtype
== RegTypeFP
) {
4437 if (inst
->dreg
!= ainfo
->reg
) {
4438 if (ainfo
->size
== 4) {
4439 s390_ldebr (code
, ainfo
->reg
, inst
->dreg
);
4441 s390_ldr (code
, ainfo
->reg
, inst
->dreg
);
4445 else if (ainfo
->regtype
== RegTypeBase
) {
4447 g_assert_not_reached ();
4449 if (ainfo
->regtype
== RegTypeGeneral
) {
4450 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4451 g_assert_not_reached();
4452 switch (ainfo
->size
) {
4454 s390_ic (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4457 s390_lh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4460 s390_lm (code
, ainfo
->reg
, ainfo
->reg
+ 1,
4461 inst
->inst_basereg
, inst
->inst_offset
);
4464 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4466 } else if (ainfo
->regtype
== RegTypeBase
) {
4467 } else if (ainfo
->regtype
== RegTypeFP
) {
4468 if (ainfo
->size
== 8)
4469 s390_ld (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4470 else if (ainfo
->size
== 4)
4471 s390_le (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4473 g_assert_not_reached ();
4474 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4475 if (ainfo
->reg
!= STK_BASE
) {
4476 switch (ainfo
->size
) {
4478 s390_ic (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4481 s390_lh (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4484 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4487 s390_lm (code
, ainfo
->reg
, ainfo
->reg
+1, inst
->inst_basereg
, inst
->inst_offset
);
4491 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4492 if (ainfo
->reg
!= STK_BASE
) {
4493 s390_l (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4496 g_assert_not_reached ();
4504 /*========================= End of Function ========================*/
4506 /*------------------------------------------------------------------*/
4508 /* Name - mono_arch_emit_prolog */
4510 /* Function - Create the instruction sequence for a function */
4513 /*------------------------------------------------------------------*/
4516 mono_arch_emit_prolog (MonoCompile
*cfg
)
4518 MonoMethod
*method
= cfg
->method
;
4520 MonoMethodSignature
*sig
;
4522 int alloc_size
, pos
, max_offset
, i
;
4528 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
))
4531 cfg
->code_size
= 1024;
4532 cfg
->native_code
= code
= g_malloc (cfg
->code_size
);
4534 s390_stm (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4536 if (cfg
->arch
.bkchain_reg
!= -1)
4537 s390_lr (code
, cfg
->arch
.bkchain_reg
, STK_BASE
);
4539 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
) {
4540 cfg
->used_int_regs
|= 1 << 11;
4543 alloc_size
= cfg
->stack_offset
;
4545 cfg
->stack_usage
= alloc_size
;
4546 s390_lr (code
, s390_r11
, STK_BASE
);
4547 if (s390_is_uimm16 (alloc_size
)) {
4548 s390_ahi (code
, STK_BASE
, -alloc_size
);
4550 int stackSize
= alloc_size
;
4551 while (stackSize
> 32767) {
4552 s390_ahi (code
, STK_BASE
, -32767);
4555 s390_ahi (code
, STK_BASE
, -stackSize
);
4557 s390_st (code
, s390_r11
, 0, STK_BASE
, 0);
4559 if (cfg
->frame_reg
!= STK_BASE
)
4560 s390_lr (code
, s390_r11
, STK_BASE
);
4562 /* compute max_offset in order to use short forward jumps
4563 * we always do it on s390 because the immediate displacement
4564 * for jumps is too small
4567 for (bb
= cfg
->bb_entry
; bb
; bb
= bb
->next_bb
) {
4568 MonoInst
*ins
= bb
->code
;
4569 bb
->max_offset
= max_offset
;
4571 if (cfg
->prof_options
& MONO_PROFILE_COVERAGE
)
4574 MONO_BB_FOR_EACH_INS (bb
, ins
)
4575 max_offset
+= ((guint8
*)ins_get_spec (ins
->opcode
))[MONO_INST_LEN
];
4578 /* load arguments allocated to register from the stack */
4579 sig
= mono_method_signature (method
);
4582 cinfo
= get_call_info (cfg
, cfg
->mempool
, sig
, sig
->pinvoke
);
4584 if (cinfo
->struct_ret
) {
4585 ArgInfo
*ainfo
= &cinfo
->ret
;
4586 inst
= cfg
->vret_addr
;
4587 inst
->backend
.size
= ainfo
->vtsize
;
4588 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4591 for (i
= 0; i
< sig
->param_count
+ sig
->hasthis
; ++i
) {
4592 ArgInfo
*ainfo
= cinfo
->args
+ i
;
4593 inst
= cfg
->args
[pos
];
4595 if (inst
->opcode
== OP_VTARG_ADDR
)
4596 inst
= inst
->inst_left
;
4598 if (inst
->opcode
== OP_REGVAR
) {
4599 if (ainfo
->regtype
== RegTypeGeneral
)
4600 s390_lr (code
, inst
->dreg
, ainfo
->reg
);
4601 else if (ainfo
->regtype
== RegTypeFP
) {
4602 if (inst
->dreg
!= ainfo
->reg
) {
4603 if (ainfo
->size
== 4) {
4604 s390_ledbr (code
, inst
->dreg
, ainfo
->reg
);
4606 s390_ldr (code
, inst
->dreg
, ainfo
->reg
);
4610 else if (ainfo
->regtype
== RegTypeBase
) {
4611 s390_lr (code
, s390_r13
, STK_BASE
);
4612 s390_ahi (code
, s390_r13
, alloc_size
);
4613 s390_l (code
, inst
->dreg
, 0, s390_r13
, ainfo
->offset
);
4615 g_assert_not_reached ();
4617 if (cfg
->verbose_level
> 2)
4618 g_print ("Argument %d assigned to register %s\n",
4619 pos
, mono_arch_regname (inst
->dreg
));
4621 if (ainfo
->regtype
== RegTypeGeneral
) {
4622 if (!((ainfo
->reg
>= 2) && (ainfo
->reg
<= 6)))
4623 g_assert_not_reached();
4624 switch (ainfo
->size
) {
4626 s390_stc (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4629 s390_sth (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4632 s390_stm (code
, ainfo
->reg
, ainfo
->reg
+ 1,
4633 inst
->inst_basereg
, inst
->inst_offset
);
4636 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4638 } else if (ainfo
->regtype
== RegTypeBase
) {
4639 } else if (ainfo
->regtype
== RegTypeFP
) {
4640 if (ainfo
->size
== 8)
4641 s390_std (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4642 else if (ainfo
->size
== 4)
4643 s390_ste (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4645 g_assert_not_reached ();
4646 } else if (ainfo
->regtype
== RegTypeStructByVal
) {
4647 int doffset
= inst
->inst_offset
;
4649 if (ainfo
->reg
!= STK_BASE
)
4653 s390_lr (code
, s390_r13
, STK_BASE
);
4654 s390_ahi (code
, s390_r13
, alloc_size
);
4656 switch (ainfo
->size
) {
4658 if (ainfo
->reg
== STK_BASE
)
4659 s390_ic (code
, reg
, 0, s390_r13
, ainfo
->offset
+3);
4660 s390_stc (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4663 if (ainfo
->reg
== STK_BASE
)
4664 s390_lh (code
, reg
, 0, s390_r13
, ainfo
->offset
+2);
4665 s390_sth (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4668 if (ainfo
->reg
== STK_BASE
)
4669 s390_l (code
, reg
, 0, s390_r13
, ainfo
->offset
);
4670 s390_st (code
, reg
, 0, inst
->inst_basereg
, doffset
);
4673 if (ainfo
->reg
== STK_BASE
)
4674 s390_lm (code
, s390_r0
, s390_r1
, s390_r13
, ainfo
->offset
);
4675 s390_stm (code
, reg
, reg
+1, inst
->inst_basereg
, doffset
);
4678 } else if (ainfo
->regtype
== RegTypeStructByAddr
) {
4679 if (ainfo
->reg
!= STK_BASE
)
4680 s390_st (code
, ainfo
->reg
, 0, inst
->inst_basereg
, inst
->inst_offset
);
4682 g_assert_not_reached ();
4687 if (method
->save_lmf
) {
4688 /*---------------------------------------------------------------*/
4689 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4690 /*---------------------------------------------------------------*/
4691 lmfOffset
= alloc_size
- sizeof(MonoLMF
);
4693 s390_lr (code
, s390_r13
, cfg
->frame_reg
);
4694 if (s390_is_uimm16(lmfOffset
))
4695 s390_ahi (code
, s390_r13
, lmfOffset
);
4697 s390_basr (code
, s390_r14
, 0);
4699 s390_word (code
, lmfOffset
);
4700 s390_a (code
, s390_r13
, 0, s390_r14
, 4);
4703 /*---------------------------------------------------------------*/
4704 /* Preserve the parameter registers while we fix up the lmf */
4705 /*---------------------------------------------------------------*/
4706 s390_stm (code
, s390_r2
, s390_r6
, s390_r13
,
4707 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4709 /*---------------------------------------------------------------*/
4710 /* On return from this call r2 have the address of the &lmf */
4711 /*---------------------------------------------------------------*/
4712 mono_add_patch_info (cfg
, code
- cfg
->native_code
,
4713 MONO_PATCH_INFO_INTERNAL_METHOD
,
4714 (gpointer
)"mono_get_lmf_addr");
4715 s390_brasl (code
, s390_r14
, 0);
4717 /*---------------------------------------------------------------*/
4718 /* Set lmf.lmf_addr = jit_tls->lmf */
4719 /*---------------------------------------------------------------*/
4720 s390_st (code
, s390_r2
, 0, s390_r13
,
4721 G_STRUCT_OFFSET(MonoLMF
, lmf_addr
));
4723 /*---------------------------------------------------------------*/
4724 /* Get current lmf */
4725 /*---------------------------------------------------------------*/
4726 s390_l (code
, s390_r0
, 0, s390_r2
, 0);
4728 /*---------------------------------------------------------------*/
4729 /* Set our lmf as the current lmf */
4730 /*---------------------------------------------------------------*/
4731 s390_st (code
, s390_r13
, 0, s390_r2
, 0);
4733 /*---------------------------------------------------------------*/
4734 /* Have our lmf.previous_lmf point to the last lmf */
4735 /*---------------------------------------------------------------*/
4736 s390_st (code
, s390_r0
, 0, s390_r13
,
4737 G_STRUCT_OFFSET(MonoLMF
, previous_lmf
));
4739 /*---------------------------------------------------------------*/
4740 /* save method info */
4741 /*---------------------------------------------------------------*/
4742 s390_basr (code
, s390_r1
, 0);
4744 s390_word (code
, method
);
4745 s390_l (code
, s390_r1
, 0, s390_r1
, 4);
4746 s390_st (code
, s390_r1
, 0, s390_r13
,
4747 G_STRUCT_OFFSET(MonoLMF
, method
));
4749 /*---------------------------------------------------------------*/
4750 /* save the current IP */
4751 /*---------------------------------------------------------------*/
4752 s390_st (code
, STK_BASE
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, ebp
));
4753 s390_basr (code
, s390_r1
, 0);
4754 s390_la (code
, s390_r1
, 0, s390_r1
, 0);
4755 s390_st (code
, s390_r1
, 0, s390_r13
, G_STRUCT_OFFSET(MonoLMF
, eip
));
4757 /*---------------------------------------------------------------*/
4758 /* Save general and floating point registers */
4759 /*---------------------------------------------------------------*/
4760 s390_stm (code
, s390_r2
, s390_r12
, s390_r13
,
4761 G_STRUCT_OFFSET(MonoLMF
, gregs
[2]));
4762 for (i
= 0; i
< 16; i
++) {
4763 s390_std (code
, i
, 0, s390_r13
,
4764 G_STRUCT_OFFSET(MonoLMF
, fregs
[i
]));
4767 /*---------------------------------------------------------------*/
4768 /* Restore the parameter registers now that we've set up the lmf */
4769 /*---------------------------------------------------------------*/
4770 s390_lm (code
, s390_r2
, s390_r6
, s390_r13
,
4771 G_STRUCT_OFFSET(MonoLMF
, pregs
[0]));
4775 code
= mono_arch_instrument_prolog(cfg
, enter_method
, code
, TRUE
);
4777 cfg
->code_len
= code
- cfg
->native_code
;
4779 g_assert (cfg
->code_len
< cfg
->code_size
);
4784 /*========================= End of Function ========================*/
4786 /*------------------------------------------------------------------*/
4788 /* Name - mono_arch_emit_epilog */
4790 /* Function - Emit the instructions for a function epilog. */
4792 /*------------------------------------------------------------------*/
4795 mono_arch_emit_epilog (MonoCompile
*cfg
)
4797 MonoMethod
*method
= cfg
->method
;
4800 int max_epilog_size
= 96;
4802 if (cfg
->method
->save_lmf
)
4803 max_epilog_size
+= 128;
4805 if (mono_jit_trace_calls
!= NULL
)
4806 max_epilog_size
+= 128;
4808 if (cfg
->prof_options
& MONO_PROFILE_ENTER_LEAVE
)
4809 max_epilog_size
+= 128;
4811 while ((cfg
->code_len
+ max_epilog_size
) > (cfg
->code_size
- 16)) {
4812 cfg
->code_size
*= 2;
4813 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4814 mono_jit_stats
.code_reallocs
++;
4817 code
= cfg
->native_code
+ cfg
->code_len
;
4819 if (mono_jit_trace_calls
!= NULL
&& mono_trace_eval (method
)) {
4820 code
= mono_arch_instrument_epilog (cfg
, leave_method
, code
, TRUE
);
4824 if (method
->save_lmf
)
4825 restoreLMF(code
, cfg
->frame_reg
, cfg
->stack_usage
);
4827 if (cfg
->flags
& MONO_CFG_HAS_ALLOCA
)
4828 s390_l (code
, STK_BASE
, 0, STK_BASE
, 0);
4830 code
= backUpStackPtr(cfg
, code
, STK_BASE
);
4832 s390_lm (code
, s390_r6
, s390_r14
, STK_BASE
, S390_REG_SAVE_OFFSET
);
4833 s390_br (code
, s390_r14
);
4835 cfg
->code_len
= code
- cfg
->native_code
;
4837 g_assert (cfg
->code_len
< cfg
->code_size
);
4841 /*========================= End of Function ========================*/
4843 /*------------------------------------------------------------------*/
4845 /* Name - mono_arch_emit_exceptions */
4847 /* Function - Emit the blocks to handle exception conditions. */
4849 /*------------------------------------------------------------------*/
4852 mono_arch_emit_exceptions (MonoCompile
*cfg
)
4854 MonoJumpInfo
*patch_info
;
4860 MonoClass
*exc_classes
[MAX_EXC
];
4861 guint8
*exc_throw_start
[MAX_EXC
];
4863 for (patch_info
= cfg
->patch_info
;
4865 patch_info
= patch_info
->next
) {
4866 if (patch_info
->type
== MONO_PATCH_INFO_EXC
)
4870 code_size
= exc_count
* 26;
4872 while ((cfg
->code_len
+ code_size
) > (cfg
->code_size
- 16)) {
4873 cfg
->code_size
*= 2;
4874 cfg
->native_code
= g_realloc (cfg
->native_code
, cfg
->code_size
);
4875 mono_jit_stats
.code_reallocs
++;
4878 code
= cfg
->native_code
+ cfg
->code_len
;
4880 /*---------------------------------------------------------------------*/
4881 /* Add code to raise exceptions */
4882 /*---------------------------------------------------------------------*/
4883 for (patch_info
= cfg
->patch_info
; patch_info
; patch_info
= patch_info
->next
) {
4884 switch (patch_info
->type
) {
4885 case MONO_PATCH_INFO_EXC
: {
4886 guint8
*ip
= patch_info
->ip
.i
+ cfg
->native_code
;
4887 MonoClass
*exc_class
;
4890 /*-----------------------------------------------------*/
4891 /* Patch the branch in epilog to come here */
4892 /*-----------------------------------------------------*/
4893 s390_patch (ip
+ 2, (guint32
) (S390_RELATIVE(code
,ip
)));
4895 exc_class
= mono_class_from_name (mono_defaults
.corlib
,
4897 patch_info
->data
.name
);
4898 g_assert (exc_class
);
4899 throw_ip
= patch_info
->ip
.i
;
4901 for (iExc
= 0; iExc
< nThrows
; ++iExc
)
4902 if (exc_classes
[iExc
] == exc_class
)
4905 if (iExc
< nThrows
) {
4906 s390_jcl (code
, S390_CC_UN
, (guint32
) exc_throw_start
[iExc
]);
4907 patch_info
->type
= MONO_PATCH_INFO_NONE
;
4910 if (nThrows
< MAX_EXC
) {
4911 exc_classes
[nThrows
] = exc_class
;
4912 exc_throw_start
[nThrows
] = code
;
4915 /*---------------------------------------------*/
4916 /* Patch the parameter passed to the handler */
4917 /*---------------------------------------------*/
4918 s390_basr (code
, s390_r13
, 0);
4920 s390_word (code
, patch_info
->data
.target
);
4921 /*---------------------------------------------*/
4922 /* Load return address & parameter register */
4923 /*---------------------------------------------*/
4924 s390_larl (code
, s390_r14
, (gsize
)S390_RELATIVE((patch_info
->ip
.i
+
4925 cfg
->native_code
+ 8), code
));
4926 s390_l (code
, s390_r2
, 0, s390_r13
, 4);
4927 /*---------------------------------------------*/
4928 /* Reuse the current patch to set the jump */
4929 /*---------------------------------------------*/
4930 patch_info
->type
= MONO_PATCH_INFO_INTERNAL_METHOD
;
4931 patch_info
->data
.name
= "mono_arch_throw_exception_by_name";
4932 patch_info
->ip
.i
= code
- cfg
->native_code
;
4933 s390_jcl (code
, S390_CC_UN
, 0);
4943 cfg
->code_len
= code
- cfg
->native_code
;
4945 g_assert (cfg
->code_len
< cfg
->code_size
);
4949 /*========================= End of Function ========================*/
4951 /*------------------------------------------------------------------*/
4953 /* Name - mono_arch_setup_jit_tls_data */
4955 /* Function - Setup the JIT's Thread Level Specific Data. */
4957 /*------------------------------------------------------------------*/
4960 mono_arch_setup_jit_tls_data (MonoJitTlsData
*tls
)
4963 if (!tls_offset_inited
) {
4964 tls_offset_inited
= TRUE
;
4968 __asm__ ("\tear\t%r1,0\n"
4975 : "=r" (appdomain_tls_offset
),
4976 "=r" (thread_tls_offset
),
4977 "=r" (lmf_tls_offset
)
4978 : "r" (&tls_appdomain
),
4979 "r" (&tls_current_object
),
4980 "r" (&mono_lmf_addr
)
4986 if (!lmf_addr_key_inited
) {
4987 lmf_addr_key_inited
= TRUE
;
4988 pthread_key_create (&lmf_addr_key
, NULL
);
4990 pthread_setspecific (lmf_addr_key
, &tls
->lmf
);
4994 /*========================= End of Function ========================*/
4996 /*------------------------------------------------------------------*/
4998 /* Name - mono_arch_free_jit_tls_data */
5000 /* Function - Free tls data. */
5002 /*------------------------------------------------------------------*/
5005 mono_arch_free_jit_tls_data (MonoJitTlsData
*tls
)
5009 /*========================= End of Function ========================*/
5011 /*------------------------------------------------------------------*/
5013 /* Name - mono_arch_emit_inst_for_method */
5015 /*------------------------------------------------------------------*/
5018 mono_arch_emit_inst_for_method (MonoCompile
*cfg
, MonoMethod
*cmethod
, MonoMethodSignature
*fsig
, MonoInst
**args
)
5023 /*========================= End of Function ========================*/
5026 mono_arch_decompose_opts (MonoCompile
*cfg
, MonoInst
*ins
)
5028 switch (ins
->opcode
) {
5030 ins
->opcode
= OP_S390_ISUB_OVF
;
5032 case OP_ISUB_OVF_UN
:
5033 ins
->opcode
= OP_S390_ISUB_OVF_UN
;
5036 ins
->opcode
= OP_S390_IADD_OVF
;
5038 case OP_IADD_OVF_UN
:
5039 ins
->opcode
= OP_S390_IADD_OVF_UN
;
5046 /*========================= End of Function ========================*/
5048 /*------------------------------------------------------------------*/
5050 /* Name - mono_arch_decompose_long_opts */
5052 /*------------------------------------------------------------------*/
5055 mono_arch_decompose_long_opts (MonoCompile
*cfg
, MonoInst
*ins
)
5057 // The generic code seems to work for OP_LSUB fine on s390, why is a different
5058 // implementation needed ? gcc also seems to use the different implementation.
5059 // FIXME: What about the other OP_L opcodes below ?
5061 switch (ins
->opcode
) {
5063 case OP_LADD_OVF_UN
:
5065 case OP_LSUB_OVF_UN
: {
5068 switch (ins
->opcode
) {
5070 opcode
= OP_S390_LADD
;
5073 opcode
= OP_S390_LADD_OVF
;
5075 case OP_LADD_OVF_UN
:
5076 opcode
= OP_S390_LADD_OVF_UN
;
5079 opcode
= OP_S390_LSUB
;
5082 opcode
= OP_S390_LSUB_OVF
;
5084 case OP_LSUB_OVF_UN
:
5085 opcode
= OP_S390_LSUB_OVF_UN
;
5088 g_assert_not_reached ();
5091 /* These hard regs make ssa crazy */
5092 cfg
->disable_ssa
= TRUE
;
5093 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r0
, ins
->sreg1
+ 1);
5094 MONO_EMIT_NEW_UNALU (cfg
, OP_MOVE
, s390_r1
, ins
->sreg1
+ 2);
5095 MONO_EMIT_NEW_BIALU (cfg
, opcode
, ins
->dreg
, ins
->sreg2
+ 1, ins
->sreg2
+ 2);
5100 int dreg
= mono_alloc_dreg (cfg
, STACK_I8
);
5101 MONO_EMIT_NEW_I8CONST (cfg
, dreg
, ins
->inst_l
);
5102 MONO_EMIT_NEW_BIALU (cfg
, OP_LADD
, ins
->dreg
, ins
->sreg1
, dreg
);
5107 int dreg
= mono_alloc_dreg (cfg
, STACK_I8
);
5108 MONO_EMIT_NEW_I8CONST (cfg
, dreg
, ins
->inst_l
);
5109 MONO_EMIT_NEW_BIALU (cfg
, OP_LSUB
, ins
->dreg
, ins
->sreg1
, dreg
);
5114 MONO_EMIT_NEW_BIALU (cfg
, OP_S390_LNEG
, ins
->dreg
, ins
->sreg1
+ 1, ins
->sreg1
+ 2);
5119 ins
->opcode
= OP_S390_ISUB_OVF
;
5121 case OP_ISUB_OVF_UN
:
5122 ins
->opcode
= OP_S390_ISUB_OVF_UN
;
5129 /*========================= End of Function ========================*/
5131 /*------------------------------------------------------------------*/
5133 /* Name - mono_arch_print_tree */
5135 /* Function - Print platform-specific opcode details. */
5137 /* Returns - 1 - opcode details have been printed */
5138 /* 0 - opcode details have not been printed */
5140 /*------------------------------------------------------------------*/
5143 mono_arch_print_tree (MonoInst
*tree
, int arity
)
5147 switch (tree
->opcode
) {
5148 case OP_S390_LOADARG
:
5149 case OP_S390_ARGREG
:
5150 case OP_S390_ARGPTR
:
5151 printf ("[0x%lx(%s)]", tree
->inst_offset
,
5152 mono_arch_regname (tree
->inst_basereg
));
5155 case OP_S390_STKARG
:
5156 printf ("[0x%lx(previous_frame)]",
5161 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5162 tree
->inst_offset
, tree
->backend
.size
,
5163 mono_arch_regname(tree
->dreg
), tree
->inst_imm
,
5164 mono_arch_regname(tree
->sreg1
));
5167 case OP_S390_SETF4RET
:
5169 mono_arch_fregname (tree
->dreg
),
5170 mono_arch_fregname (tree
->sreg1
));
5174 printf ("[0x%lx(0x%lx,%s)]", tree
->inst_offset
,
5176 mono_arch_regname (tree
->sreg1
));
5179 case OP_S390_BKCHAIN
:
5180 printf ("[previous_frame(%s)]",
5181 mono_arch_regname (tree
->sreg1
));
5190 /*========================= End of Function ========================*/
5192 /*------------------------------------------------------------------*/
5194 /* Name - mono_arch_regalloc_cost */
5196 /* Function - Determine the cost, in the number of memory */
5197 /* references, of the action of allocating the var- */
5198 /* iable VMV into a register during global register */
5201 /* Returns - Cost */
5203 /*------------------------------------------------------------------*/
5206 mono_arch_regalloc_cost (MonoCompile
*cfg
, MonoMethodVar
*vmv
)
5212 /*========================= End of Function ========================*/
5214 /*------------------------------------------------------------------*/
5216 /* Name - mono_arch_get_domain_intrinsic */
5222 /*------------------------------------------------------------------*/
5225 mono_arch_get_domain_intrinsic (MonoCompile
* cfg
)
5229 if (appdomain_tls_offset
== -1)
5232 MONO_INST_NEW (cfg
, ins
, OP_TLS_GET
);
5233 ins
->inst_offset
= appdomain_tls_offset
;
5237 /*========================= End of Function ========================*/
5239 /*------------------------------------------------------------------*/
5241 /* Name - mono_arch_get_thread_intrinsic */
5247 /*------------------------------------------------------------------*/
5250 mono_arch_get_thread_intrinsic (MonoCompile
* cfg
)
5254 if (thread_tls_offset
== -1)
5257 MONO_INST_NEW (cfg
, ins
, OP_TLS_GET
);
5258 ins
->inst_offset
= thread_tls_offset
;
5262 /*========================= End of Function ========================*/
5264 /*------------------------------------------------------------------*/
5266 /* Name - mono_arch_flush_register_windows */
5272 /*------------------------------------------------------------------*/
5275 mono_arch_flush_register_windows (void)
5279 /*========================= End of Function ========================*/
5281 /*------------------------------------------------------------------*/
5283 /* Name - mono_arch_get_lmf_addr */
5289 /*------------------------------------------------------------------*/
5292 mono_arch_get_lmf_addr (void)
5294 return pthread_getspecific (lmf_addr_key
);
5298 /*========================= End of Function ========================*/
5300 /*------------------------------------------------------------------*/
5302 /* Name - mono_arch_get_patch_offset */
5304 /* Function - Dummy entry point until s390x supports aot. */
5306 /* Returns - Offset for patch. */
5308 /*------------------------------------------------------------------*/
5311 mono_arch_get_patch_offset (guint8
*code
)
5316 /*========================= End of Function ========================*/
5319 mono_arch_context_get_int_reg (MonoContext
*ctx
, int reg
)
5321 /* FIXME: implement */
5322 g_assert_not_reached ();