Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 mono (3.2.8+dfsg-4) experimental; urgency=low
 .
   * [3930eef] Add missing libmono-winforms2.0-cil dependency to
     libmono-cil-dev.
Author: Jo Shields <directhex@apebox.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- mono-3.2.8+dfsg.orig/configure.in
+++ mono-3.2.8+dfsg/configure.in
@@ -143,6 +143,17 @@ case "$host" in
 		with_sigaltstack=no
 		use_sigposix=yes
 		;;
+	*-*-kfreebsd*-gnu)
+		platform_win32=no
+		CPPFLAGS="$CPPFLAGS -DGC_FREEBSD_THREADS -D_GNU_SOURCE -D_REENTRANT -DUSE_MMAP -DUSE_MUNMAP -DTHREAD_LOCAL_ALLOC -pthread"
+		libmono_cflags="-D_REENTRANT -DTHREAD_LOCAL_ALLOC -pthread"
+		libmono_ldflags="-lpthread -pthread"
+		libdl="-ldl"
+		libgc_threads=pthreads
+		need_link_unlink=yes
+		with_sigaltstack=no
+		use_sigposix=yes
+		;;
 	*-*-*freebsd*)
 		host_win32=no
 		if test "x$PTHREAD_CFLAGS" = "x"; then
@@ -2551,7 +2562,7 @@ case "$host" in
 			sgen_supported=true
 			AOT_SUPPORTED="yes"
 			;;
-		  darwin*|openbsd*|freebsd*)
+		  darwin*|openbsd*|freebsd*|kfreebsd-gnu*)
 			sgen_supported=true
 		        ;;
 		esac
@@ -2569,7 +2580,7 @@ case "$host" in
 			sgen_supported=true
 			AOT_SUPPORTED="yes"
 			;;
-		  darwin*|openbsd*|freebsd*)
+		  darwin*|openbsd*|freebsd*|kfreebsd-gnu*)
 			sgen_supported=true
 			;;
 		esac
@@ -2925,6 +2936,11 @@ case "$host" in
 	LIBC="libc.so.12"
 	INTL="libintl.so.0"
 	;;
+     *-*-kfreebsd*-gnu)
+	LIBC="libc.so.0.1"
+	INTL="libc.so.0.1"
+	X11="libX11.so.6"
+	;;
     *-*-*freebsd*)
     	LIBC="libc.so"
 	INTL="libintl.so"
--- mono-3.2.8+dfsg.orig/Makefile.am
+++ mono-3.2.8+dfsg/Makefile.am
@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I m4
 MONOTOUCH_SUBDIRS = $(libgc_dir) eglib/src mono
 
 if CROSS_COMPILING
-SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) data runtime scripts man samples msvc $(docs_dir)
+SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) data runtime scripts man samples msvc
 # Keep in sync with SUBDIRS
 ## 'tools' is not normally built
 DIST_SUBDIRS = m4 po libgc eglib mono ikvm-native data runtime scripts man samples tools msvc docs
@@ -11,7 +11,7 @@ else
 if ONLY_MONOTOUCH
 SUBDIRS = $(MONOTOUCH_SUBDIRS) runtime
 else
-SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) support data runtime scripts man samples msvc $(docs_dir)
+SUBDIRS = po $(libgc_dir) eglib mono $(ikvm_native_dir) support data runtime scripts man samples msvc
 # Keep in sync with SUBDIRS
 ## 'tools' is not normally built
 DIST_SUBDIRS = m4 po libgc eglib mono ikvm-native support data runtime scripts man samples tools msvc docs
--- mono-3.2.8+dfsg.orig/mono/io-layer/io.c
+++ mono-3.2.8+dfsg/mono/io-layer/io.c
@@ -4296,7 +4296,7 @@ get_fstypename (gchar *utfpath)
 }
 
 /* Linux has struct statfs which has a different layout */
