Make sure x86 ATOMIC_CAS doesn't overwrite its own operands.
[mono-debugger.git] / mono / mini / mini-s390x.c
bloba74b99038961766f2bbb26c0f80169af3400a93c
1 /*------------------------------------------------------------------*/
2 /* */
3 /* Name - mini-s390.c */
4 /* */
5 /* Function - S/390 backend for the Mono code generator. */
6 /* */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
8 /* */
9 /* Date - January, 2004 */
10 /* */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
14 /* */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
18 /* D e f i n e s */
19 /*------------------------------------------------------------------*/
21 #define EMIT_COND_BRANCH(ins,cond) \
22 { \
23 if (ins->flags & MONO_INST_BRLABEL) { \
24 if (ins->inst_i0->inst_c0) { \
25 int displace; \
26 displace = ((cfg->native_code + ins->inst_i0->inst_c0) - code) / 2; \
27 if (s390_is_imm16(displace)) { \
28 s390_brc (code, cond, displace); \
29 } else { \
30 s390_jcl (code, cond, displace); \
31 } \
32 } else { \
33 mono_add_patch_info (cfg, code - cfg->native_code, \
34 MONO_PATCH_INFO_LABEL, ins->inst_i0); \
35 s390_jcl (code, cond, 0); \
36 } \
37 } else { \
38 if (ins->inst_true_bb->native_offset) { \
39 int displace; \
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); \
44 } else { \
45 s390_jcl (code, cond, displace); \
46 } \
47 } else { \
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); \
51 } \
52 } \
55 #define EMIT_UNCOND_BRANCH(ins) \
56 { \
57 if (ins->flags & MONO_INST_BRLABEL) { \
58 if (ins->inst_i0->inst_c0) { \
59 int displace; \
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); \
63 } else { \
64 s390_jcl (code, S390_CC_UN, displace); \
65 } \
66 } else { \
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); \
70 } \
71 } else { \
72 if (ins->inst_target_bb->native_offset) { \
73 int displace; \
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); \
78 } else { \
79 s390_jcl (code, S390_CC_UN, displace); \
80 } \
81 } else { \
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); \
85 } \
86 } \
89 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
90 do { \
91 mono_add_patch_info (cfg, code - cfg->native_code, \
92 MONO_PATCH_INFO_EXC, exc_name); \
93 s390_jcl (code, cond, 0); \
94 } while (0);
96 #define CHECK_SRCDST_COM \
97 if (ins->dreg == ins->sreg2) { \
98 src2 = ins->sreg1; \
99 } else { \
100 src2 = ins->sreg2; \
101 if (ins->dreg != ins->sreg1) { \
102 s390_lgr (code, ins->dreg, ins->sreg1); \
106 #define CHECK_SRCDST_NCOM \
107 if (ins->dreg == ins->sreg2) { \
108 src2 = s390_r13; \
109 s390_lgr (code, s390_r13, ins->sreg2); \
110 } else { \
111 src2 = ins->sreg2; \
113 if (ins->dreg != ins->sreg1) { \
114 s390_lgr (code, ins->dreg, ins->sreg1); \
117 #define CHECK_SRCDST_COM_I \
118 if (ins->dreg == ins->sreg2) { \
119 src2 = ins->sreg1; \
120 } else { \
121 src2 = ins->sreg2; \
122 if (ins->dreg != ins->sreg1) { \
123 s390_lgfr (code, ins->dreg, ins->sreg1); \
127 #define CHECK_SRCDST_NCOM_I \
128 if (ins->dreg == ins->sreg2) { \
129 src2 = s390_r13; \
130 s390_lgfr (code, s390_r13, ins->sreg2); \
131 } else { \
132 src2 = ins->sreg2; \
134 if (ins->dreg != ins->sreg1) { \
135 s390_lgfr (code, ins->dreg, ins->sreg1); \
138 #define CHECK_SRCDST_COM_F \
139 if (ins->dreg == ins->sreg2) { \
140 src2 = ins->sreg1; \
141 } else { \
142 src2 = ins->sreg2; \
143 if (ins->dreg != ins->sreg1) { \
144 s390_ldr (code, ins->dreg, ins->sreg1); \
148 #define CHECK_SRCDST_NCOM_F \
149 if (ins->dreg == ins->sreg2) { \
150 src2 = s390_f15; \
151 s390_ldr (code, s390_r13, ins->sreg2); \
152 } else { \
153 src2 = ins->sreg2; \
155 if (ins->dreg != ins->sreg1) { \
156 s390_ldr (code, ins->dreg, ins->sreg1); \
159 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
160 MonoInst *inst; \
161 int tmpr = 0; \
162 int sReg, dReg; \
163 MONO_INST_NEW (cfg, inst, OP_NOP); \
164 if (size > 256) { \
165 tmpr = mono_alloc_preg (cfg); \
166 MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
167 inst->dreg = dest; \
168 inst->inst_offset = offset; \
169 inst->sreg1 = src; \
170 inst->inst_imm = imm; \
171 inst->sreg2 = tmpr; \
172 } else { \
173 if (s390_is_uimm12(offset)) { \
174 inst->dreg = dest; \
175 inst->inst_offset = offset; \
176 } else { \
177 dReg = mono_alloc_preg (cfg); \
178 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
179 dReg, dest, offset); \
180 inst->dreg = dReg; \
181 inst->inst_offset = 0; \
183 if (s390_is_uimm12(imm)) { \
184 inst->sreg1 = src; \
185 inst->inst_imm = imm; \
186 } else { \
187 sReg = mono_alloc_preg (cfg); \
188 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
189 sReg, src, imm); \
190 inst->sreg1 = sReg; \
191 inst->inst_imm = 0; \
194 inst->opcode = OP_S390_MOVE; \
195 inst->backend.size = size; \
196 MONO_ADD_INS (cfg->cbb, inst); \
197 } while (0)
199 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
200 int reg = mono_alloc_preg (cfg); \
201 switch (size) { \
202 case 0: \
203 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
204 break; \
205 case 1: \
206 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
207 reg, sr, so); \
208 break; \
209 case 2: \
210 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
211 reg, sr, so); \
212 break; \
213 case 4: \
214 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
215 reg, sr, so); \
216 break; \
217 case 8: \
218 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
219 reg, sr, so); \
220 break; \
222 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
223 } while (0)
225 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
226 int tmpr; \
227 switch (size) { \
228 case 0: \
229 tmpr = mono_alloc_preg (cfg); \
230 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
231 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
232 dr, dx, tmpr); \
233 break; \
234 case 1: \
235 tmpr = mono_alloc_preg (cfg); \
236 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
237 tmpr, sr, so); \
238 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
239 dr, dx, tmpr); \
240 break; \
241 case 2: \
242 tmpr = mono_alloc_preg (cfg); \
243 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
244 tmpr, sr, so); \
245 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
246 dr, dx, tmpr); \
247 break; \
248 case 4: \
249 tmpr = mono_alloc_preg (cfg); \
250 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
251 tmpr, sr, so); \
252 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
253 dr, dx, tmpr); \
254 break; \
255 case 8: \
256 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
257 break; \
259 } while (0)
261 #undef DEBUG
262 #define DEBUG(a) if (cfg->verbose_level > 1) a
264 #define MAX_EXC 16
266 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
268 #define MAX(a, b) ((a) > (b) ? (a) : (b))
270 /*========================= End of Defines =========================*/
272 /*------------------------------------------------------------------*/
273 /* I n c l u d e s */
274 /*------------------------------------------------------------------*/
276 #include "mini.h"
277 #include <string.h>
279 #include <mono/metadata/appdomain.h>
280 #include <mono/metadata/debug-helpers.h>
281 #include <mono/metadata/profiler-private.h>
282 #include <mono/utils/mono-math.h>
284 #include "mini-s390x.h"
285 #include "cpu-s390x.h"
286 #include "jit-icalls.h"
287 #include "ir-emit.h"
289 /*========================= End of Includes ========================*/
291 /*------------------------------------------------------------------*/
292 /* T y p e d e f s */
293 /*------------------------------------------------------------------*/
295 typedef struct {
296 guint stack_size,
297 local_size,
298 code_size,
299 parm_size,
300 offset,
301 offStruct,
302 retStruct;
303 } size_data;
305 /*------------------------------------------------------------------*/
306 /* Used by the instrument_emit_epilog */
307 /*------------------------------------------------------------------*/
309 enum {
310 SAVE_NONE,
311 SAVE_STRUCT,
312 SAVE_ONE,
313 SAVE_TWO,
314 SAVE_R4,
315 SAVE_R8
318 typedef struct InstList InstList;
320 struct InstList {
321 InstList *prev;
322 InstList *next;
323 MonoInst *data;
326 typedef enum {
327 RegTypeGeneral,
328 RegTypeBase,
329 RegTypeFP,
330 RegTypeFPR4,
331 RegTypeStructByVal,
332 RegTypeStructByValInFP,
333 RegTypeStructByAddr,
334 RegTypeStructByAddrOnStack
335 } ArgStorage;
337 typedef struct {
338 gint32 offset; /* offset from caller's stack */
339 gint32 offparm; /* offset from callee's stack */
340 guint16 vtsize; /* in param area */
341 guint8 reg;
342 ArgStorage regtype;
343 guint32 size; /* Size of structure used by RegTypeStructByVal */
344 gint32 type; /* Data type of argument */
345 } ArgInfo;
347 typedef struct {
348 int nargs;
349 int lastgr;
350 guint32 stack_usage;
351 guint32 struct_ret;
352 ArgInfo ret;
353 ArgInfo sigCookie;
354 size_data sz;
355 ArgInfo args [1];
356 } CallInfo;
358 typedef struct {
359 gint64 gr[5]; /* R2-R6 */
360 gdouble fp[3]; /* F0-F2 */
361 } __attribute__ ((packed)) RegParm;
363 /*========================= End of Typedefs ========================*/
365 /*------------------------------------------------------------------*/
366 /* P r o t o t y p e s */
367 /*------------------------------------------------------------------*/
369 static void indent (int);
370 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
371 static void decodeParm (MonoType *, void *, int);
372 static void enter_method (MonoMethod *, RegParm *, char *);
373 static void leave_method (MonoMethod *, ...);
374 static gboolean is_regsize_var (MonoType *);
375 static inline void add_general (guint *, size_data *, ArgInfo *);
376 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
377 static inline void add_float (guint *, size_data *, ArgInfo *);
378 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
379 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
380 gpointer mono_arch_get_lmf_addr (void);
381 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
382 static void catch_SIGILL(int, siginfo_t *, void *);
384 /*========================= End of Prototypes ======================*/
386 /*------------------------------------------------------------------*/
387 /* G l o b a l V a r i a b l e s */
388 /*------------------------------------------------------------------*/
390 int mono_exc_esp_offset = 0;
392 static int indent_level = 0;
394 int has_ld = 0;
396 static gboolean tls_offset_inited = FALSE;
398 static int appdomain_tls_offset = -1,
399 thread_tls_offset = -1;
401 pthread_key_t lmf_addr_key;
403 gboolean lmf_addr_key_inited = FALSE;
405 #if 0
407 extern __thread MonoDomain *tls_appdomain;
408 extern __thread MonoThread *tls_current_object;
409 extern __thread gpointer mono_lmf_addr;
411 #endif
413 /*====================== End of Global Variables ===================*/
415 /*------------------------------------------------------------------*/
416 /* */
417 /* Name - mono_arch_regname */
418 /* */
419 /* Function - Returns the name of the register specified by */
420 /* the input parameter. */
421 /* */
422 /*------------------------------------------------------------------*/
424 const char*
425 mono_arch_regname (int reg) {
426 static const char * rnames[] = {
427 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
428 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
429 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
430 "s390_r15"
433 if (reg >= 0 && reg < 16)
434 return rnames [reg];
435 else
436 return "unknown";
439 /*========================= End of Function ========================*/
441 /*------------------------------------------------------------------*/
442 /* */
443 /* Name - mono_arch_fregname */
444 /* */
445 /* Function - Returns the name of the register specified by */
446 /* the input parameter. */
447 /* */
448 /*------------------------------------------------------------------*/
450 const char*
451 mono_arch_fregname (int reg) {
452 static const char * rnames[] = {
453 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
454 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
455 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
456 "s390_f15"
459 if (reg >= 0 && reg < 16)
460 return rnames [reg];
461 else
462 return "unknown";
465 /*========================= End of Function ========================*/
467 /*------------------------------------------------------------------*/
468 /* */
469 /* Name - arch_get_argument_info */
470 /* */
471 /* Function - Gathers information on parameters such as size, */
472 /* alignment, and padding. arg_info should be large */
473 /* enough to hold param_count + 1 entries. */
474 /* */
475 /* Parameters - @csig - Method signature */
476 /* @param_count - No. of parameters to consider */
477 /* @arg_info - An array to store the result info */
478 /* */
479 /* Returns - Size of the activation frame */
480 /* */
481 /*------------------------------------------------------------------*/
484 mono_arch_get_argument_info (MonoMethodSignature *csig,
485 int param_count,
486 MonoJitArgumentInfo *arg_info)
488 int k, frame_size = 0;
489 int size, align, pad;
490 int offset = 8;
492 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
493 frame_size += sizeof (gpointer);
494 offset += 8;
497 arg_info [0].offset = offset;
499 if (csig->hasthis) {
500 frame_size += sizeof (gpointer);
501 offset += 8;
504 arg_info [0].size = frame_size;
506 for (k = 0; k < param_count; k++) {
508 if (csig->pinvoke)
509 size = mono_type_native_stack_size (csig->params [k], &align);
510 else
511 size = mini_type_stack_size (NULL, csig->params [k], &align);
513 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
514 arg_info [k].pad = pad;
515 frame_size += size;
516 arg_info [k + 1].pad = 0;
517 arg_info [k + 1].size = size;
518 offset += pad;
519 arg_info [k + 1].offset = offset;
520 offset += size;
523 align = MONO_ARCH_FRAME_ALIGNMENT;
524 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
525 arg_info [k].pad = pad;
527 return frame_size;
530 /*========================= End of Function ========================*/
532 /*------------------------------------------------------------------*/
533 /* */
534 /* Name - retFitsInReg. */
535 /* */
536 /* Function - Determines if a value can be returned in one or */
537 /* two registers. */
538 /* */
539 /*------------------------------------------------------------------*/
541 static inline gboolean
542 retFitsInReg(guint32 size)
544 switch (size) {
545 case 0:
546 case 1:
547 case 2:
548 case 4:
549 case 8:
550 return (TRUE);
551 break;
552 default:
553 return (FALSE);
557 /*========================= End of Function ========================*/
559 /*------------------------------------------------------------------*/
560 /* */
561 /* Name - backStackPtr. */
562 /* */
563 /* Function - Restore Stack Pointer to previous frame. */
564 /* */
565 /*------------------------------------------------------------------*/
567 static inline guint8 *
568 backUpStackPtr(MonoCompile *cfg, guint8 *code)
570 int stackSize = cfg->stack_usage;
572 if (s390_is_imm16 (stackSize)) {
573 s390_aghi (code, STK_BASE, stackSize);
574 } else {
575 while (stackSize > 32767) {
576 s390_aghi (code, STK_BASE, 32767);
577 stackSize -= 32767;
579 s390_aghi (code, STK_BASE, stackSize);
581 return (code);
584 /*========================= End of Function ========================*/
586 /*------------------------------------------------------------------*/
587 /* */
588 /* Name - indent */
589 /* */
590 /* Function - Perform nice indenting to current level */
591 /* */
592 /*------------------------------------------------------------------*/
594 static void
595 indent (int diff) {
596 int v;
597 if (diff < 0)
598 indent_level += diff;
599 v = indent_level;
600 printf("[%3d] ",v);
601 while (v-- > 0) {
602 printf (". ");
604 if (diff > 0)
605 indent_level += diff;
608 /*========================= End of Function ========================*/
610 /*------------------------------------------------------------------*/
611 /* */
612 /* Name - decodeParm */
613 /* */
614 /* Function - Decode a parameter for the trace. */
615 /* */
616 /*------------------------------------------------------------------*/
618 static void
619 decodeParm(MonoType *type, void *curParm, int size)
621 guint32 simpleType;
623 if (type->byref) {
624 printf("[BYREF:%p], ", *((char **) curParm));
625 } else {
626 simpleType = mono_type_get_underlying_type(type)->type;
627 enum_parmtype:
628 switch (simpleType) {
629 case MONO_TYPE_I :
630 printf ("[INTPTR:%p], ", *((int **) curParm));
631 break;
632 case MONO_TYPE_U :
633 printf ("[UINTPTR:%p], ", *((int **) curParm));
634 break;
635 case MONO_TYPE_BOOLEAN :
636 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
637 break;
638 case MONO_TYPE_CHAR :
639 printf ("[CHAR:%c], ", *((int *) curParm));
640 break;
641 case MONO_TYPE_I1 :
642 printf ("[INT1:%ld], ", *((gint64 *) curParm));
643 break;
644 case MONO_TYPE_I2 :
645 printf ("[INT2:%ld], ", *((gint64 *) curParm));
646 break;
647 case MONO_TYPE_I4 :
648 printf ("[INT4:%ld], ", *((gint64 *) curParm));
649 break;
650 case MONO_TYPE_U1 :
651 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
652 break;
653 case MONO_TYPE_U2 :
654 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
655 break;
656 case MONO_TYPE_U4 :
657 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
658 break;
659 case MONO_TYPE_U8 :
660 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
661 break;
662 case MONO_TYPE_STRING : {
663 MonoString *s = *((MonoString **) curParm);
664 if (s) {
665 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
666 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
667 } else {
668 printf("[STRING:null], ");
670 break;
672 case MONO_TYPE_CLASS :
673 case MONO_TYPE_OBJECT : {
674 MonoObject *obj = *((MonoObject **) curParm);
675 MonoClass *class;
676 if ((obj) && (obj->vtable)) {
677 printf("[CLASS/OBJ:");
678 class = obj->vtable->klass;
679 printf("%p [%p] ",obj,curParm);
680 if (class == mono_defaults.string_class) {
681 printf("[STRING:%p:%s]",
682 obj, mono_string_to_utf8 ((MonoString *) obj));
683 } else if (class == mono_defaults.int32_class) {
684 printf("[INT32:%p:%d]",
685 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
686 } else
687 printf("[%s.%s:%p]",
688 class->name_space, class->name, obj);
689 printf("], ");
690 } else {
691 printf("[OBJECT:null], ");
693 break;
695 case MONO_TYPE_PTR :
696 printf("[PTR:%p], ", *((gpointer **) (curParm)));
697 break;
698 case MONO_TYPE_FNPTR :
699 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
700 break;
701 case MONO_TYPE_ARRAY :
702 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
703 break;
704 case MONO_TYPE_SZARRAY :
705 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
706 break;
707 case MONO_TYPE_I8 :
708 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
709 break;
710 case MONO_TYPE_R4 :
711 printf("[FLOAT4:%g], ", *((float *) (curParm)));
712 break;
713 case MONO_TYPE_R8 :
714 printf("[FLOAT8:%g], ", *((double *) (curParm)));
715 break;
716 case MONO_TYPE_VALUETYPE : {
717 int i;
718 MonoMarshalType *info;
720 if (type->data.klass->enumtype) {
721 simpleType = mono_class_enum_basetype (type->data.klass)->type;
722 printf("{VALUETYPE} - ");
723 goto enum_parmtype;
726 info = mono_marshal_load_type_info (type->data.klass);
728 if ((info->native_size == sizeof(float)) &&
729 (info->num_fields == 1) &&
730 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
731 printf("[FLOAT4:%f], ", *((float *) (curParm)));
732 break;
735 if ((info->native_size == sizeof(double)) &&
736 (info->num_fields == 1) &&
737 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
738 printf("[FLOAT8:%g], ", *((double *) (curParm)));
739 break;
742 printf("[VALUETYPE:");
743 for (i = 0; i < size; i++)
744 printf("%02x,", *((guint8 *)curParm+i));
745 printf("]");
746 break;
748 case MONO_TYPE_TYPEDBYREF: {
749 int i;
750 printf("[TYPEDBYREF:");
751 for (i = 0; i < size; i++)
752 printf("%02x,", *((guint8 *)curParm+i));
753 printf("]");
754 break;
756 default :
757 printf("[?? - %d], ",simpleType);
762 /*========================= End of Function ========================*/
764 /*------------------------------------------------------------------*/
765 /* */
766 /* Name - enter_method */
767 /* */
768 /* Function - Perform tracing of the entry to the current */
769 /* method. */
770 /* */
771 /*------------------------------------------------------------------*/
773 static void
774 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
776 int i, oParm = 0, iParm = 0;
777 MonoClass *class;
778 MonoObject *obj;
779 MonoMethodSignature *sig;
780 char *fname;
781 guint64 ip;
782 CallInfo *cinfo;
783 ArgInfo *ainfo;
784 void *curParm;
786 fname = mono_method_full_name (method, TRUE);
787 indent (1);
788 printf ("ENTER: %s ", fname);
789 g_free (fname);
791 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
792 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
794 if (rParm == NULL)
795 return;
797 sig = mono_method_signature (method);
799 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
801 if (cinfo->struct_ret) {
802 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
803 iParm = 1;
806 if (sig->hasthis) {
807 gpointer *this = (gpointer *) rParm->gr[iParm];
808 obj = (MonoObject *) this;
809 if (method->klass->valuetype) {
810 if (obj) {
811 printf("this:[value:%p:%016lx], ",
812 this, *((guint64 *)(this+sizeof(MonoObject))));
813 } else
814 printf ("this:[NULL], ");
815 } else {
816 if (obj) {
817 class = obj->vtable->klass;
818 if (class == mono_defaults.string_class) {
819 printf ("this:[STRING:%p:%s], ",
820 obj, mono_string_to_utf8 ((MonoString *)obj));
821 } else {
822 printf ("this:%p[%s.%s], ",
823 obj, class->name_space, class->name);
825 } else
826 printf ("this:NULL, ");
828 oParm++;
831 for (i = 0; i < sig->param_count; ++i) {
832 ainfo = &cinfo->args[i + oParm];
833 switch (ainfo->regtype) {
834 case RegTypeGeneral :
835 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
836 break;
837 case RegTypeFP :
838 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
839 break;
840 case RegTypeBase :
841 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
842 break;
843 case RegTypeStructByVal :
844 if (ainfo->reg != STK_BASE) {
845 int offset = sizeof(glong) - ainfo->size;
846 curParm = &(rParm->gr[ainfo->reg-2])+offset;
848 else
849 curParm = sp+ainfo->offset;
851 if (retFitsInReg (ainfo->vtsize))
852 decodeParm(sig->params[i],
853 curParm,
854 ainfo->size);
855 else
856 decodeParm(sig->params[i],
857 *((char **) curParm),
858 ainfo->vtsize);
859 break;
860 case RegTypeStructByAddr :
861 if (ainfo->reg != STK_BASE)
862 curParm = &(rParm->gr[ainfo->reg-2]);
863 else
864 curParm = sp+ainfo->offset;
866 decodeParm(sig->params[i],
867 *((char **) curParm),
868 ainfo->vtsize);
869 break;
871 default :
872 printf("???, ");
875 printf("\n");
876 g_free(cinfo);
879 /*========================= End of Function ========================*/
881 /*------------------------------------------------------------------*/
882 /* */
883 /* Name - leave_method */
884 /* */
885 /* Function - */
886 /* */
887 /*------------------------------------------------------------------*/
889 static void
890 leave_method (MonoMethod *method, ...)
892 MonoType *type;
893 char *fname;
894 guint64 ip;
895 va_list ap;
897 va_start(ap, method);
899 fname = mono_method_full_name (method, TRUE);
900 indent (-1);
901 printf ("LEAVE: %s", fname);
902 g_free (fname);
904 type = mono_method_signature (method)->ret;
906 handle_enum:
907 switch (type->type) {
908 case MONO_TYPE_VOID:
909 break;
910 case MONO_TYPE_BOOLEAN: {
911 int val = va_arg (ap, int);
912 if (val)
913 printf ("[TRUE:%d]", val);
914 else
915 printf ("[FALSE]");
917 break;
919 case MONO_TYPE_CHAR: {
920 int val = va_arg (ap, int);
921 printf ("[CHAR:%d]", val);
922 break;
924 case MONO_TYPE_I1: {
925 int val = va_arg (ap, int);
926 printf ("[INT1:%d]", val);
927 break;
929 case MONO_TYPE_U1: {
930 int val = va_arg (ap, int);
931 printf ("[UINT1:%d]", val);
932 break;
934 case MONO_TYPE_I2: {
935 int val = va_arg (ap, int);
936 printf ("[INT2:%d]", val);
937 break;
939 case MONO_TYPE_U2: {
940 int val = va_arg (ap, int);
941 printf ("[UINT2:%d]", val);
942 break;
944 case MONO_TYPE_I4: {
945 int val = va_arg (ap, int);
946 printf ("[INT4:%d]", val);
947 break;
949 case MONO_TYPE_U4: {
950 int val = va_arg (ap, int);
951 printf ("[UINT4:%d]", val);
952 break;
954 case MONO_TYPE_I: {
955 gint64 val = va_arg (ap, gint64);
956 printf ("[INT:%ld]", val);
957 printf("]");
958 break;
960 case MONO_TYPE_U: {
961 gint64 val = va_arg (ap, gint64);
962 printf ("[UINT:%lu]", val);
963 printf("]");
964 break;
966 case MONO_TYPE_STRING: {
967 MonoString *s = va_arg (ap, MonoString *);
969 if (s) {
970 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
971 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
972 } else
973 printf ("[STRING:null], ");
974 break;
976 case MONO_TYPE_CLASS:
977 case MONO_TYPE_OBJECT: {
978 MonoObject *o = va_arg (ap, MonoObject *);
980 if ((o) && (o->vtable)) {
981 if (o->vtable->klass == mono_defaults.boolean_class) {
982 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
983 } else if (o->vtable->klass == mono_defaults.int32_class) {
984 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
985 } else if (o->vtable->klass == mono_defaults.int64_class) {
986 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
987 } else
988 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
989 } else
990 printf ("[OBJECT:%p]", o);
992 break;
994 case MONO_TYPE_PTR:
995 case MONO_TYPE_FNPTR:
996 case MONO_TYPE_ARRAY:
997 case MONO_TYPE_SZARRAY: {
998 gpointer p = va_arg (ap, gpointer);
999 printf ("[result=%p]", p);
1000 break;
1002 case MONO_TYPE_I8: {
1003 gint64 l = va_arg (ap, gint64);
1004 printf ("[LONG:%ld]", l);
1005 break;
1007 case MONO_TYPE_U8: {
1008 guint64 l = va_arg (ap, guint64);
1009 printf ("[ULONG:%lu]", l);
1010 break;
1012 case MONO_TYPE_R4: {
1013 double f = va_arg (ap, double);
1014 printf ("[FLOAT4:%g]\n", f);
1015 break;
1017 case MONO_TYPE_R8: {
1018 double f = va_arg (ap, double);
1019 printf ("[FLOAT8:%g]\n", f);
1020 break;
1022 case MONO_TYPE_VALUETYPE: {
1023 MonoMarshalType *info;
1024 if (type->data.klass->enumtype) {
1025 type = mono_class_enum_basetype (type->data.klass);
1026 goto handle_enum;
1027 } else {
1028 guint8 *p = va_arg (ap, gpointer);
1029 int j, size, align;
1031 info = mono_marshal_load_type_info (type->data.klass);
1033 if ((info->native_size == sizeof(float)) &&
1034 (info->num_fields == 1) &&
1035 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1036 double f = va_arg (ap, double);
1037 printf("[FLOAT4:%g]\n", (double) f);
1038 break;
1041 if ((info->native_size == sizeof(double)) &&
1042 (info->num_fields == 1) &&
1043 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1044 double f = va_arg (ap, double);
1045 printf("[FLOAT8:%g]\n", f);
1046 break;
1049 size = mono_type_size (type, &align);
1050 switch (size) {
1051 case 1:
1052 case 2:
1053 case 4:
1054 case 8:
1055 printf ("[");
1056 for (j = 0; p && j < size; j++)
1057 printf ("%02x,", p [j]);
1058 printf ("]\n");
1059 break;
1060 default:
1061 printf ("[VALUETYPE]\n");
1064 break;
1066 case MONO_TYPE_TYPEDBYREF: {
1067 guint8 *p = va_arg (ap, gpointer);
1068 int j, size, align;
1069 size = mono_type_size (type, &align);
1070 switch (size) {
1071 case 1:
1072 case 2:
1073 case 4:
1074 case 8:
1075 printf ("[");
1076 for (j = 0; p && j < size; j++)
1077 printf ("%02x,", p [j]);
1078 printf ("]\n");
1079 break;
1080 default:
1081 printf ("[TYPEDBYREF]\n");
1084 break;
1085 default:
1086 printf ("(unknown return type %x)",
1087 mono_method_signature (method)->ret->type);
1090 ip = ((gint64) __builtin_return_address (0));
1091 printf (" ip: %p\n", (gpointer) ip);
1094 /*========================= End of Function ========================*/
1096 /*------------------------------------------------------------------*/
1097 /* */
1098 /* Name - catch_SIGILL */
1099 /* */
1100 /* Function - Catch SIGILL as a result of testing for long */
1101 /* displacement facility. */
1102 /* */
1103 /*------------------------------------------------------------------*/
1105 void
1106 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1108 has_ld = 0;
1112 /*========================= End of Function ========================*/
1114 /*------------------------------------------------------------------*/
1115 /* */
1116 /* Name - mono_arch_cpu_init */
1117 /* */
1118 /* Function - Perform CPU specific initialization to execute */
1119 /* managed code. */
1120 /* */
1121 /*------------------------------------------------------------------*/
1123 void
1124 mono_arch_cpu_init (void)
1126 struct sigaction sa,
1127 *oldSa = NULL;
1128 guint mode = 1;
1130 /*--------------------------------------*/
1131 /* Set default rounding mode for FP */
1132 /*--------------------------------------*/
1133 __asm__ ("SRNM\t%0\n\t"
1134 : : "m" (mode));
1136 /*--------------------------------------*/
1137 /* Determine if we have long displace- */
1138 /* ment facility on this processor */
1139 /*--------------------------------------*/
1140 sa.sa_sigaction = catch_SIGILL;
1141 sigemptyset (&sa.sa_mask);
1142 sa.sa_flags = SA_SIGINFO;
1144 sigaction (SIGILL, &sa, oldSa);
1146 /*--------------------------------------*/
1147 /* We test by executing the STY inst */
1148 /*--------------------------------------*/
1149 __asm__ ("LGHI\t0,1\n\t"
1150 "LA\t1,%0\n\t"
1151 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1152 : "=m" (has_ld) : : "0", "1");
1154 sigaction (SIGILL, oldSa, NULL);
1157 /*========================= End of Function ========================*/
1161 * Initialize architecture specific code.
1163 void
1164 mono_arch_init (void)
1169 * Cleanup architecture specific code.
1171 void
1172 mono_arch_cleanup (void)
1176 /*------------------------------------------------------------------*/
1177 /* */
1178 /* Name - mono_arch_cpu_optimizazions */
1179 /* */
1180 /* Function - Returns the optimizations supported on this CPU */
1181 /* */
1182 /*------------------------------------------------------------------*/
1184 guint32
1185 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1187 guint32 opts = 0;
1189 /*----------------------------------------------------------*/
1190 /* No s390-specific optimizations yet */
1191 /*----------------------------------------------------------*/
1192 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1193 // *exclude_mask = MONO_OPT_INLINE;
1194 return opts;
1197 /*========================= End of Function ========================*/
1199 /*------------------------------------------------------------------*/
1200 /* */
1201 /* Name - */
1202 /* */
1203 /* Function - */
1204 /* */
1205 /*------------------------------------------------------------------*/
1207 static gboolean
1208 is_regsize_var (MonoType *t) {
1209 if (t->byref)
1210 return TRUE;
1211 switch (mono_type_get_underlying_type (t)->type) {
1212 case MONO_TYPE_I4:
1213 case MONO_TYPE_U4:
1214 case MONO_TYPE_I:
1215 case MONO_TYPE_I8:
1216 case MONO_TYPE_U8:
1217 case MONO_TYPE_U:
1218 case MONO_TYPE_PTR:
1219 case MONO_TYPE_FNPTR:
1220 return TRUE;
1221 case MONO_TYPE_OBJECT:
1222 case MONO_TYPE_STRING:
1223 case MONO_TYPE_CLASS:
1224 case MONO_TYPE_SZARRAY:
1225 case MONO_TYPE_ARRAY:
1226 return FALSE;
1227 case MONO_TYPE_VALUETYPE:
1228 if (t->data.klass->enumtype)
1229 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1230 return FALSE;
1232 return FALSE;
1235 /*========================= End of Function ========================*/
1237 /*------------------------------------------------------------------*/
1238 /* */
1239 /* Name - mono_arch_get_allocatable_int_vars */
1240 /* */
1241 /* Function - */
1242 /* */
1243 /*------------------------------------------------------------------*/
1245 GList *
1246 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1248 GList *vars = NULL;
1249 int i;
1251 for (i = 0; i < cfg->num_varinfo; i++) {
1252 MonoInst *ins = cfg->varinfo [i];
1253 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1255 /* unused vars */
1256 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1257 continue;
1259 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1260 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1261 continue;
1263 /* we can only allocate 32 bit values */
1264 if (is_regsize_var (ins->inst_vtype)) {
1265 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1266 g_assert (i == vmv->idx);
1267 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1271 return vars;
1274 /*========================= End of Function ========================*/
1276 /*------------------------------------------------------------------*/
1277 /* */
1278 /* Name - mono_arch_global_int_regs */
1279 /* */
1280 /* Function - Return a list of usable integer registers. */
1281 /* */
1282 /*------------------------------------------------------------------*/
1284 GList *
1285 mono_arch_get_global_int_regs (MonoCompile *cfg)
1287 GList *regs = NULL;
1288 MonoMethodHeader *header;
1289 int i, top = 13;
1291 header = mono_method_get_header (cfg->method);
1292 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1293 cfg->frame_reg = s390_r11;
1296 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1297 top = 12;
1298 for (i = 8; i < top; ++i) {
1299 if (cfg->frame_reg != i)
1300 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1303 return regs;
1306 /*========================= End of Function ========================*/
1308 /*------------------------------------------------------------------*/
1309 /* */
1310 /* Name - mono_arch_flush_icache */
1311 /* */
1312 /* Function - Flush the CPU icache. */
1313 /* */
1314 /*------------------------------------------------------------------*/
1316 void
1317 mono_arch_flush_icache (guint8 *code, gint size)
1321 /*========================= End of Function ========================*/
1323 /*------------------------------------------------------------------*/
1324 /* */
1325 /* Name - add_general */
1326 /* */
1327 /* Function - Determine code and stack size incremements for a */
1328 /* parameter. */
1329 /* */
1330 /*------------------------------------------------------------------*/
1332 static void inline
1333 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1335 if (*gr > S390_LAST_ARG_REG) {
1336 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1337 ainfo->offset = sz->stack_size;
1338 ainfo->reg = STK_BASE;
1339 ainfo->regtype = RegTypeBase;
1340 sz->stack_size += sizeof(long);
1341 sz->local_size += sizeof(long);
1342 sz->offStruct += sizeof(long);
1343 sz->code_size += 12;
1344 } else {
1345 ainfo->reg = *gr;
1346 sz->code_size += 8;
1348 (*gr) ++;
1351 /*========================= End of Function ========================*/
1353 /*------------------------------------------------------------------*/
1354 /* */
1355 /* Name - add_stackParm */
1356 /* */
1357 /* Function - Determine code and stack size incremements for a */
1358 /* parameter. */
1359 /* */
1360 /*------------------------------------------------------------------*/
1362 static void inline
1363 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1365 if (*gr > S390_LAST_ARG_REG) {
1366 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1367 ainfo->reg = STK_BASE;
1368 ainfo->offset = sz->stack_size;
1369 ainfo->regtype = RegTypeStructByAddrOnStack;
1370 sz->stack_size += sizeof (gpointer);
1371 sz->parm_size += sizeof(gpointer);
1372 sz->offStruct += sizeof(gpointer);
1373 } else {
1374 ainfo->reg = *gr;
1375 ainfo->offset = sz->stack_size;
1376 ainfo->regtype = RegTypeStructByAddr;
1378 (*gr) ++;
1379 ainfo->offparm = sz->offset;
1380 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1381 ainfo->size = size;
1382 ainfo->vtsize = size;
1383 sz->parm_size += size;
1386 /*========================= End of Function ========================*/
1388 /*------------------------------------------------------------------*/
1389 /* */
1390 /* Name - add_float */
1391 /* */
1392 /* Function - Determine code and stack size incremements for a */
1393 /* float parameter. */
1394 /* */
1395 /*------------------------------------------------------------------*/
1397 static void inline
1398 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1400 if ((*fr) <= S390_LAST_FPARG_REG) {
1401 ainfo->regtype = RegTypeFP;
1402 ainfo->reg = *fr;
1403 sz->code_size += 4;
1404 (*fr) += 2;
1406 else {
1407 ainfo->offset = sz->stack_size;
1408 ainfo->reg = STK_BASE;
1409 ainfo->regtype = RegTypeBase;
1410 sz->code_size += 4;
1411 sz->stack_size += sizeof(double);
1412 sz->local_size += sizeof(double);
1413 sz->offStruct += sizeof(double);
1417 /*========================= End of Function ========================*/
1419 /*------------------------------------------------------------------*/
1420 /* */
1421 /* Name - get_call_info */
1422 /* */
1423 /* Function - Determine the amount of space required for code */
1424 /* and stack. In addition determine starting points */
1425 /* for stack-based parameters, and area for struct- */
1426 /* ures being returned on the stack. */
1427 /* */
1428 /*------------------------------------------------------------------*/
1430 static CallInfo *
1431 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1433 guint i, fr, gr, size;
1434 int nParm = sig->hasthis + sig->param_count;
1435 MonoType *ret_type;
1436 guint32 simpletype, align;
1437 CallInfo *cinfo;
1438 size_data *sz;
1439 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1441 if (mp)
1442 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1443 else
1444 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1446 fr = 0;
1447 gr = s390_r2;
1448 nParm = 0;
1449 cinfo->struct_ret = 0;
1450 sz = &cinfo->sz;
1451 sz->retStruct = 0;
1452 sz->offset = 0;
1453 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1454 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1455 sz->code_size = 0;
1456 sz->parm_size = 0;
1457 sz->local_size = 0;
1459 /*----------------------------------------------------------*/
1460 /* We determine the size of the return code/stack in case we*/
1461 /* need to reserve a register to be used to address a stack */
1462 /* area that the callee will use. */
1463 /*----------------------------------------------------------*/
1465 ret_type = mono_type_get_underlying_type (sig->ret);
1466 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1467 simpletype = ret_type->type;
1468 enum_retvalue:
1469 switch (simpletype) {
1470 case MONO_TYPE_BOOLEAN:
1471 case MONO_TYPE_I1:
1472 case MONO_TYPE_U1:
1473 case MONO_TYPE_I2:
1474 case MONO_TYPE_U2:
1475 case MONO_TYPE_CHAR:
1476 case MONO_TYPE_I4:
1477 case MONO_TYPE_U4:
1478 case MONO_TYPE_I:
1479 case MONO_TYPE_U:
1480 case MONO_TYPE_CLASS:
1481 case MONO_TYPE_OBJECT:
1482 case MONO_TYPE_SZARRAY:
1483 case MONO_TYPE_ARRAY:
1484 case MONO_TYPE_PTR:
1485 case MONO_TYPE_FNPTR:
1486 case MONO_TYPE_STRING:
1487 cinfo->ret.reg = s390_r2;
1488 sz->code_size += 4;
1489 break;
1490 case MONO_TYPE_R4:
1491 case MONO_TYPE_R8:
1492 cinfo->ret.reg = s390_f0;
1493 sz->code_size += 4;
1494 break;
1495 case MONO_TYPE_I8:
1496 case MONO_TYPE_U8:
1497 cinfo->ret.reg = s390_r2;
1498 sz->code_size += 4;
1499 break;
1500 case MONO_TYPE_GENERICINST:
1501 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1502 cinfo->ret.reg = s390_r2;
1503 sz->code_size += 4;
1504 break;
1506 /* Fall through */
1507 case MONO_TYPE_VALUETYPE: {
1508 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1509 if (klass->enumtype) {
1510 simpletype = mono_class_enum_basetype (klass)->type;
1511 goto enum_retvalue;
1513 if (sig->pinvoke)
1514 size = mono_class_native_size (klass, &align);
1515 else
1516 size = mono_class_value_size (klass, &align);
1518 cinfo->ret.reg = s390_r2;
1519 cinfo->struct_ret = 1;
1520 cinfo->ret.size = size;
1521 cinfo->ret.vtsize = size;
1522 gr++;
1523 break;
1525 case MONO_TYPE_TYPEDBYREF:
1526 size = sizeof (MonoTypedRef);
1527 cinfo->ret.reg = s390_r2;
1528 cinfo->struct_ret = 1;
1529 cinfo->ret.size = size;
1530 cinfo->ret.vtsize = size;
1531 gr++;
1532 break;
1533 case MONO_TYPE_VOID:
1534 break;
1535 default:
1536 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1539 if (sig->hasthis) {
1540 cinfo->args[nParm].size = sizeof(gpointer);
1541 add_general (&gr, sz, cinfo->args+nParm);
1542 nParm++;
1545 /*----------------------------------------------------------*/
1546 /* We determine the size of the parameter code and stack */
1547 /* requirements by checking the types and sizes of the */
1548 /* parameters. */
1549 /*----------------------------------------------------------*/
1551 for (i = 0; i < sig->param_count; ++i) {
1552 MonoType *ptype;
1554 /*--------------------------------------------------*/
1555 /* Handle vararg type calls. All args are put on */
1556 /* the stack. */
1557 /*--------------------------------------------------*/
1558 if ((sig->call_convention == MONO_CALL_VARARG) &&
1559 (i == sig->sentinelpos)) {
1560 gr = S390_LAST_ARG_REG + 1;
1561 add_general (&gr, sz, &cinfo->sigCookie);
1564 if (sig->params [i]->byref) {
1565 add_general (&gr, sz, cinfo->args+nParm);
1566 cinfo->args[nParm].size = sizeof(gpointer);
1567 nParm++;
1568 continue;
1571 ptype = mono_type_get_underlying_type (sig->params [i]);
1572 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1573 simpletype = ptype->type;
1574 cinfo->args[nParm].type = simpletype;
1575 switch (simpletype) {
1576 case MONO_TYPE_BOOLEAN:
1577 case MONO_TYPE_I1:
1578 case MONO_TYPE_U1:
1579 cinfo->args[nParm].size = sizeof(char);
1580 add_general (&gr, sz, cinfo->args+nParm);
1581 nParm++;
1582 break;
1583 case MONO_TYPE_I2:
1584 case MONO_TYPE_U2:
1585 case MONO_TYPE_CHAR:
1586 cinfo->args[nParm].size = sizeof(short);
1587 add_general (&gr, sz, cinfo->args+nParm);
1588 nParm++;
1589 break;
1590 case MONO_TYPE_I4:
1591 case MONO_TYPE_U4:
1592 cinfo->args[nParm].size = sizeof(int);
1593 add_general (&gr, sz, cinfo->args+nParm);
1594 nParm++;
1595 break;
1596 case MONO_TYPE_I:
1597 case MONO_TYPE_U:
1598 case MONO_TYPE_PTR:
1599 case MONO_TYPE_FNPTR:
1600 case MONO_TYPE_CLASS:
1601 case MONO_TYPE_OBJECT:
1602 case MONO_TYPE_STRING:
1603 case MONO_TYPE_SZARRAY:
1604 case MONO_TYPE_ARRAY:
1605 cinfo->args[nParm].size = sizeof(gpointer);
1606 add_general (&gr, sz, cinfo->args+nParm);
1607 nParm++;
1608 break;
1609 case MONO_TYPE_I8:
1610 case MONO_TYPE_U8:
1611 cinfo->args[nParm].size = sizeof(long long);
1612 add_general (&gr, sz, cinfo->args+nParm);
1613 nParm++;
1614 break;
1615 case MONO_TYPE_R4:
1616 cinfo->args[nParm].size = sizeof(float);
1617 add_float (&fr, sz, cinfo->args+nParm);
1618 nParm++;
1619 break;
1620 case MONO_TYPE_R8:
1621 cinfo->args[nParm].size = sizeof(double);
1622 add_float (&fr, sz, cinfo->args+nParm);
1623 nParm++;
1624 break;
1625 case MONO_TYPE_GENERICINST:
1626 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1627 cinfo->args[nParm].size = sizeof(gpointer);
1628 add_general (&gr, sz, cinfo->args+nParm);
1629 nParm++;
1630 break;
1632 /* Fall through */
1633 case MONO_TYPE_VALUETYPE: {
1634 MonoMarshalType *info;
1635 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1636 if (sig->pinvoke)
1637 size = mono_class_native_size (klass, &align);
1638 else
1639 size = mono_class_value_size (klass, &align);
1641 info = mono_marshal_load_type_info (klass);
1643 if ((info->native_size == sizeof(float)) &&
1644 (info->num_fields == 1) &&
1645 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1646 cinfo->args[nParm].size = sizeof(float);
1647 add_float(&fr, sz, cinfo->args+nParm);
1648 nParm ++;
1649 break;
1652 if ((info->native_size == sizeof(double)) &&
1653 (info->num_fields == 1) &&
1654 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1655 cinfo->args[nParm].size = sizeof(double);
1656 add_float(&fr, sz, cinfo->args+nParm);
1657 nParm ++;
1658 break;
1661 cinfo->args[nParm].vtsize = 0;
1662 cinfo->args[nParm].size = 0;
1664 switch (size) {
1665 /*----------------------------------*/
1666 /* On S/390, structures of size 1, */
1667 /* 2, 4, and 8 bytes are passed in */
1668 /* (a) register(s). */
1669 /*----------------------------------*/
1670 case 0:
1671 case 1:
1672 case 2:
1673 case 4:
1674 case 8:
1675 add_general(&gr, sz, cinfo->args+nParm);
1676 cinfo->args[nParm].size = size;
1677 cinfo->args[nParm].regtype = RegTypeStructByVal;
1678 nParm++;
1679 sz->local_size += sizeof(long);
1680 break;
1681 default:
1682 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1683 nParm++;
1686 break;
1687 case MONO_TYPE_TYPEDBYREF: {
1688 int size = sizeof (MonoTypedRef);
1690 cinfo->args[nParm].vtsize = 0;
1691 cinfo->args[nParm].size = 0;
1693 switch (size) {
1694 /*----------------------------------*/
1695 /* On S/390, structures of size 1, */
1696 /* 2, 4, and 8 bytes are passed in */
1697 /* (a) register(s). */
1698 /*----------------------------------*/
1699 case 0:
1700 case 1:
1701 case 2:
1702 case 4:
1703 case 8:
1704 add_general(&gr, sz, cinfo->args+nParm);
1705 cinfo->args[nParm].size = size;
1706 cinfo->args[nParm].regtype = RegTypeStructByVal;
1707 nParm++;
1708 sz->local_size += sizeof(long);
1709 break;
1710 default:
1711 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1712 nParm++;
1715 break;
1716 default:
1717 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
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);
1730 /*----------------------------------------------------------*/
1731 /* If we are passing a structure back then if it won't be */
1732 /* in a register(s) then we make room at the end of the */
1733 /* parameters that may have been placed on the stack */
1734 /*----------------------------------------------------------*/
1735 if (cinfo->struct_ret) {
1736 cinfo->ret.offset = sz->stack_size;
1737 switch (cinfo->ret.size) {
1738 case 0:
1739 case 1:
1740 case 2:
1741 case 4:
1742 case 8:
1743 break;
1744 default:
1745 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1749 cinfo->lastgr = gr;
1750 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1751 sz->offset;
1752 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1754 return (cinfo);
1757 /*========================= End of Function ========================*/
1759 /*------------------------------------------------------------------*/
1760 /* */
1761 /* Name - mono_arch_allocate_vars */
1762 /* */
1763 /* Function - Set var information according to the calling */
1764 /* convention for S/390. The local var stuff should */
1765 /* most likely be split in another method. */
1766 /* */
1767 /* Parameter - @m - Compile unit. */
1768 /* */
1769 /*------------------------------------------------------------------*/
1771 void
1772 mono_arch_allocate_vars (MonoCompile *cfg)
1774 MonoMethodSignature *sig;
1775 MonoMethodHeader *header;
1776 MonoInst *inst;
1777 CallInfo *cinfo;
1778 int iParm, iVar, offset, size, align, curinst;
1779 int frame_reg = STK_BASE;
1780 int sArg, eArg;
1782 header = mono_method_get_header (cfg->method);
1784 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1786 /*---------------------------------------------------------*/
1787 /* We use the frame register also for any method that has */
1788 /* filter clauses. This way, when the handlers are called, */
1789 /* the code will reference local variables using the frame */
1790 /* reg instead of the stack pointer: if we had to restore */
1791 /* the stack pointer, we'd corrupt the method frames that */
1792 /* are already on the stack (since filters get called */
1793 /* before stack unwinding happens) when the filter code */
1794 /* would call any method. */
1795 /*---------------------------------------------------------*/
1796 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1797 frame_reg = s390_r11;
1799 cfg->frame_reg = frame_reg;
1801 cfg->arch.bkchain_reg = -1;
1803 if (frame_reg != STK_BASE)
1804 cfg->used_int_regs |= 1 << frame_reg;
1806 sig = mono_method_signature (cfg->method);
1808 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1810 if (!cinfo->struct_ret) {
1811 switch (mono_type_get_underlying_type (sig->ret)->type) {
1812 case MONO_TYPE_VOID:
1813 break;
1814 default:
1815 cfg->ret->opcode = OP_REGVAR;
1816 cfg->ret->dreg = s390_r2;
1817 break;
1821 /*--------------------------------------------------------------*/
1822 /* local vars are at a positive offset from the stack pointer */
1823 /* also note that if the function uses alloca, we use s390_r11 */
1824 /* to point at the local variables. */
1825 /* add parameter area size for called functions */
1826 /*--------------------------------------------------------------*/
1827 offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
1828 cfg->sig_cookie = 0;
1830 if (cinfo->struct_ret) {
1831 inst = cfg->vret_addr;
1832 offset = S390_ALIGN(offset, sizeof(gpointer));
1833 inst->inst_offset = offset;
1834 inst->opcode = OP_REGOFFSET;
1835 inst->inst_basereg = frame_reg;
1836 offset += sizeof(gpointer);
1837 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1838 printf ("vret_addr =");
1839 mono_print_ins (cfg->vret_addr);
1843 if (sig->hasthis) {
1844 inst = cfg->args [0];
1845 if (inst->opcode != OP_REGVAR) {
1846 inst->opcode = OP_REGOFFSET;
1847 inst->inst_basereg = frame_reg;
1848 offset = S390_ALIGN(offset, sizeof(gpointer));
1849 inst->inst_offset = offset;
1850 offset += sizeof (gpointer);
1852 curinst = sArg = 1;
1853 } else {
1854 curinst = sArg = 0;
1857 eArg = sig->param_count + sArg;
1859 if (sig->call_convention == MONO_CALL_VARARG)
1860 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1862 for (iParm = sArg; iParm < eArg; ++iParm) {
1863 inst = cfg->args [curinst];
1864 if (inst->opcode != OP_REGVAR) {
1865 switch (cinfo->args[iParm].regtype) {
1866 case RegTypeStructByAddr : {
1867 MonoInst *indir;
1869 size = sizeof (gpointer);
1871 inst->opcode = OP_REGOFFSET;
1872 inst->inst_basereg = frame_reg;
1873 offset = S390_ALIGN (offset, sizeof (gpointer));
1874 inst->inst_offset = offset;
1876 /* Add a level of indirection */
1877 MONO_INST_NEW (cfg, indir, 0);
1878 *indir = *inst;
1879 inst->opcode = OP_VTARG_ADDR;
1880 inst->inst_left = indir;
1882 break;
1883 case RegTypeStructByAddrOnStack : {
1884 MonoInst *indir;
1886 size = sizeof (gpointer);
1888 /* Similar to the == STK_BASE case below */
1889 cfg->arch.bkchain_reg = s390_r12;
1890 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1892 inst->opcode = OP_REGOFFSET;
1893 inst->dreg = mono_alloc_preg (cfg);
1894 inst->inst_basereg = cfg->arch.bkchain_reg;
1895 inst->inst_offset = cinfo->args [iParm].offset;
1897 /* Add a level of indirection */
1898 MONO_INST_NEW (cfg, indir, 0);
1899 *indir = *inst;
1900 inst->opcode = OP_VTARG_ADDR;
1901 inst->inst_left = indir;
1902 break;
1904 case RegTypeStructByVal :
1905 size = cinfo->args[iParm].size;
1906 offset = S390_ALIGN(offset, size);
1907 inst->opcode = OP_REGOFFSET;
1908 inst->inst_basereg = frame_reg;
1909 inst->inst_offset = offset;
1910 break;
1911 default :
1912 if (cinfo->args [iParm].reg == STK_BASE) {
1914 * These arguments are in the previous frame, so we can't
1915 * compute their offset from the current frame pointer right
1916 * now, since cfg->stack_offset is not yet known, so dedicate a
1917 * register holding the previous frame pointer.
1919 cfg->arch.bkchain_reg = s390_r12;
1920 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1922 inst->opcode = OP_REGOFFSET;
1923 inst->inst_basereg = cfg->arch.bkchain_reg;
1924 size = (cinfo->args[iParm].size < 8
1925 ? 8 - cinfo->args[iParm].size
1926 : 0);
1927 inst->inst_offset = cinfo->args [iParm].offset + size;
1928 size = sizeof (long);
1929 } else {
1930 inst->opcode = OP_REGOFFSET;
1931 inst->inst_basereg = frame_reg;
1932 size = (cinfo->args[iParm].size < 8
1933 ? sizeof(int)
1934 : sizeof(long));
1935 offset = S390_ALIGN(offset, size);
1936 inst->inst_offset = offset;
1938 break;
1940 if ((sig->call_convention == MONO_CALL_VARARG) &&
1941 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1942 (iParm < sig->sentinelpos))
1943 cfg->sig_cookie += size;
1945 offset += size;
1947 curinst++;
1950 curinst = cfg->locals_start;
1951 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1952 inst = cfg->varinfo [iVar];
1953 if ((inst->flags & MONO_INST_IS_DEAD) ||
1954 (inst->opcode == OP_REGVAR))
1955 continue;
1957 /*--------------------------------------------------*/
1958 /* inst->backend.is_pinvoke indicates native sized value types, */
1959 /* this is used by the pinvoke wrappers when they */
1960 /* call functions returning structure */
1961 /*--------------------------------------------------*/
1962 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1963 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype), &align);
1964 else
1965 size = mono_type_size (inst->inst_vtype, &align);
1967 offset = S390_ALIGN(offset, align);
1968 inst->inst_offset = offset;
1969 inst->opcode = OP_REGOFFSET;
1970 inst->inst_basereg = frame_reg;
1971 offset += size;
1972 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
1973 iVar, inst->inst_offset, size));
1976 /*------------------------------------------------------*/
1977 /* Allow space for the trace method stack area if needed*/
1978 /*------------------------------------------------------*/
1979 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
1980 offset += S390_TRACE_STACK_SIZE;
1982 /*------------------------------------------------------*/
1983 /* Reserve space to save LMF and caller saved registers */
1984 /*------------------------------------------------------*/
1985 if (cfg->method->save_lmf)
1986 offset += sizeof (MonoLMF);
1988 /*------------------------------------------------------*/
1989 /* align the offset */
1990 /*------------------------------------------------------*/
1991 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1995 /*========================= End of Function ========================*/
1997 /*------------------------------------------------------------------*/
1998 /* */
1999 /* Name - mono_arch_create_vars */
2000 /*------------------------------------------------------------------*/
2002 void
2003 mono_arch_create_vars (MonoCompile *cfg)
2005 MonoMethodSignature *sig;
2006 CallInfo *cinfo;
2008 sig = mono_method_signature (cfg->method);
2010 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2012 if (cinfo->struct_ret) {
2013 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
2014 if (G_UNLIKELY (cfg->verbose_level > 1)) {
2015 printf ("vret_addr = ");
2016 mono_print_ins (cfg->vret_addr);
2021 /*========================= End of Function ========================*/
2023 static void
2024 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2026 MonoInst *ins;
2028 switch (storage) {
2029 case RegTypeGeneral:
2030 MONO_INST_NEW (cfg, ins, OP_MOVE);
2031 ins->dreg = mono_alloc_ireg (cfg);
2032 ins->sreg1 = tree->dreg;
2033 MONO_ADD_INS (cfg->cbb, ins);
2034 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2035 break;
2036 case RegTypeFP:
2037 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2038 ins->dreg = mono_alloc_freg (cfg);
2039 ins->sreg1 = tree->dreg;
2040 MONO_ADD_INS (cfg->cbb, ins);
2041 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2042 break;
2043 case RegTypeFPR4:
2044 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2045 ins->dreg = mono_alloc_freg (cfg);
2046 ins->sreg1 = tree->dreg;
2047 MONO_ADD_INS (cfg->cbb, ins);
2048 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2049 break;
2050 default:
2051 g_assert_not_reached ();
2055 static void
2056 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2058 MonoMethodSignature *tmpSig;
2059 MonoInst *sig_arg;
2061 cfg->disable_aot = TRUE;
2063 /*----------------------------------------------------------*/
2064 /* mono_ArgIterator_Setup assumes the signature cookie is */
2065 /* passed first and all the arguments which were before it */
2066 /* passed on the stack after the signature. So compensate */
2067 /* by passing a different signature. */
2068 /*----------------------------------------------------------*/
2069 tmpSig = mono_metadata_signature_dup (call->signature);
2070 tmpSig->param_count -= call->signature->sentinelpos;
2071 tmpSig->sentinelpos = 0;
2072 if (tmpSig->param_count > 0)
2073 memcpy (tmpSig->params,
2074 call->signature->params + call->signature->sentinelpos,
2075 tmpSig->param_count * sizeof(MonoType *));
2077 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2078 sig_arg->dreg = mono_alloc_ireg (cfg);
2079 sig_arg->inst_p0 = tmpSig;
2080 MONO_ADD_INS (cfg->cbb, sig_arg);
2082 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2083 cinfo->sigCookie.offset, sig_arg->dreg);
2086 /*------------------------------------------------------------------*/
2087 /* */
2088 /* Name - mono_arch_emit_call */
2089 /* */
2090 /*------------------------------------------------------------------*/
2092 void
2093 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2095 MonoInst *in;
2096 MonoMethodSignature *sig;
2097 MonoInst *ins;
2098 int i, n, lParamArea;
2099 CallInfo *cinfo;
2100 ArgInfo *ainfo = NULL;
2101 int stackSize;
2103 sig = call->signature;
2104 n = sig->param_count + sig->hasthis;
2105 DEBUG (g_print ("Call requires: %d parameters\n",n));
2107 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2109 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size + cinfo->sz.parm_size + cinfo->sz.offset;
2110 call->stack_usage = MAX(stackSize, call->stack_usage);
2111 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2112 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2113 cfg->flags |= MONO_CFG_HAS_CALLS;
2115 if (cinfo->struct_ret) {
2116 MONO_INST_NEW (cfg, ins, OP_MOVE);
2117 ins->sreg1 = call->vret_var->dreg;
2118 ins->dreg = mono_alloc_preg (cfg);
2119 MONO_ADD_INS (cfg->cbb, ins);
2120 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2123 for (i = 0; i < n; ++i) {
2124 ainfo = cinfo->args + i;
2125 MonoType *t;
2127 if (i >= sig->hasthis)
2128 t = sig->params [i - sig->hasthis];
2129 else
2130 t = &mono_defaults.int_class->byval_arg;
2131 t = mono_type_get_underlying_type (t);
2133 in = call->args [i];
2135 if ((sig->call_convention == MONO_CALL_VARARG) &&
2136 (i == sig->sentinelpos)) {
2137 emit_sig_cookie (cfg, call, cinfo);
2140 switch (ainfo->regtype) {
2141 case RegTypeGeneral:
2142 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2143 break;
2144 case RegTypeFP:
2145 if (MONO_TYPE_ISSTRUCT (t)) {
2146 /* Valuetype passed in one fp register */
2147 ainfo->regtype = RegTypeStructByValInFP;
2148 /* Fall through */
2149 } else {
2150 if (ainfo->size == 4)
2151 ainfo->regtype = RegTypeFPR4;
2152 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2153 break;
2155 case RegTypeStructByVal:
2156 case RegTypeStructByAddr:
2157 case RegTypeStructByAddrOnStack: {
2158 guint32 align;
2159 guint32 size;
2161 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2162 size = sizeof (MonoTypedRef);
2163 align = sizeof (gpointer);
2165 else
2166 if (sig->pinvoke)
2167 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2168 else {
2170 * Other backends use mono_type_stack_size (), but that
2171 * aligns the size to 8, which is larger than the size of
2172 * the source, leading to reads of invalid memory if the
2173 * source is at the end of address space.
2175 size = mono_class_value_size (in->klass, &align);
2178 g_assert (in->klass);
2180 ainfo->offparm += cinfo->sz.offStruct;
2182 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2183 ins->sreg1 = in->dreg;
2184 ins->klass = in->klass;
2185 ins->backend.size = ainfo->size;
2186 ins->inst_p0 = call;
2187 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2188 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2190 MONO_ADD_INS (cfg->cbb, ins);
2192 if (ainfo->regtype == RegTypeStructByAddr) {
2194 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2195 * use the normal OUTARG opcodes to pass the address of the location to
2196 * the callee.
2198 int treg = mono_alloc_preg (cfg);
2199 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2200 STK_BASE, ainfo->offparm);
2201 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2202 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2203 /* The address of the valuetype is passed on the stack */
2204 int treg = mono_alloc_preg (cfg);
2205 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2206 STK_BASE, ainfo->offparm);
2207 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2208 ainfo->reg, ainfo->offset, treg);
2210 break;
2212 case RegTypeBase:
2213 if (!t->byref && t->type == MONO_TYPE_R4) {
2214 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2215 STK_BASE, ainfo->offset + 4,
2216 in->dreg);
2217 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2218 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2219 STK_BASE, ainfo->offset,
2220 in->dreg);
2221 } else {
2222 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2223 ins->inst_destbasereg = STK_BASE;
2224 ins->inst_offset = ainfo->offset;
2225 ins->sreg1 = in->dreg;
2227 /* This is needed by MonoTypedRef->value to point to the correct data */
2228 if ((sig->call_convention == MONO_CALL_VARARG) &&
2229 (i >= sig->sentinelpos)) {
2230 switch (ainfo->size) {
2231 case 1:
2232 ins->opcode = OP_STOREI1_MEMBASE_REG;
2233 break;
2234 case 2:
2235 ins->opcode = OP_STOREI2_MEMBASE_REG;
2236 break;
2237 case 4:
2238 ins->opcode = OP_STOREI4_MEMBASE_REG;
2239 break;
2240 default:
2241 break;
2245 MONO_ADD_INS (cfg->cbb, ins);
2247 break;
2248 default:
2249 g_assert_not_reached ();
2250 break;
2255 * Handle the case where there are no implicit arguments
2257 if ((sig->call_convention == MONO_CALL_VARARG) &&
2258 (i == sig->sentinelpos)) {
2259 emit_sig_cookie (cfg, call, cinfo);
2263 /*========================= End of Function ========================*/
2265 /*------------------------------------------------------------------*/
2266 /* */
2267 /* Name - mono_arch_emit_outarg_vt */
2268 /* */
2269 /*------------------------------------------------------------------*/
2271 void
2272 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2274 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2275 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2276 int size = ins->backend.size;
2278 if (ainfo->regtype == RegTypeStructByVal) {
2280 arg->ins.sreg1 = ainfo->reg;
2281 arg->ins.opcode = OP_OUTARG_VT;
2282 arg->size = ainfo->size;
2283 arg->offset = ainfo->offset;
2284 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2286 if (ainfo->reg != STK_BASE) {
2287 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2288 } else {
2289 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2290 src->dreg, 0);
2292 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2293 int dreg = mono_alloc_freg (cfg);
2295 if (ainfo->size == 4) {
2296 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2297 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2298 } else {
2299 g_assert (ainfo->size == 8);
2301 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2304 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2305 } else {
2306 MONO_EMIT_NEW_MOVE (cfg, STK_BASE, ainfo->offparm,
2307 src->dreg, 0, size);
2311 /*------------------------------------------------------------------*/
2312 /* */
2313 /* Name - mono_arch_emit_setret */
2314 /* */
2315 /*------------------------------------------------------------------*/
2317 void
2318 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2320 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2322 if (!ret->byref) {
2323 if (ret->type == MONO_TYPE_R4) {
2324 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2325 return;
2326 } else if (ret->type == MONO_TYPE_R8) {
2327 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2328 return;
2332 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2335 /*========================= End of Function ========================*/
2337 /*------------------------------------------------------------------*/
2338 /* */
2339 /* Name - mono_arch_instrument_mem_needs */
2340 /* */
2341 /* Function - Allow tracing to work with this interface (with */
2342 /* an optional argument). */
2343 /* */
2344 /*------------------------------------------------------------------*/
2346 void
2347 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2349 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2350 *stack = 0;
2351 /* split prolog-epilog requirements? */
2352 *code = 50; /* max bytes needed: check this number */
2355 /*========================= End of Function ========================*/
2357 /*------------------------------------------------------------------*/
2358 /* */
2359 /* Name - mono_arch_instrument_prolog */
2360 /* */
2361 /* Function - Create an "instrumented" prolog. */
2362 /* */
2363 /*------------------------------------------------------------------*/
2365 void*
2366 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2367 gboolean enable_arguments)
2369 guchar *code = p;
2370 int parmOffset,
2371 fpOffset,
2372 baseReg;
2374 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2375 if (cfg->method->save_lmf)
2376 parmOffset -= sizeof(MonoLMF);
2377 fpOffset = parmOffset + (5*sizeof(gpointer));
2378 if ((!has_ld) && (fpOffset > 4096)) {
2379 s390_lgr (code, s390_r12, STK_BASE);
2380 baseReg = s390_r12;
2381 while (fpOffset > 4096) {
2382 s390_aghi (code, baseReg, 4096);
2383 fpOffset -= 4096;
2384 parmOffset -= 4096;
2386 } else {
2387 baseReg = STK_BASE;
2390 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2391 if (has_ld) {
2392 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2393 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2394 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2395 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2396 } else {
2397 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2398 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2399 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2400 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2402 s390_basr (code, s390_r13, 0);
2403 s390_j (code, 10);
2404 s390_llong(code, cfg->method);
2405 s390_llong(code, func);
2406 s390_lg (code, s390_r2, 0, s390_r13, 4);
2407 if (has_ld)
2408 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2409 else
2410 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2411 s390_lgr (code, s390_r4, STK_BASE);
2412 s390_aghi (code, s390_r4, cfg->stack_usage);
2413 s390_lg (code, s390_r1, 0, s390_r13, 12);
2414 s390_basr (code, s390_r14, s390_r1);
2415 if (has_ld) {
2416 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2417 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2418 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2419 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2420 } else {
2421 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2422 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2423 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2424 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2426 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2428 return code;
2431 /*========================= End of Function ========================*/
2433 /*------------------------------------------------------------------*/
2434 /* */
2435 /* Name - mono_arch_instrument_epilog */
2436 /* */
2437 /* Function - Create an epilog that will handle the returned */
2438 /* values used in instrumentation. */
2439 /* */
2440 /*------------------------------------------------------------------*/
2442 void*
2443 mono_arch_instrument_epilog (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments)
2445 guchar *code = p;
2446 int save_mode = SAVE_NONE,
2447 saveOffset;
2448 MonoMethod *method = cfg->method;
2449 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2451 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2452 if (method->save_lmf)
2453 saveOffset -= sizeof(MonoLMF);
2455 handle_enum:
2456 switch (rtype) {
2457 case MONO_TYPE_VOID:
2458 /* special case string .ctor icall */
2459 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2460 save_mode = SAVE_ONE;
2461 else
2462 save_mode = SAVE_NONE;
2463 break;
2464 case MONO_TYPE_I8:
2465 case MONO_TYPE_U8:
2466 save_mode = SAVE_ONE;
2467 break;
2468 case MONO_TYPE_R4:
2469 save_mode = SAVE_R4;
2470 break;
2471 case MONO_TYPE_R8:
2472 save_mode = SAVE_R8;
2473 break;
2474 case MONO_TYPE_VALUETYPE:
2475 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2476 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2477 goto handle_enum;
2479 save_mode = SAVE_STRUCT;
2480 break;
2481 default:
2482 save_mode = SAVE_ONE;
2483 break;
2486 switch (save_mode) {
2487 case SAVE_ONE:
2488 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2489 if (enable_arguments) {
2490 s390_lgr (code, s390_r3, s390_r2);
2492 break;
2493 case SAVE_R4:
2494 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2495 if (enable_arguments) {
2496 s390_ldebr (code, s390_f0, s390_f0);
2498 break;
2499 case SAVE_R8:
2500 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2501 break;
2502 case SAVE_STRUCT:
2503 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2504 if (enable_arguments) {
2505 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2506 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2508 break;
2509 case SAVE_NONE:
2510 default:
2511 break;
2514 s390_basr (code, s390_r13, 0);
2515 s390_j (code, 10);
2516 s390_llong(code, cfg->method);
2517 s390_llong(code, func);
2518 s390_lg (code, s390_r2, 0, s390_r13, 4);
2519 s390_lg (code, s390_r1, 0, s390_r13, 12);
2520 s390_basr (code, s390_r14, s390_r1);
2522 switch (save_mode) {
2523 case SAVE_ONE:
2524 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2525 break;
2526 case SAVE_R4:
2527 case SAVE_R8:
2528 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2529 break;
2530 case SAVE_STRUCT:
2531 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2532 break;
2533 case SAVE_NONE:
2534 default:
2535 break;
2538 return code;
2541 /*========================= End of Function ========================*/
2543 void
2544 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2548 /*------------------------------------------------------------------*/
2549 /* */
2550 /* Name - mono_arch_peephole_pass */
2551 /* */
2552 /* Function - Form a peephole pass at the code looking for */
2553 /* simple optimizations. */
2554 /* */
2555 /*------------------------------------------------------------------*/
2557 void
2558 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2560 MonoInst *ins, *n;
2562 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2563 mono_peephole_ins (bb, ins);
2567 /*========================= End of Function ========================*/
2569 void
2570 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2572 MonoInst *ins, *next;
2574 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2575 switch (ins->opcode) {
2576 case OP_DIV_IMM:
2577 case OP_REM_IMM:
2578 case OP_IDIV_IMM:
2579 case OP_IREM_IMM:
2580 case OP_IDIV_UN_IMM:
2581 case OP_IREM_UN_IMM:
2582 case OP_LAND_IMM:
2583 case OP_LOR_IMM:
2584 case OP_LXOR_IMM:
2585 case OP_LOCALLOC_IMM:
2586 mono_decompose_op_imm (cfg, bb, ins);
2587 break;
2588 case OP_LADD_IMM:
2589 if (!s390_is_imm16 (ins->inst_imm))
2590 /* This is created by the memcpy code which ignores is_inst_imm */
2591 mono_decompose_op_imm (cfg, bb, ins);
2592 break;
2593 default:
2594 break;
2598 bb->max_vreg = cfg->next_vreg;
2601 /*========================= End of Function ========================*/
2603 /*------------------------------------------------------------------*/
2604 /* */
2605 /* Name - emit_float_to_int */
2606 /* */
2607 /* Function - Create instructions which will convert a floating */
2608 /* point value to integer. */
2609 /* */
2610 /*------------------------------------------------------------------*/
2612 static guchar*
2613 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2615 /* sreg is a float, dreg is an integer reg. */
2616 if (is_signed) {
2617 s390_cfdbr (code, dreg, 5, sreg);
2618 switch (size) {
2619 case 1:
2620 s390_lghi (code, s390_r0, 0);
2621 s390_lghi (code, s390_r13, 0xff);
2622 s390_ltgr (code, dreg, dreg);
2623 s390_jnl (code, 4);
2624 s390_lghi (code, s390_r0, 0x80);
2625 s390_ngr (code, dreg, s390_r13);
2626 s390_ogr (code, dreg, s390_r0);
2627 break;
2629 } else {
2630 short *o[1];
2631 s390_basr (code, s390_r13, 0);
2632 s390_j (code, 10);
2633 s390_llong (code, 0x41e0000000000000);
2634 s390_llong (code, 0x41f0000000000000);
2635 s390_ldr (code, s390_f15, sreg);
2636 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2637 s390_jl (code, 0); CODEPTR (code, o[0]);
2638 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2639 s390_cfdbr (code, dreg, 7, s390_f15);
2640 s390_j (code, 4);
2641 PTRSLOT (code, o[0]);
2642 s390_cfdbr (code, dreg, 5, sreg);
2643 switch (size) {
2644 case 1:
2645 s390_lghi (code, s390_r0, 0xff);
2646 s390_ngr (code, dreg, s390_r0);
2647 break;
2648 case 2:
2649 s390_lghi (code, s390_r0, -1);
2650 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2651 s390_ngr (code, dreg, s390_r0);
2652 break;
2655 return code;
2658 /*========================= End of Function ========================*/
2660 static gboolean is_unsigned (MonoInst *next)
2662 if ((next) &&
2663 (((next->opcode >= OP_IBNE_UN) &&
2664 (next->opcode <= OP_IBLT_UN)) ||
2665 ((next->opcode >= OP_LBNE_UN) &&
2666 (next->opcode <= OP_LBLT_UN)) ||
2667 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2668 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2669 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2670 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2671 ((next->opcode == OP_CLT_UN) ||
2672 (next->opcode == OP_CGT_UN)) ||
2673 ((next->opcode == OP_ICLT_UN) ||
2674 (next->opcode == OP_ICGT_UN) ||
2675 (next->opcode == OP_LCLT_UN) ||
2676 (next->opcode == OP_LCGT_UN))))
2677 return TRUE;
2678 else
2679 return FALSE;
2682 /*------------------------------------------------------------------*/
2683 /* */
2684 /* Name - mono_arch_output_basic_block */
2685 /* */
2686 /* Function - Perform the "real" work of emitting instructions */
2687 /* that will do the work of in the basic block. */
2688 /* */
2689 /*------------------------------------------------------------------*/
2691 void
2692 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2694 MonoInst *ins;
2695 MonoCallInst *call;
2696 guint offset;
2697 guint8 *code = cfg->native_code + cfg->code_len;
2698 guint last_offset = 0;
2699 int max_len, cpos, src2;
2701 /* we don't align basic blocks of loops on s390 */
2703 if (cfg->verbose_level > 2)
2704 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2706 cpos = bb->max_offset;
2708 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2709 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2710 //g_assert (!mono_compile_aot);
2711 //cpos += 6;
2712 //if (bb->cil_code)
2713 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2714 /* this is not thread save, but good enough */
2715 /* fixme: howto handle overflows? */
2716 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2719 MONO_BB_FOR_EACH_INS (bb, ins) {
2720 offset = code - cfg->native_code;
2722 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2724 if (offset > (cfg->code_size - max_len - 16)) {
2725 cfg->code_size *= 2;
2726 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2727 code = cfg->native_code + offset;
2730 mono_debug_record_line_number (cfg, ins, offset);
2732 switch (ins->opcode) {
2733 case OP_STOREI1_MEMBASE_IMM: {
2734 s390_lghi (code, s390_r0, ins->inst_imm);
2735 S390_LONG (code, stcy, stc, s390_r0, 0,
2736 ins->inst_destbasereg, ins->inst_offset);
2738 break;
2739 case OP_STOREI2_MEMBASE_IMM: {
2740 s390_lghi (code, s390_r0, ins->inst_imm);
2741 S390_LONG (code, sthy, sth, s390_r0, 0,
2742 ins->inst_destbasereg, ins->inst_offset);
2744 break;
2745 case OP_STOREI4_MEMBASE_IMM: {
2746 if (s390_is_imm16(ins->inst_imm)) {
2747 s390_lghi (code, s390_r0, ins->inst_imm);
2748 } else {
2749 s390_basr (code, s390_r13, 0);
2750 s390_j (code, 6);
2751 s390_llong(code, ins->inst_imm);
2752 s390_lg (code, s390_r0, 0, s390_r13, 4);
2754 S390_LONG (code, sty, st, s390_r0, 0,
2755 ins->inst_destbasereg, ins->inst_offset);
2757 break;
2758 case OP_STORE_MEMBASE_IMM:
2759 case OP_STOREI8_MEMBASE_IMM: {
2760 if (s390_is_imm16(ins->inst_imm)) {
2761 s390_lghi (code, s390_r0, ins->inst_imm);
2762 } else {
2763 s390_basr (code, s390_r13, 0);
2764 s390_j (code, 6);
2765 s390_llong(code, ins->inst_imm);
2766 s390_lg (code, s390_r0, 0, s390_r13, 4);
2768 S390_LONG (code, stg, stg, s390_r0, 0,
2769 ins->inst_destbasereg, ins->inst_offset);
2771 break;
2772 case OP_STOREI1_MEMBASE_REG: {
2773 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2774 ins->inst_destbasereg, ins->inst_offset);
2776 break;
2777 case OP_STOREI2_MEMBASE_REG: {
2778 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2779 ins->inst_destbasereg, ins->inst_offset);
2781 break;
2782 case OP_STOREI4_MEMBASE_REG: {
2783 S390_LONG (code, sty, st, ins->sreg1, 0,
2784 ins->inst_destbasereg, ins->inst_offset);
2786 break;
2787 case OP_STORE_MEMBASE_REG:
2788 case OP_STOREI8_MEMBASE_REG: {
2789 S390_LONG (code, stg, stg, ins->sreg1, 0,
2790 ins->inst_destbasereg, ins->inst_offset);
2792 break;
2793 case OP_LOADU4_MEM:
2794 g_assert_not_reached ();
2795 break;
2796 case OP_LOAD_MEMBASE:
2797 case OP_LOADI8_MEMBASE: {
2798 S390_LONG (code, lg, lg, ins->dreg, 0,
2799 ins->inst_basereg, ins->inst_offset);
2801 break;
2802 case OP_LOADI4_MEMBASE: {
2803 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2804 ins->inst_basereg, ins->inst_offset);
2806 break;
2807 case OP_LOADU4_MEMBASE: {
2808 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2809 ins->inst_basereg, ins->inst_offset);
2811 break;
2812 case OP_LOADU1_MEMBASE: {
2813 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2814 ins->inst_basereg, ins->inst_offset);
2816 break;
2817 case OP_LOADI1_MEMBASE: {
2818 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2819 ins->inst_basereg, ins->inst_offset);
2821 break;
2822 case OP_LOADU2_MEMBASE: {
2823 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2824 ins->inst_basereg, ins->inst_offset);
2826 break;
2827 case OP_LOADI2_MEMBASE: {
2828 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2829 ins->inst_basereg, ins->inst_offset);
2831 break;
2832 case OP_LCONV_TO_I1: {
2833 s390_lghi (code, s390_r0, 0x80);
2834 if (ins->dreg != ins->sreg1) {
2835 s390_lgr (code, ins->dreg, ins->sreg1);
2837 s390_ngr (code, s390_r0, ins->sreg1);
2838 s390_jz (code, 9);
2839 s390_lghi (code, s390_r13, -1);
2840 s390_sllg (code, s390_r13, s390_r13, 0, 8);
2841 s390_ogr (code, ins->dreg, s390_r13);
2843 break;
2844 case OP_LCONV_TO_I2: {
2845 s390_lghi (code, s390_r0, 0x80);
2846 s390_sllg (code, s390_r0, s390_r0, 0, 8);
2847 if (ins->dreg != ins->sreg1) {
2848 s390_lgr (code, ins->dreg, ins->sreg1);
2850 s390_ngr (code, s390_r0, ins->sreg1);
2851 s390_jz (code, 9);
2852 s390_lghi (code, s390_r13, -1);
2853 s390_sllg (code, s390_r13, s390_r13, 0, 16);
2854 s390_ogr (code, ins->dreg, s390_r13);
2856 break;
2857 case OP_LCONV_TO_U1: {
2858 s390_lghi (code, s390_r0, 0xff);
2859 if (ins->dreg != ins->sreg1) {
2860 s390_lgr (code, ins->dreg, ins->sreg1);
2862 s390_ngr (code, ins->dreg, s390_r0);
2864 break;
2865 case OP_LCONV_TO_U2: {
2866 s390_lghi (code, s390_r0, -1);
2867 s390_sllg (code, s390_r0, s390_r0, 0, 48);
2868 s390_srlg (code, s390_r0, s390_r0, 0, 48);
2869 if (ins->dreg != ins->sreg1) {
2870 s390_lgr (code, ins->dreg, ins->sreg1);
2872 s390_ngr (code, ins->dreg, s390_r0);
2874 break;
2875 case OP_ICONV_TO_I1: {
2876 s390_lhi (code, s390_r0, 0x80);
2877 if (ins->dreg != ins->sreg1) {
2878 s390_lr (code, ins->dreg, ins->sreg1);
2880 s390_nr (code, s390_r0, ins->sreg1);
2881 s390_jz (code, 7);
2882 s390_lhi (code, s390_r13, -1);
2883 s390_sll (code, s390_r13, 0, 8);
2884 s390_or (code, ins->dreg, s390_r13);
2886 break;
2887 case OP_ICONV_TO_I2: {
2888 s390_lhi (code, s390_r0, 0x80);
2889 s390_sll (code, s390_r0, 0, 8);
2890 if (ins->dreg != ins->sreg1) {
2891 s390_lr (code, ins->dreg, ins->sreg1);
2893 s390_nr (code, s390_r0, ins->sreg1);
2894 s390_jz (code, 7);
2895 s390_lhi (code, s390_r13, -1);
2896 s390_sll (code, s390_r13, 0, 16);
2897 s390_or (code, ins->dreg, s390_r13);
2899 break;
2900 case OP_ICONV_TO_U1: {
2901 s390_lhi (code, s390_r0, 0xff);
2902 if (ins->dreg != ins->sreg1) {
2903 s390_lr (code, ins->dreg, ins->sreg1);
2905 s390_nr (code, ins->dreg, s390_r0);
2907 break;
2908 case OP_ICONV_TO_U2: {
2909 s390_lhi (code, s390_r0, -1);
2910 s390_sll (code, s390_r0, 0, 16);
2911 s390_srl (code, s390_r0, 0, 16);
2912 if (ins->dreg != ins->sreg1) {
2913 s390_lr (code, ins->dreg, ins->sreg1);
2915 s390_nr (code, ins->dreg, s390_r0);
2917 break;
2918 case OP_COMPARE:
2919 case OP_LCOMPARE: {
2920 if (is_unsigned (ins->next))
2921 s390_clgr (code, ins->sreg1, ins->sreg2);
2922 else
2923 s390_cgr (code, ins->sreg1, ins->sreg2);
2925 break;
2926 case OP_ICOMPARE: {
2927 if (is_unsigned (ins->next))
2928 s390_clr (code, ins->sreg1, ins->sreg2);
2929 else
2930 s390_cr (code, ins->sreg1, ins->sreg2);
2932 break;
2933 case OP_COMPARE_IMM:
2934 case OP_LCOMPARE_IMM: {
2935 if (s390_is_imm16 (ins->inst_imm)) {
2936 s390_lghi (code, s390_r0, ins->inst_imm);
2937 if (is_unsigned (ins->next))
2938 s390_clgr (code, ins->sreg1, s390_r0);
2939 else
2940 s390_cgr (code, ins->sreg1, s390_r0);
2941 } else {
2942 s390_basr (code, s390_r13, 0);
2943 s390_j (code, 6);
2944 s390_llong(code, ins->inst_imm);
2945 if (is_unsigned (ins->next))
2946 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
2947 else
2948 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
2951 break;
2952 case OP_ICOMPARE_IMM: {
2953 if (s390_is_imm16 (ins->inst_imm)) {
2954 s390_lghi (code, s390_r0, ins->inst_imm);
2955 if (is_unsigned (ins->next))
2956 s390_clr (code, ins->sreg1, s390_r0);
2957 else
2958 s390_cr (code, ins->sreg1, s390_r0);
2960 else {
2961 s390_basr (code, s390_r13, 0);
2962 s390_j (code, 4);
2963 s390_word (code, ins->inst_imm);
2964 if (is_unsigned (ins->next))
2965 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
2966 else
2967 s390_c (code, ins->sreg1, 0, s390_r13, 4);
2970 break;
2971 case OP_BREAK: {
2972 s390_basr (code, s390_r13, 0);
2973 s390_j (code, 6);
2974 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
2975 mono_break);
2976 s390_llong (code, mono_break);
2977 s390_lg (code, s390_r14, 0, s390_r13, 4);
2978 s390_basr (code, s390_r14, s390_r14);
2980 break;
2981 case OP_ADDCC: {
2982 CHECK_SRCDST_COM;
2983 s390_agr (code, ins->dreg, src2);
2985 break;
2986 case OP_LADD: {
2987 CHECK_SRCDST_COM;
2988 s390_agr (code, ins->dreg, src2);
2990 break;
2991 case OP_ADC: {
2992 CHECK_SRCDST_COM;
2993 s390_alcgr (code, ins->dreg, src2);
2995 break;
2996 case OP_ADD_IMM: {
2997 if (ins->dreg != ins->sreg1) {
2998 s390_lgr (code, ins->dreg, ins->sreg1);
3000 if (s390_is_imm16 (ins->inst_imm)) {
3001 s390_aghi (code, ins->dreg, ins->inst_imm);
3002 } else {
3003 s390_basr (code, s390_r13, 0);
3004 s390_j (code, 6);
3005 s390_llong(code, ins->inst_imm);
3006 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3009 break;
3010 case OP_LADD_IMM: {
3011 if (ins->dreg != ins->sreg1) {
3012 s390_lgr (code, ins->dreg, ins->sreg1);
3014 g_assert (s390_is_imm16 (ins->inst_imm));
3015 s390_aghi (code, ins->dreg, ins->inst_imm);
3017 break;
3018 case OP_ADC_IMM: {
3019 if (ins->dreg != ins->sreg1) {
3020 s390_lgr (code, ins->dreg, ins->sreg1);
3022 if (s390_is_imm16 (ins->inst_imm)) {
3023 s390_lghi (code, s390_r0, ins->inst_imm);
3024 s390_alcgr (code, ins->dreg, s390_r0);
3025 } else {
3026 s390_basr (code, s390_r13, 0);
3027 s390_j (code, 6);
3028 s390_llong (code, ins->inst_imm);
3029 s390_lg (code, s390_r13, 0, s390_r13, 4);
3030 s390_alcgr (code, ins->dreg, s390_r13);
3033 break;
3034 case OP_IADD_OVF:
3035 case OP_S390_IADD_OVF: {
3036 CHECK_SRCDST_COM;
3037 s390_ar (code, ins->dreg, src2);
3038 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3039 s390_lgfr (code, ins->dreg, ins->dreg);
3041 break;
3042 case OP_IADD_OVF_UN:
3043 case OP_S390_IADD_OVF_UN: {
3044 CHECK_SRCDST_COM;
3045 s390_algr (code, ins->dreg, src2);
3046 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3047 s390_llgfr (code, ins->dreg, ins->dreg);
3049 break;
3050 case OP_ADD_OVF_CARRY: {
3051 CHECK_SRCDST_COM;
3052 s390_lghi (code, s390_r0, 0);
3053 s390_lgr (code, s390_r1, s390_r0);
3054 s390_alcgr (code, s390_r0, s390_r1);
3055 s390_agr (code, ins->dreg, src2);
3056 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3057 s390_agr (code, ins->dreg, s390_r0);
3058 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3060 break;
3061 case OP_ADD_OVF_UN_CARRY: {
3062 CHECK_SRCDST_COM;
3063 s390_alcgr (code, ins->dreg, src2);
3064 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3066 break;
3067 case OP_SUBCC: {
3068 CHECK_SRCDST_NCOM;
3069 s390_sgr (code, ins->dreg, src2);
3071 break;
3072 case OP_LSUB: {
3073 CHECK_SRCDST_NCOM;
3074 s390_sgr (code, ins->dreg, src2);
3076 break;
3077 case OP_SBB: {
3078 CHECK_SRCDST_NCOM;
3079 s390_slbgr(code, ins->dreg, src2);
3081 break;
3082 case OP_SUB_IMM: {
3083 if (ins->dreg != ins->sreg1) {
3084 s390_lgr (code, ins->dreg, ins->sreg1);
3086 if (s390_is_imm16 (-ins->inst_imm)) {
3087 s390_lghi (code, s390_r0, ins->inst_imm);
3088 s390_slgr (code, ins->dreg, s390_r0);
3089 } else {
3090 s390_basr (code, s390_r13, 0);
3091 s390_j (code, 6);
3092 s390_llong(code, ins->inst_imm);
3093 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3096 break;
3097 case OP_LSUB_IMM: {
3098 if (ins->dreg != ins->sreg1) {
3099 s390_lgr (code, ins->dreg, ins->sreg1);
3101 if (s390_is_imm16 (-ins->inst_imm)) {
3102 s390_lghi (code, s390_r0, ins->inst_imm);
3103 s390_slgr (code, ins->dreg, s390_r0);
3104 } else {
3105 s390_basr (code, s390_r13, 0);
3106 s390_j (code, 6);
3107 s390_llong(code, ins->inst_imm);
3108 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3111 break;
3112 case OP_SBB_IMM: {
3113 if (ins->dreg != ins->sreg1) {
3114 s390_lgr (code, ins->dreg, ins->sreg1);
3116 if (s390_is_imm16 (-ins->inst_imm)) {
3117 s390_lghi (code, s390_r0, ins->inst_imm);
3118 s390_slbgr (code, ins->dreg, s390_r0);
3119 } else {
3120 s390_basr (code, s390_r13, 0);
3121 s390_j (code, 6);
3122 s390_llong(code, ins->inst_imm);
3123 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3126 break;
3127 case OP_SUB_OVF_CARRY: {
3128 CHECK_SRCDST_NCOM;
3129 s390_lghi (code, s390_r0, 0);
3130 s390_lgr (code, s390_r1, s390_r0);
3131 s390_slbgr (code, s390_r0, s390_r1);
3132 s390_sgr (code, ins->dreg, src2);
3133 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3134 s390_agr (code, ins->dreg, s390_r0);
3135 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3137 break;
3138 case OP_SUB_OVF_UN_CARRY: {
3139 CHECK_SRCDST_NCOM;
3140 s390_slbgr (code, ins->dreg, src2);
3141 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3143 break;
3144 case OP_LAND: {
3145 if (ins->sreg1 == ins->dreg) {
3146 s390_ngr (code, ins->dreg, ins->sreg2);
3148 else {
3149 if (ins->sreg2 == ins->dreg) {
3150 s390_ngr (code, ins->dreg, ins->sreg1);
3152 else {
3153 s390_lgr (code, ins->dreg, ins->sreg1);
3154 s390_ngr (code, ins->dreg, ins->sreg2);
3158 break;
3159 case OP_AND_IMM: {
3160 if (ins->dreg != ins->sreg1) {
3161 s390_lgr (code, ins->dreg, ins->sreg1);
3163 if (s390_is_imm16 (ins->inst_imm)) {
3164 s390_lghi (code, s390_r0, ins->inst_imm);
3165 s390_ngr (code, ins->dreg, s390_r0);
3166 } else {
3167 s390_basr (code, s390_r13, 0);
3168 s390_j (code, 6);
3169 s390_llong(code, ins->inst_imm);
3170 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3173 break;
3174 case OP_LDIV: {
3175 s390_lgr (code, s390_r1, ins->sreg1);
3176 s390_dsgr (code, s390_r0, ins->sreg2);
3177 s390_lgr (code, ins->dreg, s390_r1);
3179 break;
3180 case OP_LDIV_UN: {
3181 s390_lgr (code, s390_r1, ins->sreg1);
3182 s390_lghi (code, s390_r0, 0);
3183 s390_dlgr (code, s390_r0, ins->sreg2);
3184 s390_lgr (code, ins->dreg, s390_r1);
3186 break;
3187 case OP_LREM: {
3188 s390_lgr (code, s390_r1, ins->sreg1);
3189 s390_dsgr (code, s390_r0, ins->sreg2);
3190 s390_lgr (code, ins->dreg, s390_r0);
3191 break;
3193 case OP_LREM_UN: {
3194 s390_lgr (code, s390_r1, ins->sreg1);
3195 s390_lghi (code, s390_r0, 0);
3196 s390_dlgr (code, s390_r0, ins->sreg2);
3197 s390_lgr (code, ins->dreg, s390_r0);
3199 break;
3200 case OP_LOR: {
3201 if (ins->sreg1 == ins->dreg) {
3202 s390_ogr (code, ins->dreg, ins->sreg2);
3204 else {
3205 if (ins->sreg2 == ins->dreg) {
3206 s390_ogr (code, ins->dreg, ins->sreg1);
3208 else {
3209 s390_lgr (code, ins->dreg, ins->sreg1);
3210 s390_ogr (code, ins->dreg, ins->sreg2);
3214 break;
3215 case OP_OR_IMM: {
3216 if (ins->dreg != ins->sreg1) {
3217 s390_lgr (code, ins->dreg, ins->sreg1);
3219 if (s390_is_imm16 (ins->inst_imm)) {
3220 s390_lghi (code, s390_r0, ins->inst_imm);
3221 s390_ogr (code, ins->dreg, s390_r0);
3222 } else {
3223 s390_basr (code, s390_r13, 0);
3224 s390_j (code, 6);
3225 s390_llong(code, ins->inst_imm);
3226 s390_og (code, ins->dreg, 0, s390_r13, 4);
3229 break;
3230 case OP_LXOR: {
3231 if (ins->sreg1 == ins->dreg) {
3232 s390_xgr (code, ins->dreg, ins->sreg2);
3234 else {
3235 if (ins->sreg2 == ins->dreg) {
3236 s390_xgr (code, ins->dreg, ins->sreg1);
3238 else {
3239 s390_lgr (code, ins->dreg, ins->sreg1);
3240 s390_xgr (code, ins->dreg, ins->sreg2);
3244 break;
3245 case OP_XOR_IMM: {
3246 if (ins->dreg != ins->sreg1) {
3247 s390_lgr (code, ins->dreg, ins->sreg1);
3249 if (s390_is_imm16 (ins->inst_imm)) {
3250 s390_lghi (code, s390_r0, ins->inst_imm);
3251 s390_xgr (code, ins->dreg, s390_r0);
3252 } else {
3253 s390_basr (code, s390_r13, 0);
3254 s390_j (code, 6);
3255 s390_llong(code, ins->inst_imm);
3256 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3259 break;
3260 case OP_LSHL: {
3261 CHECK_SRCDST_NCOM;
3262 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3264 break;
3265 case OP_SHL_IMM:
3266 case OP_LSHL_IMM: {
3267 if (ins->sreg1 != ins->dreg) {
3268 s390_lgr (code, ins->dreg, ins->sreg1);
3270 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3272 break;
3273 case OP_LSHR: {
3274 CHECK_SRCDST_NCOM;
3275 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3277 break;
3278 case OP_SHR_IMM:
3279 case OP_LSHR_IMM: {
3280 if (ins->sreg1 != ins->dreg) {
3281 s390_lgr (code, ins->dreg, ins->sreg1);
3283 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3285 break;
3286 case OP_SHR_UN_IMM:
3287 case OP_LSHR_UN_IMM: {
3288 if (ins->sreg1 != ins->dreg) {
3289 s390_lgr (code, ins->dreg, ins->sreg1);
3291 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3293 break;
3294 case OP_LSHR_UN: {
3295 CHECK_SRCDST_NCOM;
3296 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3298 break;
3299 case OP_LNOT: {
3300 if (ins->sreg1 != ins->dreg) {
3301 s390_lgr (code, ins->dreg, ins->sreg1);
3303 s390_lghi (code, s390_r0, -1);
3304 s390_xgr (code, ins->dreg, s390_r0);
3306 break;
3307 case OP_LNEG: {
3308 s390_lcgr (code, ins->dreg, ins->sreg1);
3310 break;
3311 case OP_LMUL: {
3312 CHECK_SRCDST_COM;
3313 s390_msgr (code, ins->dreg, src2);
3315 break;
3316 case OP_MUL_IMM:
3317 case OP_LMUL_IMM: {
3318 if (ins->dreg != ins->sreg1) {
3319 s390_lgr (code, ins->dreg, ins->sreg1);
3321 if (s390_is_imm16 (ins->inst_imm)) {
3322 s390_lghi (code, s390_r13, ins->inst_imm);
3323 } else {
3324 s390_basr (code, s390_r13, 0);
3325 s390_j (code, 6);
3326 s390_llong(code, ins->inst_imm);
3327 s390_lg (code, s390_r13, 0, s390_r13, 4);
3329 s390_msgr (code, ins->dreg, s390_r13);
3331 break;
3332 case OP_LMUL_OVF: {
3333 short int *o[2];
3334 s390_ltgr (code, s390_r1, ins->sreg1);
3335 s390_jz (code, 0); CODEPTR(code, o[0]);
3336 s390_ltgr (code, s390_r0, ins->sreg2);
3337 s390_jnz (code, 6);
3338 s390_lghi (code, s390_r1, 0);
3339 s390_j (code, 0); CODEPTR(code, o[1]);
3340 s390_xgr (code, s390_r0, s390_r1);
3341 s390_msgr (code, s390_r1, ins->sreg2);
3342 s390_xgr (code, s390_r0, s390_r1);
3343 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3344 s390_ltgr (code, s390_r0, s390_r0);
3345 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3346 PTRSLOT (code, o[0]);
3347 PTRSLOT (code, o[1]);
3348 s390_lgr (code, ins->dreg, s390_r1);
3350 break;
3351 case OP_LMUL_OVF_UN: {
3352 s390_lghi (code, s390_r0, 0);
3353 s390_lgr (code, s390_r1, ins->sreg1);
3354 s390_mlgr (code, s390_r0, ins->sreg2);
3355 s390_ltgr (code, s390_r0, s390_r0);
3356 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3357 s390_lgr (code, ins->dreg, s390_r1);
3359 break;
3360 case OP_IADDCC: {
3361 g_assert_not_reached ();
3362 CHECK_SRCDST_COM_I;
3363 s390_algr (code, ins->dreg, src2);
3365 break;
3366 case OP_IADD: {
3367 CHECK_SRCDST_COM_I;
3368 s390_agr (code, ins->dreg, src2);
3370 break;
3371 case OP_IADC: {
3372 g_assert_not_reached ();
3373 CHECK_SRCDST_COM_I;
3374 s390_alcgr (code, ins->dreg, src2);
3376 break;
3377 case OP_IADD_IMM: {
3378 if (ins->dreg != ins->sreg1) {
3379 s390_lgfr (code, ins->dreg, ins->sreg1);
3381 if (s390_is_imm16 (ins->inst_imm)) {
3382 s390_aghi(code, ins->dreg, ins->inst_imm);
3383 } else {
3384 s390_basr (code, s390_r13, 0);
3385 s390_j (code, 4);
3386 s390_word (code, ins->inst_imm);
3387 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3390 break;
3391 case OP_IADC_IMM: {
3392 if (ins->dreg != ins->sreg1) {
3393 s390_lgfr (code, ins->dreg, ins->sreg1);
3395 if (s390_is_imm16 (ins->inst_imm)) {
3396 s390_lghi (code, s390_r0, ins->inst_imm);
3397 s390_alcgr (code, ins->dreg, s390_r0);
3398 } else {
3399 s390_basr (code, s390_r13, 0);
3400 s390_j (code, 4);
3401 s390_word (code, ins->inst_imm);
3402 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3403 s390_alcgr (code, ins->dreg, s390_r13);
3406 break;
3407 case OP_LADD_OVF:
3408 case OP_S390_LADD_OVF: {
3409 CHECK_SRCDST_COM;
3410 s390_agr (code, ins->dreg, src2);
3411 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3413 break;
3414 case OP_LADD_OVF_UN:
3415 case OP_S390_LADD_OVF_UN: {
3416 CHECK_SRCDST_COM;
3417 s390_algr (code, ins->dreg, src2);
3418 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3420 break;
3421 case OP_ISUBCC: {
3422 CHECK_SRCDST_NCOM_I;
3423 s390_slgr (code, ins->dreg, src2);
3425 break;
3426 case OP_ISUB: {
3427 CHECK_SRCDST_NCOM_I;
3428 s390_sgr (code, ins->dreg, src2);
3430 break;
3431 case OP_ISBB: {
3432 CHECK_SRCDST_NCOM_I;
3433 s390_slbgr (code, ins->dreg, src2);
3435 break;
3436 case OP_ISUB_IMM: {
3437 if (ins->dreg != ins->sreg1) {
3438 s390_lgfr (code, ins->dreg, ins->sreg1);
3440 if (s390_is_imm16 (-ins->inst_imm)) {
3441 s390_aghi (code, ins->dreg, -ins->inst_imm);
3442 } else {
3443 s390_basr (code, s390_r13, 0);
3444 s390_j (code, 4);
3445 s390_word (code, ins->inst_imm);
3446 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3449 break;
3450 case OP_ISBB_IMM: {
3451 s390_basr (code, s390_r13, 0);
3452 s390_j (code, 4);
3453 s390_word (code, ins->inst_imm);
3454 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3456 break;
3457 case OP_ISUB_OVF:
3458 case OP_S390_ISUB_OVF: {
3459 CHECK_SRCDST_NCOM;
3460 s390_sr (code, ins->dreg, src2);
3461 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3462 s390_lgfr (code, ins->dreg, ins->dreg);
3464 break;
3465 case OP_ISUB_OVF_UN:
3466 case OP_S390_ISUB_OVF_UN: {
3467 CHECK_SRCDST_NCOM;
3468 s390_slr (code, ins->dreg, src2);
3469 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3470 s390_llgfr(code, ins->dreg, ins->dreg);
3472 break;
3473 case OP_LSUB_OVF:
3474 case OP_S390_LSUB_OVF: {
3475 CHECK_SRCDST_NCOM;
3476 s390_sgr (code, ins->dreg, src2);
3477 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3479 break;
3480 case OP_LSUB_OVF_UN:
3481 case OP_S390_LSUB_OVF_UN: {
3482 CHECK_SRCDST_NCOM;
3483 s390_slgr (code, ins->dreg, src2);
3484 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3486 break;
3487 case OP_IAND: {
3488 CHECK_SRCDST_NCOM_I;
3489 s390_ngr (code, ins->dreg, src2);
3491 break;
3492 case OP_IAND_IMM: {
3493 if (ins->dreg != ins->sreg1) {
3494 s390_lgfr (code, ins->dreg, ins->sreg1);
3496 if (s390_is_imm16 (ins->inst_imm)) {
3497 s390_lghi (code, s390_r0, ins->inst_imm);
3498 s390_ngr (code, ins->dreg, s390_r0);
3499 } else {
3500 s390_basr (code, s390_r13, 0);
3501 s390_j (code, 6);
3502 s390_llong(code, ins->inst_imm);
3503 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3506 break;
3507 case OP_IDIV: {
3508 s390_lgfr (code, s390_r0, ins->sreg1);
3509 s390_srda (code, s390_r0, 0, 32);
3510 s390_dr (code, s390_r0, ins->sreg2);
3511 s390_lgfr (code, ins->dreg, s390_r1);
3513 break;
3514 case OP_IDIV_UN: {
3515 s390_lgfr (code, s390_r0, ins->sreg1);
3516 s390_srdl (code, s390_r0, 0, 32);
3517 s390_dlr (code, s390_r0, ins->sreg2);
3518 s390_lgfr (code, ins->dreg, s390_r1);
3520 break;
3521 case OP_IDIV_IMM: {
3522 if (s390_is_imm16 (ins->inst_imm)) {
3523 s390_lghi (code, s390_r13, ins->inst_imm);
3524 s390_lgfr (code, s390_r0, ins->sreg1);
3525 } else {
3526 s390_basr (code, s390_r13, 0);
3527 s390_j (code, 4);
3528 s390_word (code, ins->inst_imm);
3529 s390_lgfr (code, s390_r0, ins->sreg1);
3530 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3532 s390_srda (code, s390_r0, 0, 32);
3533 s390_dr (code, s390_r0, ins->sreg2);
3534 s390_lgfr (code, ins->dreg, s390_r1);
3536 break;
3537 case OP_IREM: {
3538 s390_lgfr (code, s390_r0, ins->sreg1);
3539 s390_srda (code, s390_r0, 0, 32);
3540 s390_dr (code, s390_r0, ins->sreg2);
3541 s390_lgfr (code, ins->dreg, s390_r0);
3542 break;
3543 case OP_IREM_UN:
3544 s390_lgfr (code, s390_r0, ins->sreg1);
3545 s390_srdl (code, s390_r0, 0, 32);
3546 s390_dlr (code, s390_r0, ins->sreg2);
3547 s390_lgfr (code, ins->dreg, s390_r0);
3549 break;
3550 case OP_IREM_IMM: {
3551 if (s390_is_imm16 (ins->inst_imm)) {
3552 s390_lghi (code, s390_r13, ins->inst_imm);
3553 s390_lgfr (code, s390_r0, ins->sreg1);
3554 } else {
3555 s390_basr (code, s390_r13, 0);
3556 s390_j (code, 4);
3557 s390_word (code, ins->inst_imm);
3558 s390_lgfr (code, s390_r0, ins->sreg1);
3559 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3561 s390_srda (code, s390_r0, 0, 32);
3562 s390_dr (code, s390_r0, ins->sreg2);
3563 s390_lgfr (code, ins->dreg, s390_r0);
3565 break;
3566 case OP_IOR: {
3567 CHECK_SRCDST_COM_I;
3568 s390_ogr (code, ins->dreg, src2);
3570 break;
3571 case OP_IOR_IMM: {
3572 if (ins->dreg != ins->sreg1) {
3573 s390_lgfr (code, ins->dreg, ins->sreg1);
3575 if (s390_is_imm16 (ins->inst_imm)) {
3576 s390_lghi (code, s390_r0, ins->inst_imm);
3577 s390_ogr (code, ins->dreg, s390_r0);
3578 } else {
3579 s390_basr (code, s390_r13, 0);
3580 s390_j (code, 6);
3581 s390_llong(code, ins->inst_imm);
3582 s390_og (code, ins->dreg, 0, s390_r13, 4);
3585 break;
3586 case OP_IXOR: {
3587 CHECK_SRCDST_COM_I;
3588 s390_xgr (code, ins->dreg, src2);
3590 break;
3591 case OP_IXOR_IMM: {
3592 if (ins->dreg != ins->sreg1) {
3593 s390_lgfr (code, ins->dreg, ins->sreg1);
3595 if (s390_is_imm16 (ins->inst_imm)) {
3596 s390_lghi (code, s390_r0, ins->inst_imm);
3597 s390_xgr (code, ins->dreg, s390_r0);
3598 } else {
3599 s390_basr (code, s390_r13, 0);
3600 s390_j (code, 6);
3601 s390_llong(code, ins->inst_imm);
3602 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3605 break;
3606 case OP_ISHL: {
3607 CHECK_SRCDST_NCOM;
3608 s390_sll (code, ins->dreg, src2, 0);
3610 break;
3611 case OP_ISHL_IMM: {
3612 if (ins->sreg1 != ins->dreg) {
3613 s390_lgfr (code, ins->dreg, ins->sreg1);
3615 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3617 break;
3618 case OP_ISHR: {
3619 CHECK_SRCDST_NCOM;
3620 s390_sra (code, ins->dreg, src2, 0);
3622 break;
3623 case OP_ISHR_IMM: {
3624 if (ins->sreg1 != ins->dreg) {
3625 s390_lgfr (code, ins->dreg, ins->sreg1);
3627 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3629 break;
3630 case OP_ISHR_UN_IMM: {
3631 if (ins->sreg1 != ins->dreg) {
3632 s390_lgfr (code, ins->dreg, ins->sreg1);
3634 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3636 break;
3637 case OP_ISHR_UN: {
3638 CHECK_SRCDST_NCOM;
3639 s390_srl (code, ins->dreg, src2, 0);
3641 break;
3642 case OP_INOT: {
3643 if (ins->sreg1 != ins->dreg) {
3644 s390_lgfr (code, ins->dreg, ins->sreg1);
3646 s390_lghi (code, s390_r0, -1);
3647 s390_xgr (code, ins->dreg, s390_r0);
3649 break;
3650 case OP_INEG: {
3651 s390_lcgr (code, ins->dreg, ins->sreg1);
3653 break;
3654 case OP_IMUL: {
3655 CHECK_SRCDST_COM_I;
3656 s390_msr (code, ins->dreg, src2);
3658 break;
3659 case OP_IMUL_IMM: {
3660 if (ins->dreg != ins->sreg1) {
3661 s390_lgfr (code, ins->dreg, ins->sreg1);
3663 if (s390_is_imm16 (ins->inst_imm)) {
3664 s390_lghi (code, s390_r13, ins->inst_imm);
3665 } else {
3666 s390_basr (code, s390_r13, 0);
3667 s390_j (code, 4);
3668 s390_word (code, ins->inst_imm);
3669 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3671 s390_msr (code, ins->dreg, s390_r13);
3673 break;
3674 case OP_IMUL_OVF: {
3675 short int *o[2];
3676 s390_ltr (code, s390_r1, ins->sreg1);
3677 s390_jz (code, 0); CODEPTR(code, o[0]);
3678 s390_ltr (code, s390_r0, ins->sreg2);
3679 s390_jnz (code, 6);
3680 s390_lhi (code, s390_r1, 0);
3681 s390_j (code, 0); CODEPTR(code, o[1]);
3682 s390_xr (code, s390_r0, s390_r1);
3683 s390_msr (code, s390_r1, ins->sreg2);
3684 s390_xr (code, s390_r0, s390_r1);
3685 s390_srl (code, s390_r0, 0, 31);
3686 s390_ltr (code, s390_r0, s390_r0);
3687 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3688 PTRSLOT (code, o[0]);
3689 PTRSLOT (code, o[1]);
3690 s390_lgfr (code, ins->dreg, s390_r1);
3692 break;
3693 case OP_IMUL_OVF_UN: {
3694 s390_lhi (code, s390_r0, 0);
3695 s390_lr (code, s390_r1, ins->sreg1);
3696 s390_mlr (code, s390_r0, ins->sreg2);
3697 s390_ltr (code, s390_r0, s390_r0);
3698 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3699 s390_lgfr (code, ins->dreg, s390_r1);
3701 break;
3702 case OP_ICONST:
3703 case OP_I8CONST: {
3704 if (s390_is_imm16(ins->inst_c0)) {
3705 s390_lghi (code, ins->dreg, ins->inst_c0);
3706 } else {
3707 s390_basr (code, s390_r13, 0);
3708 s390_j (code, 6);
3709 s390_llong(code, ins->inst_c0);
3710 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3713 break;
3714 case OP_AOTCONST: {
3715 s390_basr (code, s390_r13, 0);
3716 s390_j (code, 6);
3717 mono_add_patch_info (cfg, code - cfg->native_code,
3718 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3719 s390_llong(code, 0);
3720 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3722 break;
3723 case OP_JUMP_TABLE: {
3724 mono_add_patch_info (cfg, code - cfg->native_code,
3725 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3726 s390_basr (code, s390_r13, 0);
3727 s390_j (code, 6);
3728 s390_llong (code, 0);
3729 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3731 break;
3732 case OP_MOVE:
3733 if (ins->dreg != ins->sreg1) {
3734 s390_lgr (code, ins->dreg, ins->sreg1);
3736 break;
3737 case OP_LCONV_TO_I:
3738 case OP_LCONV_TO_I8:
3739 case OP_SEXT_I4:
3740 s390_lgfr (code, ins->dreg, ins->sreg1);
3741 break;
3742 case OP_LCONV_TO_I4:
3743 s390_lgfr (code, ins->dreg, ins->sreg1);
3744 break;
3745 case OP_LCONV_TO_U:
3746 case OP_LCONV_TO_U8:
3747 case OP_LCONV_TO_U4:
3748 case OP_ZEXT_I4:
3749 s390_llgfr (code, ins->dreg, ins->sreg1);
3750 break;
3751 case OP_LCONV_TO_OVF_U4:
3752 s390_basr (code, s390_r13, 0);
3753 s390_j (code, 6);
3754 s390_llong(code, 4294967295);
3755 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3756 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3757 s390_ltgr (code, ins->sreg1, ins->sreg1);
3758 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3759 s390_llgfr(code, ins->dreg, ins->sreg1);
3760 break;
3761 case OP_LCONV_TO_OVF_I4_UN:
3762 s390_basr (code, s390_r13, 0);
3763 s390_j (code, 6);
3764 s390_llong(code, 2147483647);
3765 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3766 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3767 s390_ltgr (code, ins->sreg1, ins->sreg1);
3768 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3769 s390_lgfr (code, ins->dreg, ins->sreg1);
3770 break;
3771 case OP_FMOVE:
3772 case OP_FCONV_TO_R4: {
3773 if (ins->dreg != ins->sreg1) {
3774 s390_ldr (code, ins->dreg, ins->sreg1);
3777 break;
3778 case OP_S390_SETF4RET: {
3779 s390_ledbr (code, ins->dreg, ins->sreg1);
3781 break;
3782 case OP_JMP: {
3783 if (cfg->method->save_lmf)
3784 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3786 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3787 code = emit_load_volatile_arguments (code, cfg);
3790 code = backUpStackPtr(cfg, code);
3791 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3792 mono_add_patch_info (cfg, code - cfg->native_code,
3793 MONO_PATCH_INFO_METHOD_JUMP,
3794 ins->inst_p0);
3795 s390_jcl (code, S390_CC_UN, 0);
3797 break;
3798 case OP_CHECK_THIS: {
3799 /* ensure ins->sreg1 is not NULL */
3800 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3801 s390_ltgr (code, s390_r0, s390_r0);
3803 break;
3804 case OP_ARGLIST: {
3805 int offset = cfg->sig_cookie + cfg->stack_usage;
3807 if (s390_is_imm16 (offset))
3808 s390_lghi (code, s390_r0, offset);
3809 else {
3810 s390_basr (code, s390_r13, 0);
3811 s390_j (code, 6);
3812 s390_llong(code, offset);
3813 s390_lg (code, s390_r0, 0, s390_r13, 0);
3815 s390_agr (code, s390_r0, cfg->frame_reg);
3816 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3818 break;
3819 case OP_FCALL: {
3820 s390_basr (code, s390_r13, 0);
3821 s390_j (code, 6);
3822 call = (MonoCallInst*)ins;
3823 if (ins->flags & MONO_INST_HAS_METHOD)
3824 mono_add_patch_info (cfg, code-cfg->native_code,
3825 MONO_PATCH_INFO_METHOD,
3826 call->method);
3827 else
3828 mono_add_patch_info (cfg, code-cfg->native_code,
3829 MONO_PATCH_INFO_ABS,
3830 call->fptr);
3831 s390_llong(code, 0);
3832 s390_lg (code, s390_r14, 0, s390_r13, 4);
3833 s390_basr (code, s390_r14, s390_r14);
3834 if (call->signature->ret->type == MONO_TYPE_R4)
3835 s390_ldebr (code, s390_f0, s390_f0);
3837 break;
3838 case OP_LCALL:
3839 case OP_VCALL:
3840 case OP_VCALL2:
3841 case OP_VOIDCALL:
3842 case OP_CALL: {
3843 s390_basr (code, s390_r13, 0);
3844 s390_j (code, 6);
3845 call = (MonoCallInst*)ins;
3846 if (ins->flags & MONO_INST_HAS_METHOD)
3847 mono_add_patch_info (cfg, code-cfg->native_code,
3848 MONO_PATCH_INFO_METHOD,
3849 call->method);
3850 else
3851 mono_add_patch_info (cfg, code-cfg->native_code,
3852 MONO_PATCH_INFO_ABS,
3853 call->fptr);
3854 s390_llong(code, 0);
3855 s390_lg (code, s390_r14, 0, s390_r13, 4);
3856 s390_basr (code, s390_r14, s390_r14);
3858 break;
3859 case OP_FCALL_REG: {
3860 call = (MonoCallInst*)ins;
3861 s390_lgr (code, s390_r1, ins->sreg1);
3862 s390_basr (code, s390_r14, s390_r1);
3863 if (call->signature->ret->type == MONO_TYPE_R4)
3864 s390_ldebr (code, s390_f0, s390_f0);
3866 break;
3867 case OP_LCALL_REG:
3868 case OP_VCALL_REG:
3869 case OP_VCALL2_REG:
3870 case OP_VOIDCALL_REG:
3871 case OP_CALL_REG: {
3872 s390_lgr (code, s390_r1, ins->sreg1);
3873 s390_basr (code, s390_r14, s390_r1);
3875 break;
3876 case OP_FCALL_MEMBASE: {
3877 call = (MonoCallInst*)ins;
3878 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3879 s390_basr (code, s390_r14, s390_r1);
3880 if (call->signature->ret->type == MONO_TYPE_R4)
3881 s390_ldebr (code, s390_f0, s390_f0);
3883 break;
3884 case OP_LCALL_MEMBASE:
3885 case OP_VCALL_MEMBASE:
3886 case OP_VCALL2_MEMBASE:
3887 case OP_VOIDCALL_MEMBASE:
3888 case OP_CALL_MEMBASE: {
3889 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3890 s390_basr (code, s390_r14, s390_r1);
3892 break;
3893 case OP_LOCALLOC: {
3894 int alloca_skip = S390_MINIMAL_STACK_SIZE + cfg->param_area;
3895 int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3896 s390_lgr (code, s390_r1, ins->sreg1);
3897 if (ins->flags & MONO_INST_INIT)
3898 s390_lgr (code, s390_r0, ins->sreg1);
3899 s390_aghi (code, s390_r1, 14);
3900 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3901 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3902 if (cfg->method->save_lmf) {
3903 /*----------------------------------*/
3904 /* we have to adjust lmf ebp value */
3905 /*----------------------------------*/
3906 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3908 s390_lgr (code, s390_r13, cfg->frame_reg);
3909 if (s390_is_imm16(lmfOffset))
3910 s390_aghi (code, s390_r13, lmfOffset);
3911 else {
3912 s390_basr (code, s390_r14, 0);
3913 s390_j (code, 4);
3914 s390_word (code, lmfOffset);
3915 s390_agf (code, s390_r13, 0, s390_r14, 4);
3917 s390_lgr (code, s390_r14, STK_BASE);
3918 s390_sgr (code, s390_r14, s390_r1);
3919 s390_stg (code, s390_r14, 0, s390_r13,
3920 G_STRUCT_OFFSET(MonoLMF, ebp));
3922 s390_lg (code, s390_r13, 0, STK_BASE, 0);
3923 s390_sgr (code, STK_BASE, s390_r1);
3924 s390_stg (code, s390_r13, 0, STK_BASE, 0);
3925 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
3926 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
3927 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
3928 if (ins->flags & MONO_INST_INIT) {
3929 s390_lgr (code, s390_r1, s390_r0);
3930 s390_lgr (code, s390_r0, ins->dreg);
3931 s390_lgr (code, s390_r14, s390_r12);
3932 s390_lghi (code, s390_r13, 0);
3933 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
3934 s390_jo (code, -2);
3935 s390_lgr (code, s390_r12, s390_r14);
3938 break;
3939 case OP_THROW: {
3940 s390_lgr (code, s390_r2, ins->sreg1);
3941 s390_basr (code, s390_r13, 0);
3942 s390_j (code, 6);
3943 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3944 (gpointer) "mono_arch_throw_exception");
3945 s390_llong(code, 0);
3946 s390_lg (code, s390_r14, 0, s390_r13, 4);
3947 s390_basr (code, s390_r14, s390_r14);
3949 break;
3950 case OP_RETHROW: {
3951 s390_lgr (code, s390_r2, ins->sreg1);
3952 s390_basr (code, s390_r13, 0);
3953 s390_j (code, 6);
3954 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3955 (gpointer) "mono_arch_rethrow_exception");
3956 s390_llong(code, 0);
3957 s390_lg (code, s390_r14, 0, s390_r13, 4);
3958 s390_basr (code, s390_r14, s390_r14);
3960 break;
3961 case OP_START_HANDLER: {
3962 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3964 S390_LONG (code, stg, stg, s390_r14, 0,
3965 spvar->inst_basereg,
3966 spvar->inst_offset);
3968 break;
3969 case OP_ENDFILTER: {
3970 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3972 if (ins->sreg1 != s390_r2)
3973 s390_lgr(code, s390_r2, ins->sreg1);
3974 S390_LONG (code, lg, lg, s390_r14, 0,
3975 spvar->inst_basereg,
3976 spvar->inst_offset);
3977 s390_br (code, s390_r14);
3979 break;
3980 case OP_ENDFINALLY: {
3981 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3983 S390_LONG (code, lg, lg, s390_r14, 0,
3984 spvar->inst_basereg,
3985 spvar->inst_offset);
3986 s390_br (code, s390_r14);
3988 break;
3989 case OP_CALL_HANDLER: {
3990 mono_add_patch_info (cfg, code-cfg->native_code,
3991 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3992 s390_brasl (code, s390_r14, 0);
3994 break;
3995 case OP_LABEL: {
3996 ins->inst_c0 = code - cfg->native_code;
3998 break;
3999 case OP_RELAXED_NOP:
4000 case OP_NOP:
4001 case OP_DUMMY_USE:
4002 case OP_DUMMY_STORE:
4003 case OP_NOT_REACHED:
4004 case OP_NOT_NULL: {
4006 break;
4007 case OP_BR:
4008 EMIT_UNCOND_BRANCH(ins);
4009 break;
4010 case OP_BR_REG: {
4011 s390_br (code, ins->sreg1);
4013 break;
4014 case OP_CEQ:
4015 case OP_ICEQ:
4016 case OP_LCEQ: {
4017 s390_lghi(code, ins->dreg, 1);
4018 s390_jz (code, 4);
4019 s390_lghi(code, ins->dreg, 0);
4021 break;
4022 case OP_CLT:
4023 case OP_ICLT:
4024 case OP_LCLT: {
4025 s390_lghi(code, ins->dreg, 1);
4026 s390_jl (code, 4);
4027 s390_lghi(code, ins->dreg, 0);
4029 break;
4030 case OP_CLT_UN:
4031 case OP_ICLT_UN:
4032 case OP_LCLT_UN: {
4033 s390_lghi(code, ins->dreg, 1);
4034 s390_jlo (code, 4);
4035 s390_lghi(code, ins->dreg, 0);
4037 break;
4038 case OP_CGT:
4039 case OP_ICGT:
4040 case OP_LCGT: {
4041 s390_lghi(code, ins->dreg, 1);
4042 s390_jh (code, 4);
4043 s390_lghi(code, ins->dreg, 0);
4045 break;
4046 case OP_CGT_UN:
4047 case OP_ICGT_UN:
4048 case OP_LCGT_UN: {
4049 s390_lghi(code, ins->dreg, 1);
4050 s390_jho (code, 4);
4051 s390_lghi(code, ins->dreg, 0);
4053 break;
4054 case OP_COND_EXC_EQ:
4055 case OP_COND_EXC_IEQ:
4056 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4057 break;
4058 case OP_COND_EXC_NE_UN:
4059 case OP_COND_EXC_INE_UN:
4060 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4061 break;
4062 case OP_COND_EXC_LT:
4063 case OP_COND_EXC_ILT:
4064 case OP_COND_EXC_LT_UN:
4065 case OP_COND_EXC_ILT_UN:
4066 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4067 break;
4068 case OP_COND_EXC_GT:
4069 case OP_COND_EXC_IGT:
4070 case OP_COND_EXC_GT_UN:
4071 case OP_COND_EXC_IGT_UN:
4072 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4073 break;
4074 case OP_COND_EXC_GE:
4075 case OP_COND_EXC_IGE:
4076 case OP_COND_EXC_GE_UN:
4077 case OP_COND_EXC_IGE_UN:
4078 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4079 break;
4080 case OP_COND_EXC_LE:
4081 case OP_COND_EXC_ILE:
4082 case OP_COND_EXC_LE_UN:
4083 case OP_COND_EXC_ILE_UN:
4084 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4085 break;
4086 case OP_COND_EXC_OV:
4087 case OP_COND_EXC_IOV:
4088 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4089 break;
4090 case OP_COND_EXC_NO:
4091 case OP_COND_EXC_INO:
4092 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4093 break;
4094 case OP_COND_EXC_C:
4095 case OP_COND_EXC_IC:
4096 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4097 break;
4098 case OP_COND_EXC_NC:
4099 case OP_COND_EXC_INC:
4100 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4101 break;
4102 case OP_LBEQ:
4103 case OP_IBEQ:
4104 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4105 break;
4106 case OP_LBNE_UN:
4107 case OP_IBNE_UN:
4108 EMIT_COND_BRANCH (ins, S390_CC_NE);
4109 break;
4110 case OP_LBLT:
4111 case OP_LBLT_UN:
4112 case OP_IBLT:
4113 case OP_IBLT_UN:
4114 EMIT_COND_BRANCH (ins, S390_CC_LT);
4115 break;
4116 case OP_LBGT:
4117 case OP_LBGT_UN:
4118 case OP_IBGT:
4119 case OP_IBGT_UN:
4120 EMIT_COND_BRANCH (ins, S390_CC_GT);
4121 break;
4122 case OP_LBGE:
4123 case OP_LBGE_UN:
4124 case OP_IBGE:
4125 case OP_IBGE_UN:
4126 EMIT_COND_BRANCH (ins, S390_CC_GE);
4127 break;
4128 case OP_LBLE:
4129 case OP_LBLE_UN:
4130 case OP_IBLE:
4131 case OP_IBLE_UN:
4132 EMIT_COND_BRANCH (ins, S390_CC_LE);
4133 break;
4135 /* floating point opcodes */
4136 case OP_R8CONST: {
4137 if (*((float *) ins->inst_p0) == 0) {
4138 s390_lzdr (code, ins->dreg);
4139 } else {
4140 s390_basr (code, s390_r13, 0);
4141 s390_j (code, 6);
4142 s390_llong (code, ins->inst_p0);
4143 s390_lg (code, s390_r13, 0, s390_r13, 4);
4144 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4147 break;
4148 case OP_R4CONST: {
4149 if (*((float *) ins->inst_p0) == 0) {
4150 s390_lzdr (code, ins->dreg);
4151 } else {
4152 s390_basr (code, s390_r13, 0);
4153 s390_j (code, 6);
4154 s390_llong(code, ins->inst_p0);
4155 s390_lg (code, s390_r13, 0, s390_r13, 4);
4156 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4159 break;
4160 case OP_STORER8_MEMBASE_REG: {
4161 S390_LONG (code, stdy, std, ins->sreg1, 0,
4162 ins->inst_destbasereg, ins->inst_offset);
4164 break;
4165 case OP_LOADR8_MEMBASE: {
4166 S390_LONG (code, ldy, ld, ins->dreg, 0,
4167 ins->inst_basereg, ins->inst_offset);
4169 break;
4170 case OP_STORER4_MEMBASE_REG: {
4171 s390_ledbr (code, s390_f15, ins->sreg1);
4172 S390_LONG (code, stey, ste, s390_f15, 0,
4173 ins->inst_destbasereg, ins->inst_offset);
4175 break;
4176 case OP_LOADR4_MEMBASE: {
4177 S390_LONG (code, ldy, ld, s390_f15, 0,
4178 ins->inst_basereg, ins->inst_offset);
4179 s390_ldebr (code, ins->dreg, s390_f15);
4181 break;
4182 case OP_ICONV_TO_R_UN: {
4183 s390_cdfbr (code, ins->dreg, ins->sreg1);
4184 s390_ltr (code, ins->sreg1, ins->sreg1);
4185 s390_jnl (code, 12);
4186 s390_basr (code, s390_r13, 0);
4187 s390_j (code, 6);
4188 s390_word (code, 0x41f00000);
4189 s390_word (code, 0);
4190 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4192 break;
4193 case OP_LCONV_TO_R_UN: {
4194 s390_cdgbr (code, ins->dreg, ins->sreg1);
4195 s390_ltgr (code, ins->sreg1, ins->sreg1);
4196 s390_jnl (code, 12);
4197 s390_basr (code, s390_r13, 0);
4198 s390_j (code, 6);
4199 s390_word (code, 0x41f00000);
4200 s390_word (code, 0);
4201 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4203 break;
4204 case OP_LCONV_TO_R4:
4205 case OP_ICONV_TO_R4: {
4206 s390_cdgbr (code, ins->dreg, ins->sreg1);
4208 break;
4209 case OP_LCONV_TO_R8:
4210 case OP_ICONV_TO_R8: {
4211 s390_cdgbr (code, ins->dreg, ins->sreg1);
4213 break;
4214 case OP_FCONV_TO_I1:
4215 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4216 break;
4217 case OP_FCONV_TO_U1:
4218 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4219 break;
4220 case OP_FCONV_TO_I2:
4221 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4222 break;
4223 case OP_FCONV_TO_U2:
4224 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4225 break;
4226 case OP_FCONV_TO_I4:
4227 case OP_FCONV_TO_I:
4228 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4229 break;
4230 case OP_FCONV_TO_U4:
4231 case OP_FCONV_TO_U:
4232 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4233 break;
4234 case OP_FCONV_TO_I8:
4235 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4236 break;
4237 case OP_LCONV_TO_OVF_I: {
4238 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4239 short int *o[5];
4240 s390_ltgr (code, ins->sreg2, ins->sreg2);
4241 s390_jnl (code, 0); CODEPTR(code, o[0]);
4242 s390_ltgr (code, ins->sreg1, ins->sreg1);
4243 s390_jnl (code, 0); CODEPTR(code, o[1]);
4244 s390_lhi (code, s390_r13, -1);
4245 s390_cgr (code, ins->sreg1, s390_r13);
4246 s390_jnz (code, 0); CODEPTR(code, o[2]);
4247 if (ins->dreg != ins->sreg2)
4248 s390_lgr (code, ins->dreg, ins->sreg2);
4249 s390_j (code, 0); CODEPTR(code, o[3]);
4250 PTRSLOT(code, o[0]);
4251 s390_jz (code, 0); CODEPTR(code, o[4]);
4252 PTRSLOT(code, o[1]);
4253 PTRSLOT(code, o[2]);
4254 mono_add_patch_info (cfg, code - cfg->native_code,
4255 MONO_PATCH_INFO_EXC, "OverflowException");
4256 s390_brasl (code, s390_r14, 0);
4257 PTRSLOT(code, o[3]);
4258 PTRSLOT(code, o[4]);
4260 break;
4261 case OP_ABS: {
4262 s390_lpdbr (code, ins->dreg, ins->sreg1);
4264 break;
4265 case OP_SQRT: {
4266 s390_sqdbr (code, ins->dreg, ins->sreg1);
4268 break;
4269 case OP_FADD: {
4270 CHECK_SRCDST_COM_F;
4271 s390_adbr (code, ins->dreg, src2);
4273 break;
4274 case OP_FSUB: {
4275 CHECK_SRCDST_NCOM_F;
4276 s390_sdbr (code, ins->dreg, src2);
4278 break;
4279 case OP_FMUL: {
4280 CHECK_SRCDST_COM_F;
4281 s390_mdbr (code, ins->dreg, src2);
4283 break;
4284 case OP_FDIV: {
4285 CHECK_SRCDST_NCOM_F;
4286 s390_ddbr (code, ins->dreg, src2);
4288 break;
4289 case OP_FNEG: {
4290 s390_lcdbr (code, ins->dreg, ins->sreg1);
4292 break;
4293 case OP_FREM: {
4294 CHECK_SRCDST_NCOM_F;
4295 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4297 break;
4298 case OP_FCOMPARE: {
4299 s390_cdbr (code, ins->sreg1, ins->sreg2);
4301 break;
4302 case OP_FCEQ: {
4303 s390_cdbr (code, ins->sreg1, ins->sreg2);
4304 s390_lghi (code, ins->dreg, 1);
4305 s390_je (code, 4);
4306 s390_lghi (code, ins->dreg, 0);
4308 break;
4309 case OP_FCLT: {
4310 s390_cdbr (code, ins->sreg1, ins->sreg2);
4311 s390_lghi (code, ins->dreg, 1);
4312 s390_jl (code, 4);
4313 s390_lghi (code, ins->dreg, 0);
4315 break;
4316 case OP_FCLT_UN: {
4317 s390_cdbr (code, ins->sreg1, ins->sreg2);
4318 s390_lghi (code, ins->dreg, 1);
4319 s390_jlo (code, 4);
4320 s390_lghi (code, ins->dreg, 0);
4322 break;
4323 case OP_FCGT: {
4324 s390_cdbr (code, ins->sreg1, ins->sreg2);
4325 s390_lghi (code, ins->dreg, 1);
4326 s390_jh (code, 4);
4327 s390_lghi (code, ins->dreg, 0);
4329 break;
4330 case OP_FCGT_UN: {
4331 s390_cdbr (code, ins->sreg1, ins->sreg2);
4332 s390_lghi (code, ins->dreg, 1);
4333 s390_jho (code, 4);
4334 s390_lghi (code, ins->dreg, 0);
4336 break;
4337 case OP_FBEQ: {
4338 short *o;
4339 s390_jo (code, 0); CODEPTR(code, o);
4340 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4341 PTRSLOT (code, o);
4343 break;
4344 case OP_FBNE_UN:
4345 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4346 break;
4347 case OP_FBLT: {
4348 short *o;
4349 s390_jo (code, 0); CODEPTR(code, o);
4350 EMIT_COND_BRANCH (ins, S390_CC_LT);
4351 PTRSLOT (code, o);
4353 break;
4354 case OP_FBLT_UN:
4355 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4356 break;
4357 case OP_FBGT: {
4358 short *o;
4359 s390_jo (code, 0); CODEPTR(code, o);
4360 EMIT_COND_BRANCH (ins, S390_CC_GT);
4361 PTRSLOT (code, o);
4363 break;
4364 case OP_FBGT_UN:
4365 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4366 break;
4367 case OP_FBGE: {
4368 short *o;
4369 s390_jo (code, 0); CODEPTR(code, o);
4370 EMIT_COND_BRANCH (ins, S390_CC_GE);
4371 PTRSLOT (code, o);
4373 break;
4374 case OP_FBGE_UN:
4375 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4376 break;
4377 case OP_FBLE: {
4378 short *o;
4379 s390_jo (code, 0); CODEPTR(code, o);
4380 EMIT_COND_BRANCH (ins, S390_CC_LE);
4381 PTRSLOT (code, o);
4383 break;
4384 case OP_FBLE_UN:
4385 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4386 break;
4387 case OP_CKFINITE: {
4388 short *o;
4389 s390_lhi (code, s390_r13, 0x7f);
4390 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4391 s390_jz (code, 0); CODEPTR(code, o);
4392 mono_add_patch_info (cfg, code - cfg->native_code,
4393 MONO_PATCH_INFO_EXC, "ArithmeticException");
4394 s390_brasl (code, s390_r14,0);
4395 PTRSLOT(code, o);
4397 break;
4398 case OP_S390_MOVE: {
4399 if (ins->backend.size > 0) {
4400 if (ins->backend.size <= 256) {
4401 s390_mvc (code, ins->backend.size, ins->dreg,
4402 ins->inst_offset, ins->sreg1, ins->inst_imm);
4403 } else {
4404 s390_lgr (code, s390_r0, ins->dreg);
4405 if (s390_is_imm16 (ins->inst_offset)) {
4406 s390_aghi (code, s390_r0, ins->inst_offset);
4407 } else {
4408 s390_basr (code, s390_r13, 0);
4409 s390_j (code, 6);
4410 s390_llong(code, ins->inst_offset);
4411 s390_a (code, s390_r0, 0, s390_r13, 4);
4413 s390_lgr (code, s390_r12, ins->sreg1);
4414 if (s390_is_imm16 (ins->inst_imm)) {
4415 s390_aghi (code, s390_r12, ins->inst_imm);
4416 } else {
4417 s390_basr (code, s390_r13, 0);
4418 s390_j (code, 6);
4419 s390_llong(code, ins->inst_imm);
4420 s390_ag (code, s390_r12, 0, s390_r13, 4);
4422 s390_lgr (code, s390_r1, ins->sreg1);
4423 s390_lgr (code, s390_r13, s390_r1);
4424 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4425 s390_jo (code, -2);
4429 break;
4430 case OP_ATOMIC_ADD_I8: {
4431 s390_lgr (code, s390_r1, ins->sreg2);
4432 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4433 s390_agr (code, s390_r1, s390_r0);
4434 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4435 s390_jnz (code, -10);
4436 s390_lgr (code, ins->dreg, s390_r1);
4438 break;
4439 case OP_ATOMIC_ADD_NEW_I8: {
4440 s390_lgr (code, s390_r1, ins->sreg2);
4441 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4442 s390_agr (code, s390_r1, s390_r0);
4443 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4444 s390_jnz (code, -10);
4445 s390_lgr (code, ins->dreg, s390_r1);
4447 break;
4448 case OP_ATOMIC_EXCHANGE_I8: {
4449 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4450 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4451 s390_jnz (code, -6);
4452 s390_lgr (code, ins->dreg, s390_r0);
4454 break;
4455 case OP_ATOMIC_ADD_I4: {
4456 s390_lgfr(code, s390_r1, ins->sreg2);
4457 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4458 s390_agr (code, s390_r1, s390_r0);
4459 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4460 s390_jnz (code, -9);
4461 s390_lgfr(code, ins->dreg, s390_r1);
4463 break;
4464 case OP_ATOMIC_ADD_NEW_I4: {
4465 s390_lgfr(code, s390_r1, ins->sreg2);
4466 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4467 s390_agr (code, s390_r1, s390_r0);
4468 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4469 s390_jnz (code, -9);
4470 s390_lgfr(code, ins->dreg, s390_r1);
4472 break;
4473 case OP_ATOMIC_EXCHANGE_I4: {
4474 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4475 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4476 s390_jnz (code, -4);
4477 s390_lgfr(code, ins->dreg, s390_r0);
4479 break;
4480 case OP_S390_BKCHAIN: {
4481 s390_lgr (code, ins->dreg, ins->sreg1);
4482 if (s390_is_imm16 (cfg->stack_offset)) {
4483 s390_aghi (code, ins->dreg, cfg->stack_offset);
4484 } else {
4485 s390_basr (code, s390_r13, 0);
4486 s390_j (code, 6);
4487 s390_llong(code, cfg->stack_offset);
4488 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4491 break;
4492 case OP_MEMORY_BARRIER: {
4494 break;
4495 default:
4496 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4497 g_assert_not_reached ();
4500 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4501 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4502 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4503 g_assert_not_reached ();
4506 cpos += max_len;
4508 last_offset = offset;
4511 cfg->code_len = code - cfg->native_code;
4514 /*========================= End of Function ========================*/
4516 /*------------------------------------------------------------------*/
4517 /* */
4518 /* Name - mono_arch_register_lowlevel_calls */
4519 /* */
4520 /* Function - Register routines to help with --trace operation. */
4521 /* */
4522 /*------------------------------------------------------------------*/
4524 void
4525 mono_arch_register_lowlevel_calls (void)
4527 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4530 /*========================= End of Function ========================*/
4532 /*------------------------------------------------------------------*/
4533 /* */
4534 /* Name - mono_arch_patch_code */
4535 /* */
4536 /* Function - Process the patch data created during the */
4537 /* instruction build process. This resolves jumps, */
4538 /* calls, variables etc. */
4539 /* */
4540 /*------------------------------------------------------------------*/
4542 void
4543 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4544 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4546 MonoJumpInfo *patch_info;
4548 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4549 unsigned char *ip = patch_info->ip.i + code;
4550 gconstpointer target = NULL;
4552 target = mono_resolve_patch_target (method, domain, code,
4553 patch_info, run_cctors);
4555 switch (patch_info->type) {
4556 case MONO_PATCH_INFO_IP:
4557 case MONO_PATCH_INFO_EXC_NAME:
4558 case MONO_PATCH_INFO_LDSTR:
4559 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4560 case MONO_PATCH_INFO_LDTOKEN:
4561 case MONO_PATCH_INFO_EXC:
4562 case MONO_PATCH_INFO_ABS:
4563 case MONO_PATCH_INFO_METHOD:
4564 case MONO_PATCH_INFO_INTERNAL_METHOD:
4565 case MONO_PATCH_INFO_CLASS_INIT:
4566 s390_patch_addr (ip, (guint64) target);
4567 continue;
4568 case MONO_PATCH_INFO_SWITCH:
4569 /*----------------------------------*/
4570 /* ip points at the basr r13,0/j +4 */
4571 /* instruction the vtable value */
4572 /* follows this (i.e. ip+6) */
4573 /*----------------------------------*/
4574 *((gconstpointer *)(ip+6)) = target;
4575 continue;
4576 case MONO_PATCH_INFO_METHODCONST:
4577 case MONO_PATCH_INFO_CLASS:
4578 case MONO_PATCH_INFO_IMAGE:
4579 case MONO_PATCH_INFO_FIELD:
4580 case MONO_PATCH_INFO_IID:
4581 target = S390_RELATIVE(target, ip);
4582 s390_patch_rel (ip, (guint64) target);
4583 continue;
4584 case MONO_PATCH_INFO_R4:
4585 case MONO_PATCH_INFO_R8:
4586 case MONO_PATCH_INFO_METHOD_REL:
4587 g_assert_not_reached ();
4588 continue;
4589 default:
4590 target = S390_RELATIVE(target, ip);
4591 ip += 2;
4592 s390_patch_rel (ip, (guint64) target);
4597 /*========================= End of Function ========================*/
4599 /*------------------------------------------------------------------*/
4600 /* */
4601 /* Name - emit_load_volatile_arguments */
4602 /* */
4603 /* Function - Emit the instructions to reload parameter regist- */
4604 /* registers for use with "tail" operations. */
4605 /* */
4606 /* The register loading operations performed here */
4607 /* are the mirror of the store operations performed */
4608 /* in mono_arch_emit_prolog and need to be kept in */
4609 /* synchronization with it. */
4610 /* */
4611 /*------------------------------------------------------------------*/
4613 guint8 *
4614 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4616 MonoInst *inst;
4617 MonoMethod *method = cfg->method;
4618 MonoMethodSignature *sig = mono_method_signature(method);
4619 int pos = 0, i;
4620 CallInfo *cinfo;
4622 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4624 if (cinfo->struct_ret) {
4625 ArgInfo *ainfo = &cinfo->ret;
4626 inst = cfg->vret_addr;
4627 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4630 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4631 ArgInfo *ainfo = cinfo->args + i;
4632 inst = cfg->args [pos];
4634 if (inst->opcode == OP_REGVAR) {
4635 if (ainfo->regtype == RegTypeGeneral)
4636 s390_lgr (code, ainfo->reg, inst->dreg);
4637 else if (ainfo->regtype == RegTypeFP) {
4638 if (inst->dreg != ainfo->reg) {
4639 if (ainfo->size == 4) {
4640 s390_ldebr (code, ainfo->reg, inst->dreg);
4641 } else {
4642 s390_ldr (code, ainfo->reg, inst->dreg);
4646 else if (ainfo->regtype == RegTypeBase) {
4647 } else
4648 g_assert_not_reached ();
4649 } else {
4650 if (ainfo->regtype == RegTypeGeneral) {
4651 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4652 g_assert_not_reached();
4653 switch (ainfo->size) {
4654 case 1:
4655 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4656 break;
4657 case 2:
4658 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4659 break;
4660 case 4:
4661 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4662 break;
4663 case 8:
4664 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4665 break;
4667 } else if (ainfo->regtype == RegTypeBase) {
4668 } else if (ainfo->regtype == RegTypeFP) {
4669 if (ainfo->size == 8)
4670 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4671 else if (ainfo->size == 4)
4672 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4673 else
4674 g_assert_not_reached ();
4675 } else if (ainfo->regtype == RegTypeStructByVal) {
4676 if (ainfo->reg != STK_BASE) {
4677 switch (ainfo->size) {
4678 case 1:
4679 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4680 break;
4681 case 2:
4682 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4683 break;
4684 case 4:
4685 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4686 break;
4687 case 8:
4688 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4689 break;
4692 } else if (ainfo->regtype == RegTypeStructByAddr) {
4693 if (ainfo->reg != STK_BASE) {
4694 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4696 } else
4697 g_assert_not_reached ();
4699 pos++;
4702 return code;
4705 /*========================= End of Function ========================*/
4707 /*------------------------------------------------------------------*/
4708 /* */
4709 /* Name - mono_arch_emit_prolog */
4710 /* */
4711 /* Function - Create the instruction sequence for a function */
4712 /* prolog. */
4713 /* */
4714 /*------------------------------------------------------------------*/
4716 guint8 *
4717 mono_arch_emit_prolog (MonoCompile *cfg)
4719 MonoMethod *method = cfg->method;
4720 MonoBasicBlock *bb;
4721 MonoMethodSignature *sig;
4722 MonoInst *inst;
4723 int alloc_size, pos, max_offset, i;
4724 guint8 *code;
4725 CallInfo *cinfo;
4726 int tracing = 0;
4727 int lmfOffset;
4729 cfg->code_size = 512;
4731 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4732 tracing = 1;
4733 cfg->code_size += 256;
4736 if (method->save_lmf)
4737 cfg->code_size += 200;
4739 cfg->native_code = code = g_malloc (cfg->code_size);
4741 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4743 if (cfg->arch.bkchain_reg != -1)
4744 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4746 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4747 cfg->used_int_regs |= 1 << 11;
4750 alloc_size = cfg->stack_offset;
4752 cfg->stack_usage = alloc_size;
4753 s390_lgr (code, s390_r11, STK_BASE);
4754 if (s390_is_imm16 (alloc_size)) {
4755 s390_aghi (code, STK_BASE, -alloc_size);
4756 } else {
4757 int stackSize = alloc_size;
4758 while (stackSize > 32767) {
4759 s390_aghi (code, STK_BASE, -32767);
4760 stackSize -= 32767;
4762 s390_aghi (code, STK_BASE, -stackSize);
4764 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4766 if (cfg->frame_reg != STK_BASE)
4767 s390_lgr (code, s390_r11, STK_BASE);
4769 /* compute max_offset in order to use short forward jumps
4770 * we always do it on s390 because the immediate displacement
4771 * for jumps is too small
4773 max_offset = 0;
4774 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4775 MonoInst *ins;
4776 bb->max_offset = max_offset;
4778 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4779 max_offset += 6;
4781 MONO_BB_FOR_EACH_INS (bb, ins)
4782 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4785 /* load arguments allocated to register from the stack */
4786 sig = mono_method_signature (method);
4787 pos = 0;
4789 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4791 if (cinfo->struct_ret) {
4792 ArgInfo *ainfo = &cinfo->ret;
4793 inst = cfg->vret_addr;
4794 inst->backend.size = ainfo->vtsize;
4795 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4798 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4799 ArgInfo *ainfo = cinfo->args + i;
4800 inst = cfg->args [pos];
4802 if (inst->opcode == OP_VTARG_ADDR)
4803 inst = inst->inst_left;
4805 if (inst->opcode == OP_REGVAR) {
4806 if (ainfo->regtype == RegTypeGeneral)
4807 s390_lgr (code, inst->dreg, ainfo->reg);
4808 else if (ainfo->regtype == RegTypeFP) {
4809 if (inst->dreg != ainfo->reg) {
4810 if (ainfo->size == 4) {
4811 s390_ledbr (code, inst->dreg, ainfo->reg);
4812 } else {
4813 s390_ldr (code, inst->dreg, ainfo->reg);
4817 else if (ainfo->regtype == RegTypeBase) {
4818 s390_lgr (code, s390_r13, STK_BASE);
4819 s390_aghi (code, s390_r13, alloc_size);
4820 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4821 } else
4822 g_assert_not_reached ();
4824 if (cfg->verbose_level > 2)
4825 g_print ("Argument %d assigned to register %s\n",
4826 pos, mono_arch_regname (inst->dreg));
4827 } else {
4828 if (ainfo->regtype == RegTypeGeneral) {
4829 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4830 g_assert_not_reached();
4831 switch (ainfo->size) {
4832 case 1:
4833 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4834 break;
4835 case 2:
4836 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4837 break;
4838 case 4:
4839 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4840 break;
4841 case 8:
4842 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4843 break;
4845 } else if (ainfo->regtype == RegTypeBase) {
4846 } else if (ainfo->regtype == RegTypeFP) {
4847 if (ainfo->size == 8)
4848 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4849 else if (ainfo->size == 4)
4850 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4851 else
4852 g_assert_not_reached ();
4853 } else if (ainfo->regtype == RegTypeStructByVal) {
4854 int doffset = inst->inst_offset;
4855 int reg;
4856 if (ainfo->reg != STK_BASE)
4857 reg = ainfo->reg;
4858 else {
4859 reg = s390_r0;
4860 s390_lgr (code, s390_r13, STK_BASE);
4861 s390_aghi (code, s390_r13, alloc_size);
4863 switch (ainfo->size) {
4864 case 1:
4865 if (ainfo->reg == STK_BASE)
4866 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
4867 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4868 break;
4869 case 2:
4870 if (ainfo->reg == STK_BASE)
4871 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
4872 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4873 break;
4874 case 4:
4875 if (ainfo->reg == STK_BASE)
4876 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
4877 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4878 break;
4879 case 8:
4880 if (ainfo->reg == STK_BASE)
4881 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
4882 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
4883 break;
4885 } else if (ainfo->regtype == RegTypeStructByAddr) {
4886 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4887 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
4888 } else
4889 g_assert_not_reached ();
4891 pos++;
4894 if (method->save_lmf) {
4895 /*---------------------------------------------------------------*/
4896 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4897 /*---------------------------------------------------------------*/
4898 lmfOffset = alloc_size - sizeof(MonoLMF);
4900 s390_lgr (code, s390_r13, cfg->frame_reg);
4901 s390_aghi (code, s390_r13, lmfOffset);
4903 /*---------------------------------------------------------------*/
4904 /* Preserve the parameter registers while we fix up the lmf */
4905 /*---------------------------------------------------------------*/
4906 s390_stmg (code, s390_r2, s390_r6, s390_r13,
4907 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4909 /*---------------------------------------------------------------*/
4910 /* On return from this call r2 have the address of the &lmf */
4911 /*---------------------------------------------------------------*/
4912 s390_basr(code, s390_r10, 0);
4913 s390_j (code, 6);
4914 mono_add_patch_info (cfg, code - cfg->native_code,
4915 MONO_PATCH_INFO_INTERNAL_METHOD,
4916 (gpointer)"mono_get_lmf_addr");
4917 s390_llong(code, 0);
4918 s390_lg (code, s390_r1, 0, s390_r10, 4);
4919 s390_basr (code, s390_r14, s390_r1);
4921 /*---------------------------------------------------------------*/
4922 /* Set lmf.lmf_addr = jit_tls->lmf */
4923 /*---------------------------------------------------------------*/
4924 s390_stg (code, s390_r2, 0, s390_r13,
4925 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4927 /*---------------------------------------------------------------*/
4928 /* Get current lmf */
4929 /*---------------------------------------------------------------*/
4930 s390_lg (code, s390_r0, 0, s390_r2, 0);
4932 /*---------------------------------------------------------------*/
4933 /* Set our lmf as the current lmf */
4934 /*---------------------------------------------------------------*/
4935 s390_stg (code, s390_r13, 0, s390_r2, 0);
4937 /*---------------------------------------------------------------*/
4938 /* Have our lmf.previous_lmf point to the last lmf */
4939 /*---------------------------------------------------------------*/
4940 s390_stg (code, s390_r0, 0, s390_r13,
4941 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4943 /*---------------------------------------------------------------*/
4944 /* save method info */
4945 /*---------------------------------------------------------------*/
4946 s390_basr (code, s390_r1, 0);
4947 s390_j (code, 6);
4948 s390_llong (code, method);
4949 s390_lg (code, s390_r1, 0, s390_r1, 4);
4950 s390_stg (code, s390_r1, 0, s390_r13,
4951 G_STRUCT_OFFSET(MonoLMF, method));
4953 /*---------------------------------------------------------------*/
4954 /* save the current IP */
4955 /*---------------------------------------------------------------*/
4956 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4957 s390_basr (code, s390_r1, 0);
4958 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4960 /*---------------------------------------------------------------*/
4961 /* Save general and floating point registers */
4962 /*---------------------------------------------------------------*/
4963 s390_stmg (code, s390_r2, s390_r12, s390_r13,
4964 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
4965 for (i = 0; i < 16; i++) {
4966 s390_std (code, i, 0, s390_r13,
4967 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
4970 /*---------------------------------------------------------------*/
4971 /* Restore the parameter registers now that we've set up the lmf */
4972 /*---------------------------------------------------------------*/
4973 s390_lmg (code, s390_r2, s390_r6, s390_r13,
4974 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4977 if (tracing)
4978 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
4980 cfg->code_len = code - cfg->native_code;
4981 g_assert (cfg->code_len < cfg->code_size);
4983 return code;
4986 /*========================= End of Function ========================*/
4988 /*------------------------------------------------------------------*/
4989 /* */
4990 /* Name - mono_arch_emit_epilog */
4991 /* */
4992 /* Function - Emit the instructions for a function epilog. */
4993 /* */
4994 /*------------------------------------------------------------------*/
4996 void
4997 mono_arch_emit_epilog (MonoCompile *cfg)
4999 MonoMethod *method = cfg->method;
5000 int tracing = 0;
5001 guint8 *code;
5002 int max_epilog_size = 96;
5004 if (cfg->method->save_lmf)
5005 max_epilog_size += 128;
5007 if (mono_jit_trace_calls != NULL)
5008 max_epilog_size += 128;
5010 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5011 max_epilog_size += 128;
5013 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5014 cfg->code_size *= 2;
5015 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5016 mono_jit_stats.code_reallocs++;
5019 code = cfg->native_code + cfg->code_len;
5021 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5022 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5023 tracing = 1;
5026 if (method->save_lmf)
5027 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5029 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
5030 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5031 else
5032 code = backUpStackPtr(cfg, code);
5034 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5035 s390_br (code, s390_r14);
5037 cfg->code_len = code - cfg->native_code;
5039 g_assert (cfg->code_len < cfg->code_size);
5043 /*========================= End of Function ========================*/
5045 /*------------------------------------------------------------------*/
5046 /* */
5047 /* Name - mono_arch_emit_exceptions */
5048 /* */
5049 /* Function - Emit the blocks to handle exception conditions. */
5050 /* */
5051 /*------------------------------------------------------------------*/
5053 void
5054 mono_arch_emit_exceptions (MonoCompile *cfg)
5056 MonoJumpInfo *patch_info;
5057 guint8 *code;
5058 int nThrows = 0,
5059 exc_count = 0,
5060 iExc;
5061 guint32 code_size;
5062 MonoClass *exc_classes [MAX_EXC];
5063 guint8 *exc_throw_start [MAX_EXC];
5065 for (patch_info = cfg->patch_info;
5066 patch_info;
5067 patch_info = patch_info->next) {
5068 if (patch_info->type == MONO_PATCH_INFO_EXC)
5069 exc_count++;
5072 code_size = exc_count * 48;
5074 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5075 cfg->code_size *= 2;
5076 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5077 mono_jit_stats.code_reallocs++;
5080 code = cfg->native_code + cfg->code_len;
5082 /*---------------------------------------------------------------------*/
5083 /* Add code to raise exceptions */
5084 /*---------------------------------------------------------------------*/
5085 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5086 switch (patch_info->type) {
5087 case MONO_PATCH_INFO_EXC: {
5088 guint8 *ip = patch_info->ip.i + cfg->native_code;
5089 MonoClass *exc_class;
5090 guint64 throw_ip;
5092 /*-----------------------------------------------------*/
5093 /* Patch the branch in epilog to come here */
5094 /*-----------------------------------------------------*/
5095 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5097 exc_class = mono_class_from_name (mono_defaults.corlib,
5098 "System",
5099 patch_info->data.name);
5100 g_assert (exc_class);
5101 throw_ip = patch_info->ip.i;
5103 for (iExc = 0; iExc < nThrows; ++iExc)
5104 if (exc_classes [iExc] == exc_class)
5105 break;
5107 if (iExc < nThrows) {
5108 s390_jcl (code, S390_CC_UN,
5109 (guint64) exc_throw_start [iExc]);
5110 patch_info->type = MONO_PATCH_INFO_NONE;
5111 } else {
5113 if (nThrows < MAX_EXC) {
5114 exc_classes [nThrows] = exc_class;
5115 exc_throw_start [nThrows] = code;
5118 /*---------------------------------------------*/
5119 /* Patch the parameter passed to the handler */
5120 /*---------------------------------------------*/
5121 s390_basr (code, s390_r13, 0);
5122 s390_j (code, 6);
5123 s390_llong(code, patch_info->data.target);
5124 /*---------------------------------------------*/
5125 /* Load return address & parameter register */
5126 /*---------------------------------------------*/
5127 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5128 cfg->native_code + 8), code));
5129 s390_lg (code, s390_r2, 0, s390_r13, 4);
5130 /*---------------------------------------------*/
5131 /* Reuse the current patch to set the jump */
5132 /*---------------------------------------------*/
5133 s390_basr (code, s390_r13, 0);
5134 s390_j (code, 6);
5135 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5136 patch_info->data.name = "mono_arch_throw_exception_by_name";
5137 patch_info->ip.i = code - cfg->native_code;
5138 s390_llong(code, 0);
5139 s390_lg (code, s390_r1, 0, s390_r13, 4);
5140 s390_br (code, s390_r1);
5142 break;
5144 default:
5145 /* do nothing */
5146 break;
5150 cfg->code_len = code - cfg->native_code;
5152 g_assert (cfg->code_len < cfg->code_size);
5156 /*========================= End of Function ========================*/
5158 /*------------------------------------------------------------------*/
5159 /* */
5160 /* Name - mono_arch_setup_jit_tls_data */
5161 /* */
5162 /* Function - Setup the JIT's Thread Level Specific Data. */
5163 /* */
5164 /*------------------------------------------------------------------*/
5166 void
5167 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5169 if (!tls_offset_inited) {
5170 tls_offset_inited = TRUE;
5172 #if HAVE_KW_THREAD
5173 # if 0
5174 __asm__ ("\tear\t%r1,0\n"
5175 "\tlr\t%0,%3\n"
5176 "\tsr\t%0,%r1\n"
5177 "\tlr\t%1,%4\n"
5178 "\tsr\t%1,%r1\n"
5179 "\tlr\t%2,%5\n"
5180 "\tsr\t%2,%r1\n"
5181 : "=r" (appdomain_tls_offset),
5182 "=r" (thread_tls_offset),
5183 "=r" (lmf_tls_offset)
5184 : "r" (&tls_appdomain),
5185 "r" (&tls_current_object),
5186 "r" (&mono_lmf_addr)
5187 : "1", "cc");
5188 # endif
5189 #endif
5192 if (!lmf_addr_key_inited) {
5193 lmf_addr_key_inited = TRUE;
5194 pthread_key_create (&lmf_addr_key, NULL);
5196 pthread_setspecific (lmf_addr_key, &tls->lmf);
5200 /*========================= End of Function ========================*/
5202 /*------------------------------------------------------------------*/
5203 /* */
5204 /* Name - mono_arch_free_jit_tls_data */
5205 /* */
5206 /* Function - Free tls data. */
5207 /* */
5208 /*------------------------------------------------------------------*/
5210 void
5211 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5215 /*========================= End of Function ========================*/
5217 /*------------------------------------------------------------------*/
5218 /* */
5219 /* Name - mono_arch_emit_inst_for_method */
5220 /* */
5221 /*------------------------------------------------------------------*/
5223 MonoInst*
5224 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5226 return NULL;
5229 /*========================= End of Function ========================*/
5231 void
5232 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5235 * Have to rename these to avoid being decomposed normally, since the normal
5236 * decomposition does not work on S390.
5238 switch (ins->opcode) {
5239 case OP_ISUB_OVF:
5240 ins->opcode = OP_S390_ISUB_OVF;
5241 break;
5242 case OP_ISUB_OVF_UN:
5243 ins->opcode = OP_S390_ISUB_OVF_UN;
5244 break;
5245 case OP_IADD_OVF:
5246 ins->opcode = OP_S390_IADD_OVF;
5247 break;
5248 case OP_IADD_OVF_UN:
5249 ins->opcode = OP_S390_IADD_OVF_UN;
5250 break;
5251 case OP_LADD_OVF:
5252 ins->opcode = OP_S390_LADD_OVF;
5253 break;
5254 case OP_LADD_OVF_UN:
5255 ins->opcode = OP_S390_LADD_OVF_UN;
5256 break;
5257 case OP_LSUB_OVF:
5258 ins->opcode = OP_S390_LSUB_OVF;
5259 break;
5260 case OP_LSUB_OVF_UN:
5261 ins->opcode = OP_S390_LSUB_OVF_UN;
5262 break;
5263 default:
5264 break;
5268 /*========================= End of Function ========================*/
5270 /*------------------------------------------------------------------*/
5271 /* */
5272 /* Name - mono_arch_print_tree */
5273 /* */
5274 /* Function - Print platform-specific opcode details. */
5275 /* */
5276 /* Returns - 1 - opcode details have been printed */
5277 /* 0 - opcode details have not been printed */
5278 /* */
5279 /*------------------------------------------------------------------*/
5281 gboolean
5282 mono_arch_print_tree (MonoInst *tree, int arity)
5284 gboolean done;
5286 switch (tree->opcode) {
5287 case OP_S390_LOADARG:
5288 case OP_S390_ARGREG:
5289 case OP_S390_ARGPTR:
5290 printf ("[0x%lx(%s)]", tree->inst_offset,
5291 mono_arch_regname (tree->inst_basereg));
5292 done = 1;
5293 break;
5294 case OP_S390_STKARG:
5295 printf ("[0x%lx(previous_frame)]",
5296 tree->inst_offset);
5297 done = 1;
5298 break;
5299 case OP_S390_MOVE:
5300 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5301 tree->inst_offset, tree->backend.size,
5302 mono_arch_regname(tree->dreg),
5303 tree->inst_imm,
5304 mono_arch_regname(tree->sreg1));
5305 done = 1;
5306 break;
5307 case OP_S390_SETF4RET:
5308 printf ("[f%s,f%s]",
5309 mono_arch_regname (tree->dreg),
5310 mono_arch_regname (tree->sreg1));
5311 done = 1;
5312 break;
5313 case OP_TLS_GET:
5314 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5315 tree->inst_imm,
5316 mono_arch_regname (tree->sreg1));
5317 done = 1;
5318 break;
5319 case OP_S390_BKCHAIN:
5320 printf ("[previous_frame(%s)]",
5321 mono_arch_regname (tree->sreg1));
5322 done = 1;
5323 default:
5324 done = 0;
5326 return (done);
5329 /*========================= End of Function ========================*/
5331 /*------------------------------------------------------------------*/
5332 /* */
5333 /* Name - mono_arch_regalloc_cost */
5334 /* */
5335 /* Function - Determine the cost, in the number of memory */
5336 /* references, of the action of allocating the var- */
5337 /* iable VMV into a register during global register */
5338 /* allocation. */
5339 /* */
5340 /* Returns - Cost */
5341 /* */
5342 /*------------------------------------------------------------------*/
5344 guint32
5345 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5347 /* FIXME: */
5348 return 2;
5351 /*========================= End of Function ========================*/
5353 /*------------------------------------------------------------------*/
5354 /* */
5355 /* Name - mono_arch_get_domain_intrinsic */
5356 /* */
5357 /* Function - */
5358 /* */
5359 /* Returns - */
5360 /* */
5361 /*------------------------------------------------------------------*/
5363 MonoInst *
5364 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5366 MonoInst *ins;
5368 if (appdomain_tls_offset == -1)
5369 return NULL;
5371 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5372 ins->inst_offset = appdomain_tls_offset;
5373 return (ins);
5376 /*========================= End of Function ========================*/
5378 /*------------------------------------------------------------------*/
5379 /* */
5380 /* Name - mono_arch_get_thread_intrinsic */
5381 /* */
5382 /* Function - */
5383 /* */
5384 /* Returns - */
5385 /* */
5386 /*------------------------------------------------------------------*/
5388 MonoInst *
5389 mono_arch_get_thread_intrinsic (MonoCompile* cfg)
5391 MonoInst *ins;
5393 if (thread_tls_offset == -1)
5394 return NULL;
5396 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5397 ins->inst_offset = thread_tls_offset;
5398 return (ins);
5401 /*========================= End of Function ========================*/
5403 /*------------------------------------------------------------------*/
5404 /* */
5405 /* Name - mono_arch_flush_register_windows */
5406 /* */
5407 /* Function - */
5408 /* */
5409 /* Returns - */
5410 /* */
5411 /*------------------------------------------------------------------*/
5413 void
5414 mono_arch_flush_register_windows (void)
5418 /*========================= End of Function ========================*/
5420 /*------------------------------------------------------------------*/
5421 /* */
5422 /* Name - mono_arch_get_lmf_addr */
5423 /* */
5424 /* Function - */
5425 /* */
5426 /* Returns - */
5427 /* */
5428 /*------------------------------------------------------------------*/
5430 gpointer
5431 mono_arch_get_lmf_addr (void)
5433 return pthread_getspecific (lmf_addr_key);
5436 /*========================= End of Function ========================*/
5438 /*------------------------------------------------------------------*/
5439 /* */
5440 /* Name - mono_arch_is_inst_imm */
5441 /* */
5442 /* Function - Determine if operand qualifies as an immediate */
5443 /* value. For s390 this is a value -32768-32768 */
5444 /* */
5445 /* Returns - True|False - is [not] immediate value. */
5446 /* */
5447 /*------------------------------------------------------------------*/
5449 gboolean
5450 mono_arch_is_inst_imm (gint64 imm)
5452 return s390_is_imm16 (imm);
5455 /*========================= End of Function ========================*/
5457 /*------------------------------------------------------------------*/
5458 /* */
5459 /* Name - mono_arch_get_patch_offset */
5460 /* */
5461 /* Function - Dummy entry point until s390x supports aot. */
5462 /* */
5463 /* Returns - Offset for patch. */
5464 /* */
5465 /*------------------------------------------------------------------*/
5467 guint32
5468 mono_arch_get_patch_offset (guint8 *code)
5470 return 0;
5473 /*========================= End of Function ========================*/
5475 gpointer
5476 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5478 /* FIXME: implement */
5479 g_assert_not_reached ();
5480 return NULL;