Make sure x86 ATOMIC_CAS doesn't overwrite its own operands.
[mono-debugger.git] / mono / mini / mini-s390x.h
blob3de7f0b0e2b68ee40b27e96f8b6ba4eb61c5beef
1 #ifndef __MONO_MINI_S390X_H__
2 #define __MONO_MINI_S390X_H__
4 #include <mono/arch/s390x/s390x-codegen.h>
5 #include <signal.h>
7 #define MONO_ARCH_CPU_SPEC s390x_cpu_desc
9 #define MONO_MAX_IREGS 16
10 #define MONO_MAX_FREGS 16
12 /*-------------------------------------------*/
13 /* Parameters used by the register allocator */
14 /*-------------------------------------------*/
16 #define S390_LONG(loc, opy, op, r, ix, br, off) \
17 if (has_ld) { \
18 if (s390_is_imm20(off)) { \
19 s390_##opy (loc, r, ix, br, off); \
20 } else { \
21 s390_basr (code, s390_r13, 0); \
22 s390_j (code, 6); \
23 s390_llong(code, off); \
24 s390_lg (code, s390_r13, 0, s390_r13, 4); \
25 s390_##op (code, r, s390_r13, br, 0); \
26 } \
27 } else { \
28 if (s390_is_uimm12(off)) { \
29 s390_##op (loc, r, ix, br, off); \
30 } else { \
31 s390_basr (code, s390_r13, 0); \
32 s390_j (code, 6); \
33 s390_llong(code, off); \
34 s390_lg (code, s390_r13, 0, s390_r13, 4); \
35 s390_##op (code, r, s390_r13, br, 0); \
36 } \
39 struct MonoLMF {
40 gpointer previous_lmf;
41 gpointer lmf_addr;
42 MonoMethod *method;
43 gulong ebp;
44 gulong eip;
45 gulong pregs[6];
46 gulong gregs[16];
47 gdouble fregs[16];
50 typedef struct ucontext MonoContext;
52 typedef struct MonoCompileArch {
53 gpointer litpool;
54 glong litsize;
55 int bkchain_reg;
56 } MonoCompileArch;
58 typedef struct
60 void *prev;
61 void *unused[5];
62 void *regs[8];
63 void *return_address;
64 } MonoS390StackFrame;
66 // #define MONO_ARCH_SIGSEGV_ON_ALTSTACK 1
67 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
68 #define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS 1
69 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS 1
70 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
71 #define MONO_ARCH_NEED_DIV_CHECK 1
72 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
73 #define MONO_ARCH_HAVE_ATOMIC_EXCHANGE 1
74 #define MONO_ARCH_SIGNAL_STACK_SIZE 256*1024
75 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
76 // #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
78 #define MONO_ARCH_USE_SIGACTION 1
80 #define S390_STACK_ALIGNMENT 8
81 #define S390_FIRST_ARG_REG s390_r2
82 #define S390_LAST_ARG_REG s390_r6
83 #define S390_FIRST_FPARG_REG s390_f0
84 #define S390_LAST_FPARG_REG s390_f6
85 #define S390_PASS_STRUCTS_BY_VALUE 1
86 #define S390_SMALL_RET_STRUCT_IN_REG 1
88 #define S390_NUM_REG_ARGS (S390_LAST_ARG_REG-S390_FIRST_ARG_REG+1)
89 #define S390_NUM_REG_FPARGS ((S390_LAST_FPARG_REG-S390_FIRST_FPARG_REG)/2)
91 /*===============================================*/
92 /* Definitions used by mini-codegen.c */
93 /*===============================================*/
95 /*------------------------------------------------------*/
96 /* use s390_r2-s390_r6 as parm registers */
97 /* s390_r0, s390_r1, s390_r12, s390_r13 used internally */
98 /* s390_r8..s390_r11 are used for global regalloc */
99 /* s390_r15 is the stack pointer */
100 /*------------------------------------------------------*/
101 #define MONO_ARCH_CALLEE_REGS (0xfc)
103 #define MONO_ARCH_CALLEE_SAVED_REGS 0xff80
105 /*----------------------------------------*/
106 /* use s390_f1/s390_f3-s390_f15 as temps */
107 /*----------------------------------------*/
109 #define MONO_ARCH_CALLEE_FREGS (0xfffe)
111 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
113 #define MONO_ARCH_USE_FPSTACK FALSE
114 #define MONO_ARCH_FPSTACK_SIZE 0
116 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 'o') ? s390_r2 : \
117 ((desc == 'g') ? s390_f0 : - 1))
119 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
121 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
123 #define MONO_ARCH_INST_IS_REGPAIR(desc) (0)
124 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hr) -1
126 #define MONO_ARCH_IS_GLOBAL_IREG(reg) 0
128 #define MONO_ARCH_FRAME_ALIGNMENT 8
129 #define MONO_ARCH_CODE_ALIGNMENT 32
131 #define MONO_ARCH_RETREG1 s390_r2
133 /*-----------------------------------------------*/
134 /* Macros used to generate instructions */
135 /*-----------------------------------------------*/
136 #define S390_OFFSET(b, t) (guchar *) ((guint64) (b) - (guint64) (t))
137 #define S390_RELATIVE(b, t) (guchar *) ((((guint64) (b) - (guint64) (t))) / 2)
139 #define CODEPTR(c, o) (o) = (short *) ((guint64) c - 2)
140 #define PTRSLOT(c, o) *(o) = (short) ((guint64) c - (guint64) (o) + 2)/2
142 #define S390_CC_EQ 8
143 #define S390_ALIGN(v, a) (((a) > 0 ? (((v) + ((a) - 1)) & ~((a) - 1)) : (v)))
145 #define MONO_CONTEXT_SET_IP(ctx,ip) \
146 do { \
147 (ctx)->uc_mcontext.gregs[14] = (unsigned long)ip; \
148 (ctx)->uc_mcontext.psw.addr = (unsigned long)ip; \
149 } while (0);
151 #define MONO_CONTEXT_SET_SP(ctx,bp) MONO_CONTEXT_SET_BP((ctx),(bp))
152 #define MONO_CONTEXT_SET_BP(ctx,bp) \
153 do { \
154 (ctx)->uc_mcontext.gregs[15] = (unsigned long)bp; \
155 (ctx)->uc_stack.ss_sp = (void*)bp; \
156 } while (0)
158 #define MONO_CONTEXT_GET_IP(ctx) (gpointer) (ctx)->uc_mcontext.psw.addr
159 #define MONO_CONTEXT_GET_BP(ctx) MONO_CONTEXT_GET_SP((ctx))
160 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->uc_mcontext.gregs[15]))
162 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do { \
163 MonoS390StackFrame *sframe; \
164 __asm__ volatile("lgr %0,15" : "=r" (sframe)); \
165 MONO_CONTEXT_SET_BP ((ctx), sframe->prev); \
166 MONO_CONTEXT_SET_SP ((ctx), sframe->prev); \
167 sframe = (MonoS390StackFrame*)sframe->prev; \
168 MONO_CONTEXT_SET_IP ((ctx), sframe->return_address); \
169 } while (0)
171 /*------------------------------------------------------------------*/
172 /* */
173 /* Name - s390_patch_rel */
174 /* */
175 /* Function - Patch the code with a given offset. */
176 /* */
177 /*------------------------------------------------------------------*/
179 static void inline
180 s390_patch_rel (guchar *code, guint64 target)
182 guint32 *offset = (guint32 *) code;
184 if (target != 0) {
185 *offset = (guint32) target;
189 /*========================= End of Function ========================*/
191 /*------------------------------------------------------------------*/
192 /* */
193 /* Name - s390_patch_addr */
194 /* */
195 /* Function - Patch the code with a given address. */
196 /* */
197 /*------------------------------------------------------------------*/
199 static void inline
200 s390_patch_addr (guchar *code, guint64 target)
202 guint64 *offset = (guint64 *) code;
204 if (target != 0) {
205 *offset = target;
209 /*========================= End of Function ========================*/
211 /*------------------------------------------------------------------*/
212 /* */
213 /* Name - restoreLMF */
214 /* */
215 /* Function - Restore the LMF state prior to exiting a method. */
216 /* */
217 /*------------------------------------------------------------------*/
219 #define restoreLMF(code, frame_reg, stack_usage) do \
221 int lmfOffset = 0; \
223 s390_lgr (code, s390_r13, frame_reg); \
225 lmfOffset = stack_usage - sizeof(MonoLMF); \
227 /*-------------------------------------------------*/ \
228 /* r13 = my lmf */ \
229 /*-------------------------------------------------*/ \
230 s390_aghi (code, s390_r13, lmfOffset); \
232 /*-------------------------------------------------*/ \
233 /* r6 = &jit_tls->lmf */ \
234 /*-------------------------------------------------*/ \
235 s390_lg (code, s390_r6, 0, s390_r13, \
236 G_STRUCT_OFFSET(MonoLMF, lmf_addr)); \
238 /*-------------------------------------------------*/ \
239 /* r0 = lmf.previous_lmf */ \
240 /*-------------------------------------------------*/ \
241 s390_lg (code, s390_r0, 0, s390_r13, \
242 G_STRUCT_OFFSET(MonoLMF, previous_lmf)); \
244 /*-------------------------------------------------*/ \
245 /* jit_tls->lmf = previous_lmf */ \
246 /*-------------------------------------------------*/ \
247 s390_lg (code, s390_r13, 0, s390_r6, 0); \
248 s390_stg (code, s390_r0, 0, s390_r6, 0); \
249 } while (0)
251 /*========================= End of Function ========================*/
253 #endif /* __MONO_MINI_S390X_H__ */