Treat CEE_BREAK the same as Debugger:Break (), i.e. route it through sdb.
[mono-project/dkf.git] / mono / mini / mini-ppc.h
blob7346b654c573024beb79fe79ced0f087d7a8f33f
1 #ifndef __MONO_MINI_PPC_H__
2 #define __MONO_MINI_PPC_H__
4 #include <mono/arch/ppc/ppc-codegen.h>
5 #include <mono/utils/mono-sigcontext.h>
6 #include <mono/utils/mono-context.h>
7 #include <glib.h>
9 #ifdef __mono_ppc64__
10 #define MONO_ARCH_CPU_SPEC ppc64_cpu_desc
11 #else
12 #define MONO_ARCH_CPU_SPEC ppcg4
13 #endif
15 #define MONO_MAX_IREGS 32
16 #define MONO_MAX_FREGS 32
18 #define MONO_SAVED_GREGS 19
19 #define MONO_SAVED_FREGS 18
21 #define MONO_ARCH_FRAME_ALIGNMENT 16
23 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
24 * reproduceable results for benchmarks */
25 #define MONO_ARCH_CODE_ALIGNMENT 32
27 void ppc_patch (guchar *code, const guchar *target);
28 void ppc_patch_full (guchar *code, const guchar *target, gboolean is_fd);
30 struct MonoLMF {
32 * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and
33 * the other fields are not valid.
35 gpointer previous_lmf;
36 gpointer lmf_addr;
37 MonoMethod *method;
38 gulong ebp;
39 gulong eip;
40 /* Add a dummy field to force iregs to be aligned when cross compiling from x86 */
41 gulong dummy;
42 mgreg_t iregs [MONO_SAVED_GREGS]; /* 13..31 */
43 gdouble fregs [MONO_SAVED_FREGS]; /* 14..31 */
47 typedef struct MonoCompileArch {
48 int fp_conv_var_offset;
49 } MonoCompileArch;
52 * ILP32 uses a version of the ppc64 abi with sizeof(void*)==sizeof(long)==4.
53 * To support this, code needs to follow the following conventions:
54 * - for the size of a pointer use sizeof (gpointer)
55 * - for the size of a register/stack slot use SIZEOF_REGISTER.
56 * - for variables which contain values of registers, use mgreg_t.
57 * - for loading/saving pointers/ints, use the normal ppc_load_reg/ppc_save_reg ()
58 * macros.
59 * - for loading/saving register sized quantities, use the ppc_ldr/ppc_str
60 * macros.
61 * - make sure to not mix the two kinds of macros for the same memory location,
62 * since ppc is big endian, so a 8 byte store followed by a 4 byte load will
63 * load the upper 32 bit of the value.
64 * - use OP_LOADR_MEMBASE/OP_STORER_MEMBASE to load/store register sized
65 * quantities.
68 #ifdef __mono_ppc64__
69 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
70 #define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
71 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
72 #define PPC_USES_FUNCTION_DESCRIPTOR
74 #ifndef __mono_ilp32__
75 #define MONO_ARCH_HAVE_TLS_GET 1
76 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
77 #endif
79 #else /* must be __mono_ppc__ */
81 #if 0
82 /* enabling this for PPC32 causes hangs in the thread/delegate tests.
83 So disable for now. */
84 #if defined(__linux__)
85 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
86 #endif
87 #endif
89 #define MONO_ARCH_HAVE_TLS_GET 1
90 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
91 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
92 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
93 #endif
95 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
96 #define MONO_ARCH_EMULATE_FREM 1
97 #define MONO_ARCH_BIGMUL_INTRINS 1
98 #define MONO_ARCH_HAVE_ATOMIC_CAS 1
100 /* Parameters used by the register allocator */
101 #define MONO_ARCH_CALLEE_REGS ((0xff << ppc_r3) | (1 << ppc_r11) | (1 << ppc_r12))
102 #define MONO_ARCH_CALLEE_SAVED_REGS (0xfffff << ppc_r13) /* ppc_13 - ppc_31 */
104 #if defined(__APPLE__) || defined(__mono_ppc64__)
105 #define MONO_ARCH_CALLEE_FREGS (0x1fff << ppc_f1)
106 #else
107 #define MONO_ARCH_CALLEE_FREGS (0xff << ppc_f1)
108 #endif
109 #define MONO_ARCH_CALLEE_SAVED_FREGS (~(MONO_ARCH_CALLEE_FREGS | 1))
111 #define MONO_ARCH_USE_FPSTACK FALSE
112 #define MONO_ARCH_FPSTACK_SIZE 0
114 #ifdef __mono_ppc64__
115 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'a')? ppc_r3:\
116 ((desc) == 'g'? ppc_f1:-1))
117 #define MONO_ARCH_INST_IS_REGPAIR(desc) FALSE
118 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (-1)
119 #else
120 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'a')? ppc_r3:\
121 ((desc) == 'l')? ppc_r4:\
122 ((desc) == 'g'? ppc_f1:-1))
123 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l')
124 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? ppc_r3 : -1)
125 #endif
127 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
129 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
131 /* deal with some of the ABI differences here */
132 #ifdef __APPLE__
133 #define PPC_RET_ADDR_OFFSET 8
134 #define PPC_STACK_PARAM_OFFSET 24
135 #define PPC_MINIMAL_STACK_SIZE 24
136 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
137 #define PPC_FIRST_ARG_REG ppc_r3
138 #define PPC_LAST_ARG_REG ppc_r10
139 #define PPC_FIRST_FPARG_REG ppc_f1
140 #define PPC_LAST_FPARG_REG ppc_f13
141 #define PPC_PASS_STRUCTS_BY_VALUE 1
142 #else
143 /* Linux */
144 #ifdef __mono_ppc64__
145 #define PPC_RET_ADDR_OFFSET 16
146 #define PPC_STACK_PARAM_OFFSET 48
147 #define PPC_MINIMAL_STACK_SIZE 48
148 #define PPC_MINIMAL_PARAM_AREA_SIZE 64
149 #define PPC_LAST_FPARG_REG ppc_f13
150 #define PPC_PASS_STRUCTS_BY_VALUE 1
151 #define PPC_SMALL_RET_STRUCT_IN_REG 0
152 #define PPC_THREAD_PTR_REG ppc_r13
153 #else
154 #define PPC_RET_ADDR_OFFSET 4
155 #define PPC_STACK_PARAM_OFFSET 8
156 #define PPC_MINIMAL_STACK_SIZE 8
157 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
158 #define PPC_LAST_FPARG_REG ppc_f8
159 #define PPC_PASS_STRUCTS_BY_VALUE 0
160 #define PPC_SMALL_RET_STRUCT_IN_REG 1
161 #define PPC_THREAD_PTR_REG ppc_r2
162 #endif
163 #define PPC_FIRST_ARG_REG ppc_r3
164 #define PPC_LAST_ARG_REG ppc_r10
165 #define PPC_FIRST_FPARG_REG ppc_f1
166 #endif
168 #if defined(HAVE_WORKING_SIGALTSTACK) && !defined(__APPLE__)
169 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK 1
170 #define MONO_ARCH_SIGNAL_STACK_SIZE (12 * 1024)
171 #endif /* HAVE_WORKING_SIGALTSTACK */
173 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
174 #define MONO_ARCH_HAVE_IMT 1
175 #define MONO_ARCH_IMT_REG ppc_r12
177 #define MONO_ARCH_VTABLE_REG ppc_r12
178 #define MONO_ARCH_RGCTX_REG ppc_r12
180 #define MONO_ARCH_NO_IOV_CHECK 1
181 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
182 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
184 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
186 #define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
187 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
188 #define MONO_ARCH_HAVE_XP_UNWIND 1
190 #define MONO_ARCH_GSHARED_SUPPORTED 1
192 #define MONO_ARCH_NEED_DIV_CHECK 1
193 #define MONO_ARCH_AOT_SUPPORTED 1
194 #define MONO_ARCH_NEED_GOT_VAR 1
195 #if !defined(MONO_CROSS_COMPILE) && !defined(TARGET_PS3)
196 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
197 #endif
198 #define MONO_ARCH_THIS_AS_FIRST_ARG 1
200 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
201 #define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
203 #ifdef MONO_CROSS_COMPILE
205 typedef struct {
206 unsigned long sp;
207 unsigned long unused1;
208 unsigned long lr;
209 } MonoPPCStackFrame;
211 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) g_assert_not_reached ()
213 #elif defined(__APPLE__)
215 typedef struct {
216 unsigned long sp;
217 unsigned long unused1;
218 unsigned long lr;
219 } MonoPPCStackFrame;
221 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
222 gpointer r1; \
223 __asm__ volatile("mr %0,r1" : "=r" (r1)); \
224 MONO_CONTEXT_SET_BP ((ctx), r1); \
225 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
226 } while (0)
228 #else
230 typedef struct {
231 mgreg_t sp;
232 #ifdef __mono_ppc64__
233 mgreg_t cr;
234 #endif
235 mgreg_t lr;
236 } MonoPPCStackFrame;
238 #ifdef G_COMPILER_CODEWARRIOR
239 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
240 register gpointer r1_var; \
241 asm { mr r1_var, r1 }; \
242 MONO_CONTEXT_SET_BP ((ctx), r1); \
243 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
244 } while (0)
246 #else
247 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
248 gpointer r1; \
249 __asm__ volatile("mr %0,1" : "=r" (r1)); \
250 MONO_CONTEXT_SET_BP ((ctx), r1); \
251 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
252 } while (0)
254 #endif
255 #endif
257 #define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->ebp = -1; } while (0)
259 typedef struct {
260 gint8 reg;
261 gint8 size;
262 int vtsize;
263 int offset;
264 } MonoPPCArgInfo;
266 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
267 typedef struct {
268 gpointer code;
269 gpointer toc;
270 gpointer env;
271 } MonoPPCFunctionDescriptor;
273 #define PPC_FTNPTR_SIZE sizeof (MonoPPCFunctionDescriptor)
274 extern guint8* mono_ppc_create_pre_code_ftnptr (guint8 *code) MONO_INTERNAL;
275 #else
276 #define PPC_FTNPTR_SIZE 0
277 #define mono_ppc_create_pre_code_ftnptr(c) c
278 #endif
280 #if defined(__linux__)
281 #define MONO_ARCH_USE_SIGACTION 1
282 #elif defined (__APPLE__) && defined (_STRUCT_MCONTEXT)
283 #define MONO_ARCH_USE_SIGACTION 1
284 #elif defined (__APPLE__) && !defined (_STRUCT_MCONTEXT)
285 #define MONO_ARCH_USE_SIGACTION 1
286 #elif defined(__NetBSD__)
287 #define MONO_ARCH_USE_SIGACTION 1
288 #elif defined(__FreeBSD__)
289 #define MONO_ARCH_USE_SIGACTION 1
290 #elif defined(MONO_CROSS_COMPILE)
291 typedef MonoContext ucontext_t;
292 /* typedef struct {
293 int dummy;
294 } ucontext_t;*/
295 #define UCONTEXT_REG_Rn(ctx, n)
296 #define UCONTEXT_REG_FPRn(ctx, n)
297 #define UCONTEXT_REG_NIP(ctx)
298 #define UCONTEXT_REG_LNK(ctx)
300 #else
301 /* For other operating systems, we pull the definition from an external file */
302 #include "mini-ppc-os.h"
303 #endif
305 gboolean
306 mono_ppc_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
308 #define MONO_ARCH_USE_OP_TAIL_CALL(caller_sig, callee_sig) mono_ppc_tail_call_supported (caller_sig, callee_sig)
310 void
311 mono_ppc_patch (guchar *code, const guchar *target) MONO_INTERNAL;
313 void
314 mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, mgreg_t *int_regs, gdouble *fp_regs, gboolean rethrow) MONO_INTERNAL;
316 #ifdef __mono_ppc64__
317 #define MONO_PPC_32_64_CASE(c32,c64) c64
318 extern void mono_ppc_emitted (guint8 *code, gint64 length, const char *format, ...);
319 #else
320 #define MONO_PPC_32_64_CASE(c32,c64) c32
321 #endif
323 gboolean mono_ppc_is_direct_call_sequence (guint32 *code) MONO_INTERNAL;
325 void mono_ppc_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr) MONO_INTERNAL;
327 void mono_ppc_set_func_into_sigctx (void *sigctx, void *func) MONO_INTERNAL;
329 #endif /* __MONO_MINI_PPC_H__ */