diff --git gdb/Makefile.in gdb/Makefile.in
index 17b71c6e7c..282522187b 100644
--- gdb/Makefile.in
+++ gdb/Makefile.in
@@ -230,7 +230,8 @@ INCGNU = -I$(srcdir)/gnulib/import -I$(GNULIB_BUILDDIR)/import
 
 # Generated headers in the gnulib directory.  These must be listed
 # so that they are generated before other files are compiled.
-GNULIB_H = $(GNULIB_BUILDDIR)/import/string.h @GNULIB_STDINT_H@
+GNULIB_H = $(GNULIB_BUILDDIR)/import/string.h \
+	$(GNULIB_BUILDDIR)/import/alloca.h @GNULIB_STDINT_H@
 
 #
 # CLI sub directory definitons
@@ -629,6 +630,7 @@ TARGET_OBS = @TARGET_OBS@
 # All target-dependent objects files that require 64-bit CORE_ADDR
 # (used with --enable-targets=all --enable-64-bit-bfd).
 ALL_64_TARGET_OBS = \
+	aarch64-fbsd-kern.o \
 	aarch64-fbsd-tdep.o \
 	aarch64-linux-tdep.o \
 	aarch64-newlib-tdep.o \
@@ -642,6 +644,7 @@ ALL_64_TARGET_OBS = \
 	amd64-darwin-tdep.o \
 	amd64-dicos-tdep.o \
 	amd64-fbsd-tdep.o \
+	amd64fbsd-kern.o \
 	amd64-linux-tdep.o \
 	amd64-nbsd-tdep.o \
 	amd64-obsd-tdep.o \
@@ -656,6 +659,7 @@ ALL_64_TARGET_OBS = \
 	ia64-vms-tdep.o \
 	mips64-obsd-tdep.o \
 	sparc64-fbsd-tdep.o \
+	sparc64fbsd-kern.o \
 	sparc64-linux-tdep.o \
 	sparc64-nbsd-tdep.o \
 	sparc64-obsd-tdep.o \
@@ -684,6 +688,8 @@ ALL_TARGET_OBS = \
 	cris-linux-tdep.o \
 	cris-tdep.o \
 	dicos-tdep.o \
+	fbsd-kld.o \
+	fbsd-kthr.o \
 	fbsd-tdep.o \
 	frv-linux-tdep.o \
 	frv-tdep.o \
@@ -700,6 +706,7 @@ ALL_TARGET_OBS = \
 	i386-darwin-tdep.o \
 	i386-dicos-tdep.o \
 	i386-fbsd-tdep.o \
+	i386fbsd-kern.o \
 	i386-gnu-tdep.o \
 	i386-go32-tdep.o \
 	i386-linux-tdep.o \
@@ -724,6 +731,7 @@ ALL_TARGET_OBS = \
 	mep-tdep.o \
 	microblaze-linux-tdep.o \
 	microblaze-tdep.o \
+	mipsfbsd-kern.o \
 	mips-fbsd-tdep.o \
 	mips-linux-tdep.o \
 	mips-nbsd-tdep.o \
@@ -741,6 +749,7 @@ ALL_TARGET_OBS = \
 	nto-tdep.o \
 	obsd-tdep.o \
 	ppc-fbsd-tdep.o \
+	ppcfbsd-kern.o \
 	ppc-linux-tdep.o \
 	ppc-nbsd-tdep.o \
 	ppc-obsd-tdep.o \
@@ -1610,7 +1619,7 @@ generated_files = \
 # Flags needed to compile Python code
 PYTHON_CFLAGS = @PYTHON_CFLAGS@
 
-all: gdb$(EXEEXT) $(CONFIG_ALL)
+all: gdb$(EXEEXT) kgdb$(EXEEXT) $(CONFIG_ALL)
 	@$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do
 
 # Rule for compiling .c files in the top-level gdb directory.
@@ -1920,6 +1929,12 @@ gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS)
 		-o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \
 		$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
 