-#if defined (PLATFORM_MACOSX) || defined (__linux__) || defined(PLATFORM_BSD) || defined(__native_client__)
+#if defined (PLATFORM_MACOSX) || defined (__linux__) || defined(PLATFORM_BSD) || defined(__native_client__) || defined(__FreeBSD_kernel__)
 gboolean
 GetVolumeInformation (const gunichar2 *path, gunichar2 *volumename, int volumesize, int *outserial, int *maxcomp, int *fsflags, gunichar2 *fsbuffer, int fsbuffersize)
 {
--- mono-3.2.8+dfsg.orig/mono/mini/Makefile.am
+++ mono-3.2.8+dfsg/mono/mini/Makefile.am
@@ -193,7 +193,7 @@ buildver-boehm.h: libmini-static.la $(mo
 else
 buildver-boehm.h: libmini-static.la $(monodir)/mono/metadata/libmonoruntime-static.la
 endif
-	@echo "const char *build_date = \"`date`\";" > buildver-boehm.h
+	@echo "const char *build_date;" > buildver-boehm.h
 mono_boehm-main.$(OBJEXT): buildver-boehm.h
 endif
 
@@ -202,7 +202,7 @@ buildver-sgen.h: libmini-static.la $(mon
 else
 buildver-sgen.h: libmini-static.la $(monodir)/mono/metadata/libmonoruntimesgen-static.la
 endif
-	@echo "const char *build_date = \"`date`\";" > buildver-sgen.h
+	@echo "const char *build_date;" > buildver-sgen.h
 mono_sgen-main-sgen.$(OBJEXT): buildver-sgen.h
 
 if DTRACE_G_REQUIRED
@@ -727,16 +727,7 @@ EXTRA_DIST = TestDriver.cs ldscript ldsc
 	Makefile.am.in
 
 version.h: Makefile
-	if test -d $(top_srcdir)/.git; then \
-		(cd $(top_srcdir); \
-			LANG=C; export LANG; \
-			branch=`git branch | grep '^\*' | cut -d ' ' -f 2`; \
-			version=`git log --no-color --first-parent -n1 --pretty=format:%h`; \
-			echo "#define FULL_VERSION \"$$branch/$$version\""; \
-		); \
-	else \
-		echo "#define FULL_VERSION \"tarball\""; \
-	fi > version.h
+	echo "#define FULL_VERSION \"Debian $$(dpkg-parsechangelog -l$(top_srcdir)/debian/changelog | grep ^Vers | cut -d\  -f2)\"" > version.h
 
 # Utility target for patching libtool to speed up linking
 patch-libtool:
--- mono-3.2.8+dfsg.orig/mono/mini/mini-amd64.h
+++ mono-3.2.8+dfsg/mono/mini/mini-amd64.h
@@ -298,7 +298,7 @@ typedef struct MonoCompileArch {
 
 #define MONO_ARCH_NOMAP32BIT
 
-#elif defined (__FreeBSD__)
+#elif defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
 
 #define REG_RAX 7
 #define REG_RCX 4
--- mono-3.2.8+dfsg.orig/mono/mini/mini-x86.h
+++ mono-3.2.8+dfsg/mono/mini/mini-x86.h
@@ -48,7 +48,7 @@ struct sigcontext {
 #endif /* __HAIKU__ */
 
 #if defined( __linux__) || defined(__sun) || defined(__APPLE__) || defined(__NetBSD__) || \
-       defined(__FreeBSD__) || defined(__OpenBSD__)
+       defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 #define MONO_ARCH_USE_SIGACTION
 #endif
 
--- mono-3.2.8+dfsg.orig/mono/metadata/sgen-os-posix.c
+++ mono-3.2.8+dfsg/mono/metadata/sgen-os-posix.c
@@ -36,7 +36,7 @@
 #include "metadata/object-internals.h"
 #include "utils/mono-signal-handler.h"
 
-#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 const static int suspend_signal_num = SIGXFSZ;
 #else
 const static int suspend_signal_num = SIGPWR;
--- mono-3.2.8+dfsg.orig/mono/metadata/security.c
+++ mono-3.2.8+dfsg/mono/metadata/security.c
@@ -13,6 +13,7 @@
 
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/appdomain.h>
+#include <mono/metadata/assembly.h>
 #include <mono/metadata/image.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/object-internals.h>
--- mono-3.2.8+dfsg.orig/mono/tests/Makefile.am
+++ mono-3.2.8+dfsg/mono/tests/Makefile.am
@@ -341,7 +341,6 @@ BASE_TEST_CS_SRC=		\
 	modules.cs	\
 	bug-81673.cs	\
 	bug-81691.cs	\
-	bug-80307.cs	\
 	bug-415577.cs	\
 	filter-stack.cs	\
 	vararg2.cs	\
@@ -372,7 +371,6 @@ BASE_TEST_CS_SRC=		\
 	bug-575941.cs	\
 	bug-599469.cs	\
 	bug-389886-3.cs \
-	monitor.cs	\
 	dynamic-method-resurrection.cs	\
 	bug-666008.cs	\
 	bug-685908.cs	\
@@ -388,7 +386,6 @@ BASE_TEST_CS_SRC=		\
 	appdomain-unload-doesnot-raise-pending-events.cs	\
 	bug-6148.cs	\
 	assembly_append_ordering.cs	\
-	bug-10127.cs	\
 	allow-synchronous-major.cs	\
 	unload-appdomain-on-shutdown.cs	\
 	block_guard_restore_aligment_on_exit.cs	\
--- mono-3.2.8+dfsg.orig/mono/utils/mono-sigcontext.h
+++ mono-3.2.8+dfsg/mono/utils/mono-sigcontext.h
@@ -16,14 +16,14 @@
 
 #if defined(TARGET_X86)
 
-#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__DragonFly__)
 #include <ucontext.h>
 #endif
 #if defined(__APPLE__)
 #include <AvailabilityMacros.h>
 #endif
 
-#if defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
 	#define UCONTEXT_REG_EAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_eax)
 	#define UCONTEXT_REG_EBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ebx)
 	#define UCONTEXT_REG_ECX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_ecx)
@@ -154,7 +154,7 @@ typedef struct ucontext {
 
 #elif defined(TARGET_AMD64)
 
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 #include <ucontext.h>
 #endif
 
@@ -176,7 +176,7 @@ typedef struct ucontext {
 	#define UCONTEXT_REG_R13(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r13)
 	#define UCONTEXT_REG_R14(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r14)
 	#define UCONTEXT_REG_R15(ctx) (((ucontext_t*)(ctx))->uc_mcontext->__ss.__r15)
-#elif defined(__FreeBSD__)
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 	#define UCONTEXT_REG_RAX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rax)
 	#define UCONTEXT_REG_RBX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rbx)
 	#define UCONTEXT_REG_RCX(ctx) (((ucontext_t*)(ctx))->uc_mcontext.mc_rcx)
--- mono-3.2.8+dfsg.orig/mcs/class/Mono.WebBrowser/Mono.WebBrowser.dll.sources
+++ mono-3.2.8+dfsg/mcs/class/Mono.WebBrowser/Mono.WebBrowser.dll.sources
@@ -133,6 +133,9 @@ Mono.Mozilla/interfaces/nsIWebNavigation
 Mono.Mozilla/interfaces/extras/NodeType.cs
 Mono.Mozilla/interfaces/extras/nsIWriteSegmentFun.cs
 Mono.Mozilla/interfaces/extras/Options.cs
+Mono.NullBrowser/Base.cs
+Mono.NullBrowser/WebBrowser.cs
+Mono.NullBrowser/DOM/Navigation.cs
 Mono.WebBrowser/DOM/IDocumentType.cs
 Mono.WebBrowser/DOM/IDOMImplementation.cs
 Mono.WebBrowser/DOM/IMediaList.cs
--- /dev/null
+++ mono-3.2.8+dfsg/mcs/class/Mono.WebBrowser/Mono.NullBrowser/WebBrowser.cs
@@ -0,0 +1,414 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007, 2008 Novell, Inc.
+// Copyright (c) 2013 Jo Shields
+//
+// Authors:
+//	Andreia Gaita (avidigal@novell.com)
+//	Jo Shields (directhex@apebox.org)
+//
+
+#undef debug
+
+using System;
+using System.Collections;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Diagnostics;
+using Mono.WebBrowser;
+using Mono.WebBrowser.DOM;
+
+namespace Mono.NullBrowser
+{
+	internal class WebBrowser : IWebBrowser
+	{
+		bool loaded;
+		internal bool created = false;
+		bool creating = false;
+
+                internal DOM.Navigation navigation;
+
+		internal Platform platform;
+		internal Platform enginePlatform;
+		System.ComponentModel.EventHandlerList events;
+		System.ComponentModel.EventHandlerList domEvents;
+
+		string statusText;
+
+		bool streamingMode;
+		
+		internal Hashtable documents;
+
+		int width;
+		int height;
+		bool isDirty;
+		
+		public WebBrowser (Platform platform)
+		{
+			this.platform = platform;
+			loaded = Base.Init (this, platform);
+			documents = new Hashtable ();
+		}
+
+		public bool Load (IntPtr handle, int width, int height)
+		{
+			loaded = Base.Bind (this, handle, width, height);
+			return loaded;
+		}
+
+		bool Created {
+			get {
+				if (!creating && !created) {
+					creating = true;
+					created = Base.Create (this);
+					if (created && isDirty) {
+						isDirty = false;
+						Base.Resize (this, width, height);
+					}
+				}
+				return created;
+			}
+		}
+
+		public void Shutdown ()
+		{
+			Base.Shutdown (this);
+		}
+		
+		internal void Reset ()
+		{
+			this.DomEvents.Dispose ();
+			this.domEvents = null;
+			this.documents.Clear ();
+		}
+
+		public bool Initialized {
+			get { return this.loaded; }
+		}
+		
+		public IWindow Window {
+			get {
+				return null;
+			}
+		}
+
+		public IDocument Document {
+			get {
+				return null;
+			}
+		}
+
+		public INavigation Navigation {
+			get {
+                                if (!Created) return null;
+
+                                if (navigation == null) {
+
+                                        navigation = new DOM.Navigation ();
+                                }
+                                return navigation as INavigation;
+			}
+		}
+		
+		public string StatusText {
+			get { return statusText; }
+		}
+		
+		public bool Offline {
+			get {
+				return false;
+			}
+			set {
+			}
+		}
+		
+		internal System.ComponentModel.EventHandlerList DomEvents {
+			get {
+				if (domEvents == null)
+					domEvents = new System.ComponentModel.EventHandlerList();
+
+				return domEvents;
+			}
+		}
+
+		internal System.ComponentModel.EventHandlerList Events {
+			get {
+				if (events == null)
+					events = new System.ComponentModel.EventHandlerList();
+
+				return events;
+			}
+		}
+		
+		#region Layout
+		public void FocusIn (FocusOption focus)
+		{
+			if (!created) return;
+			Base.Focus (this, focus);
+		}
+		public void FocusOut ()
+		{
+			if (!created) return;
+			Base.Blur (this);
+		}
+		
+		public void Activate ()
+		{
+			if (!Created) return;
+			Base.Activate (this);
+		}
+		public void Deactivate ()
+		{
+			if (!created) return;
+			Base.Deactivate (this);
+		}
+
+		public void Resize (int width, int height)
+		{
+			this.width = width;
+			this.height = height;
+			isDirty = true;
+			if (!created) return;
+			Base.Resize (this, width, height);			
+		}
+
+		public void Render (byte[] data)
+		{
+			if (!Created) return;
+			if (data == null)
+				throw new ArgumentNullException ("data");
+			string html = System.Text.ASCIIEncoding.UTF8.GetString (data);
+			Render (html);
+		}
+
+		public void Render (string html)
+		{
+			if (!Created) return;
+			Render (html, "file:///", "text/html");
+		}
+
+				
+		public void Render (string html, string uri, string contentType)
+		{
+			if (!Created) return;
+			throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.Navigation);
+
+			IntPtr native_html = Marshal.StringToHGlobalAnsi (html);
+			Marshal.FreeHGlobal (native_html);
+
+
+		}
+		
+		public void ExecuteScript (string script) {
+			if (!Created) return;
+			Base.EvalScript (this, script);
+		}
+				
+		internal void AttachEvent (INode node, string eve, EventHandler handler) {
+			string key = String.Intern (node.GetHashCode() + ":" + eve);
+#if debug
+			Console.Error.WriteLine ("Event Attached: " + key);
+#endif
+			DomEvents.AddHandler (key, handler);
+		}
+
+		internal void DetachEvent (INode node, string eve, EventHandler handler) {
+			string key = String.Intern (node.GetHashCode() + ":" + eve);
+#if debug			
+			Console.Error.WriteLine ("Event Detached: " + key);
+#endif			
+			DomEvents.RemoveHandler (key, handler);
+		}
+		
+		#endregion
+
+		#region Events
+		internal static object KeyDownEvent = new object ();
+		internal static object KeyPressEvent = new object ();
+		internal static object KeyUpEvent = new object ();
+		internal static object MouseClickEvent = new object ();
+		internal static object MouseDoubleClickEvent = new object ();
+		internal static object MouseDownEvent = new object ();
+		internal static object MouseEnterEvent = new object ();
+		internal static object MouseLeaveEvent = new object ();
+		internal static object MouseMoveEvent = new object ();
+		internal static object MouseUpEvent = new object ();
+		internal static object FocusEvent = new object ();
+		internal static object BlurEvent = new object ();
+		internal static object CreateNewWindowEvent = new object ();
+		internal static object AlertEvent = new object ();
+			
+		internal static object LoadStartedEvent = new object ();
+		internal static object LoadCommitedEvent = new object ();
+		internal static object ProgressChangedEvent = new object ();
+		internal static object LoadFinishedEvent = new object ();	
+		
+		internal static object LoadEvent = new object ();
+		internal static object UnloadEvent = new object ();
+		internal static object StatusChangedEvent = new object ();
+		internal static object SecurityChangedEvent = new object ();
+		internal static object ProgressEvent = new object ();
+		internal static object ContextMenuEvent = new object ();
+		
+		internal static object NavigationRequestedEvent = new object ();
+		
+		public event NodeEventHandler KeyDown
+		{
+			add { Events.AddHandler (KeyDownEvent, value); }
+			remove { Events.RemoveHandler (KeyDownEvent, value); }
+		}
+
+		public event NodeEventHandler KeyPress
+		{
+			add { Events.AddHandler (KeyPressEvent, value); }
+			remove { Events.RemoveHandler (KeyPressEvent, value); }
+		}
+		public event NodeEventHandler KeyUp
+		{
+			add { Events.AddHandler (KeyUpEvent, value); }
+			remove { Events.RemoveHandler (KeyUpEvent, value); }
+		}
+		public event NodeEventHandler MouseClick
+		{
+			add { Events.AddHandler (MouseClickEvent, value); }
+			remove { Events.RemoveHandler (MouseClickEvent, value); }
+		}
+		public event NodeEventHandler MouseDoubleClick
+		{
+			add { Events.AddHandler (MouseDoubleClickEvent, value); }
+			remove { Events.RemoveHandler (MouseDoubleClickEvent, value); }
+		}
+		public event NodeEventHandler MouseDown
+		{
+			add { Events.AddHandler (MouseDownEvent, value); }
+			remove { Events.RemoveHandler (MouseDownEvent, value); }
+		}
+		public event NodeEventHandler MouseEnter
+		{
+			add { Events.AddHandler (MouseEnterEvent, value); }
+			remove { Events.RemoveHandler (MouseEnterEvent, value); }
+		}
+		public event NodeEventHandler MouseLeave
+		{
+			add { Events.AddHandler (MouseLeaveEvent, value); }
+			remove { Events.RemoveHandler (MouseLeaveEvent, value); }
+		}
+		public event NodeEventHandler MouseMove
+		{
+			add { Events.AddHandler (MouseMoveEvent, value); }
+			remove { Events.RemoveHandler (MouseMoveEvent, value); }
+		}
+		public event NodeEventHandler MouseUp
+		{
+			add { Events.AddHandler (MouseUpEvent, value); }
+			remove { Events.RemoveHandler (MouseUpEvent, value); }
+		}
+		public event EventHandler Focus
+		{
+			add { Events.AddHandler (FocusEvent, value); }
+			remove { Events.RemoveHandler (FocusEvent, value); }
+		}
+		public event EventHandler Blur
+		{
+			add { Events.AddHandler (BlurEvent, value); }
+			remove { Events.RemoveHandler (BlurEvent, value); }
+		}
+		public event CreateNewWindowEventHandler CreateNewWindow
+		{
+			add { Events.AddHandler (CreateNewWindowEvent, value); }
+			remove { Events.RemoveHandler (CreateNewWindowEvent, value); }
+		}
+		public event AlertEventHandler Alert
+		{
+			add { Events.AddHandler (AlertEvent, value); }
+			remove { Events.RemoveHandler (AlertEvent, value); }
+		}
+		public event EventHandler Loaded
+		{
+			add { Events.AddHandler (LoadEvent, value); }
+			remove { Events.RemoveHandler (LoadEvent, value); }
+		}
+		public event EventHandler Unloaded
+		{
+			add { Events.AddHandler (UnloadEvent, value); }
+			remove { Events.RemoveHandler (UnloadEvent, value); }
+		}
+
+ 		public event StatusChangedEventHandler StatusChanged
+		{
+			add { Events.AddHandler (StatusChangedEvent, value); }
+			remove { Events.RemoveHandler (StatusChangedEvent, value); }
+		}
+		
+ 		public event SecurityChangedEventHandler SecurityChanged
+		{
+			add { Events.AddHandler (SecurityChangedEvent, value); }
+			remove { Events.RemoveHandler (SecurityChangedEvent, value); }
+		}
+
+		public event LoadStartedEventHandler LoadStarted
+		{
+			add { Events.AddHandler (LoadStartedEvent, value); }
+			remove { Events.RemoveHandler (LoadStartedEvent, value); }
+		}
+		
+		public event LoadCommitedEventHandler LoadCommited
+		{
+			add { Events.AddHandler (LoadCommitedEvent, value); }
+			remove { Events.RemoveHandler (LoadCommitedEvent, value); }
+		}		
+		
+		public event ProgressChangedEventHandler ProgressChanged
+		{
+			add { Events.AddHandler (ProgressChangedEvent, value); }
+			remove { Events.RemoveHandler (ProgressChangedEvent, value); }
+		}
+		
+		public event LoadFinishedEventHandler LoadFinished
+		{
+			add { Events.AddHandler (LoadFinishedEvent, value); }
+			remove { Events.RemoveHandler (LoadFinishedEvent, value); }
+		}
+
+		public event ContextMenuEventHandler ContextMenuShown
+		{
+			add { Events.AddHandler (ContextMenuEvent, value); }
+			remove { Events.RemoveHandler (ContextMenuEvent, value); }
+		}
+
+		public event NavigationRequestedEventHandler NavigationRequested
+		{
+			add { }
+			remove { }
+		}
+
+		internal static object GenericEvent = new object ();
+		internal event EventHandler Generic
+		{
+			add { Events.AddHandler (GenericEvent, value); }
+			remove { Events.RemoveHandler (GenericEvent, value); }
+		}
+
+		#endregion
+
+
+	}
+}
--- /dev/null
+++ mono-3.2.8+dfsg/mcs/class/Mono.WebBrowser/Mono.NullBrowser/Base.cs
@@ -0,0 +1,174 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007, 2008 Novell, Inc.
+//
+// Authors:
+//	Andreia Gaita (avidigal@novell.com)
+//
+
+using System;
+using System.Text;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Diagnostics;
+using Mono.WebBrowser;
+
+namespace Mono.NullBrowser
+{
+	internal class Base
+	{
+		private static Hashtable boundControls;
+		private static bool initialized;
+		private static object initLock = new object ();
+		private static string monoMozDir;
+
+		private static bool isInitialized ()
+		{
+			if (!initialized)
+				return false;
+			return true;
+		}
+
+		static Base ()
+		{
+			boundControls = new Hashtable ();
+		}
+
+		public Base () { }
+
+		public static bool Init (WebBrowser control, Platform platform)
+		{
+			lock (initLock) {
+				if (!initialized) {
+				
+					initialized = true;
+				}
+			}
+			return initialized;
+		}
+
+		public static bool Bind (WebBrowser control, IntPtr handle, int width, int height)
+		{
+			if (!isInitialized ())
+				return false;
+
+			
+			return true;
+		}
+
+		public static bool Create (IWebBrowser control) {
+			if (!isInitialized ())
+				return false;
+
+			return true;
+		}
+
+		public static void Shutdown (IWebBrowser control)
+		{
+			lock (initLock) {
+				if (!initialized)
+					return;
+					
+				
+				boundControls.Remove (control);
+				if (boundControls.Count == 0) {
+					initialized = false;
+				}
+			}
+		}
+
+		// layout
+		public static void Focus (IWebBrowser control, FocusOption focus)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+
+		public static void Blur (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		public static void Activate (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		public static void Deactivate (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		public static void Resize (IWebBrowser control, int width, int height)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+		// navigation
+		public static void Home (IWebBrowser control)
+		{
+			if (!isInitialized ())
+				return;
+
+		}
+
+
+		public static IntPtr StringInit ()
+		{
+			return IntPtr.Zero;
+		}
+
+		public static void StringFinish (HandleRef str)
+		{
+		}
+
+		public static string StringGet (HandleRef str)
+		{
+			return String.Empty;
+		}
+
+		public static void StringSet (HandleRef str, string text)
+		{
+		}
+
+
+		public static object GetProxyForObject (IWebBrowser control, Guid iid, object obj)
+		{
+			return null;
+		}
+
+		public static string EvalScript (IWebBrowser control, string script)
+		{
+			return null;
+		}
+
+
+	}
+}
--- /dev/null
+++ mono-3.2.8+dfsg/mcs/class/Mono.WebBrowser/Mono.NullBrowser/DOM/Navigation.cs
@@ -0,0 +1,127 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2007, 2008 Novell, Inc.
+//
+// Authors:
+//	Andreia Gaita (avidigal@novell.com)
+//
+
+using System;
+using System.Runtime.InteropServices;
+using System.Text;
+using Mono.WebBrowser;
+using Mono.WebBrowser.DOM;
+
+namespace Mono.NullBrowser.DOM
+{
+	internal class Navigation: INavigation
+	{
+
+
+		#region INavigation Members
+
+		public bool CanGoBack {
+			get {
+				return false;
+			}
+		}
+
+		public bool CanGoForward {
+			get {
+				return false;
+			}
+		}
+
+		public bool Back ()
+		{
+			return false;
+		}
+
+		public bool Forward ()
+		{
+			return false;
+		}
+
+		public void Home ()
+		{
+		}
+
+		public void Reload ()
+		{
+		}
+
+		public void Reload (ReloadOption option)
+		{
+		}
+
+		public void Stop ()
+		{
+		}
+		
+		
+		/// <summary>
+		/// Navigate to the page in the history, by index.
+		/// </summary>
+		/// <param name="index">
+		/// A <see cref="System.Int32"/> representing an absolute index in the 
+		/// history (that is, > -1 and < history length
+		/// </param>
+		public void Go (int index)
+		{
+		}
+
+		/// <summary>
+		/// 
+		/// </summary>
+		/// <param name="index">
+		/// A <see cref="System.Int32"/> representing an index in the 
+		/// history, that can be relative or absolute depending on the relative argument
+		/// </param>
+		/// <param name="relative">
+		/// A <see cref="System.Boolean"/> indicating whether the index is relative to 
+		/// the current place in history or not (i.e., if relative = true, index can be
+		/// positive or negative, and index=-1 means load the previous page in the history.
+		/// if relative = false, index must be > -1, and index = 0 means load the first
+		/// page of the history.
+		/// </param>
+		public void Go (int index, bool relative) {
+		}
+		
+		public void Go (string url)
+		{
+		}
+
+		public void Go (string url, LoadFlags flags) 
+		{
+		}
+
+		public int HistoryCount {
+			get {
+				return 0;
+			}
+		}
+
+		#endregion
+
+		public override int GetHashCode () {
+			return 0;
+		}		
+	}
+}
--- mono-3.2.8+dfsg.orig/mcs/class/Mono.WebBrowser/Mono.WebBrowser/Manager.cs
+++ mono-3.2.8+dfsg/mcs/class/Mono.WebBrowser/Mono.WebBrowser/Manager.cs
@@ -52,8 +52,15 @@ namespace Mono.WebBrowser
 				}
 			}
 #endif
-			if (browserEngine == null || browserEngine == "mozilla")
-				return new Mono.Mozilla.WebBrowser (platform);
+			if (browserEngine == "mozilla") {
+				try {
+					return new Mono.Mozilla.WebBrowser (platform);
+				} catch {
+					browserEngine = null;
+				}
+			}
+			if (browserEngine == null)
+				return new Mono.NullBrowser.WebBrowser (platform);
 			throw new Exception (Mono.WebBrowser.Exception.ErrorCodes.EngineNotSupported, browserEngine);
 		}
 
--- mono-3.2.8+dfsg.orig/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
+++ mono-3.2.8+dfsg/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
@@ -556,14 +556,16 @@ namespace Microsoft.Build.BuildEngine {
 
 		public string DefaultToolsVersion {
 			get {
-				// This is used as the fall back version if the
-				// project can't find a version to use
-				// Hard-coded to 2.0, so it allows even vs2005 projects
-				// to build correctly, as they won't have a ToolsVersion
-				// set!
-				return String.IsNullOrEmpty (defaultToolsVersion)
-						? "2.0"
-						: defaultToolsVersion;
+				if (String.IsNullOrEmpty (defaultToolsVersion))
+#if NET_4_0
+					return "4.0";
+#elif NET_3_5
+					return "3.5";
+#else
+					return "2.0";
+#endif
+				
+				return defaultToolsVersion;
 			}
 			set {
 				if (Toolsets [value] == null)
--- mono-3.2.8+dfsg.orig/mcs/class/corlib/System/Console.cs
+++ mono-3.2.8+dfsg/mcs/class/corlib/System/Console.cs
@@ -127,8 +127,7 @@ namespace System
 				int code_page = 0;
 				Encoding.InternalCodePage (ref code_page);
 
-				if (code_page != -1 && ((code_page & 0x0fffffff) == 3 // UTF8Encoding.UTF8_CODE_PAGE
-					|| ((code_page & 0x10000000) != 0)))
+				if (code_page == UTF8Encoding.UTF8_CODE_PAGE || ((code_page & 0x10000000) != 0))
 					inputEncoding = outputEncoding = Encoding.UTF8Unmarked;
 				else
 					inputEncoding = outputEncoding = Encoding.Default;
--- mono-3.2.8+dfsg.orig/data/mono.pc.in
+++ mono-3.2.8+dfsg/data/mono.pc.in
@@ -1,5 +1,5 @@
-prefix=${pcfiledir}/../..
-exec_prefix=${pcfiledir}/../..
+prefix=@prefix@
+exec_prefix=${prefix}
 libdir=${prefix}/@reloc_libdir@
 includedir=${prefix}/include/mono-@API_VER@
 sysconfdir=@sysconfdir@
--- mono-3.2.8+dfsg.orig/data/mono-cairo.pc.in
+++ mono-3.2.8+dfsg/data/mono-cairo.pc.in
@@ -1,5 +1,5 @@
-prefix=${pcfiledir}/../..
-exec_prefix=${pcfiledir}/../..
+prefix=@prefix@
+exec_prefix=${prefix}
 libdir=${prefix}/@reloc_libdir@
 includedir=${prefix}/include
 
--- mono-3.2.8+dfsg.orig/libgc/configure.in
+++ mono-3.2.8+dfsg/libgc/configure.in
@@ -114,6 +114,17 @@ case "$THREADS" in
 	AC_DEFINE(THREAD_LOCAL_ALLOC)
 	THREADDLLIBS="-lpthread -lrt"
 	;;
+     *-*-kfreebsd*-gnu)
+	AC_DEFINE(GC_FREEBSD_THREADS)
+	INCLUDES="$INCLUDES -pthread"
+	THREADDLLIBS=-pthread
+	AC_DEFINE(_REENTRANT)
+	if test "${enable_parallel_mark}" = yes; then
+		AC_DEFINE(PARALLEL_MARK)
+	fi
+	AC_DEFINE(THREAD_LOCAL_ALLOC)
+	AC_DEFINE(USE_COMPILER_TLS)
+	;;
       *-*-freebsd*)
 	AC_DEFINE(GC_FREEBSD_THREADS)
 	if test "x$PTHREAD_CFLAGS" != "x"; then
--- mono-3.2.8+dfsg.orig/libgc/dyn_load.c
+++ mono-3.2.8+dfsg/libgc/dyn_load.c
@@ -26,7 +26,7 @@
  * None of this is safe with dlclose and incremental collection.
  * But then not much of anything is safe in the presence of dlclose.
  */
-#if (defined(__linux__) || defined(__native_client__)) && !defined(_GNU_SOURCE)
+#if (defined(__linux__) || defined(__GLIBC__) || defined(__native_client__)) && !defined(_GNU_SOURCE)
     /* Can't test LINUX, since this must be define before other includes */
 #   define _GNU_SOURCE
 #endif
@@ -394,7 +394,7 @@ GC_bool GC_register_main_static_data()
 /* For glibc 2.2.4+.  Unfortunately, it doesn't work for older	*/
 /* versions.  Thanks to Jakub Jelinek for most of the code.	*/
 
-# if (defined(LINUX) || defined(NACL)) /* Are others OK here, too? */ \
+# if (defined(LINUX) || defined (__GLIBC__) || defined(NACL)) /* Are others OK here, too? */ \
      && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
          || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG))) 
 
--- mono-3.2.8+dfsg.orig/libgc/include/gc.h
+++ mono-3.2.8+dfsg/libgc/include/gc.h
@@ -493,7 +493,7 @@ GC_API GC_PTR GC_malloc_atomic_ignore_of
 #   define GC_RETURN_ADDR (GC_word)__return_address
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__GLIBC__)
 # include <features.h>
 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
      && !defined(__ia64__)
--- mono-3.2.8+dfsg.orig/libgc/include/private/gcconfig.h
+++ mono-3.2.8+dfsg/libgc/include/private/gcconfig.h
@@ -55,7 +55,7 @@
 # endif
 
 /* And one for FreeBSD: */
-# if defined(__FreeBSD__) && !defined(FREEBSD)
+# if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
 #    define FREEBSD
 # endif
 
@@ -1371,8 +1371,15 @@
 #	ifndef GC_FREEBSD_THREADS
 #	    define MPROTECT_VDB
 #	endif
-#      define SIG_SUSPEND SIGTSTP
-#      define SIG_THR_RESTART SIGCONT
+#       ifdef __GLIBC__
+#           define SIG_SUSPEND          (32+6)
+#           define SIG_THR_RESTART      (32+5)
+            extern int _end[];
+#           define DATAEND (_end)
+#       else
+#           define SIG_SUSPEND SIGTSTP
+#           define SIG_THR_RESTART SIGCONT
+#       endif
 #	define FREEBSD_STACKBOTTOM
 #	ifdef __ELF__
 #	    define DYNAMIC_LOADING
@@ -2143,6 +2150,28 @@
 	extern char * GC_FreeBSDGetDataStart();
 #	define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
 #   endif
+#   ifdef FREEBSD
+#	define OS_TYPE "FREEBSD"
+#	ifndef GC_FREEBSD_THREADS
+#	    define MPROTECT_VDB
+#	endif
+#	ifdef __GLIBC__
+#	    define SIG_SUSPEND		(32+6)
+#	    define SIG_THR_RESTART	(32+5)
+	    extern int _end[];
+#	    define DATAEND (_end)
+#	else
+#	    define SIG_SUSPEND SIGUSR1
+#	    define SIG_THR_RESTART SIGUSR2
+#	endif
+#	define FREEBSD_STACKBOTTOM
+#	ifdef __ELF__
+#	    define DYNAMIC_LOADING
+#	endif
+	extern char etext[];
+	extern char * GC_FreeBSDGetDataStart();
+#	define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
+#   endif
 #   ifdef NETBSD
 #	define OS_TYPE "NETBSD"
 #	ifdef __ELF__
@@ -2230,7 +2259,7 @@
 #   define SUNOS5SIGS
 # endif
 
-# if defined(FREEBSD) && (__FreeBSD__ >= 4)
+# if defined(FREEBSD) && ((__FreeBSD__ >= 4) || (__FreeBSD_kernel__ >= 4))
 #   define SUNOS5SIGS
 # endif
 
@@ -2293,7 +2322,7 @@
 #   define CACHE_LINE_SIZE 32	/* Wild guess	*/
 # endif
 
-# ifdef LINUX
+# if defined(LINUX) || defined(__GLIBC__)
 #   define REGISTER_LIBRARIES_EARLY
     /* We sometimes use dl_iterate_phdr, which may acquire an internal	*/
     /* lock.  This isn't safe after the world has stopped.  So we must	*/
@@ -2374,7 +2403,7 @@
 #if defined(SPARC)
 # define CAN_SAVE_CALL_ARGS
 #endif
-#if (defined(I386) || defined(X86_64)) && defined(LINUX)
+#if (defined(I386) || defined(X86_64)) && (defined(LINUX) || defined(__GLIBC__))
 	    /* SAVE_CALL_CHAIN is supported if the code is compiled to save	*/
 	    /* frame pointers by default, i.e. no -fomit-frame-pointer flag.	*/
 # define CAN_SAVE_CALL_ARGS
--- mono-3.2.8+dfsg.orig/support/syslog.c
+++ mono-3.2.8+dfsg/support/syslog.c
@@ -38,7 +38,16 @@ Mono_Posix_Syscall_closelog (void)
 int
 Mono_Posix_Syscall_syslog (int priority, const char* message)
 {
+#ifdef __GNUC__
+	#pragma GCC diagnostic push
+	#pragma GCC diagnostic ignored "-Wformat-security"
+#endif
+
 	syslog (priority, message);
+
+#ifdef __GNUC__
+	#pragma GCC diagnostic pop
+#endif
 	return 0;
 }
 
--- mono-3.2.8+dfsg.orig/mcs/Makefile
+++ mono-3.2.8+dfsg/mcs/Makefile
@@ -82,7 +82,7 @@ all-local $(STD_TARGETS:=-local):
 	@:
 
 dir-check:
-	@if [ "$(NO_DIR_CHECK)" = "" -a "$(PROFILE)" != "basic" ]; then make -C ../runtime; fi
+	@if [ "$(NO_DIR_CHECK)" = "" -a "$(PROFILE)" != "basic" ]; then $(MAKE) -C ../runtime; fi
 
 # fun specialty targets
 
--- mono-3.2.8+dfsg.orig/mono/arch/ppc/ppc-codegen.h
+++ mono-3.2.8+dfsg/mono/arch/ppc/ppc-codegen.h
@@ -123,7 +123,7 @@ enum {
 	PPC_TRAP_GE_UN = 16 + PPC_TRAP_EQ
 };
 
-#define ppc_emit32(c,x) do { *((guint32 *) (c)) = GUINT32_TO_BE (x); (c) = (gpointer)((guint8 *)(c) + sizeof (guint32));} while (0)
+#define ppc_emit32(c,x) do { *((guint32 *) (c)) = (guint32) (x); (c) = (gpointer)((guint8 *)(c) + sizeof (guint32));} while (0)
 
 #define ppc_is_imm16(val) ((((val)>> 15) == 0) || (((val)>> 15) == -1))
 #define ppc_is_uimm16(val) ((glong)(val) >= 0L && (glong)(val) <= 65535L)
@@ -806,11 +806,15 @@ my and Ximian's copyright to this code.
 		}	\
 	} G_STMT_END
 
+#if _CALL_ELF == 2
+#define ppc_load_func(c,D,V)	      ppc_load_sequence ((c), (D), (V))
+#else
 #define ppc_load_func(c,D,v) G_STMT_START { \
-		ppc_load_sequence ((c), ppc_r11, (guint64)(gsize)(v));	\
-		ppc_ldptr ((c), ppc_r2, sizeof (gpointer), ppc_r11);	\
-		ppc_ldptr ((c), (D), 0, ppc_r11);	\
+		ppc_load_sequence ((c), ppc_r12, (guint64)(gsize)(v));	\
+		ppc_ldptr ((c), ppc_r2, sizeof (gpointer), ppc_r12);	\
+		ppc_ldptr ((c), (D), 0, ppc_r12);	\
 	} G_STMT_END
