Merge remote-tracking branch 'mfoliveira/ppc64el-v2'
[mono.git] / mono / mini / mini-ppc.h
index fb35e2a60f85f02b92a9bd822ccbbdc1dfb9e045..2a9af123de4d3d816136fb52c5d504b2e09c7517 100644 (file)
@@ -2,6 +2,8 @@
 #define __MONO_MINI_PPC_H__
 
 #include <mono/arch/ppc/ppc-codegen.h>
+#include <mono/utils/mono-sigcontext.h>
+#include <mono/utils/mono-context.h>
 #include <glib.h>
 
 #ifdef __mono_ppc64__
@@ -26,27 +28,21 @@ void ppc_patch (guchar *code, const guchar *target);
 void ppc_patch_full (guchar *code, const guchar *target, gboolean is_fd);
 
 struct MonoLMF {
+       /*
+        * If the second lowest bit is set to 1, then this is a MonoLMFExt structure, and
+        * the other fields are not valid.
+        */
        gpointer    previous_lmf;
        gpointer    lmf_addr;
        MonoMethod *method;
        gulong     ebp;
        gulong     eip;
-       gulong     iregs [MONO_SAVED_GREGS]; /* 13..31 */
+       /* Add a dummy field to force iregs to be aligned when cross compiling from x86 */
+       gulong     dummy;
+       mgreg_t    iregs [MONO_SAVED_GREGS]; /* 13..31 */
        gdouble    fregs [MONO_SAVED_FREGS]; /* 14..31 */
 };
 