+kgdb$(EXEEXT): kgdb-main.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS)
+	rm -f kgdb$(EXEEXT)
+	$(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \
+		-o kgdb$(EXEEXT) kgdb-main.o $(LIBGDB_OBS) \
+		$(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES)
+
 # Convenience rule to handle recursion.
 $(LIBGNU) $(GNULIB_H): all-lib
 all-lib: $(GNULIB_BUILDDIR)/Makefile
@@ -1964,7 +1979,7 @@ clean mostlyclean: $(CONFIG_CLEAN)
 	@$(MAKE) $(FLAGS_TO_PASS) DO=clean "DODIRS=$(CLEANDIRS)" subdir_do
 	rm -f *.o *.a $(ADD_FILES) *~ init.c-tmp init.l-tmp version.c-tmp
 	rm -f init.c version.c observer.h observer.inc
-	rm -f gdb$(EXEEXT) core make.log
+	rm -f gdb$(EXEEXT) core make.log kgdb$(EXEEXT)
 	rm -f gdb[0-9]$(EXEEXT)
 	rm -f test-cp-name-parser$(EXEEXT)
 	rm -f xml-builtin.c stamp-xml
@@ -2178,6 +2193,7 @@ MAKEOVERRIDES =
 
 ALLDEPFILES = \
 	aarch64-fbsd-nat.c \
+	aarch64-fbsd-kern.c \
 	aarch64-fbsd-tdep.c \
 	aarch64-linux-nat.c \
 	aarch64-linux-tdep.c \
@@ -2195,6 +2211,7 @@ ALLDEPFILES = \
 	amd64-bsd-nat.c \
 	amd64-darwin-tdep.c \
 	amd64-dicos-tdep.c \
+	amd64fbsd-kern.c \
 	amd64-fbsd-nat.c \
 	amd64-fbsd-tdep.c \
 	amd64-linux-nat.c \
@@ -2228,6 +2245,9 @@ ALLDEPFILES = \
 	darwin-nat.c \
 	dicos-tdep.c \
 	exec.c \
+	fbsd-kld.c \
+	fbsd-kthr.c \
+	fbsd-kvm.c \
 	fbsd-nat.c \
 	fbsd-tdep.c \
 	fork-child.c \
@@ -2249,6 +2269,7 @@ ALLDEPFILES = \
 	i386-darwin-nat.c \
 	i386-darwin-tdep.c \
 	i386-dicos-tdep.c \
+	i386fbsd-kern.c \
 	i386-fbsd-nat.c \
 	i386-fbsd-tdep.c \
 	i386-gnu-nat.c \
@@ -2290,6 +2311,7 @@ ALLDEPFILES = \
 	mingw-hdep.c \
 	mips-fbsd-nat.c \
 	mips-fbsd-tdep.c \
+	mipsfbsd-kern.c \
 	mips-linux-nat.c \
 	mips-linux-tdep.c \
 	mips-nbsd-nat.c \
@@ -2307,6 +2329,7 @@ ALLDEPFILES = \
 	obsd-nat.c \
 	obsd-tdep.c \
 	posix-hdep.c \
+	ppcfbsd-kern.c \
 	ppc-fbsd-nat.c \
 	ppc-fbsd-tdep.c \
 	ppc-linux-nat.c \
@@ -2351,6 +2374,7 @@ ALLDEPFILES = \
 	sparc-sol2-nat.c \
 	sparc-sol2-tdep.c \
 	sparc-tdep.c \
+	sparc64fbsd-kern.c \
 	sparc64-fbsd-nat.c \
 	sparc64-fbsd-tdep.c \
 	sparc64-linux-nat.c \
@@ -2638,7 +2662,7 @@ endif
 
 # A list of all the objects we might care about in this build, for
 # dependency tracking.
-all_object_files = gdb.o $(LIBGDB_OBS) gdbtk-main.o \
+all_object_files = kgdb-main.o gdb.o $(LIBGDB_OBS) gdbtk-main.o \
 	test-cp-name-parser.o
 
 # All the .deps files to include.
diff --git gdb/config.in gdb/config.in
index 1d11a97080..50a5a5b322 100644
--- gdb/config.in
+++ gdb/config.in
@@ -222,6 +222,9 @@
 /* Define to 1 if your system has the kinfo_getvmmap function. */
 #undef HAVE_KINFO_GETVMMAP
 
+/* Define to 1 if your system has the kvm_open2 function. */
+#undef HAVE_KVM_OPEN2
+
 /* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
 #undef HAVE_LANGINFO_CODESET
 
diff --git gdb/configure gdb/configure
index 84a0790c0d..f4c323d4ab 100755
--- gdb/configure
+++ gdb/configure
@@ -7927,6 +7927,66 @@ $as_echo "#define HAVE_KINFO_GETVMMAP 1" >>confdefs.h
 fi
 
 
+# kgdb needs kvm_open2 for cross-debugging
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing kvm_open2" >&5
+$as_echo_n "checking for library containing kvm_open2... " >&6; }
+if test "${ac_cv_search_kvm_open2+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char kvm_open2 ();
+int
+main ()
+{
+return kvm_open2 ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' kvm; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_kvm_open2=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if test "${ac_cv_search_kvm_open2+set}" = set; then :
+  break
+fi
+done
+if test "${ac_cv_search_kvm_open2+set}" = set; then :
+
+else
+  ac_cv_search_kvm_open2=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_kvm_open2" >&5
+$as_echo "$ac_cv_search_kvm_open2" >&6; }
+ac_res=$ac_cv_search_kvm_open2
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+$as_echo "#define HAVE_KVM_OPEN2 1" >>confdefs.h
+
+fi
+
+
 
       if test "X$prefix" = "XNONE"; then
     acl_final_prefix="$ac_default_prefix"
diff --git gdb/configure.ac gdb/configure.ac
index d4133ea71e..bac85c53e0 100644
--- gdb/configure.ac
+++ gdb/configure.ac
@@ -523,6 +523,11 @@ AC_SEARCH_LIBS(kinfo_getvmmap, util util-freebsd,
   [AC_DEFINE(HAVE_KINFO_GETVMMAP, 1,
             [Define to 1 if your system has the kinfo_getvmmap function. ])])
 
+# kgdb needs kvm_open2 for cross-debugging
+AC_SEARCH_LIBS(kvm_open2, kvm,
+  [AC_DEFINE(HAVE_KVM_OPEN2, 1,
+            [Define to 1 if your system has the kvm_open2 function. ])])
+
 AM_ICONV
 
 # GDB may fork/exec the iconv program to get the list of supported character
diff --git gdb/configure.nat gdb/configure.nat
index 8e14892722..ada205f34d 100644
--- gdb/configure.nat
+++ gdb/configure.nat
@@ -62,7 +62,8 @@ case ${gdb_host} in
 	LOADLIBES='-ldl $(RDYNAMIC)'
 	;;
     fbsd*)
-	NATDEPFILES='fork-child.o fork-inferior.o inf-ptrace.o fbsd-nat.o'
+	NATDEPFILES='fork-child.o fork-inferior.o inf-ptrace.o fbsd-nat.o \
+		fbsd-kvm.o'
 	HAVE_NATIVE_GCORE_HOST=1
 	LOADLIBES='-lkvm'
 	;;
diff --git gdb/configure.tgt gdb/configure.tgt
index fb8014a8e8..1a86608840 100644
--- gdb/configure.tgt
+++ gdb/configure.tgt
@@ -92,7 +92,7 @@ esac
 
 case "${targ}" in
 *-*-freebsd* | *-*-kfreebsd*-gnu)
-	os_obs="fbsd-tdep.o solib-svr4.o";;
+	os_obs="fbsd-tdep.o solib-svr4.o fbsd-kld.o fbsd-kthr.o";;
 *-*-netbsd* | *-*-knetbsd*-gnu)
 	os_obs="nbsd-tdep.o solib-svr4.o";;
 *-*-openbsd*)
@@ -249,7 +249,11 @@ i[34567]86-*-dicos*)
 	;;
 i[34567]86-*-freebsd* | i[34567]86-*-kfreebsd*-gnu)
 	# Target: FreeBSD/i386
-	gdb_target_obs="i386-bsd-tdep.o i386-fbsd-tdep.o "
+	gdb_target_obs="i386-bsd-tdep.o i386-fbsd-tdep.o i386fbsd-kern.o"
+	if test "x$enable_64_bit_bfd" = "xyes"; then
+	    # Target: FreeBSD amd64
+	    gdb_target_obs="amd64fbsd-tdep.o amd64fbsd-kern.o ${gdb_target_obs}"
+	fi
 	;;
 i[34567]86-*-netbsd* | i[34567]86-*-knetbsd*-gnu)
 	# Target: NetBSD/i386
@@ -408,7 +412,7 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu)
 	;;
 mips*-*-freebsd*)
 	# Target: MIPS running FreeBSD
-	gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o"
+	gdb_target_obs="mips-tdep.o mips-fbsd-tdep.o mipsfbsd-kern.o"
 	gdb_sim=../sim/mips/libsim.a
 	;;
 mips64*-*-openbsd*)
@@ -472,7 +476,7 @@ or1k-*-* | or1knd-*-*)
 powerpc*-*-freebsd*)
 	# Target: FreeBSD/powerpc
 	gdb_target_obs="rs6000-tdep.o ppc-sysv-tdep.o ppc64-tdep.o \
-		        ppc-fbsd-tdep.o \
+		        ppc-fbsd-tdep.o ppcfbsd-kern.o \
 			ravenscar-thread.o ppc-ravenscar-thread.o"
 	;;
 
@@ -594,6 +598,7 @@ sparc64-*-linux*)
 sparc*-*-freebsd* | sparc*-*-kfreebsd*-gnu)
 	# Target: FreeBSD/sparc64
 	gdb_target_obs="sparc-tdep.o sparc64-tdep.o sparc64-fbsd-tdep.o \
+			sparc64fbsd-kern.o \
 			ravenscar-thread.o sparc-ravenscar-thread.o"
 	;;
 sparc-*-netbsd* | sparc-*-knetbsd*-gnu)
@@ -716,8 +721,8 @@ x86_64-*-linux*)
 	;;
 x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
 	# Target: FreeBSD/amd64
-	gdb_target_obs="amd64-fbsd-tdep.o ${i386_tobjs} \
-			i386-bsd-tdep.o i386-fbsd-tdep.o"
+	gdb_target_obs="amd64-fbsd-tdep.o amd64fbsd-kern.o ${i386_tobjs} \
+			i386-bsd-tdep.o i386-fbsd-tdep.o i386fbsd-kern.o"
 	;;
 x86_64-*-mingw* | x86_64-*-cygwin*)
         # Target: MingW/amd64
diff --git gdb/defs.h gdb/defs.h
index 4fb2129b30..0cb0bad5c5 100644
--- gdb/defs.h
+++ gdb/defs.h
@@ -516,6 +516,7 @@ enum gdb_osabi
   GDB_OSABI_SOLARIS,
   GDB_OSABI_LINUX,
   GDB_OSABI_FREEBSD,
+  GDB_OSABI_FREEBSD_KERNEL,
   GDB_OSABI_NETBSD,
   GDB_OSABI_OPENBSD,
   GDB_OSABI_WINCE,
diff --git gdb/gnulib/configure gdb/gnulib/configure
index 37efd06b67..a23fc0a81c 100644
--- gdb/gnulib/configure
+++ gdb/gnulib/configure
@@ -16790,6 +16790,7 @@ else
       case "$host_os" in
                 # Guess all is fine on glibc systems.
         *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
+        freebsd*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
                 # If we don't know, assume the worst.
         *)      gl_cv_func_gettimeofday_clobber="guessing yes" ;;
       esac
diff --git gdb/osabi.c gdb/osabi.c
index 129164f51e..4eacc074a3 100644
--- gdb/osabi.c
+++ gdb/osabi.c
@@ -65,6 +65,7 @@ static const struct osabi_names gdb_osabi_names[] =
   { "Solaris", NULL },
   { "GNU/Linux", "linux(-gnu)?" },
   { "FreeBSD", NULL },
+  { "FreeBSD/kernel", NULL },
   { "NetBSD", NULL },
   { "OpenBSD", NULL },
   { "WindowsCE", NULL },
diff --git gdb/regcache.c gdb/regcache.c
index fb6a904dec..f9b7105b8f 100644
--- gdb/regcache.c
+++ gdb/regcache.c
@@ -1079,6 +1079,23 @@ regcache::raw_supply_zeroed (int regnum)
   m_register_status[regnum] = REG_VALID;
 }
 
+void
+regcache::raw_supply_unsigned (int regnum, ULONGEST val)
+{
+  enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
+  gdb_byte *regbuf;
+  size_t regsize;
+
+  assert_regnum (regnum);
+  gdb_assert (!m_readonly_p);
+
+  regbuf = register_buffer (regnum);
+  regsize = m_descr->sizeof_register[regnum];
+
+  store_unsigned_integer (regbuf, regsize, byte_order, val);
+  m_register_status[regnum] = REG_VALID;
+}
+
 /* Collect register REGNUM from REGCACHE and store its contents in BUF.  */
 
 void
diff --git gdb/regcache.h gdb/regcache.h
index 9e3da8c3fc..5c65a9be1e 100644
--- gdb/regcache.h
+++ gdb/regcache.h
@@ -294,6 +294,8 @@ public:
   void raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len,
 			   bool is_signed);
 
+  void raw_supply_unsigned (int regnum, ULONGEST val);
+
   void raw_supply_zeroed (int regnum);
 
   enum register_status get_register_status (int regnum) const;
