1 /*------------------------------------------------------------------*/
3 /* Name - mini-s390.c */
5 /* Function - S/390 backend for the Mono code generator. */
7 /* Name - Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com) */
9 /* Date - January, 2004 */
11 /* Derivation - From mini-x86 & mini-ppc by - */
12 /* Paolo Molaro (lupus@ximian.com) */
13 /* Dietmar Maurer (dietmar@ximian.com) */
15 /*------------------------------------------------------------------*/
17 /*------------------------------------------------------------------*/
19 /*------------------------------------------------------------------*/
21 #define EMIT_COND_BRANCH(ins,cond) \
23 if (ins->inst_true_bb->native_offset) { \
25 displace = ((cfg->native_code + \
26 ins->inst_true_bb->native_offset) - code) / 2; \
27 if (s390_is_imm16(displace)) { \
28 s390_brc (code, cond, displace); \
30 s390_jcl (code, cond, displace); \
33 mono_add_patch_info (cfg, code - cfg->native_code, \
34 MONO_PATCH_INFO_BB, ins->inst_true_bb); \
35 s390_jcl (code, cond, 0); \
39 #define EMIT_UNCOND_BRANCH(ins) \
41 if (ins->inst_target_bb->native_offset) { \
43 displace = ((cfg->native_code + \
44 ins->inst_target_bb->native_offset) - code) / 2; \
45 if (s390_is_imm16(displace)) { \
46 s390_brc (code, S390_CC_UN, displace); \
48 s390_jcl (code, S390_CC_UN, displace); \
51 mono_add_patch_info (cfg, code - cfg->native_code, \
52 MONO_PATCH_INFO_BB, ins->inst_target_bb); \
53 s390_jcl (code, S390_CC_UN, 0); \
57 #define EMIT_COND_SYSTEM_EXCEPTION(cond,exc_name) \
59 mono_add_patch_info (cfg, code - cfg->native_code, \
60 MONO_PATCH_INFO_EXC, exc_name); \
61 s390_jcl (code, cond, 0); \
64 #define CHECK_SRCDST_COM \
65 if (ins->dreg == ins->sreg2) { \
69 if (ins->dreg != ins->sreg1) { \
70 s390_lgr (code, ins->dreg, ins->sreg1); \
74 #define CHECK_SRCDST_NCOM \
75 if (ins->dreg == ins->sreg2) { \
77 s390_lgr (code, s390_r13, ins->sreg2); \
81 if (ins->dreg != ins->sreg1) { \
82 s390_lgr (code, ins->dreg, ins->sreg1); \
85 #define CHECK_SRCDST_COM_I \
86 if (ins->dreg == ins->sreg2) { \
90 if (ins->dreg != ins->sreg1) { \
91 s390_lgfr (code, ins->dreg, ins->sreg1); \
95 #define CHECK_SRCDST_NCOM_I \
96 if (ins->dreg == ins->sreg2) { \
98 s390_lgfr (code, s390_r13, ins->sreg2); \
102 if (ins->dreg != ins->sreg1) { \
103 s390_lgfr (code, ins->dreg, ins->sreg1); \
106 #define CHECK_SRCDST_COM_F \
107 if (ins->dreg == ins->sreg2) { \
111 if (ins->dreg != ins->sreg1) { \
112 s390_ldr (code, ins->dreg, ins->sreg1); \
116 #define CHECK_SRCDST_NCOM_F \
117 if (ins->dreg == ins->sreg2) { \
119 s390_ldr (code, s390_r13, ins->sreg2); \
123 if (ins->dreg != ins->sreg1) { \
124 s390_ldr (code, ins->dreg, ins->sreg1); \
127 #define MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
131 MONO_INST_NEW (cfg, inst, OP_NOP); \
133 tmpr = mono_alloc_preg (cfg); \
134 MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
136 inst->inst_offset = offset; \
138 inst->inst_imm = imm; \
139 inst->sreg2 = tmpr; \
141 if (s390_is_uimm12(offset)) { \
143 inst->inst_offset = offset; \
145 dReg = mono_alloc_preg (cfg); \
146 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
147 dReg, dest, offset); \
149 inst->inst_offset = 0; \
151 if (s390_is_uimm12(imm)) { \
153 inst->inst_imm = imm; \
155 sReg = mono_alloc_preg (cfg); \
156 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
158 inst->sreg1 = sReg; \
159 inst->inst_imm = 0; \
162 inst->opcode = OP_S390_MOVE; \
163 inst->backend.size = size; \
164 MONO_ADD_INS (cfg->cbb, inst); \
167 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
168 int reg = mono_alloc_preg (cfg); \
171 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
174 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
178 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
182 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
186 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI8_MEMBASE, \
190 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
193 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
197 tmpr = mono_alloc_preg (cfg); \
198 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
199 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
203 tmpr = mono_alloc_preg (cfg); \
204 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
206 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
210 tmpr = mono_alloc_preg (cfg); \
211 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
213 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
217 tmpr = mono_alloc_preg (cfg); \
218 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADI4_MEMBASE, \
220 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
224 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
230 #define DEBUG(a) if (cfg->verbose_level > 1) a
234 #define S390_TRACE_STACK_SIZE (5*sizeof(gpointer)+4*sizeof(gdouble))
236 #define MAX(a, b) ((a) > (b) ? (a) : (b))
238 /*========================= End of Defines =========================*/
240 /*------------------------------------------------------------------*/
241 /* I n c l u d e s */
242 /*------------------------------------------------------------------*/
247 #include <mono/metadata/appdomain.h>
248 #include <mono/metadata/debug-helpers.h>
249 #include <mono/metadata/profiler-private.h>
250 #include <mono/utils/mono-math.h>
252 #include "mini-s390x.h"
253 #include "cpu-s390x.h"
254 #include "jit-icalls.h"
257 /*========================= End of Includes ========================*/
259 /*------------------------------------------------------------------*/
260 /* T y p e d e f s */
261 /*------------------------------------------------------------------*/
273 /*------------------------------------------------------------------*/
274 /* Used by the instrument_emit_epilog */
275 /*------------------------------------------------------------------*/
286 typedef struct InstList InstList;
300 RegTypeStructByValInFP,
302 RegTypeStructByAddrOnStack
306 gint32 offset; /* offset from caller's stack */
307 gint32 offparm; /* offset from callee's stack */
308 guint16 vtsize; /* in param area */
311 guint32 size; /* Size of structure used by RegTypeStructByVal */
312 gint32 type; /* Data type of argument */
327 gint64 gr[5]; /* R2-R6 */
328 gdouble fp[3]; /* F0-F2 */
329 } __attribute__ ((packed)) RegParm;
331 /*========================= End of Typedefs ========================*/
333 /*------------------------------------------------------------------*/
334 /* P r o t o t y p e s */
335 /*------------------------------------------------------------------*/
337 static void indent (int);
338 static guint8 * backUpStackPtr(MonoCompile *, guint8 *);
339 static void decodeParm (MonoType *, void *, int);
340 static void enter_method (MonoMethod *, RegParm *, char *);
341 static void leave_method (MonoMethod *, ...);
342 static gboolean is_regsize_var (MonoType *);
343 static inline void add_general (guint *, size_data *, ArgInfo *);
344 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
345 static inline void add_float (guint *, size_data *, ArgInfo *);
346 static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
347 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
348 gpointer mono_arch_get_lmf_addr (void);
349 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
350 static void catch_SIGILL(int, siginfo_t *, void *);
352 /*========================= End of Prototypes ======================*/
354 /*------------------------------------------------------------------*/
355 /* G l o b a l V a r i a b l e s */
356 /*------------------------------------------------------------------*/
358 int mono_exc_esp_offset = 0;
360 static int indent_level = 0;
364 static gboolean tls_offset_inited = FALSE;
366 static int appdomain_tls_offset = -1,
367 thread_tls_offset = -1;
369 pthread_key_t lmf_addr_key;
371 gboolean lmf_addr_key_inited = FALSE;
375 extern __thread MonoDomain *tls_appdomain;
376 extern __thread MonoThread *tls_current_object;
377 extern __thread gpointer mono_lmf_addr;
381 /*====================== End of Global Variables ===================*/
383 /*------------------------------------------------------------------*/
385 /* Name - mono_arch_regname */
387 /* Function - Returns the name of the register specified by */
388 /* the input parameter. */
390 /*------------------------------------------------------------------*/
393 mono_arch_regname (int reg) {
394 static const char * rnames[] = {
395 "s390_r0", "s390_sp", "s390_r2", "s390_r3", "s390_r4",
396 "s390_r5", "s390_r6", "s390_r7", "s390_r8", "s390_r9",
397 "s390_r10", "s390_r11", "s390_r12", "s390_r13", "s390_r14",
401 if (reg >= 0 && reg < 16)
407 /*========================= End of Function ========================*/
409 /*------------------------------------------------------------------*/
411 /* Name - mono_arch_fregname */
413 /* Function - Returns the name of the register specified by */
414 /* the input parameter. */
416 /*------------------------------------------------------------------*/
419 mono_arch_fregname (int reg) {
420 static const char * rnames[] = {
421 "s390_f0", "s390_f1", "s390_f2", "s390_f3", "s390_f4",
422 "s390_f5", "s390_f6", "s390_f7", "s390_f8", "s390_f9",
423 "s390_f10", "s390_f11", "s390_f12", "s390_f13", "s390_f14",
427 if (reg >= 0 && reg < 16)
433 /*========================= End of Function ========================*/
435 /*------------------------------------------------------------------*/
437 /* Name - arch_get_argument_info */
439 /* Function - Gathers information on parameters such as size, */
440 /* alignment, and padding. arg_info should be large */
441 /* enough to hold param_count + 1 entries. */
443 /* Parameters - @csig - Method signature */
444 /* @param_count - No. of parameters to consider */
445 /* @arg_info - An array to store the result info */
447 /* Returns - Size of the activation frame */
449 /*------------------------------------------------------------------*/
452 mono_arch_get_argument_info (MonoMethodSignature *csig,
454 MonoJitArgumentInfo *arg_info)
456 int k, frame_size = 0;
457 int size, align, pad;
460 if (MONO_TYPE_ISSTRUCT (csig->ret)) {
461 frame_size += sizeof (gpointer);
465 arg_info [0].offset = offset;
468 frame_size += sizeof (gpointer);
472 arg_info [0].size = frame_size;
474 for (k = 0; k < param_count; k++) {
477 size = mono_type_native_stack_size (csig->params [k], (guint32 *) &align);
479 size = mini_type_stack_size (NULL, csig->params [k], &align);
481 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
482 arg_info [k].pad = pad;
484 arg_info [k + 1].pad = 0;
485 arg_info [k + 1].size = size;
487 arg_info [k + 1].offset = offset;
491 align = MONO_ARCH_FRAME_ALIGNMENT;
492 frame_size += pad = (align - (frame_size & (align - 1))) & (align - 1);
493 arg_info [k].pad = pad;
498 /*========================= End of Function ========================*/
500 /*------------------------------------------------------------------*/
502 /* Name - retFitsInReg. */
504 /* Function - Determines if a value can be returned in one or */
507 /*------------------------------------------------------------------*/
509 static inline gboolean
510 retFitsInReg(guint32 size)
525 /*========================= End of Function ========================*/
527 /*------------------------------------------------------------------*/
529 /* Name - backStackPtr. */
531 /* Function - Restore Stack Pointer to previous frame. */
533 /*------------------------------------------------------------------*/
535 static inline guint8 *
536 backUpStackPtr(MonoCompile *cfg, guint8 *code)
538 int stackSize = cfg->stack_usage;
540 if (s390_is_imm16 (stackSize)) {
541 s390_aghi (code, STK_BASE, stackSize);
543 while (stackSize > 32767) {
544 s390_aghi (code, STK_BASE, 32767);
547 s390_aghi (code, STK_BASE, stackSize);
552 /*========================= End of Function ========================*/
554 /*------------------------------------------------------------------*/
558 /* Function - Perform nice indenting to current level */
560 /*------------------------------------------------------------------*/
566 indent_level += diff;
573 indent_level += diff;
576 /*========================= End of Function ========================*/
578 /*------------------------------------------------------------------*/
580 /* Name - decodeParm */
582 /* Function - Decode a parameter for the trace. */
584 /*------------------------------------------------------------------*/
587 decodeParm(MonoType *type, void *curParm, int size)
592 printf("[BYREF:%p], ", *((char **) curParm));
594 simpleType = mono_type_get_underlying_type(type)->type;
596 switch (simpleType) {
598 printf ("[INTPTR:%p], ", *((int **) curParm));
601 printf ("[UINTPTR:%p], ", *((int **) curParm));
603 case MONO_TYPE_BOOLEAN :
604 printf ("[BOOL:%ld], ", *((gint64 *) curParm));
606 case MONO_TYPE_CHAR :
607 printf ("[CHAR:%c], ", *((int *) curParm));
610 printf ("[INT1:%ld], ", *((gint64 *) curParm));
613 printf ("[INT2:%ld], ", *((gint64 *) curParm));
616 printf ("[INT4:%ld], ", *((gint64 *) curParm));
619 printf ("[UINT1:%lu], ", *((guint64 *) curParm));
622 printf ("[UINT2:%lu], ", *((guint64 *) curParm));
625 printf ("[UINT4:%lu], ", *((guint64 *) curParm));
628 printf ("[UINT8:%lu], ", *((guint64 *) curParm));
630 case MONO_TYPE_STRING : {
631 MonoString *s = *((MonoString **) curParm);
633 g_assert (((MonoObject *) s)->vtable->klass == mono_defaults.string_class);
634 printf("[STRING:%p:%s], ", s, mono_string_to_utf8(s));
636 printf("[STRING:null], ");
640 case MONO_TYPE_CLASS :
641 case MONO_TYPE_OBJECT : {
642 MonoObject *obj = *((MonoObject **) curParm);
644 if ((obj) && (obj->vtable)) {
645 printf("[CLASS/OBJ:");
646 class = obj->vtable->klass;
647 printf("%p [%p] ",obj,curParm);
648 if (class == mono_defaults.string_class) {
649 printf("[STRING:%p:%s]",
650 obj, mono_string_to_utf8 ((MonoString *) obj));
651 } else if (class == mono_defaults.int32_class) {
652 printf("[INT32:%p:%d]",
653 obj, *(gint32 *)((char *)obj + sizeof (MonoObject)));
656 class->name_space, class->name, obj);
659 printf("[OBJECT:null], ");
664 printf("[PTR:%p], ", *((gpointer **) (curParm)));
666 case MONO_TYPE_FNPTR :
667 printf("[FNPTR:%p], ", *((gpointer **) (curParm)));
669 case MONO_TYPE_ARRAY :
670 printf("[ARRAY:%p], ", *((gpointer **) (curParm)));
672 case MONO_TYPE_SZARRAY :
673 printf("[SZARRAY:%p], ", *((gpointer **) (curParm)));
676 printf("[INT8:%ld], ", *((gint64 *) (curParm)));
679 printf("[FLOAT4:%g], ", *((float *) (curParm)));
682 printf("[FLOAT8:%g], ", *((double *) (curParm)));
684 case MONO_TYPE_VALUETYPE : {
686 MonoMarshalType *info;
688 if (type->data.klass->enumtype) {
689 simpleType = mono_class_enum_basetype (type->data.klass)->type;
690 printf("{VALUETYPE} - ");
694 info = mono_marshal_load_type_info (type->data.klass);
696 if ((info->native_size == sizeof(float)) &&
697 (info->num_fields == 1) &&
698 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
699 printf("[FLOAT4:%f], ", *((float *) (curParm)));
703 if ((info->native_size == sizeof(double)) &&
704 (info->num_fields == 1) &&
705 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
706 printf("[FLOAT8:%g], ", *((double *) (curParm)));
710 printf("[VALUETYPE:");
711 for (i = 0; i < size; i++)
712 printf("%02x,", *((guint8 *)curParm+i));
716 case MONO_TYPE_TYPEDBYREF: {
718 printf("[TYPEDBYREF:");
719 for (i = 0; i < size; i++)
720 printf("%02x,", *((guint8 *)curParm+i));
725 printf("[?? - %d], ",simpleType);
730 /*========================= End of Function ========================*/
732 /*------------------------------------------------------------------*/
734 /* Name - enter_method */
736 /* Function - Perform tracing of the entry to the current */
739 /*------------------------------------------------------------------*/
742 enter_method (MonoMethod *method, RegParm *rParm, char *sp)
744 int i, oParm = 0, iParm = 0;
747 MonoMethodSignature *sig;
754 fname = mono_method_full_name (method, TRUE);
756 printf ("ENTER: %s ", fname);
759 ip = (*(guint64 *) (sp+S390_RET_ADDR_OFFSET));
760 printf ("ip: %p sp: %p - ", (gpointer) ip, sp);
765 sig = mono_method_signature (method);
767 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
769 if (cinfo->struct_ret) {
770 printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
775 gpointer *this = (gpointer *) rParm->gr[iParm];
776 obj = (MonoObject *) this;
777 if (method->klass->valuetype) {
779 printf("this:[value:%p:%016lx], ",
780 this, *((guint64 *)(this+sizeof(MonoObject))));
782 printf ("this:[NULL], ");
785 class = obj->vtable->klass;
786 if (class == mono_defaults.string_class) {
787 printf ("this:[STRING:%p:%s], ",
788 obj, mono_string_to_utf8 ((MonoString *)obj));
790 printf ("this:%p[%s.%s], ",
791 obj, class->name_space, class->name);
794 printf ("this:NULL, ");
799 for (i = 0; i < sig->param_count; ++i) {
800 ainfo = &cinfo->args[i + oParm];
801 switch (ainfo->regtype) {
802 case RegTypeGeneral :
803 decodeParm(sig->params[i], &(rParm->gr[ainfo->reg-2]), ainfo->size);
806 decodeParm(sig->params[i], &(rParm->fp[ainfo->reg]), ainfo->size);
809 decodeParm(sig->params[i], sp+ainfo->offset, ainfo->size);
811 case RegTypeStructByVal :
812 if (ainfo->reg != STK_BASE) {
813 int offset = sizeof(glong) - ainfo->size;
814 curParm = &(rParm->gr[ainfo->reg-2])+offset;
817 curParm = sp+ainfo->offset;
819 if (retFitsInReg (ainfo->vtsize))
820 decodeParm(sig->params[i],
824 decodeParm(sig->params[i],
825 *((char **) curParm),
828 case RegTypeStructByAddr :
829 if (ainfo->reg != STK_BASE)
830 curParm = &(rParm->gr[ainfo->reg-2]);
832 curParm = sp+ainfo->offset;
834 decodeParm(sig->params[i],
835 *((char **) curParm),
847 /*========================= End of Function ========================*/
849 /*------------------------------------------------------------------*/
851 /* Name - leave_method */
855 /*------------------------------------------------------------------*/
858 leave_method (MonoMethod *method, ...)
865 va_start(ap, method);
867 fname = mono_method_full_name (method, TRUE);
869 printf ("LEAVE: %s", fname);
872 type = mono_method_signature (method)->ret;
875 switch (type->type) {
878 case MONO_TYPE_BOOLEAN: {
879 int val = va_arg (ap, int);
881 printf ("[TRUE:%d]", val);
887 case MONO_TYPE_CHAR: {
888 int val = va_arg (ap, int);
889 printf ("[CHAR:%d]", val);
893 int val = va_arg (ap, int);
894 printf ("[INT1:%d]", val);
898 int val = va_arg (ap, int);
899 printf ("[UINT1:%d]", val);
903 int val = va_arg (ap, int);
904 printf ("[INT2:%d]", val);
908 int val = va_arg (ap, int);
909 printf ("[UINT2:%d]", val);
913 int val = va_arg (ap, int);
914 printf ("[INT4:%d]", val);
918 int val = va_arg (ap, int);
919 printf ("[UINT4:%d]", val);
923 gint64 val = va_arg (ap, gint64);
924 printf ("[INT:%ld]", val);
929 gint64 val = va_arg (ap, gint64);
930 printf ("[UINT:%lu]", val);
934 case MONO_TYPE_STRING: {
935 MonoString *s = va_arg (ap, MonoString *);
938 g_assert (((MonoObject *)s)->vtable->klass == mono_defaults.string_class);
939 printf ("[STRING:%p:%s]", s, mono_string_to_utf8 (s));
941 printf ("[STRING:null], ");
944 case MONO_TYPE_CLASS:
945 case MONO_TYPE_OBJECT: {
946 MonoObject *o = va_arg (ap, MonoObject *);
948 if ((o) && (o->vtable)) {
949 if (o->vtable->klass == mono_defaults.boolean_class) {
950 printf ("[BOOLEAN:%p:%d]", o, *((guint8 *)o + sizeof (MonoObject)));
951 } else if (o->vtable->klass == mono_defaults.int32_class) {
952 printf ("[INT32:%p:%d]", o, *((gint32 *)((char *)o + sizeof (MonoObject))));
953 } else if (o->vtable->klass == mono_defaults.int64_class) {
954 printf ("[INT64:%p:%ld]", o, *((gint64 *)((char *)o + sizeof (MonoObject))));
956 printf ("[%s.%s:%p]", o->vtable->klass->name_space, o->vtable->klass->name, o);
958 printf ("[OBJECT:%p]", o);
963 case MONO_TYPE_FNPTR:
964 case MONO_TYPE_ARRAY:
965 case MONO_TYPE_SZARRAY: {
966 gpointer p = va_arg (ap, gpointer);
967 printf ("[result=%p]", p);
971 gint64 l = va_arg (ap, gint64);
972 printf ("[LONG:%ld]", l);
976 guint64 l = va_arg (ap, guint64);
977 printf ("[ULONG:%lu]", l);
981 double f = va_arg (ap, double);
982 printf ("[FLOAT4:%g]\n", f);
986 double f = va_arg (ap, double);
987 printf ("[FLOAT8:%g]\n", f);
990 case MONO_TYPE_VALUETYPE: {
991 MonoMarshalType *info;
992 if (type->data.klass->enumtype) {
993 type = mono_class_enum_basetype (type->data.klass);
998 info = mono_marshal_load_type_info (type->data.klass);
1000 if ((info->native_size == sizeof(float)) &&
1001 (info->num_fields == 1) &&
1002 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1003 double f = va_arg (ap, double);
1004 printf("[FLOAT4:%g]\n", (double) f);
1008 if ((info->native_size == sizeof(double)) &&
1009 (info->num_fields == 1) &&
1010 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1011 double f = va_arg (ap, double);
1012 printf("[FLOAT8:%g]\n", f);
1016 size = mono_type_size (type, &align);
1019 guint32 p = va_arg (ap, guint32);
1020 printf ("[%02x]\n",p);
1024 guint32 p = va_arg (ap, guint32);
1025 printf ("[%04x]\n",p);
1029 guint32 p = va_arg (ap, guint32);
1030 printf ("[%08x]\n",p);
1034 guint64 p = va_arg (ap, guint64);
1035 printf ("[%016lx]\n",p);
1039 gpointer p = va_arg (ap, gpointer);
1040 printf ("[VALUETYPE] %p\n",p);
1046 case MONO_TYPE_TYPEDBYREF: {
1047 guint8 *p = va_arg (ap, gpointer);
1049 size = mono_type_size (type, &align);
1056 for (j = 0; p && j < size; j++)
1057 printf ("%02x,", p [j]);
1061 printf ("[TYPEDBYREF]\n");
1066 printf ("(unknown return type %x)",
1067 mono_method_signature (method)->ret->type);
1070 ip = ((gint64) __builtin_return_address (0));
1071 printf (" ip: %p\n", (gpointer) ip);
1074 /*========================= End of Function ========================*/
1076 /*------------------------------------------------------------------*/
1078 /* Name - catch_SIGILL */
1080 /* Function - Catch SIGILL as a result of testing for long */
1081 /* displacement facility. */
1083 /*------------------------------------------------------------------*/
1086 catch_SIGILL(int sigNo, siginfo_t *info, void *act) {
1092 /*========================= End of Function ========================*/
1094 /*------------------------------------------------------------------*/
1096 /* Name - mono_arch_cpu_init */
1098 /* Function - Perform CPU specific initialization to execute */
1101 /*------------------------------------------------------------------*/
1104 mono_arch_cpu_init (void)
1106 struct sigaction sa,
1110 /*--------------------------------------*/
1111 /* Set default rounding mode for FP */
1112 /*--------------------------------------*/
1113 __asm__ ("SRNM\t%0\n\t"
1116 /*--------------------------------------*/
1117 /* Determine if we have long displace- */
1118 /* ment facility on this processor */
1119 /*--------------------------------------*/
1120 sa.sa_sigaction = catch_SIGILL;
1121 sigemptyset (&sa.sa_mask);
1122 sa.sa_flags = SA_SIGINFO;
1124 sigaction (SIGILL, &sa, oldSa);
1126 /*--------------------------------------*/
1127 /* We test by executing the STY inst */
1128 /*--------------------------------------*/
1129 __asm__ ("LGHI\t0,1\n\t"
1131 ".byte\t0xe3,0x00,0x10,0x00,0x00,0x50\n\t"
1132 : "=m" (has_ld) : : "0", "1");
1134 sigaction (SIGILL, oldSa, NULL);
1137 /*========================= End of Function ========================*/
1141 * Initialize architecture specific code.
1144 mono_arch_init (void)
1149 * Cleanup architecture specific code.
1152 mono_arch_cleanup (void)
1156 /*------------------------------------------------------------------*/
1158 /* Name - mono_arch_cpu_optimizazions */
1160 /* Function - Returns the optimizations supported on this CPU */
1162 /*------------------------------------------------------------------*/
1165 mono_arch_cpu_optimizazions (guint32 *exclude_mask)
1169 /*----------------------------------------------------------*/
1170 /* No s390-specific optimizations yet */
1171 /*----------------------------------------------------------*/
1172 *exclude_mask = MONO_OPT_INLINE|MONO_OPT_LINEARS;
1173 // *exclude_mask = MONO_OPT_INLINE;
1177 /*========================= End of Function ========================*/
1179 /*------------------------------------------------------------------*/
1185 /*------------------------------------------------------------------*/
1188 is_regsize_var (MonoType *t) {
1191 switch (mono_type_get_underlying_type (t)->type) {
1199 case MONO_TYPE_FNPTR:
1201 case MONO_TYPE_OBJECT:
1202 case MONO_TYPE_STRING:
1203 case MONO_TYPE_CLASS:
1204 case MONO_TYPE_SZARRAY:
1205 case MONO_TYPE_ARRAY:
1207 case MONO_TYPE_VALUETYPE:
1208 if (t->data.klass->enumtype)
1209 return is_regsize_var (mono_class_enum_basetype (t->data.klass));
1215 /*========================= End of Function ========================*/
1217 /*------------------------------------------------------------------*/
1219 /* Name - mono_arch_get_allocatable_int_vars */
1223 /*------------------------------------------------------------------*/
1226 mono_arch_get_allocatable_int_vars (MonoCompile *cfg)
1231 for (i = 0; i < cfg->num_varinfo; i++) {
1232 MonoInst *ins = cfg->varinfo [i];
1233 MonoMethodVar *vmv = MONO_VARINFO (cfg, i);
1236 if (vmv->range.first_use.abs_pos >= vmv->range.last_use.abs_pos)
1239 if (ins->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT) ||
1240 (ins->opcode != OP_LOCAL && ins->opcode != OP_ARG))
1243 /* we can only allocate 32 bit values */
1244 if (is_regsize_var (ins->inst_vtype)) {
1245 g_assert (MONO_VARINFO (cfg, i)->reg == -1);
1246 g_assert (i == vmv->idx);
1247 vars = mono_varlist_insert_sorted (cfg, vars, vmv, FALSE);
1254 /*========================= End of Function ========================*/
1256 /*------------------------------------------------------------------*/
1258 /* Name - mono_arch_global_int_regs */
1260 /* Function - Return a list of usable integer registers. */
1262 /*------------------------------------------------------------------*/
1265 mono_arch_get_global_int_regs (MonoCompile *cfg)
1268 MonoMethodHeader *header;
1271 header = mono_method_get_header (cfg->method);
1272 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1273 cfg->frame_reg = s390_r11;
1276 /* FIXME: s390_r12 is reserved for bkchain_reg. Only reserve it if needed */
1278 for (i = 8; i < top; ++i) {
1279 if (cfg->frame_reg != i)
1280 regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
1286 /*========================= End of Function ========================*/
1288 /*------------------------------------------------------------------*/
1290 /* Name - mono_arch_flush_icache */
1292 /* Function - Flush the CPU icache. */
1294 /*------------------------------------------------------------------*/
1297 mono_arch_flush_icache (guint8 *code, gint size)
1301 /*========================= End of Function ========================*/
1303 /*------------------------------------------------------------------*/
1305 /* Name - add_general */
1307 /* Function - Determine code and stack size incremements for a */
1310 /*------------------------------------------------------------------*/
1313 add_general (guint *gr, size_data *sz, ArgInfo *ainfo)
1315 if (*gr > S390_LAST_ARG_REG) {
1316 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1317 ainfo->offset = sz->stack_size;
1318 ainfo->reg = STK_BASE;
1319 ainfo->regtype = RegTypeBase;
1320 sz->stack_size += sizeof(long);
1321 sz->local_size += sizeof(long);
1322 sz->offStruct += sizeof(long);
1323 sz->code_size += 12;
1331 /*========================= End of Function ========================*/
1333 /*------------------------------------------------------------------*/
1335 /* Name - add_stackParm */
1337 /* Function - Determine code and stack size incremements for a */
1340 /*------------------------------------------------------------------*/
1343 add_stackParm (guint *gr, size_data *sz, ArgInfo *ainfo, gint size)
1345 if (*gr > S390_LAST_ARG_REG) {
1346 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1347 ainfo->reg = STK_BASE;
1348 ainfo->offset = sz->stack_size;
1349 ainfo->regtype = RegTypeStructByAddrOnStack;
1350 sz->stack_size += sizeof (gpointer);
1351 sz->parm_size += sizeof(gpointer);
1352 sz->offStruct += sizeof(gpointer);
1355 ainfo->offset = sz->stack_size;
1356 ainfo->regtype = RegTypeStructByAddr;
1359 ainfo->offparm = sz->offset;
1360 sz->offset = S390_ALIGN(sz->offset+size, sizeof(long));
1362 ainfo->vtsize = size;
1363 sz->parm_size += size;
1366 /*========================= End of Function ========================*/
1368 /*------------------------------------------------------------------*/
1370 /* Name - add_float */
1372 /* Function - Determine code and stack size incremements for a */
1373 /* float parameter. */
1375 /*------------------------------------------------------------------*/
1378 add_float (guint *fr, size_data *sz, ArgInfo *ainfo)
1380 if ((*fr) <= S390_LAST_FPARG_REG) {
1381 ainfo->regtype = RegTypeFP;
1387 ainfo->offset = sz->stack_size;
1388 ainfo->reg = STK_BASE;
1389 ainfo->regtype = RegTypeBase;
1391 sz->stack_size += sizeof(double);
1392 sz->local_size += sizeof(double);
1393 sz->offStruct += sizeof(double);
1397 /*========================= End of Function ========================*/
1399 /*------------------------------------------------------------------*/
1401 /* Name - get_call_info */
1403 /* Function - Determine the amount of space required for code */
1404 /* and stack. In addition determine starting points */
1405 /* for stack-based parameters, and area for struct- */
1406 /* ures being returned on the stack. */
1408 /*------------------------------------------------------------------*/
1411 get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
1413 guint i, fr, gr, size;
1414 int nParm = sig->hasthis + sig->param_count;
1416 guint32 simpletype, align;
1419 MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
1422 cinfo = mono_mempool_alloc0 (mp, sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1424 cinfo = g_malloc0 (sizeof (CallInfo) + sizeof (ArgInfo) * nParm);
1429 cinfo->struct_ret = 0;
1433 sz->offStruct = S390_MINIMAL_STACK_SIZE;
1434 sz->stack_size = S390_MINIMAL_STACK_SIZE;
1439 /*----------------------------------------------------------*/
1440 /* We determine the size of the return code/stack in case we*/
1441 /* need to reserve a register to be used to address a stack */
1442 /* area that the callee will use. */
1443 /*----------------------------------------------------------*/
1445 ret_type = mono_type_get_underlying_type (sig->ret);
1446 ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
1447 simpletype = ret_type->type;
1449 switch (simpletype) {
1450 case MONO_TYPE_BOOLEAN:
1455 case MONO_TYPE_CHAR:
1460 case MONO_TYPE_CLASS:
1461 case MONO_TYPE_OBJECT:
1462 case MONO_TYPE_SZARRAY:
1463 case MONO_TYPE_ARRAY:
1465 case MONO_TYPE_FNPTR:
1466 case MONO_TYPE_STRING:
1467 cinfo->ret.reg = s390_r2;
1472 cinfo->ret.reg = s390_f0;
1477 cinfo->ret.reg = s390_r2;
1480 case MONO_TYPE_GENERICINST:
1481 if (!mono_type_generic_inst_is_valuetype (sig->ret)) {
1482 cinfo->ret.reg = s390_r2;
1487 case MONO_TYPE_VALUETYPE: {
1488 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1489 if (klass->enumtype) {
1490 simpletype = mono_class_enum_basetype (klass)->type;
1494 size = mono_class_native_size (klass, &align);
1496 size = mono_class_value_size (klass, &align);
1498 cinfo->ret.reg = s390_r2;
1499 cinfo->struct_ret = 1;
1500 cinfo->ret.size = size;
1501 cinfo->ret.vtsize = size;
1505 case MONO_TYPE_TYPEDBYREF:
1506 size = sizeof (MonoTypedRef);
1507 cinfo->ret.reg = s390_r2;
1508 cinfo->struct_ret = 1;
1509 cinfo->ret.size = size;
1510 cinfo->ret.vtsize = size;
1513 case MONO_TYPE_VOID:
1516 g_error ("Can't handle as return value 0x%x", sig->ret->type);
1520 cinfo->args[nParm].size = sizeof(gpointer);
1521 add_general (&gr, sz, cinfo->args+nParm);
1525 /*----------------------------------------------------------*/
1526 /* We determine the size of the parameter code and stack */
1527 /* requirements by checking the types and sizes of the */
1529 /*----------------------------------------------------------*/
1531 for (i = 0; i < sig->param_count; ++i) {
1534 /*--------------------------------------------------*/
1535 /* Handle vararg type calls. All args are put on */
1537 /*--------------------------------------------------*/
1538 if ((sig->call_convention == MONO_CALL_VARARG) &&
1539 (i == sig->sentinelpos)) {
1540 gr = S390_LAST_ARG_REG + 1;
1541 add_general (&gr, sz, &cinfo->sigCookie);
1544 if (sig->params [i]->byref) {
1545 add_general (&gr, sz, cinfo->args+nParm);
1546 cinfo->args[nParm].size = sizeof(gpointer);
1551 ptype = mono_type_get_underlying_type (sig->params [i]);
1552 ptype = mini_get_basic_type_from_generic (gsctx, ptype);
1553 simpletype = ptype->type;
1554 cinfo->args[nParm].type = simpletype;
1555 switch (simpletype) {
1556 case MONO_TYPE_BOOLEAN:
1559 cinfo->args[nParm].size = sizeof(char);
1560 add_general (&gr, sz, cinfo->args+nParm);
1565 case MONO_TYPE_CHAR:
1566 cinfo->args[nParm].size = sizeof(short);
1567 add_general (&gr, sz, cinfo->args+nParm);
1572 cinfo->args[nParm].size = sizeof(int);
1573 add_general (&gr, sz, cinfo->args+nParm);
1579 case MONO_TYPE_FNPTR:
1580 case MONO_TYPE_CLASS:
1581 case MONO_TYPE_OBJECT:
1582 case MONO_TYPE_STRING:
1583 case MONO_TYPE_SZARRAY:
1584 case MONO_TYPE_ARRAY:
1585 cinfo->args[nParm].size = sizeof(gpointer);
1586 add_general (&gr, sz, cinfo->args+nParm);
1591 cinfo->args[nParm].size = sizeof(long long);
1592 add_general (&gr, sz, cinfo->args+nParm);
1596 cinfo->args[nParm].size = sizeof(float);
1597 add_float (&fr, sz, cinfo->args+nParm);
1601 cinfo->args[nParm].size = sizeof(double);
1602 add_float (&fr, sz, cinfo->args+nParm);
1605 case MONO_TYPE_GENERICINST:
1606 if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
1607 cinfo->args[nParm].size = sizeof(gpointer);
1608 add_general (&gr, sz, cinfo->args+nParm);
1613 case MONO_TYPE_VALUETYPE: {
1614 MonoMarshalType *info;
1615 MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
1617 size = mono_class_native_size (klass, &align);
1619 size = mono_class_value_size (klass, &align);
1621 info = mono_marshal_load_type_info (klass);
1623 if ((info->native_size == sizeof(float)) &&
1624 (info->num_fields == 1) &&
1625 (info->fields[0].field->type->type == MONO_TYPE_R4)) {
1626 cinfo->args[nParm].size = sizeof(float);
1627 add_float(&fr, sz, cinfo->args+nParm);
1632 if ((info->native_size == sizeof(double)) &&
1633 (info->num_fields == 1) &&
1634 (info->fields[0].field->type->type == MONO_TYPE_R8)) {
1635 cinfo->args[nParm].size = sizeof(double);
1636 add_float(&fr, sz, cinfo->args+nParm);
1641 cinfo->args[nParm].vtsize = 0;
1642 cinfo->args[nParm].size = 0;
1645 /*----------------------------------*/
1646 /* On S/390, structures of size 1, */
1647 /* 2, 4, and 8 bytes are passed in */
1648 /* (a) register(s). */
1649 /*----------------------------------*/
1655 add_general(&gr, sz, cinfo->args+nParm);
1656 cinfo->args[nParm].size = size;
1657 cinfo->args[nParm].regtype = RegTypeStructByVal;
1659 sz->local_size += sizeof(long);
1662 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1667 case MONO_TYPE_TYPEDBYREF: {
1668 int size = sizeof (MonoTypedRef);
1670 cinfo->args[nParm].vtsize = 0;
1671 cinfo->args[nParm].size = 0;
1674 /*----------------------------------*/
1675 /* On S/390, structures of size 1, */
1676 /* 2, 4, and 8 bytes are passed in */
1677 /* (a) register(s). */
1678 /*----------------------------------*/
1684 add_general(&gr, sz, cinfo->args+nParm);
1685 cinfo->args[nParm].size = size;
1686 cinfo->args[nParm].regtype = RegTypeStructByVal;
1688 sz->local_size += sizeof(long);
1691 add_stackParm(&gr, sz, cinfo->args+nParm, size);
1697 g_error ("Can't trampoline 0x%x", sig->params [i]->type);
1701 /*----------------------------------------------------------*/
1702 /* Handle the case where there are no implicit arguments */
1703 /*----------------------------------------------------------*/
1704 if ((sig->call_convention == MONO_CALL_VARARG) &&
1705 (sig->param_count == sig->sentinelpos)) {
1706 gr = S390_LAST_ARG_REG + 1;
1707 add_general (&gr, sz, &cinfo->sigCookie);
1710 /*----------------------------------------------------------*/
1711 /* If we are passing a structure back then if it won't be */
1712 /* in a register(s) then we make room at the end of the */
1713 /* parameters that may have been placed on the stack */
1714 /*----------------------------------------------------------*/
1715 if (cinfo->struct_ret) {
1716 cinfo->ret.offset = sz->stack_size;
1717 switch (cinfo->ret.size) {
1725 sz->stack_size += S390_ALIGN(cinfo->ret.size, align);
1730 sz->stack_size = sz->stack_size + sz->local_size + sz->parm_size +
1732 sz->stack_size = S390_ALIGN(sz->stack_size, sizeof(long));
1737 /*========================= End of Function ========================*/
1739 /*------------------------------------------------------------------*/
1741 /* Name - mono_arch_allocate_vars */
1743 /* Function - Set var information according to the calling */
1744 /* convention for S/390. The local var stuff should */
1745 /* most likely be split in another method. */
1747 /* Parameter - @m - Compile unit. */
1749 /*------------------------------------------------------------------*/
1752 mono_arch_allocate_vars (MonoCompile *cfg)
1754 MonoMethodSignature *sig;
1755 MonoMethodHeader *header;
1758 int iParm, iVar, offset, align, size, curinst;
1759 int frame_reg = STK_BASE;
1762 header = mono_method_get_header (cfg->method);
1764 cfg->flags |= MONO_CFG_HAS_SPILLUP;
1766 /*---------------------------------------------------------*/
1767 /* We use the frame register also for any method that has */
1768 /* filter clauses. This way, when the handlers are called, */
1769 /* the code will reference local variables using the frame */
1770 /* reg instead of the stack pointer: if we had to restore */
1771 /* the stack pointer, we'd corrupt the method frames that */
1772 /* are already on the stack (since filters get called */
1773 /* before stack unwinding happens) when the filter code */
1774 /* would call any method. */
1775 /*---------------------------------------------------------*/
1776 if ((cfg->flags & MONO_CFG_HAS_ALLOCA) || header->num_clauses)
1777 frame_reg = s390_r11;
1779 cfg->frame_reg = frame_reg;
1781 cfg->arch.bkchain_reg = -1;
1783 if (frame_reg != STK_BASE)
1784 cfg->used_int_regs |= 1 << frame_reg;
1786 sig = mono_method_signature (cfg->method);
1788 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1790 if (!cinfo->struct_ret) {
1791 switch (mono_type_get_underlying_type (sig->ret)->type) {
1792 case MONO_TYPE_VOID:
1795 cfg->ret->opcode = OP_REGVAR;
1796 cfg->ret->dreg = s390_r2;
1801 /*--------------------------------------------------------------*/
1802 /* local vars are at a positive offset from the stack pointer */
1803 /* also note that if the function uses alloca, we use s390_r11 */
1804 /* to point at the local variables. */
1805 /* add parameter area size for called functions */
1806 /*--------------------------------------------------------------*/
1807 offset = (cfg->param_area + S390_MINIMAL_STACK_SIZE);
1808 cfg->sig_cookie = 0;
1810 if (cinfo->struct_ret) {
1811 inst = cfg->vret_addr;
1812 offset = S390_ALIGN(offset, sizeof(gpointer));
1813 inst->inst_offset = offset;
1814 inst->opcode = OP_REGOFFSET;
1815 inst->inst_basereg = frame_reg;
1816 offset += sizeof(gpointer);
1817 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1818 printf ("vret_addr =");
1819 mono_print_ins (cfg->vret_addr);
1824 inst = cfg->args [0];
1825 if (inst->opcode != OP_REGVAR) {
1826 inst->opcode = OP_REGOFFSET;
1827 inst->inst_basereg = frame_reg;
1828 offset = S390_ALIGN(offset, sizeof(gpointer));
1829 inst->inst_offset = offset;
1830 offset += sizeof (gpointer);
1837 eArg = sig->param_count + sArg;
1839 if (sig->call_convention == MONO_CALL_VARARG)
1840 cfg->sig_cookie += S390_MINIMAL_STACK_SIZE;
1842 for (iParm = sArg; iParm < eArg; ++iParm) {
1843 inst = cfg->args [curinst];
1844 if (inst->opcode != OP_REGVAR) {
1845 switch (cinfo->args[iParm].regtype) {
1846 case RegTypeStructByAddr : {
1849 size = sizeof (gpointer);
1851 inst->opcode = OP_REGOFFSET;
1852 inst->inst_basereg = frame_reg;
1853 offset = S390_ALIGN (offset, sizeof (gpointer));
1854 inst->inst_offset = offset;
1856 /* Add a level of indirection */
1857 MONO_INST_NEW (cfg, indir, 0);
1859 inst->opcode = OP_VTARG_ADDR;
1860 inst->inst_left = indir;
1863 case RegTypeStructByAddrOnStack : {
1866 size = sizeof (gpointer);
1868 /* Similar to the == STK_BASE case below */
1869 cfg->arch.bkchain_reg = s390_r12;
1870 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1872 inst->opcode = OP_REGOFFSET;
1873 inst->dreg = mono_alloc_preg (cfg);
1874 inst->inst_basereg = cfg->arch.bkchain_reg;
1875 inst->inst_offset = cinfo->args [iParm].offset;
1877 /* Add a level of indirection */
1878 MONO_INST_NEW (cfg, indir, 0);
1880 inst->opcode = OP_VTARG_ADDR;
1881 inst->inst_left = indir;
1884 case RegTypeStructByVal :
1885 size = cinfo->args[iParm].size;
1886 offset = S390_ALIGN(offset, size);
1887 inst->opcode = OP_REGOFFSET;
1888 inst->inst_basereg = frame_reg;
1889 inst->inst_offset = offset;
1892 if (cinfo->args [iParm].reg == STK_BASE) {
1894 * These arguments are in the previous frame, so we can't
1895 * compute their offset from the current frame pointer right
1896 * now, since cfg->stack_offset is not yet known, so dedicate a
1897 * register holding the previous frame pointer.
1899 cfg->arch.bkchain_reg = s390_r12;
1900 cfg->used_int_regs |= 1 << cfg->arch.bkchain_reg;
1902 inst->opcode = OP_REGOFFSET;
1903 inst->inst_basereg = cfg->arch.bkchain_reg;
1904 size = (cinfo->args[iParm].size < 8
1905 ? 8 - cinfo->args[iParm].size
1907 inst->inst_offset = cinfo->args [iParm].offset + size;
1908 size = sizeof (long);
1910 inst->opcode = OP_REGOFFSET;
1911 inst->inst_basereg = frame_reg;
1912 size = (cinfo->args[iParm].size < 8
1915 offset = S390_ALIGN(offset, size);
1916 inst->inst_offset = offset;
1920 if ((sig->call_convention == MONO_CALL_VARARG) &&
1921 (cinfo->args[iParm].regtype != RegTypeGeneral) &&
1922 (iParm < sig->sentinelpos))
1923 cfg->sig_cookie += size;
1930 curinst = cfg->locals_start;
1931 for (iVar = curinst; iVar < cfg->num_varinfo; ++iVar) {
1932 inst = cfg->varinfo [iVar];
1933 if ((inst->flags & MONO_INST_IS_DEAD) ||
1934 (inst->opcode == OP_REGVAR))
1937 /*--------------------------------------------------*/
1938 /* inst->backend.is_pinvoke indicates native sized value types, */
1939 /* this is used by the pinvoke wrappers when they */
1940 /* call functions returning structure */
1941 /*--------------------------------------------------*/
1942 if (inst->backend.is_pinvoke && MONO_TYPE_ISSTRUCT (inst->inst_vtype))
1943 size = mono_class_native_size (mono_class_from_mono_type(inst->inst_vtype),
1944 (guint32 *) &align);
1946 size = mono_type_size (inst->inst_vtype, &align);
1948 offset = S390_ALIGN(offset, align);
1949 inst->inst_offset = offset;
1950 inst->opcode = OP_REGOFFSET;
1951 inst->inst_basereg = frame_reg;
1953 DEBUG (g_print("allocating local %d to %ld, size: %d\n",
1954 iVar, inst->inst_offset, size));
1957 /*------------------------------------------------------*/
1958 /* Allow space for the trace method stack area if needed*/
1959 /*------------------------------------------------------*/
1960 if (mono_jit_trace_calls != NULL && mono_trace_eval (cfg->method))
1961 offset += S390_TRACE_STACK_SIZE;
1963 /*------------------------------------------------------*/
1964 /* Reserve space to save LMF and caller saved registers */
1965 /*------------------------------------------------------*/
1966 if (cfg->method->save_lmf)
1967 offset += sizeof (MonoLMF);
1969 /*------------------------------------------------------*/
1970 /* align the offset */
1971 /*------------------------------------------------------*/
1972 cfg->stack_offset = S390_ALIGN(offset, S390_STACK_ALIGNMENT);
1976 /*========================= End of Function ========================*/
1978 /*------------------------------------------------------------------*/
1980 /* Name - mono_arch_create_vars */
1981 /*------------------------------------------------------------------*/
1984 mono_arch_create_vars (MonoCompile *cfg)
1986 MonoMethodSignature *sig;
1989 sig = mono_method_signature (cfg->method);
1991 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
1993 if (cinfo->struct_ret) {
1994 cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
1995 if (G_UNLIKELY (cfg->verbose_level > 1)) {
1996 printf ("vret_addr = ");
1997 mono_print_ins (cfg->vret_addr);
2002 /*========================= End of Function ========================*/
2005 add_outarg_reg2 (MonoCompile *cfg, MonoCallInst *call, ArgStorage storage, int reg, MonoInst *tree)
2010 case RegTypeGeneral:
2011 MONO_INST_NEW (cfg, ins, OP_MOVE);
2012 ins->dreg = mono_alloc_ireg (cfg);
2013 ins->sreg1 = tree->dreg;
2014 MONO_ADD_INS (cfg->cbb, ins);
2015 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, FALSE);
2018 MONO_INST_NEW (cfg, ins, OP_FMOVE);
2019 ins->dreg = mono_alloc_freg (cfg);
2020 ins->sreg1 = tree->dreg;
2021 MONO_ADD_INS (cfg->cbb, ins);
2022 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2025 MONO_INST_NEW (cfg, ins, OP_S390_SETF4RET);
2026 ins->dreg = mono_alloc_freg (cfg);
2027 ins->sreg1 = tree->dreg;
2028 MONO_ADD_INS (cfg->cbb, ins);
2029 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, reg, TRUE);
2032 g_assert_not_reached ();
2037 emit_sig_cookie (MonoCompile *cfg, MonoCallInst *call, CallInfo *cinfo)
2039 MonoMethodSignature *tmpSig;
2042 cfg->disable_aot = TRUE;
2044 /*----------------------------------------------------------*/
2045 /* mono_ArgIterator_Setup assumes the signature cookie is */
2046 /* passed first and all the arguments which were before it */
2047 /* passed on the stack after the signature. So compensate */
2048 /* by passing a different signature. */
2049 /*----------------------------------------------------------*/
2050 tmpSig = mono_metadata_signature_dup (call->signature);
2051 tmpSig->param_count -= call->signature->sentinelpos;
2052 tmpSig->sentinelpos = 0;
2053 if (tmpSig->param_count > 0)
2054 memcpy (tmpSig->params,
2055 call->signature->params + call->signature->sentinelpos,
2056 tmpSig->param_count * sizeof(MonoType *));
2058 MONO_INST_NEW (cfg, sig_arg, OP_ICONST);
2059 sig_arg->dreg = mono_alloc_ireg (cfg);
2060 sig_arg->inst_p0 = tmpSig;
2061 MONO_ADD_INS (cfg->cbb, sig_arg);
2063 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, STK_BASE,
2064 cinfo->sigCookie.offset, sig_arg->dreg);
2067 /*------------------------------------------------------------------*/
2069 /* Name - mono_arch_emit_call */
2071 /*------------------------------------------------------------------*/
2074 mono_arch_emit_call (MonoCompile *cfg, MonoCallInst *call)
2077 MonoMethodSignature *sig;
2079 int i, n, lParamArea;
2081 ArgInfo *ainfo = NULL;
2084 sig = call->signature;
2085 n = sig->param_count + sig->hasthis;
2086 DEBUG (g_print ("Call requires: %d parameters\n",n));
2088 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
2090 stackSize = cinfo->sz.stack_size + cinfo->sz.local_size + cinfo->sz.parm_size + cinfo->sz.offset;
2091 call->stack_usage = MAX(stackSize, call->stack_usage);
2092 lParamArea = MAX((call->stack_usage-S390_MINIMAL_STACK_SIZE-cinfo->sz.parm_size), 0);
2093 cfg->param_area = MAX(((signed) cfg->param_area), lParamArea);
2094 cfg->flags |= MONO_CFG_HAS_CALLS;
2096 if (cinfo->struct_ret) {
2097 MONO_INST_NEW (cfg, ins, OP_MOVE);
2098 ins->sreg1 = call->vret_var->dreg;
2099 ins->dreg = mono_alloc_preg (cfg);
2100 MONO_ADD_INS (cfg->cbb, ins);
2101 mono_call_inst_add_outarg_reg (cfg, call, ins->dreg, cinfo->ret.reg, FALSE);
2104 for (i = 0; i < n; ++i) {
2107 ainfo = cinfo->args + i;
2108 if (i >= sig->hasthis)
2109 t = sig->params [i - sig->hasthis];
2111 t = &mono_defaults.int_class->byval_arg;
2112 t = mono_type_get_underlying_type (t);
2114 in = call->args [i];
2116 if ((sig->call_convention == MONO_CALL_VARARG) &&
2117 (i == sig->sentinelpos)) {
2118 emit_sig_cookie (cfg, call, cinfo);
2121 switch (ainfo->regtype) {
2122 case RegTypeGeneral:
2123 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2126 if (MONO_TYPE_ISSTRUCT (t)) {
2127 /* Valuetype passed in one fp register */
2128 ainfo->regtype = RegTypeStructByValInFP;
2131 if (ainfo->size == 4)
2132 ainfo->regtype = RegTypeFPR4;
2133 add_outarg_reg2 (cfg, call, ainfo->regtype, ainfo->reg, in);
2136 case RegTypeStructByVal:
2137 case RegTypeStructByAddr:
2138 case RegTypeStructByAddrOnStack: {
2142 if (sig->params [i - sig->hasthis]->type == MONO_TYPE_TYPEDBYREF) {
2143 size = sizeof (MonoTypedRef);
2144 align = sizeof (gpointer);
2148 size = mono_type_native_stack_size (&in->klass->byval_arg, &align);
2151 * Other backends use mono_type_stack_size (), but that
2152 * aligns the size to 8, which is larger than the size of
2153 * the source, leading to reads of invalid memory if the
2154 * source is at the end of address space.
2156 size = mono_class_value_size (in->klass, &align);
2159 g_assert (in->klass);
2161 ainfo->offparm += cinfo->sz.offStruct;
2163 MONO_INST_NEW (cfg, ins, OP_OUTARG_VT);
2164 ins->sreg1 = in->dreg;
2165 ins->klass = in->klass;
2166 ins->backend.size = ainfo->size;
2167 ins->inst_p0 = call;
2168 ins->inst_p1 = mono_mempool_alloc (cfg->mempool, sizeof (ArgInfo));
2169 memcpy (ins->inst_p1, ainfo, sizeof (ArgInfo));
2171 MONO_ADD_INS (cfg->cbb, ins);
2173 if (ainfo->regtype == RegTypeStructByAddr) {
2175 * We use OP_OUTARG_VT to copy the valuetype to a stack location, then
2176 * use the normal OUTARG opcodes to pass the address of the location to
2179 int treg = mono_alloc_preg (cfg);
2180 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2181 STK_BASE, ainfo->offparm);
2182 mono_call_inst_add_outarg_reg (cfg, call, treg, ainfo->reg, FALSE);
2183 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
2184 /* The address of the valuetype is passed on the stack */
2185 int treg = mono_alloc_preg (cfg);
2186 MONO_EMIT_NEW_BIALU_IMM (cfg, OP_ADD_IMM, treg,
2187 STK_BASE, ainfo->offparm);
2188 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG,
2189 ainfo->reg, ainfo->offset, treg);
2194 if (!t->byref && t->type == MONO_TYPE_R4) {
2195 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER4_MEMBASE_REG,
2196 STK_BASE, ainfo->offset + 4,
2198 } else if (!t->byref && (t->type == MONO_TYPE_R8)) {
2199 MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORER8_MEMBASE_REG,
2200 STK_BASE, ainfo->offset,
2203 MONO_INST_NEW (cfg, ins, OP_STORE_MEMBASE_REG);
2204 ins->inst_destbasereg = STK_BASE;
2205 ins->inst_offset = ainfo->offset;
2206 ins->sreg1 = in->dreg;
2208 /* This is needed by MonoTypedRef->value to point to the correct data */
2209 if ((sig->call_convention == MONO_CALL_VARARG) &&
2210 (i >= sig->sentinelpos)) {
2211 switch (ainfo->size) {
2213 ins->opcode = OP_STOREI1_MEMBASE_REG;
2216 ins->opcode = OP_STOREI2_MEMBASE_REG;
2219 ins->opcode = OP_STOREI4_MEMBASE_REG;
2226 MONO_ADD_INS (cfg->cbb, ins);
2230 g_assert_not_reached ();
2236 * Handle the case where there are no implicit arguments
2238 if ((sig->call_convention == MONO_CALL_VARARG) &&
2239 (i == sig->sentinelpos)) {
2240 emit_sig_cookie (cfg, call, cinfo);
2244 /*========================= End of Function ========================*/
2246 /*------------------------------------------------------------------*/
2248 /* Name - mono_arch_emit_outarg_vt */
2250 /*------------------------------------------------------------------*/
2253 mono_arch_emit_outarg_vt (MonoCompile *cfg, MonoInst *ins, MonoInst *src)
2255 MonoCallInst *call = (MonoCallInst*)ins->inst_p0;
2256 ArgInfo *ainfo = (ArgInfo*)ins->inst_p1;
2257 int size = ins->backend.size;
2259 if (ainfo->regtype == RegTypeStructByVal) {
2261 arg->ins.sreg1 = ainfo->reg;
2262 arg->ins.opcode = OP_OUTARG_VT;
2263 arg->size = ainfo->size;
2264 arg->offset = ainfo->offset;
2265 arg->offPrm = ainfo->offparm + cinfo->sz.offStruct;
2267 if (ainfo->reg != STK_BASE) {
2268 MONO_OUTPUT_VTR (cfg, size, ainfo->reg, src->dreg, 0);
2270 MONO_OUTPUT_VTS (cfg, size, ainfo->reg, ainfo->offset,
2273 } else if (ainfo->regtype == RegTypeStructByValInFP) {
2274 int dreg = mono_alloc_freg (cfg);
2276 if (ainfo->size == 4) {
2277 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR4_MEMBASE, dreg, src->dreg, 0);
2278 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, dreg, dreg);
2280 g_assert (ainfo->size == 8);
2282 MONO_EMIT_NEW_LOAD_MEMBASE_OP (cfg, OP_LOADR8_MEMBASE, dreg, src->dreg, 0);
2285 mono_call_inst_add_outarg_reg (cfg, call, dreg, ainfo->reg, TRUE);
2287 MONO_EMIT_NEW_MOVE (cfg, STK_BASE, ainfo->offparm,
2288 src->dreg, 0, size);
2292 /*------------------------------------------------------------------*/
2294 /* Name - mono_arch_emit_setret */
2296 /*------------------------------------------------------------------*/
2299 mono_arch_emit_setret (MonoCompile *cfg, MonoMethod *method, MonoInst *val)
2301 MonoType *ret = mono_type_get_underlying_type (mono_method_signature (method)->ret);
2304 if (ret->type == MONO_TYPE_R4) {
2305 MONO_EMIT_NEW_UNALU (cfg, OP_S390_SETF4RET, s390_f0, val->dreg);
2307 } else if (ret->type == MONO_TYPE_R8) {
2308 MONO_EMIT_NEW_UNALU (cfg, OP_FMOVE, s390_f0, val->dreg);
2313 MONO_EMIT_NEW_UNALU (cfg, OP_MOVE, cfg->ret->dreg, val->dreg);
2316 /*========================= End of Function ========================*/
2318 /*------------------------------------------------------------------*/
2320 /* Name - mono_arch_instrument_mem_needs */
2322 /* Function - Allow tracing to work with this interface (with */
2323 /* an optional argument). */
2325 /*------------------------------------------------------------------*/
2328 mono_arch_instrument_mem_needs (MonoMethod *method, int *stack, int *code)
2330 /* no stack room needed now (may be needed for FASTCALL-trace support) */
2332 /* split prolog-epilog requirements? */
2333 *code = 50; /* max bytes needed: check this number */
2336 /*========================= End of Function ========================*/
2338 /*------------------------------------------------------------------*/
2340 /* Name - mono_arch_instrument_prolog */
2342 /* Function - Create an "instrumented" prolog. */
2344 /*------------------------------------------------------------------*/
2347 mono_arch_instrument_prolog (MonoCompile *cfg, void *func, void *p,
2348 gboolean enable_arguments)
2355 parmOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2356 if (cfg->method->save_lmf)
2357 parmOffset -= sizeof(MonoLMF);
2358 fpOffset = parmOffset + (5*sizeof(gpointer));
2359 if ((!has_ld) && (fpOffset > 4096)) {
2360 s390_lgr (code, s390_r12, STK_BASE);
2362 while (fpOffset > 4096) {
2363 s390_aghi (code, baseReg, 4096);
2371 s390_stmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2373 s390_stdy (code, s390_f0, 0, STK_BASE, fpOffset);
2374 s390_stdy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2375 s390_stdy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2376 s390_stdy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2378 s390_std (code, s390_f0, 0, baseReg, fpOffset);
2379 s390_std (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2380 s390_std (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2381 s390_std (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2383 s390_basr (code, s390_r13, 0);
2385 s390_llong(code, cfg->method);
2386 s390_llong(code, func);
2387 s390_lg (code, s390_r2, 0, s390_r13, 4);
2389 s390_lay (code, s390_r3, 0, STK_BASE, parmOffset);
2391 s390_la (code, s390_r3, 0, baseReg, parmOffset);
2392 s390_lgr (code, s390_r4, STK_BASE);
2393 s390_aghi (code, s390_r4, cfg->stack_usage);
2394 s390_lg (code, s390_r1, 0, s390_r13, 12);
2395 s390_basr (code, s390_r14, s390_r1);
2397 s390_ldy (code, s390_f6, 0, STK_BASE, fpOffset+3*sizeof(gdouble));
2398 s390_ldy (code, s390_f4, 0, STK_BASE, fpOffset+2*sizeof(gdouble));
2399 s390_ldy (code, s390_f2, 0, STK_BASE, fpOffset+sizeof(gdouble));
2400 s390_ldy (code, s390_f0, 0, STK_BASE, fpOffset);
2402 s390_ld (code, s390_f6, 0, baseReg, fpOffset+3*sizeof(gdouble));
2403 s390_ld (code, s390_f4, 0, baseReg, fpOffset+2*sizeof(gdouble));
2404 s390_ld (code, s390_f2, 0, baseReg, fpOffset+sizeof(gdouble));
2405 s390_ld (code, s390_f0, 0, baseReg, fpOffset);
2407 s390_lmg (code, s390_r2, s390_r6, STK_BASE, parmOffset);
2412 /*========================= End of Function ========================*/
2414 /*------------------------------------------------------------------*/
2416 /* Name - mono_arch_instrument_epilog */
2418 /* Function - Create an epilog that will handle the returned */
2419 /* values used in instrumentation. */
2421 /*------------------------------------------------------------------*/
2424 mono_arch_instrument_epilog_full (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers)
2427 int save_mode = SAVE_NONE,
2429 MonoMethod *method = cfg->method;
2430 int rtype = mono_type_get_underlying_type (mono_method_signature (method)->ret)->type;
2432 saveOffset = cfg->stack_usage - S390_TRACE_STACK_SIZE;
2433 if (method->save_lmf)
2434 saveOffset -= sizeof(MonoLMF);
2438 case MONO_TYPE_VOID:
2439 /* special case string .ctor icall */
2440 if (strcmp (".ctor", method->name) && method->klass == mono_defaults.string_class)
2441 save_mode = SAVE_ONE;
2443 save_mode = SAVE_NONE;
2447 save_mode = SAVE_ONE;
2450 save_mode = SAVE_R4;
2453 save_mode = SAVE_R8;
2455 case MONO_TYPE_VALUETYPE:
2456 if (mono_method_signature (method)->ret->data.klass->enumtype) {
2457 rtype = mono_class_enum_basetype (mono_method_signature (method)->ret->data.klass)->type;
2460 save_mode = SAVE_STRUCT;
2463 save_mode = SAVE_ONE;
2467 switch (save_mode) {
2469 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2470 if (enable_arguments) {
2471 s390_lgr (code, s390_r3, s390_r2);
2475 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2476 if (enable_arguments) {
2477 s390_ldebr (code, s390_f0, s390_f0);
2481 s390_std (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2484 s390_stg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2485 if (enable_arguments) {
2486 s390_lg (code, s390_r3, 0, cfg->frame_reg,
2487 S390_MINIMAL_STACK_SIZE+cfg->param_area);
2495 s390_basr (code, s390_r13, 0);
2497 s390_llong(code, cfg->method);
2498 s390_llong(code, func);
2499 s390_lg (code, s390_r2, 0, s390_r13, 4);
2500 s390_lg (code, s390_r1, 0, s390_r13, 12);
2501 s390_basr (code, s390_r14, s390_r1);
2503 switch (save_mode) {
2505 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2509 s390_ld (code, s390_f0, 0, cfg->frame_reg, saveOffset);
2512 s390_lg (code, s390_r2, 0, cfg->frame_reg, saveOffset);
2522 /*========================= End of Function ========================*/
2525 mono_arch_peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
2529 /*------------------------------------------------------------------*/
2531 /* Name - mono_arch_peephole_pass */
2533 /* Function - Form a peephole pass at the code looking for */
2534 /* simple optimizations. */
2536 /*------------------------------------------------------------------*/
2539 mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
2543 MONO_BB_FOR_EACH_INS_SAFE (bb, n, ins) {
2544 mono_peephole_ins (bb, ins);
2548 /*========================= End of Function ========================*/
2551 mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
2553 MonoInst *ins, *next;
2555 MONO_BB_FOR_EACH_INS_SAFE (bb, next, ins) {
2556 switch (ins->opcode) {
2561 case OP_IDIV_UN_IMM:
2562 case OP_IREM_UN_IMM:
2566 case OP_LOCALLOC_IMM:
2567 mono_decompose_op_imm (cfg, bb, ins);
2570 if (!s390_is_imm16 (ins->inst_imm))
2571 /* This is created by the memcpy code which ignores is_inst_imm */
2572 mono_decompose_op_imm (cfg, bb, ins);
2579 bb->max_vreg = cfg->next_vreg;
2582 /*========================= End of Function ========================*/
2584 /*------------------------------------------------------------------*/
2586 /* Name - emit_float_to_int */
2588 /* Function - Create instructions which will convert a floating */
2589 /* point value to integer. */
2591 /*------------------------------------------------------------------*/
2594 emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, gboolean is_signed)
2596 /* sreg is a float, dreg is an integer reg. */
2598 s390_cgdbr (code, dreg, 5, sreg);
2601 s390_lghi (code, s390_r0, 0);
2602 s390_lghi (code, s390_r13, 0xff);
2603 s390_ltgr (code, dreg, dreg);
2605 s390_lghi (code, s390_r0, 0x80);
2606 s390_ngr (code, dreg, s390_r13);
2607 s390_ogr (code, dreg, s390_r0);
2612 s390_basr (code, s390_r13, 0);
2614 s390_llong (code, 0x41e0000000000000);
2615 s390_llong (code, 0x41f0000000000000);
2616 s390_ldr (code, s390_f15, sreg);
2617 s390_cdb (code, s390_f15, 0, s390_r13, 4);
2618 s390_jl (code, 0); CODEPTR (code, o[0]);
2619 s390_sdb (code, s390_f15, 0, s390_r13, 12);
2620 s390_cfdbr (code, dreg, 7, s390_f15);
2622 PTRSLOT (code, o[0]);
2623 s390_cfdbr (code, dreg, 5, sreg);
2626 s390_lghi (code, s390_r0, 0xff);
2627 s390_ngr (code, dreg, s390_r0);
2630 s390_lghi (code, s390_r0, -1);
2631 s390_srlg (code, s390_r0, s390_r0, 0, 16);
2632 s390_ngr (code, dreg, s390_r0);
2639 /*========================= End of Function ========================*/
2641 /*------------------------------------------------------------------*/
2643 /* Name - gboolean_is_unsigned. */
2645 /* Function - Return TRUE if next opcode is checking for un- */
2648 /*------------------------------------------------------------------*/
2651 gboolean is_unsigned (MonoInst *next)
2654 (((next->opcode >= OP_IBNE_UN) &&
2655 (next->opcode <= OP_IBLT_UN)) ||
2656 ((next->opcode >= OP_LBNE_UN) &&
2657 (next->opcode <= OP_LBLT_UN)) ||
2658 ((next->opcode >= OP_COND_EXC_NE_UN) &&
2659 (next->opcode <= OP_COND_EXC_LT_UN)) ||
2660 ((next->opcode >= OP_COND_EXC_INE_UN) &&
2661 (next->opcode <= OP_COND_EXC_ILT_UN)) ||
2662 ((next->opcode == OP_CLT_UN) ||
2663 (next->opcode == OP_CGT_UN)) ||
2664 ((next->opcode == OP_ICLT_UN) ||
2665 (next->opcode == OP_ICGT_UN) ||
2666 (next->opcode == OP_LCLT_UN) ||
2667 (next->opcode == OP_LCGT_UN))))
2673 /*========================= End of Function ========================*/
2675 /*------------------------------------------------------------------*/
2677 /* Name - mono_arch_output_basic_block */
2679 /* Function - Perform the "real" work of emitting instructions */
2680 /* that will do the work of in the basic block. */
2682 /*------------------------------------------------------------------*/
2685 mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
2690 guint8 *code = cfg->native_code + cfg->code_len;
2691 guint last_offset = 0;
2692 int max_len, cpos, src2;
2694 /* we don't align basic blocks of loops on s390 */
2696 if (cfg->verbose_level > 2)
2697 g_print ("Basic block %d starting at offset 0x%x\n", bb->block_num, bb->native_offset);
2699 cpos = bb->max_offset;
2701 if (cfg->prof_options & MONO_PROFILE_COVERAGE) {
2702 //MonoCoverageInfo *cov = mono_get_coverage_info (cfg->method);
2703 //g_assert (!mono_compile_aot);
2706 // cov->data [bb->dfn].iloffset = bb->cil_code - cfg->cil_code;
2707 /* this is not thread save, but good enough */
2708 /* fixme: howto handle overflows? */
2709 //x86_inc_mem (code, &cov->data [bb->dfn].count);
2712 MONO_BB_FOR_EACH_INS (bb, ins) {
2713 offset = code - cfg->native_code;
2715 max_len = ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
2717 if (offset > (cfg->code_size - max_len - 16)) {
2718 cfg->code_size *= 2;
2719 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
2720 code = cfg->native_code + offset;
2723 mono_debug_record_line_number (cfg, ins, offset);
2725 switch (ins->opcode) {
2726 case OP_STOREI1_MEMBASE_IMM: {
2727 s390_lghi (code, s390_r0, ins->inst_imm);
2728 S390_LONG (code, stcy, stc, s390_r0, 0,
2729 ins->inst_destbasereg, ins->inst_offset);
2732 case OP_STOREI2_MEMBASE_IMM: {
2733 s390_lghi (code, s390_r0, ins->inst_imm);
2734 S390_LONG (code, sthy, sth, s390_r0, 0,
2735 ins->inst_destbasereg, ins->inst_offset);
2738 case OP_STOREI4_MEMBASE_IMM: {
2739 if (s390_is_imm16(ins->inst_imm)) {
2740 s390_lghi (code, s390_r0, ins->inst_imm);
2742 s390_basr (code, s390_r13, 0);
2744 s390_llong(code, ins->inst_imm);
2745 s390_lg (code, s390_r0, 0, s390_r13, 4);
2747 S390_LONG (code, sty, st, s390_r0, 0,
2748 ins->inst_destbasereg, ins->inst_offset);
2751 case OP_STORE_MEMBASE_IMM:
2752 case OP_STOREI8_MEMBASE_IMM: {
2753 if (s390_is_imm16(ins->inst_imm)) {
2754 s390_lghi (code, s390_r0, ins->inst_imm);
2756 s390_basr (code, s390_r13, 0);
2758 s390_llong(code, ins->inst_imm);
2759 s390_lg (code, s390_r0, 0, s390_r13, 4);
2761 S390_LONG (code, stg, stg, s390_r0, 0,
2762 ins->inst_destbasereg, ins->inst_offset);
2765 case OP_STOREI1_MEMBASE_REG: {
2766 S390_LONG (code, stcy, stc, ins->sreg1, 0,
2767 ins->inst_destbasereg, ins->inst_offset);
2770 case OP_STOREI2_MEMBASE_REG: {
2771 S390_LONG (code, sthy, sth, ins->sreg1, 0,
2772 ins->inst_destbasereg, ins->inst_offset);
2775 case OP_STOREI4_MEMBASE_REG: {
2776 S390_LONG (code, sty, st, ins->sreg1, 0,
2777 ins->inst_destbasereg, ins->inst_offset);
2780 case OP_STORE_MEMBASE_REG:
2781 case OP_STOREI8_MEMBASE_REG: {
2782 S390_LONG (code, stg, stg, ins->sreg1, 0,
2783 ins->inst_destbasereg, ins->inst_offset);
2787 g_assert_not_reached ();
2789 case OP_LOAD_MEMBASE:
2790 case OP_LOADI8_MEMBASE: {
2791 S390_LONG (code, lg, lg, ins->dreg, 0,
2792 ins->inst_basereg, ins->inst_offset);
2795 case OP_LOADI4_MEMBASE: {
2796 S390_LONG (code, lgf, lgf, ins->dreg, 0,
2797 ins->inst_basereg, ins->inst_offset);
2800 case OP_LOADU4_MEMBASE: {
2801 S390_LONG (code, llgf, llgf, ins->dreg, 0,
2802 ins->inst_basereg, ins->inst_offset);
2805 case OP_LOADU1_MEMBASE: {
2806 S390_LONG (code, llgc, llgc, ins->dreg, 0,
2807 ins->inst_basereg, ins->inst_offset);
2810 case OP_LOADI1_MEMBASE: {
2811 S390_LONG (code, lgb, lgb, ins->dreg, 0,
2812 ins->inst_basereg, ins->inst_offset);
2815 case OP_LOADU2_MEMBASE: {
2816 S390_LONG (code, llgh, llgh, ins->dreg, 0,
2817 ins->inst_basereg, ins->inst_offset);
2820 case OP_LOADI2_MEMBASE: {
2821 S390_LONG (code, lgh, lgh, ins->dreg, 0,
2822 ins->inst_basereg, ins->inst_offset);
2825 case OP_LCONV_TO_I1: {
2827 s390_lgbr (code, ins->dreg, ins->sreg1);
2829 s390_sllg (code, ins->dreg, ins->sreg1, 0, 56);
2830 s390_srag (code, ins->dreg, ins->dreg, 0, 56);
2834 case OP_LCONV_TO_I2: {
2836 s390_lghr (code, ins->dreg, ins->sreg1);
2838 s390_sllg (code, ins->dreg, ins->sreg1, 0, 48);
2839 s390_srag (code, ins->dreg, ins->dreg, 0, 48);
2843 case OP_LCONV_TO_U1: {
2845 s390_llghr (code, ins->dreg, ins->sreg1);
2847 if (ins->dreg != ins->sreg1)
2848 s390_lgr (code, ins->dreg, ins->sreg1);
2849 s390_lghi (code, s390_r0, 0xff);
2850 s390_ngr (code, ins->dreg, s390_r0);
2854 case OP_LCONV_TO_U2: {
2856 s390_llghr (code, ins->dreg, ins->sreg1);
2858 if (ins->dreg != ins->sreg1)
2859 s390_lgr (code, ins->dreg, ins->sreg1);
2860 s390_lghi (code, s390_r0, -1);
2861 s390_srlg (code, s390_r0, s390_r0, 0, 48);
2862 s390_ngr (code, ins->dreg, s390_r0);
2866 case OP_ICONV_TO_I1: {
2868 s390_lbr (code, ins->dreg, ins->sreg1);
2870 if (ins->dreg != ins->sreg1)
2871 s390_lr (code, ins->dreg, ins->sreg1);
2872 s390_sll (code, ins->dreg, 0, 24);
2873 s390_sra (code, ins->dreg, 0, 24);
2878 case OP_ICONV_TO_I2: {
2880 s390_lhr (code, ins->dreg, ins->sreg1);
2882 if (ins->dreg != ins->sreg1)
2883 s390_lr (code, ins->dreg, ins->sreg1);
2884 s390_sll (code, ins->dreg, 0, 16);
2885 s390_sra (code, ins->dreg, 0, 16);
2889 case OP_ICONV_TO_U1: {
2891 s390_llcr (code, ins->dreg, ins->sreg1);
2893 if (ins->dreg != ins->sreg1)
2894 s390_lr (code, ins->dreg, ins->sreg1);
2895 s390_lhi (code, s390_r0, 0xff);
2896 s390_nr (code, ins->dreg, s390_r0);
2900 case OP_ICONV_TO_U2: {
2902 s390_llhr (code, ins->dreg, ins->sreg1);
2904 if (ins->dreg != ins->sreg1)
2905 s390_lr (code, ins->dreg, ins->sreg1);
2906 s390_lhi (code, s390_r0, -1);
2907 s390_srl (code, s390_r0, 0, 16);
2908 s390_nr (code, ins->dreg, s390_r0);
2914 if (is_unsigned (ins->next))
2915 s390_clgr (code, ins->sreg1, ins->sreg2);
2917 s390_cgr (code, ins->sreg1, ins->sreg2);
2921 if (is_unsigned (ins->next))
2922 s390_clr (code, ins->sreg1, ins->sreg2);
2924 s390_cr (code, ins->sreg1, ins->sreg2);
2927 case OP_COMPARE_IMM:
2928 case OP_LCOMPARE_IMM: {
2929 if (s390_is_imm16 (ins->inst_imm)) {
2930 s390_lghi (code, s390_r0, ins->inst_imm);
2931 if (is_unsigned (ins->next))
2932 s390_clgr (code, ins->sreg1, s390_r0);
2934 s390_cgr (code, ins->sreg1, s390_r0);
2936 s390_basr (code, s390_r13, 0);
2938 s390_llong(code, ins->inst_imm);
2939 if (is_unsigned (ins->next))
2940 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
2942 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
2946 case OP_ICOMPARE_IMM: {
2947 if (s390_is_imm16 (ins->inst_imm)) {
2948 s390_lghi (code, s390_r0, ins->inst_imm);
2949 if (is_unsigned (ins->next))
2950 s390_clr (code, ins->sreg1, s390_r0);
2952 s390_cr (code, ins->sreg1, s390_r0);
2955 s390_basr (code, s390_r13, 0);
2957 s390_word (code, ins->inst_imm);
2958 if (is_unsigned (ins->next))
2959 s390_cl (code, ins->sreg1, 0, s390_r13, 4);
2961 s390_c (code, ins->sreg1, 0, s390_r13, 4);
2966 s390_basr (code, s390_r13, 0);
2968 mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS,
2970 s390_llong (code, mono_break);
2971 s390_lg (code, s390_r14, 0, s390_r13, 4);
2972 s390_basr (code, s390_r14, s390_r14);
2977 s390_agr (code, ins->dreg, src2);
2982 s390_agr (code, ins->dreg, src2);
2987 s390_alcgr (code, ins->dreg, src2);
2991 if (ins->dreg != ins->sreg1) {
2992 s390_lgr (code, ins->dreg, ins->sreg1);
2994 if (s390_is_imm16 (ins->inst_imm)) {
2995 s390_aghi (code, ins->dreg, ins->inst_imm);
2997 s390_basr (code, s390_r13, 0);
2999 s390_llong(code, ins->inst_imm);
3000 s390_ag (code, ins->dreg, 0, s390_r13, 4);
3005 if (ins->dreg != ins->sreg1) {
3006 s390_lgr (code, ins->dreg, ins->sreg1);
3008 g_assert (s390_is_imm16 (ins->inst_imm));
3009 s390_aghi (code, ins->dreg, ins->inst_imm);
3013 if (ins->dreg != ins->sreg1) {
3014 s390_lgr (code, ins->dreg, ins->sreg1);
3016 if (s390_is_imm16 (ins->inst_imm)) {
3017 s390_lghi (code, s390_r0, ins->inst_imm);
3018 s390_alcgr (code, ins->dreg, s390_r0);
3020 s390_basr (code, s390_r13, 0);
3022 s390_llong (code, ins->inst_imm);
3023 s390_lg (code, s390_r13, 0, s390_r13, 4);
3024 s390_alcgr (code, ins->dreg, s390_r13);
3029 case OP_S390_IADD_OVF: {
3031 s390_ar (code, ins->dreg, src2);
3032 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3033 s390_lgfr (code, ins->dreg, ins->dreg);
3036 case OP_IADD_OVF_UN:
3037 case OP_S390_IADD_OVF_UN: {
3039 s390_algr (code, ins->dreg, src2);
3040 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3041 s390_llgfr (code, ins->dreg, ins->dreg);
3044 case OP_ADD_OVF_CARRY: {
3046 s390_lghi (code, s390_r0, 0);
3047 s390_lgr (code, s390_r1, s390_r0);
3048 s390_alcgr (code, s390_r0, s390_r1);
3049 s390_agr (code, ins->dreg, src2);
3050 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3051 s390_agr (code, ins->dreg, s390_r0);
3052 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3055 case OP_ADD_OVF_UN_CARRY: {
3057 s390_alcgr (code, ins->dreg, src2);
3058 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3063 s390_sgr (code, ins->dreg, src2);
3068 s390_sgr (code, ins->dreg, src2);
3073 s390_slbgr(code, ins->dreg, src2);
3077 if (ins->dreg != ins->sreg1) {
3078 s390_lgr (code, ins->dreg, ins->sreg1);
3080 if (s390_is_imm16 (-ins->inst_imm)) {
3081 s390_lghi (code, s390_r0, ins->inst_imm);
3082 s390_slgr (code, ins->dreg, s390_r0);
3084 s390_basr (code, s390_r13, 0);
3086 s390_llong(code, ins->inst_imm);
3087 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3092 if (ins->dreg != ins->sreg1) {
3093 s390_lgr (code, ins->dreg, ins->sreg1);
3095 if (s390_is_imm16 (-ins->inst_imm)) {
3096 s390_lghi (code, s390_r0, ins->inst_imm);
3097 s390_slgr (code, ins->dreg, s390_r0);
3099 s390_basr (code, s390_r13, 0);
3101 s390_llong(code, ins->inst_imm);
3102 s390_slg (code, ins->dreg, 0, s390_r13, 4);
3107 if (ins->dreg != ins->sreg1) {
3108 s390_lgr (code, ins->dreg, ins->sreg1);
3110 if (s390_is_imm16 (-ins->inst_imm)) {
3111 s390_lghi (code, s390_r0, ins->inst_imm);
3112 s390_slbgr (code, ins->dreg, s390_r0);
3114 s390_basr (code, s390_r13, 0);
3116 s390_llong(code, ins->inst_imm);
3117 s390_slbg (code, ins->dreg, 0, s390_r13, 4);
3121 case OP_SUB_OVF_CARRY: {
3123 s390_lghi (code, s390_r0, 0);
3124 s390_lgr (code, s390_r1, s390_r0);
3125 s390_slbgr (code, s390_r0, s390_r1);
3126 s390_sgr (code, ins->dreg, src2);
3127 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3128 s390_agr (code, ins->dreg, s390_r0);
3129 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3132 case OP_SUB_OVF_UN_CARRY: {
3134 s390_slbgr (code, ins->dreg, src2);
3135 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3139 if (ins->sreg1 == ins->dreg) {
3140 s390_ngr (code, ins->dreg, ins->sreg2);
3143 if (ins->sreg2 == ins->dreg) {
3144 s390_ngr (code, ins->dreg, ins->sreg1);
3147 s390_lgr (code, ins->dreg, ins->sreg1);
3148 s390_ngr (code, ins->dreg, ins->sreg2);
3154 if (ins->dreg != ins->sreg1) {
3155 s390_lgr (code, ins->dreg, ins->sreg1);
3157 if (s390_is_imm16 (ins->inst_imm)) {
3158 s390_lghi (code, s390_r0, ins->inst_imm);
3159 s390_ngr (code, ins->dreg, s390_r0);
3161 s390_basr (code, s390_r13, 0);
3163 s390_llong(code, ins->inst_imm);
3164 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3169 s390_lgr (code, s390_r1, ins->sreg1);
3170 s390_dsgr (code, s390_r0, ins->sreg2);
3171 s390_lgr (code, ins->dreg, s390_r1);
3175 s390_lgr (code, s390_r1, ins->sreg1);
3176 s390_lghi (code, s390_r0, 0);
3177 s390_dlgr (code, s390_r0, ins->sreg2);
3178 s390_lgr (code, ins->dreg, s390_r1);
3182 s390_lgr (code, s390_r1, ins->sreg1);
3183 s390_dsgr (code, s390_r0, ins->sreg2);
3184 s390_lgr (code, ins->dreg, s390_r0);
3188 s390_lgr (code, s390_r1, ins->sreg1);
3189 s390_lghi (code, s390_r0, 0);
3190 s390_dlgr (code, s390_r0, ins->sreg2);
3191 s390_lgr (code, ins->dreg, s390_r0);
3195 if (ins->sreg1 == ins->dreg) {
3196 s390_ogr (code, ins->dreg, ins->sreg2);
3199 if (ins->sreg2 == ins->dreg) {
3200 s390_ogr (code, ins->dreg, ins->sreg1);
3203 s390_lgr (code, ins->dreg, ins->sreg1);
3204 s390_ogr (code, ins->dreg, ins->sreg2);
3210 if (ins->dreg != ins->sreg1) {
3211 s390_lgr (code, ins->dreg, ins->sreg1);
3213 if (s390_is_imm16 (ins->inst_imm)) {
3214 s390_lghi (code, s390_r0, ins->inst_imm);
3215 s390_ogr (code, ins->dreg, s390_r0);
3217 s390_basr (code, s390_r13, 0);
3219 s390_llong(code, ins->inst_imm);
3220 s390_og (code, ins->dreg, 0, s390_r13, 4);
3225 if (ins->sreg1 == ins->dreg) {
3226 s390_xgr (code, ins->dreg, ins->sreg2);
3229 if (ins->sreg2 == ins->dreg) {
3230 s390_xgr (code, ins->dreg, ins->sreg1);
3233 s390_lgr (code, ins->dreg, ins->sreg1);
3234 s390_xgr (code, ins->dreg, ins->sreg2);
3240 if (ins->dreg != ins->sreg1) {
3241 s390_lgr (code, ins->dreg, ins->sreg1);
3243 if (s390_is_imm16 (ins->inst_imm)) {
3244 s390_lghi (code, s390_r0, ins->inst_imm);
3245 s390_xgr (code, ins->dreg, s390_r0);
3247 s390_basr (code, s390_r13, 0);
3249 s390_llong(code, ins->inst_imm);
3250 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3256 s390_sllg (code, ins->dreg, ins->dreg, src2, 0);
3261 if (ins->sreg1 != ins->dreg) {
3262 s390_lgr (code, ins->dreg, ins->sreg1);
3264 s390_sllg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3269 s390_srag (code, ins->dreg, ins->dreg, src2, 0);
3274 if (ins->sreg1 != ins->dreg) {
3275 s390_lgr (code, ins->dreg, ins->sreg1);
3277 s390_srag (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3281 case OP_LSHR_UN_IMM: {
3282 if (ins->sreg1 != ins->dreg) {
3283 s390_lgr (code, ins->dreg, ins->sreg1);
3285 s390_srlg (code, ins->dreg, ins->dreg, 0, (ins->inst_imm & 0x3f));
3290 s390_srlg (code, ins->dreg, ins->dreg, src2, 0);
3294 if (ins->sreg1 != ins->dreg) {
3295 s390_lgr (code, ins->dreg, ins->sreg1);
3297 s390_lghi (code, s390_r0, -1);
3298 s390_xgr (code, ins->dreg, s390_r0);
3302 s390_lcgr (code, ins->dreg, ins->sreg1);
3307 s390_msgr (code, ins->dreg, src2);
3312 if (ins->dreg != ins->sreg1) {
3313 s390_lgr (code, ins->dreg, ins->sreg1);
3315 if (s390_is_imm16 (ins->inst_imm)) {
3316 s390_lghi (code, s390_r13, ins->inst_imm);
3318 s390_basr (code, s390_r13, 0);
3320 s390_llong(code, ins->inst_imm);
3321 s390_lg (code, s390_r13, 0, s390_r13, 4);
3323 s390_msgr (code, ins->dreg, s390_r13);
3328 s390_ltgr (code, s390_r1, ins->sreg1);
3329 s390_jz (code, 0); CODEPTR(code, o[0]);
3330 s390_ltgr (code, s390_r0, ins->sreg2);
3332 s390_lghi (code, s390_r1, 0);
3333 s390_j (code, 0); CODEPTR(code, o[1]);
3334 s390_xgr (code, s390_r0, s390_r1);
3335 s390_msgr (code, s390_r1, ins->sreg2);
3336 s390_xgr (code, s390_r0, s390_r1);
3337 s390_srlg (code, s390_r0, s390_r0, 0, 63);
3338 s390_ltgr (code, s390_r0, s390_r0);
3339 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3340 PTRSLOT (code, o[0]);
3341 PTRSLOT (code, o[1]);
3342 s390_lgr (code, ins->dreg, s390_r1);
3345 case OP_LMUL_OVF_UN: {
3346 s390_lghi (code, s390_r0, 0);
3347 s390_lgr (code, s390_r1, ins->sreg1);
3348 s390_mlgr (code, s390_r0, ins->sreg2);
3349 s390_ltgr (code, s390_r0, s390_r0);
3350 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3351 s390_lgr (code, ins->dreg, s390_r1);
3355 g_assert_not_reached ();
3357 s390_algr (code, ins->dreg, src2);
3362 s390_agr (code, ins->dreg, src2);
3366 g_assert_not_reached ();
3368 s390_alcgr (code, ins->dreg, src2);
3372 if (ins->dreg != ins->sreg1) {
3373 s390_lgfr (code, ins->dreg, ins->sreg1);
3375 if (s390_is_imm16 (ins->inst_imm)) {
3376 s390_aghi(code, ins->dreg, ins->inst_imm);
3378 s390_basr (code, s390_r13, 0);
3380 s390_word (code, ins->inst_imm);
3381 s390_agf (code, ins->dreg, 0, s390_r13, 4);
3386 if (ins->dreg != ins->sreg1) {
3387 s390_lgfr (code, ins->dreg, ins->sreg1);
3389 if (s390_is_imm16 (ins->inst_imm)) {
3390 s390_lghi (code, s390_r0, ins->inst_imm);
3391 s390_alcgr (code, ins->dreg, s390_r0);
3393 s390_basr (code, s390_r13, 0);
3395 s390_word (code, ins->inst_imm);
3396 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3397 s390_alcgr (code, ins->dreg, s390_r13);
3402 case OP_S390_LADD_OVF: {
3404 s390_agr (code, ins->dreg, src2);
3405 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3408 case OP_LADD_OVF_UN:
3409 case OP_S390_LADD_OVF_UN: {
3411 s390_algr (code, ins->dreg, src2);
3412 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, "OverflowException");
3416 CHECK_SRCDST_NCOM_I;
3417 s390_slgr (code, ins->dreg, src2);
3421 CHECK_SRCDST_NCOM_I;
3422 s390_sgr (code, ins->dreg, src2);
3426 CHECK_SRCDST_NCOM_I;
3427 s390_slbgr (code, ins->dreg, src2);
3431 if (ins->dreg != ins->sreg1) {
3432 s390_lgfr (code, ins->dreg, ins->sreg1);
3434 if (s390_is_imm16 (-ins->inst_imm)) {
3435 s390_aghi (code, ins->dreg, -ins->inst_imm);
3437 s390_basr (code, s390_r13, 0);
3439 s390_word (code, ins->inst_imm);
3440 s390_sgf (code, ins->dreg, 0, s390_r13, 4);
3445 s390_basr (code, s390_r13, 0);
3447 s390_word (code, ins->inst_imm);
3448 s390_slgf (code, ins->dreg, 0, s390_r13, 4);
3452 case OP_S390_ISUB_OVF: {
3454 s390_sr (code, ins->dreg, src2);
3455 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3456 s390_lgfr (code, ins->dreg, ins->dreg);
3459 case OP_ISUB_OVF_UN:
3460 case OP_S390_ISUB_OVF_UN: {
3462 s390_slr (code, ins->dreg, src2);
3463 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3464 s390_llgfr(code, ins->dreg, ins->dreg);
3468 case OP_S390_LSUB_OVF: {
3470 s390_sgr (code, ins->dreg, src2);
3471 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, "OverflowException");
3474 case OP_LSUB_OVF_UN:
3475 case OP_S390_LSUB_OVF_UN: {
3477 s390_slgr (code, ins->dreg, src2);
3478 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, "OverflowException");
3482 CHECK_SRCDST_NCOM_I;
3483 s390_ngr (code, ins->dreg, src2);
3487 if (ins->dreg != ins->sreg1) {
3488 s390_lgfr (code, ins->dreg, ins->sreg1);
3490 if (s390_is_imm16 (ins->inst_imm)) {
3491 s390_lghi (code, s390_r0, ins->inst_imm);
3492 s390_ngr (code, ins->dreg, s390_r0);
3494 s390_basr (code, s390_r13, 0);
3496 s390_llong(code, ins->inst_imm);
3497 s390_ng (code, ins->dreg, 0, s390_r13, 4);
3502 s390_lgfr (code, s390_r0, ins->sreg1);
3503 s390_srda (code, s390_r0, 0, 32);
3504 s390_dr (code, s390_r0, ins->sreg2);
3505 s390_lgfr (code, ins->dreg, s390_r1);
3509 s390_lgfr (code, s390_r0, ins->sreg1);
3510 s390_srdl (code, s390_r0, 0, 32);
3511 s390_dlr (code, s390_r0, ins->sreg2);
3512 s390_lgfr (code, ins->dreg, s390_r1);
3516 if (s390_is_imm16 (ins->inst_imm)) {
3517 s390_lghi (code, s390_r13, ins->inst_imm);
3518 s390_lgfr (code, s390_r0, ins->sreg1);
3520 s390_basr (code, s390_r13, 0);
3522 s390_word (code, ins->inst_imm);
3523 s390_lgfr (code, s390_r0, ins->sreg1);
3524 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3526 s390_srda (code, s390_r0, 0, 32);
3527 s390_dr (code, s390_r0, ins->sreg2);
3528 s390_lgfr (code, ins->dreg, s390_r1);
3532 s390_lgfr (code, s390_r0, ins->sreg1);
3533 s390_srda (code, s390_r0, 0, 32);
3534 s390_dr (code, s390_r0, ins->sreg2);
3535 s390_lgfr (code, ins->dreg, s390_r0);
3538 s390_lgfr (code, s390_r0, ins->sreg1);
3539 s390_srdl (code, s390_r0, 0, 32);
3540 s390_dlr (code, s390_r0, ins->sreg2);
3541 s390_lgfr (code, ins->dreg, s390_r0);
3545 if (s390_is_imm16 (ins->inst_imm)) {
3546 s390_lghi (code, s390_r13, ins->inst_imm);
3547 s390_lgfr (code, s390_r0, ins->sreg1);
3549 s390_basr (code, s390_r13, 0);
3551 s390_word (code, ins->inst_imm);
3552 s390_lgfr (code, s390_r0, ins->sreg1);
3553 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3555 s390_srda (code, s390_r0, 0, 32);
3556 s390_dr (code, s390_r0, ins->sreg2);
3557 s390_lgfr (code, ins->dreg, s390_r0);
3562 s390_ogr (code, ins->dreg, src2);
3566 if (ins->dreg != ins->sreg1) {
3567 s390_lgfr (code, ins->dreg, ins->sreg1);
3569 if (s390_is_imm16 (ins->inst_imm)) {
3570 s390_lghi (code, s390_r0, ins->inst_imm);
3571 s390_ogr (code, ins->dreg, s390_r0);
3573 s390_basr (code, s390_r13, 0);
3575 s390_llong(code, ins->inst_imm);
3576 s390_og (code, ins->dreg, 0, s390_r13, 4);
3582 s390_xgr (code, ins->dreg, src2);
3586 if (ins->dreg != ins->sreg1) {
3587 s390_lgfr (code, ins->dreg, ins->sreg1);
3589 if (s390_is_imm16 (ins->inst_imm)) {
3590 s390_lghi (code, s390_r0, ins->inst_imm);
3591 s390_xgr (code, ins->dreg, s390_r0);
3593 s390_basr (code, s390_r13, 0);
3595 s390_llong(code, ins->inst_imm);
3596 s390_xg (code, ins->dreg, 0, s390_r13, 4);
3602 s390_sll (code, ins->dreg, src2, 0);
3606 if (ins->sreg1 != ins->dreg) {
3607 s390_lgfr (code, ins->dreg, ins->sreg1);
3609 s390_sll (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3614 s390_sra (code, ins->dreg, src2, 0);
3618 if (ins->sreg1 != ins->dreg) {
3619 s390_lgfr (code, ins->dreg, ins->sreg1);
3621 s390_sra (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3624 case OP_ISHR_UN_IMM: {
3625 if (ins->sreg1 != ins->dreg) {
3626 s390_lgfr (code, ins->dreg, ins->sreg1);
3628 s390_srl (code, ins->dreg, 0, (ins->inst_imm & 0x1f));
3633 s390_srl (code, ins->dreg, src2, 0);
3637 if (ins->sreg1 != ins->dreg) {
3638 s390_lgfr (code, ins->dreg, ins->sreg1);
3640 s390_lghi (code, s390_r0, -1);
3641 s390_xgr (code, ins->dreg, s390_r0);
3645 s390_lcgr (code, ins->dreg, ins->sreg1);
3650 s390_msr (code, ins->dreg, src2);
3654 if (ins->dreg != ins->sreg1) {
3655 s390_lgfr (code, ins->dreg, ins->sreg1);
3657 if (s390_is_imm16 (ins->inst_imm)) {
3658 s390_lghi (code, s390_r13, ins->inst_imm);
3660 s390_basr (code, s390_r13, 0);
3662 s390_word (code, ins->inst_imm);
3663 s390_lgf (code, s390_r13, 0, s390_r13, 4);
3665 s390_msr (code, ins->dreg, s390_r13);
3670 s390_ltr (code, s390_r1, ins->sreg1);
3671 s390_jz (code, 0); CODEPTR(code, o[0]);
3672 s390_ltr (code, s390_r0, ins->sreg2);
3674 s390_lhi (code, s390_r1, 0);
3675 s390_j (code, 0); CODEPTR(code, o[1]);
3676 s390_xr (code, s390_r0, s390_r1);
3677 s390_msr (code, s390_r1, ins->sreg2);
3678 s390_xr (code, s390_r0, s390_r1);
3679 s390_srl (code, s390_r0, 0, 31);
3680 s390_ltr (code, s390_r0, s390_r0);
3681 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3682 PTRSLOT (code, o[0]);
3683 PTRSLOT (code, o[1]);
3684 s390_lgfr (code, ins->dreg, s390_r1);
3687 case OP_IMUL_OVF_UN: {
3688 s390_lhi (code, s390_r0, 0);
3689 s390_lr (code, s390_r1, ins->sreg1);
3690 s390_mlr (code, s390_r0, ins->sreg2);
3691 s390_ltr (code, s390_r0, s390_r0);
3692 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NZ, "OverflowException");
3693 s390_lgfr (code, ins->dreg, s390_r1);
3698 if (s390_is_imm16(ins->inst_c0)) {
3699 s390_lghi (code, ins->dreg, ins->inst_c0);
3701 s390_basr (code, s390_r13, 0);
3703 s390_llong(code, ins->inst_c0);
3704 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3709 s390_basr (code, s390_r13, 0);
3711 mono_add_patch_info (cfg, code - cfg->native_code,
3712 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3713 s390_llong(code, 0);
3714 s390_lg (code,ins->dreg, 0, s390_r13, 4);
3717 case OP_JUMP_TABLE: {
3718 mono_add_patch_info (cfg, code - cfg->native_code,
3719 (MonoJumpInfoType)ins->inst_i1, ins->inst_p0);
3720 s390_basr (code, s390_r13, 0);
3722 s390_llong (code, 0);
3723 s390_lg (code, ins->dreg, 0, s390_r13, 4);
3727 if (ins->dreg != ins->sreg1) {
3728 s390_lgr (code, ins->dreg, ins->sreg1);
3732 case OP_LCONV_TO_I8:
3734 s390_lgfr (code, ins->dreg, ins->sreg1);
3736 case OP_LCONV_TO_I4:
3737 s390_lgfr (code, ins->dreg, ins->sreg1);
3740 case OP_LCONV_TO_U8:
3741 case OP_LCONV_TO_U4:
3743 s390_llgfr (code, ins->dreg, ins->sreg1);
3745 case OP_LCONV_TO_OVF_U4:
3746 s390_basr (code, s390_r13, 0);
3748 s390_llong(code, 4294967295);
3749 s390_clg (code, ins->sreg1, 0, s390_r13, 4);
3750 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3751 s390_ltgr (code, ins->sreg1, ins->sreg1);
3752 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3753 s390_llgfr(code, ins->dreg, ins->sreg1);
3755 case OP_LCONV_TO_OVF_I4_UN:
3756 s390_basr (code, s390_r13, 0);
3758 s390_llong(code, 2147483647);
3759 s390_cg (code, ins->sreg1, 0, s390_r13, 4);
3760 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, "OverflowException");
3761 s390_ltgr (code, ins->sreg1, ins->sreg1);
3762 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, "OverflowException");
3763 s390_lgfr (code, ins->dreg, ins->sreg1);
3766 case OP_FCONV_TO_R4: {
3767 if (ins->dreg != ins->sreg1) {
3768 s390_ldr (code, ins->dreg, ins->sreg1);
3772 case OP_S390_SETF4RET: {
3773 s390_ledbr (code, ins->dreg, ins->sreg1);
3777 if (cfg->method->save_lmf)
3778 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
3780 if (cfg->flags & MONO_CFG_HAS_TAIL) {
3781 code = emit_load_volatile_arguments (code, cfg);
3784 code = backUpStackPtr(cfg, code);
3785 s390_lg (code, s390_r14, 0, STK_BASE, S390_RET_ADDR_OFFSET);
3786 mono_add_patch_info (cfg, code - cfg->native_code,
3787 MONO_PATCH_INFO_METHOD_JUMP,
3789 s390_jcl (code, S390_CC_UN, 0);
3792 case OP_CHECK_THIS: {
3793 /* ensure ins->sreg1 is not NULL */
3794 s390_lg (code, s390_r0, 0, ins->sreg1, 0);
3795 s390_ltgr (code, s390_r0, s390_r0);
3799 int offset = cfg->sig_cookie + cfg->stack_usage;
3801 if (s390_is_imm16 (offset))
3802 s390_lghi (code, s390_r0, offset);
3804 s390_basr (code, s390_r13, 0);
3806 s390_llong(code, offset);
3807 s390_lg (code, s390_r0, 0, s390_r13, 0);
3809 s390_agr (code, s390_r0, cfg->frame_reg);
3810 s390_stg (code, s390_r0, 0, ins->sreg1, 0);
3814 s390_basr (code, s390_r13, 0);
3816 call = (MonoCallInst*)ins;
3817 if (ins->flags & MONO_INST_HAS_METHOD)
3818 mono_add_patch_info (cfg, code-cfg->native_code,
3819 MONO_PATCH_INFO_METHOD,
3822 mono_add_patch_info (cfg, code-cfg->native_code,
3823 MONO_PATCH_INFO_ABS,
3825 s390_llong(code, 0);
3826 s390_lg (code, s390_r14, 0, s390_r13, 4);
3827 s390_basr (code, s390_r14, s390_r14);
3828 if (call->signature->ret->type == MONO_TYPE_R4)
3829 s390_ldebr (code, s390_f0, s390_f0);
3837 s390_basr (code, s390_r13, 0);
3839 call = (MonoCallInst*)ins;
3840 if (ins->flags & MONO_INST_HAS_METHOD)
3841 mono_add_patch_info (cfg, code-cfg->native_code,
3842 MONO_PATCH_INFO_METHOD,
3845 mono_add_patch_info (cfg, code-cfg->native_code,
3846 MONO_PATCH_INFO_ABS,
3848 s390_llong(code, 0);
3849 s390_lg (code, s390_r14, 0, s390_r13, 4);
3850 s390_basr (code, s390_r14, s390_r14);
3853 case OP_FCALL_REG: {
3854 call = (MonoCallInst*)ins;
3855 s390_lgr (code, s390_r1, ins->sreg1);
3856 s390_basr (code, s390_r14, s390_r1);
3857 if (call->signature->ret->type == MONO_TYPE_R4)
3858 s390_ldebr (code, s390_f0, s390_f0);
3864 case OP_VOIDCALL_REG:
3866 s390_lgr (code, s390_r1, ins->sreg1);
3867 s390_basr (code, s390_r14, s390_r1);
3870 case OP_FCALL_MEMBASE: {
3871 call = (MonoCallInst*)ins;
3872 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3873 s390_basr (code, s390_r14, s390_r1);
3874 if (call->signature->ret->type == MONO_TYPE_R4)
3875 s390_ldebr (code, s390_f0, s390_f0);
3878 case OP_LCALL_MEMBASE:
3879 case OP_VCALL_MEMBASE:
3880 case OP_VCALL2_MEMBASE:
3881 case OP_VOIDCALL_MEMBASE:
3882 case OP_CALL_MEMBASE: {
3883 s390_lg (code, s390_r1, 0, ins->sreg1, ins->inst_offset);
3884 s390_basr (code, s390_r14, s390_r1);
3888 int alloca_skip = S390_MINIMAL_STACK_SIZE + cfg->param_area;
3889 int area_offset = S390_ALIGN(alloca_skip, S390_STACK_ALIGNMENT);
3890 s390_lgr (code, s390_r1, ins->sreg1);
3891 if (ins->flags & MONO_INST_INIT)
3892 s390_lgr (code, s390_r0, ins->sreg1);
3893 s390_aghi (code, s390_r1, 14);
3894 s390_srlg (code, s390_r1, s390_r1, 0, 3);
3895 s390_sllg (code, s390_r1, s390_r1, 0, 3);
3896 if (cfg->method->save_lmf) {
3897 /*----------------------------------*/
3898 /* we have to adjust lmf ebp value */
3899 /*----------------------------------*/
3900 int lmfOffset = cfg->stack_usage - sizeof(MonoLMF);
3902 s390_lgr (code, s390_r13, cfg->frame_reg);
3903 if (s390_is_imm16(lmfOffset))
3904 s390_aghi (code, s390_r13, lmfOffset);
3906 s390_basr (code, s390_r14, 0);
3908 s390_word (code, lmfOffset);
3909 s390_agf (code, s390_r13, 0, s390_r14, 4);
3911 s390_lgr (code, s390_r14, STK_BASE);
3912 s390_sgr (code, s390_r14, s390_r1);
3913 s390_stg (code, s390_r14, 0, s390_r13,
3914 G_STRUCT_OFFSET(MonoLMF, ebp));
3916 s390_lg (code, s390_r13, 0, STK_BASE, 0);
3917 s390_sgr (code, STK_BASE, s390_r1);
3918 s390_stg (code, s390_r13, 0, STK_BASE, 0);
3919 s390_la (code, ins->dreg, 0, STK_BASE, area_offset);
3920 s390_srlg (code, ins->dreg, ins->dreg, 0, 3);
3921 s390_sllg (code, ins->dreg, ins->dreg, 0, 3);
3922 if (ins->flags & MONO_INST_INIT) {
3923 s390_lgr (code, s390_r1, s390_r0);
3924 s390_lgr (code, s390_r0, ins->dreg);
3925 s390_lgr (code, s390_r14, s390_r12);
3926 s390_lghi (code, s390_r13, 0);
3927 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
3929 s390_lgr (code, s390_r12, s390_r14);
3934 s390_lgr (code, s390_r2, ins->sreg1);
3935 s390_basr (code, s390_r13, 0);
3937 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3938 (gpointer) "mono_arch_throw_exception");
3939 s390_llong(code, 0);
3940 s390_lg (code, s390_r14, 0, s390_r13, 4);
3941 s390_basr (code, s390_r14, s390_r14);
3945 s390_lgr (code, s390_r2, ins->sreg1);
3946 s390_basr (code, s390_r13, 0);
3948 mono_add_patch_info (cfg, code-cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD,
3949 (gpointer) "mono_arch_rethrow_exception");
3950 s390_llong(code, 0);
3951 s390_lg (code, s390_r14, 0, s390_r13, 4);
3952 s390_basr (code, s390_r14, s390_r14);
3955 case OP_START_HANDLER: {
3956 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3958 S390_LONG (code, stg, stg, s390_r14, 0,
3959 spvar->inst_basereg,
3960 spvar->inst_offset);
3963 case OP_ENDFILTER: {
3964 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3966 if (ins->sreg1 != s390_r2)
3967 s390_lgr(code, s390_r2, ins->sreg1);
3968 S390_LONG (code, lg, lg, s390_r14, 0,
3969 spvar->inst_basereg,
3970 spvar->inst_offset);
3971 s390_br (code, s390_r14);
3974 case OP_ENDFINALLY: {
3975 MonoInst *spvar = mono_find_spvar_for_region (cfg, bb->region);
3977 S390_LONG (code, lg, lg, s390_r14, 0,
3978 spvar->inst_basereg,
3979 spvar->inst_offset);
3980 s390_br (code, s390_r14);
3983 case OP_CALL_HANDLER: {
3984 mono_add_patch_info (cfg, code-cfg->native_code,
3985 MONO_PATCH_INFO_BB, ins->inst_target_bb);
3986 s390_brasl (code, s390_r14, 0);
3990 ins->inst_c0 = code - cfg->native_code;
3993 case OP_RELAXED_NOP:
3996 case OP_DUMMY_STORE:
3997 case OP_NOT_REACHED:
4002 EMIT_UNCOND_BRANCH(ins);
4005 s390_br (code, ins->sreg1);
4011 s390_lghi(code, ins->dreg, 1);
4013 s390_lghi(code, ins->dreg, 0);
4019 s390_lghi(code, ins->dreg, 1);
4021 s390_lghi(code, ins->dreg, 0);
4027 s390_lghi(code, ins->dreg, 1);
4029 s390_lghi(code, ins->dreg, 0);
4035 s390_lghi(code, ins->dreg, 1);
4037 s390_lghi(code, ins->dreg, 0);
4043 s390_lghi(code, ins->dreg, 1);
4045 s390_lghi(code, ins->dreg, 0);
4048 case OP_COND_EXC_EQ:
4049 case OP_COND_EXC_IEQ:
4050 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_EQ, ins->inst_p1);
4052 case OP_COND_EXC_NE_UN:
4053 case OP_COND_EXC_INE_UN:
4054 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NE, ins->inst_p1);
4056 case OP_COND_EXC_LT:
4057 case OP_COND_EXC_ILT:
4058 case OP_COND_EXC_LT_UN:
4059 case OP_COND_EXC_ILT_UN:
4060 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LT, ins->inst_p1);
4062 case OP_COND_EXC_GT:
4063 case OP_COND_EXC_IGT:
4064 case OP_COND_EXC_GT_UN:
4065 case OP_COND_EXC_IGT_UN:
4066 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GT, ins->inst_p1);
4068 case OP_COND_EXC_GE:
4069 case OP_COND_EXC_IGE:
4070 case OP_COND_EXC_GE_UN:
4071 case OP_COND_EXC_IGE_UN:
4072 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_GE, ins->inst_p1);
4074 case OP_COND_EXC_LE:
4075 case OP_COND_EXC_ILE:
4076 case OP_COND_EXC_LE_UN:
4077 case OP_COND_EXC_ILE_UN:
4078 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_LE, ins->inst_p1);
4080 case OP_COND_EXC_OV:
4081 case OP_COND_EXC_IOV:
4082 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_OV, ins->inst_p1);
4084 case OP_COND_EXC_NO:
4085 case OP_COND_EXC_INO:
4086 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NO, ins->inst_p1);
4089 case OP_COND_EXC_IC:
4090 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_CY, ins->inst_p1);
4092 case OP_COND_EXC_NC:
4093 case OP_COND_EXC_INC:
4094 EMIT_COND_SYSTEM_EXCEPTION (S390_CC_NC, ins->inst_p1);
4098 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4102 EMIT_COND_BRANCH (ins, S390_CC_NE);
4108 EMIT_COND_BRANCH (ins, S390_CC_LT);
4114 EMIT_COND_BRANCH (ins, S390_CC_GT);
4120 EMIT_COND_BRANCH (ins, S390_CC_GE);
4126 EMIT_COND_BRANCH (ins, S390_CC_LE);
4129 /* floating point opcodes */
4131 if (*((float *) ins->inst_p0) == 0) {
4132 s390_lzdr (code, ins->dreg);
4134 s390_basr (code, s390_r13, 0);
4136 s390_llong (code, ins->inst_p0);
4137 s390_lg (code, s390_r13, 0, s390_r13, 4);
4138 s390_ld (code, ins->dreg, 0, s390_r13, 0);
4143 if (*((float *) ins->inst_p0) == 0) {
4144 s390_lzdr (code, ins->dreg);
4146 s390_basr (code, s390_r13, 0);
4148 s390_llong(code, ins->inst_p0);
4149 s390_lg (code, s390_r13, 0, s390_r13, 4);
4150 s390_ldeb (code, ins->dreg, 0, s390_r13, 0);
4154 case OP_STORER8_MEMBASE_REG: {
4155 S390_LONG (code, stdy, std, ins->sreg1, 0,
4156 ins->inst_destbasereg, ins->inst_offset);
4159 case OP_LOADR8_MEMBASE: {
4160 S390_LONG (code, ldy, ld, ins->dreg, 0,
4161 ins->inst_basereg, ins->inst_offset);
4164 case OP_STORER4_MEMBASE_REG: {
4165 s390_ledbr (code, s390_f15, ins->sreg1);
4166 S390_LONG (code, stey, ste, s390_f15, 0,
4167 ins->inst_destbasereg, ins->inst_offset);
4170 case OP_LOADR4_MEMBASE: {
4171 S390_LONG (code, ldy, ld, s390_f15, 0,
4172 ins->inst_basereg, ins->inst_offset);
4173 s390_ldebr (code, ins->dreg, s390_f15);
4176 case OP_ICONV_TO_R_UN: {
4177 s390_cdfbr (code, ins->dreg, ins->sreg1);
4178 s390_ltr (code, ins->sreg1, ins->sreg1);
4179 s390_jnl (code, 12);
4180 s390_basr (code, s390_r13, 0);
4182 s390_word (code, 0x41f00000);
4183 s390_word (code, 0);
4184 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4187 case OP_LCONV_TO_R_UN: {
4188 s390_cdgbr (code, ins->dreg, ins->sreg1);
4189 s390_ltgr (code, ins->sreg1, ins->sreg1);
4190 s390_jnl (code, 12);
4191 s390_basr (code, s390_r13, 0);
4193 s390_word (code, 0x41f00000);
4194 s390_word (code, 0);
4195 s390_adb (code, ins->dreg, 0, s390_r13, 4);
4198 case OP_LCONV_TO_R4:
4199 case OP_ICONV_TO_R4: {
4200 s390_cdgbr (code, ins->dreg, ins->sreg1);
4203 case OP_LCONV_TO_R8:
4204 case OP_ICONV_TO_R8: {
4205 s390_cdgbr (code, ins->dreg, ins->sreg1);
4208 case OP_FCONV_TO_I1:
4209 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE);
4211 case OP_FCONV_TO_U1:
4212 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE);
4214 case OP_FCONV_TO_I2:
4215 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE);
4217 case OP_FCONV_TO_U2:
4218 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE);
4220 case OP_FCONV_TO_I4:
4222 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE);
4224 case OP_FCONV_TO_U4:
4226 code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE);
4228 case OP_FCONV_TO_I8:
4229 s390_cgdbr (code, ins->dreg, 5, ins->sreg1);
4231 case OP_LCONV_TO_OVF_I: {
4232 /* Valid ints: 0xffffffff:8000000 to 00000000:0x7f000000 */
4234 s390_ltgr (code, ins->sreg2, ins->sreg2);
4235 s390_jnl (code, 0); CODEPTR(code, o[0]);
4236 s390_ltgr (code, ins->sreg1, ins->sreg1);
4237 s390_jnl (code, 0); CODEPTR(code, o[1]);
4238 s390_lhi (code, s390_r13, -1);
4239 s390_cgr (code, ins->sreg1, s390_r13);
4240 s390_jnz (code, 0); CODEPTR(code, o[2]);
4241 if (ins->dreg != ins->sreg2)
4242 s390_lgr (code, ins->dreg, ins->sreg2);
4243 s390_j (code, 0); CODEPTR(code, o[3]);
4244 PTRSLOT(code, o[0]);
4245 s390_jz (code, 0); CODEPTR(code, o[4]);
4246 PTRSLOT(code, o[1]);
4247 PTRSLOT(code, o[2]);
4248 mono_add_patch_info (cfg, code - cfg->native_code,
4249 MONO_PATCH_INFO_EXC, "OverflowException");
4250 s390_brasl (code, s390_r14, 0);
4251 PTRSLOT(code, o[3]);
4252 PTRSLOT(code, o[4]);
4256 s390_lpdbr (code, ins->dreg, ins->sreg1);
4260 s390_sqdbr (code, ins->dreg, ins->sreg1);
4265 s390_adbr (code, ins->dreg, src2);
4269 CHECK_SRCDST_NCOM_F;
4270 s390_sdbr (code, ins->dreg, src2);
4275 s390_mdbr (code, ins->dreg, src2);
4279 CHECK_SRCDST_NCOM_F;
4280 s390_ddbr (code, ins->dreg, src2);
4284 s390_lcdbr (code, ins->dreg, ins->sreg1);
4288 CHECK_SRCDST_NCOM_F;
4289 s390_didbr (code, ins->dreg, src2, 5, s390_f15);
4293 s390_cdbr (code, ins->sreg1, ins->sreg2);
4297 s390_cdbr (code, ins->sreg1, ins->sreg2);
4298 s390_lghi (code, ins->dreg, 1);
4300 s390_lghi (code, ins->dreg, 0);
4304 s390_cdbr (code, ins->sreg1, ins->sreg2);
4305 s390_lghi (code, ins->dreg, 1);
4307 s390_lghi (code, ins->dreg, 0);
4311 s390_cdbr (code, ins->sreg1, ins->sreg2);
4312 s390_lghi (code, ins->dreg, 1);
4314 s390_lghi (code, ins->dreg, 0);
4318 s390_cdbr (code, ins->sreg1, ins->sreg2);
4319 s390_lghi (code, ins->dreg, 1);
4321 s390_lghi (code, ins->dreg, 0);
4325 s390_cdbr (code, ins->sreg1, ins->sreg2);
4326 s390_lghi (code, ins->dreg, 1);
4328 s390_lghi (code, ins->dreg, 0);
4333 s390_jo (code, 0); CODEPTR(code, o);
4334 EMIT_COND_BRANCH (ins, S390_CC_EQ);
4339 EMIT_COND_BRANCH (ins, S390_CC_NE|S390_CC_OV);
4343 s390_jo (code, 0); CODEPTR(code, o);
4344 EMIT_COND_BRANCH (ins, S390_CC_LT);
4349 EMIT_COND_BRANCH (ins, S390_CC_LT|S390_CC_OV);
4353 s390_jo (code, 0); CODEPTR(code, o);
4354 EMIT_COND_BRANCH (ins, S390_CC_GT);
4359 EMIT_COND_BRANCH (ins, S390_CC_GT|S390_CC_OV);
4363 s390_jo (code, 0); CODEPTR(code, o);
4364 EMIT_COND_BRANCH (ins, S390_CC_GE);
4369 EMIT_COND_BRANCH (ins, S390_CC_GE|S390_CC_OV);
4373 s390_jo (code, 0); CODEPTR(code, o);
4374 EMIT_COND_BRANCH (ins, S390_CC_LE);
4379 EMIT_COND_BRANCH (ins, S390_CC_LE|S390_CC_OV);
4383 s390_lhi (code, s390_r13, 0x7f);
4384 s390_tcdb (code, ins->sreg1, 0, s390_r13, 0);
4385 s390_jz (code, 0); CODEPTR(code, o);
4386 mono_add_patch_info (cfg, code - cfg->native_code,
4387 MONO_PATCH_INFO_EXC, "ArithmeticException");
4388 s390_brasl (code, s390_r14,0);
4392 case OP_S390_MOVE: {
4393 if (ins->backend.size > 0) {
4394 if (ins->backend.size <= 256) {
4395 s390_mvc (code, ins->backend.size, ins->dreg,
4396 ins->inst_offset, ins->sreg1, ins->inst_imm);
4398 s390_lgr (code, s390_r0, ins->dreg);
4399 if (s390_is_imm16 (ins->inst_offset)) {
4400 s390_aghi (code, s390_r0, ins->inst_offset);
4402 s390_basr (code, s390_r13, 0);
4404 s390_llong(code, ins->inst_offset);
4405 s390_a (code, s390_r0, 0, s390_r13, 4);
4407 s390_lgr (code, s390_r12, ins->sreg1);
4408 if (s390_is_imm16 (ins->inst_imm)) {
4409 s390_aghi (code, s390_r12, ins->inst_imm);
4411 s390_basr (code, s390_r13, 0);
4413 s390_llong(code, ins->inst_imm);
4414 s390_ag (code, s390_r12, 0, s390_r13, 4);
4416 s390_lgr (code, s390_r1, ins->sreg1);
4417 s390_lgr (code, s390_r13, s390_r1);
4418 s390_mvcle(code, s390_r0, s390_r12, 0, 0);
4424 case OP_ATOMIC_ADD_I8: {
4425 s390_lgr (code, s390_r1, ins->sreg2);
4426 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4427 s390_agr (code, s390_r1, s390_r0);
4428 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4429 s390_jnz (code, -10);
4430 s390_lgr (code, ins->dreg, s390_r1);
4433 case OP_ATOMIC_ADD_NEW_I8: {
4434 s390_lgr (code, s390_r1, ins->sreg2);
4435 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4436 s390_agr (code, s390_r1, s390_r0);
4437 s390_csg (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4438 s390_jnz (code, -10);
4439 s390_lgr (code, ins->dreg, s390_r1);
4442 case OP_ATOMIC_EXCHANGE_I8: {
4443 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4444 s390_csg (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4445 s390_jnz (code, -6);
4446 s390_lgr (code, ins->dreg, s390_r0);
4449 case OP_ATOMIC_ADD_I4: {
4450 s390_lgfr(code, s390_r1, ins->sreg2);
4451 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4452 s390_agr (code, s390_r1, s390_r0);
4453 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4454 s390_jnz (code, -9);
4455 s390_lgfr(code, ins->dreg, s390_r1);
4458 case OP_ATOMIC_ADD_NEW_I4: {
4459 s390_lgfr(code, s390_r1, ins->sreg2);
4460 s390_lgf (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4461 s390_agr (code, s390_r1, s390_r0);
4462 s390_cs (code, s390_r0, s390_r1, ins->inst_basereg, ins->inst_offset);
4463 s390_jnz (code, -9);
4464 s390_lgfr(code, ins->dreg, s390_r1);
4467 case OP_ATOMIC_EXCHANGE_I4: {
4468 s390_lg (code, s390_r0, 0, ins->inst_basereg, ins->inst_offset);
4469 s390_cs (code, s390_r0, ins->sreg2, ins->inst_basereg, ins->inst_offset);
4470 s390_jnz (code, -4);
4471 s390_lgfr(code, ins->dreg, s390_r0);
4474 case OP_S390_BKCHAIN: {
4475 s390_lgr (code, ins->dreg, ins->sreg1);
4476 if (s390_is_imm16 (cfg->stack_offset)) {
4477 s390_aghi (code, ins->dreg, cfg->stack_offset);
4479 s390_basr (code, s390_r13, 0);
4481 s390_llong(code, cfg->stack_offset);
4482 s390_ag (code, ins->dreg, 0, s390_r13, 4);
4486 case OP_MEMORY_BARRIER: {
4490 g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4491 g_assert_not_reached ();
4494 if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4495 g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4496 mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
4497 g_assert_not_reached ();
4502 last_offset = offset;
4505 cfg->code_len = code - cfg->native_code;
4508 /*========================= End of Function ========================*/
4510 /*------------------------------------------------------------------*/
4512 /* Name - mono_arch_register_lowlevel_calls */
4514 /* Function - Register routines to help with --trace operation. */
4516 /*------------------------------------------------------------------*/
4519 mono_arch_register_lowlevel_calls (void)
4521 mono_register_jit_icall (mono_arch_get_lmf_addr, "mono_arch_get_lmf_addr", NULL, TRUE);
4524 /*========================= End of Function ========================*/
4526 /*------------------------------------------------------------------*/
4528 /* Name - mono_arch_patch_code */
4530 /* Function - Process the patch data created during the */
4531 /* instruction build process. This resolves jumps, */
4532 /* calls, variables etc. */
4534 /*------------------------------------------------------------------*/
4537 mono_arch_patch_code (MonoMethod *method, MonoDomain *domain,
4538 guint8 *code, MonoJumpInfo *ji, gboolean run_cctors)
4540 MonoJumpInfo *patch_info;
4542 for (patch_info = ji; patch_info; patch_info = patch_info->next) {
4543 unsigned char *ip = patch_info->ip.i + code;
4544 gconstpointer target = NULL;
4546 target = mono_resolve_patch_target (method, domain, code,
4547 patch_info, run_cctors);
4549 switch (patch_info->type) {
4550 case MONO_PATCH_INFO_IP:
4551 case MONO_PATCH_INFO_EXC_NAME:
4552 case MONO_PATCH_INFO_LDSTR:
4553 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
4554 case MONO_PATCH_INFO_LDTOKEN:
4555 case MONO_PATCH_INFO_EXC:
4556 case MONO_PATCH_INFO_ABS:
4557 case MONO_PATCH_INFO_METHOD:
4558 case MONO_PATCH_INFO_INTERNAL_METHOD:
4559 case MONO_PATCH_INFO_CLASS_INIT:
4560 s390_patch_addr (ip, (guint64) target);
4562 case MONO_PATCH_INFO_SWITCH:
4563 /*----------------------------------*/
4564 /* ip points at the basr r13,0/j +4 */
4565 /* instruction the vtable value */
4566 /* follows this (i.e. ip+6) */
4567 /*----------------------------------*/
4568 *((gconstpointer *)(ip+6)) = target;
4570 case MONO_PATCH_INFO_METHODCONST:
4571 case MONO_PATCH_INFO_CLASS:
4572 case MONO_PATCH_INFO_IMAGE:
4573 case MONO_PATCH_INFO_FIELD:
4574 case MONO_PATCH_INFO_IID:
4575 target = S390_RELATIVE(target, ip);
4576 s390_patch_rel (ip, (guint64) target);
4578 case MONO_PATCH_INFO_R4:
4579 case MONO_PATCH_INFO_R8:
4580 case MONO_PATCH_INFO_METHOD_REL:
4581 g_assert_not_reached ();
4584 target = S390_RELATIVE(target, ip);
4586 s390_patch_rel (ip, (guint64) target);
4591 /*========================= End of Function ========================*/
4593 /*------------------------------------------------------------------*/
4595 /* Name - emit_load_volatile_arguments */
4597 /* Function - Emit the instructions to reload parameter regist- */
4598 /* registers for use with "tail" operations. */
4600 /* The register loading operations performed here */
4601 /* are the mirror of the store operations performed */
4602 /* in mono_arch_emit_prolog and need to be kept in */
4603 /* synchronization with it. */
4605 /*------------------------------------------------------------------*/
4608 emit_load_volatile_arguments (guint8 *code, MonoCompile *cfg)
4611 MonoMethod *method = cfg->method;
4612 MonoMethodSignature *sig = mono_method_signature(method);
4616 cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
4618 if (cinfo->struct_ret) {
4619 ArgInfo *ainfo = &cinfo->ret;
4620 inst = cfg->vret_addr;
4621 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4624 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4625 ArgInfo *ainfo = cinfo->args + i;
4626 inst = cfg->args [pos];
4628 if (inst->opcode == OP_REGVAR) {
4629 if (ainfo->regtype == RegTypeGeneral)
4630 s390_lgr (code, ainfo->reg, inst->dreg);
4631 else if (ainfo->regtype == RegTypeFP) {
4632 if (inst->dreg != ainfo->reg) {
4633 if (ainfo->size == 4) {
4634 s390_ldebr (code, ainfo->reg, inst->dreg);
4636 s390_ldr (code, ainfo->reg, inst->dreg);
4640 else if (ainfo->regtype == RegTypeBase) {
4642 g_assert_not_reached ();
4644 if (ainfo->regtype == RegTypeGeneral) {
4645 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4646 g_assert_not_reached();
4647 switch (ainfo->size) {
4649 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4652 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4655 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4658 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4661 } else if (ainfo->regtype == RegTypeBase) {
4662 } else if (ainfo->regtype == RegTypeFP) {
4663 if (ainfo->size == 8)
4664 s390_ld (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4665 else if (ainfo->size == 4)
4666 s390_le (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4668 g_assert_not_reached ();
4669 } else if (ainfo->regtype == RegTypeStructByVal) {
4670 if (ainfo->reg != STK_BASE) {
4671 switch (ainfo->size) {
4673 s390_llgc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4676 s390_lgh (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4679 s390_lgf (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4682 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4686 } else if (ainfo->regtype == RegTypeStructByAddr) {
4687 if (ainfo->reg != STK_BASE) {
4688 s390_lg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4691 g_assert_not_reached ();
4699 /*========================= End of Function ========================*/
4701 /*------------------------------------------------------------------*/
4703 /* Name - mono_arch_emit_prolog */
4705 /* Function - Create the instruction sequence for a function */
4708 /*------------------------------------------------------------------*/
4711 mono_arch_emit_prolog (MonoCompile *cfg)
4713 MonoMethod *method = cfg->method;
4715 MonoMethodSignature *sig;
4717 int alloc_size, pos, max_offset, i;
4723 cfg->code_size = 512;
4725 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
4727 cfg->code_size += 256;
4730 if (method->save_lmf)
4731 cfg->code_size += 200;
4733 cfg->native_code = code = g_malloc (cfg->code_size);
4735 s390_stmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
4737 if (cfg->arch.bkchain_reg != -1)
4738 s390_lgr (code, cfg->arch.bkchain_reg, STK_BASE);
4740 if (cfg->flags & MONO_CFG_HAS_ALLOCA) {
4741 cfg->used_int_regs |= 1 << 11;
4744 alloc_size = cfg->stack_offset;
4746 cfg->stack_usage = alloc_size;
4747 s390_lgr (code, s390_r11, STK_BASE);
4748 if (s390_is_imm16 (alloc_size)) {
4749 s390_aghi (code, STK_BASE, -alloc_size);
4751 int stackSize = alloc_size;
4752 while (stackSize > 32767) {
4753 s390_aghi (code, STK_BASE, -32767);
4756 s390_aghi (code, STK_BASE, -stackSize);
4758 s390_stg (code, s390_r11, 0, STK_BASE, 0);
4760 if (cfg->frame_reg != STK_BASE)
4761 s390_lgr (code, s390_r11, STK_BASE);
4763 /* compute max_offset in order to use short forward jumps
4764 * we always do it on s390 because the immediate displacement
4765 * for jumps is too small
4768 for (bb = cfg->bb_entry; bb; bb = bb->next_bb) {
4770 bb->max_offset = max_offset;
4772 if (cfg->prof_options & MONO_PROFILE_COVERAGE)
4775 MONO_BB_FOR_EACH_INS (bb, ins)
4776 max_offset += ((guint8 *)ins_get_spec (ins->opcode))[MONO_INST_LEN];
4779 /* load arguments allocated to register from the stack */
4780 sig = mono_method_signature (method);
4783 cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
4785 if (cinfo->struct_ret) {
4786 ArgInfo *ainfo = &cinfo->ret;
4787 inst = cfg->vret_addr;
4788 inst->backend.size = ainfo->vtsize;
4789 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4792 for (i = 0; i < sig->param_count + sig->hasthis; ++i) {
4793 ArgInfo *ainfo = cinfo->args + i;
4794 inst = cfg->args [pos];
4796 if (inst->opcode == OP_VTARG_ADDR)
4797 inst = inst->inst_left;
4799 if (inst->opcode == OP_REGVAR) {
4800 if (ainfo->regtype == RegTypeGeneral)
4801 s390_lgr (code, inst->dreg, ainfo->reg);
4802 else if (ainfo->regtype == RegTypeFP) {
4803 if (inst->dreg != ainfo->reg) {
4804 if (ainfo->size == 4) {
4805 s390_ledbr (code, inst->dreg, ainfo->reg);
4807 s390_ldr (code, inst->dreg, ainfo->reg);
4811 else if (ainfo->regtype == RegTypeBase) {
4812 s390_lgr (code, s390_r13, STK_BASE);
4813 s390_aghi (code, s390_r13, alloc_size);
4814 s390_lg (code, inst->dreg, 0, s390_r13, ainfo->offset);
4816 g_assert_not_reached ();
4818 if (cfg->verbose_level > 2)
4819 g_print ("Argument %d assigned to register %s\n",
4820 pos, mono_arch_regname (inst->dreg));
4822 if (ainfo->regtype == RegTypeGeneral) {
4823 if (!((ainfo->reg >= 2) && (ainfo->reg <= 6)))
4824 g_assert_not_reached();
4825 switch (ainfo->size) {
4827 s390_stc (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4830 s390_sth (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4833 s390_st (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4836 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4839 } else if (ainfo->regtype == RegTypeBase) {
4840 } else if (ainfo->regtype == RegTypeFP) {
4841 if (ainfo->size == 8)
4842 s390_std (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4843 else if (ainfo->size == 4)
4844 s390_ste (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4846 g_assert_not_reached ();
4847 } else if (ainfo->regtype == RegTypeStructByVal) {
4848 int doffset = inst->inst_offset;
4850 if (ainfo->reg != STK_BASE)
4854 s390_lgr (code, s390_r13, STK_BASE);
4855 s390_aghi (code, s390_r13, alloc_size);
4857 switch (ainfo->size) {
4859 if (ainfo->reg == STK_BASE)
4860 s390_ic (code, reg, 0, s390_r13, ainfo->offset+7);
4861 s390_stc (code, reg, 0, inst->inst_basereg, doffset);
4864 if (ainfo->reg == STK_BASE)
4865 s390_lh (code, reg, 0, s390_r13, ainfo->offset+6);
4866 s390_sth (code, reg, 0, inst->inst_basereg, doffset);
4869 if (ainfo->reg == STK_BASE)
4870 s390_l (code, reg, 0, s390_r13, ainfo->offset+4);
4871 s390_st (code, reg, 0, inst->inst_basereg, doffset);
4874 if (ainfo->reg == STK_BASE)
4875 s390_lg (code, reg, 0, s390_r13, ainfo->offset);
4876 s390_stg (code, reg, 0, inst->inst_basereg, doffset);
4879 } else if (ainfo->regtype == RegTypeStructByAddr) {
4880 s390_stg (code, ainfo->reg, 0, inst->inst_basereg, inst->inst_offset);
4881 } else if (ainfo->regtype == RegTypeStructByAddrOnStack) {
4883 g_assert_not_reached ();
4888 if (method->save_lmf) {
4889 /*---------------------------------------------------------------*/
4890 /* we build the MonoLMF structure on the stack - see mini-s390.h */
4891 /*---------------------------------------------------------------*/
4892 lmfOffset = alloc_size - sizeof(MonoLMF);
4894 s390_lgr (code, s390_r13, cfg->frame_reg);
4895 s390_aghi (code, s390_r13, lmfOffset);
4897 /*---------------------------------------------------------------*/
4898 /* Preserve the parameter registers while we fix up the lmf */
4899 /*---------------------------------------------------------------*/
4900 s390_stmg (code, s390_r2, s390_r6, s390_r13,
4901 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4903 /*---------------------------------------------------------------*/
4904 /* On return from this call r2 have the address of the &lmf */
4905 /*---------------------------------------------------------------*/
4906 s390_basr(code, s390_r10, 0);
4908 mono_add_patch_info (cfg, code - cfg->native_code,
4909 MONO_PATCH_INFO_INTERNAL_METHOD,
4910 (gpointer)"mono_get_lmf_addr");
4911 s390_llong(code, 0);
4912 s390_lg (code, s390_r1, 0, s390_r10, 4);
4913 s390_basr (code, s390_r14, s390_r1);
4915 /*---------------------------------------------------------------*/
4916 /* Set lmf.lmf_addr = jit_tls->lmf */
4917 /*---------------------------------------------------------------*/
4918 s390_stg (code, s390_r2, 0, s390_r13,
4919 G_STRUCT_OFFSET(MonoLMF, lmf_addr));
4921 /*---------------------------------------------------------------*/
4922 /* Get current lmf */
4923 /*---------------------------------------------------------------*/
4924 s390_lg (code, s390_r0, 0, s390_r2, 0);
4926 /*---------------------------------------------------------------*/
4927 /* Set our lmf as the current lmf */
4928 /*---------------------------------------------------------------*/
4929 s390_stg (code, s390_r13, 0, s390_r2, 0);
4931 /*---------------------------------------------------------------*/
4932 /* Have our lmf.previous_lmf point to the last lmf */
4933 /*---------------------------------------------------------------*/
4934 s390_stg (code, s390_r0, 0, s390_r13,
4935 G_STRUCT_OFFSET(MonoLMF, previous_lmf));
4937 /*---------------------------------------------------------------*/
4938 /* save method info */
4939 /*---------------------------------------------------------------*/
4940 s390_basr (code, s390_r1, 0);
4942 s390_llong (code, method);
4943 s390_lg (code, s390_r1, 0, s390_r1, 4);
4944 s390_stg (code, s390_r1, 0, s390_r13,
4945 G_STRUCT_OFFSET(MonoLMF, method));
4947 /*---------------------------------------------------------------*/
4948 /* save the current IP */
4949 /*---------------------------------------------------------------*/
4950 s390_stg (code, STK_BASE, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, ebp));
4951 s390_basr (code, s390_r1, 0);
4952 s390_stg (code, s390_r1, 0, s390_r13, G_STRUCT_OFFSET(MonoLMF, eip));
4954 /*---------------------------------------------------------------*/
4955 /* Save general and floating point registers */
4956 /*---------------------------------------------------------------*/
4957 s390_stmg (code, s390_r2, s390_r12, s390_r13,
4958 G_STRUCT_OFFSET(MonoLMF, gregs[2]));
4959 for (i = 0; i < 16; i++) {
4960 s390_std (code, i, 0, s390_r13,
4961 G_STRUCT_OFFSET(MonoLMF, fregs[i]));
4964 /*---------------------------------------------------------------*/
4965 /* Restore the parameter registers now that we've set up the lmf */
4966 /*---------------------------------------------------------------*/
4967 s390_lmg (code, s390_r2, s390_r6, s390_r13,
4968 G_STRUCT_OFFSET(MonoLMF, pregs[0]));
4972 code = mono_arch_instrument_prolog(cfg, enter_method, code, TRUE);
4974 cfg->code_len = code - cfg->native_code;
4975 g_assert (cfg->code_len < cfg->code_size);
4980 /*========================= End of Function ========================*/
4982 /*------------------------------------------------------------------*/
4984 /* Name - mono_arch_emit_epilog */
4986 /* Function - Emit the instructions for a function epilog. */
4988 /*------------------------------------------------------------------*/
4991 mono_arch_emit_epilog (MonoCompile *cfg)
4993 MonoMethod *method = cfg->method;
4996 int max_epilog_size = 96;
4998 if (cfg->method->save_lmf)
4999 max_epilog_size += 128;
5001 if (mono_jit_trace_calls != NULL)
5002 max_epilog_size += 128;
5004 if (cfg->prof_options & MONO_PROFILE_ENTER_LEAVE)
5005 max_epilog_size += 128;
5007 while ((cfg->code_len + max_epilog_size) > (cfg->code_size - 16)) {
5008 cfg->code_size *= 2;
5009 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5010 mono_jit_stats.code_reallocs++;
5013 code = cfg->native_code + cfg->code_len;
5015 if (mono_jit_trace_calls != NULL && mono_trace_eval (method)) {
5016 code = mono_arch_instrument_epilog (cfg, leave_method, code, TRUE);
5020 if (method->save_lmf)
5021 restoreLMF(code, cfg->frame_reg, cfg->stack_usage);
5023 if (cfg->flags & MONO_CFG_HAS_ALLOCA)
5024 s390_lg (code, STK_BASE, 0, STK_BASE, 0);
5026 code = backUpStackPtr(cfg, code);
5028 s390_lmg (code, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
5029 s390_br (code, s390_r14);
5031 cfg->code_len = code - cfg->native_code;
5033 g_assert (cfg->code_len < cfg->code_size);
5037 /*========================= End of Function ========================*/
5039 /*------------------------------------------------------------------*/
5041 /* Name - mono_arch_emit_exceptions */
5043 /* Function - Emit the blocks to handle exception conditions. */
5045 /*------------------------------------------------------------------*/
5048 mono_arch_emit_exceptions (MonoCompile *cfg)
5050 MonoJumpInfo *patch_info;
5056 MonoClass *exc_classes [MAX_EXC];
5057 guint8 *exc_throw_start [MAX_EXC];
5059 for (patch_info = cfg->patch_info;
5061 patch_info = patch_info->next) {
5062 if (patch_info->type == MONO_PATCH_INFO_EXC)
5066 code_size = exc_count * 48;
5068 while ((cfg->code_len + code_size) > (cfg->code_size - 16)) {
5069 cfg->code_size *= 2;
5070 cfg->native_code = g_realloc (cfg->native_code, cfg->code_size);
5071 mono_jit_stats.code_reallocs++;
5074 code = cfg->native_code + cfg->code_len;
5076 /*---------------------------------------------------------------------*/
5077 /* Add code to raise exceptions */
5078 /*---------------------------------------------------------------------*/
5079 for (patch_info = cfg->patch_info; patch_info; patch_info = patch_info->next) {
5080 switch (patch_info->type) {
5081 case MONO_PATCH_INFO_EXC: {
5082 guint8 *ip = patch_info->ip.i + cfg->native_code;
5083 MonoClass *exc_class;
5086 /*-----------------------------------------------------*/
5087 /* Patch the branch in epilog to come here */
5088 /*-----------------------------------------------------*/
5089 s390_patch_rel (ip + 2, (guint64) S390_RELATIVE(code,ip));
5091 exc_class = mono_class_from_name (mono_defaults.corlib,
5093 patch_info->data.name);
5094 g_assert (exc_class);
5095 throw_ip = patch_info->ip.i;
5097 for (iExc = 0; iExc < nThrows; ++iExc)
5098 if (exc_classes [iExc] == exc_class)
5101 if (iExc < nThrows) {
5102 s390_jcl (code, S390_CC_UN,
5103 (guint64) exc_throw_start [iExc]);
5104 patch_info->type = MONO_PATCH_INFO_NONE;
5107 if (nThrows < MAX_EXC) {
5108 exc_classes [nThrows] = exc_class;
5109 exc_throw_start [nThrows] = code;
5112 /*---------------------------------------------*/
5113 /* Patch the parameter passed to the handler */
5114 /*---------------------------------------------*/
5115 s390_basr (code, s390_r13, 0);
5117 s390_llong(code, patch_info->data.target);
5118 /*---------------------------------------------*/
5119 /* Load return address & parameter register */
5120 /*---------------------------------------------*/
5121 s390_larl (code, s390_r14, (guint64)S390_RELATIVE((patch_info->ip.i +
5122 cfg->native_code + 8), code));
5123 s390_lg (code, s390_r2, 0, s390_r13, 4);
5124 /*---------------------------------------------*/
5125 /* Reuse the current patch to set the jump */
5126 /*---------------------------------------------*/
5127 s390_basr (code, s390_r13, 0);
5129 patch_info->type = MONO_PATCH_INFO_INTERNAL_METHOD;
5130 patch_info->data.name = "mono_arch_throw_exception_by_name";
5131 patch_info->ip.i = code - cfg->native_code;
5132 s390_llong(code, 0);
5133 s390_lg (code, s390_r1, 0, s390_r13, 4);
5134 s390_br (code, s390_r1);
5144 cfg->code_len = code - cfg->native_code;
5146 g_assert (cfg->code_len < cfg->code_size);
5150 /*========================= End of Function ========================*/
5152 /*------------------------------------------------------------------*/
5154 /* Name - mono_arch_setup_jit_tls_data */
5156 /* Function - Setup the JIT's Thread Level Specific Data. */
5158 /*------------------------------------------------------------------*/
5161 mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
5163 if (!tls_offset_inited) {
5164 tls_offset_inited = TRUE;
5168 __asm__ ("\tear\t%r1,0\n"
5175 : "=r" (appdomain_tls_offset),
5176 "=r" (thread_tls_offset),
5177 "=r" (lmf_tls_offset)
5178 : "r" (&tls_appdomain),
5179 "r" (&tls_current_object),
5180 "r" (&mono_lmf_addr)
5186 if (!lmf_addr_key_inited) {
5187 lmf_addr_key_inited = TRUE;
5188 pthread_key_create (&lmf_addr_key, NULL);
5190 pthread_setspecific (lmf_addr_key, &tls->lmf);
5194 /*========================= End of Function ========================*/
5196 /*------------------------------------------------------------------*/
5198 /* Name - mono_arch_free_jit_tls_data */
5200 /* Function - Free tls data. */
5202 /*------------------------------------------------------------------*/
5205 mono_arch_free_jit_tls_data (MonoJitTlsData *tls)
5209 /*========================= End of Function ========================*/
5211 /*------------------------------------------------------------------*/
5213 /* Name - mono_arch_emit_inst_for_method */
5215 /*------------------------------------------------------------------*/
5218 mono_arch_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsig, MonoInst **args)
5223 /*========================= End of Function ========================*/
5225 /*------------------------------------------------------------------*/
5227 /* Name - mono_arch_decompose_opts */
5229 /* Function - Decompose opcode into a System z opcode. */
5231 /*------------------------------------------------------------------*/
5234 mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
5237 * Have to rename these to avoid being decomposed normally, since the normal
5238 * decomposition does not work on S390.
5240 switch (ins->opcode) {
5242 ins->opcode = OP_S390_ISUB_OVF;
5244 case OP_ISUB_OVF_UN:
5245 ins->opcode = OP_S390_ISUB_OVF_UN;
5248 ins->opcode = OP_S390_IADD_OVF;
5250 case OP_IADD_OVF_UN:
5251 ins->opcode = OP_S390_IADD_OVF_UN;
5254 ins->opcode = OP_S390_LADD_OVF;
5256 case OP_LADD_OVF_UN:
5257 ins->opcode = OP_S390_LADD_OVF_UN;
5260 ins->opcode = OP_S390_LSUB_OVF;
5262 case OP_LSUB_OVF_UN:
5263 ins->opcode = OP_S390_LSUB_OVF_UN;
5270 /*========================= End of Function ========================*/
5272 /*------------------------------------------------------------------*/
5274 /* Name - mono_arch_print_tree */
5276 /* Function - Print platform-specific opcode details. */
5278 /* Returns - 1 - opcode details have been printed */
5279 /* 0 - opcode details have not been printed */
5281 /*------------------------------------------------------------------*/
5284 mono_arch_print_tree (MonoInst *tree, int arity)
5288 switch (tree->opcode) {
5289 case OP_S390_LOADARG:
5290 case OP_S390_ARGREG:
5291 case OP_S390_ARGPTR:
5292 printf ("[0x%lx(%s)]", tree->inst_offset,
5293 mono_arch_regname (tree->inst_basereg));
5296 case OP_S390_STKARG:
5297 printf ("[0x%lx(previous_frame)]",
5302 printf ("[0x%lx(%d,%s),0x%lx(%s)]",
5303 tree->inst_offset, tree->backend.size,
5304 mono_arch_regname(tree->dreg),
5306 mono_arch_regname(tree->sreg1));
5309 case OP_S390_SETF4RET:
5310 printf ("[f%s,f%s]",
5311 mono_arch_regname (tree->dreg),
5312 mono_arch_regname (tree->sreg1));
5316 printf ("[0x%lx(0x%lx,%s)]", tree->inst_offset,
5318 mono_arch_regname (tree->sreg1));
5321 case OP_S390_BKCHAIN:
5322 printf ("[previous_frame(%s)]",
5323 mono_arch_regname (tree->sreg1));
5331 /*========================= End of Function ========================*/
5333 /*------------------------------------------------------------------*/
5335 /* Name - mono_arch_regalloc_cost */
5337 /* Function - Determine the cost, in the number of memory */
5338 /* references, of the action of allocating the var- */
5339 /* iable VMV into a register during global register */
5342 /* Returns - Cost */
5344 /*------------------------------------------------------------------*/
5347 mono_arch_regalloc_cost (MonoCompile *cfg, MonoMethodVar *vmv)
5353 /*========================= End of Function ========================*/
5355 /*------------------------------------------------------------------*/
5357 /* Name - mono_arch_get_domain_intrinsic */
5363 /*------------------------------------------------------------------*/
5366 mono_arch_get_domain_intrinsic (MonoCompile* cfg)
5370 if (appdomain_tls_offset == -1)
5373 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5374 ins->inst_offset = appdomain_tls_offset;
5378 /*========================= End of Function ========================*/
5380 /*------------------------------------------------------------------*/
5382 /* Name - mono_arch_get_thread_intrinsic */
5388 /*------------------------------------------------------------------*/
5391 mono_arch_get_thread_intrinsic (MonoCompile* cfg)
5395 if (thread_tls_offset == -1)
5398 MONO_INST_NEW (cfg, ins, OP_TLS_GET);
5399 ins->inst_offset = thread_tls_offset;
5403 /*========================= End of Function ========================*/
5405 /*------------------------------------------------------------------*/
5407 /* Name - mono_arch_flush_register_windows */
5413 /*------------------------------------------------------------------*/
5416 mono_arch_flush_register_windows (void)
5420 /*========================= End of Function ========================*/
5422 /*------------------------------------------------------------------*/
5424 /* Name - mono_arch_get_lmf_addr */
5430 /*------------------------------------------------------------------*/
5433 mono_arch_get_lmf_addr (void)
5435 return pthread_getspecific (lmf_addr_key);
5438 /*========================= End of Function ========================*/
5440 /*------------------------------------------------------------------*/
5442 /* Name - mono_arch_is_inst_imm */
5444 /* Function - Determine if operand qualifies as an immediate */
5445 /* value. For s390 this is a value -32768-32768 */
5447 /* Returns - True|False - is [not] immediate value. */
5449 /*------------------------------------------------------------------*/
5452 mono_arch_is_inst_imm (gint64 imm)
5454 return s390_is_imm16 (imm);
5457 /*========================= End of Function ========================*/
5459 /*------------------------------------------------------------------*/
5461 /* Name - mono_arch_get_patch_offset */
5463 /* Function - Dummy entry point until s390x supports aot. */
5465 /* Returns - Offset for patch. */
5467 /*------------------------------------------------------------------*/
5470 mono_arch_get_patch_offset (guint8 *code)
5475 /*========================= End of Function ========================*/
5477 /*------------------------------------------------------------------*/
5479 /* Name - mono_arch_context_get_int_reg. */
5483 /* Returns - Offset for patch. */
5485 /*------------------------------------------------------------------*/
5488 mono_arch_context_get_int_reg (MonoContext *ctx, int reg)
5490 /* FIXME: implement */
5491 g_assert_not_reached ();
5495 /*========================= End of Function ========================*/