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>
9 #define MONO_ARCH_CPU_SPEC ppc64_cpu_desc
11 #define MONO_ARCH_CPU_SPEC ppcg4
14 #define MONO_MAX_IREGS 32
15 #define MONO_MAX_FREGS 32
17 #define MONO_SAVED_GREGS 19
18 #define MONO_SAVED_FREGS 18
20 #define MONO_ARCH_FRAME_ALIGNMENT 16
22 /* fixme: align to 16byte instead of 32byte (we align to 32byte to get
23 * reproduceable results for benchmarks */
24 #define MONO_ARCH_CODE_ALIGNMENT 32
26 void ppc_patch (guchar
*code
, const guchar
*target
);
27 void ppc_patch_full (guchar
*code
, const guchar
*target
, gboolean is_fd
);
31 * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and
32 * the other fields are not valid.
34 gpointer previous_lmf
;
39 /* Add a dummy field to force iregs to be aligned when cross compiling from x86 */
41 mgreg_t iregs
[MONO_SAVED_GREGS
]; /* 13..31 */
42 gdouble fregs
[MONO_SAVED_FREGS
]; /* 14..31 */
45 /* we define our own structure and we'll copy the data
46 * from sigcontext/ucontext/mach when we need it.
47 * This also makes us save stack space and time when copying
48 * We might also want to add an additional field to propagate
49 * the original context from the signal handler.
54 mgreg_t regs
[MONO_SAVED_GREGS
];
55 double fregs
[MONO_SAVED_FREGS
];
58 typedef struct MonoCompileArch
{
59 int fp_conv_var_offset
;
63 * ILP32 uses a version of the ppc64 abi with sizeof(void*)==sizeof(long)==4.
64 * To support this, code needs to follow the following conventions:
65 * - for the size of a pointer use sizeof (gpointer)
66 * - for the size of a register/stack slot use SIZEOF_REGISTER.
67 * - for variables which contain values of registers, use mgreg_t.
68 * - for loading/saving pointers/ints, use the normal ppc_load_reg/ppc_save_reg ()
70 * - for loading/saving register sized quantities, use the ppc_ldr/ppc_str
72 * - make sure to not mix the two kinds of macros for the same memory location,
73 * since ppc is big endian, so a 8 byte store followed by a 4 byte load will
74 * load the upper 32 bit of the value.
75 * - use OP_LOADR_MEMBASE/OP_STORER_MEMBASE to load/store register sized
80 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
81 #define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
82 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
83 #define PPC_USES_FUNCTION_DESCRIPTOR
85 #ifndef __mono_ilp32__
86 #define MONO_ARCH_HAVE_TLS_GET 1
87 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
90 #else /* must be __mono_ppc__ */
93 /* enabling this for PPC32 causes hangs in the thread/delegate tests.
94 So disable for now. */
95 #if defined(__linux__)
96 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
100 #define MONO_ARCH_HAVE_TLS_GET 1
101 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
102 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
103 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
106 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
107 #define MONO_ARCH_EMULATE_FREM 1
108 #define MONO_ARCH_BIGMUL_INTRINS 1
109 #define MONO_ARCH_HAVE_ATOMIC_CAS 1
111 /* Parameters used by the register allocator */
112 #define MONO_ARCH_CALLEE_REGS ((0xff << ppc_r3) | (1 << ppc_r11) | (1 << ppc_r12))
113 #define MONO_ARCH_CALLEE_SAVED_REGS (0xfffff << ppc_r13) /* ppc_13 - ppc_31 */
115 #if defined(__APPLE__) || defined(__mono_ppc64__)
116 #define MONO_ARCH_CALLEE_FREGS (0x1fff << ppc_f1)
118 #define MONO_ARCH_CALLEE_FREGS (0xff << ppc_f1)
120 #define MONO_ARCH_CALLEE_SAVED_FREGS (~(MONO_ARCH_CALLEE_FREGS | 1))
122 #define MONO_ARCH_USE_FPSTACK FALSE
123 #define MONO_ARCH_FPSTACK_SIZE 0
125 #ifdef __mono_ppc64__
126 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'a')? ppc_r3:\
127 ((desc) == 'g'? ppc_f1:-1))
128 #define MONO_ARCH_INST_IS_REGPAIR(desc) FALSE
129 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (-1)
131 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'a')? ppc_r3:\
132 ((desc) == 'l')? ppc_r4:\
133 ((desc) == 'g'? ppc_f1:-1))
134 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l')
135 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? ppc_r3 : -1)
138 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
140 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
142 /* deal with some of the ABI differences here */
144 #define PPC_RET_ADDR_OFFSET 8
145 #define PPC_STACK_PARAM_OFFSET 24
146 #define PPC_MINIMAL_STACK_SIZE 24
147 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
148 #define PPC_FIRST_ARG_REG ppc_r3
149 #define PPC_LAST_ARG_REG ppc_r10
150 #define PPC_FIRST_FPARG_REG ppc_f1
151 #define PPC_LAST_FPARG_REG ppc_f13
152 #define PPC_PASS_STRUCTS_BY_VALUE 1
155 #ifdef __mono_ppc64__
156 #define PPC_RET_ADDR_OFFSET 16
157 #define PPC_STACK_PARAM_OFFSET 48
158 #define PPC_MINIMAL_STACK_SIZE 48
159 #define PPC_MINIMAL_PARAM_AREA_SIZE 64
160 #define PPC_LAST_FPARG_REG ppc_f13
161 #define PPC_PASS_STRUCTS_BY_VALUE 1
162 #define PPC_SMALL_RET_STRUCT_IN_REG 0
163 #define PPC_THREAD_PTR_REG ppc_r13
165 #define PPC_RET_ADDR_OFFSET 4
166 #define PPC_STACK_PARAM_OFFSET 8
167 #define PPC_MINIMAL_STACK_SIZE 8
168 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
169 #define PPC_LAST_FPARG_REG ppc_f8
170 #define PPC_PASS_STRUCTS_BY_VALUE 0
171 #define PPC_SMALL_RET_STRUCT_IN_REG 1
172 #define PPC_THREAD_PTR_REG ppc_r2
174 #define PPC_FIRST_ARG_REG ppc_r3
175 #define PPC_LAST_ARG_REG ppc_r10
176 #define PPC_FIRST_FPARG_REG ppc_f1
179 #if defined(HAVE_WORKING_SIGALTSTACK) && !defined(__APPLE__)
180 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK 1
181 #define MONO_ARCH_SIGNAL_STACK_SIZE (12 * 1024)
182 #endif /* HAVE_WORKING_SIGALTSTACK */
184 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
185 #define MONO_ARCH_HAVE_IMT 1
186 #define MONO_ARCH_IMT_REG ppc_r12
188 #define MONO_ARCH_VTABLE_REG ppc_r12
189 #define MONO_ARCH_RGCTX_REG ppc_r12
191 #define MONO_ARCH_NO_IOV_CHECK 1
192 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
193 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
195 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
197 #define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
198 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
199 #define MONO_ARCH_HAVE_XP_UNWIND 1
201 #define MONO_ARCH_GSHARED_SUPPORTED 1
203 #define MONO_ARCH_NEED_DIV_CHECK 1
204 #define MONO_ARCH_AOT_SUPPORTED 1
205 #define MONO_ARCH_NEED_GOT_VAR 1
206 #if !defined(MONO_CROSS_COMPILE) && !defined(TARGET_PS3)
207 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
209 #define MONO_ARCH_THIS_AS_FIRST_ARG 1
211 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
212 #define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
214 /* we have the stack pointer, not the base pointer in sigcontext */
215 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (gulong)ip; } while (0);
216 /* FIXME: should be called SET_SP */
217 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (gulong)bp; } while (0);
218 #define MONO_CONTEXT_SET_SP(ctx,sp) do { (ctx)->sc_sp = (gulong)sp; } while (0);
220 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
221 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs [ppc_r31-13]))
222 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
224 #ifdef MONO_CROSS_COMPILE
228 unsigned long unused1
;
232 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) g_assert_not_reached ()
234 #elif defined(__APPLE__)
238 unsigned long unused1
;
242 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
244 __asm__ volatile("mr %0,r1" : "=r" (r1)); \
245 MONO_CONTEXT_SET_BP ((ctx), r1); \
246 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
253 #ifdef __mono_ppc64__
259 #ifdef G_COMPILER_CODEWARRIOR
260 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
261 register gpointer r1_var; \
262 asm { mr r1_var, r1 }; \
263 MONO_CONTEXT_SET_BP ((ctx), r1); \
264 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
268 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
270 __asm__ volatile("mr %0,1" : "=r" (r1)); \
271 MONO_CONTEXT_SET_BP ((ctx), r1); \
272 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
278 #define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->ebp = -1; } while (0)
287 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
292 } MonoPPCFunctionDescriptor
;
294 #define PPC_FTNPTR_SIZE sizeof (MonoPPCFunctionDescriptor)
295 extern guint8
* mono_ppc_create_pre_code_ftnptr (guint8
*code
) MONO_INTERNAL
;
297 #define PPC_FTNPTR_SIZE 0
298 #define mono_ppc_create_pre_code_ftnptr(c) c
301 #if defined(__linux__)
302 #define MONO_ARCH_USE_SIGACTION 1
303 #elif defined (__APPLE__) && defined (_STRUCT_MCONTEXT)
304 #define MONO_ARCH_USE_SIGACTION 1
305 #elif defined (__APPLE__) && !defined (_STRUCT_MCONTEXT)
306 #define MONO_ARCH_USE_SIGACTION 1
307 #elif defined(__NetBSD__)
308 #define MONO_ARCH_USE_SIGACTION 1
309 #elif defined(__FreeBSD__)
310 #define MONO_ARCH_USE_SIGACTION 1
311 #elif defined(MONO_CROSS_COMPILE)
312 typedef MonoContext ucontext_t
;
316 #define UCONTEXT_REG_Rn(ctx, n)
317 #define UCONTEXT_REG_FPRn(ctx, n)
318 #define UCONTEXT_REG_NIP(ctx)
319 #define UCONTEXT_REG_LNK(ctx)
322 /* For other operating systems, we pull the definition from an external file */
323 #include "mini-ppc-os.h"
327 mono_ppc_patch (guchar
*code
, const guchar
*target
) MONO_INTERNAL
;
330 mono_ppc_throw_exception (MonoObject
*exc
, unsigned long eip
, unsigned long esp
, mgreg_t
*int_regs
, gdouble
*fp_regs
, gboolean rethrow
) MONO_INTERNAL
;
332 #ifdef __mono_ppc64__
333 #define MONO_PPC_32_64_CASE(c32,c64) c64
334 extern void mono_ppc_emitted (guint8
*code
, gint64 length
, const char *format
, ...);
336 #define MONO_PPC_32_64_CASE(c32,c64) c32
339 gboolean
mono_ppc_is_direct_call_sequence (guint32
*code
) MONO_INTERNAL
;
341 void mono_ppc_patch_plt_entry (guint8
*code
, gpointer
*got
, mgreg_t
*regs
, guint8
*addr
) MONO_INTERNAL
;
343 void mono_ppc_set_func_into_sigctx (void *sigctx
, void *func
) MONO_INTERNAL
;
345 #endif /* __MONO_MINI_PPC_H__ */