1 #ifndef __MONO_MINI_S390_H__
2 #define __MONO_MINI_S390_H__
4 #include <mono/arch/s390/s390-codegen.h>
7 #define MONO_ARCH_CPU_SPEC s390_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 MONO_EMIT_NEW_MOVE(cfg,dest,offset,src,imm,size) do { \
21 inst = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
23 tmpr = mono_regstate_next_int (cfg->rs); \
24 MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
26 inst->inst_offset = offset; \
28 inst->inst_imm = imm; \
31 if (s390_is_uimm12(offset)) { \
33 inst->inst_offset = offset; \
35 dReg = mono_regstate_next_int (cfg->rs); \
36 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
37 dReg, dest, offset); \
39 inst->inst_offset = 0; \
41 if (s390_is_uimm12(imm)) { \
43 inst->inst_imm = imm; \
45 sReg = mono_regstate_next_int (cfg->rs); \
46 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
52 inst->opcode = OP_S390_MOVE; \
53 inst->backend.size = size; \
54 mono_bblock_add_inst (cfg->cbb, inst); \
57 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
58 int reg = mono_regstate_next_int (cfg->rs); \
61 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
62 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
65 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
67 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
70 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
72 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
75 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
77 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
80 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
82 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
83 reg = mono_regstate_next_int (cfg->rs); \
84 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
85 reg, sr, so + sizeof (guint32)); \
86 mono_call_inst_add_outarg_reg(cfg, call, reg, dr + 1, FALSE); \
91 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
95 tmpr = mono_regstate_next_int (cfg->rs); \
96 MONO_EMIT_NEW_ICONST(cfg, tmpr, 0); \
97 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
101 tmpr = mono_regstate_next_int (cfg->rs); \
102 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
104 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
108 tmpr = mono_regstate_next_int (cfg->rs); \
109 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
111 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
116 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
122 gpointer previous_lmf
;
132 typedef struct ucontext MonoContext
;
134 typedef struct MonoCompileArch
{
143 void *return_address
;
144 } MonoS390StackFrame
;
153 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
154 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
155 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
156 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
157 #define MONO_ARCH_EMULATE_LMUL 1
158 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW 1
159 #define MONO_ARCH_NEED_DIV_CHECK 1
160 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
161 #define MONO_ARCH_HAVE_ATOMIC_EXCHANGE 1
162 #define MONO_ARCH_ENABLE_NORMALIZE_OPCODES 1
163 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
164 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
165 // #define MONO_ARCH_SIGSEGV_ON_ALTSTACK 1
166 // #define MONO_ARCH_SIGNAL_STACK_SIZE 65536
167 // #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
169 #define MONO_ARCH_USE_SIGACTION 1
171 #define S390_STACK_ALIGNMENT 8
172 #define S390_FIRST_ARG_REG s390_r2
173 #define S390_LAST_ARG_REG s390_r6
174 #define S390_FIRST_FPARG_REG s390_f0
175 #define S390_LAST_FPARG_REG s390_f2
176 #define S390_PASS_STRUCTS_BY_VALUE 1
177 #define S390_SMALL_RET_STRUCT_IN_REG 1
179 #define S390_NUM_REG_ARGS (S390_LAST_ARG_REG-S390_FIRST_ARG_REG+1)
180 #define S390_NUM_REG_FPARGS (S390_LAST_FPARG_REG-S390_FIRST_FPARG_REG)
182 /*===============================================*/
183 /* Definitions used by mini-codegen.c */
184 /*===============================================*/
186 /*-----------------------------------------------------*/
187 /* use s390_r2-s390_r6 as parm registers */
188 /* s390_r0, s390_r1, s390_r12, s390_r13 used internally*/
189 /* s390_r8..s390_r11 are used for global regalloc */
190 /* s390_r15 is the stack pointer */
191 /*-----------------------------------------------------*/
192 #define MONO_ARCH_CALLEE_REGS (0xfc)
194 #define MONO_ARCH_CALLEE_SAVED_REGS 0xff80
196 /*----------------------------------------*/
197 /* use s390_f1/s390_f3-s390_f15 as temps */
198 /*----------------------------------------*/
200 #define MONO_ARCH_CALLEE_FREGS (0xfffe)
202 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
204 #define MONO_ARCH_USE_FPSTACK FALSE
205 #define MONO_ARCH_FPSTACK_SIZE 0
207 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 'o') ? s390_r2 : \
208 ((desc == 'L') ? s390_r3 : \
209 ((desc == 'g') ? s390_f0 : - 1)))
211 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
213 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
215 #define MONO_ARCH_INST_IS_REGPAIR(desc) ((desc == 'l') || (desc == 'L'))
216 //#define MONO_ARCH_INST_IS_REGPAIR(desc) (0)
217 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hr) ((desc == 'l') ? (hr + 1) : \
218 ((desc == 'L') ? s390_r2 : -1))
220 #define MONO_ARCH_IS_GLOBAL_IREG(reg) 0
222 #define MONO_ARCH_FRAME_ALIGNMENT 4
223 #define MONO_ARCH_CODE_ALIGNMENT 32
225 #define MONO_ARCH_RETREG1 s390_r2
227 /*-----------------------------------------------*/
228 /* Macros used to generate instructions */
229 /*-----------------------------------------------*/
230 #define S390_OFFSET(b, t) (guchar *) ((gint32) (b) - (gint32) (t))
231 #define S390_RELATIVE(b, t) (guchar *) ((((gint32) (b) - (gint32) (t))) / 2)
233 #define CODEPTR(c, o) (o) = (short *) ((guint32) c - 2)
234 #define PTRSLOT(c, o) *(o) = (short) ((guint32) c - (guint32) (o) + 2)/2
237 #define S390_ALIGN(v, a) (((a) > 0 ? (((v) + ((a) - 1)) & ~((a) - 1)) : (v)))
239 #define MONO_CONTEXT_SET_IP(ctx,ip) \
241 (ctx)->uc_mcontext.gregs[14] = (unsigned long)ip; \
242 (ctx)->uc_mcontext.psw.addr = (unsigned long)ip; \
245 #define MONO_CONTEXT_SET_SP(ctx,bp) MONO_CONTEXT_SET_BP((ctx),(bp))
246 #define MONO_CONTEXT_SET_BP(ctx,bp) \
248 (ctx)->uc_mcontext.gregs[15] = (unsigned long)bp; \
249 (ctx)->uc_stack.ss_sp = (void*)bp; \
252 #define MONO_CONTEXT_GET_IP(ctx) context_get_ip ((ctx))
253 #define MONO_CONTEXT_GET_BP(ctx) MONO_CONTEXT_GET_SP((ctx))
254 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->uc_mcontext.gregs[15]))
256 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do { \
257 MonoS390StackFrame *sframe; \
258 __asm__ volatile("lr %0,15" : "=r" (sframe)); \
259 MONO_CONTEXT_SET_BP ((ctx), sframe->prev); \
260 MONO_CONTEXT_SET_SP ((ctx), sframe->prev); \
261 sframe = (MonoS390StackFrame*)sframe->prev; \
262 MONO_CONTEXT_SET_IP ((ctx), sframe->return_address); \
265 /*------------------------------------------------------------------*/
267 /* Name - context_get_ip */
269 /* Function - Extract the current instruction address from the */
272 /*------------------------------------------------------------------*/
274 static inline gpointer
275 context_get_ip (MonoContext
*ctx
)
279 ip
= (gpointer
) ((gint32
) (ctx
->uc_mcontext
.psw
.addr
) & 0x7fffffff);
283 /*========================= End of Function ========================*/
285 /*------------------------------------------------------------------*/
287 /* Name - s390_patch */
289 /* Function - Patch the code with a given value. */
291 /*------------------------------------------------------------------*/
294 s390_patch (guchar
*code
, gint32 target
)
296 gint32
*offset
= (gint32
*) code
;
303 /*========================= End of Function ========================*/
305 /*------------------------------------------------------------------*/
307 /* Name - restoreLMF */
309 /* Function - Restore the LMF state prior to exiting a method. */
311 /*------------------------------------------------------------------*/
313 #define restoreLMF(code, frame_reg, stack_usage) do \
317 s390_lr (code, s390_r13, frame_reg); \
319 lmfOffset = stack_usage - sizeof(MonoLMF); \
321 /*-------------------------------------------------*/ \
323 /*-------------------------------------------------*/ \
324 s390_ahi (code, s390_r13, lmfOffset); \
326 /*-------------------------------------------------*/ \
327 /* r6 = &jit_tls->lmf */ \
328 /*-------------------------------------------------*/ \
329 s390_l (code, s390_r6, 0, s390_r13, \
330 G_STRUCT_OFFSET(MonoLMF, lmf_addr)); \
332 /*-------------------------------------------------*/ \
333 /* r0 = lmf.previous_lmf */ \
334 /*-------------------------------------------------*/ \
335 s390_l (code, s390_r0, 0, s390_r13, \
336 G_STRUCT_OFFSET(MonoLMF, previous_lmf)); \
338 /*-------------------------------------------------*/ \
339 /* jit_tls->lmf = previous_lmf */ \
340 /*-------------------------------------------------*/ \
341 s390_l (code, s390_r13, 0, s390_r6, 0); \
342 s390_st (code, s390_r0, 0, s390_r6, 0); \
345 /*========================= End of Function ========================*/
347 #endif /* __MONO_MINI_S390_H__ */