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.0.6+dfsg2-4) unstable; urgency=low
 .
   [ Iain Lane ]
   * [2a84a9f] Install Mono.Posix and System.Data.OracleClient into 4.5 too
 .
   [ Neale Ferguson ]
   * [a4118b9] Add lazy rgctx support to s390x
     (cherry picked from commit 3cbc51a82063f879680eab3c99415028e9c80c00)
   * [8f533d3] Correct call parameter processing for GENERICINST types
     (cherry picked from commit efa707b468967f1fa57bb39c642109439dc03c84)
   * [a99f491] Remove unneeded call - lazy support
     (cherry picked from commit 89cbc62dee8e694b1d80157d254322523bbce411)
Author: Mirco Bauer <meebey@debian.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.0.6+dfsg2.orig/configure.in
+++ mono-3.0.6+dfsg2/configure.in
@@ -150,6 +150,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
@@ -2448,7 +2459,7 @@ case "$host" in
 			sgen_supported=true
 			AOT_SUPPORTED="yes"
 			;;
-		  darwin*|openbsd*|freebsd*)
+		  darwin*|openbsd*|freebsd*|kfreebsd-gnu*)
 			sgen_supported=true
 		        ;;
 		esac
@@ -2462,7 +2473,7 @@ case "$host" in
 			sgen_supported=true
 			AOT_SUPPORTED="yes"
 			;;
-		  darwin*|openbsd*|freebsd*)
+		  darwin*|openbsd*|freebsd*|kfreebsd-gnu*)
 			sgen_supported=true
 			;;
 		esac
@@ -2791,6 +2802,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"
@@ -2806,7 +2822,7 @@ case "$host" in
     *-*-*linux*)
 	AC_PATH_X
 	AC_MSG_CHECKING(for the soname of libX11.so)
-	for i in $x_libraries /usr/lib /usr/lib64; do
+	for i in $x_libraries /usr/lib /usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/; do
 		for r in 4 5 6; do
 			if test -f $i/libX11.so.$r; then
 				X11=libX11.so.$r
@@ -2914,32 +2930,32 @@ if test "x$with_tls" = "x__thread"; then
 	])
 fi
 
-if test ${TARGET} = ARM && test x$cross_compiling = xno && test x$enable_mcs_build != xno; then
+AC_ARG_WITH(fpu, [ --with-fpu=FPA,VFP,VFP_HARD,NONE    Select fpu to use on arm],[fpu=$withval])
+
+if test ${TARGET} = ARM; then
 	dnl ******************************************
 	dnl *** Check to see what FPU is available ***
 	dnl ******************************************
 	AC_MSG_CHECKING(which FPU to use)
 
-	fpu=NONE
-	if gcc -v 2>&1 | grep -q -- '--with-float=hard'; then
+	if test x$fpu = x && gcc -v 2>&1 | grep -q -- '--with-float=hard'; then
 	   fpu=VFP_HARD
 	fi
 
-	if test x$fpu = xNONE; then
+	if test x$fpu = x; then
 	   ORIG_CFLAGS=$CFLAGS
 	   CFLAGS="$CFLAGS -mfpu=vfp -mfloat-abi=softfp"
 	   AC_TRY_RUN([
 				int main () { __asm__ ("faddd	d7, d6, d7"); return 0; }
-				], fpu=VFP, fpu=NONE)
+				], fpu=VFP, fpu=)
 	   CFLAGS=$ORIG_CFLAGS
 	fi
 
-	if test x$fpu = xNONE; then
+	if test x$fpu = x; then
 		AC_TRY_COMPILE([], [
 			__asm__ ("ldfd f0, [r0]");
 			], fpu=FPA, fpu=NONE)
 	fi
-
 	AC_MSG_RESULT($fpu)
 	CPPFLAGS="$CPPFLAGS -DARM_FPU_$fpu=1"
 	unset fpu
--- mono-3.0.6+dfsg2.orig/Makefile.am
+++ mono-3.0.6+dfsg2/Makefile.am
@@ -4,7 +4,7 @@ MOONLIGHT_SUBDIRS = $(libgc_dir) eglib/s
 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
