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
];
59 * This structure is an extension of MonoLMF and contains extra information.
63 gboolean debugger_invoke
;
64 MonoContext ctx
; /* if debugger_invoke is TRUE */
67 typedef struct MonoCompileArch
{
68 int fp_conv_var_offset
;
72 * ILP32 uses a version of the ppc64 abi with sizeof(void*)==sizeof(long)==4.
73 * To support this, code needs to follow the following conventions:
74 * - for the size of a pointer use sizeof (gpointer)
75 * - for the size of a register/stack slot use SIZEOF_REGISTER.
76 * - for variables which contain values of registers, use mgreg_t.
77 * - for loading/saving pointers/ints, use the normal ppc_load_reg/ppc_save_reg ()
79 * - for loading/saving register sized quantities, use the ppc_ldr/ppc_str
81 * - make sure to not mix the two kinds of macros for the same memory location,
82 * since ppc is big endian, so a 8 byte store followed by a 4 byte load will
83 * load the upper 32 bit of the value.
84 * - use OP_LOADR_MEMBASE/OP_STORER_MEMBASE to load/store register sized
89 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
90 #define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
91 #define MONO_ARCH_HAVE_ATOMIC_ADD 1
92 #define PPC_USES_FUNCTION_DESCRIPTOR
94 #ifndef __mono_ilp32__
95 #define MONO_ARCH_HAVE_TLS_GET 1
96 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
99 #else /* must be __mono_ppc__ */
102 /* enabling this for PPC32 causes hangs in the thread/delegate tests.
103 So disable for now. */
104 #if defined(__linux__)
105 #define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
109 #define MONO_ARCH_HAVE_TLS_GET 1
110 #define MONO_ARCH_EMULATE_FCONV_TO_I8 1
111 #define MONO_ARCH_EMULATE_LCONV_TO_R8 1
112 #define MONO_ARCH_EMULATE_LCONV_TO_R4 1
115 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
116 #define MONO_ARCH_EMULATE_FREM 1
117 #define MONO_ARCH_BIGMUL_INTRINS 1
118 #define MONO_ARCH_HAVE_ATOMIC_CAS 1
120 /* Parameters used by the register allocator */
121 #define MONO_ARCH_CALLEE_REGS ((0xff << ppc_r3) | (1 << ppc_r11) | (1 << ppc_r12))
122 #define MONO_ARCH_CALLEE_SAVED_REGS (0xfffff << ppc_r13) /* ppc_13 - ppc_31 */
124 #if defined(__APPLE__) || defined(__mono_ppc64__)
125 #define MONO_ARCH_CALLEE_FREGS (0x1fff << ppc_f1)
127 #define MONO_ARCH_CALLEE_FREGS (0xff << ppc_f1)
129 #define MONO_ARCH_CALLEE_SAVED_FREGS (~(MONO_ARCH_CALLEE_FREGS | 1))
131 #define MONO_ARCH_USE_FPSTACK FALSE
132 #define MONO_ARCH_FPSTACK_SIZE 0
134 #ifdef __mono_ppc64__
135 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'a')? ppc_r3:\
136 ((desc) == 'g'? ppc_f1:-1))
137 #define MONO_ARCH_INST_IS_REGPAIR(desc) FALSE
138 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (-1)
140 #define MONO_ARCH_INST_FIXED_REG(desc) (((desc) == 'a')? ppc_r3:\
141 ((desc) == 'l')? ppc_r4:\
142 ((desc) == 'g'? ppc_f1:-1))
143 #define MONO_ARCH_INST_IS_REGPAIR(desc) (desc == 'l')
144 #define MONO_ARCH_INST_REGPAIR_REG2(desc,hreg1) (desc == 'l' ? ppc_r3 : -1)
147 #define MONO_ARCH_INST_SREG2_MASK(ins) (0)
149 #define MONO_ARCH_INST_IS_FLOAT(desc) ((desc == 'f') || (desc == 'g'))
151 /* deal with some of the ABI differences here */
153 #define PPC_RET_ADDR_OFFSET 8
154 #define PPC_STACK_PARAM_OFFSET 24
155 #define PPC_MINIMAL_STACK_SIZE 24
156 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
157 #define PPC_FIRST_ARG_REG ppc_r3
158 #define PPC_LAST_ARG_REG ppc_r10
159 #define PPC_FIRST_FPARG_REG ppc_f1
160 #define PPC_LAST_FPARG_REG ppc_f13
161 #define PPC_PASS_STRUCTS_BY_VALUE 1
164 #ifdef __mono_ppc64__
165 #define PPC_RET_ADDR_OFFSET 16
166 #define PPC_STACK_PARAM_OFFSET 48
167 #define PPC_MINIMAL_STACK_SIZE 48
168 #define PPC_MINIMAL_PARAM_AREA_SIZE 64
169 #define PPC_LAST_FPARG_REG ppc_f13
170 #define PPC_PASS_STRUCTS_BY_VALUE 1
171 #define PPC_SMALL_RET_STRUCT_IN_REG 0
172 #define PPC_THREAD_PTR_REG ppc_r13
174 #define PPC_RET_ADDR_OFFSET 4
175 #define PPC_STACK_PARAM_OFFSET 8
176 #define PPC_MINIMAL_STACK_SIZE 8
177 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
178 #define PPC_LAST_FPARG_REG ppc_f8
179 #define PPC_PASS_STRUCTS_BY_VALUE 0
180 #define PPC_SMALL_RET_STRUCT_IN_REG 1
181 #define PPC_THREAD_PTR_REG ppc_r2
183 #define PPC_FIRST_ARG_REG ppc_r3
184 #define PPC_LAST_ARG_REG ppc_r10
185 #define PPC_FIRST_FPARG_REG ppc_f1
188 #if defined(HAVE_WORKING_SIGALTSTACK) && !defined(__APPLE__)
189 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK 1
190 #define MONO_ARCH_SIGNAL_STACK_SIZE (12 * 1024)
191 #endif /* HAVE_WORKING_SIGALTSTACK */
193 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
194 #define MONO_ARCH_HAVE_IMT 1
195 #define MONO_ARCH_IMT_REG ppc_r12
197 #define MONO_ARCH_VTABLE_REG ppc_r12
198 #define MONO_ARCH_RGCTX_REG ppc_r12
200 #define MONO_ARCH_NO_IOV_CHECK 1
201 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
202 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
204 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
205 #define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
207 #define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
208 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
209 #define MONO_ARCH_HAVE_XP_UNWIND 1
210 #define MONO_ARCH_HAVE_FIND_JIT_INFO_EXT 1
212 #define MONO_ARCH_GSHARED_SUPPORTED 1
214 #define MONO_ARCH_NEED_DIV_CHECK 1
215 #define MONO_ARCH_AOT_SUPPORTED 1
216 #define MONO_ARCH_NEED_GOT_VAR 1
217 #if !defined(MONO_CROSS_COMPILE) && !defined(TARGET_PS3)
218 #define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
221 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
222 #define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
224 /* we have the stack pointer, not the base pointer in sigcontext */
225 #define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (gulong)ip; } while (0);
226 /* FIXME: should be called SET_SP */
227 #define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (gulong)bp; } while (0);
229 #define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
230 #define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs [ppc_r31-13]))
231 #define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
233 #ifdef MONO_CROSS_COMPILE
237 unsigned long unused1
;
241 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) g_assert_not_reached ()
243 #elif defined(__APPLE__)
247 unsigned long unused1
;
251 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
253 __asm__ volatile("mr %0,r1" : "=r" (r1)); \
254 MONO_CONTEXT_SET_BP ((ctx), r1); \
255 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
262 #ifdef __mono_ppc64__
268 #ifdef G_COMPILER_CODEWARRIOR
269 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
270 register gpointer r1_var; \
271 asm { mr r1_var, r1 }; \
272 MONO_CONTEXT_SET_BP ((ctx), r1); \
273 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
277 #define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) do { \
279 __asm__ volatile("mr %0,1" : "=r" (r1)); \
280 MONO_CONTEXT_SET_BP ((ctx), r1); \
281 MONO_CONTEXT_SET_IP ((ctx), (start_func)); \
294 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
299 } MonoPPCFunctionDescriptor
;
301 #define PPC_FTNPTR_SIZE sizeof (MonoPPCFunctionDescriptor)
302 extern guint8
* mono_ppc_create_pre_code_ftnptr (guint8
*code
) MONO_INTERNAL
;
304 #define PPC_FTNPTR_SIZE 0
305 #define mono_ppc_create_pre_code_ftnptr(c) c
308 #if defined(__linux__)
309 #define MONO_ARCH_USE_SIGACTION 1
310 #elif defined (__APPLE__) && defined (_STRUCT_MCONTEXT)
311 #define MONO_ARCH_USE_SIGACTION 1
312 #elif defined (__APPLE__) && !defined (_STRUCT_MCONTEXT)
313 #define MONO_ARCH_USE_SIGACTION 1
314 #elif defined(__NetBSD__)
315 #define MONO_ARCH_USE_SIGACTION 1
316 #elif defined(__FreeBSD__)
317 #define MONO_ARCH_USE_SIGACTION 1
318 #elif defined(MONO_CROSS_COMPILE)
319 typedef MonoContext ucontext_t
;
323 #define UCONTEXT_REG_Rn(ctx, n)
324 #define UCONTEXT_REG_FPRn(ctx, n)
325 #define UCONTEXT_REG_NIP(ctx)
326 #define UCONTEXT_REG_LNK(ctx)
329 /* For other operating systems, we pull the definition from an external file */
330 #include "mini-ppc-os.h"
334 mono_ppc_patch (guchar
*code
, const guchar
*target
) MONO_INTERNAL
;
337 mono_ppc_throw_exception (MonoObject
*exc
, unsigned long eip
, unsigned long esp
, mgreg_t
*int_regs
, gdouble
*fp_regs
, gboolean rethrow
) MONO_INTERNAL
;
339 #ifdef __mono_ppc64__
340 #define MONO_PPC_32_64_CASE(c32,c64) c64
341 extern void mono_ppc_emitted (guint8
*code
, gint64 length
, const char *format
, ...);
343 #define MONO_PPC_32_64_CASE(c32,c64) c32
346 gboolean
mono_ppc_is_direct_call_sequence (guint32
*code
) MONO_INTERNAL
;
348 void mono_ppc_patch_plt_entry (guint8
*code
, gpointer
*got
, mgreg_t
*regs
, guint8
*addr
) MONO_INTERNAL
;
350 void mono_ppc_set_func_into_sigctx (void *sigctx
, void *func
) MONO_INTERNAL
;
352 #endif /* __MONO_MINI_PPC_H__ */