From bf8e3967e4809923d99159ebfa294daf897b5c29 Mon Sep 17 00:00:00 2001
From: Zoltan Varga <vargaz@gmail.com>
Date: Mon, 10 Nov 2014 05:22:04 -0500
Subject: [PATCH] [jit] Move the ppc sigctx<->monoctx conversion code to
 mono-context.c.

Backported from upstream commit
7e056cd346ccab104715e19d51d0ceccd51b696d by Thomas Petazzoni
<thomas.petazzoni@free-electrons.com>.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 mono/mini/exceptions-ppc.c | 22 ++--------------------
 mono/utils/mono-context.c  | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/mono/mini/exceptions-ppc.c b/mono/mini/exceptions-ppc.c
index 6c3878e..9b9dbef 100644
--- a/mono/mini/exceptions-ppc.c
+++ b/mono/mini/exceptions-ppc.c
@@ -600,31 +600,13 @@ mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls,
 void
 mono_arch_sigctx_to_monoctx (void *ctx, MonoContext *mctx)
 {
-#ifdef MONO_CROSS_COMPILE
-	g_assert_not_reached ();
-#else
-	os_ucontext *uc = ctx;
-
-	mctx->sc_ir = UCONTEXT_REG_NIP(uc);
-	mctx->sc_sp = UCONTEXT_REG_Rn(uc, 1);
-	memcpy (&mctx->regs, &UCONTEXT_REG_Rn(uc, 13), sizeof (mgreg_t) * MONO_SAVED_GREGS);
-	memcpy (&mctx->fregs, &UCONTEXT_REG_FPRn(uc, 14), sizeof (double) * MONO_SAVED_FREGS);
-#endif
+	return mono_sigctx_to_monoctx (ctx, mctx);
 }
 
 void
 mono_arch_monoctx_to_sigctx (MonoContext *mctx, void *ctx)
 {
-#ifdef MONO_CROSS_COMPILE
-	g_assert_not_reached ();
-#else
-	os_ucontext *uc = ctx;
-
-	UCONTEXT_REG_NIP(uc) = mctx->sc_ir;
-	UCONTEXT_REG_Rn(uc, 1) = mctx->sc_sp;
-	memcpy (&UCONTEXT_REG_Rn(uc, 13), &mctx->regs, sizeof (mgreg_t) * MONO_SAVED_GREGS);
-	memcpy (&UCONTEXT_REG_FPRn(uc, 14), &mctx->fregs, sizeof (double) * MONO_SAVED_FREGS);
-#endif
+	return mono_monoctx_to_sigctx (mctx, ctx);
 }
 
 gpointer
diff --git a/mono/utils/mono-context.c b/mono/utils/mono-context.c
index c52d044..689bf86 100644
--- a/mono/utils/mono-context.c
+++ b/mono/utils/mono-context.c
@@ -421,4 +421,30 @@ mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx)
 	}
 }
 
+#elif (((defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__)) && !defined(MONO_CROSS_COMPILE))) || (defined(TARGET_POWERPC))
+
+#include <mono/utils/mono-context.h>
+
+void
+mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx)
+{
+	os_ucontext *uc = sigctx;
+
+	mctx->sc_ir = UCONTEXT_REG_NIP(uc);
+	mctx->sc_sp = UCONTEXT_REG_Rn(uc, 1);
+	memcpy (&mctx->regs, &UCONTEXT_REG_Rn(uc, 13), sizeof (mgreg_t) * MONO_SAVED_GREGS);
+	memcpy (&mctx->fregs, &UCONTEXT_REG_FPRn(uc, 14), sizeof (double) * MONO_SAVED_FREGS);
+}
+
+void
+mono_monoctx_to_sigctx (MonoContext *mctx, void *sigctx)
+{
+	os_ucontext *uc = sigctx;
+
+	UCONTEXT_REG_NIP(uc) = mctx->sc_ir;
+	UCONTEXT_REG_Rn(uc, 1) = mctx->sc_sp;
+	memcpy (&UCONTEXT_REG_Rn(uc, 13), &mctx->regs, sizeof (mgreg_t) * MONO_SAVED_GREGS);
+	memcpy (&UCONTEXT_REG_FPRn(uc, 14), &mctx->fregs, sizeof (double) * MONO_SAVED_FREGS);
+}
+
 #endif /* #if defined(__i386__) */
-- 
2.1.0