+#endif
 
 #define ppc_load_multiple_regs(c,D,d,A) G_STMT_START { \
 		int __i, __o = (d);			\
--- mono-3.2.8+dfsg.orig/mono/metadata/sgen-marksweep.c
+++ mono-3.2.8+dfsg/mono/metadata/sgen-marksweep.c
@@ -45,8 +45,10 @@
 #define SGEN_HAVE_CONCURRENT_MARK
 #endif
 
-#define MS_BLOCK_SIZE	(16*1024)
-#define MS_BLOCK_SIZE_SHIFT	14
+/* MS_BLOCK_SIZE must be a multiple of the system pagesize, which for some
+   archs is 64k.  */
+#define MS_BLOCK_SIZE	(64*1024)
+#define MS_BLOCK_SIZE_SHIFT	16
 #define MAJOR_SECTION_SIZE	MS_BLOCK_SIZE
 #define CARDS_PER_BLOCK (MS_BLOCK_SIZE / CARD_SIZE_IN_BYTES)
 
--- mono-3.2.8+dfsg.orig/mono/mini/aot-compiler.c
+++ mono-3.2.8+dfsg/mono/mini/aot-compiler.c
@@ -1839,14 +1839,14 @@ arch_emit_imt_thunk (MonoAotCompile *acf
 	code = buf;
 
 	/* Load the mscorlib got address */
-	ppc_ldptr (code, ppc_r11, sizeof (gpointer), ppc_r30);
+	ppc_ldptr (code, ppc_r12, sizeof (gpointer), ppc_r30);
 	/* Load the parameter from the GOT */
 	ppc_load (code, ppc_r0, offset * sizeof (gpointer));
-	ppc_ldptr_indexed (code, ppc_r11, ppc_r11, ppc_r0);
+	ppc_ldptr_indexed (code, ppc_r12, ppc_r12, ppc_r0);
 
 	/* Load and check key */
 	labels [1] = code;
-	ppc_ldptr (code, ppc_r0, 0, ppc_r11);
+	ppc_ldptr (code, ppc_r0, 0, ppc_r12);
 	ppc_cmp (code, 0, sizeof (gpointer) == 8 ? 1 : 0, ppc_r0, MONO_ARCH_IMT_REG);
 	labels [2] = code;
 	ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
@@ -1857,18 +1857,18 @@ arch_emit_imt_thunk (MonoAotCompile *acf
 	ppc_bc (code, PPC_BR_TRUE, PPC_BR_EQ, 0);
 
 	/* Loop footer */
-	ppc_addi (code, ppc_r11, ppc_r11, 2 * sizeof (gpointer));
+	ppc_addi (code, ppc_r12, ppc_r12, 2 * sizeof (gpointer));
 	labels [4] = code;
 	ppc_b (code, 0);
 	mono_ppc_patch (labels [4], labels [1]);
 
 	/* Match */
 	mono_ppc_patch (labels [2], code);
-	ppc_ldptr (code, ppc_r11, sizeof (gpointer), ppc_r11);
-	/* r11 now contains the value of the vtable slot */
+	ppc_ldptr (code, ppc_r12, sizeof (gpointer), ppc_r12);
+	/* r12 now contains the value of the vtable slot */
 	/* this is not a function descriptor on ppc64 */
-	ppc_ldptr (code, ppc_r11, 0, ppc_r11);
-	ppc_mtctr (code, ppc_r11);
+	ppc_ldptr (code, ppc_r12, 0, ppc_r12);
+	ppc_mtctr (code, ppc_r12);
 	ppc_bcctr (code, PPC_BR_ALWAYS, 0);
 
 	/* Fail */
--- mono-3.2.8+dfsg.orig/mono/mini/exceptions-ppc.c
+++ mono-3.2.8+dfsg/mono/mini/exceptions-ppc.c
@@ -381,18 +381,18 @@ mono_arch_get_throw_exception_generic (i
 
 		if (aot) {
 			code = mono_arch_emit_load_aotconst (start, code, &ji, MONO_PATCH_INFO_IMAGE, mono_defaults.corlib);
-			ppc_mr (code, ppc_r3, ppc_r11);
+			ppc_mr (code, ppc_r3, ppc_r12);
 			code = mono_arch_emit_load_aotconst (start, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_exception_from_token");
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-			ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
-			ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+			ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r12);
+			ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 #endif
-			ppc_mtctr (code, ppc_r11);
+			ppc_mtctr (code, ppc_r12);
 			ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
 		} else {
 			ppc_load (code, ppc_r3, (gulong)mono_defaults.corlib);
-			ppc_load_func (code, ppc_r0, mono_exception_from_token);
-			ppc_mtctr (code, ppc_r0);
+			ppc_load_func (code, PPC_CALL_REG, mono_exception_from_token);
+			ppc_mtctr (code, PPC_CALL_REG);
 			ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
 		}
 	}
@@ -420,14 +420,14 @@ mono_arch_get_throw_exception_generic (i
 		code = mono_arch_emit_load_got_addr (start, code, NULL, &ji);
 		code = mono_arch_emit_load_aotconst (start, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_ppc_throw_exception");
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-		ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
-		ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+		ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r12);
+		ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 #endif
-		ppc_mtctr (code, ppc_r11);
+		ppc_mtctr (code, ppc_r12);
 		ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
 	} else {
-		ppc_load_func (code, ppc_r0, mono_ppc_throw_exception);
-		ppc_mtctr (code, ppc_r0);
+		ppc_load_func (code, PPC_CALL_REG, mono_ppc_throw_exception);
+		ppc_mtctr (code, PPC_CALL_REG);
 		ppc_bcctrl (code, PPC_BR_ALWAYS, 0);
 	}
 	/* we should never reach this breakpoint */
--- mono-3.2.8+dfsg.orig/mono/mini/mini-gc.c
+++ mono-3.2.8+dfsg/mono/mini/mini-gc.c
@@ -438,6 +438,13 @@ static int callee_saved_regs [] = { X86_
 static int callee_saved_regs [] = { ARMREG_V1, ARMREG_V2, ARMREG_V3, ARMREG_V4, ARMREG_V5, ARMREG_V7, ARMREG_FP };
 #elif defined(TARGET_S390X)
 static int callee_saved_regs [] = { s390_r6, s390_r7, s390_r8, s390_r9, s390_r10, s390_r11, s390_r12, s390_r13, s390_r14 };
+#elif defined(TARGET_POWERPC)
+static int callee_saved_regs [] = {
+  ppc_r13, ppc_r14, ppc_r15, ppc_r16, 
+  ppc_r17, ppc_r18, ppc_r19, ppc_r20,
+  ppc_r21, ppc_r22, ppc_r23, ppc_r24,
+  ppc_r25, ppc_r26, ppc_r27, ppc_r28,
+  ppc_r29, ppc_r30, ppc_r31 };
 #endif
 
 static guint32
--- mono-3.2.8+dfsg.orig/mono/mini/mini-mips.c
+++ mono-3.2.8+dfsg/mono/mini/mini-mips.c
@@ -3298,8 +3298,8 @@ emit_reserve_param_area (MonoCompile *cf
 	if (ppc_is_imm16 (-size)) {
 		ppc_stwu (code, ppc_r0, -size, ppc_sp);
 	} else {
-		ppc_load (code, ppc_r11, -size);
-		ppc_stwux (code, ppc_r0, ppc_sp, ppc_r11);
+		ppc_load (code, ppc_r12, -size);
+		ppc_stwux (code, ppc_r0, ppc_sp, ppc_r12);
 	}
 #endif
 	return code;
@@ -3320,8 +3320,8 @@ emit_unreserve_param_area (MonoCompile *
 	if (ppc_is_imm16 (size)) {
 		ppc_stwu (code, ppc_r0, size, ppc_sp);
 	} else {
-		ppc_load (code, ppc_r11, size);
-		ppc_stwux (code, ppc_r0, ppc_sp, ppc_r11);
+		ppc_load (code, ppc_r12, size);
+		ppc_stwux (code, ppc_r0, ppc_sp, ppc_r12);
 	}
 #endif
 	return code;
@@ -3712,8 +3712,8 @@ mono_arch_output_basic_block (MonoCompil
 		case OP_DIV_IMM:
 			g_assert_not_reached ();
 #if 0
-			ppc_load (code, ppc_r11, ins->inst_imm);
-			ppc_divwod (code, ins->dreg, ins->sreg1, ppc_r11);
+			ppc_load (code, ppc_r12, ins->inst_imm);
+			ppc_divwod (code, ins->dreg, ins->sreg1, ppc_r12);
 			ppc_mfspr (code, ppc_r0, ppc_xer);
 			ppc_andisd (code, ppc_r0, ppc_r0, (1<<14));
 			/* FIXME: use OverflowException for 0x80000000/-1 */
--- mono-3.2.8+dfsg.orig/mono/mini/mini-ppc.c
+++ mono-3.2.8+dfsg/mono/mini/mini-ppc.c
@@ -103,11 +103,11 @@ offsets_from_pthread_key (guint32 key, i
 /* FIXME: ensure the sc call preserves all but r3 */
 #define emit_darwing4_tls(code,dreg,key) do {\
 		int off1 = 0x48 + key * sizeof (gpointer);	\
-		if ((dreg) != ppc_r3) ppc_mr ((code), ppc_r11, ppc_r3);	\
+		if ((dreg) != ppc_r3) ppc_mr ((code), ppc_r12, ppc_r3);	\
 		ppc_li ((code), ppc_r0, 0x7FF2);	\
 		ppc_sc ((code));	\
 		ppc_lwz ((code), (dreg), off1, ppc_r3);	\
-		if ((dreg) != ppc_r3) ppc_mr ((code), ppc_r3, ppc_r11);	\
+		if ((dreg) != ppc_r3) ppc_mr ((code), ppc_r3, ppc_r12);	\
 	} while (0);
 
 #ifdef PPC_THREAD_PTR_REG
@@ -118,8 +118,8 @@ offsets_from_pthread_key (guint32 key, i
 			ppc_ldptr ((code), (dreg), off1, PPC_THREAD_PTR_REG);	\
 		} else { \
 			int off3 = (off2 + 1) > 1; \
-			ppc_addis ((code), ppc_r11, PPC_THREAD_PTR_REG, off3); \
-			ppc_ldptr ((code), (dreg), off1, ppc_r11);	\
+			ppc_addis ((code), ppc_r12, PPC_THREAD_PTR_REG, off3); \
+			ppc_ldptr ((code), (dreg), off1, ppc_r12);	\
 		} \
 	} while (0);
 #else
@@ -190,29 +190,29 @@ emit_memcpy (guint8 *code, int size, int
 
 		ppc_load (code, ppc_r0, shifted);
 		ppc_mtctr (code, ppc_r0);
-		//g_assert (sreg == ppc_r11);
-		ppc_addi (code, ppc_r12, dreg, (doffset - sizeof (gpointer)));
-		ppc_addi (code, ppc_r11, sreg, (soffset - sizeof (gpointer)));
+		//g_assert (sreg == ppc_r12);
+		ppc_addi (code, ppc_r11, dreg, (doffset - sizeof (gpointer)));
+		ppc_addi (code, ppc_r12, sreg, (soffset - sizeof (gpointer)));
 		copy_loop_start = code;
-		ppc_ldptr_update (code, ppc_r0, (unsigned int)sizeof (gpointer), ppc_r11);
-		ppc_stptr_update (code, ppc_r0, (unsigned int)sizeof (gpointer), ppc_r12);
+		ppc_ldptr_update (code, ppc_r0, (unsigned int)sizeof (gpointer), ppc_r12);
+		ppc_stptr_update (code, ppc_r0, (unsigned int)sizeof (gpointer), ppc_r11);
 		copy_loop_jump = code;
 		ppc_bc (code, PPC_BR_DEC_CTR_NONZERO, 0, 0);
 		ppc_patch (copy_loop_jump, copy_loop_start);
 		size -= shifted * sizeof (gpointer);
 		doffset = soffset = 0;
-		dreg = ppc_r12;
+		dreg = ppc_r11;
 	}
 #ifdef __mono_ppc64__
 	/* the hardware has multiple load/store units and the move is long
 	   enough to use more then one regiester, then use load/load/store/store
 	   to execute 2 instructions per cycle. */
-	if ((cpu_hw_caps & PPC_MULTIPLE_LS_UNITS) && (dreg != ppc_r12) && (sreg != ppc_r12)) { 
+	if ((cpu_hw_caps & PPC_MULTIPLE_LS_UNITS) && (dreg != ppc_r11) && (sreg != ppc_r11)) { 
 		while (size >= 16) {
 			ppc_ldptr (code, ppc_r0, soffset, sreg);
-			ppc_ldptr (code, ppc_r12, soffset+8, sreg);
+			ppc_ldptr (code, ppc_r11, soffset+8, sreg);
 			ppc_stptr (code, ppc_r0, doffset, dreg);
-			ppc_stptr (code, ppc_r12, doffset+8, dreg);
+			ppc_stptr (code, ppc_r11, doffset+8, dreg);
 			size -= 16;
 			soffset += 16;
 			doffset += 16; 
@@ -226,12 +226,12 @@ emit_memcpy (guint8 *code, int size, int
 		doffset += 8;
 	}
 #else
-	if ((cpu_hw_caps & PPC_MULTIPLE_LS_UNITS) && (dreg != ppc_r12) && (sreg != ppc_r12)) { 
+	if ((cpu_hw_caps & PPC_MULTIPLE_LS_UNITS) && (dreg != ppc_r11) && (sreg != ppc_r11)) { 
 		while (size >= 8) {
 			ppc_lwz (code, ppc_r0, soffset, sreg);
-			ppc_lwz (code, ppc_r12, soffset+4, sreg);
+			ppc_lwz (code, ppc_r11, soffset+4, sreg);
 			ppc_stw (code, ppc_r0, doffset, dreg);
-			ppc_stw (code, ppc_r12, doffset+4, dreg);
+			ppc_stw (code, ppc_r11, doffset+4, dreg);
 			size -= 8;
 			soffset += 8;
 			doffset += 8; 
@@ -737,7 +737,7 @@ mono_arch_get_global_int_regs (MonoCompi
 	for (i = 14; i < top; ++i) {
 		/*
 		 * Reserve r29 for holding the vtable address for virtual calls in AOT mode,
-		 * since the trampolines can clobber r11.
+		 * since the trampolines can clobber r12.
 		 */
 		if (!(cfg->compile_aot && i == 29))
 			regs = g_list_prepend (regs, GUINT_TO_POINTER (i));
@@ -1782,8 +1782,8 @@ mono_arch_instrument_prolog (MonoCompile
 
 	ppc_load_ptr (code, ppc_r3, cfg->method);
 	ppc_li (code, ppc_r4, 0); /* NULL ebp for now */
-	ppc_load_func (code, ppc_r0, func);
-	ppc_mtlr (code, ppc_r0);
+	ppc_load_func (code, PPC_CALL_REG, func);
+	ppc_mtlr (code, PPC_CALL_REG);
 	ppc_blrl (code);
 	return code;
 }
@@ -1880,8 +1880,8 @@ mono_arch_instrument_epilog_full (MonoCo
 	}
 
 	ppc_load_ptr (code, ppc_r3, cfg->method);
-	ppc_load_func (code, ppc_r0, func);
-	ppc_mtlr (code, ppc_r0);
+	ppc_load_func (code, PPC_CALL_REG, func);
+	ppc_mtlr (code, PPC_CALL_REG);
 	ppc_blrl (code);
 
 	switch (save_mode) {
@@ -2811,14 +2811,14 @@ handle_thunk (int absolute, guchar *code
 static void
 patch_ins (guint8 *code, guint32 ins)
 {
-	*(guint32*)code = GUINT32_TO_BE (ins);
+	*(guint32*)code = ins;
 	mono_arch_flush_icache (code, 4);
 }
 
 void
 ppc_patch_full (guchar *code, const guchar *target, gboolean is_fd)
 {
-	guint32 ins = GUINT32_FROM_BE (*(guint32*)code);
+	guint32 ins = *(guint32*)code;
 	guint32 prim = ins >> 26;
 	guint32 ovf;
 
@@ -2901,7 +2901,13 @@ ppc_patch_full (guchar *code, const guch
 			else
 				code -= 24;
 		} else {
-			if (ppc_is_load_op (seq [5]) || ppc_opcode (seq [5]) == 31) /* ld || lwz || mr */
+			if (ppc_is_load_op (seq [5])
+#ifdef PPC_USES_FUNCTION_DESCRIPTOR
+			    /* With function descs we need to do more careful
+			       matches.  */
+			    || ppc_opcode (seq [5]) == 31 /* ld || lwz || mr */
+#endif
+			   )
 				branch_ins = seq + 8;
 			else
 				branch_ins = seq + 6;
@@ -2916,7 +2922,7 @@ ppc_patch_full (guchar *code, const guch
 
 			if (!is_fd) {
 				guint8 *buf = (guint8*)&seq [5];
-				ppc_mr (buf, ppc_r0, ppc_r11);
+				ppc_mr (buf, PPC_CALL_REG, ppc_r12);
 				ppc_nop (buf);
 			}
 		} else {
@@ -2925,8 +2931,12 @@ ppc_patch_full (guchar *code, const guch
 		}
 
 		/* FIXME: make this thread safe */
-		/* FIXME: we're assuming we're using r11 here */
-		ppc_load_ptr_sequence (code, ppc_r11, target);
+#ifdef PPC_USES_FUNCTION_DESCRIPTOR
+		/* FIXME: we're assuming we're using r12 here */
+		ppc_load_ptr_sequence (code, ppc_r12, target);
+#else
+		ppc_load_ptr_sequence (code, PPC_CALL_REG, target);
+#endif
 		mono_arch_flush_icache ((guint8*)seq, 28);
 #else
 		guint32 *seq;
@@ -2941,8 +2951,8 @@ ppc_patch_full (guchar *code, const guch
 		g_assert ((seq [2] >> 26) == 31);
 		g_assert (seq [3] == 0x4e800021 || seq [3] == 0x4e800020 || seq [3] == 0x4e800420);
 		/* FIXME: make this thread safe */
-		ppc_lis (code, ppc_r0, (guint32)(target) >> 16);
-		ppc_ori (code, ppc_r0, ppc_r0, (guint32)(target) & 0xffff);
+		ppc_lis (code, PPC_CALL_REG, (guint32)(target) >> 16);
+		ppc_ori (code, PPC_CALL_REG, PPC_CALL_REG, (guint32)(target) & 0xffff);
 		mono_arch_flush_icache (code - 8, 8);
 #endif
 	} else {
@@ -2999,8 +3009,8 @@ emit_reserve_param_area (MonoCompile *cf
 	if (ppc_is_imm16 (-size)) {
 		ppc_stptr_update (code, ppc_r0, -size, ppc_sp);
 	} else {
-		ppc_load (code, ppc_r11, -size);
-		ppc_stptr_update_indexed (code, ppc_r0, ppc_sp, ppc_r11);
+		ppc_load (code, ppc_r12, -size);
+		ppc_stptr_update_indexed (code, ppc_r0, ppc_sp, ppc_r12);
 	}
 
 	return code;
@@ -3021,8 +3031,8 @@ emit_unreserve_param_area (MonoCompile *
 	if (ppc_is_imm16 (size)) {
 		ppc_stptr_update (code, ppc_r0, size, ppc_sp);
 	} else {
-		ppc_load (code, ppc_r11, size);
-		ppc_stptr_update_indexed (code, ppc_r0, ppc_sp, ppc_r11);
+		ppc_load (code, ppc_r12, size);
+		ppc_stptr_update_indexed (code, ppc_r0, ppc_sp, ppc_r12);
 	}
 
 	return code;
@@ -3096,8 +3106,8 @@ mono_arch_output_basic_block (MonoCompil
 			 * a breakpoint is hit will step to the next IL offset.
 			 */
 			if (ins->flags & MONO_INST_SINGLE_STEP_LOC) {
-				ppc_load (code, ppc_r11, (gsize)ss_trigger_page);
-				ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+				ppc_load (code, ppc_r12, (gsize)ss_trigger_page);
+				ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 			}
 
 			mono_add_seq_point (cfg, bb, ins, code - cfg->native_code);
@@ -3131,8 +3141,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_stb (code, ins->sreg1, ins->inst_offset, ins->inst_destbasereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_stb (code, ins->sreg1, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_stb (code, ins->sreg1, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_stbx (code, ins->sreg1, ins->inst_destbasereg, ppc_r0);
@@ -3144,8 +3154,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_sth (code, ins->sreg1, ins->inst_offset, ins->inst_destbasereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_sth (code, ins->sreg1, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_sth (code, ins->sreg1, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_sthx (code, ins->sreg1, ins->inst_destbasereg, ppc_r0);
@@ -3157,8 +3167,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_stptr (code, ins->sreg1, ins->inst_offset, ins->inst_destbasereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_stptr (code, ins->sreg1, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_stptr (code, ins->sreg1, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_stptr_indexed (code, ins->sreg1, ins->inst_destbasereg, ppc_r0);
@@ -3360,8 +3370,8 @@ mono_arch_output_basic_block (MonoCompil
 			mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD, 
 					     (gpointer)"mono_break");
 			if ((FORCE_INDIR_CALL || cfg->method->dynamic) && !cfg->compile_aot) {
-				ppc_load_func (code, ppc_r0, 0);
-				ppc_mtlr (code, ppc_r0);
+				ppc_load_func (code, PPC_CALL_REG, 0);
+				ppc_mtlr (code, PPC_CALL_REG);
 				ppc_blrl (code);
 			} else {
 				ppc_bl (code, 0);
@@ -3714,7 +3724,7 @@ mono_arch_output_basic_block (MonoCompil
 			 */
 			g_assert (!cfg->method->save_lmf);
 			/*
-			 * Note: we can use ppc_r11 here because it is dead anyway:
+			 * Note: we can use ppc_r12 here because it is dead anyway:
 			 * we're leaving the method.
 			 */
 			if (1 || cfg->flags & MONO_CFG_HAS_CALLS) {
@@ -3722,26 +3732,26 @@ mono_arch_output_basic_block (MonoCompil
 				if (ppc_is_imm16 (ret_offset)) {
 					ppc_ldptr (code, ppc_r0, ret_offset, cfg->frame_reg);
 				} else {
-					ppc_load (code, ppc_r11, ret_offset);
-					ppc_ldptr_indexed (code, ppc_r0, cfg->frame_reg, ppc_r11);
+					ppc_load (code, ppc_r12, ret_offset);
+					ppc_ldptr_indexed (code, ppc_r0, cfg->frame_reg, ppc_r12);
 				}
 				ppc_mtlr (code, ppc_r0);
 			}
 
 			if (ppc_is_imm16 (cfg->stack_usage)) {
-				ppc_addi (code, ppc_r11, cfg->frame_reg, cfg->stack_usage);
+				ppc_addi (code, ppc_r12, cfg->frame_reg, cfg->stack_usage);
 			} else {
 				/* cfg->stack_usage is an int, so we can use
 				 * an addis/addi sequence here even in 64-bit.  */
-				ppc_addis (code, ppc_r11, cfg->frame_reg, ppc_ha(cfg->stack_usage));
-				ppc_addi (code, ppc_r11, ppc_r11, cfg->stack_usage);
+				ppc_addis (code, ppc_r12, cfg->frame_reg, ppc_ha(cfg->stack_usage));
+				ppc_addi (code, ppc_r12, ppc_r12, cfg->stack_usage);
 			}
 			if (!cfg->method->save_lmf) {
 				pos = 0;
 				for (i = 31; i >= 13; --i) {
 					if (cfg->used_int_regs & (1 << i)) {
 						pos += sizeof (gpointer);
-						ppc_ldptr (code, i, -pos, ppc_r11);
+						ppc_ldptr (code, i, -pos, ppc_r12);
 					}
 				}
 			} else {
@@ -3750,27 +3760,27 @@ mono_arch_output_basic_block (MonoCompil
 
 			/* Copy arguments on the stack to our argument area */
 			if (call->stack_usage) {
-				code = emit_memcpy (code, call->stack_usage, ppc_r11, PPC_STACK_PARAM_OFFSET, ppc_sp, PPC_STACK_PARAM_OFFSET);
-				/* r11 was clobbered */
+				code = emit_memcpy (code, call->stack_usage, ppc_r12, PPC_STACK_PARAM_OFFSET, ppc_sp, PPC_STACK_PARAM_OFFSET);
+				/* r12 was clobbered */
 				g_assert (cfg->frame_reg == ppc_sp);
 				if (ppc_is_imm16 (cfg->stack_usage)) {
-					ppc_addi (code, ppc_r11, cfg->frame_reg, cfg->stack_usage);
+					ppc_addi (code, ppc_r12, cfg->frame_reg, cfg->stack_usage);
 				} else {
 					/* cfg->stack_usage is an int, so we can use
 					 * an addis/addi sequence here even in 64-bit.  */
-					ppc_addis (code, ppc_r11, cfg->frame_reg, ppc_ha(cfg->stack_usage));
-					ppc_addi (code, ppc_r11, ppc_r11, cfg->stack_usage);
+					ppc_addis (code, ppc_r12, cfg->frame_reg, ppc_ha(cfg->stack_usage));
+					ppc_addi (code, ppc_r12, ppc_r12, cfg->stack_usage);
 				}
 			}
 
-			ppc_mr (code, ppc_sp, ppc_r11);
+			ppc_mr (code, ppc_sp, ppc_r12);
 			mono_add_patch_info (cfg, (guint8*) code - cfg->native_code, MONO_PATCH_INFO_METHOD_JUMP, call->method);
 			if (cfg->compile_aot) {
 				/* arch_emit_got_access () patches this */
 				ppc_load32 (code, ppc_r0, 0);
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-				ppc_ldptr_indexed (code, ppc_r11, ppc_r30, ppc_r0);
-				ppc_ldptr (code, ppc_r0, 0, ppc_r11);
+				ppc_ldptr_indexed (code, ppc_r12, ppc_r30, ppc_r0);
+				ppc_ldptr (code, ppc_r0, 0, ppc_r12);
 #else
 				ppc_ldptr_indexed (code, ppc_r0, ppc_r30, ppc_r0);
 #endif
@@ -3808,8 +3818,8 @@ mono_arch_output_basic_block (MonoCompil
 			else
 				mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr);
 			if ((FORCE_INDIR_CALL || cfg->method->dynamic) && !cfg->compile_aot) {
-				ppc_load_func (code, ppc_r0, 0);
-				ppc_mtlr (code, ppc_r0);
+				ppc_load_func (code, PPC_CALL_REG, 0);
+				ppc_mtlr (code, PPC_CALL_REG);
 				ppc_blrl (code);
 			} else {
 				ppc_bl (code, 0);
@@ -3842,7 +3852,7 @@ mono_arch_output_basic_block (MonoCompil
 		case OP_VCALL2_MEMBASE:
 		case OP_VOIDCALL_MEMBASE:
 		case OP_CALL_MEMBASE:
-			if (cfg->compile_aot && ins->sreg1 == ppc_r11) {
+			if (cfg->compile_aot && ins->sreg1 == ppc_r12) {
 				/* The trampolines clobber this */
 				ppc_mr (code, ppc_r29, ins->sreg1);
 				ppc_ldptr (code, ppc_r0, ins->inst_offset, ppc_r29);
@@ -3860,9 +3870,9 @@ mono_arch_output_basic_block (MonoCompil
 			int alloca_waste = PPC_STACK_PARAM_OFFSET + cfg->param_area + 31;
 			int area_offset = alloca_waste;
 			area_offset &= ~31;
-			ppc_addi (code, ppc_r11, ins->sreg1, alloca_waste + 31);
+			ppc_addi (code, ppc_r12, ins->sreg1, alloca_waste + 31);
 			/* FIXME: should be calculated from MONO_ARCH_FRAME_ALIGNMENT */
-			ppc_clear_right_imm (code, ppc_r11, ppc_r11, 4);
+			ppc_clear_right_imm (code, ppc_r12, ppc_r12, 4);
 			/* use ctr to store the number of words to 0 if needed */
 			if (ins->flags & MONO_INST_INIT) {
 				/* we zero 4 bytes at a time:
@@ -3875,8 +3885,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_mtctr (code, ppc_r0);
 			}
 			ppc_ldptr (code, ppc_r0, 0, ppc_sp);
-			ppc_neg (code, ppc_r11, ppc_r11);
-			ppc_stptr_update_indexed (code, ppc_r0, ppc_sp, ppc_r11);
+			ppc_neg (code, ppc_r12, ppc_r12);
+			ppc_stptr_update_indexed (code, ppc_r0, ppc_sp, ppc_r12);
 
 			/* FIXME: make this loop work in 8 byte
 			   increments on PPC64 */
@@ -3886,9 +3896,9 @@ mono_arch_output_basic_block (MonoCompil
 				 * run at least once
 				 */
 				ppc_addi (code, ins->dreg, ppc_sp, (area_offset - 8));
-				ppc_li (code, ppc_r11, 0);
+				ppc_li (code, ppc_r12, 0);
 				zero_loop_start = code;
-				ppc_stwu (code, ppc_r11, 4, ins->dreg);
+				ppc_stwu (code, ppc_r12, 4, ins->dreg);
 				zero_loop_jump = code;
 				ppc_bc (code, PPC_BR_DEC_CTR_NONZERO, 0, 0);
 				ppc_patch (zero_loop_jump, zero_loop_start);
@@ -3902,8 +3912,8 @@ mono_arch_output_basic_block (MonoCompil
 			mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD, 
 					     (gpointer)"mono_arch_throw_exception");
 			if ((FORCE_INDIR_CALL || cfg->method->dynamic) && !cfg->compile_aot) {
-				ppc_load_func (code, ppc_r0, 0);
-				ppc_mtlr (code, ppc_r0);
+				ppc_load_func (code, PPC_CALL_REG, 0);
+				ppc_mtlr (code, PPC_CALL_REG);
 				ppc_blrl (code);
 			} else {
 				ppc_bl (code, 0);
@@ -3916,8 +3926,8 @@ mono_arch_output_basic_block (MonoCompil
 			mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD, 
 					     (gpointer)"mono_arch_rethrow_exception");
 			if ((FORCE_INDIR_CALL || cfg->method->dynamic) && !cfg->compile_aot) {
-				ppc_load_func (code, ppc_r0, 0);
-				ppc_mtlr (code, ppc_r0);
+				ppc_load_func (code, PPC_CALL_REG, 0);
+				ppc_mtlr (code, PPC_CALL_REG);
 				ppc_blrl (code);
 			} else {
 				ppc_bl (code, 0);
@@ -3932,8 +3942,8 @@ mono_arch_output_basic_block (MonoCompil
 			if (ppc_is_imm16 (spvar->inst_offset)) {
 				ppc_stptr (code, ppc_r0, spvar->inst_offset, spvar->inst_basereg);
 			} else {
-				ppc_load (code, ppc_r11, spvar->inst_offset);
-				ppc_stptr_indexed (code, ppc_r0, ppc_r11, spvar->inst_basereg);
+				ppc_load (code, ppc_r12, spvar->inst_offset);
+				ppc_stptr_indexed (code, ppc_r0, ppc_r12, spvar->inst_basereg);
 			}
 			break;
 		}
@@ -3946,8 +3956,8 @@ mono_arch_output_basic_block (MonoCompil
 			if (ppc_is_imm16 (spvar->inst_offset)) {
 				ppc_ldptr (code, ppc_r0, spvar->inst_offset, spvar->inst_basereg);
 			} else {
-				ppc_load (code, ppc_r11, spvar->inst_offset);
-				ppc_ldptr_indexed (code, ppc_r0, spvar->inst_basereg, ppc_r11);
+				ppc_load (code, ppc_r12, spvar->inst_offset);
+				ppc_ldptr_indexed (code, ppc_r0, spvar->inst_basereg, ppc_r12);
 			}
 			ppc_mtlr (code, ppc_r0);
 			ppc_blr (code);
@@ -4053,11 +4063,11 @@ mono_arch_output_basic_block (MonoCompil
 
 			/* FIXME: Optimize this */
 			ppc_bl (code, 1);
-			ppc_mflr (code, ppc_r11);
+			ppc_mflr (code, ppc_r12);
 			ppc_b (code, 3);
 			*(double*)code = *(double*)ins->inst_p0;
 			code += 8;
-			ppc_lfd (code, ins->dreg, 8, ppc_r11);
+			ppc_lfd (code, ins->dreg, 8, ppc_r12);
 			break;
 		case OP_R4CONST:
 			g_assert_not_reached ();
@@ -4067,8 +4077,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_stfd (code, ins->sreg1, ins->inst_offset, ins->inst_destbasereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_stfd (code, ins->sreg1, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_stfd (code, ins->sreg1, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_stfdx (code, ins->sreg1, ins->inst_destbasereg, ppc_r0);
@@ -4080,8 +4090,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_lfd (code, ins->dreg, ins->inst_offset, ins->inst_basereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_lfd (code, ins->dreg, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_lfd (code, ins->dreg, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_lfdx (code, ins->dreg, ins->inst_destbasereg, ppc_r0);
@@ -4094,8 +4104,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_stfs (code, ins->sreg1, ins->inst_offset, ins->inst_destbasereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_stfs (code, ins->sreg1, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_stfs (code, ins->sreg1, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_stfsx (code, ins->sreg1, ins->inst_destbasereg, ppc_r0);
@@ -4107,8 +4117,8 @@ mono_arch_output_basic_block (MonoCompil
 				ppc_lfs (code, ins->dreg, ins->inst_offset, ins->inst_basereg);
 			} else {
 				if (ppc_is_imm32 (ins->inst_offset)) {
-					ppc_addis (code, ppc_r12, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
-					ppc_lfs (code, ins->dreg, ins->inst_offset, ppc_r12);
+					ppc_addis (code, ppc_r11, ins->inst_destbasereg, ppc_ha(ins->inst_offset));
+					ppc_lfs (code, ins->dreg, ins->inst_offset, ppc_r11);
 				} else {
 					ppc_load (code, ppc_r0, ins->inst_offset);
 					ppc_lfsx (code, ins->dreg, ins->inst_destbasereg, ppc_r0);
@@ -4481,6 +4491,16 @@ mono_arch_register_lowlevel_calls (void)
 }
 
 #ifdef __mono_ppc64__
+#ifdef _LITTLE_ENDIAN
+#define patch_load_sequence(ip,val) do {\
+		guint16 *__load = (guint16*)(ip);	\
+		g_assert (sizeof (val) == sizeof (gsize)); \
+		__load [0] = (((guint64)(gsize)(val)) >> 48) & 0xffff;	\
+		__load [2] = (((guint64)(gsize)(val)) >> 32) & 0xffff;	\
+		__load [6] = (((guint64)(gsize)(val)) >> 16) & 0xffff;	\
+		__load [8] =  ((guint64)(gsize)(val))        & 0xffff;	\
+	} while (0)
+#elif defined _BIG_ENDIAN
 #define patch_load_sequence(ip,val) do {\
 		guint16 *__load = (guint16*)(ip);	\
 		g_assert (sizeof (val) == sizeof (gsize)); \
@@ -4490,6 +4510,9 @@ mono_arch_register_lowlevel_calls (void)
 		__load [9] =  ((guint64)(gsize)(val))        & 0xffff;	\
 	} while (0)
 #else
+#error huh?  No endianess defined by compiler
+#endif
+#else
 #define patch_load_sequence(ip,val) do {\
 		guint16 *__lis_ori = (guint16*)(ip);	\
 		__lis_ori [1] = (((gulong)(val)) >> 16) & 0xffff;	\
@@ -4700,12 +4723,12 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 			code = save_registers (cfg, code, alloc_size - pos, ppc_sp, method->save_lmf, cfg->used_int_regs, cfa_offset);
 		} else {
 			if (pos)
-				ppc_addi (code, ppc_r11, ppc_sp, -pos);
+				ppc_addi (code, ppc_r12, ppc_sp, -pos);
 			ppc_load (code, ppc_r0, -alloc_size);
 			ppc_str_update_indexed (code, ppc_sp, ppc_sp, ppc_r0);
 			cfa_offset = alloc_size;
 			mono_emit_unwind_op_def_cfa_offset (cfg, code, alloc_size);
-			code = save_registers (cfg, code, 0, ppc_r11, method->save_lmf, cfg->used_int_regs, cfa_offset);
+			code = save_registers (cfg, code, 0, ppc_r12, method->save_lmf, cfg->used_int_regs, cfa_offset);
 		}
 	}
 	if (cfg->frame_reg != ppc_sp) {
@@ -4751,8 +4774,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 		if (ppc_is_imm16 (inst->inst_offset)) {
 			ppc_stptr (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 		} else {
-			ppc_load (code, ppc_r11, inst->inst_offset);
-			ppc_stptr_indexed (code, ainfo->reg, ppc_r11, inst->inst_basereg);
+			ppc_load (code, ppc_r12, inst->inst_offset);
+			ppc_stptr_indexed (code, ainfo->reg, ppc_r12, inst->inst_basereg);
 		}
 	}
 
@@ -4769,8 +4792,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 			else if (ainfo->regtype == RegTypeFP)
 				ppc_fmr (code, inst->dreg, ainfo->reg);
 			else if (ainfo->regtype == RegTypeBase) {
-				ppc_ldr (code, ppc_r11, 0, ppc_sp);
-				ppc_ldptr (code, inst->dreg, ainfo->offset, ppc_r11);
+				ppc_ldr (code, ppc_r12, 0, ppc_sp);
+				ppc_ldptr (code, inst->dreg, ainfo->offset, ppc_r12);
 			} else
 				g_assert_not_reached ();
 
@@ -4785,11 +4808,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_stb (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_stb (code, ainfo->reg, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_stb (code, ainfo->reg, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_stbx (code, ainfo->reg, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_stbx (code, ainfo->reg, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4798,11 +4821,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_sth (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_sth (code, ainfo->reg, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_sth (code, ainfo->reg, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_sthx (code, ainfo->reg, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_sthx (code, ainfo->reg, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4812,11 +4835,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_stw (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_stw (code, ainfo->reg, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_stw (code, ainfo->reg, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_stwx (code, ainfo->reg, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_stwx (code, ainfo->reg, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4824,8 +4847,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 					if (ppc_is_imm16 (inst->inst_offset)) {
 						ppc_str (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 					} else {
-						ppc_load (code, ppc_r11, inst->inst_offset);
-						ppc_str_indexed (code, ainfo->reg, ppc_r11, inst->inst_basereg);
+						ppc_load (code, ppc_r12, inst->inst_offset);
+						ppc_str_indexed (code, ainfo->reg, ppc_r12, inst->inst_basereg);
 					}
 					break;
 #else
@@ -4834,10 +4857,10 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_stw (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 						ppc_stw (code, ainfo->reg + 1, inst->inst_offset + 4, inst->inst_basereg);
 					} else {
-						ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-						ppc_addi (code, ppc_r11, ppc_r11, inst->inst_offset);
-						ppc_stw (code, ainfo->reg, 0, ppc_r11);
-						ppc_stw (code, ainfo->reg + 1, 4, ppc_r11);
+						ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+						ppc_addi (code, ppc_r12, ppc_r12, inst->inst_offset);
+						ppc_stw (code, ainfo->reg, 0, ppc_r12);
+						ppc_stw (code, ainfo->reg + 1, 4, ppc_r12);
 					}
 					break;
 #endif
@@ -4846,31 +4869,31 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_stptr (code, ainfo->reg, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_stptr (code, ainfo->reg, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_stptr (code, ainfo->reg, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_stptr_indexed (code, ainfo->reg, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_stptr_indexed (code, ainfo->reg, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
 				}
 			} else if (ainfo->regtype == RegTypeBase) {
 				g_assert (ppc_is_imm16 (ainfo->offset));
-				/* load the previous stack pointer in r11 */
-				ppc_ldr (code, ppc_r11, 0, ppc_sp);
-				ppc_ldptr (code, ppc_r0, ainfo->offset, ppc_r11);
+				/* load the previous stack pointer in r12 */
+				ppc_ldr (code, ppc_r12, 0, ppc_sp);
+				ppc_ldptr (code, ppc_r0, ainfo->offset, ppc_r12);
 				switch (ainfo->size) {
 				case 1:
 					if (ppc_is_imm16 (inst->inst_offset)) {
 						ppc_stb (code, ppc_r0, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_stb (code, ppc_r0, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_stb (code, ppc_r0, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_stbx (code, ppc_r0, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_stbx (code, ppc_r0, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4879,11 +4902,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_sth (code, ppc_r0, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_sth (code, ppc_r0, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_sth (code, ppc_r0, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_sthx (code, ppc_r0, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_sthx (code, ppc_r0, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4893,11 +4916,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_stw (code, ppc_r0, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_stw (code, ppc_r0, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_stw (code, ppc_r0, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_stwx (code, ppc_r0, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_stwx (code, ppc_r0, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4905,8 +4928,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 					if (ppc_is_imm16 (inst->inst_offset)) {
 						ppc_str (code, ppc_r0, inst->inst_offset, inst->inst_basereg);
 					} else {
-						ppc_load (code, ppc_r11, inst->inst_offset);
-						ppc_str_indexed (code, ppc_r0, ppc_r11, inst->inst_basereg);
+						ppc_load (code, ppc_r12, inst->inst_offset);
+						ppc_str_indexed (code, ppc_r0, ppc_r12, inst->inst_basereg);
 					}
 					break;
 #else
@@ -4914,15 +4937,15 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 					g_assert (ppc_is_imm16 (ainfo->offset + 4));
 					if (ppc_is_imm16 (inst->inst_offset + 4)) {
 						ppc_stw (code, ppc_r0, inst->inst_offset, inst->inst_basereg);
-						ppc_lwz (code, ppc_r0, ainfo->offset + 4, ppc_r11);
+						ppc_lwz (code, ppc_r0, ainfo->offset + 4, ppc_r12);
 						ppc_stw (code, ppc_r0, inst->inst_offset + 4, inst->inst_basereg);
 					} else {
-						/* use r12 to load the 2nd half of the long before we clobber r11.  */
-						ppc_lwz (code, ppc_r12, ainfo->offset + 4, ppc_r11);
-						ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-						ppc_addi (code, ppc_r11, ppc_r11, inst->inst_offset);
-						ppc_stw (code, ppc_r0, 0, ppc_r11);
-						ppc_stw (code, ppc_r12, 4, ppc_r11);
+						/* use r11 to load the 2nd half of the long before we clobber r12.  */
+						ppc_lwz (code, ppc_r11, ainfo->offset + 4, ppc_r12);
+						ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+						ppc_addi (code, ppc_r12, ppc_r12, inst->inst_offset);
+						ppc_stw (code, ppc_r0, 0, ppc_r12);
+						ppc_stw (code, ppc_r11, 4, ppc_r12);
 					}
 					break;
 #endif
@@ -4931,11 +4954,11 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 						ppc_stptr (code, ppc_r0, inst->inst_offset, inst->inst_basereg);
 					} else {
 						if (ppc_is_imm32 (inst->inst_offset)) {
-							ppc_addis (code, ppc_r11, inst->inst_basereg, ppc_ha(inst->inst_offset));
-							ppc_stptr (code, ppc_r0, inst->inst_offset, ppc_r11);
+							ppc_addis (code, ppc_r12, inst->inst_basereg, ppc_ha(inst->inst_offset));
+							ppc_stptr (code, ppc_r0, inst->inst_offset, ppc_r12);
 						} else {
-							ppc_load (code, ppc_r11, inst->inst_offset);
-							ppc_stptr_indexed (code, ppc_r0, inst->inst_basereg, ppc_r11);
+							ppc_load (code, ppc_r12, inst->inst_offset);
+							ppc_stptr_indexed (code, ppc_r0, inst->inst_basereg, ppc_r12);
 						}
 					}
 					break;
@@ -4994,39 +5017,39 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 					/* FIXME: we need to do the shifting here, too */
 					if (ainfo->bytes)
 						NOT_IMPLEMENTED;
-					/* load the previous stack pointer in r11 (r0 gets overwritten by the memcpy) */
-					ppc_ldr (code, ppc_r11, 0, ppc_sp);
+					/* load the previous stack pointer in r12 (r0 gets overwritten by the memcpy) */
+					ppc_ldr (code, ppc_r12, 0, ppc_sp);
 					if ((size & MONO_PPC_32_64_CASE (3, 7)) != 0) {
 						code = emit_memcpy (code, size - soffset,
 							inst->inst_basereg, doffset,
-							ppc_r11, ainfo->offset + soffset);
+							ppc_r12, ainfo->offset + soffset);
 					} else {
 						code = emit_memcpy (code, ainfo->vtsize * sizeof (gpointer),
 							inst->inst_basereg, doffset,
-							ppc_r11, ainfo->offset + soffset);
+							ppc_r12, ainfo->offset + soffset);
 					}
 				}
 			} else if (ainfo->regtype == RegTypeStructByAddr) {
 				/* if it was originally a RegTypeBase */
 				if (ainfo->offset) {
-					/* load the previous stack pointer in r11 */
-					ppc_ldr (code, ppc_r11, 0, ppc_sp);
-					ppc_ldptr (code, ppc_r11, ainfo->offset, ppc_r11);
+					/* load the previous stack pointer in r12 */
+					ppc_ldr (code, ppc_r12, 0, ppc_sp);
+					ppc_ldptr (code, ppc_r12, ainfo->offset, ppc_r12);
 				} else {
-					ppc_mr (code, ppc_r11, ainfo->reg);
+					ppc_mr (code, ppc_r12, ainfo->reg);
 				}
 
 				if (cfg->tailcall_valuetype_addrs) {
 					MonoInst *addr = cfg->tailcall_valuetype_addrs [tailcall_struct_index];
 
 					g_assert (ppc_is_imm16 (addr->inst_offset));
-					ppc_stptr (code, ppc_r11, addr->inst_offset, addr->inst_basereg);
+					ppc_stptr (code, ppc_r12, addr->inst_offset, addr->inst_basereg);
 
 					tailcall_struct_index++;
 				}
 
 				g_assert (ppc_is_imm16 (inst->inst_offset));
-				code = emit_memcpy (code, ainfo->vtsize, inst->inst_basereg, inst->inst_offset, ppc_r11, 0);
+				code = emit_memcpy (code, ainfo->vtsize, inst->inst_basereg, inst->inst_offset, ppc_r12, 0);
 				/*g_print ("copy in %s: %d bytes from %d to offset: %d\n", method->name, ainfo->vtsize, ainfo->reg, inst->inst_offset);*/
 			} else
 				g_assert_not_reached ();
@@ -5047,8 +5070,8 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 			mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_INTERNAL_METHOD, 
 				     (gpointer)"mono_get_lmf_addr");
 			if ((FORCE_INDIR_CALL || cfg->method->dynamic) && !cfg->compile_aot) {
-				ppc_load_func (code, ppc_r0, 0);
-				ppc_mtlr (code, ppc_r0);
+				ppc_load_func (code, PPC_CALL_REG, 0);
+				ppc_mtlr (code, PPC_CALL_REG);
 				ppc_blrl (code);
 			} else {
 				ppc_bl (code, 0);
@@ -5058,25 +5081,25 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 		/* lmf_offset is the offset from the previous stack pointer,
 		 * alloc_size is the total stack space allocated, so the offset
 		 * of MonoLMF from the current stack ptr is alloc_size - lmf_offset.
-		 * The pointer to the struct is put in ppc_r11 (new_lmf).
+		 * The pointer to the struct is put in ppc_r12 (new_lmf).
 		 * The callee-saved registers are already in the MonoLMF structure
 		 */
-		ppc_addi (code, ppc_r11, ppc_sp, alloc_size - lmf_offset);
+		ppc_addi (code, ppc_r12, ppc_sp, alloc_size - lmf_offset);
 		/* ppc_r3 is the result from mono_get_lmf_addr () */
-		ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
+		ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r12);
 		/* new_lmf->previous_lmf = *lmf_addr */
 		ppc_ldptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
-		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
-		/* *(lmf_addr) = r11 */
-		ppc_stptr (code, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
+		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r12);
+		/* *(lmf_addr) = r12 */
+		ppc_stptr (code, ppc_r12, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
 		/* save method info */
 		if (cfg->compile_aot)
 			// FIXME:
 			ppc_load (code, ppc_r0, 0);
 		else
 			ppc_load_ptr (code, ppc_r0, method);
-		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
-		ppc_stptr (code, ppc_sp, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
+		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r12);
+		ppc_stptr (code, ppc_sp, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r12);
 		/* save the current IP */
 		if (cfg->compile_aot) {
 			ppc_bl (code, 1);
@@ -5089,7 +5112,7 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 			ppc_load_sequence (code, ppc_r0, (gulong)0x01010101L);
 #endif
 		}
-		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
+		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r12);
 	}
 
 	if (tracing)
@@ -5141,21 +5164,21 @@ mono_arch_emit_epilog (MonoCompile *cfg)
 		lmf_offset = pos;
 		/* save the frame reg in r8 */
 		ppc_mr (code, ppc_r8, cfg->frame_reg);
-		ppc_addi (code, ppc_r11, cfg->frame_reg, cfg->stack_usage - lmf_offset);
+		ppc_addi (code, ppc_r12, cfg->frame_reg, cfg->stack_usage - lmf_offset);
 		/* r5 = previous_lmf */
-		ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
+		ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r12);
 		/* r6 = lmf_addr */
-		ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
+		ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r12);
 		/* *(lmf_addr) = previous_lmf */
 		ppc_stptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
 		/* FIXME: speedup: there is no actual need to restore the registers if
 		 * we didn't actually change them (idea from Zoltan).
 		 */
 		/* restore iregs */
-		ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r11);
+		ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r12);
 		/* restore fregs */
 		/*for (i = 14; i < 32; i++) {
-			ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r11);
+			ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r12);
 		}*/
 		g_assert (ppc_is_imm16 (cfg->stack_usage + PPC_RET_ADDR_OFFSET));
 		/* use the saved copy of the frame reg in r8 */
@@ -5170,8 +5193,8 @@ mono_arch_emit_epilog (MonoCompile *cfg)
 			if (ppc_is_imm16 (return_offset)) {
 				ppc_ldr (code, ppc_r0, return_offset, cfg->frame_reg);
 			} else {
-				ppc_load (code, ppc_r11, return_offset);
-				ppc_ldr_indexed (code, ppc_r0, cfg->frame_reg, ppc_r11);
+				ppc_load (code, ppc_r12, return_offset);
+				ppc_ldr_indexed (code, ppc_r0, cfg->frame_reg, ppc_r12);
 			}
 			ppc_mtlr (code, ppc_r0);
 		}
@@ -5182,7 +5205,7 @@ mono_arch_emit_epilog (MonoCompile *cfg)
 					offset -= sizeof (mgreg_t);
 			}
 			if (cfg->frame_reg != ppc_sp)
-				ppc_mr (code, ppc_r11, cfg->frame_reg);
+				ppc_mr (code, ppc_r12, cfg->frame_reg);
 			/* note r31 (possibly the frame register) is restored last */
 			for (i = 13; i <= 31; i++) {
 				if (cfg->used_int_regs & (1 << i)) {
@@ -5191,22 +5214,22 @@ mono_arch_emit_epilog (MonoCompile *cfg)
 				}
 			}
 			if (cfg->frame_reg != ppc_sp)
-				ppc_addi (code, ppc_sp, ppc_r11, cfg->stack_usage);
+				ppc_addi (code, ppc_sp, ppc_r12, cfg->stack_usage);
 			else
 				ppc_addi (code, ppc_sp, ppc_sp, cfg->stack_usage);
 		} else {
-			ppc_load32 (code, ppc_r11, cfg->stack_usage);
+			ppc_load32 (code, ppc_r12, cfg->stack_usage);
 			if (cfg->used_int_regs) {
-				ppc_add (code, ppc_r11, cfg->frame_reg, ppc_r11);
+				ppc_add (code, ppc_r12, cfg->frame_reg, ppc_r12);
 				for (i = 31; i >= 13; --i) {
 					if (cfg->used_int_regs & (1 << i)) {
 						pos += sizeof (mgreg_t);
-						ppc_ldr (code, i, -pos, ppc_r11);
+						ppc_ldr (code, i, -pos, ppc_r12);
 					}
 				}
-				ppc_mr (code, ppc_sp, ppc_r11);
+				ppc_mr (code, ppc_sp, ppc_r12);
 			} else {
-				ppc_add (code, ppc_sp, cfg->frame_reg, ppc_r11);
+				ppc_add (code, ppc_sp, cfg->frame_reg, ppc_r12);
 			}
 		}
 
@@ -5357,8 +5380,8 @@ mono_arch_emit_exceptions (MonoCompile *
 			patch_info->data.name = "mono_arch_throw_corlib_exception";
 			patch_info->ip.i = code - cfg->native_code;
 			if (FORCE_INDIR_CALL || cfg->method->dynamic) {
-				ppc_load_func (code, ppc_r0, 0);
-				ppc_mtctr (code, ppc_r0);
+				ppc_load_func (code, PPC_CALL_REG, 0);
+				ppc_mtctr (code, PPC_CALL_REG);
 				ppc_bcctr (code, PPC_BR_ALWAYS, 0);
 			} else {
 				ppc_bl (code, 0);
@@ -5595,15 +5618,15 @@ mono_arch_build_imt_thunk (MonoVTable *v
 	start = code;
 
 	/*
-	 * We need to save and restore r11 because it might be
+	 * We need to save and restore r12 because it might be
 	 * used by the caller as the vtable register, so
 	 * clobbering it will trip up the magic trampoline.
 	 *
-	 * FIXME: Get rid of this by making sure that r11 is
+	 * FIXME: Get rid of this by making sure that r12 is
 	 * not used as the vtable register in interface calls.
 	 */
-	ppc_stptr (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_sp);
-	ppc_load (code, ppc_r11, (gsize)(& (vtable->vtable [0])));
+	ppc_stptr (code, ppc_r12, PPC_RET_ADDR_OFFSET, ppc_sp);
+	ppc_load (code, ppc_r12, (gsize)(& (vtable->vtable [0])));
 
 	for (i = 0; i < count; ++i) {
 		MonoIMTCheckItem *item = imt_entries [i];
@@ -5619,8 +5642,8 @@ mono_arch_build_imt_thunk (MonoVTable *v
 				if (item->has_target_code) {
 					ppc_load_ptr (code, ppc_r0, item->value.target_code);
 				} else {
-					ppc_ldptr (code, ppc_r0, (sizeof (gpointer) * item->value.vtable_slot), ppc_r11);
-					ppc_ldptr (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_sp);
+					ppc_ldptr (code, ppc_r0, (sizeof (gpointer) * item->value.vtable_slot), ppc_r12);
+					ppc_ldptr (code, ppc_r12, PPC_RET_ADDR_OFFSET, ppc_sp);
 				}
 				ppc_mtctr (code, ppc_r0);
 				ppc_bcctr (code, PPC_BR_ALWAYS, 0);
@@ -5652,8 +5675,8 @@ mono_arch_build_imt_thunk (MonoVTable *v
 					item->jmp_code = code;
 					ppc_bc (code, PPC_BR_FALSE, PPC_BR_EQ, 0);
 #endif
-					ppc_ldptr (code, ppc_r0, (sizeof (gpointer) * item->value.vtable_slot), ppc_r11);
-					ppc_ldptr (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_sp);
+					ppc_ldptr (code, ppc_r0, (sizeof (gpointer) * item->value.vtable_slot), ppc_r12);
+					ppc_ldptr (code, ppc_r12, PPC_RET_ADDR_OFFSET, ppc_sp);
 					ppc_mtctr (code, ppc_r0);
 					ppc_bcctr (code, PPC_BR_ALWAYS, 0);
 #if ENABLE_WRONG_METHOD_CHECK
@@ -5779,17 +5802,17 @@ mono_arch_emit_load_got_addr (guint8 *st
  *   Emit code to load the contents of the GOT slot identified by TRAMP_TYPE and
  * TARGET from the mscorlib GOT in full-aot code.
  * On PPC, the GOT address is assumed to be in r30, and the result is placed into 
- * r11.
+ * r12.
  */
 guint8*
 mono_arch_emit_load_aotconst (guint8 *start, guint8 *code, MonoJumpInfo **ji, int tramp_type, gconstpointer target)
 {
 	/* Load the mscorlib got address */
-	ppc_ldptr (code, ppc_r11, sizeof (gpointer), ppc_r30);
+	ppc_ldptr (code, ppc_r12, sizeof (gpointer), ppc_r30);
 	*ji = mono_patch_info_list_prepend (*ji, code - start, tramp_type, target);
 	/* arch_emit_got_access () patches this */
 	ppc_load32 (code, ppc_r0, 0);
-	ppc_ldptr_indexed (code, ppc_r11, ppc_r11, ppc_r0);
+	ppc_ldptr_indexed (code, ppc_r12, ppc_r12, ppc_r0);
 
 	return code;
 }
@@ -5812,8 +5835,8 @@ mono_arch_set_breakpoint (MonoJitInfo *j
 	guint8 *code = ip;
 	guint8 *orig_code = code;
 
-	ppc_load_sequence (code, ppc_r11, (gsize)bp_trigger_page);
-	ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+	ppc_load_sequence (code, ppc_r12, (gsize)bp_trigger_page);
+	ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 
 	g_assert (code - orig_code == BREAKPOINT_SIZE);
 
--- mono-3.2.8+dfsg.orig/mono/mini/mini-ppc.h
+++ mono-3.2.8+dfsg/mono/mini/mini-ppc.h
@@ -69,7 +69,13 @@ typedef struct MonoCompileArch {
 #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
@@ -96,9 +102,10 @@ typedef struct MonoCompileArch {
 #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__)
@@ -165,6 +172,8 @@ 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)
@@ -172,9 +181,9 @@ typedef struct MonoCompileArch {
 
 #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_VTABLE_REG	ppc_r11
 #define MONO_ARCH_RGCTX_REG	MONO_ARCH_IMT_REG
 
 #define MONO_ARCH_NO_IOV_CHECK 1
--- mono-3.2.8+dfsg.orig/mono/mini/mini.c
+++ mono-3.2.8+dfsg/mono/mini/mini.c
@@ -6929,10 +6929,9 @@ mini_get_debug_options (void)
 static gpointer
 mini_create_ftnptr (MonoDomain *domain, gpointer addr)
 {
-#if !defined(__ia64__) && !defined(__ppc64__) && !defined(__powerpc64__)
+#if !defined(__ia64__) && (!defined(__ppc64__) && !defined(__powerpc64__) || _CALL_ELF == 2)
 	return addr;
 #else
-
 	gpointer* desc = NULL;
 
 	if ((desc = g_hash_table_lookup (domain->ftnptrs_hash, addr)))
@@ -6958,7 +6957,7 @@ mini_create_ftnptr (MonoDomain *domain,
 static gpointer
 mini_get_addr_from_ftnptr (gpointer descr)
 {
-#if defined(__ia64__) || defined(__ppc64__) || defined(__powerpc64__)
+#if defined(__ia64__) || ((defined(__ppc64__) || defined(__powerpc64__)) && _CALL_ELF != 2)
 	return *(gpointer*)descr;
 #else
 	return descr;
--- mono-3.2.8+dfsg.orig/mono/mini/tramp-ppc.c
+++ mono-3.2.8+dfsg/mono/mini/tramp-ppc.c
@@ -300,44 +300,44 @@ mono_arch_create_generic_trampoline (Mon
 	if (aot) {
 		code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "mono_get_lmf_addr");
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-		ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
-		ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+		ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r12);
+		ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 #endif
-		ppc_mtlr (code, ppc_r11);
+		ppc_mtlr (code, ppc_r12);
 		ppc_blrl (code);
 	}  else {
-		ppc_load_func (code, ppc_r0, mono_get_lmf_addr);
-		ppc_mtlr (code, ppc_r0);
+		ppc_load_func (code, PPC_CALL_REG, mono_get_lmf_addr);
+		ppc_mtlr (code, PPC_CALL_REG);
 		ppc_blrl (code);
 	}
 	/* we build the MonoLMF structure on the stack - see mini-ppc.h
-	 * The pointer to the struct is put in ppc_r11.
+	 * The pointer to the struct is put in ppc_r12.
 	 */
-	ppc_addi (code, ppc_r11, ppc_sp, STACK - sizeof (MonoLMF));
-	ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
+	ppc_addi (code, ppc_r12, ppc_sp, STACK - sizeof (MonoLMF));
+	ppc_stptr (code, ppc_r3, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r12);
 	/* new_lmf->previous_lmf = *lmf_addr */
 	ppc_ldptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
-	ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
-	/* *(lmf_addr) = r11 */
-	ppc_stptr (code, ppc_r11, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
+	ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r12);
+	/* *(lmf_addr) = r12 */
+	ppc_stptr (code, ppc_r12, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r3);
 	/* save method info (it's stored on the stack, so get it first). */
 	if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP)) {
 		ppc_ldr (code, ppc_r0, GREGS_OFFSET, ppc_r1);
-		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
+		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r12);
 	} else {
 		ppc_load (code, ppc_r0, 0);
-		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r11);
+		ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, method), ppc_r12);
 	}
 	/* store the frame pointer of the calling method */
 	ppc_addi (code, ppc_r0, ppc_sp, STACK);
-	ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r11);
+	ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, ebp), ppc_r12);
 	/* save the IP (caller ip) */
 	if (tramp_type == MONO_TRAMPOLINE_JUMP) {
 		ppc_li (code, ppc_r0, 0);
 	} else {
 		ppc_ldr (code, ppc_r0, STACK + PPC_RET_ADDR_OFFSET, ppc_r1);
 	}
-	ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r11);
+	ppc_stptr (code, ppc_r0, G_STRUCT_OFFSET(MonoLMF, eip), ppc_r12);
 
 	/*
 	 * Now we're ready to call trampoline (mgreg_t *regs, guint8 *code, gpointer value, guint8 *tramp)
@@ -361,15 +361,15 @@ mono_arch_create_generic_trampoline (Mon
 	if (aot) {
 		code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("trampoline_func_%d", tramp_type));
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-		ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r11);
-		ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+		ppc_ldptr (code, ppc_r2, sizeof (gpointer), ppc_r12);
+		ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 #endif
-		ppc_mtlr (code, ppc_r11);
+		ppc_mtlr (code, ppc_r12);
 		ppc_blrl (code);
 	} else {
 		tramp_handler = mono_get_trampoline_func (tramp_type);
-		ppc_load_func (code, ppc_r0, tramp_handler);
-		ppc_mtlr (code, ppc_r0);
+		ppc_load_func (code, PPC_CALL_REG, tramp_handler);
+		ppc_mtlr (code, PPC_CALL_REG);
 		ppc_blrl (code);
 	}
 		
@@ -389,20 +389,20 @@ mono_arch_create_generic_trampoline (Mon
 	 * Now we restore the MonoLMF (see emit_epilogue in mini-ppc.c)
 	 * and the rest of the registers, so the method called will see
 	 * the same state as before we executed.
-	 * The pointer to MonoLMF is in ppc_r11.
+	 * The pointer to MonoLMF is in ppc_r12.
 	 */
-	ppc_addi (code, ppc_r11, ppc_r1, STACK - sizeof (MonoLMF));
+	ppc_addi (code, ppc_r12, ppc_r1, STACK - sizeof (MonoLMF));
 	/* r5 = previous_lmf */
-	ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r11);
+	ppc_ldptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r12);
 	/* r6 = lmf_addr */
-	ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r11);
+	ppc_ldptr (code, ppc_r6, G_STRUCT_OFFSET(MonoLMF, lmf_addr), ppc_r12);
 	/* *(lmf_addr) = previous_lmf */
 	ppc_stptr (code, ppc_r5, G_STRUCT_OFFSET(MonoLMF, previous_lmf), ppc_r6);
 	/* restore iregs */
-	ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r11);
+	ppc_ldr_multiple (code, ppc_r13, G_STRUCT_OFFSET(MonoLMF, iregs), ppc_r12);
 	/* restore fregs */
 	for (i = 14; i < 32; i++)
-		ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r11);
+		ppc_lfd (code, i, G_STRUCT_OFFSET(MonoLMF, fregs) + ((i-14) * sizeof (gdouble)), ppc_r12);
 
 	/* restore the volatile registers, we skip r1, of course */
 	offset = STACK - sizeof (MonoLMF) - (14 * sizeof (double));
@@ -424,8 +424,8 @@ mono_arch_create_generic_trampoline (Mon
 	 */
 	/* Restore stack pointer and LR and jump to the code */
 	ppc_ldr  (code, ppc_r1,  0, ppc_r1);
-	ppc_ldr  (code, ppc_r11, PPC_RET_ADDR_OFFSET, ppc_r1);
-	ppc_mtlr (code, ppc_r11);
+	ppc_ldr  (code, ppc_r12, PPC_RET_ADDR_OFFSET, ppc_r1);
+	ppc_mtlr (code, ppc_r12);
 	if (MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type))
 		ppc_blr (code);
 	else
@@ -596,9 +596,9 @@ mono_arch_create_rgctx_lazy_fetch_trampo
 		code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, g_strdup_printf ("specific_trampoline_lazy_fetch_%u", slot));
 		/* Branch to the trampoline */
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-		ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+		ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 #endif
-		ppc_mtctr (code, ppc_r11);
+		ppc_mtctr (code, ppc_r12);
 		ppc_bcctr (code, PPC_BR_ALWAYS, 0);
 	} else {
 		tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
@@ -658,9 +658,9 @@ mono_arch_create_generic_class_init_tram
 		code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_generic_class_init");
 		/* Branch to the trampoline */
 #ifdef PPC_USES_FUNCTION_DESCRIPTOR
-		ppc_ldptr (code, ppc_r11, 0, ppc_r11);
+		ppc_ldptr (code, ppc_r12, 0, ppc_r12);
 #endif
-		ppc_mtctr (code, ppc_r11);
+		ppc_mtctr (code, ppc_r12);
 		ppc_bcctr (code, PPC_BR_ALWAYS, 0);
 	} else {
 		tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT,
--- mono-3.2.8+dfsg.orig/mono/utils/lock-free-alloc.c
+++ mono-3.2.8+dfsg/mono/utils/lock-free-alloc.c
@@ -123,7 +123,9 @@ struct _MonoLockFreeAllocDescriptor {
 
 #define NUM_DESC_BATCH	64
 
-#define SB_SIZE		16384
+/* SB_SIZE must be a multiple of the system pagesize, which for some
+   archs is 64k.  */
+#define SB_SIZE		65536
 #define SB_HEADER_SIZE	16
 #define SB_USABLE_SIZE	(SB_SIZE - SB_HEADER_SIZE)
 
--- mono-3.2.8+dfsg.orig/mono/utils/mono-mmap.c
+++ mono-3.2.8+dfsg/mono/utils/mono-mmap.c
@@ -332,6 +332,11 @@ mono_valloc (void *addr, size_t length,
 int
 mono_vfree (void *addr, size_t length)
 {
+/*if ( (length & (mono_pagesize () - 1)) != 0)
+  printf ("XXXX vfree: length not multiple of pagesize\n");
+if ( aligned_address (addr, length, mono_pagesize()) != addr)
+  printf ("XXXX vfree: addr not aligned to pagesize\n");*/
+
 	return munmap (addr, length);
 }
 
--- mono-3.2.8+dfsg.orig/mono/utils/strtod.c
+++ mono-3.2.8+dfsg/mono/utils/strtod.c
@@ -173,6 +173,12 @@
  * #define NO_ERRNO if strtod should not assign errno = ERANGE when
  *	the result overflows to +-Infinity or underflows to 0.
  */
+#if defined __BIG_ENDIAN__ || defined _BIG_ENDIAN
+#   define IEEE_MC68k
+#elif defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN
+#   define IEEE_8087
+#else
+
 #if defined(TARGET_X86) || defined(mips) && defined(MIPSEL) || defined (__arm__)
 
 #   define IEEE_8087
@@ -194,9 +200,12 @@
 #   define IEEE_MC68k
 
 #else
+#warning byte order unknown, assuming big endian
 #define IEEE_MC68k
 #endif
 
+#endif
+
 #define Long gint32
 #define ULong guint32
 
