#define __MONO_MINI_PPC_H__
#include <mono/arch/ppc/ppc-codegen.h>
+#include <mono/utils/mono-sigcontext.h>
#include <glib.h>
#ifdef __mono_ppc64__
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 */
};
typedef struct {
gulong sc_ir; // pc
gulong sc_sp; // r1
- gulong regs [MONO_SAVED_GREGS];
+ mgreg_t regs [MONO_SAVED_GREGS];
double fregs [MONO_SAVED_FREGS];
} MonoContext;
+/*
+ * This structure is an extension of MonoLMF and contains extra information.
+ */
+typedef struct {
+ struct MonoLMF lmf;
+ gboolean debugger_invoke;
+ MonoContext ctx; /* if debugger_invoke is TRUE */
+} MonoLMFExt;
+
typedef struct MonoCompileArch {
int fp_conv_var_offset;
} MonoCompileArch;
+/*
+ * ILP32 uses a version of the ppc64 abi with sizeof(void*)==sizeof(long)==4.
+ * 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
#define PPC_USES_FUNCTION_DESCRIPTOR
+
+#ifndef __mono_ilp32__
#define MONO_ARCH_HAVE_TLS_GET 1
#define MONO_ARCH_ENABLE_MONITOR_IL_FASTPATH 1
+#endif
+
#else /* must be __mono_ppc__ */
+
#if 0
/* enabling this for PPC32 causes hangs in the thread/delegate tests.
So disable for now. */
#define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
-#ifndef __mono_ppc64__
#define MONO_ARCH_HAVE_STATIC_RGCTX_TRAMPOLINE 1
-#endif
+#define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
+#define MONO_ARCH_HAVE_XP_UNWIND 1
+
+#define MONO_ARCH_GSHARED_SUPPORTED 1
#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_THIS_AS_FIRST_ARG 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)
#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_SET_SP(ctx,sp) do { (ctx)->sc_sp = (gulong)sp; } 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 __APPLE__
+#ifdef MONO_CROSS_COMPILE
+
+typedef struct {
+ unsigned long sp;
+ unsigned long unused1;
+ unsigned long lr;
+} MonoPPCStackFrame;
+
+#define MONO_INIT_CONTEXT_FROM_FUNC(ctx,start_func) g_assert_not_reached ()
+
+#elif defined(__APPLE__)
typedef struct {
unsigned long sp;
#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
#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
+void
+mono_ppc_patch (guchar *code, const guchar *target) MONO_INTERNAL;
+
+void
+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
-extern gboolean mono_ppc_is_direct_call_sequence (guint32 *code);
+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__ */