@@ -15,7 +15,7 @@ else
 if ONLY_MOONLIGHT
 SUBDIRS = $(MOONLIGHT_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.0.6+dfsg2.orig/mono/arch/s390x/s390x-codegen.h
+++ mono-3.0.6+dfsg2/mono/arch/s390x/s390x-codegen.h
@@ -593,11 +593,14 @@ typedef struct {
 #define s390_basr(c, r1, r2)		S390_RR(c, 0x0d, r1, r2)
 #define s390_bctr(c, r1, r2)		S390_RR(c, 0x06, r1, r2)
 #define s390_bctrg(c, r1, r2)		S390_RRE(c, 0xb946, r1, r2)
+#define s390_bnzr(c, r)			S390_RR(c, 0x07, 0x07, r)
 #define s390_bras(c, r, o)		S390_RI(c, 0xa75, r, o)
 #define s390_brasl(c, r, o)		S390_RIL_1(c, 0xc05, r, o)
 #define s390_brc(c, m, d)		S390_RI(c, 0xa74, m, d)
+#define s390_brcl(c, m, d)		S390_RIL_2(c, 0xc04, m, d)
 #define s390_br(c, r)			S390_RR(c, 0x07, 0xf, r)
 #define s390_break(c)			S390_RR(c, 0, 0, 0)
+#define s390_bzr(c, r)			S390_RR(c, 0x07, 0x08, r)
 #define s390_c(c, r, x, b, d)		S390_RX(c, 0x59, r, x, b, d)
 #define s390_cdb(c, r, x, b, d)		S390_RXE(c, 0xed19, r, x, b, d)
 #define s390_cdbr(c, r1, r2)		S390_RRE(c, 0xb319, r1, r2)
@@ -636,7 +639,7 @@ typedef struct {
 #define s390_icy(c, r, x, b, d)		S390_RXY(c, 0xe373, r, x, b, d)
 #define s390_j(c,d)			s390_brc(c, S390_CC_UN, d)
 #define s390_jc(c, m, d)		s390_brc(c, m, d)
-#define s390_jcl(c, m, d)		S390_RIL_2(c, 0xc04, m, d)
+#define s390_jcl(c, m, d)		s390_brcl(c, m, d)
 #define s390_jcy(c, d)			s390_brc(c, S390_CC_CY, d)
 #define s390_je(c, d)			s390_brc(c, S390_CC_EQ, d)
 #define s390_jeo(c, d)			s390_brc(c, S390_CC_ZR|S390_CC_OV, d)
@@ -654,6 +657,24 @@ typedef struct {
 #define s390_jno(c, d)			s390_brc(c, S390_CC_NO, d)
 #define s390_jp(c, d)			s390_brc(c, S390_CC_GT, d)
 #define s390_jz(c, d)			s390_brc(c, S390_CC_ZR, d)
+#define s390_jg(c,d)			s390_brcl(c, S390_CC_UN, d)
+#define s390_jgcy(c, d)			s390_brcl(c, S390_CC_CY, d)
+#define s390_jge(c, d)			s390_brcl(c, S390_CC_EQ, d)
+#define s390_jgeo(c, d)			s390_brcl(c, S390_CC_ZR|S390_CC_OV, d)
+#define s390_jgh(c, d)			s390_brcl(c, S390_CC_GT, d)
+#define s390_jgho(c, d)			s390_brcl(c, S390_CC_GT|S390_CC_OV, d)
+#define s390_jgl(c, d)			s390_brcl(c, S390_CC_LT, d)
+#define s390_jglo(c, d)			s390_brcl(c, S390_CC_LT|S390_CC_OV, d)
+#define s390_jgm(c, d)			s390_brcl(c, S390_CC_LT, d)
+#define s390_jgnc(c, d)			s390_brcl(c, S390_CC_NC, d)
+#define s390_jgne(c, d)			s390_brcl(c, S390_CC_NZ, d)
+#define s390_jgnh(c, d)			s390_brcl(c, S390_CC_LE, d)
+#define s390_jgnl(c, d)			s390_brcl(c, S390_CC_GE, d)
+#define s390_jgnz(c, d)			s390_brcl(c, S390_CC_NZ, d)
+#define s390_jgo(c, d)			s390_brcl(c, S390_CC_OV, d)
+#define s390_jgno(c, d)			s390_brcl(c, S390_CC_NO, d)
+#define s390_jgp(c, d)			s390_brcl(c, S390_CC_GT, d)
+#define s390_jgz(c, d)			s390_brcl(c, S390_CC_ZR, d)
 #define s390_l(c, r, x, b, d)		S390_RX(c, 0x58, r, x, b, d)
 #define s390_ly(c, r, x, b, d)		S390_RXY(c, 0xe358, r, x, b, d)
 #define s390_la(c, r, x, b, d)		S390_RX(c, 0x41, r, x, b, d)
--- mono-3.0.6+dfsg2.orig/mono/io-layer/io.c
+++ mono-3.0.6+dfsg2/mono/io-layer/io.c
@@ -4194,7 +4194,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.0.6+dfsg2.orig/mono/utils/mono-sigcontext.h
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/mono/tests/Makefile.am
+++ mono-3.0.6+dfsg2/mono/tests/Makefile.am
@@ -340,7 +340,6 @@ BASE_TEST_CS_SRC=		\
 	modules.cs	\
 	bug-81673.cs	\
 	bug-81691.cs	\
-	bug-80307.cs	\
 	bug-415577.cs	\
 	filter-stack.cs	\
 	vararg2.cs	\
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-x86.h
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/mono/mini/tramp-s390x.c
+++ mono-3.0.6+dfsg2/mono/mini/tramp-s390x.c
@@ -27,6 +27,9 @@
 #define CREATE_FP_OFFSET	CREATE_GR_OFFSET+GR_SAVE_SIZE
 #define CREATE_LMF_OFFSET	CREATE_FP_OFFSET+FP_SAVE_SIZE
 #define CREATE_STACK_SIZE	(CREATE_LMF_OFFSET+2*sizeof(long)+sizeof(MonoLMF))
+#define GENERIC_REG_OFFSET	CREATE_STACK_SIZE + \
+				S390_REG_SAVE_OFFSET + \
+				3*sizeof(long)
 
 /*------------------------------------------------------------------*/
 /* Method-specific trampoline code fragment sizes		    */
@@ -343,10 +346,11 @@ mono_arch_create_generic_trampoline (Mon
 		s390_lg   (buf, s390_r3, 0, s390_r11, S390_RET_ADDR_OFFSET);
 	}
 
-	/* Arg 3: MonoMethod *method. It was put in r1 by the
-	   method-specific trampoline code, and then saved before the call
-	   to mono_get_lmf_addr()'. */
-	s390_lg  (buf, s390_r4, 0, STK_BASE, METHOD_SAVE_OFFSET);
+	/* Arg 3: Trampoline argument */
+	if (tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
+		s390_lg (buf, s390_r4, 0, STK_BASE, GENERIC_REG_OFFSET);
+	else
+		s390_lg (buf, s390_r4, 0, STK_BASE, METHOD_SAVE_OFFSET);
 
 	/* Arg 4: trampoline address. Ignore for now */
 		
@@ -387,10 +391,12 @@ mono_arch_create_generic_trampoline (Mon
 	s390_lgr  (buf, STK_BASE, s390_r11);
 	s390_lmg  (buf, s390_r6, s390_r14, STK_BASE, S390_REG_SAVE_OFFSET);
 
-	if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT || tramp_type == MONO_TRAMPOLINE_GENERIC_CLASS_INIT)
-		s390_br (buf, s390_r14);
-	else
-		s390_br (buf, s390_r1);
+	if (MONO_TRAMPOLINE_TYPE_MUST_RETURN(tramp_type)) {
+		s390_lgr (buf, s390_r2, s390_r1);
+		s390_br  (buf, s390_r14);
+	} else {
+		s390_br  (buf, s390_r1);
+	}
 
 	/* Flush instruction cache, since we've generated code */
 	mono_arch_flush_icache (code, buf - code);
@@ -435,7 +441,7 @@ mono_arch_create_specific_trampoline (gp
 	s390_llong(buf, arg1);
 	s390_lg   (buf, s390_r1, 0, s390_r1, 4);
 	displace = (tramp - buf) / 2;
-	s390_jcl  (buf, S390_CC_UN, displace);
+	s390_jg   (buf, displace);
 
 	/* Flush instruction cache, since we've generated code */
 	mono_arch_flush_icache (code, buf - code);
@@ -462,9 +468,201 @@ mono_arch_create_specific_trampoline (gp
 gpointer
 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot)
 {
-	/* FIXME: implement! */
+#ifdef MONO_ARCH_VTABLE_REG
+	guint8 *tramp;
+	guint8 *code, *buf;
+	guint8 **rgctx_null_jumps;
+	gint32 displace;
+	int tramp_size,
+	    depth, 
+	    index, 
+	    iPatch = 0,
+	    i;
+	gboolean mrgctx;
+	MonoJumpInfo *ji = NULL;
+	GSList *unwind_ops = NULL;
+
+	mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
+	index = MONO_RGCTX_SLOT_INDEX (slot);
+	if (mrgctx)
+		index += MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT / sizeof (gpointer);
+	for (depth = 0; ; ++depth) {
+		int size = mono_class_rgctx_get_array_size (depth, mrgctx);
+
+		if (index < size - 1)
+			break;
+		index -= size - 1;
+	}
+
+	tramp_size = 48 + 16 * depth;
+	if (mrgctx)
+		tramp_size += 4;
+	else
+		tramp_size += 12;
+
+	code = buf = mono_global_codeman_reserve (tramp_size);
+
+	unwind_ops = mono_arch_get_cie_program ();
+
+	rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
+
+	if (mrgctx) {
+		/* get mrgctx ptr */
+		s390_lgr (code, s390_r1, s390_r2);
+	} else {
+		/* load rgctx ptr from vtable */
+		s390_lg (code, s390_r1, 0, s390_r2, G_STRUCT_OFFSET(MonoVTable, runtime_generic_context));
+		/* is the rgctx ptr null? */
+		s390_ltgr (code, s390_r1, s390_r1);
+		/* if yes, jump to actual trampoline */
+		rgctx_null_jumps [iPatch++] = code;
+		s390_jge (code, 0);
+	}
+
+	for (i = 0; i < depth; ++i) {
+		/* load ptr to next array */
+		if (mrgctx && i == 0)
+			s390_lg (code, s390_r1, 0, s390_r1, MONO_SIZEOF_METHOD_RUNTIME_GENERIC_CONTEXT);
+		else
+			s390_lg (code, s390_r1, 0, s390_r1, 0);
+		s390_ltgr (code, s390_r1, s390_r1);
+		/* if the ptr is null then jump to actual trampoline */
+		rgctx_null_jumps [iPatch++] = code;
+		s390_jge (code, 0);
+	}
+
+	/* fetch slot */
+	s390_lg (code, s390_r1, 0, s390_r1, (sizeof (gpointer) * (index  + 1)));
+	/* is the slot null? */
+	s390_ltgr (code, s390_r1, s390_r1);
+	/* if yes, jump to actual trampoline */
+	rgctx_null_jumps [iPatch++] = code;
+	s390_jge (code, 0);
+	/* otherwise return r1 */
+	s390_lgr (code, s390_r2, s390_r1);
+	s390_br  (code, s390_r14);
+
+	for (i = 0; i < iPatch; i++) {
+		displace = ((uintptr_t) code - (uintptr_t) rgctx_null_jumps[i]) / 2;
+		s390_patch_rel ((rgctx_null_jumps [i] + 2), displace);
+	}
+
+	g_free (rgctx_null_jumps);
+
+	/* move the rgctx pointer to the VTABLE register */
+	s390_lgr (code, MONO_ARCH_VTABLE_REG, s390_r2);
+
+	tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot),
+		MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
+
+	/* jump to the actual trampoline */
+	displace = (tramp - code) / 2;
+	s390_jg (code, displace);
+
+	mono_arch_flush_icache (buf, code - buf);
+
+	g_assert (code - buf <= tramp_size);
+
+	if (info)
+		*info = mono_tramp_info_create (mono_get_rgctx_fetch_trampoline_name (slot), buf, code - buf, ji, unwind_ops);
+
+	return(buf);
+#else
 	g_assert_not_reached ();
-	return NULL;
+#endif
+	return(NULL);
 }	
 
 /*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name    	- mono_arch_get_static_rgctx_trampoline		    */
+/*                                                                  */
+/* Function	- Create a trampoline which sets RGCTX_REG to MRGCTX*/
+/*		  then jumps to ADDR.				    */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_get_static_rgctx_trampoline (MonoMethod *m, 
+					MonoMethodRuntimeGenericContext *mrgctx, 
+					gpointer addr)
+{
+	guint8 *code, *start;
+	gint32 displace;
+	int buf_len;
+
+	MonoDomain *domain = mono_domain_get ();
+
+	buf_len = 32;
+
+	start = code = mono_domain_code_reserve (domain, buf_len);
+
+	s390_basr (code, s390_r1, 0);
+	s390_j    (code, 6);
+	s390_llong(code, mrgctx);
+	s390_lg   (code, MONO_ARCH_RGCTX_REG, 0, s390_r1, 4);
+	displace = ((uintptr_t) addr - (uintptr_t) code) / 2;
+	s390_jg   (code, displace);
+	g_assert ((code - start) < buf_len);
+
+	mono_arch_flush_icache (start, code - start);
+
+	return(start);
+}	
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name		- mono_arch_create_generic_class_init_trampoline    */
+/*                                                                  */
+/* Function	- 						    */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+	guint8 *tramp;
+	guint8 *code, *buf;
+	static int byte_offset = -1;
+	static guint8 bitmask;
+	guint8 *jump;
+	gint32 displace;
+	int tramp_size;
+	GSList *unwind_ops = NULL;
+	MonoJumpInfo *ji = NULL;
+
+	tramp_size = 48;
+
+	code = buf = mono_global_codeman_reserve (tramp_size);
+
+	unwind_ops = mono_arch_get_cie_program ();
+
+	if (byte_offset < 0)
+		mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
+
+	s390_llgc(code, s390_r0, 0, MONO_ARCH_VTABLE_REG, byte_offset);
+	s390_nill(code, s390_r0, bitmask);
+	s390_bnzr(code, s390_r14);
+
+	tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT,
+		mono_get_root_domain (), NULL);
+
+	/* jump to the actual trampoline */
+	displace = (tramp - code) / 2;
+	s390_jg (code, displace);
+
+	mono_arch_flush_icache (buf, code - buf);
+
+	g_assert (code - buf <= tramp_size);
+
+	if (info)
+		*info = mono_tramp_info_create (g_strdup_printf ("generic_class_init_trampoline"), buf, code - buf, ji, unwind_ops);
+
+	return(buf);
+}
+
+/*========================= End of Function ========================*/
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-amd64.h
+++ mono-3.0.6+dfsg2/mono/mini/mini-amd64.h
@@ -282,7 +282,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.0.6+dfsg2.orig/mono/mini/mini-s390x.c
+++ mono-3.0.6+dfsg2/mono/mini/mini-s390x.c
@@ -246,6 +246,9 @@ if (ins->inst_target_bb->native_offset)
 #define JUMP_SIZE	6
 #define ENABLE_WRONG_METHOD_CHECK 0
 
+#define mono_mini_arch_lock() EnterCriticalSection (&mini_arch_mutex)
+#define mono_mini_arch_unlock() LeaveCriticalSection (&mini_arch_mutex)
+
 /*========================= End of Defines =========================*/
 
 /*------------------------------------------------------------------*/
@@ -365,7 +368,7 @@ static gboolean is_regsize_var (MonoType
 static inline void add_general (guint *, size_data *, ArgInfo *);
 static inline void add_stackParm (guint *, size_data *, ArgInfo *, gint);
 static inline void add_float (guint *, size_data *, ArgInfo *);
-static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *, gboolean);
+static CallInfo * get_call_info (MonoCompile *, MonoMemPool *, MonoMethodSignature *);
 static guchar * emit_float_to_int (MonoCompile *, guchar *, int, int, int, gboolean);
 static guint8 * emit_load_volatile_arguments (guint8 *, MonoCompile *);
 static void catch_SIGILL(int, siginfo_t *, void *);
@@ -414,6 +417,11 @@ static gpointer bp_trigger_page;
 
 breakpoint_t breakpointCode;
 
+/* 
+ * This mutex protects architecture specific caches 
+ */
+static CRITICAL_SECTION mini_arch_mutex;
+
 /*====================== End of Global Variables ===================*/
 
 /*------------------------------------------------------------------*/
@@ -916,7 +924,7 @@ enter_method (MonoMethod *method, RegPar
 	
 	sig = mono_method_signature (method);
 	
-	cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
+	cinfo = get_call_info (NULL, NULL, sig);
 
 	if (cinfo->struct_ret) {
 		printf ("[STRUCTRET:%p], ", (gpointer) rParm->gr[0]);
@@ -1623,12 +1631,13 @@ add_float (guint *fr,  size_data *sz, Ar
 /*------------------------------------------------------------------*/
 
 static CallInfo *
-get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig, gboolean is_pinvoke)
+get_call_info (MonoCompile *cfg, MonoMemPool *mp, MonoMethodSignature *sig)
 {
 	guint i, fr, gr, size, pstart;
 	int nParm = sig->hasthis + sig->param_count;
 	MonoType *ret_type;
-	guint32 simpletype, align;
+	guint32 simpleType, align;
+	gboolean is_pinvoke = sig->pinvoke;
 	CallInfo *cinfo;
 	size_data *sz;
 	MonoGenericSharingContext *gsctx = cfg ? cfg->generic_sharing_context : NULL;
@@ -1659,11 +1668,11 @@ get_call_info (MonoCompile *cfg, MonoMem
 	/* area that the callee will use.			    */
 	/*----------------------------------------------------------*/
 
-	ret_type = mono_type_get_underlying_type (sig->ret);
+	ret_type = mini_type_get_underlying_type (gsctx, sig->ret);
 	ret_type = mini_get_basic_type_from_generic (gsctx, ret_type);
-	simpletype = ret_type->type;
+	simpleType = ret_type->type;
 enum_retvalue:
-	switch (simpletype) {
+	switch (simpleType) {
 		case MONO_TYPE_BOOLEAN:
 		case MONO_TYPE_I1:
 		case MONO_TYPE_U1:
@@ -1704,13 +1713,10 @@ enum_retvalue:
 		case MONO_TYPE_VALUETYPE: {
 			MonoClass *klass = mono_class_from_mono_type (sig->ret);
 			if (klass->enumtype) {
-				simpletype = mono_class_enum_basetype (klass)->type;
+				simpleType = mono_class_enum_basetype (klass)->type;
 				goto enum_retvalue;
 			}
-			if (sig->pinvoke)
-				size = mono_class_native_size (klass, &align);
-			else
-				size = mono_class_value_size (klass, &align);
+			size = mini_type_stack_size_full (gsctx, &klass->byval_arg, NULL, sig->pinvoke);
 	
 			cinfo->struct_ret = 1;
 			cinfo->ret.size   = size;
@@ -1803,11 +1809,10 @@ enum_retvalue:
 			continue;
 		}
 
-		ptype = mono_type_get_underlying_type (sig->params [i]);
-		ptype = mini_get_basic_type_from_generic (gsctx, ptype);
-		simpletype = ptype->type;
-		cinfo->args[nParm].type = simpletype;
-		switch (simpletype) {
+		ptype = mini_type_get_underlying_type (gsctx, sig->params [i]);
+		simpleType = ptype->type;
+		cinfo->args[nParm].type = simpleType;
+		switch (simpleType) {
 		case MONO_TYPE_BOOLEAN:
 		case MONO_TYPE_I1:
 		case MONO_TYPE_U1:
@@ -1858,7 +1863,7 @@ enum_retvalue:
 			nParm++;
 			break;
 		case MONO_TYPE_GENERICINST:
-			if (!mono_type_generic_inst_is_valuetype (sig->params [i])) {
+			if (!mono_type_generic_inst_is_valuetype (ptype)) {
 				cinfo->args[nParm].size = sizeof(gpointer);
 				add_general (&gr, sz, cinfo->args+nParm);
 				nParm++;
@@ -1867,30 +1872,29 @@ enum_retvalue:
 			/* Fall through */
 		case MONO_TYPE_VALUETYPE: {
 			MonoMarshalType *info;
-			MonoClass *klass = mono_class_from_mono_type (sig->params [i]);
-			if (sig->pinvoke)
-				size = mono_class_native_size (klass, &align);
-			else
-				size = mono_class_value_size (klass, &align);
-	
-			info = mono_marshal_load_type_info (klass);
+			MonoClass *klass = mono_class_from_mono_type (ptype);
 
-			if ((info->native_size == sizeof(float)) &&
-			    (info->num_fields  == 1) &&
-			    (info->fields[0].field->type->type == MONO_TYPE_R4)) {
-				cinfo->args[nParm].size = sizeof(float);
-				add_float(&fr, sz, cinfo->args+nParm);
-				nParm ++;
-				break;
-			}
+			size = mini_type_stack_size_full(gsctx, &klass->byval_arg, NULL, sig->pinvoke);
+			if (simpleType != MONO_TYPE_GENERICINST) {
+				info = mono_marshal_load_type_info(klass);
 
-			if ((info->native_size == sizeof(double)) &&
-			    (info->num_fields  == 1) &&
-			    (info->fields[0].field->type->type == MONO_TYPE_R8)) {
-				cinfo->args[nParm].size = sizeof(double);
-				add_float(&fr, sz, cinfo->args+nParm);
-				nParm ++;
-				break;
+				if ((info->native_size == sizeof(float)) &&
+				    (info->num_fields  == 1) &&
+				    (info->fields[0].field->type->type == MONO_TYPE_R4)) {
+					cinfo->args[nParm].size = sizeof(float);
+					add_float(&fr, sz, cinfo->args+nParm);
+					nParm ++;
+					break;
+				}
+
+				if ((info->native_size == sizeof(double)) &&
+				    (info->num_fields  == 1) &&
+				    (info->fields[0].field->type->type == MONO_TYPE_R8)) {
+					cinfo->args[nParm].size = sizeof(double);
+					add_float(&fr, sz, cinfo->args+nParm);
+					nParm ++;
+					break;
+				}
 			}
 
 			cinfo->args[nParm].vtsize  = 0;
@@ -1949,7 +1953,7 @@ enum_retvalue:
 		}
 			break;
 		default:
-			g_error ("Can't trampoline 0x%x", sig->params [i]->type);
+			g_error ("Can't trampoline 0x%x", ptype);
 		}
 	}
 
@@ -2043,7 +2047,7 @@ mono_arch_allocate_vars (MonoCompile *cf
 
 	sig     = mono_method_signature (cfg->method);
 	
-	cinfo   = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo   = get_call_info (cfg, cfg->mempool, sig);
 
 	if (!cinfo->struct_ret) {
 		switch (mono_type_get_underlying_type (sig->ret)->type) {
@@ -2272,7 +2276,7 @@ mono_arch_create_vars (MonoCompile *cfg)
 
 	sig = mono_method_signature (cfg->method);
 
-	cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo = get_call_info (cfg, cfg->mempool, sig);
 
 	if (cinfo->struct_ret) {
 		cfg->vret_addr = mono_compile_create_var (cfg, &mono_defaults.int_class->byval_arg, OP_ARG);
@@ -2387,7 +2391,7 @@ mono_arch_emit_call (MonoCompile *cfg, M
 	n = sig->param_count + sig->hasthis;
 	DEBUG (g_print ("Call requires: %d parameters\n",n));
 	
-	cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo = get_call_info (cfg, cfg->mempool, sig);
 
 	stackSize         = cinfo->sz.stack_size + cinfo->sz.local_size + 
 			    cinfo->sz.parm_size + cinfo->sz.offset;
@@ -4161,6 +4165,7 @@ mono_arch_output_basic_block (MonoCompil
 			/* ensure ins->sreg1 is not NULL */
 			s390_lg   (code, s390_r0, 0, ins->sreg1, 0);
 			s390_ltgr (code, s390_r0, s390_r0);
+			EMIT_COND_SYSTEM_EXCEPTION (S390_CC_ZR, "NullReferenceException");
 		}
 			break;
 		case OP_ARGLIST: {
@@ -4979,8 +4984,11 @@ mono_arch_patch_code (MonoMethod *method
 			case MONO_PATCH_INFO_EXC:
 			case MONO_PATCH_INFO_ABS:
 			case MONO_PATCH_INFO_METHOD:
+			case MONO_PATCH_INFO_RGCTX_FETCH:
 			case MONO_PATCH_INFO_INTERNAL_METHOD:
 			case MONO_PATCH_INFO_CLASS_INIT:
+			case MONO_PATCH_INFO_JIT_ICALL_ADDR:
+			case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
 				s390_patch_addr (ip, (guint64) target);
 				continue;
 			case MONO_PATCH_INFO_SWITCH: 
@@ -5037,7 +5045,7 @@ emit_load_volatile_arguments (guint8 *co
 	int pos = 0, i;
 	CallInfo *cinfo;
 
-	cinfo = get_call_info (NULL, NULL, sig, sig->pinvoke);
+	cinfo = get_call_info (NULL, NULL, sig);
 
 	if (cinfo->struct_ret) {
 		ArgInfo *ainfo = &cinfo->ret;
@@ -5191,6 +5199,15 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 
 	mono_emit_unwind_op_def_cfa_reg (cfg, code, cfg->frame_reg);
 
+	/* store runtime generic context */
+	if (cfg->rgctx_var) {
+		g_assert (cfg->rgctx_var->opcode == OP_REGOFFSET);
+
+		s390_stg  (code, MONO_ARCH_RGCTX_REG, 0, 
+			   cfg->rgctx_var->inst_basereg, 
+			   cfg->rgctx_var->inst_offset);
+	}
+
         /* compute max_offset in order to use short forward jumps
 	 * we always do it on s390 because the immediate displacement
 	 * for jumps is too small 
@@ -5211,7 +5228,7 @@ mono_arch_emit_prolog (MonoCompile *cfg)
 	sig = mono_method_signature (method);
 	pos = 0;
 
-	cinfo = get_call_info (cfg, cfg->mempool, sig, sig->pinvoke);
+	cinfo = get_call_info (cfg, cfg->mempool, sig);
 
 	if (cinfo->struct_ret) {
 		ArgInfo *ainfo     = &cinfo->ret;
@@ -6230,6 +6247,44 @@ mono_arch_find_imt_method (mgreg_t *regs
 }
 
 /*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name		- mono_arch_find_static_call_vtable                 */
+/*                                                                  */
+/* Function	- Find the static call vtable.                      */
+/*		                               			    */
+/*------------------------------------------------------------------*/
+
+MonoVTable*
+mono_arch_find_static_call_vtable (mgreg_t *regs, guint8 *code)
+{
+	mgreg_t *r = (mgreg_t*)regs;
+
+	return (MonoVTable*)(gsize) r [MONO_ARCH_RGCTX_REG];
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/* Name		- mono_arch_get_cie_program                         */
+/*                                                                  */
+/* Function	- Find the static call vtable.                      */
+/*		                               			    */
+/*------------------------------------------------------------------*/
+
+GSList*
+mono_arch_get_cie_program (void)
+{
+	GSList *l = NULL;
+
+	mono_add_unwind_op_def_cfa (l, NULL, NULL, STK_BASE, 0);
+
+	return(l);
+}
+
+/*========================= End of Function ========================*/
 
 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
 
--- mono-3.0.6+dfsg2.orig/mono/mini/mini-gc.c
+++ mono-3.0.6+dfsg2/mono/mini/mini-gc.c
@@ -2547,11 +2547,6 @@ mini_gc_set_slot_type_from_cfa (MonoComp
 
 #endif /* DISABLE_JIT */
 
-void
-mini_gc_enable_gc_maps_for_aot (void)
-{
-}
-
 #endif
 
 #ifndef DISABLE_JIT
--- mono-3.0.6+dfsg2.orig/mono/mini/Makefile.am
+++ mono-3.0.6+dfsg2/mono/mini/Makefile.am
@@ -169,12 +169,12 @@ mono_sgen_CFLAGS = $(AM_CFLAGS)
 # link was done
 if SUPPORT_BOEHM
 buildver.h: libmini-static.la
-	@echo "const char *build_date = \"`date`\";" > buildver.h
+	@echo "const char *build_date;" > buildver.h
 mono-main.$(OBJEXT): buildver.h
 endif
 
 buildver-sgen.h: libmini-static.la
-	@echo "const char *build_date = \"`date`\";" > buildver-sgen.h
+	@echo "const char *build_date;" > buildver-sgen.h
 mono_sgen-main.$(OBJEXT): buildver-sgen.h
 
 if DTRACE_G_REQUIRED
@@ -738,16 +738,7 @@ EXTRA_DIST = TestDriver.cs ldscript ldsc
 	$(posix_sources)
 
 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.0.6+dfsg2.orig/mono/mini/mini-s390x.h
+++ mono-3.0.6+dfsg2/mono/mini/mini-s390x.h
@@ -117,6 +117,8 @@ typedef struct
 #define MONO_ARCH_HAVE_TLS_GET				1
 #define MONO_ARCH_ENABLE_MONO_LMF_VAR			1
 #define MONO_ARCH_IMT_REG				s390_r9
+#define MONO_ARCH_VTABLE_REG				MONO_ARCH_IMT_REG
+#define MONO_ARCH_RGCTX_REG				MONO_ARCH_IMT_REG
 #define MONO_ARCH_THIS_AS_FIRST_ARG     		1
 #define MONO_ARCH_HAVE_XP_UNWIND			1
 #define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX		1
@@ -124,6 +126,8 @@ typedef struct
 #define MONO_ARCH_HAVE_CONTEXT_SET_INT_REG		1
 #define MONO_ARCH_USE_SIGACTION 			1
 #define MONO_ARCH_GC_MAPS_SUPPORTED			1
+#define MONO_ARCH_GSHARED_SUPPORTED			1
+#define MONO_ARCH_MONITOR_ENTER_ADJUSTMENT		1
 
 #define S390_STACK_ALIGNMENT		 8
 #define S390_FIRST_ARG_REG 		s390_r2
--- mono-3.0.6+dfsg2.orig/mono/mini/cpu-s390x.md
+++ mono-3.0.6+dfsg2/mono/mini/cpu-s390x.md
@@ -70,7 +70,7 @@ call_reg: dest:o src1:i len:8 clob:c
 ceq: dest:i len:12
 cgt.un: dest:i len:12
 cgt: dest:i len:12
-checkthis: src1:b len:10
+checkthis: src1:b len:16
 ckfinite: dest:f src1:f len:22
 clt.un: dest:i len:12
 clt: dest:i len:12
--- mono-3.0.6+dfsg2.orig/mono/metadata/sgen-os-posix.c
+++ mono-3.0.6+dfsg2/mono/metadata/sgen-os-posix.c
@@ -35,7 +35,7 @@
 #include "metadata/sgen-archdep.h"
 #include "metadata/object-internals.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.0.6+dfsg2.orig/mono/metadata/security.c
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/data/mono.pc.in
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/data/mono-cairo.pc.in
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/support/syslog.c
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/mcs/class/System.Net/Makefile
+++ mono-3.0.6+dfsg2/mcs/class/System.Net/Makefile
@@ -3,7 +3,7 @@ SUBDIRS =
 include ../../build/rules.make
 
 LIBRARY = System.Net.dll
-LIB_MCS_FLAGS =  -unsafe -r:System.dll -r:System.Core.dll -r:System.Xml.dll -d:NET_2_1 -d:NET_2_0 -d:NET_1_1
+LIB_MCS_FLAGS =  -unsafe -r:System.dll -r:System.Core.dll -r:System.Xml.dll
 
 ifneq (2.1, $(FRAMEWORK_VERSION))
 LIB_MCS_FLAGS += -d:NET_3_5 -nowarn:1720
--- mono-3.0.6+dfsg2.orig/mcs/class/corlib/System/Console.cs
+++ mono-3.0.6+dfsg2/mcs/class/corlib/System/Console.cs
@@ -133,8 +133,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.0.6+dfsg2.orig/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
+++ mono-3.0.6+dfsg2/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs
@@ -553,14 +553,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.0.6+dfsg2.orig/libgc/dyn_load.c
+++ mono-3.0.6+dfsg2/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(_GNU_SOURCE)
+#if (defined(__linux__) || defined(__GLIBC__)) && !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) /* Are others OK here, too? */ \
+# if (defined(LINUX) || defined (__GLIBC__)) /* Are others OK here, too? */ \
      && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
          || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG))) 
 
--- mono-3.0.6+dfsg2.orig/libgc/configure.in
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/libgc/include/gc.h
+++ mono-3.0.6+dfsg2/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.0.6+dfsg2.orig/libgc/include/private/gcconfig.h
+++ mono-3.0.6+dfsg2/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
 
@@ -1368,8 +1368,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
@@ -2136,6 +2143,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__
@@ -2223,7 +2252,7 @@
 #   define SUNOS5SIGS
 # endif
 
-# if defined(FREEBSD) && (__FreeBSD__ >= 4)
+# if defined(FREEBSD) && ((__FreeBSD__ >= 4) || (__FreeBSD_kernel__ >= 4))
 #   define SUNOS5SIGS
 # endif
 
@@ -2286,7 +2315,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	*/
@@ -2367,7 +2396,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
