[sockets] Fixed reading blocking flag
[mono.git] / mono / mini / mini-s390x.h
1 #ifndef __MONO_MINI_S390X_H__
2 #define __MONO_MINI_S390X_H__
3
4 #include <mono/arch/s390x/s390x-codegen.h>
5 #include <signal.h>
6
7 #define MONO_ARCH_CPU_SPEC s390x_cpu_desc
8
9 #define MONO_MAX_IREGS 16
10 #define MONO_MAX_FREGS 16
11
12 /*-------------------------------------------*/
13 /* Parameters used by the register allocator */
14 /*-------------------------------------------*/
15
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                 }                                                               \
37         }
38
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];
48 };
49
50 typedef struct ucontext MonoContext;
51
52 typedef struct MonoCompileArch {
53         gpointer    litpool;
54         glong       litsize;
55         int         bkchain_reg;
56 } MonoCompileArch;
57
58 typedef struct
59 {
60         void *prev;
61         void *unused[5];
62         void *regs[8];
63         void *return_address;
64 } MonoS390StackFrame;
65
66 typedef struct
67 {
68         char    n3:1;           // N3 instructions present
69         char    zArch:1;        // z/Architecture mode installed
70         char    zAct:1;         // z/Architecture mode active
71         char    date:1;         // DATE enhancement facility
72         char    idte1:1;        // IDTE present (PST)
73         char    idte2:1;        // IDTE present (REG)
74         char    asnlx:1;        // ASN and LX reuse facility
75         char    stfle:1;        // STFLE installed
76         char    zDATe:1;        // Enhanced DAT in z mode
77         char    srstat:1;       // Sense running status facility
78         char    cSSKE:1;        // Conditional SSKE facility
79         char    topo:1;         // COnfiguration topology facility
80         char    xTrans2:1;      // Extended translation facility 2
81         char    msgSec:1;       // Message security facility
82         char    longDsp:1;      // Long displacement facility
83         char    hiPerfLD:1;     // High performance long displacement facility
84         char    hfpMAS:1;       // HFP multiply-and-add/subtrace facility
85         char    xImm:1;         // Extended immediate facility
86         char    xTrans3:1;      // Extended translation facility 3
87         char    hfpUnX:1;       // HFP unnormalized extension facility
88         char    etf2:1;         // ETF2-enhancement facility
89         char    stckf:1;        // Store-clock-fast facility
90         char    parse:1;        // Parsing enhancement facility
91         char    mvcos:1;        // MVCOS facility
92         char    todSteer:1;     // TOD-clock steering facility
93         char    etf3:1;         // ETF3-enhancement facility
94         char    xCPUtm:1;       // Extract CPU time facility
95         char    csst:1;         // Compare-swap-and-store facility
96         char    csst2:1;        // Compare-swap-and-store facility 2
97         char    giX:1;          // General instructions extension facility
98         char    exX:1;          // Execute extensions facility
99         char    ibm:1;          // IBM internal use
100         char    fps:1;          // Floating point support enhancement
101         char    dfp:1;          // Decimal floating point facility
102         char    hiDFP:1;        // High Performance DFP facility
103         char    pfpo:1;         // PFPO instruction facility
104 } __attribute__((aligned(8))) facilityList_t;
105         
106 // #define MONO_ARCH_SIGSEGV_ON_ALTSTACK                1
107 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN                1
108 #define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS              1
109 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS             1
110 #define MONO_ARCH_HAVE_IS_INT_OVERFLOW                  1
111 #define MONO_ARCH_NEED_DIV_CHECK                        1
112 #define MONO_ARCH_HAVE_ATOMIC_ADD                       1
113 #define MONO_ARCH_HAVE_ATOMIC_EXCHANGE                  1
114 #define MONO_ARCH_SIGNAL_STACK_SIZE                     256*1024
115 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS                   1
116 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE       1
117 #define MONO_ARCH_HAVE_IMT                              1
118 #define MONO_ARCH_IMT_REG                               s390_r9
119 #define MONO_ARCH_THIS_AS_FIRST_ARG                     1
120
121 #define MONO_ARCH_USE_SIGACTION         1
122
123 #define S390_STACK_ALIGNMENT             8
124 #define S390_FIRST_ARG_REG              s390_r2
125 #define S390_LAST_ARG_REG               s390_r6
126 #define S390_FIRST_FPARG_REG            s390_f0
127 #define S390_LAST_FPARG_REG             s390_f6
128 #define S390_PASS_STRUCTS_BY_VALUE       1
129 #define S390_SMALL_RET_STRUCT_IN_REG     1
130
131 #define S390_NUM_REG_ARGS (S390_LAST_ARG_REG-S390_FIRST_ARG_REG+1)
132 #define S390_NUM_REG_FPARGS ((S390_LAST_FPARG_REG-S390_FIRST_FPARG_REG)/2)
133
134 /*===============================================*/
135 /* Definitions used by mini-codegen.c            */
136 /*===============================================*/
137
138 /*------------------------------------------------------*/
139 /* use s390_r2-s390_r6 as parm registers                */
140 /* s390_r0, s390_r1, s390_r12, s390_r13 used internally */
141 /* s390_r8..s390_r11 are used for global regalloc       */
142 /* s390_r15 is the stack pointer                        */
143 /*------------------------------------------------------*/
144
145 #define MONO_ARCH_CALLEE_REGS (0xfc)
146
147 #define MONO_ARCH_CALLEE_SAVED_REGS 0xff80
148
149 /*----------------------------------------*/
150 /* use s390_f1/s390_f3-s390_f15 as temps  */
151 /*----------------------------------------*/
152
153 #define MONO_ARCH_CALLEE_FREGS (0xfffe)
154
155 #define MONO_ARCH_CALLEE_SAVED_FREGS 0
156
157 #define MONO_ARCH_USE_FPSTACK FALSE
158 #define MONO_ARCH_FPSTACK_SIZE 0
159
160 #define MONO_ARCH_INST_FIXED_REG(desc) ((desc == 'o') ? s390_r2 :               \
161                                         ((desc == 'g') ? s390_f0 : - 1))
162
163 #define MONO_ARCH_INST_IS_FLOAT(desc)  ((desc == 'f') || (desc == 'g'))
164
165 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
166
167 #define MONO_ARCH_INST_IS_REGPAIR(desc) (0)
168 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hr) -1
169
170 #define MONO_ARCH_IS_GLOBAL_IREG(reg) 0
171
172 #define MONO_ARCH_FRAME_ALIGNMENT 8
173 #define MONO_ARCH_CODE_ALIGNMENT 32
174
175 #define MONO_ARCH_RETREG1 s390_r2
176
177 /*-----------------------------------------------*/
178 /* Macros used to generate instructions          */
179 /*-----------------------------------------------*/
180 #define S390_OFFSET(b, t)       (guchar *) ((guint64) (b) - (guint64) (t))
181 #define S390_RELATIVE(b, t)     (guchar *) ((((guint64) (b) - (guint64) (t))) / 2)
182
183 #define CODEPTR(c, o) (o) = (short *) ((guint64) c - 2)
184 #define PTRSLOT(c, o) *(o) = (short) ((guint64) c - (guint64) (o) + 2)/2
185
186 #define S390_CC_EQ                      8
187 #define S390_ALIGN(v, a)        (((a) > 0 ? (((v) + ((a) - 1)) & ~((a) - 1)) : (v)))
188
189 #define MONO_CONTEXT_SET_IP(ctx,ip)                                     \
190         do {                                                            \
191                 (ctx)->uc_mcontext.gregs[14] = (unsigned long)ip;       \
192                 (ctx)->uc_mcontext.psw.addr = (unsigned long)ip;        \
193         } while (0); 
194
195 #define MONO_CONTEXT_SET_SP(ctx,bp) MONO_CONTEXT_SET_BP((ctx),(bp))
196 #define MONO_CONTEXT_SET_BP(ctx,bp)                                     \
197         do {                                                            \
198                 (ctx)->uc_mcontext.gregs[15] = (unsigned long)bp;       \
199                 (ctx)->uc_stack.ss_sp        = (void*)bp;               \
200         } while (0) 
201
202 #define MONO_CONTEXT_GET_IP(ctx) (gpointer) (ctx)->uc_mcontext.psw.addr
203 #define MONO_CONTEXT_GET_BP(ctx) MONO_CONTEXT_GET_SP((ctx))
204 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->uc_mcontext.gregs[15]))
205
206 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,func) do {                      \
207                 MonoS390StackFrame *sframe;                             \
208                 __asm__ volatile("lgr   %0,15" : "=r" (sframe));        \
209                 MONO_CONTEXT_SET_BP ((ctx), sframe->prev);              \
210                 MONO_CONTEXT_SET_SP ((ctx), sframe->prev);              \
211                 sframe = (MonoS390StackFrame*)sframe->prev;             \
212                 MONO_CONTEXT_SET_IP ((ctx), sframe->return_address);    \
213         } while (0)
214
215 #define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->ebp = -1; } while (0)
216
217 /*------------------------------------------------------------------*/
218 /*                                                                  */
219 /* Name         - s390_patch_rel                                    */
220 /*                                                                  */
221 /* Function     - Patch the code with a given offset.               */
222 /*                                                                  */
223 /*------------------------------------------------------------------*/
224
225 static void inline
226 s390_patch_rel (guchar *code, guint64 target)
227 {
228         guint32 *offset = (guint32 *) code;
229         
230         if (target != 0) {
231                 *offset = (guint32) target;
232         }
233 }
234
235 /*========================= End of Function ========================*/
236
237 /*------------------------------------------------------------------*/
238 /*                                                                  */
239 /* Name         - s390_patch_addr                                   */
240 /*                                                                  */
241 /* Function     - Patch the code with a given address.              */
242 /*                                                                  */
243 /*------------------------------------------------------------------*/
244
245 static void inline
246 s390_patch_addr (guchar *code, guint64 target)
247 {
248         guint64 *offset = (guint64 *) code;
249         
250         if (target != 0) {
251                 *offset = target;
252         }
253 }
254
255 /*========================= End of Function ========================*/
256
257 /*------------------------------------------------------------------*/
258 /*                                                                  */
259 /* Name         - restoreLMF                                        */
260 /*                                                                  */
261 /* Function     - Restore the LMF state prior to exiting a method.  */
262 /*                                                                  */
263 /*------------------------------------------------------------------*/
264
265 #define restoreLMF(code, frame_reg, stack_usage) do                     \
266 {                                                                       \
267         int lmfOffset = 0;                                              \
268                                                                         \
269         s390_lgr (code, s390_r13, frame_reg);                           \
270                                                                         \
271         lmfOffset = stack_usage -  sizeof(MonoLMF);                     \
272                                                                         \
273         /*-------------------------------------------------*/           \
274         /* r13 = my lmf                                    */           \
275         /*-------------------------------------------------*/           \
276         s390_aghi (code, s390_r13, lmfOffset);                          \
277                                                                         \
278         /*-------------------------------------------------*/           \
279         /* r6 = &jit_tls->lmf                              */           \
280         /*-------------------------------------------------*/           \
281         s390_lg  (code, s390_r6, 0, s390_r13,                           \
282                   G_STRUCT_OFFSET(MonoLMF, lmf_addr));                  \
283                                                                         \
284         /*-------------------------------------------------*/           \
285         /* r0 = lmf.previous_lmf                           */           \
286         /*-------------------------------------------------*/           \
287         s390_lg  (code, s390_r0, 0, s390_r13,                           \
288                   G_STRUCT_OFFSET(MonoLMF, previous_lmf));              \
289                                                                         \
290         /*-------------------------------------------------*/           \
291         /* jit_tls->lmf = previous_lmf                     */           \
292         /*-------------------------------------------------*/           \
293         s390_lg  (code, s390_r13, 0, s390_r6, 0);                       \
294         s390_stg (code, s390_r0, 0, s390_r6, 0);                        \
295 } while (0)
296
297 /*========================= End of Function ========================*/
298
299 #endif /* __MONO_MINI_S390X_H__ */