2009-01-07 Zoltan Varga <vargaz@gmail.com>
[mono-project.git] / mono / mini / mini-s390.h
blobb98624e7dc3e1c6ce4851804ea9d57511f4c4798
1 #ifndef __MONO_MINI_S390_H__
2 #define __MONO_MINI_S390_H__
4 #include <mono/arch/s390/s390-codegen.h>
5 #include <signal.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 { \
17 MonoInst *inst; \
18 int tmpr = 0; \
19 int sReg, dReg; \
21 inst = mono_mempool_alloc0 ((cfg)->mempool, sizeof (MonoInst)); \
22 if (size > 256) { \
23 tmpr = mono_regstate_next_int (cfg->rs); \
24 MONO_EMIT_NEW_ICONST(cfg,tmpr,size); \
25 inst->dreg = dest; \
26 inst->inst_offset = offset; \
27 inst->sreg1 = src; \
28 inst->inst_imm = imm; \
29 inst->sreg2 = tmpr; \
30 } else { \
31 if (s390_is_uimm12(offset)) { \
32 inst->dreg = dest; \
33 inst->inst_offset = offset; \
34 } else { \
35 dReg = mono_regstate_next_int (cfg->rs); \
36 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
37 dReg, dest, offset); \
38 inst->dreg = dReg; \
39 inst->inst_offset = 0; \
40 } \
41 if (s390_is_uimm12(imm)) { \
42 inst->sreg1 = src; \
43 inst->inst_imm = imm; \
44 } else { \
45 sReg = mono_regstate_next_int (cfg->rs); \
46 MONO_EMIT_NEW_BIALU_IMM(cfg, OP_ADD_IMM, \
47 sReg, src, imm); \
48 inst->sreg1 = sReg; \
49 inst->inst_imm = 0; \
50 } \
51 } \
52 inst->opcode = OP_S390_MOVE; \
53 inst->backend.size = size; \
54 mono_bblock_add_inst (cfg->cbb, inst); \
55 } while (0)
57 #define MONO_OUTPUT_VTR(cfg, size, dr, sr, so) do { \
58 int reg = mono_regstate_next_int (cfg->rs); \
59 switch (size) { \
60 case 0: \
61 MONO_EMIT_NEW_ICONST(cfg, reg, 0); \
62 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
63 break; \
64 case 1: \
65 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
66 reg, sr, so); \
67 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
68 break; \
69 case 2: \
70 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
71 reg, sr, so); \
72 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
73 break; \
74 case 4: \
75 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
76 reg, sr, so); \
77 mono_call_inst_add_outarg_reg(cfg, call, reg, dr, FALSE); \
78 break; \
79 case 8: \
80 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOAD_MEMBASE, \
81 reg, sr, so); \
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); \
87 break; \
88 } \
89 } while (0)
91 #define MONO_OUTPUT_VTS(cfg, size, dr, dx, sr, so) do { \
92 int tmpr; \
93 switch (size) { \
94 case 0: \
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, \
98 dr, dx, tmpr); \
99 break; \
100 case 1: \
101 tmpr = mono_regstate_next_int (cfg->rs); \
102 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU1_MEMBASE, \
103 tmpr, sr, so); \
104 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
105 dr, dx, tmpr); \
106 break; \
107 case 2: \
108 tmpr = mono_regstate_next_int (cfg->rs); \
109 MONO_EMIT_NEW_LOAD_MEMBASE_OP(cfg, OP_LOADU2_MEMBASE, \
110 tmpr, sr, so); \
111 MONO_EMIT_NEW_STORE_MEMBASE(cfg, OP_STORE_MEMBASE_REG, \
112 dr, dx, tmpr); \
113 break; \
114 case 4: \
115 case 8: \
116 MONO_EMIT_NEW_MOVE (cfg, dr, dx, sr, so, size); \
117 break; \
119 } while (0)
121 struct MonoLMF {
122 gpointer previous_lmf;
123 gpointer lmf_addr;
124 MonoMethod *method;
125 gulong ebp;
126 gulong eip;
127 gulong pregs[6];
128 gulong gregs[16];
129 gdouble fregs[16];
132 typedef struct ucontext MonoContext;
134 typedef struct MonoCompileArch {
135 int bkchain_reg;
136 } MonoCompileArch;
138 typedef struct
140 void *prev;
141 void *unused[5];
142 void *regs[8];
143 void *return_address;
144 } MonoS390StackFrame;
146 typedef struct
148 gint32 size;
149 gint32 offset;
150 gint32 offPrm;
151 } MonoS390ArgParm;
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
236 #define S390_CC_EQ 8
237 #define S390_ALIGN(v, a) (((a) > 0 ? (((v) + ((a) - 1)) & ~((a) - 1)) : (v)))
239 #define MONO_CONTEXT_SET_IP(ctx,ip) \
240 do { \
241 (ctx)->uc_mcontext.gregs[14] = (unsigned long)ip; \
242 (ctx)->uc_mcontext.psw.addr = (unsigned long)ip; \
243 } while (0);
245 #define MONO_CONTEXT_SET_SP(ctx,bp) MONO_CONTEXT_SET_BP((ctx),(bp))
246 #define MONO_CONTEXT_SET_BP(ctx,bp) \
247 do { \
248 (ctx)->uc_mcontext.gregs[15] = (unsigned long)bp; \
249 (ctx)->uc_stack.ss_sp = (void*)bp; \
250 } while (0);
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); \
263 } while (0)
265 /*------------------------------------------------------------------*/
266 /* */
267 /* Name - context_get_ip */
268 /* */
269 /* Function - Extract the current instruction address from the */
270 /* context. */
271 /* */
272 /*------------------------------------------------------------------*/
274 static inline gpointer
275 context_get_ip (MonoContext *ctx)
277 gpointer ip;
279 ip = (gpointer) ((gint32) (ctx->uc_mcontext.psw.addr) & 0x7fffffff);
280 return ip;
283 /*========================= End of Function ========================*/
285 /*------------------------------------------------------------------*/
286 /* */
287 /* Name - s390_patch */
288 /* */
289 /* Function - Patch the code with a given value. */
290 /* */
291 /*------------------------------------------------------------------*/
293 static void inline
294 s390_patch (guchar *code, gint32 target)
296 gint32 *offset = (gint32 *) code;
298 if (target != 00) {
299 *offset = target;
303 /*========================= End of Function ========================*/
305 /*------------------------------------------------------------------*/
306 /* */
307 /* Name - restoreLMF */
308 /* */
309 /* Function - Restore the LMF state prior to exiting a method. */
310 /* */
311 /*------------------------------------------------------------------*/
313 #define restoreLMF(code, frame_reg, stack_usage) do \
315 int lmfOffset = 0; \
317 s390_lr (code, s390_r13, frame_reg); \
319 lmfOffset = stack_usage - sizeof(MonoLMF); \
321 /*-------------------------------------------------*/ \
322 /* r13 = my lmf */ \
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); \
343 } while (0)
345 /*========================= End of Function ========================*/
347 #endif /* __MONO_MINI_S390_H__ */