-/* we define our own structure and we'll copy the data
- * from sigcontext/ucontext/mach when we need it.
- * This also makes us save stack space and time when copying
- * We might also want to add an additional field to propagate
- * the original context from the signal handler.
- */
-typedef struct {
-       gulong sc_ir;          // pc 
-       gulong sc_sp;          // r1
-       gulong regs [MONO_SAVED_GREGS];
-       double fregs [MONO_SAVED_FREGS];
-} MonoContext;
 
 typedef struct MonoCompileArch {
        int fp_conv_var_offset;
@@ -54,16 +50,31 @@ typedef struct MonoCompileArch {
 
 /*
  * ILP32 uses a version of the ppc64 abi with sizeof(void*)==sizeof(long)==4.
- * To support this, code which needs the size of a pointer needs to use 
- * sizeof (gpointer), while code which needs the size of a register/stack slot 
- * needs to use SIZEOF_REGISTER.
+ * To support this, code needs to follow the following conventions:
+ * - for the size of a pointer use sizeof (gpointer)
+ * - for the size of a register/stack slot use SIZEOF_REGISTER.
+ * - for variables which contain values of registers, use mgreg_t.
+ * - for loading/saving pointers/ints, use the normal ppc_load_reg/ppc_save_reg ()
+ *   macros.
+ * - for loading/saving register sized quantities, use the ppc_ldr/ppc_str 
+ *   macros.
+ * - make sure to not mix the two kinds of macros for the same memory location, 
+ *   since ppc is big endian, so a 8 byte store followed by a 4 byte load will
+ *   load the upper 32 bit of the value.
+ * - use OP_LOADR_MEMBASE/OP_STORER_MEMBASE to load/store register sized
+ *   quantities.
  */
 
 #ifdef __mono_ppc64__
 #define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS
 #define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS
-#define MONO_ARCH_HAVE_ATOMIC_ADD 1
+
+/* ELFv2 ABI doesn't use function descriptors.  */
+#if _CALL_ELF == 2
+#undef PPC_USES_FUNCTION_DESCRIPTOR
+#else
 #define PPC_USES_FUNCTION_DESCRIPTOR
+#endif
 
 #ifndef __mono_ilp32__
 #define MONO_ARCH_HAVE_TLS_GET 1
@@ -88,11 +99,10 @@ typedef struct MonoCompileArch {
 
 #define MONO_ARCH_EMULATE_LCONV_TO_R8_UN 1
 #define MONO_ARCH_EMULATE_FREM 1
-#define MONO_ARCH_BIGMUL_INTRINS 1
-#define MONO_ARCH_HAVE_ATOMIC_CAS 1
+#define MONO_ARCH_GC_MAPS_SUPPORTED 1
 
 /* Parameters used by the register allocator */
-#define MONO_ARCH_CALLEE_REGS ((0xff << ppc_r3) | (1 << ppc_r11) | (1 << ppc_r12))
+#define MONO_ARCH_CALLEE_REGS ((0xff << ppc_r3) | (1 << ppc_r12) | (1 << ppc_r11))
 #define MONO_ARCH_CALLEE_SAVED_REGS (0xfffff << ppc_r13) /* ppc_13 - ppc_31 */
 
 #if defined(__APPLE__) || defined(__mono_ppc64__)
@@ -142,7 +152,6 @@ typedef struct MonoCompileArch {
 #define PPC_MINIMAL_PARAM_AREA_SIZE 64
 #define PPC_LAST_FPARG_REG ppc_f13
 #define PPC_PASS_STRUCTS_BY_VALUE 1
-#define PPC_SMALL_RET_STRUCT_IN_REG 0
 #define PPC_THREAD_PTR_REG ppc_r13
 #else
 #define PPC_RET_ADDR_OFFSET 4
@@ -151,7 +160,6 @@ typedef struct MonoCompileArch {
 #define PPC_MINIMAL_PARAM_AREA_SIZE 0
 #define PPC_LAST_FPARG_REG ppc_f8
 #define PPC_PASS_STRUCTS_BY_VALUE 0
-#define PPC_SMALL_RET_STRUCT_IN_REG 1
 #define PPC_THREAD_PTR_REG ppc_r2
 #endif
 #define PPC_FIRST_ARG_REG ppc_r3
@@ -159,26 +167,25 @@ typedef struct MonoCompileArch {
 #define PPC_FIRST_FPARG_REG ppc_f1
 #endif
 
+#define PPC_CALL_REG ppc_r12
+
 #if defined(HAVE_WORKING_SIGALTSTACK) && !defined(__APPLE__)
 #define MONO_ARCH_SIGSEGV_ON_ALTSTACK 1
 #define MONO_ARCH_SIGNAL_STACK_SIZE (12 * 1024)
 #endif /* HAVE_WORKING_SIGALTSTACK */
 
 #define MONO_ARCH_HAVE_CREATE_DELEGATE_TRAMPOLINE
-#define MONO_ARCH_HAVE_IMT 1
-#define MONO_ARCH_IMT_REG ppc_r12
+#define MONO_ARCH_IMT_REG ppc_r11
 
-#define MONO_ARCH_VTABLE_REG   ppc_r12
-#define MONO_ARCH_RGCTX_REG    ppc_r12
+#define MONO_ARCH_VTABLE_REG   ppc_r11
+#define MONO_ARCH_RGCTX_REG    MONO_ARCH_IMT_REG
 
 #define MONO_ARCH_NO_IOV_CHECK 1
 #define MONO_ARCH_HAVE_DECOMPOSE_OPTS 1
 #define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
 
 #define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
-#define MONO_ARCH_HAVE_THROW_CORLIB_EXCEPTION 1
 
-#define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
 #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
 
 #define MONO_ARCH_GSHARED_SUPPORTED 1
@@ -186,18 +193,12 @@ typedef struct MonoCompileArch {
 #define MONO_ARCH_NEED_DIV_CHECK 1
 #define MONO_ARCH_AOT_SUPPORTED 1
 #define MONO_ARCH_NEED_GOT_VAR 1
+#if !defined(MONO_CROSS_COMPILE) && !defined(TARGET_PS3)
+#define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
+#endif
+#define MONO_ARCH_HAVE_OP_TAIL_CALL 1
 
 #define PPC_NUM_REG_ARGS (PPC_LAST_ARG_REG-PPC_FIRST_ARG_REG+1)
-#define PPC_NUM_REG_FPARGS (PPC_LAST_FPARG_REG-PPC_FIRST_FPARG_REG+1)
-
-/* we have the stack pointer, not the base pointer in sigcontext */
-#define MONO_CONTEXT_SET_IP(ctx,ip) do { (ctx)->sc_ir = (gulong)ip; } while (0);
-/* FIXME: should be called SET_SP */
-#define MONO_CONTEXT_SET_BP(ctx,bp) do { (ctx)->sc_sp = (gulong)bp; } while (0);
-
-#define MONO_CONTEXT_GET_IP(ctx) ((gpointer)((ctx)->sc_ir))
-#define MONO_CONTEXT_GET_BP(ctx) ((gpointer)((ctx)->regs [ppc_r31-13]))
-#define MONO_CONTEXT_GET_SP(ctx) ((gpointer)((ctx)->sc_sp))
 
 #ifdef MONO_CROSS_COMPILE
 
@@ -227,11 +228,11 @@ typedef struct {
 #else
 
 typedef struct {
-       unsigned long sp;
+       mgreg_t sp;
 #ifdef __mono_ppc64__
-       unsigned long cr;
+       mgreg_t cr;
 #endif
-       unsigned long lr;
+       mgreg_t lr;
 } MonoPPCStackFrame;
 
 #ifdef G_COMPILER_CODEWARRIOR
@@ -253,6 +254,8 @@ typedef struct {
 #endif
 #endif
 
+#define MONO_ARCH_INIT_TOP_LMF_ENTRY(lmf) do { (lmf)->ebp = -1; } while (0)
+
 typedef struct {
        gint8 reg;
        gint8 size;
@@ -275,59 +278,42 @@ extern guint8* mono_ppc_create_pre_code_ftnptr (guint8 *code) MONO_INTERNAL;
 #endif
 
 #if defined(__linux__)
-       typedef struct ucontext os_ucontext;
-
 #define MONO_ARCH_USE_SIGACTION 1
-
-#ifdef __mono_ppc64__
-       #define UCONTEXT_REG_Rn(ctx, n)   ((ctx)->uc_mcontext.gp_regs [(n)])
-       #define UCONTEXT_REG_FPRn(ctx, n) ((ctx)->uc_mcontext.fp_regs [(n)])
-       #define UCONTEXT_REG_NIP(ctx)     ((ctx)->uc_mcontext.gp_regs [PT_NIP])
-       #define UCONTEXT_REG_LNK(ctx)     ((ctx)->uc_mcontext.gp_regs [PT_LNK])
-#else
-       #define UCONTEXT_REG_Rn(ctx, n)   ((ctx)->uc_mcontext.uc_regs->gregs [(n)])
-       #define UCONTEXT_REG_FPRn(ctx, n) ((ctx)->uc_mcontext.uc_regs->fpregs.fpregs [(n)])
-       #define UCONTEXT_REG_NIP(ctx)     ((ctx)->uc_mcontext.uc_regs->gregs [PT_NIP])
-       #define UCONTEXT_REG_LNK(ctx)     ((ctx)->uc_mcontext.uc_regs->gregs [PT_LNK])
-#endif
 #elif defined (__APPLE__) && defined (_STRUCT_MCONTEXT)
 #define MONO_ARCH_USE_SIGACTION 1
-       typedef struct __darwin_ucontext os_ucontext;
-
-       #define UCONTEXT_REG_Rn(ctx, n)   ((&(ctx)->uc_mcontext->__ss.__r0) [(n)])
-       #define UCONTEXT_REG_FPRn(ctx, n) ((ctx)->uc_mcontext->__fs.__fpregs [(n)])
-       #define UCONTEXT_REG_NIP(ctx)     ((ctx)->uc_mcontext->__ss.__srr0)
-       #define UCONTEXT_REG_LNK(ctx)     ((ctx)->uc_mcontext->__ss.__lr)
 #elif defined (__APPLE__) && !defined (_STRUCT_MCONTEXT)
 #define MONO_ARCH_USE_SIGACTION 1
-       typedef struct ucontext os_ucontext;
-
-       #define UCONTEXT_REG_Rn(ctx, n)   ((&(ctx)->uc_mcontext->ss.r0) [(n)])
-       #define UCONTEXT_REG_FPRn(ctx, n) ((ctx)->uc_mcontext->fs.fpregs [(n)])
-       #define UCONTEXT_REG_NIP(ctx)     ((ctx)->uc_mcontext->ss.srr0)
-       #define UCONTEXT_REG_LNK(ctx)     ((ctx)->uc_mcontext->ss.lr)
 #elif defined(__NetBSD__)
 #define MONO_ARCH_USE_SIGACTION 1
-       typedef ucontext_t os_ucontext;
+#elif defined(__FreeBSD__)
+#define MONO_ARCH_USE_SIGACTION 1
+#elif defined(MONO_CROSS_COMPILE)
+       typedef MonoContext ucontext_t;
+/*     typedef struct {
+               int dummy;
+       } ucontext_t;*/
+       #define UCONTEXT_REG_Rn(ctx, n)
+       #define UCONTEXT_REG_FPRn(ctx, n)
+       #define UCONTEXT_REG_NIP(ctx)
+       #define UCONTEXT_REG_LNK(ctx)
 
-       #define UCONTEXT_REG_Rn(ctx, n)   ((ctx)->uc_mcontext.__gregs [(n)])
-       #define UCONTEXT_REG_FPRn(ctx, n) ((ctx)->uc_mcontext.__fpregs.__fpu_regs [(n)])
-       #define UCONTEXT_REG_NIP(ctx)     _UC_MACHINE_PC(ctx)
-       #define UCONTEXT_REG_LNK(ctx)     ((ctx)->uc_mcontext.__gregs [_REG_LR])
 #else
 /* For other operating systems, we pull the definition from an external file */
 #include "mini-ppc-os.h"
 #endif
 
+gboolean
+mono_ppc_tail_call_supported (MonoMethodSignature *caller_sig, MonoMethodSignature *callee_sig) MONO_INTERNAL;
+
 void
 mono_ppc_patch (guchar *code, const guchar *target) MONO_INTERNAL;
 
 void
-mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gulong *int_regs, gdouble *fp_regs, gboolean rethrow) MONO_INTERNAL;
+mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, mgreg_t *int_regs, gdouble *fp_regs, gboolean rethrow) MONO_INTERNAL;
 
 #ifdef __mono_ppc64__
 #define MONO_PPC_32_64_CASE(c32,c64)   c64
-extern void mono_ppc_emitted (guint8 *code, ssize_t length, const char *format, ...);
+extern void mono_ppc_emitted (guint8 *code, gint64 length, const char *format, ...);
 #else
 #define MONO_PPC_32_64_CASE(c32,c64)   c32
 #endif
@@ -336,4 +322,6 @@ gboolean mono_ppc_is_direct_call_sequence (guint32 *code) MONO_INTERNAL;
 
 void mono_ppc_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr) MONO_INTERNAL;
 
+void mono_ppc_set_func_into_sigctx (void *sigctx, void *func) MONO_INTERNAL;
+
 #endif /* __MONO_MINI_PPC_H__ */