[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Thu Jan 5 12:04:37 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/77905f94b3a7
changeset: 262:77905f94b3a7
user:      ray at terran.dlink.ua
date:      Thu Jan 05 13:30:52 2012 +0200
description:
FreeBSD HEAD @svn 229577r.

diffstat:

 head/bin/sh/exec.c                                                    |     5 +-
 head/bin/sh/exec.h                                                    |     3 +-
 head/bin/sh/expand.c                                                  |   100 +-
 head/bin/sh/expand.h                                                  |     3 +-
 head/bin/sh/histedit.c                                                |     8 +-
 head/bin/sh/input.c                                                   |     5 +-
 head/bin/sh/input.h                                                   |     3 +-
 head/bin/sh/main.c                                                    |     5 +-
 head/bin/sh/main.h                                                    |     3 +-
 head/bin/sh/myhistedit.h                                              |     4 +-
 head/bin/sh/mystring.c                                                |    21 +-
 head/bin/sh/mystring.h                                                |     3 +-
 head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/io/tst.fds.c |     2 +-
 head/contrib/compiler-rt/LICENSE.TXT                                  |     4 +-
 head/contrib/compiler-rt/lib/trampoline_setup.c                       |     2 +-
 head/contrib/less/command.c                                           |    14 +-
 head/contrib/less/prompt.c                                            |    20 +-
 head/games/fortune/fortune/fortune.c                                  |     8 +-
 head/gnu/usr.bin/gdb/kgdb/main.c                                      |     4 +-
 head/include/stdatomic.h                                              |     6 +-
 head/include/stdnoreturn.h                                            |     8 +-
 head/include/tgmath.h                                                 |   113 +-
 head/lib/clang/clang.build.mk                                         |     8 +-
 head/lib/clang/libllvmarminfo/Makefile                                |     4 +-
 head/lib/clang/libllvmmipsinfo/Makefile                               |     4 +-
 head/lib/clang/libllvmpowerpcinfo/Makefile                            |     4 +-
 head/lib/clang/libllvmx86info/Makefile                                |     4 +-
 head/lib/libc/Makefile                                                |     6 +-
 head/lib/libc/arm/string/Makefile.inc                                 |     9 +-
 head/lib/libc/gen/exec.c                                              |     4 +-
 head/lib/libc/gen/getttyent.c                                         |     8 +-
 head/lib/libc/gen/timezone.c                                          |     4 +-
 head/lib/libc/i386/string/Makefile.inc                                |     9 +-
 head/lib/libc/i386/string/index.S                                     |    66 -
 head/lib/libc/i386/string/rindex.S                                    |    67 -
 head/lib/libc/i386/string/strchr.S                                    |     4 +-
 head/lib/libc/i386/string/strrchr.S                                   |     4 +-
 head/lib/libc/mips/string/Makefile.inc                                |     8 +-
 head/lib/libc/mips/string/index.S                                     |    59 -
 head/lib/libc/mips/string/rindex.S                                    |    57 -
 head/lib/libc/mips/string/strchr.S                                    |    61 +
 head/lib/libc/mips/string/strrchr.S                                   |    59 +
 head/lib/libc/net/gethostbynis.c                                      |     4 +-
 head/lib/libc/net/getnetbynis.c                                       |     4 +-
 head/lib/libc/string/Makefile.inc                                     |     6 +-
 head/lib/libc/string/index.c                                          |    61 -
 head/lib/libc/string/rindex.c                                         |    62 -
 head/lib/libc/string/strchr.c                                         |    55 +-
 head/lib/libc/string/strrchr.c                                        |    56 +-
 head/lib/libc/sys/chroot.2                                            |    22 +-
 head/lib/libcam/camlib.c                                              |     4 +-
 head/lib/libpmc/pmc.corei7.3                                          |    19 +-
 head/lib/libstand/Makefile                                            |    17 +-
 head/lib/libstand/bootp.c                                             |     8 +-
 head/lib/libutil/libutil.h                                            |     3 +-
 head/lib/libutil/pw_util.c                                            |    18 +-
 head/lib/libutil/quotafile.c                                          |     4 +-
 head/lib/libvgl/simple.c                                              |   215 +-
 head/libexec/mknetid/parse_group.c                                    |     4 +-
 head/libexec/rlogind/rlogind.c                                        |     9 +-
 head/libexec/rtld-elf/rtld.c                                          |    11 +-
 head/release/picobsd/build/Makefile.conf                              |     7 +-
 head/release/picobsd/build/picobsd                                    |   168 +-
 head/sbin/bsdlabel/bsdlabel.c                                         |     6 +-
 head/sbin/dump/main.c                                                 |     4 +-
 head/sbin/fsck_ffs/pass2.c                                            |     4 +-
 head/sbin/ifconfig/ifconfig.8                                         |    11 +-
 head/sbin/ipfw/main.c                                                 |    12 +-
 head/sbin/shutdown/shutdown.c                                         |     4 +-
 head/share/man/man3/tgmath.3                                          |    25 +-
 head/share/man/man5/src.conf.5                                        |     9 +-
 head/share/man/man9/Makefile                                          |     3 +-
 head/share/man/man9/memcchr.9                                         |    59 +
 head/share/mk/bsd.own.mk                                              |     3 +-
 head/sys/Makefile                                                     |    14 +-
 head/sys/boot/common/interp_parse.c                                   |     4 +-
 head/sys/boot/i386/libi386/biospci.c                                  |     8 +-
 head/sys/boot/i386/libi386/comconsole.c                               |   221 +-
 head/sys/boot/i386/libi386/libi386.h                                  |     3 +-
 head/sys/boot/ofw/common/main.c                                       |     4 +-
 head/sys/boot/ofw/libofw/ofw_net.c                                    |     4 +-
 head/sys/boot/pc98/boot2/boot1.S                                      |     4 +-
 head/sys/boot/pc98/libpc98/comconsole.c                               |   221 +-
 head/sys/boot/userboot/libstand/Makefile                              |    10 +-
 head/sys/cam/ata/ata_da.c                                             |     9 +-
 head/sys/cam/scsi/scsi_cd.c                                           |    12 +-
 head/sys/cam/scsi/scsi_da.c                                           |    33 +-
 head/sys/cam/scsi/scsi_sa.c                                           |    34 +-
 head/sys/cam/scsi/scsi_ses.c                                          |     4 +-
 head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c       |     2 +-
 head/sys/compat/linux/linux_ioctl.c                                   |     4 +-
 head/sys/conf/files                                                   |    44 +-
 head/sys/conf/kern.pre.mk                                             |     6 +-
 head/sys/conf/options                                                 |     3 +-
 head/sys/contrib/xz-embedded/freebsd/xz_config.h                      |    73 +
 head/sys/contrib/xz-embedded/freebsd/xz_malloc.c                      |    49 +
 head/sys/contrib/xz-embedded/freebsd/xz_malloc.h                      |    34 +
 head/sys/contrib/xz-embedded/linux/Documentation/xz.txt               |   122 +
 head/sys/contrib/xz-embedded/linux/include/linux/decompress/unxz.h    |    19 +
 head/sys/contrib/xz-embedded/linux/include/linux/xz.h                 |   278 ++
 head/sys/contrib/xz-embedded/linux/lib/decompress_unxz.c              |   397 +++
 head/sys/contrib/xz-embedded/linux/lib/xz/Kconfig                     |    59 +
 head/sys/contrib/xz-embedded/linux/lib/xz/Makefile                    |     5 +
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_crc32.c                  |    59 +
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_bcj.c                |   574 ++++
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c              |  1171 ++++++++++
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_stream.c             |   821 +++++++
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_syms.c               |    26 +
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_test.c               |   220 +
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_lzma2.h                  |   204 +
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_private.h                |   156 +
 head/sys/contrib/xz-embedded/linux/lib/xz/xz_stream.h                 |    62 +
 head/sys/contrib/xz-embedded/linux/scripts/xz_wrap.sh                 |    23 +
 head/sys/contrib/xz-embedded/userspace/Makefile                       |    48 +
 head/sys/contrib/xz-embedded/userspace/boottest.c                     |    93 +
 head/sys/contrib/xz-embedded/userspace/buftest.c                      |    48 +
 head/sys/contrib/xz-embedded/userspace/xz_config.h                    |   109 +
 head/sys/contrib/xz-embedded/userspace/xzminidec.c                    |   132 +
 head/sys/ddb/db_input.c                                               |     4 +-
 head/sys/dev/ata/ata-disk.c                                           |     6 +-
 head/sys/dev/flash/mx25l.c                                            |     4 +-
 head/sys/dev/hwpmc/hwpmc_core.c                                       |    13 +-
 head/sys/dev/hwpmc/hwpmc_uncore.c                                     |    42 +-
 head/sys/dev/hwpmc/hwpmc_uncore.h                                     |     9 +-
 head/sys/dev/hwpmc/pmc_events.h                                       |    34 +-
 head/sys/dev/if_ndis/if_ndis_pccard.c                                 |     4 +-
 head/sys/dev/iwn/if_iwn.c                                             |     4 +-
 head/sys/dev/mxge/if_mxge.c                                           |     4 +-
 head/sys/dev/qlxgb/qla_misc.c                                         |     4 +-
 head/sys/dev/sound/pci/emu10k1.c                                      |   542 ++-
 head/sys/dev/sound/pci/emuxkireg.h                                    |   689 +++++
 head/sys/dev/tws/tws.c                                                |     3 +-
 head/sys/dev/uart/uart_bus_pci.c                                      |     6 +-
 head/sys/dev/uart/uart_cpu_sparc64.c                                  |     4 +-
 head/sys/dev/usb/controller/usb_controller.c                          |    10 +-
 head/sys/fs/ext2fs/ext2_alloc.c                                       |    41 +-
 head/sys/fs/nfs/nfsport.h                                             |     4 +-
 head/sys/fs/ntfs/ntfs_compr.c                                         |    12 +-
 head/sys/fs/ntfs/ntfs_subr.c                                          |     6 +-
 head/sys/fs/nullfs/null_subr.c                                        |     8 +-
 head/sys/fs/nullfs/null_vfsops.c                                      |     5 +-
 head/sys/fs/nullfs/null_vnops.c                                       |    10 +-
 head/sys/fs/nwfs/nwfs_vfsops.c                                        |     6 +-
 head/sys/fs/smbfs/smbfs_vfsops.c                                      |     6 +-
 head/sys/fs/smbfs/smbfs_vnops.c                                       |    12 +-
 head/sys/fs/tmpfs/tmpfs_vnops.c                                       |     6 +-
 head/sys/geom/uncompress/g_uncompress.c                               |    83 +-
 head/sys/gnu/fs/xfs/xfs_vfsops.c                                      |     3 +-
 head/sys/i386/ibcs2/ibcs2_socksys.c                                   |     6 +-
 head/sys/i386/ibcs2/ibcs2_stat.c                                      |     4 +-
 head/sys/i386/include/asm.h                                           |    16 +-
 head/sys/kern/kern_intr.c                                             |    10 +-
 head/sys/kern/kern_ktr.c                                              |     8 +-
 head/sys/kern/kern_linker.c                                           |     8 +-
 head/sys/kern/kern_thread.c                                           |    27 +-
 head/sys/kern/sched_4bsd.c                                            |     6 +-
 head/sys/kern/sched_ule.c                                             |     6 +-
 head/sys/kern/subr_hints.c                                            |    13 +-
 head/sys/kern/tty_inq.c                                               |     4 +-
 head/sys/kern/uipc_mqueue.c                                           |     6 +-
 head/sys/kern/vfs_lookup.c                                            |    23 +-
 head/sys/libkern/fnmatch.c                                            |     6 +-
 head/sys/libkern/index.c                                              |    58 -
 head/sys/libkern/memcchr.c                                            |   115 +
 head/sys/libkern/rindex.c                                             |    59 -
 head/sys/libkern/skpc.c                                               |    49 -
 head/sys/libkern/strchr.c                                             |    52 +
 head/sys/libkern/strrchr.c                                            |    53 +
 head/sys/mips/cavium/ciu.c                                            |     4 +-
 head/sys/mips/cavium/cryptocteon/cavium_crypto.c                      |     2 +-
 head/sys/mips/cavium/cryptocteon/cryptocteon.c                        |     2 +-
 head/sys/mips/cavium/cryptocteon/cryptocteonvar.h                     |     2 +-
 head/sys/mips/cavium/cvmx_config.h                                    |     2 +-
 head/sys/mips/cavium/files.octeon1                                    |     8 +-
 head/sys/mips/cavium/obio.c                                           |     2 +-
 head/sys/mips/cavium/obiovar.h                                        |     2 +-
 head/sys/mips/cavium/octe/cavium-ethernet.h                           |     2 +-
 head/sys/mips/cavium/octe/ethernet-common.h                           |     2 +-
 head/sys/mips/cavium/octe/ethernet-defines.h                          |     2 +-
 head/sys/mips/cavium/octe/ethernet-headers.h                          |     2 +-
 head/sys/mips/cavium/octe/ethernet-mdio.c                             |     2 +-
 head/sys/mips/cavium/octe/ethernet-mdio.h                             |     2 +-
 head/sys/mips/cavium/octe/ethernet-mem.c                              |     2 +-
 head/sys/mips/cavium/octe/ethernet-mem.h                              |     2 +-
 head/sys/mips/cavium/octe/ethernet-mv88e61xx.c                        |     4 +-
 head/sys/mips/cavium/octe/ethernet-mv88e61xx.h                        |     2 +-
 head/sys/mips/cavium/octe/ethernet-rgmii.c                            |    11 +-
 head/sys/mips/cavium/octe/ethernet-rx.c                               |     2 +-
 head/sys/mips/cavium/octe/ethernet-rx.h                               |     2 +-
 head/sys/mips/cavium/octe/ethernet-sgmii.c                            |     2 +-
 head/sys/mips/cavium/octe/ethernet-spi.c                              |     2 +-
 head/sys/mips/cavium/octe/ethernet-tx.c                               |     2 +-
 head/sys/mips/cavium/octe/ethernet-tx.h                               |     2 +-
 head/sys/mips/cavium/octe/ethernet-util.h                             |     2 +-
 head/sys/mips/cavium/octe/ethernet-xaui.c                             |     2 +-
 head/sys/mips/cavium/octe/mv88e61xxphy.c                              |     4 +-
 head/sys/mips/cavium/octe/mv88e61xxphyreg.h                           |     2 +-
 head/sys/mips/cavium/octe/octe.c                                      |    27 +-
 head/sys/mips/cavium/octe/octebus.c                                   |     2 +-
 head/sys/mips/cavium/octe/octebusvar.h                                |     2 +-
 head/sys/mips/cavium/octe/wrapper-cvmx-includes.h                     |     2 +-
 head/sys/mips/cavium/octeon_ds1337.c                                  |    10 +-
 head/sys/mips/cavium/octeon_nmi.S                                     |     2 +-
 head/sys/mips/cavium/octeon_rnd.c                                     |     4 +-
 head/sys/mips/cavium/octeon_rtc.c                                     |     4 +-
 head/sys/mips/cavium/octeon_wdog.c                                    |     2 +-
 head/sys/mips/cavium/octopci.c                                        |     2 -
 head/sys/mips/cavium/octopci_bus_space.c                              |     4 +-
 head/sys/mips/cavium/octopcireg.h                                     |     2 +-
 head/sys/mips/cavium/octopcivar.h                                     |     2 +-
 head/sys/mips/cavium/std.octeon1                                      |     2 +-
 head/sys/mips/cavium/uart_bus_octeonusart.c                           |     2 +-
 head/sys/mips/cavium/uart_cpu_octeonusart.c                           |     2 +-
 head/sys/mips/cavium/uart_dev_oct16550.c                              |     2 +-
 head/sys/mips/cavium/usb/octusb.c                                     |     4 +-
 head/sys/mips/conf/PB47                                               |    27 +-
 head/sys/mips/include/_stdint.h                                       |    16 +-
 head/sys/modules/ath/Makefile                                         |     4 +-
 head/sys/modules/geom/geom_uncompress/Makefile                        |    11 +-
 head/sys/modules/kgssapi_krb5/Makefile                                |     3 +-
 head/sys/modules/sound/driver/emu10k1/Makefile                        |    12 +-
 head/sys/net80211/ieee80211_ht.c                                      |     4 +-
 head/sys/netgraph/ng_ksocket.c                                        |     8 +-
 head/sys/netinet/igmp.c                                               |    25 +-
 head/sys/netinet/in.c                                                 |    17 +-
 head/sys/netinet/raw_ip.c                                             |     4 +-
 head/sys/netinet6/in6.c                                               |    24 +-
 head/sys/netinet6/in6_ifattach.c                                      |    10 +-
 head/sys/netinet6/in6_var.h                                           |     5 +-
 head/sys/netinet6/mld6.c                                              |    71 +-
 head/sys/netinet6/nd6.h                                               |     5 +-
 head/sys/netinet6/nd6_rtr.c                                           |    11 +-
 head/sys/powerpc/include/_stdint.h                                    |    16 +-
 head/sys/security/mac_lomac/mac_lomac.c                               |    12 +-
 head/sys/sys/cdefs.h                                                  |    22 +-
 head/sys/sys/libkern.h                                                |    18 +-
 head/sys/sys/param.h                                                  |     4 +-
 head/sys/ufs/ffs/ffs_alloc.c                                          |    22 +-
 head/sys/vm/vm_object.c                                               |    18 +-
 head/sys/x86/acpica/srat.c                                            |    19 +-
 head/tools/build/options/WITHOUT_CAPSICUM                             |     2 +
 head/tools/tools/net80211/wesside/wesside/wesside.c                   |     4 +-
 head/usr.bin/cksum/cksum.c                                            |     4 +-
 head/usr.bin/compress/compress.c                                      |     8 +-
 head/usr.bin/finger/finger.c                                          |     4 +-
 head/usr.bin/hexdump/display.c                                        |     4 +-
 head/usr.bin/hexdump/hexdump.c                                        |     4 +-
 head/usr.bin/hexdump/hexsyntax.c                                      |     4 +-
 head/usr.bin/hexdump/parse.c                                          |    10 +-
 head/usr.bin/locate/locate/fastfind.c                                 |     4 +-
 head/usr.bin/locate/locate/util.c                                     |    10 +-
 head/usr.bin/mkulzma/Makefile                                         |     2 +-
 head/usr.bin/mkulzma/mkulzma.8                                        |     2 +-
 head/usr.bin/mkulzma/mkulzma.c                                        |     6 +-
 head/usr.bin/netstat/if.c                                             |     4 +-
 head/usr.bin/netstat/inet.c                                           |     4 +-
 head/usr.bin/netstat/inet6.c                                          |     8 +-
 head/usr.bin/netstat/sctp.c                                           |     8 +-
 head/usr.bin/rlogin/rlogin.c                                          |     4 +-
 head/usr.bin/rpcgen/rpc_main.c                                        |    10 +-
 head/usr.bin/systat/devs.c                                            |     4 +-
 head/usr.bin/systat/netcmds.c                                         |     4 +-
 head/usr.bin/systat/netstat.c                                         |     6 +-
 head/usr.bin/talk/get_names.c                                         |     5 +-
 head/usr.bin/tftp/main.c                                              |    16 +-
 head/usr.bin/tr/str.c                                                 |     4 +-
 head/usr.bin/tset/map.c                                               |     4 +-
 head/usr.bin/tset/term.c                                              |     6 +-
 head/usr.bin/tset/wrterm.c                                            |     4 +-
 head/usr.sbin/bootparamd/bootparamd/bootparamd.c                      |     6 +-
 head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c                   |     4 +-
 head/usr.sbin/config/main.c                                           |     4 +-
 head/usr.sbin/config/mkmakefile.c                                     |    16 +-
 head/usr.sbin/inetd/inetd.c                                           |     6 +-
 head/usr.sbin/ipfwpcap/ipfwpcap.c                                     |     4 +-
 head/usr.sbin/mptable/mptable.c                                       |     4 +-
 head/usr.sbin/mtree/spec.c                                            |     6 +-
 head/usr.sbin/newsyslog/newsyslog.c                                   |    10 +-
 head/usr.sbin/quotaon/quotaon.c                                       |     8 +-
 head/usr.sbin/rwhod/rwhod.c                                           |     4 +-
 head/usr.sbin/sade/variable.c                                         |    14 +-
 head/usr.sbin/uhsoctl/uhsoctl.c                                       |     4 +-
 282 files changed, 8058 insertions(+), 1964 deletions(-)

diffs (16312 lines):

diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/exec.c
--- a/head/bin/sh/exec.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/exec.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/bin/sh/exec.c 229220 2012-01-01 22:17:12Z jilles $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -100,6 +100,7 @@
 static void printentry(struct tblentry *, int);
 static struct tblentry *cmdlookup(const char *, int);
 static void delete_cmd_entry(void);
+static void addcmdentry(const char *, struct cmdentry *);
 
 
 
@@ -593,7 +594,7 @@
  * the same name.
  */
 
-void
+static void
 addcmdentry(const char *name, struct cmdentry *entry)
 {
 	struct tblentry *cmdp;
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/exec.h
--- a/head/bin/sh/exec.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/exec.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)exec.h	8.3 (Berkeley) 6/8/95
- * $FreeBSD: head/bin/sh/exec.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/exec.h 229220 2012-01-01 22:17:12Z jilles $
  */
 
 /* values of cmdtype */
@@ -70,7 +70,6 @@
 int find_builtin(const char *, int *);
 void hashcd(void);
 void changepath(const char *);
-void addcmdentry(const char *, struct cmdentry *);
 void defun(const char *, union node *);
 int unsetfunc(const char *);
 int typecmd_impl(int, char **, int, const char *);
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/expand.c
--- a/head/bin/sh/expand.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/expand.c	Thu Jan 05 13:30:52 2012 +0200
@@ -38,7 +38,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/expand.c 228942 2011-12-28 23:40:46Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/expand.c 229220 2012-01-01 22:17:12Z jilles $");
 
 #include <sys/types.h>
 #include <sys/time.h>
@@ -113,6 +113,7 @@
 static void addfname(char *);
 static struct strlist *expsort(struct strlist *);
 static struct strlist *msort(struct strlist *, int);
+static int patmatch(const char *, const char *, int);
 static char *cvtnum(int, char *);
 static int collate_range_cmp(wchar_t, wchar_t);
 
@@ -1441,61 +1442,67 @@
  * Returns true if the pattern matches the string.
  */
 
-int
+static int
 patmatch(const char *pattern, const char *string, int squoted)
 {
 	const char *p, *q, *end;
+	const char *bt_p, *bt_q;
 	char c;
 	wchar_t wc, wc2;
 
 	p = pattern;
 	q = string;
+	bt_p = NULL;
+	bt_q = NULL;
 	for (;;) {
 		switch (c = *p++) {
 		case '\0':
-			goto breakloop;
+			if (*q != '\0')
+				goto backtrack;
+			return 1;
 		case CTLESC:
 			if (squoted && *q == CTLESC)
 				q++;
 			if (*q++ != *p++)
-				return 0;
+				goto backtrack;
 			break;
 		case CTLQUOTEMARK:
 			continue;
 		case '?':
 			if (squoted && *q == CTLESC)
 				q++;
-			if (localeisutf8)
+			if (*q == '\0')
+				return 0;
+			if (localeisutf8) {
 				wc = get_wc(&q);
-			else
+				/*
+				 * A '?' does not match invalid UTF-8 but a
+				 * '*' does, so backtrack.
+				 */
+				if (wc == 0)
+					goto backtrack;
+			} else
 				wc = (unsigned char)*q++;
-			if (wc == '\0')
-				return 0;
 			break;
 		case '*':
 			c = *p;
 			while (c == CTLQUOTEMARK || c == '*')
 				c = *++p;
-			if (c != CTLESC &&  c != CTLQUOTEMARK &&
-			    c != '?' && c != '*' && c != '[') {
-				while (*q != c) {
-					if (squoted && *q == CTLESC &&
-					    q[1] == c)
-						break;
-					if (*q == '\0')
-						return 0;
-					if (squoted && *q == CTLESC)
-						q++;
-					q++;
-				}
-			}
-			do {
-				if (patmatch(p, q, squoted))
-					return 1;
-				if (squoted && *q == CTLESC)
-					q++;
-			} while (*q++ != '\0');
-			return 0;
+			/*
+			 * If the pattern ends here, we know the string
+			 * matches without needing to look at the rest of it.
+			 */
+			if (c == '\0')
+				return 1;
+			/*
+			 * First try the shortest match for the '*' that
+			 * could work. We can forget any earlier '*' since
+			 * there is no way having it match more characters
+			 * can help us, given that we are already here.
+			 */
+			bt_p = p;
+			bt_q = q;
+			break;
 		case '[': {
 			const char *endp;
 			int invert, found;
@@ -1507,7 +1514,7 @@
 			for (;;) {
 				while (*endp == CTLQUOTEMARK)
 					endp++;
-				if (*endp == '\0')
+				if (*endp == 0)
 					goto dft;		/* no matching ] */
 				if (*endp == CTLESC)
 					endp++;
@@ -1522,12 +1529,14 @@
 			found = 0;
 			if (squoted && *q == CTLESC)
 				q++;
-			if (localeisutf8)
+			if (*q == '\0')
+				return 0;
+			if (localeisutf8) {
 				chr = get_wc(&q);
-			else
+				if (chr == 0)
+					goto backtrack;
+			} else
 				chr = (unsigned char)*q++;
-			if (chr == '\0')
-				return 0;
 			c = *p++;
 			do {
 				if (c == CTLQUOTEMARK)
@@ -1568,21 +1577,34 @@
 				}
 			} while ((c = *p++) != ']');
 			if (found == invert)
-				return 0;
+				goto backtrack;
 			break;
 		}
 dft:	        default:
 			if (squoted && *q == CTLESC)
 				q++;
-			if (*q++ != c)
+			if (*q == '\0')
 				return 0;
+			if (*q++ == c)
+				break;
+backtrack:
+			/*
+			 * If we have a mismatch (other than hitting the end
+			 * of the string), go back to the last '*' seen and
+			 * have it match one additional character.
+			 */
+			if (bt_p == NULL)
+				return 0;
+			if (squoted && *bt_q == CTLESC)
+				bt_q++;
+			if (*bt_q == '\0')
+				return 0;
+			bt_q++;
+			p = bt_p;
+			q = bt_q;
 			break;
 		}
 	}
-breakloop:
-	if (*q != '\0')
-		return 0;
-	return 1;
 }
 
 
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/expand.h
--- a/head/bin/sh/expand.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/expand.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)expand.h	8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/expand.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/expand.h 229220 2012-01-01 22:17:12Z jilles $
  */
 
 struct strlist {
@@ -60,6 +60,5 @@
 void expandhere(union node *, int);
 void expandarg(union node *, struct arglist *, int);
 void expari(int);
-int patmatch(const char *, const char *, int);
 void rmescapes(char *);
 int casematch(union node *, const char *);
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/histedit.c
--- a/head/bin/sh/histedit.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/histedit.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/histedit.c 223060 2011-06-13 21:03:27Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/histedit.c 229220 2012-01-01 22:17:12Z jilles $");
 
 #include <sys/param.h>
 #include <limits.h>
@@ -70,6 +70,8 @@
 static FILE *el_in, *el_out, *el_err;
 
 static char *fc_replace(const char *, char *, char *);
+static int not_fcnumber(const char *);
+static int str_to_event(const char *, int);
 
 /*
  * Set history and editing status.  Called whenever the status may
@@ -425,7 +427,7 @@
 	return (dest);
 }
 
-int
+static int
 not_fcnumber(const char *s)
 {
 	if (s == NULL)
@@ -435,7 +437,7 @@
 	return (!is_number(s));
 }
 
-int
+static int
 str_to_event(const char *str, int last)
 {
 	HistEvent he;
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/input.c
--- a/head/bin/sh/input.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/input.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/input.c 222684 2011-06-04 15:05:52Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/input.c 229220 2012-01-01 22:17:12Z jilles $");
 
 #include <stdio.h>	/* defines BUFSIZ */
 #include <fcntl.h>
@@ -106,6 +106,7 @@
 
 static void pushfile(void);
 static int preadfd(void);
+static void popstring(void);
 
 #ifdef mkinit
 INCLUDE "input.h"
@@ -372,7 +373,7 @@
 	INTON;
 }
 
-void
+static void
 popstring(void)
 {
 	struct strpush *sp = parsefile->strpush;
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/input.h
--- a/head/bin/sh/input.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/input.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)input.h	8.2 (Berkeley) 5/4/95
- * $FreeBSD$
+ * $FreeBSD: head/bin/sh/input.h 229220 2012-01-01 22:17:12Z jilles $
  */
 
 /* PEOF (the end of file marker) is defined in syntax.h */
@@ -53,7 +53,6 @@
 int preadateof(void);
 void pungetc(void);
 void pushstring(char *, int, void *);
-void popstring(void);
 void setinputfile(const char *, int);
 void setinputfd(int, int);
 void setinputstring(char *, int);
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/main.c
--- a/head/bin/sh/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -42,7 +42,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/bin/sh/main.c 223060 2011-06-13 21:03:27Z jilles $");
+__FBSDID("$FreeBSD: head/bin/sh/main.c 229220 2012-01-01 22:17:12Z jilles $");
 
 #include <stdio.h>
 #include <signal.h>
@@ -79,6 +79,7 @@
 struct jmploc main_handler;
 int localeisutf8, initial_localeisutf8;
 
+static void cmdloop(int);
 static void read_profile(char *);
 static char *find_dot_file(char *);
 
@@ -184,7 +185,7 @@
  * loop; it turns on prompting if the shell is interactive.
  */
 
-void
+static void
 cmdloop(int top)
 {
 	union node *n;
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/main.h
--- a/head/bin/sh/main.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/main.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)main.h	8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/main.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/main.h 229220 2012-01-01 22:17:12Z jilles $
  */
 
 extern int rootpid;	/* pid of main shell */
@@ -38,4 +38,3 @@
 extern struct jmploc main_handler;	/* top level exception handler */
 
 void readcmdfile(const char *);
-void cmdloop(int);
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/myhistedit.h
--- a/head/bin/sh/myhistedit.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/myhistedit.h	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)myhistedit.h	8.2 (Berkeley) 5/4/95
- * $FreeBSD: head/bin/sh/myhistedit.h 223060 2011-06-13 21:03:27Z jilles $
+ * $FreeBSD: head/bin/sh/myhistedit.h 229220 2012-01-01 22:17:12Z jilles $
  */
 
 #include <histedit.h>
@@ -39,6 +39,4 @@
 void histedit(void);
 void sethistsize(const char *);
 void setterm(const char *);
-int not_fcnumber(const char *);
-int str_to_event(const char *, int);
 
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/mystring.c
--- a/head/bin/sh/mystring.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/mystring.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,14 +36,13 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/bin/sh/mystring.c 229219 2012-01-01 22:15:38Z jilles $");
 
 /*
  * String functions.
  *
  *	equal(s1, s2)		Return true if strings are equal.
  *	scopy(from, to)		Copy a string.
- *	scopyn(from, to, n)	Like scopy, but checks for overflow.
  *	number(s)		Convert a string of digits to an integer.
  *	is_number(s)		Return true if s is a string of digits.
  */
@@ -67,24 +66,6 @@
 
 
 /*
- * scopyn - copy a string from "from" to "to", truncating the string
- *		if necessary.  "To" is always nul terminated, even if
- *		truncation is performed.  "Size" is the size of "to".
- */
-
-void
-scopyn(const char *from, char *to, int size)
-{
-
-	while (--size > 0) {
-		if ((*to++ = *from++) == '\0')
-			return;
-	}
-	*to = '\0';
-}
-
-
-/*
  * prefix -- see if pfx is a prefix of string.
  */
 
diff -r 9f40516392fd -r 77905f94b3a7 head/bin/sh/mystring.h
--- a/head/bin/sh/mystring.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/bin/sh/mystring.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,12 +30,11 @@
  * SUCH DAMAGE.
  *
  *	@(#)mystring.h	8.2 (Berkeley) 5/4/95
- * $FreeBSD$
+ * $FreeBSD: head/bin/sh/mystring.h 229219 2012-01-01 22:15:38Z jilles $
  */
 
 #include <string.h>
 
-void scopyn(const char *, char *, int);
 int prefix(const char *, const char *);
 int number(const char *);
 int is_number(const char *);
diff -r 9f40516392fd -r 77905f94b3a7 head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/io/tst.fds.c
--- a/head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/io/tst.fds.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/io/tst.fds.c	Thu Jan 05 13:30:52 2012 +0200
@@ -82,7 +82,7 @@
 
 	fds[n++] = open(file, O_RDWR | O_APPEND | O_CREAT | O_DSYNC |
 	    O_LARGEFILE | O_NOCTTY | O_NONBLOCK | O_NDELAY | O_RSYNC |
-	    O_SYNC | O_TRUNC | O_XATTR);
+	    O_SYNC | O_TRUNC | O_XATTR, 0666);
 
 	fds[n++] = open(file, O_RDWR);
 	(void) lseek(fds[n - 1], 123, SEEK_SET);
diff -r 9f40516392fd -r 77905f94b3a7 head/contrib/compiler-rt/LICENSE.TXT
--- a/head/contrib/compiler-rt/LICENSE.TXT	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/contrib/compiler-rt/LICENSE.TXT	Thu Jan 05 13:30:52 2012 +0200
@@ -14,7 +14,7 @@
 University of Illinois/NCSA
 Open Source License
 
-Copyright (c) 2009-2010 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2012 by the contributors listed in CREDITS.TXT
 
 All rights reserved.
 
@@ -55,7 +55,7 @@
 
 ==============================================================================
 
-Copyright (c) 2009-2010 by the contributors listed in CREDITS.TXT
+Copyright (c) 2009-2012 by the contributors listed in CREDITS.TXT
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff -r 9f40516392fd -r 77905f94b3a7 head/contrib/compiler-rt/lib/trampoline_setup.c
--- a/head/contrib/compiler-rt/lib/trampoline_setup.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/contrib/compiler-rt/lib/trampoline_setup.c	Thu Jan 05 13:30:52 2012 +0200
@@ -44,4 +44,4 @@
     /* clear instruction cache */
     __clear_cache(trampOnStack, &trampOnStack[10]);
 }
-#endif /* __ppc__ */
+#endif /* __ppc__ && !defined(__powerpc64__) */
diff -r 9f40516392fd -r 77905f94b3a7 head/contrib/less/command.c
--- a/head/contrib/less/command.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/contrib/less/command.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/contrib/less/command.c 228645 2011-12-17 16:10:14Z dim $ */
+/* $FreeBSD: head/contrib/less/command.c 229196 2012-01-01 20:13:02Z dim $ */
 /*
  * Copyright (C) 1984-2011  Mark Nudelman
  *
@@ -105,7 +105,7 @@
 start_mca(action, prompt, mlist, cmdflags)
 	int action;
 	char *prompt;
-	void *mlist;
+	void constant *mlist;
 	int cmdflags;
 {
 	mca = action;
@@ -686,7 +686,7 @@
 	static void
 prompt()
 {
-	register char *p;
+	register char constant *p;
 
 	if (ungot != NULL)
 	{
@@ -1461,7 +1461,7 @@
 				error("Command not available", NULL_PARG);
 				break;
 			}
-			start_mca(A_EXAMINE, "Examine: ", (void*)ml_examine, 0);
+			start_mca(A_EXAMINE, "Examine: ", ml_examine, 0);
 			c = getcc();
 			goto again;
 #else
@@ -1491,7 +1491,7 @@
 				error("WARNING: This file was viewed via LESSOPEN",
 					NULL_PARG);
 			}
-			start_mca(A_SHELL, "!", (void*)ml_shell, 0);
+			start_mca(A_SHELL, "!", ml_shell, 0);
 			/*
 			 * Expand the editor prototype string
 			 * and pass it to the system to execute.
@@ -1655,7 +1655,7 @@
 				error("Command not available", NULL_PARG);
 				break;
 			}
-			start_mca(A_SHELL, "!", (void*)ml_shell, 0);
+			start_mca(A_SHELL, "!", ml_shell, 0);
 			c = getcc();
 			goto again;
 #else
@@ -1706,7 +1706,7 @@
 			if (badmark(c))
 				break;
 			pipec = c;
-			start_mca(A_PIPE, "!", (void*)ml_shell, 0);
+			start_mca(A_PIPE, "!", ml_shell, 0);
 			c = getcc();
 			goto again;
 #else
diff -r 9f40516392fd -r 77905f94b3a7 head/contrib/less/prompt.c
--- a/head/contrib/less/prompt.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/contrib/less/prompt.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/contrib/less/prompt.c 228645 2011-12-17 16:10:14Z dim $ */
+/* $FreeBSD: head/contrib/less/prompt.c 229196 2012-01-01 20:13:02Z dim $ */
 /*
  * Copyright (C) 1984-2011  Mark Nudelman
  *
@@ -394,9 +394,9 @@
  * where to resume parsing the string.
  * We must keep track of nested IFs and skip them properly.
  */
-	static char *
+	static char constant *
 skipcond(p)
-	register char *p;
+	register char constant *p;
 {
 	register int iflevel;
 
@@ -452,9 +452,9 @@
 /*
  * Decode a char that represents a position on the screen.
  */
-	static char *
+	static char constant *
 wherechar(p, wp)
-	char *p;
+	char constant *p;
 	int *wp;
 {
 	switch (*p)
@@ -478,10 +478,10 @@
  */
 	public char *
 pr_expand(proto, maxwidth)
-	char *proto;
+	char constant *proto;
 	int maxwidth;
 {
-	register char *p;
+	register char constant *p;
 	register int c;
 	int where;
 
@@ -555,7 +555,7 @@
 	public char *
 eq_message()
 {
-	return (pr_expand((char*)eqproto, 0));
+	return (pr_expand(eqproto, 0));
 }
 
 /*
@@ -572,7 +572,7 @@
 
 	type = (!less_is_more) ? pr_type : pr_type ? 0 : 1;
 	prompt = pr_expand((ch_getflags() & CH_HELPFILE) ?
-				(char*)hproto : prproto[type],
+				hproto : prproto[type],
 			sc_width-so_s_width-so_e_width-2);
 	new_file = 0;
 	return (prompt);
@@ -584,5 +584,5 @@
 	public char *
 wait_message()
 {
-	return (pr_expand((char*)wproto, sc_width-so_s_width-so_e_width-2));
+	return (pr_expand(wproto, sc_width-so_s_width-so_e_width-2));
 }
diff -r 9f40516392fd -r 77905f94b3a7 head/games/fortune/fortune/fortune.c
--- a/head/games/fortune/fortune/fortune.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/games/fortune/fortune/fortune.c	Thu Jan 05 13:30:52 2012 +0200
@@ -42,7 +42,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/games/fortune/fortune/fortune.c 227101 2011-11-05 07:18:53Z ed $");
+__FBSDID("$FreeBSD: head/games/fortune/fortune/fortune.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/stat.h>
 #include <sys/endian.h>
@@ -683,7 +683,7 @@
 	obscene->fd = fd;
 	obscene->inf = NULL;
 	obscene->path = offensive;
-	if ((sp = rindex(offensive, '/')) == NULL)
+	if ((sp = strrchr(offensive, '/')) == NULL)
 		obscene->name = offensive;
 	else
 		obscene->name = ++sp;
@@ -785,7 +785,7 @@
 		}
 	}
 
-	if ((sp = rindex(file, '/')) == NULL)
+	if ((sp = strrchr(file, '/')) == NULL)
 		sp = file;
 	else
 		sp++;
@@ -797,7 +797,7 @@
 		DPRINTF(2, (stderr, "FALSE (check fortunes only)\n"));
 		return (FALSE);
 	}
-	if ((sp = rindex(sp, '.')) != NULL) {
+	if ((sp = strrchr(sp, '.')) != NULL) {
 		sp++;
 		for (i = 0; suflist[i] != NULL; i++)
 			if (strcmp(sp, suflist[i]) == 0) {
diff -r 9f40516392fd -r 77905f94b3a7 head/gnu/usr.bin/gdb/kgdb/main.c
--- a/head/gnu/usr.bin/gdb/kgdb/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/gnu/usr.bin/gdb/kgdb/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/gnu/usr.bin/gdb/kgdb/main.c 229521 2012-01-04 21:26:47Z rwatson $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -83,7 +83,7 @@
 {
 
 	fprintf(stderr,
-	    "usage: %s [-afqv] [-d crashdir] [-c core | -n dumpnr | -r device]\n"
+	    "usage: %s [-afqvw] [-d crashdir] [-c core | -n dumpnr | -r device]\n"
 	    "\t[kernel [core]]\n", getprogname());
 	exit(1);
 }
diff -r 9f40516392fd -r 77905f94b3a7 head/include/stdatomic.h
--- a/head/include/stdatomic.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/include/stdatomic.h	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/include/stdatomic.h 228977 2011-12-30 01:37:25Z ed $
+ * $FreeBSD: head/include/stdatomic.h 229332 2012-01-02 22:58:32Z ed $
  */
 
 #ifndef _STDATOMIC_H_
@@ -106,13 +106,13 @@
 
 #if defined(__CLANG_ATOMICS)
 #define	atomic_thread_fence(order)	__atomic_thread_fence(order)
-#define	atomic_signal_fence(order)	__asm volatile ("" : : : "memory");
+#define	atomic_signal_fence(order)	__asm volatile ("" : : : "memory")
 #elif defined(__GNUC_ATOMICS)
 #define	atomic_thread_fence(order)	__atomic_thread_fence(order)
 #define	atomic_signal_fence(order)	__atomic_signal_fence(order)
 #else
 #define	atomic_thread_fence(order)	__sync_synchronize()
-#define	atomic_signal_fence(order)	__asm volatile ("" : : : "memory");
+#define	atomic_signal_fence(order)	__asm volatile ("" : : : "memory")
 #endif
 
 /*
diff -r 9f40516392fd -r 77905f94b3a7 head/include/stdnoreturn.h
--- a/head/include/stdnoreturn.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/include/stdnoreturn.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,14 +23,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/include/stdnoreturn.h 228879 2011-12-25 20:51:40Z ed $
+ * $FreeBSD: head/include/stdnoreturn.h 229437 2012-01-03 23:05:23Z ed $
  */
 
+#ifdef __cplusplus
+#error "<stdnoreturn.h> cannot be used in combination with C++11."
+#endif
+
 #ifndef noreturn
 
-#if !defined(__cplusplus) || __cplusplus < 201103L
 #include <sys/cdefs.h>
 #define	noreturn		_Noreturn
-#endif
 
 #endif /* !noreturn */
diff -r 9f40516392fd -r 77905f94b3a7 head/include/tgmath.h
--- a/head/include/tgmath.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/include/tgmath.h	Thu Jan 05 13:30:52 2012 +0200
@@ -2,6 +2,9 @@
  * Copyright (c) 2004 Stefan Farfeleder.
  * All rights reserved.
  *
+ * Copyright (c) 2012 Ed Schouten <ed at FreeBSD.org>
+ * All rights reserved.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -23,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/include/tgmath.h 229575 2012-01-05 10:46:22Z ed $
  */
 
 #ifndef _TGMATH_H_
@@ -33,64 +36,83 @@
 #include <math.h>
 
 /*
- * This implementation of <tgmath.h> requires two implementation-dependent
- * macros to be defined:
- * __tg_impl_simple(x, y, z, fn, fnf, fnl, ...)
+ * This implementation of <tgmath.h> uses the two following macros,
+ * which are based on the macros described in C11 proposal N1404:
+ * __tg_impl_simple(x, y, z, fnl, fn, fnf, ...)
  *	Invokes fnl() if the corresponding real type of x, y or z is long
  *	double, fn() if it is double or any has an integer type, and fnf()
  *	otherwise.
- * __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...)
- *	Invokes [c]fnl() if the corresponding real type of x, y or z is long
+ * __tg_impl_full(x, y, cfnl, cfn, cfnf, fnl, fn, fnf, ...)
+ *	Invokes [c]fnl() if the corresponding real type of x or y is long
  *	double, [c]fn() if it is double or any has an integer type, and
  *	[c]fnf() otherwise.  The function with the 'c' prefix is called if
- *	any of x, y or z is a complex number.
+ *	any of x or y is a complex number.
  * Both macros call the chosen function with all additional arguments passed
  * to them, as given by __VA_ARGS__.
  *
  * Note that these macros cannot be implemented with C's ?: operator,
  * because the return type of the whole expression would incorrectly be long
  * double complex regardless of the argument types.
+ *
+ * The _Complex_I distinction should not be needed, but due to a bug in
+ * GCC 4.2, _Complex_I is not of type float _Complex.
  */
 
-#if __GNUC_PREREQ__(3, 1)
-#define	__tg_type(e, t)	__builtin_types_compatible_p(__typeof__(e), t)
-#define	__tg_type3(e1, e2, e3, t)					\
-	(__tg_type(e1, t) || __tg_type(e2, t) || __tg_type(e3, t))
-#define	__tg_type_corr(e1, e2, e3, t)					\
-	(__tg_type3(e1, e2, e3, t) || __tg_type3(e1, e2, e3, t _Complex))
-#define	__tg_integer(e1, e2, e3)					\
-	(((__typeof__(e1))1.5 == 1) || ((__typeof__(e2))1.5 == 1) ||	\
-	    ((__typeof__(e3))1.5 == 1))
-#define	__tg_is_complex(e1, e2, e3)					\
-	(__tg_type3(e1, e2, e3, float _Complex) ||			\
-	    __tg_type3(e1, e2, e3, double _Complex) ||			\
-	    __tg_type3(e1, e2, e3, long double _Complex) ||		\
-	    __tg_type3(e1, e2, e3, __typeof__(_Complex_I)))
+#ifndef __generic
+#error "<tgmath.h> not implemented for this compiler"
+#endif
 
-#define	__tg_impl_simple(x, y, z, fn, fnf, fnl, ...)			\
-	__builtin_choose_expr(__tg_type_corr(x, y, z, long double),	\
-	    fnl(__VA_ARGS__), __builtin_choose_expr(			\
-		__tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\
-		fn(__VA_ARGS__), fnf(__VA_ARGS__)))
-
-#define	__tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...)	\
-	__builtin_choose_expr(__tg_is_complex(x, y, z),			\
-	    __tg_impl_simple(x, y, z, cfn, cfnf, cfnl, __VA_ARGS__),	\
-	    __tg_impl_simple(x, y, z, fn, fnf, fnl, __VA_ARGS__))
-
-#else	/* __GNUC__ */
-#error "<tgmath.h> not implemented for this compiler"
-#endif	/* !__GNUC__ */
+#define	__tg_generic_simple(x, fnl, fn, fnf)				\
+	__generic(x, long double _Complex, fnl,				\
+	    __generic(x, double _Complex, fn,				\
+	        __generic(x, float _Complex, fnf,			\
+	            __generic(x, __typeof(_Complex_I), fnf,		\
+	                __generic(x, long double, fnl,			\
+	                    __generic(x, float, fnf, fn))))))
+#define	__tg_impl_simple(x, y, z, fnl, fn, fnf, ...)			\
+	__tg_generic_simple(x,						\
+	    __tg_generic_simple(y,					\
+	        __tg_generic_simple(z, fnl, fnl, fnl),			\
+	        __tg_generic_simple(z, fnl, fnl, fnl),			\
+	        __tg_generic_simple(z, fnl, fnl, fnl)),			\
+	    __tg_generic_simple(y,					\
+	        __tg_generic_simple(z, fnl, fnl, fnl),			\
+	        __tg_generic_simple(z, fnl, fn , fn ),			\
+	        __tg_generic_simple(z, fnl, fn , fn )),			\
+	    __tg_generic_simple(y,					\
+	        __tg_generic_simple(z, fnl, fnl, fnl),			\
+	        __tg_generic_simple(z, fnl, fn , fn ),			\
+	        __tg_generic_simple(z, fnl, fn , fnf)))(__VA_ARGS__)
+#define	__tg_generic_full(x, cfnl, cfn, cfnf, fnl, fn, fnf)		\
+	__generic(x, long double _Complex, cfnl,			\
+	    __generic(x, double _Complex, cfn,				\
+	        __generic(x, float _Complex, cfnf,			\
+	            __generic(x, __typeof(_Complex_I), cfnf,		\
+	                __generic(x, long double, fnl,			\
+	                    __generic(x, float, fnf, fn))))))
+#define	__tg_impl_full(x, y, cfnl, cfn, cfnf, fnl, fn, fnf, ...)	\
+	__tg_generic_full(x,						\
+	    __tg_generic_full(y, cfnl, cfnl, cfnl, cfnl, cfnl, cfnl),	\
+	    __tg_generic_full(y, cfnl, cfn , cfn , cfnl, cfn , cfn ),	\
+	    __tg_generic_full(y, cfnl, cfn , cfnf, cfnl, cfn , cfnf),	\
+	    __tg_generic_full(y, cfnl, cfnl, cfnl, fnl , fnl , fnl ),	\
+	    __tg_generic_full(y, cfnl, cfn , cfn , fnl , fn  , fn  ),	\
+	    __tg_generic_full(y, cfnl, cfn , cfnf, fnl , fn  , fnf ))	\
+	    (__VA_ARGS__)
 
 /* Macros to save lots of repetition below */
 #define	__tg_simple(x, fn)						\
-	__tg_impl_simple(x, x, x, fn, fn##f, fn##l, x)
+	__tg_impl_simple(x, x, x, fn##l, fn, fn##f, x)
 #define	__tg_simple2(x, y, fn)						\
-	__tg_impl_simple(x, x, y, fn, fn##f, fn##l, x, y)
+	__tg_impl_simple(x, x, y, fn##l, fn, fn##f, x, y)
+#define	__tg_simple3(x, y, z, fn)					\
+	__tg_impl_simple(x, y, z, fn##l, fn, fn##f, x, y, z)
 #define	__tg_simplev(x, fn, ...)					\
-	__tg_impl_simple(x, x, x, fn, fn##f, fn##l, __VA_ARGS__)
+	__tg_impl_simple(x, x, x, fn##l, fn, fn##f, __VA_ARGS__)
 #define	__tg_full(x, fn)						\
-	__tg_impl_full(x, x, x, fn, fn##f, fn##l, c##fn, c##fn##f, c##fn##l, x)
+	__tg_impl_full(x, x, c##fn##l, c##fn, c##fn##f, fn##l, fn, fn##f, x)
+#define	__tg_full2(x, y, fn)						\
+	__tg_impl_full(x, y, c##fn##l, c##fn, c##fn##f, fn##l, fn, fn##f, x, y)
 
 /* 7.22#4 -- These macros expand to real or complex functions, depending on
  * the type of their arguments. */
@@ -108,13 +130,12 @@
 #define	tanh(x)		__tg_full(x, tanh)
 #define	exp(x)		__tg_full(x, exp)
 #define	log(x)		__tg_full(x, log)
-#define	pow(x, y)	__tg_impl_full(x, x, y, pow, powf, powl,	\
-			    cpow, cpowf, cpowl, x, y)
+#define	pow(x, y)	__tg_full2(x, y, pow)
 #define	sqrt(x)		__tg_full(x, sqrt)
 
 /* "The corresponding type-generic macro for fabs and cabs is fabs." */
-#define	fabs(x)		__tg_impl_full(x, x, x, fabs, fabsf, fabsl,	\
-    			    cabs, cabsf, cabsl, x)
+#define	fabs(x)		__tg_impl_full(x, x, cabsl, cabs, cabsf,	\
+    			    fabsl, fabs, fabsf, x)
 
 /* 7.22#5 -- These macros are only defined for arguments with real type. */
 #define	atan2(x, y)	__tg_simple2(x, y, atan2)
@@ -127,7 +148,7 @@
 #define	expm1(x)	__tg_simple(x, expm1)
 #define	fdim(x, y)	__tg_simple2(x, y, fdim)
 #define	floor(x)	__tg_simple(x, floor)
-#define	fma(x, y, z)	__tg_impl_simple(x, y, z, fma, fmaf, fmal, x, y, z)
+#define	fma(x, y, z)	__tg_simple3(x, y, z, fma)
 #define	fmax(x, y)	__tg_simple2(x, y, fmax)
 #define	fmin(x, y)	__tg_simple2(x, y, fmin)
 #define	fmod(x, y)	__tg_simple2(x, y, fmod)
@@ -148,8 +169,8 @@
 #define	nextafter(x, y)	__tg_simple2(x, y, nextafter)
 #define	nexttoward(x, y) __tg_simplev(x, nexttoward, x, y)
 #define	remainder(x, y)	__tg_simple2(x, y, remainder)
-#define	remquo(x, y, z)	__tg_impl_simple(x, x, y, remquo, remquof,	\
-			    remquol, x, y, z)
+#define	remquo(x, y, z)	__tg_impl_simple(x, x, y, remquol, remquo,	\
+			    remquof, x, y, z)
 #define	rint(x)		__tg_simple(x, rint)
 #define	round(x)	__tg_simple(x, round)
 #define	scalbn(x, y)	__tg_simplev(x, scalbn, x, y)
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/clang/clang.build.mk
--- a/head/lib/clang/clang.build.mk	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/clang/clang.build.mk	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/clang/clang.build.mk 227775 2011-11-21 00:49:46Z nwhitehorn $
+# $FreeBSD: head/lib/clang/clang.build.mk 229169 2012-01-01 15:56:15Z nwhitehorn $
 
 CLANG_SRCS=${LLVM_SRCS}/tools/clang
 
@@ -8,10 +8,8 @@
 	-DLLVM_ON_UNIX -DLLVM_ON_FREEBSD \
 	-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS #-DNDEBUG
 
-# Correct for gcc miscompilation when compiling on PPC with -O2
-.if ${MACHINE_CPUARCH} == "powerpc"
-CFLAGS+= -O1
-.endif
+# LLVM is not strict aliasing safe as of 12/31/2011
+CFLAGS+= -fno-strict-aliasing
 
 TARGET_ARCH?=	${MACHINE_ARCH}
 CFLAGS+=-DLLVM_HOSTTRIPLE=\"${TARGET_ARCH:C/amd64/x86_64/}-unknown-freebsd10.0\"
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/clang/libllvmarminfo/Makefile
--- a/head/lib/clang/libllvmarminfo/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/clang/libllvmarminfo/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,8 +1,8 @@
-# $FreeBSD: head/lib/clang/libllvmarminfo/Makefile 224145 2011-07-17 19:51:40Z dim $
+# $FreeBSD: head/lib/clang/libllvmarminfo/Makefile 229183 2012-01-01 18:36:42Z dim $
 
 LIB=	llvmarminfo
 
-SRCDIR=	lib/Target/ARM/TargetInfo/
+SRCDIR=	lib/Target/ARM/TargetInfo
 INCDIR=	lib/Target/ARM
 SRCS=	ARMTargetInfo.cpp
 
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/clang/libllvmmipsinfo/Makefile
--- a/head/lib/clang/libllvmmipsinfo/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/clang/libllvmmipsinfo/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,8 +1,8 @@
-# $FreeBSD: head/lib/clang/libllvmmipsinfo/Makefile 224145 2011-07-17 19:51:40Z dim $
+# $FreeBSD: head/lib/clang/libllvmmipsinfo/Makefile 229183 2012-01-01 18:36:42Z dim $
 
 LIB=	llvmmipsinfo
 
-SRCDIR=	lib/Target/Mips/TargetInfo/
+SRCDIR=	lib/Target/Mips/TargetInfo
 INCDIR=	lib/Target/Mips
 SRCS=	MipsTargetInfo.cpp
 
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/clang/libllvmpowerpcinfo/Makefile
--- a/head/lib/clang/libllvmpowerpcinfo/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/clang/libllvmpowerpcinfo/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,8 +1,8 @@
-# $FreeBSD: head/lib/clang/libllvmpowerpcinfo/Makefile 224145 2011-07-17 19:51:40Z dim $
+# $FreeBSD: head/lib/clang/libllvmpowerpcinfo/Makefile 229183 2012-01-01 18:36:42Z dim $
 
 LIB=	llvmpowerpcinfo
 
-SRCDIR=	lib/Target/PowerPC/TargetInfo/
+SRCDIR=	lib/Target/PowerPC/TargetInfo
 INCDIR=	lib/Target/PowerPC
 SRCS=	PowerPCTargetInfo.cpp
 
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/clang/libllvmx86info/Makefile
--- a/head/lib/clang/libllvmx86info/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/clang/libllvmx86info/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,8 +1,8 @@
-# $FreeBSD: head/lib/clang/libllvmx86info/Makefile 224145 2011-07-17 19:51:40Z dim $
+# $FreeBSD: head/lib/clang/libllvmx86info/Makefile 229183 2012-01-01 18:36:42Z dim $
 
 LIB=	llvmx86info
 
-SRCDIR=	lib/Target/X86/TargetInfo/
+SRCDIR=	lib/Target/X86/TargetInfo
 INCDIR=	lib/Target/X86
 SRCS=	X86TargetInfo.cpp
 
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/Makefile
--- a/head/lib/libc/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,5 @@
 #	@(#)Makefile	8.2 (Berkeley) 2/3/94
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/Makefile 229368 2012-01-03 07:14:01Z ed $
 
 SHLIBDIR?= /lib
 
@@ -127,8 +127,8 @@
 KQSRCS=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
 	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
 	subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
-KSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c index.c mcount.c rindex.c \
-	strcat.c strcmp.c strcpy.c strlen.c strncpy.c
+KSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
+	strcmp.c strcpy.c strlen.c strncpy.c strrchr.c
 
 libkern: libkern.gen libkern.${LIBC_ARCH}
 
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/arm/string/Makefile.inc
--- a/head/lib/libc/arm/string/Makefile.inc	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/arm/string/Makefile.inc	Thu Jan 05 13:30:52 2012 +0200
@@ -1,7 +1,6 @@
 #	@(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/arm/string/Makefile.inc 229368 2012-01-03 07:14:01Z ed $
 
-MDSRCS+=bcmp.c bcopy.S bzero.S ffs.S index.c memchr.c memcmp.S memcpy.S \
-	memmove.S memset.S rindex.c strcat.c strchr.c strcmp.S strcpy.c \
-	strlen.S strncmp.S strrchr.c swab.c wcschr.c wcscmp.c wcslen.c \
-	wmemchr.c
+MDSRCS+=bcmp.c bcopy.S bzero.S ffs.S memchr.c memcmp.S memcpy.S \
+	memmove.S memset.S strcat.c strchr.c strcmp.S strcpy.c strlen.S \
+	strncmp.S strrchr.c swab.c wcschr.c wcscmp.c wcslen.c wmemchr.c
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/gen/exec.c
--- a/head/lib/libc/gen/exec.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/gen/exec.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)exec.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/exec.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include "namespace.h"
 #include <sys/param.h>
@@ -159,7 +159,7 @@
 	eacces = 0;
 
 	/* If it's an absolute or relative path name, it's easy. */
-	if (index(name, '/')) {
+	if (strchr(name, '/')) {
 		bp = name;
 		cur = NULL;
 		goto retry;
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/gen/getttyent.c
--- a/head/lib/libc/gen/getttyent.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/gen/getttyent.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)getttyent.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/getttyent.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <ttyent.h>
 #include <stdio.h>
@@ -78,7 +78,7 @@
 		if (!fgets(p = line, lbsize, tf))
 			return (NULL);
 		/* extend buffer if line was too big, and retry */
-		while (!index(p, '\n') && !feof(tf)) {
+		while (!strchr(p, '\n') && !feof(tf)) {
 			i = strlen(p);
 			lbsize += MALLOCCHUNK;
 			if ((p = realloc(line, lbsize)) == NULL) {
@@ -148,7 +148,7 @@
 	tty.ty_comment = p;
 	if (*p == 0)
 		tty.ty_comment = 0;
-	if ( (p = index(p, '\n')) )
+	if ((p = strchr(p, '\n')))
 		*p = '\0';
 	return (&tty);
 }
@@ -196,7 +196,7 @@
 value(char *p)
 {
 
-	return ((p = index(p, '=')) ? ++p : NULL);
+	return ((p = strchr(p, '=')) ? ++p : NULL);
 }
 
 int
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/gen/timezone.c
--- a/head/lib/libc/gen/timezone.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/gen/timezone.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
 static char sccsid[] = "@(#)timezone.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/gen/timezone.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 #include <sys/time.h>
@@ -59,7 +59,7 @@
 			*end;
 
 	if ( (beg = getenv("TZNAME")) ) {	/* set in environment */
-		if ( (end = index(beg, ',')) ) {/* "PST,PDT" */
+		if ((end = strchr(beg, ','))) {	/* "PST,PDT" */
 			if (dst)
 				return(++end);
 			*end = '\0';
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/i386/string/Makefile.inc
--- a/head/lib/libc/i386/string/Makefile.inc	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/i386/string/Makefile.inc	Thu Jan 05 13:30:52 2012 +0200
@@ -1,7 +1,6 @@
 #	@(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/i386/string/Makefile.inc 229368 2012-01-03 07:14:01Z ed $
 
-MDSRCS+=bcmp.S bcopy.S bzero.S ffs.S index.S memchr.S memcmp.S memcpy.S \
-	memmove.S memset.S rindex.S strcat.S strchr.S strcmp.S strcpy.S \
-	strncmp.S strrchr.S swab.S wcschr.S wcscmp.S wcslen.S \
-	wmemchr.S
+MDSRCS+=bcmp.S bcopy.S bzero.S ffs.S memchr.S memcmp.S memcpy.S memmove.S \
+	memset.S strcat.S strchr.S strcmp.S strcpy.S strncmp.S strrchr.S \
+	swab.S wcschr.S wcscmp.S wcslen.S wmemchr.S
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/i386/string/index.S
--- a/head/lib/libc/i386/string/index.S	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 1993 Winning Strategies, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Winning Strategies, Inc.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * index(s, c)
- *	return a pointer to the first occurance of the character c in
- *	string s, or NULL if c does not occur in the string.
- *
- * %edx - pointer iterating through string
- * %eax - pointer to first occurance of 'c'
- * %cl  - character we're comparing against
- * %bl  - character at %edx
- *
- * Written by:
- *	J.T. Conklin (jtc at wimsey.com), Winning Strategies, Inc.
- */
-
-ENTRY(index)
-	pushl	%ebx
-	movl	8(%esp),%eax
-	movb	12(%esp),%cl
-	.align 2,0x90
-L1:
-	movb	(%eax),%bl
-	cmpb	%bl,%cl			/* found char??? */
-	je 	L2
-	incl	%eax
-	testb	%bl,%bl			/* null terminator??? */
-	jne	L1
-	xorl	%eax,%eax
-L2:
-	popl	%ebx
-	ret
-END(index)
-
-	.section .note.GNU-stack,"",%progbits
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/i386/string/rindex.S
--- a/head/lib/libc/i386/string/rindex.S	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 1993 Winning Strategies, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Winning Strategies, Inc.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-/*
- * rindex(s, c)
- *	return a pointer to the last occurance of the character c in
- *	string s, or NULL if c does not occur in the string.
- *
- * %edx - pointer iterating through string
- * %eax - pointer to last occurance of 'c'
- * %cl  - character we're comparing against
- * %bl  - character at %edx
- *
- * Written by:
- *	J.T. Conklin (jtc at wimsey.com), Winning Strategies, Inc.
- */
- 
-ENTRY(rindex)
-	pushl	%ebx
-	movl	8(%esp),%edx
-	movb	12(%esp),%cl
-	xorl	%eax,%eax		/* init pointer to null */
-	.align 2,0x90
-L1:
-	movb	(%edx),%bl
-	cmpb	%bl,%cl
-	jne	L2
-	movl	%edx,%eax
-L2:	
-	incl	%edx
-	testb	%bl,%bl			/* null terminator??? */
-	jne	L1
-	popl	%ebx
-	ret
-END(rindex)
-
-	.section .note.GNU-stack,"",%progbits
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/i386/string/strchr.S
--- a/head/lib/libc/i386/string/strchr.S	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/i386/string/strchr.S	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
  */
 
 #include <machine/asm.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/i386/string/strchr.S 229571 2012-01-05 10:32:53Z ed $");
 
 /*
  * strchr(s, c)
@@ -63,4 +63,6 @@
 	ret
 END(strchr)
 
+WEAK_ALIAS(index, strchr)
+
 	.section .note.GNU-stack,"",%progbits
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/i386/string/strrchr.S
--- a/head/lib/libc/i386/string/strrchr.S	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/i386/string/strrchr.S	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
  */
 
 #include <machine/asm.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/i386/string/strrchr.S 229571 2012-01-05 10:32:53Z ed $");
 
 /*
  * strrchr(s, c)
@@ -64,4 +64,6 @@
 	ret
 END(strrchr)
 
+WEAK_ALIAS(rindex, strrchr)
+
 	.section .note.GNU-stack,"",%progbits
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/mips/string/Makefile.inc
--- a/head/lib/libc/mips/string/Makefile.inc	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/mips/string/Makefile.inc	Thu Jan 05 13:30:52 2012 +0200
@@ -1,8 +1,8 @@
 #	$NetBSD: Makefile.inc,v 1.2 2000/10/10 21:51:54 jeffs Exp $
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/mips/string/Makefile.inc 229368 2012-01-03 07:14:01Z ed $
 
-SRCS+=	bcmp.S bcopy.S bzero.S  ffs.S index.S memchr.c memcmp.c memset.c \
+SRCS+=	bcmp.S bcopy.S bzero.S ffs.S memchr.c memcmp.c memset.c \
 	memcpy.S memmove.S \
-	rindex.S strcat.c strcmp.S strcpy.c strcspn.c strlen.S \
-	strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
+	strcat.c strchr.S strcmp.S strcpy.c strcspn.c strlen.S \
+	strncat.c strncmp.c strncpy.c strrchr.S strpbrk.c strsep.c \
 	strspn.c strstr.c swab.c
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/mips/string/index.S
--- a/head/lib/libc/mips/string/index.S	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*	$NetBSD: index.S,v 1.8 2005/04/22 06:59:00 simonb Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#if defined(LIBC_SCCS) && !defined(lint)
-	ASMSTR("from: @(#)index.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: index.S,v 1.8 2005/04/22 06:59:00 simonb Exp $")
-#endif /* LIBC_SCCS and not lint */
-
-#ifdef __ABICALLS__
-	.abicalls
-#endif
-
-LEAF(index)
-1:
-	lbu		a2, 0(a0)		# get a byte
-	PTR_ADDU	a0, a0, 1
-	beq		a2, a1, fnd
-	bne		a2, zero, 1b
-notfnd:
-	move		v0, zero
-	j		ra
-fnd:
-	PTR_SUBU	v0, a0, 1
-	j		ra
-END(index)
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/mips/string/rindex.S
--- a/head/lib/libc/mips/string/rindex.S	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*	$NetBSD: rindex.S,v 1.7 2003/08/07 16:42:16 agc Exp $	*/
-
-/*-
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Ralph Campbell.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-__FBSDID("$FreeBSD$");
-
-#if defined(LIBC_SCCS) && !defined(lint)
-	ASMSTR("from: @(#)rindex.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: rindex.S,v 1.7 2003/08/07 16:42:16 agc Exp $")
-#endif /* LIBC_SCCS and not lint */
-
-#ifdef __ABICALLS__
-	.abicalls
-#endif
-
-LEAF(rindex)
-	move		v0, zero		# default if not found
-1:
-	lbu		a3, 0(a0)		# get a byte
-	PTR_ADDU	a0, a0, 1
-	bne		a3, a1, 2f
-	PTR_SUBU	v0, a0, 1		# save address of last match
-2:
-	bne		a3, zero, 1b		# continue if not end
-	j		ra
-END(rindex)
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/mips/string/strchr.S
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/mips/string/strchr.S	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,61 @@
+/*	$NetBSD: index.S,v 1.8 2005/04/22 06:59:00 simonb Exp $	*/
+
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD: head/lib/libc/mips/string/strchr.S 229571 2012-01-05 10:32:53Z ed $");
+
+#if defined(LIBC_SCCS) && !defined(lint)
+	ASMSTR("from: @(#)index.s	8.1 (Berkeley) 6/4/93")
+	ASMSTR("$NetBSD: index.S,v 1.8 2005/04/22 06:59:00 simonb Exp $")
+#endif /* LIBC_SCCS and not lint */
+
+#ifdef __ABICALLS__
+	.abicalls
+#endif
+
+LEAF(strchr)
+1:
+	lbu		a2, 0(a0)		# get a byte
+	PTR_ADDU	a0, a0, 1
+	beq		a2, a1, fnd
+	bne		a2, zero, 1b
+notfnd:
+	move		v0, zero
+	j		ra
+fnd:
+	PTR_SUBU	v0, a0, 1
+	j		ra
+END(strchr)
+
+WEAK_ALIAS(index, strchr)
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/mips/string/strrchr.S
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/lib/libc/mips/string/strrchr.S	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,59 @@
+/*	$NetBSD: rindex.S,v 1.7 2003/08/07 16:42:16 agc Exp $	*/
+
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD: head/lib/libc/mips/string/strrchr.S 229571 2012-01-05 10:32:53Z ed $");
+
+#if defined(LIBC_SCCS) && !defined(lint)
+	ASMSTR("from: @(#)rindex.s	8.1 (Berkeley) 6/4/93")
+	ASMSTR("$NetBSD: rindex.S,v 1.7 2003/08/07 16:42:16 agc Exp $")
+#endif /* LIBC_SCCS and not lint */
+
+#ifdef __ABICALLS__
+	.abicalls
+#endif
+
+LEAF(strrchr)
+	move		v0, zero		# default if not found
+1:
+	lbu		a3, 0(a0)		# get a byte
+	PTR_ADDU	a0, a0, 1
+	bne		a3, a1, 2f
+	PTR_SUBU	v0, a0, 1		# save address of last match
+2:
+	bne		a3, zero, 1b		# continue if not end
+	j		ra
+END(strrchr)
+
+WEAK_ALIAS(rindex, strrchr)
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/net/gethostbynis.c
--- a/head/lib/libc/net/gethostbynis.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/net/gethostbynis.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/net/gethostbynis.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -91,7 +91,7 @@
 	free(result);
 	result = (char *)&ypbuf;
 
-	if ((cp = index(result, '\n')))
+	if ((cp = strchr(result, '\n')))
 		*cp = '\0';
 
 	cp = strpbrk(result, " \t");
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/net/getnetbynis.c
--- a/head/lib/libc/net/getnetbynis.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/net/getnetbynis.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/net/getnetbynis.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -80,7 +80,7 @@
 	free(result);
 	result = (char *)&ypbuf;
 
-	if ((cp = index(result, '\n')))
+	if ((cp = strchr(result, '\n')))
 		*cp = '\0';
 
 	cp = strpbrk(result, " \t");
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/string/Makefile.inc
--- a/head/lib/libc/string/Makefile.inc	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/string/Makefile.inc	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,5 @@
 #	@(#)Makefile.inc	8.1 (Berkeley) 6/4/93
-# $FreeBSD$
+# $FreeBSD: head/lib/libc/string/Makefile.inc 229368 2012-01-03 07:14:01Z ed $
 
 .PATH: ${.CURDIR}/${LIBC_ARCH}/string ${.CURDIR}/string
 
@@ -7,8 +7,8 @@
 
 # machine-independent string sources
 MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \
-	index.c memccpy.c memchr.c memrchr.c memcmp.c \
-	memcpy.c memmem.c memmove.c memset.c rindex.c \
+	memccpy.c memchr.c memrchr.c memcmp.c \
+	memcpy.c memmem.c memmove.c memset.c \
 	stpcpy.c stpncpy.c strcasecmp.c \
 	strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \
 	strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/string/index.c
--- a/head/lib/libc/string/index.c	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)index.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stddef.h>
-
-#ifdef STRCHR
-#include <string.h>
-
-char *
-strchr
-#else
-#include <strings.h>
-
-char *
-index
-#endif
-(const char *p, int ch)
-{
-	char c;
-
-	c = ch;
-	for (;; ++p) {
-		if (*p == c)
-			return ((char *)p);
-		if (*p == '\0')
-			return (NULL);
-	}
-	/* NOTREACHED */
-}
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/string/rindex.c
--- a/head/lib/libc/string/rindex.c	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)rindex.c	8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <stddef.h>
-
-#ifdef STRRCHR
-#include <string.h>
-
-char *
-strrchr
-#else
-#include <strings.h>
-
-char *
-rindex
-#endif
-(const char *p, int ch)
-{
-	char *save;
-	char c;
-
-	c = ch;
-	for (save = NULL;; ++p) {
-		if (*p == c)
-			save = (char *)p;
-		if (*p == '\0')
-			return (save);
-	}
-	/* NOTREACHED */
-}
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/string/strchr.c
--- a/head/lib/libc/string/strchr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/string/strchr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,54 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)index.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/strchr.c 229571 2012-01-05 10:32:53Z ed $");
 
-#define	STRCHR
-#include "index.c"
+#include <stddef.h>
+#include <string.h>
+
+char *
+strchr(const char *p, int ch)
+{
+	char c;
+
+	c = ch;
+	for (;; ++p) {
+		if (*p == c)
+			return ((char *)p);
+		if (*p == '\0')
+			return (NULL);
+	}
+	/* NOTREACHED */
+}
+
+__weak_reference(strchr, index);
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/string/strrchr.c
--- a/head/lib/libc/string/strrchr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/string/strrchr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,55 @@
+/*
+ * Copyright (c) 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)rindex.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libc/string/strrchr.c 229571 2012-01-05 10:32:53Z ed $");
 
-#define	STRRCHR
-#include "rindex.c"
+#include <stddef.h>
+#include <string.h>
+
+char *
+strrchr(const char *p, int ch)
+{
+	char *save;
+	char c;
+
+	c = ch;
+	for (save = NULL;; ++p) {
+		if (*p == c)
+			save = (char *)p;
+		if (*p == '\0')
+			return (save);
+	}
+	/* NOTREACHED */
+}
+
+__weak_reference(strrchr, rindex);
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libc/sys/chroot.2
--- a/head/lib/libc/sys/chroot.2	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libc/sys/chroot.2	Thu Jan 05 13:30:52 2012 +0200
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)chroot.2	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libc/sys/chroot.2 229459 2012-01-04 02:04:20Z delphij $
 .\"
-.Dd June 4, 1993
+.Dd January 3, 2012
 .Dt CHROOT 2
 .Os
 .Sh NAME
@@ -134,9 +134,27 @@
 .Fn chroot
 system call appeared in
 .Bx 4.2 .
+It was marked as
+.Dq legacy
+in
+.St -susv2 ,
+and was removed in subsequent standards.
 .Sh BUGS
 If the process is able to change its working directory to the target
 directory, but another access control check fails (such as a check for
 open directories, or a MAC check), it is possible that this system
 call may return an error, with the working directory of the process
 left changed.
+.Sh SECURITY CONSIDERATIONS
+The system have many hardcoded paths to files where it may load after
+the process starts.
+It is generally recommended to drop privileges immediately after a
+successful
+.Nm
+call,
+and restrict write access to a limited subtree of the
+.Nm
+root,
+for instance,
+setup the sandbox so that the sandboxed user will have no write
+access to any well-known system directories.
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libcam/camlib.c
--- a/head/lib/libcam/camlib.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libcam/camlib.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libcam/camlib.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -137,7 +137,7 @@
 	 */
 	if (*tmpstr == '/') {
 		tmpstr2 = tmpstr;
-		tmpstr = (char *)rindex(tmpstr2, '/');
+		tmpstr = strrchr(tmpstr2, '/');
 		if ((tmpstr != NULL) && (*tmpstr != '\0'))
 			tmpstr++;
 	}
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libpmc/pmc.corei7.3
--- a/head/lib/libpmc/pmc.corei7.3	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libpmc/pmc.corei7.3	Thu Jan 05 13:30:52 2012 +0200
@@ -21,7 +21,7 @@
 .\" out of the use of this software, even if advised of the possibility of
 .\" such damage.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/lib/libpmc/pmc.corei7.3 229470 2012-01-04 07:58:36Z fabient $
 .\"
 .Dd March 24, 2010
 .Dt PMC.COREI7 3
@@ -200,10 +200,6 @@
 .Pq Event 08H , Umask 20H
 Number of DTLB cache load misses where the low part of the linear to
 physical address translation was missed.
-.It Li DTLB_LOAD_MISSES.PDP_MISS
-.Pq Event 08H , Umask 40H
-Number of DTLB cache load misses where the high part of the linear to
-physical address translation was missed.
 .It Li DTLB_LOAD_MISSES.LARGE_WALK_COMPLETED
 .Pq Event 08H , Umask 80H
 Counts number of completed large page walks due to load miss in the STLB.
@@ -646,10 +642,6 @@
 Counts all data reads and writes (speculated and retired) from cacheable
 memory, including locked operations.
 Counter 0, 1 only
-.It Li L1D_PEND_MISS.LOAD_BUFFERS_FULL
-.Pq Event 48H , Umask 02H
-Counts cycles of L1 data cache load fill buffers full.
-Counter 0, 1 only
 .It Li DTLB_MISSES.ANY
 .Pq Event 49H , Umask 01H
 Counts the number of misses in the STLB which causes a page walk.
@@ -660,6 +652,12 @@
 .Pq Event 49H , Umask 10H
 Counts the number of DTLB first level misses that hit in the second level
 TLB. This event is only relevant if the core contains multiple DTLB levels.
+.It Li DTLB_MISSES.PDE_MISS
+.Pq Event 49H , Umask 20H
+Number of DTLB misses caused by low part of address, includes references to 2M pages because 2M pages do not use the PDE.
+.It Li DTLB_MISSES.LARGE_WALK_COMPLETED
+.Pq Event 49H , Umask 80H
+Counts number of misses in the STLB which resulted in a completed page walk for large pages.
 .It Li LOAD_HIT_PRE
 .Pq Event 4CH , Umask 01H
 Counts load operations sent to the L1 data cache while a previous SSE
@@ -1205,9 +1203,6 @@
 .Pq Event E8H , Umask 02H
 Counts late Branch Prediction Unit clears due to Most Recently Used
 conflicts. The PBU clear leads to a 3 cycle bubble in the Front End.
-.It Li BPU_CLEARS.ANY
-.Pq Event E8H , Umask 03H
-Counts all BPU clears.
 .It Li L2_TRANSACTIONS.LOAD
 .Pq Event F0H , Umask 01H
 Counts L2 load operations due to HW prefetch or demand loads.
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libstand/Makefile
--- a/head/lib/libstand/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libstand/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/lib/libstand/Makefile 223156 2011-06-16 18:00:27Z imp $
+# $FreeBSD: head/lib/libstand/Makefile 229368 2012-01-03 07:14:01Z ed $
 # Originally from	$NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $
 #
 # Notes:
@@ -54,10 +54,10 @@
 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "powerpc" || \
 	${MACHINE_CPUARCH} == "sparc64" || ${MACHINE_CPUARCH} == "amd64" || \
 	${MACHINE_CPUARCH} == "arm"
-SRCS+=	bcmp.c bcopy.c bzero.c ffs.c index.c memccpy.c memchr.c memcmp.c \
-        memcpy.c memmove.c memset.c qdivrem.c rindex.c strcat.c strchr.c \
-        strcmp.c strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c \
-	strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
+SRCS+=	bcmp.c bcopy.c bzero.c ffs.c memccpy.c memchr.c memcmp.c memcpy.c \
+	memmove.c memset.c qdivrem.c strcat.c strchr.c strcmp.c strcpy.c \
+	strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
+	strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
 .endif
 .if ${MACHINE_CPUARCH} == "arm"
 .PATH: ${.CURDIR}/../libc/arm/gen
@@ -65,10 +65,9 @@
 .endif
 .if ${MACHINE_CPUARCH} == "ia64"
 .PATH: ${.CURDIR}/../libc/ia64/string
-SRCS+=	bcmp.c bcopy.S bzero.S ffs.S index.c memccpy.c memchr.c memcmp.c \
-	memcpy.S memmove.S memset.c rindex.c strcat.c strchr.c \
-	strcmp.c strcpy.c strcspn.c strlen.c \
-	strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \
+SRCS+=	bcmp.c bcopy.S bzero.S ffs.S memccpy.c memchr.c memcmp.c memcpy.S \
+	memmove.S memset.c strcat.c strchr.c strcmp.c strcpy.c strcspn.c \
+	strlen.c strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \
 	strspn.c strstr.c strtok.c swab.c
 
 .PATH: ${.CURDIR}/../libc/ia64/gen
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libstand/bootp.c
--- a/head/lib/libstand/bootp.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libstand/bootp.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libstand/bootp.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 #include <netinet/in.h>
@@ -703,13 +703,13 @@
 		u_char *s = NULL;	/* semicolon ? */
 
 		/* skip leading whitespace */
-		while (*endv && index(" \t\n\r", *endv))
+		while (*endv && strchr(" \t\n\r", *endv))
 		    endv++;
-		vp = index(endv, '=');	/* find name=value separator */
+		vp = strchr(endv, '=');	/* find name=value separator */
 		if (!vp)
 		    break;
 		*vp++ = 0;
-		if (op->fmt == __ILIST && (s = index(vp, ';')))
+		if (op->fmt == __ILIST && (s = strchr(vp, ';')))
 		    *s++ = '\0';
 		setenv(endv, vp, 1);
 		vp = s;	/* prepare for next round */
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libutil/libutil.h
--- a/head/lib/libutil/libutil.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libutil/libutil.h	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/lib/libutil/libutil.h 228545 2011-12-15 22:07:36Z bapt $
+ * $FreeBSD: head/lib/libutil/libutil.h 229572 2012-01-05 10:40:24Z bapt $
  */
 
 #ifndef _LIBUTIL_H_
@@ -144,6 +144,7 @@
 void	pw_fini(void);
 int	pw_init(const char *_dir, const char *_master);
 char	*pw_make(const struct passwd *_pw);
+char	*pw_make_v7(const struct passwd *_pw);
 int	pw_mkdb(const char *_user);
 int	pw_lock(void);
 struct passwd *pw_scan(const char *_line, int _flags);
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libutil/pw_util.c
--- a/head/lib/libutil/pw_util.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libutil/pw_util.c	Thu Jan 05 13:30:52 2012 +0200
@@ -39,7 +39,7 @@
 static const char sccsid[] = "@(#)pw_util.c	8.3 (Berkeley) 4/2/94";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: head/lib/libutil/pw_util.c 228545 2011-12-15 22:07:36Z bapt $";
+  "$FreeBSD: head/lib/libutil/pw_util.c 229572 2012-01-05 10:40:24Z bapt $";
 #endif /* not lint */
 
 /*
@@ -406,7 +406,21 @@
 	    pw->pw_passwd, (uintmax_t)pw->pw_uid, (uintmax_t)pw->pw_gid,
 	    pw->pw_class, (uintmax_t)pw->pw_change, (uintmax_t)pw->pw_expire,
 	    pw->pw_gecos, pw->pw_dir, pw->pw_shell);
-	return line;
+	return (line);
+}
+
+/*
+ * Make a passwd line (in v7 format) out of a struct passwd
+ */
+char *
+pw_make_v7(const struct passwd *pw)
+{
+	char *line;
+
+	asprintf(&line, "%s:*:%ju:%ju:%s:%s:%s", pw->pw_name,
+	    (uintmax_t)pw->pw_uid, (uintmax_t)pw->pw_gid,
+	    pw->pw_gecos, pw->pw_dir, pw->pw_shell);
+	return (line);
 }
 
 /*
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libutil/quotafile.c
--- a/head/lib/libutil/quotafile.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libutil/quotafile.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/lib/libutil/quotafile.c 229403 2012-01-03 18:51:58Z ed $
  */
 
 #include <sys/types.h>
@@ -84,7 +84,7 @@
 	}
 	strcpy(buf, fs->fs_mntops);
 	for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
-		if ((cp = index(opt, '=')))
+		if ((cp = strchr(opt, '=')))
 			*cp++ = '\0';
 		if (type == USRQUOTA && strcmp(opt, usrname) == 0)
 			break;
diff -r 9f40516392fd -r 77905f94b3a7 head/lib/libvgl/simple.c
--- a/head/lib/libvgl/simple.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/lib/libvgl/simple.c	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/libvgl/simple.c 229516 2012-01-04 20:05:38Z pfg $");
 
 #include <signal.h>
 #include <sys/fbio.h>
@@ -198,36 +198,205 @@
   return 0;		/* XXX black? */
 }
 
+ /*
+  * Symmetric Double Step Line Algorithm by Brian Wyvill from
+  * "Graphics Gems", Academic Press, 1990.
+  */
+
+#define SL_SWAP(a,b)           {a^=b; b^=a; a^=b;}
+#define SL_ABSOLUTE(i,j,k)     ( (i-j)*(k = ( (i-j)<0 ? -1 : 1)))
+
+void
+plot(VGLBitmap * object, int x, int y, int flag, byte color)
+{
+  /* non-zero flag indicates the pixels need swapping back. */
+  if (flag)
+    VGLSetXY(object, y, x, color);
+  else
+    VGLSetXY(object, x, y, color);
+}
+
+
 void
 VGLLine(VGLBitmap *object, int x1, int y1, int x2, int y2, u_long color)
 {
-  int d, x, y, ax, ay, sx, sy, dx, dy;
+  int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left;
+  int sign_x, sign_y, step, reverse, i;
 
-  dx = x2-x1; ax = ABS(dx)<<1; sx = SGN(dx); x = x1;
-  dy = y2-y1; ay = ABS(dy)<<1; sy = SGN(dy); y = y1;
+  dx = SL_ABSOLUTE(x2, x1, sign_x);
+  dy = SL_ABSOLUTE(y2, y1, sign_y);
+  /* decide increment sign by the slope sign */
+  if (sign_x == sign_y)
+    step = 1;
+  else
+    step = -1;
 
-  if (ax>ay) {					/* x dominant */
-    d = ay-(ax>>1);
-    for (;;) {
-      VGLSetXY(object, x, y, color);
-      if (x==x2)
-	break;
-      if (d>=0) {
-	y += sy; d -= ax;
+  if (dy > dx) {	/* chooses axis of greatest movement (make dx) */
+    SL_SWAP(x1, y1);
+    SL_SWAP(x2, y2);
+    SL_SWAP(dx, dy);
+    reverse = 1;
+  } else
+    reverse = 0;
+  /* note error check for dx==0 should be included here */
+  if (x1 > x2) {      /* start from the smaller coordinate */
+    x = x2;
+    y = y2;
+/*  x1 = x1;
+    y1 = y1; */
+  } else {
+    x = x1;
+    y = y1;
+    x1 = x2;
+    y1 = y2;
+  }
+
+
+  /* Note dx=n implies 0 - n or (dx+1) pixels to be set */
+  /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */
+  /* In fact (dx-1)/4 as 2 pixels are already plotted */
+  xend = (dx - 1) / 4;
+  pixels_left = (dx - 1) % 4;  /* number of pixels left over at the
+           * end */
+  plot(object, x, y, reverse, color);
+  if (pixels_left < 0)
+    return;      /* plot only one pixel for zero length
+           * vectors */
+  plot(object, x1, y1, reverse, color);  /* plot first two points */
+  incr2 = 4 * dy - 2 * dx;
+  if (incr2 < 0) {    /* slope less than 1/2 */
+    c = 2 * dy;
+    incr1 = 2 * c;
+    D = incr1 - dx;
+
+    for (i = 0; i < xend; i++) {  /* plotting loop */
+      ++x;
+      --x1;
+      if (D < 0) {
+        /* pattern 1 forwards */
+        plot(object, x, y, reverse, color);
+        plot(object, ++x, y, reverse, color);
+        /* pattern 1 backwards */
+        plot(object, x1, y1, reverse, color);
+        plot(object, --x1, y1, reverse, color);
+        D += incr1;
+      } else {
+        if (D < c) {
+          /* pattern 2 forwards */
+          plot(object, x, y, reverse, color);
+          plot(object, ++x, y += step, reverse,
+              color);
+          /* pattern 2 backwards */
+          plot(object, x1, y1, reverse, color);
+          plot(object, --x1, y1 -= step, reverse,
+              color);
+        } else {
+          /* pattern 3 forwards */
+          plot(object, x, y += step, reverse, color);
+          plot(object, ++x, y, reverse, color);
+          /* pattern 3 backwards */
+          plot(object, x1, y1 -= step, reverse,
+              color);
+          plot(object, --x1, y1, reverse, color);
+        }
+        D += incr2;
       }
-      x += sx; d += ay;
-    }
+    }      /* end for */
+
+    /* plot last pattern */
+    if (pixels_left) {
+      if (D < 0) {
+        plot(object, ++x, y, reverse, color);  /* pattern 1 */
+        if (pixels_left > 1)
+          plot(object, ++x, y, reverse, color);
+        if (pixels_left > 2)
+          plot(object, --x1, y1, reverse, color);
+      } else {
+        if (D < c) {
+          plot(object, ++x, y, reverse, color);  /* pattern 2  */
+          if (pixels_left > 1)
+            plot(object, ++x, y += step, reverse, color);
+          if (pixels_left > 2)
+            plot(object, --x1, y1, reverse, color);
+        } else {
+          /* pattern 3 */
+          plot(object, ++x, y += step, reverse, color);
+          if (pixels_left > 1)
+            plot(object, ++x, y, reverse, color);
+          if (pixels_left > 2)
+            plot(object, --x1, y1 -= step, reverse, color);
+        }
+      }
+    }      /* end if pixels_left */
   }
-  else {					/* y dominant */
-    d = ax-(ay>>1);
-    for (;;) {
-      VGLSetXY(object, x, y, color);
-      if (y==y2) 
-	break;
-      if (d>=0) {
-	x += sx; d -= ay;
+  /* end slope < 1/2 */
+  else {        /* slope greater than 1/2 */
+    c = 2 * (dy - dx);
+    incr1 = 2 * c;
+    D = incr1 + dx;
+    for (i = 0; i < xend; i++) {
+      ++x;
+      --x1;
+      if (D > 0) {
+        /* pattern 4 forwards */
+        plot(object, x, y += step, reverse, color);
+        plot(object, ++x, y += step, reverse, color);
+        /* pattern 4 backwards */
+        plot(object, x1, y1 -= step, reverse, color);
+        plot(object, --x1, y1 -= step, reverse, color);
+        D += incr1;
+      } else {
+        if (D < c) {
+          /* pattern 2 forwards */
+          plot(object, x, y, reverse, color);
+          plot(object, ++x, y += step, reverse,
+              color);
+
+          /* pattern 2 backwards */
+          plot(object, x1, y1, reverse, color);
+          plot(object, --x1, y1 -= step, reverse,
+              color);
+        } else {
+          /* pattern 3 forwards */
+          plot(object, x, y += step, reverse, color);
+          plot(object, ++x, y, reverse, color);
+          /* pattern 3 backwards */
+          plot(object, x1, y1 -= step, reverse, color);
+          plot(object, --x1, y1, reverse, color);
+        }
+        D += incr2;
       }
-      y += sy; d += ax;
+    }      /* end for */
+    /* plot last pattern */
+    if (pixels_left) {
+      if (D > 0) {
+        plot(object, ++x, y += step, reverse, color);  /* pattern 4 */
+        if (pixels_left > 1)
+          plot(object, ++x, y += step, reverse,
+              color);
+        if (pixels_left > 2)
+          plot(object, --x1, y1 -= step, reverse,
+              color);
+      } else {
+        if (D < c) {
+          plot(object, ++x, y, reverse, color);  /* pattern 2  */
+          if (pixels_left > 1)
+            plot(object, ++x, y += step, reverse, color);
+          if (pixels_left > 2)
+            plot(object, --x1, y1, reverse, color);
+        } else {
+          /* pattern 3 */
+          plot(object, ++x, y += step, reverse, color);
+          if (pixels_left > 1)
+            plot(object, ++x, y, reverse, color);
+          if (pixels_left > 2) {
+            if (D > c)  /* step 3 */
+              plot(object, --x1, y1 -= step, reverse, color);
+            else  /* step 2 */
+              plot(object, --x1, y1, reverse, color);
+          }
+        }
+      }
     }
   }
 }
diff -r 9f40516392fd -r 77905f94b3a7 head/libexec/mknetid/parse_group.c
--- a/head/libexec/mknetid/parse_group.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/libexec/mknetid/parse_group.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
 static const char sccsid[] = "@(#)getgrent.c	8.2 (Berkeley) 3/21/94";
 #endif
 static const char rcsid[] =
-  "$FreeBSD$";
+  "$FreeBSD: head/libexec/mknetid/parse_group.c 229403 2012-01-03 18:51:58Z ed $";
 #endif /* not lint */
 
 /*
@@ -114,7 +114,7 @@
 			return(0);
 		bp = line;
 		/* skip lines that are too big */
-		if (!index(line, '\n')) {
+		if (!strchr(line, '\n')) {
 			int ch;
 
 			while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)
diff -r 9f40516392fd -r 77905f94b3a7 head/libexec/rlogind/rlogind.c
--- a/head/libexec/rlogind/rlogind.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/libexec/rlogind/rlogind.c	Thu Jan 05 13:30:52 2012 +0200
@@ -50,7 +50,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/libexec/rlogind/rlogind.c 229403 2012-01-03 18:51:58Z ed $");
 
 /*
  * remote login server:
@@ -543,16 +543,17 @@
 void
 setup_term(int fd)
 {
-	char *cp = index(term+ENVSIZE, '/');
+	char *cp;
 	char *speed;
 	struct termios tt, def;
 
+	cp = strchr(term + ENVSIZE, '/');
 #ifndef notyet
 	tcgetattr(fd, &tt);
 	if (cp) {
 		*cp++ = '\0';
 		speed = cp;
-		cp = index(speed, '/');
+		cp = strchr(speed, '/');
 		if (cp)
 			*cp++ = '\0';
 		cfsetspeed(&tt, atoi(speed));
@@ -567,7 +568,7 @@
 	if (cp) {
 		*cp++ = '\0';
 		speed = cp;
-		cp = index(speed, '/');
+		cp = strchr(speed, '/');
 		if (cp)
 			*cp++ = '\0';
 		tcgetattr(fd, &tt);
diff -r 9f40516392fd -r 77905f94b3a7 head/libexec/rtld-elf/rtld.c
--- a/head/libexec/rtld-elf/rtld.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/libexec/rtld-elf/rtld.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: head/libexec/rtld-elf/rtld.c 228503 2011-12-14 16:47:53Z kib $
+ * $FreeBSD: head/libexec/rtld-elf/rtld.c 229508 2012-01-04 17:17:11Z kib $
  */
 
 /*
@@ -515,10 +515,6 @@
       ld_bind_now != NULL && *ld_bind_now != '\0', &obj_rtld, NULL) == -1)
 	die();
 
-    if (resolve_objects_ifunc(obj_main,
-      ld_bind_now != NULL && *ld_bind_now != '\0', NULL) == -1)
-	die();
-
     dbg("doing copy relocations");
     if (do_copy_relocations(obj_main) == -1)
 	die();
@@ -549,6 +545,11 @@
 
     map_stacks_exec(NULL);
 
+    dbg("resolving ifuncs");
+    if (resolve_objects_ifunc(obj_main,
+      ld_bind_now != NULL && *ld_bind_now != '\0', NULL) == -1)
+	die();
+
     wlock_acquire(rtld_bind_lock, &lockstate);
     objlist_call_init(&initlist, &lockstate);
     objlist_clear(&initlist);
diff -r 9f40516392fd -r 77905f94b3a7 head/release/picobsd/build/Makefile.conf
--- a/head/release/picobsd/build/Makefile.conf	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/release/picobsd/build/Makefile.conf	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/release/picobsd/build/Makefile.conf 227878 2011-11-23 12:05:39Z luigi $
+# $FreeBSD: head/release/picobsd/build/Makefile.conf 229511 2012-01-04 19:37:25Z luigi $
 #
 # Makefile for building PICOBSD kernels and running crunchgen
 #
@@ -13,6 +13,7 @@
 SRC?=/usr/src
 CONFIG?=config
 MODULES?=-DNO_MODULES	# do not build them as a default
+KERNCONF ?= PICOBSD
 
 # caller will set MODULES to empty if modules are needed.
 # Indeed, it can be used to specify other Makefile options as well.
@@ -45,10 +46,10 @@
 	(cd ${CONF}; ${CONFIG} -d ${COMPILE} ${CONFFILE}; \
 	cd ${COMPILE}; ${BINMAKE} KERNEL=kernel ${MODULES} depend )
 
-${CONF}/${CONFFILE}: PICOBSD
+${CONF}/${CONFFILE}: ${KERNCONF}
 	# -mkdir -p ${CONF}		# XXX not needed yet.
 	cp ${.OODATE} ${.TARGET}
-	if [ -f PICOBSD.hints ] ; then cp PICOBSD.hints ${CONF}/PICOBSD.hints ; fi
+	[ -f PICOBSD.hints ] && cp PICOBSD.hints ${CONF}/
 
 # This part creates crunch1.conf and crunch.mk from crunch.conf
 ${BUILDDIR}/crunch.mk: ${BUILDDIR}/crunch1.conf
diff -r 9f40516392fd -r 77905f94b3a7 head/release/picobsd/build/picobsd
--- a/head/release/picobsd/build/picobsd	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/release/picobsd/build/picobsd	Thu Jan 05 13:30:52 2012 +0200
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-# $FreeBSD: head/release/picobsd/build/picobsd 227878 2011-11-23 12:05:39Z luigi $
+# $FreeBSD: head/release/picobsd/build/picobsd 229532 2012-01-04 23:00:25Z luigi $
 # This file requires sysutils/makefs to run
 #
 # The PicoBSD build script. Invoked as
@@ -105,11 +105,6 @@
     EDITOR=${EDITOR:-vi}
     fd_size=${fd_size:-1440}
 
-    o_use_loader="yes"		# use /boot/loader
-	# You should not change it unless you are really short
-	# of space, and your kernel is small enough that the
-	# bootblocks manage to load it.
-
     o_all_in_mfs="yes"		# put all files in mfs so you can boot
 				# and run the image via diskless boot.
     o_clean=""			# set if you want to clean prev.builds.
@@ -166,20 +161,30 @@
 # and also to build a specific target
 create_includes_and_libraries2() { # opt_dir opt_target
     local no
-    log "create_includes_and_libraries2() for ${SRC}"
+    log "create_includes_and_libraries2() for ${SRC} $1"
     if [ ${OSVERSION} -ge 600000 ] ; then
 	no="-DNO_CLEAN -DNO_PROFILE -DNO_GAMES -DNO_LIBC_R" # WITHOUT_CDDL=1"
     else
 	no="-DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R"
     fi
-    MAKEOBJDIRPREFIX=${l_objtree}
-    export MAKEOBJDIRPREFIX
     ( cd ${SRC};
     # make -DNOCLEAN -DNOPROFILE -DNOGAMES -DNOLIBC_R -DPICOBSD buildworld
     if [ -d "$1" ] ; then
 	cd $1 ; ${BINMAKE} ${o_par} $2	# specific target, e.g. ld-elf.so
     else
-	${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
+	MAKEOBJDIRPREFIX=${l_objtree}
+	export MAKEOBJDIRPREFIX
+	# export WITH_RESCUE=yes	# build crunchide
+	# ${BINMAKE} ${o_par} _+_= $no toolchain _includes _libraries
+	(
+	    # eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V BMAKEENV`
+	    eval "export XMAKE=\"`cd ${SRC}; make -f Makefile -V XMAKE`\""
+	    ${BINMAKE} ${o_par} _+_= $no toolchain
+	)
+        eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
+	${BINMAKE} ${o_par} _+_= $no _includes _libraries
+	[ ${o_arch} != `uname -m` ] && \
+	    (cd ${l_objtree}; ln -s . ${o_arch}.${o_arch} || true )
     fi
     )
 }
@@ -242,16 +247,19 @@
     name=""	# clear in case of errors
     for i in ${c_startdir}/${a} ${PICO_TREE}/${a} ; do
 	log "set_type: checking $i"
-	[ -d $i -a -f $i/PICOBSD -a -f $i/crunch.conf ] || continue
-	set -- `cat $i/PICOBSD | \
+	[ -d $i -a -f $i/crunch.conf ] || continue
+	# look for a kernel config file, privilege arch-specific
+	l_kernconf=$i/PICOBSD.${o_arch}
+	[ -f $l_kernconf ] || l_kernconf=$i/PICOBSD
+	[ -f $l_kernconf ] || continue
+	set -- `cat $l_kernconf | \
 	    awk '/^#PicoBSD/ {print $2, $3, $4, $5, $6}'`
 	[ x"$1" != "x" ] || continue
-	MFS_SIZE=$1 ; init_name=$2
-	mfs_inodes=$3 ; fd_inodes=$4
+	MFS_SIZE=$1
 	name=`(cd $i ; pwd) `
 	name=`basename $name`
 	MY_TREE=$i
-	BUILDDIR=${c_startdir}/build_dir-${name}
+	BUILDDIR=${c_startdir}/build_dir-${name}-${o_arch}
 	log "Matching file $name in $i"
 	return ;
     done
@@ -328,10 +336,7 @@
 	K "edit Kernel config file" \
 	E "Edit crunch.conf file" \
 	S "MFS Size: ${MFS_SIZE}kB" \
-	I "Init type: ${init_name}" \
 	F "Floppy size: ${fd_size}kB" \
-	M "MFS bytes per inode: ${mfs_inodes}" \
-	U "UFS bytes per inode: ${fd_inodes}" \
 	$ "Site-info: ${SITE}" \
 	Q "Quit" \
 	2> ${c_reply}
@@ -349,12 +354,6 @@
 	{ dialog --menu "Setup the type of configuration" 12 70 5 $l \
 		2> ${c_reply} && set_type "`cat ${c_reply}`" ${SITE} ; } || true
 	;;
-    I)
-	{ dialog --menu "Choose your init(8) program" \
-	10 70 2 init "Standard init (requires getty)" \
-	oinit "small init from TinyWare" 2> ${c_reply} \
-		&& init_name=`cat ${c_reply}` ; } || true
-	;;
 
     K) ${EDITOR} ${MY_TREE}/PICOBSD ;;
 
@@ -386,20 +385,6 @@
 		 2> ${c_reply} && fd_size=`cat ${c_reply}` ; } || true
 	;;
 
-    M)
-	{ dialog --title "MFS bytes per inode:" --inputbox \
-	"Enter MFS bytes per inode (typically 4096..65536). \
-	A larger value means fewer inodes but more space on MFS" \
-	10 70 2> ${c_reply} && mfs_inodes=`cat ${c_reply}`  ; } || true
-	;;
-
-    U)
-	{ dialog --title "Floppy bytes per inode:" --inputbox \
-	"Enter floppy bytes per inode (typically 3072..65536). \
-	A larger value means fewer inodes but more space on the floppy." \
-	10 70 2> ${c_reply} && fd_inodes=`cat ${c_reply}` ; } || true
-	;;
-
     N) break 2
 	;;
 
@@ -454,8 +439,9 @@
 	# export CONFIG
 	export WARNS CWARNFLAGS
 	[ "${o_do_modules}" = "yes" ] && export MODULES=""
-	${BINMAKE} ${o_par} -v -f ${PICO_TREE}/build/Makefile.conf ) || \
-	fail $? missing_kernel
+	${BINMAKE} ${o_par} KERNCONF=${l_kernconf}	\
+		-v -f ${PICO_TREE}/build/Makefile.conf ) || \
+	    fail $? missing_kernel
 }
 
 # Populate the variable part of the floppy filesystem. Must be done before
@@ -565,7 +551,7 @@
 # find_progs is a helper function to locate the named programs
 # or libraries in ${o_objdir} or ${_SHLIBDIRPREFIX},
 # and return the full pathnames.
-# Called as "find_progs [-L libpath] [-P binpath] prog1 prog2 ... "
+# Called as "find_progs [[-L libpath] [-P binpath]] prog1 prog2 ... "
 # On return it sets ${u_progs} to the list of programs, and ${u_libs}
 # to the list of shared libraries used.
 # 
@@ -588,23 +574,32 @@
 #  }
 
 find_progs() {	# programs
-	local i
-	local oo=${o_objdir:-${_SHLIBDIRPREFIX}} # default objdir
-	local lp=$oo/lib			# default lib.prefix
-	local o=""				# additional objdir
+	local pass i old_libs="" tmp o=""
 	if [ x"$1" = "x-L" -a -d "$2" ] ; then # set lib search path
-		o=$2; shift; shift
-		lp="$lp:$o/lib:$o/usr/lib:$o/usr/local/lib"
-		o="-P $o"
+		o="-P $2"; shift; shift
 	fi
-	u_libs=""
-	u_progs="`find_progs_helper $*`"
-	log "looking for libs for <$u_progs> in $lp"
+	# Result returned in global variables
+	u_libs="" ; u_progs="`find_progs_helper $*`"
 	[ -z "${u_progs}" ] && return 1	# not found, error
-	i="`( LD_LIBRARY_PATH=$lp ldd ${u_progs} ) | \
-		grep -v '^/' | awk '{print $1}' | sort | uniq`"
-	u_libs="`find_progs_helper $o $i`"
-	return 0
+	# use objdump to find libraries. Iterate to fetch recursive
+	# dependencies.
+	tmp="${u_progs}" ; pass=1
+	while [ $pass -lt 10 ] ; do
+		pass=$(($pass + 1))
+		i="`objdump -x ${tmp} | \
+			awk '$1 == "NEEDED" { print $2 }' | sort | uniq`"
+		if [ "$old_libs" = "$i" ] ; then
+			log "libraries for: $my_progs ($u_progs) are ($i) $u_libs"
+			log "--- done find_progs ---"
+			return 0
+		else
+			# logverbose "old--- $old_libs --- new +++ $i +++"
+		fi
+		u_libs="`find_progs_helper $o $i`"
+		old_libs="$i"
+		tmp="$tmp $u_libs"
+	done
+	log "WARNING: Too many passes, giving up"
 }
 
 find_progs_helper() {	# programs
@@ -637,8 +632,12 @@
 		[ -d "${ldir}/${i}" ] && places="${places} ${ldir}/${i}"
 	    done
 	fi
+	for i in $progs ; do
+		# full pathnames are just listed
+		[ -f "$i" ] && echo $i && continue
+		find ${places} -maxdepth 3 -type f -name ${i} | head -1
+	done
 	# use maxdepth 3 because some libs are way down
-	find ${places} -maxdepth 3 -type f \( ${names} \)
 }
 
 # Populate the memory filesystem with binaries and non-variable
@@ -788,7 +787,6 @@
 final_cleanup() {
     log "final_cleanup()"
     rm -rf ${c_mnt} ${c_reply} 2> /dev/null || true
-    rm -f ${c_reply}
 }
 
 # fail errno errcode
@@ -857,17 +855,6 @@
     fi
 
     log "Labeling floppy image"
-    b2=${BUILDDIR}/boot2 # modified boot2
-    cp -f ${c_boot2} ${b2}
-    chmod 0644 ${b2}
-
-    if [ ${o_use_loader} = "no" ] ; then
-	log "patch ${c_boot2} to boot /kernel right away"
-	set `strings -at d ${b2} | grep "/boot/loader"`
-	echo -e "/kernel\0\0\0\0\0" | \
-	    dd of=${b2} obs=$1 oseek=1 conv=notrunc 2>/dev/null
-    fi
-    chmod 0444 ${b2}
 
     dst=${BUILDDIR}/image.tree
     rm -rf ${dst}
@@ -893,17 +880,13 @@
     	log "not loading mfs, size ${mfs_size} img ${imgsize}"
     fi
     log "Compress with kgzip and copy to floppy image"
-    if [ ${o_use_loader} = "no" ] ; then
-	kgzip -o kernel.gz kernel
-	cp -p kernel.gz ${dst}/kernel || fail $? no_space "copying kernel"
-    else
-        gzip kernel
-	mkdir -p  ${dst}/boot/kernel
-	echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
-	echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
-	cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
-	cp -p kernel.gz ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"
-    fi
+
+    mkdir -p  ${dst}/boot/kernel
+    # XXX update loader.conf
+    echo "hint.acpi.0.disabled=\"1\"" > ${dst}/boot/loader.conf
+    echo "console=\"comconsole\"" >> ${dst}/boot/loader.conf
+    cp -p /boot/loader ${dst}/boot/loader || fail $? no_space "copying bootloader"
+    gzip -c kernel > ${dst}/boot/kernel/kernel.gz || fail $? no_space "copying kernel"
 
     # now transfer the floppy tree. If it is already in mfs, dont bother.
     if [ "${o_all_in_mfs}" != "yes" ] ; then
@@ -953,10 +936,13 @@
     # so we skip 276 from the source, and 276+512=788 from dst
     # the old style blocks used 512 and 1024 respectively
 
-    dd if=${b2} iseek=1 ibs=276 2> /dev/null | \
+    dd if=${c_boot2} iseek=1 ibs=276 2> /dev/null | \
 	dd of=${BUILDDIR}/${c_img} oseek=1 obs=788 conv=notrunc 2>/dev/null
     log "done disk image"
     # XXX (log "Fixing permissions"; cd ${dst}; chown -R root *)
+    # leave build stuff if verbose
+    [ ${o_verbose} -gt 0 ] && return
+
     rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
     # df -ik ${dst} | colrm 70 > .build.reply
     rm -rf ${dst}
@@ -984,9 +970,10 @@
     if [ ${OSVERSION} -ge 500035 ] ; then
 	export MAKEOBJDIRPREFIX=${l_objtree}
 	export TARGET_ARCH=${o_arch} TARGET=${o_arch}
+	# XXX why change machine_arch ?
+	#-- export MACHINE_ARCH=`uname -m` MACHINE=`uname -m`
 	# export CWARNFLAGS="-Wextra -Wno-sign-compare -Wno-missing-field-initializers"
 	eval "export BINMAKE=\"`cd ${SRC}; make -f Makefile -V BINMAKE`\""
-	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
     fi
 
     if [ "${o_init_src}" != "" ] ; then
@@ -995,6 +982,8 @@
 	else
 	    create_includes_and_libraries2
 	fi
+    else
+	eval export `cd ${SRC}; ${BINMAKE} -f Makefile.inc1 -V WMAKEENV`
     fi
     if [ ${OSVERSION} -lt 500035 ] ; then
 	# Create the right LIBS and CFLAGS for further builds.
@@ -1030,29 +1019,29 @@
 while [ true ]; do
     log "Parsing $1"
     case $1 in
+    --par)
+	o_par="-j 8"
+	;;
+
     --src)	# set the source path instead of /usr/src
 	SRC=`realpath $2`
 	shift
 	;;
-    --init)
+
+    --init)	# run a partial buildworld on the source tree
 	o_init_src="YES"
 	;;
 
-    --arch)
+    --arch)	# override the target architecture
 	o_arch=$2
 	shift
 	;;
 
-    --floppy_size)
+    --floppy_size)	# image size
 	fd_size=$2
 	shift
 	;;
 
-    --no_loader)	# omit /boot/loader, just rely on boot2
-			# (it may have problems with kernels > 4MB)
-	o_use_loader="no"
-	;;
-
     --all_in_mfs)
 	o_all_in_mfs="yes"
 	;;
@@ -1064,6 +1053,7 @@
     --modules)	# also build kernel modules
 	o_do_modules="yes"
 	;;
+
     -n)
 	o_interactive="NO"
 	;;
diff -r 9f40516392fd -r 77905f94b3a7 head/sbin/bsdlabel/bsdlabel.c
--- a/head/sbin/bsdlabel/bsdlabel.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sbin/bsdlabel/bsdlabel.c	Thu Jan 05 13:30:52 2012 +0200
@@ -53,7 +53,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sbin/bsdlabel/bsdlabel.c 229049 2011-12-31 00:09:33Z sobomax $");
+__FBSDID("$FreeBSD: head/sbin/bsdlabel/bsdlabel.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <stdint.h>
@@ -782,12 +782,12 @@
 	lp->d_sbsize = 0;				/* XXX */
 	while (fgets(line, sizeof(line) - 1, f)) {
 		lineno++;
-		if ((cp = index(line,'\n')) != 0)
+		if ((cp = strchr(line,'\n')) != 0)
 			*cp = '\0';
 		cp = skip(line);
 		if (cp == NULL)
 			continue;
-		tp = index(cp, ':');
+		tp = strchr(cp, ':');
 		if (tp == NULL) {
 			fprintf(stderr, "line %d: syntax error\n", lineno);
 			errors++;
diff -r 9f40516392fd -r 77905f94b3a7 head/sbin/dump/main.c
--- a/head/sbin/dump/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sbin/dump/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -38,7 +38,7 @@
 static char sccsid[] = "@(#)main.c	8.6 (Berkeley) 5/1/95";
 #endif
 static const char rcsid[] =
-  "$FreeBSD$";
+  "$FreeBSD: head/sbin/dump/main.c 229403 2012-01-03 18:51:58Z ed $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -290,7 +290,7 @@
 		tape = strchr(host, ':');
 		*tape++ = '\0';
 #ifdef RDUMP
-		if (index(tape, '\n')) {
+		if (strchr(tape, '\n')) {
 		    (void)fprintf(stderr, "invalid characters in tape\n");
 		    exit(X_STARTUP);
 		}
diff -r 9f40516392fd -r 77905f94b3a7 head/sbin/fsck_ffs/pass2.c
--- a/head/sbin/fsck_ffs/pass2.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sbin/fsck_ffs/pass2.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sbin/fsck_ffs/pass2.c 221110 2011-04-27 02:55:03Z des $");
+__FBSDID("$FreeBSD: head/sbin/fsck_ffs/pass2.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -613,7 +613,7 @@
 			printf(" (IGNORED)\n");
 			return (0);
 		}
-		if ((cp = rindex(oldname, '/')) == NULL) {
+		if ((cp = strchr(oldname, '/')) == NULL) {
 			printf(" (IGNORED)\n");
 			return (0);
 		}
diff -r 9f40516392fd -r 77905f94b3a7 head/sbin/ifconfig/ifconfig.8
--- a/head/sbin/ifconfig/ifconfig.8	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sbin/ifconfig/ifconfig.8	Thu Jan 05 13:30:52 2012 +0200
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     From: @(#)ifconfig.8	8.3 (Berkeley) 1/5/94
-.\" $FreeBSD: head/sbin/ifconfig/ifconfig.8 228641 2011-12-17 15:44:34Z bz $
+.\" $FreeBSD: head/sbin/ifconfig/ifconfig.8 229518 2012-01-04 21:04:57Z rwatson $
 .\"
-.Dd December 17, 2011
+.Dd January 4, 2012
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -2378,7 +2378,7 @@
 .It Cm vlan Ar vlan_tag
 Set the VLAN tag value to
 .Ar vlan_tag .
-This value is a 16-bit number which is used to create an 802.1Q
+This value is a 12-bit VLAN Identifier (VID) which is used to create an 802.1Q
 VLAN header for packets sent from the
 .Xr vlan 4
 interface.
@@ -2400,7 +2400,7 @@
 .Ar iface
 with 802.1Q VLAN encapsulation.
 Packets with 802.1Q encapsulation received
-by the parent interface with the correct VLAN tag will be diverted to
+by the parent interface with the correct VLAN Identifier will be diverted to
 the associated
 .Xr vlan 4
 pseudo-interface.
@@ -2439,7 +2439,8 @@
 This breaks the link between the
 .Xr vlan 4
 interface and its parent,
-clears its VLAN tag, flags and its link address and shuts the interface down.
+clears its VLAN Identifier, flags and its link address and shuts the interface
+down.
 The
 .Ar iface
 argument is useless and hence deprecated.
diff -r 9f40516392fd -r 77905f94b3a7 head/sbin/ipfw/main.c
--- a/head/sbin/ipfw/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sbin/ipfw/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -17,7 +17,7 @@
  *
  * Command line interface for IP firewall facility
  *
- * $FreeBSD: head/sbin/ipfw/main.c 228871 2011-12-24 22:37:27Z eadler $
+ * $FreeBSD: head/sbin/ipfw/main.c 229403 2012-01-03 18:51:58Z ed $
  */
 
 #include <sys/wait.h>
@@ -122,9 +122,9 @@
 				break;
 			if (copy) {
 				arg[j++] = arg[i];
-				copy = !index("," WHITESP, arg[i]);
+				copy = !strchr("," WHITESP, arg[i]);
 			} else {
-				copy = !index(WHITESP, arg[i]);
+				copy = !strchr(WHITESP, arg[i]);
 				if (copy)
 					arg[j++] = arg[i];
 			}
@@ -141,7 +141,7 @@
 		 * processing, this is just the number of blanks plus 1.
 		 */
 		for (i = 0, ac = 1; i < l; i++)
-			if (index(WHITESP, arg[i]) != NULL)
+			if (strchr(WHITESP, arg[i]) != NULL)
 				ac++;
 
 		/*
@@ -162,7 +162,7 @@
 		 */
 		av_p = (char *)&av[ac+1];
 		for (ac = 1, i = j = 0; i < l; i++) {
-			if (index(WHITESP, arg[i]) != NULL || i == l-1) {
+			if (strchr(WHITESP, arg[i]) != NULL || i == l-1) {
 				if (i == l-1)
 					i++;
 				bcopy(arg+j, av_p, i-j);
@@ -240,7 +240,7 @@
 				"	ipfw sysctl -a\n");
 			return 0;
 		}
-		s = index(av[2], '=');
+		s = strchr(av[2], '=');
 		if (s == NULL) {
 			s = !strcmp(av[2], "-a") ? NULL : av[2];
 			sysctlbyname(s, NULL, NULL, NULL, 0);
diff -r 9f40516392fd -r 77905f94b3a7 head/sbin/shutdown/shutdown.c
--- a/head/sbin/shutdown/shutdown.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sbin/shutdown/shutdown.c	Thu Jan 05 13:30:52 2012 +0200
@@ -39,7 +39,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sbin/shutdown/shutdown.c 227081 2011-11-04 13:36:02Z ed $");
+__FBSDID("$FreeBSD: head/sbin/shutdown/shutdown.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -123,7 +123,7 @@
 	 * Test for the special case where the utility is called as
 	 * "poweroff", for which it runs 'shutdown -p now'.
 	 */
-	if ((p = rindex(argv[0], '/')) == NULL)
+	if ((p = strrchr(argv[0], '/')) == NULL)
 		p = argv[0];
 	else
 		++p;
diff -r 9f40516392fd -r 77905f94b3a7 head/share/man/man3/tgmath.3
--- a/head/share/man/man3/tgmath.3	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/share/man/man3/tgmath.3	Thu Jan 05 13:30:52 2012 +0200
@@ -22,9 +22,9 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/share/man/man3/tgmath.3 229575 2012-01-05 10:46:22Z ed $
 .\"
-.Dd August 14, 2004
+.Dd January 4, 2012
 .Dt TGMATH 3
 .Os
 .Sh NAME
@@ -139,15 +139,24 @@
 .In tgmath.h
 first appeared in
 .Fx 5.3 .
+.Sh COMPILER SUPPORT
+Before
+.St -isoC-11 ,
+the header
+.In tgmath.h
+could not be implemented with strictly conforming C code and needed
+special compiler support.
+As of
+.St -isoC-11 ,
+this header file can be implemented using the
+.Fn _Generic
+language keyword.
+In addition to compilers that support this keyword, this header file
+works with GCC.
 .Sh BUGS
-The header
-.In tgmath.h
-cannot be implemented with strictly conforming C code and needs
-special compiler support.
-The current implementation only works for GCC.
-.Pp
 Many of the functions mentioned here are not prototyped in
 .In math.h
 or
 .In complex.h
 as they are not yet implemented.
+This prevents the corresponding type-generic macro from working at all.
diff -r 9f40516392fd -r 77905f94b3a7 head/share/man/man5/src.conf.5
--- a/head/share/man/man5/src.conf.5	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/share/man/man5/src.conf.5	Thu Jan 05 13:30:52 2012 +0200
@@ -1,7 +1,7 @@
 .\" DO NOT EDIT-- this file is automatically generated.
 .\" from FreeBSD: head/tools/build/options/makeman 221733 2011-05-10 13:01:11Z ru
-.\" $FreeBSD: head/share/man/man5/src.conf.5 228197 2011-12-02 09:28:19Z fjoe $
-.Dd December 2, 2011
+.\" $FreeBSD: head/share/man/man5/src.conf.5 229319 2012-01-02 21:57:58Z rwatson $
+.Dd December 30, 2011
 .Dt SRC.CONF 5
 .Os
 .Sh NAME
@@ -251,6 +251,9 @@
 .\" from FreeBSD: head/tools/build/options/WITHOUT_CALENDAR 156932 2006-03-21 07:50:50Z ru
 Set to not build
 .Xr calendar 1 .
+.It Va WITHOUT_CAPSICUM
+.\" $FreeBSD: head/share/man/man5/src.conf.5 229319 2012-01-02 21:57:58Z rwatson $
+Set to not build Capsicum support into system programs.
 .It Va WITHOUT_CDDL
 .\" from FreeBSD: head/tools/build/options/WITHOUT_CDDL 163861 2006-11-01 09:02:11Z jb
 Set to not build code licensed under Sun's CDDL.
@@ -821,7 +824,7 @@
 .Xr ppp 8
 and related programs.
 .It Va WITHOUT_PROFILE
-.\" from FreeBSD: head/tools/build/options/WITH_PROFILE 228143 2011-11-29 19:46:17Z fjoe
+.\" from FreeBSD: head/tools/build/options/WITHOUT_PROFILE 228196 2011-12-02 09:09:54Z fjoe
 Set to avoid compiling profiled libraries.
 .It Va WITHOUT_QUOTAS
 .\" from FreeBSD: head/tools/build/options/WITHOUT_QUOTAS 183242 2008-09-21 22:02:26Z sam
diff -r 9f40516392fd -r 77905f94b3a7 head/share/man/man9/Makefile
--- a/head/share/man/man9/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/share/man/man9/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/share/man/man9/Makefile 228731 2011-12-20 11:40:22Z mav $
+# $FreeBSD: head/share/man/man9/Makefile 229206 2012-01-01 20:59:42Z ed $
 
 MAN=	accept_filter.9 \
 	accf_data.9 \
@@ -164,6 +164,7 @@
 	mbuf_tags.9 \
 	MD5.9 \
 	mdchain.9 \
+	memcchr.9 \
 	memguard.9 \
 	microseq.9 \
 	microtime.9 \
diff -r 9f40516392fd -r 77905f94b3a7 head/share/man/man9/memcchr.9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/share/man/man9/memcchr.9	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,59 @@
+.\" Copyright (c) 2012 Ed Schouten <ed at FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: head/share/man/man9/memcchr.9 229206 2012-01-01 20:59:42Z ed $
+.\"
+.Dd January 1, 2012
+.Dt MEMCCHR 9
+.Os
+.Sh NAME
+.Nm memcchr
+.Nd locate the complement of a byte in byte string
+.Sh SYNOPSIS
+.In sys/libkern.h
+.Ft void *
+.Fn memcchr "const void *b" "int c" "size_t len"
+.Sh DESCRIPTION
+The
+.Fn memcchr
+function locates the first occurrence of a byte unequal to
+.Fa c
+(converted to an
+.Vt "unsigned char" )
+in string
+.Fa b .
+.Sh RETURN VALUES
+The
+.Fn memcchr
+function returns a pointer to the byte located, or NULL if no such byte
+exists within
+.Fa len
+bytes.
+.Sh SEE ALSO
+.Xr memchr 3
+.Sh HISTORY
+The
+.Fn memcchr
+function first appeared in
+.Fx 10.0 .
diff -r 9f40516392fd -r 77905f94b3a7 head/share/mk/bsd.own.mk
--- a/head/share/mk/bsd.own.mk	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/share/mk/bsd.own.mk	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/share/mk/bsd.own.mk 228196 2011-12-02 09:09:54Z fjoe $
+# $FreeBSD: head/share/mk/bsd.own.mk 229319 2012-01-02 21:57:58Z rwatson $
 #
 # The include file <bsd.own.mk> set common variables for owner,
 # group, mode, and directories. Defaults are in brackets.
@@ -327,6 +327,7 @@
     BSNMP \
     BZIP2 \
     CALENDAR \
+    CAPSICUM \
     CDDL \
     CPP \
     CRYPT \
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/Makefile
--- a/head/sys/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/sys/Makefile 222952 2011-06-10 20:51:41Z gibbs $
+# $FreeBSD: head/sys/Makefile 229400 2012-01-03 17:31:27Z jhb $
 
 .include <bsd.own.mk>
 
@@ -13,10 +13,18 @@
 		netgraph netinet netinet6 netipsec netipx netnatm netncp \
 		netsmb nfs nfsclient nfsserver nlm opencrypto \
 		pci rpc security sys ufs vm xdr xen ${CSCOPE_ARCHDIR}
+.if !defined(CSCOPE_ARCHDIR)
 .if defined(ALL_ARCH)
-CSCOPE_ARCHDIR ?= amd64 arm i386 ia64 mips pc98 powerpc sparc64 x86
+CSCOPE_ARCHDIR = amd64 arm i386 ia64 mips pc98 powerpc sparc64 x86
 .else
-CSCOPE_ARCHDIR ?= ${MACHINE}
+CSCOPE_ARCHDIR = ${MACHINE} 
+.if ${MACHINE} != ${MACHINE_CPUARCH}
+CSCOPE_ARCHDIR += ${MACHINE_CPUARCH}
+.endif
+.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
+CSCOPE_ARCHDIR += x86
+.endif
+.endif
 .endif
 
 # Loadable kernel modules
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/common/interp_parse.c
--- a/head/sys/boot/common/interp_parse.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/common/interp_parse.c	Thu Jan 05 13:30:52 2012 +0200
@@ -15,7 +15,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/boot/common/interp_parse.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <stand.h>
 #include <string.h>
@@ -137,7 +137,7 @@
 
 	case VAR:
 	    if (token) {
-		PARSE_FAIL((q = index(p, token)) == NULL);
+		PARSE_FAIL((q = strchr(p, token)) == NULL);
 	    } else {
 		q = p;
 		while (*q && !isspace(*q))
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/i386/libi386/biospci.c
--- a/head/sys/boot/i386/libi386/biospci.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/i386/libi386/biospci.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/biospci.c 226746 2011-10-25 19:45:12Z jhb $");
+__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/biospci.c 229435 2012-01-03 22:36:12Z kib $");
 
 /*
  * PnP enumerator using the PCI BIOS.
@@ -342,3 +342,9 @@
 	return (0);
 }
 
+uint32_t
+biospci_locator(int8_t bus, uint8_t device, uint8_t function)
+{
+
+	return ((bus << 8) | ((device & 0x1f) << 3) | (function & 0x7));
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/i386/libi386/comconsole.c
--- a/head/sys/boot/i386/libi386/comconsole.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/i386/libi386/comconsole.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,12 +24,13 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/boot/i386/libi386/comconsole.c 229435 2012-01-03 22:36:12Z kib $");
 
 #include <stand.h>
 #include <bootstrap.h>
 #include <machine/cpufunc.h>
 #include <dev/ic/ns16550.h>
+#include <dev/pci/pcireg.h>
 #include "libi386.h"
 
 #define COMC_FMT	0x3		/* 8N1 */
@@ -49,14 +50,23 @@
 static void	comc_putchar(int c);
 static int	comc_getchar(void);
 static int	comc_getspeed(void);
+static void	set_hw_console_hint(void);
 static int	comc_ischar(void);
-static int	comc_parsespeed(const char *string);
-static void	comc_setup(int speed);
+static int	comc_parseint(const char *string);
+static uint32_t comc_parse_pcidev(const char *string);
+static int	comc_pcidev_set(struct env_var *ev, int flags,
+		    const void *value);
+static int	comc_pcidev_handle(uint32_t locator);
+static int	comc_port_set(struct env_var *ev, int flags,
+		    const void *value);
+static void	comc_setup(int speed, int port);
 static int	comc_speed_set(struct env_var *ev, int flags,
 		    const void *value);
 
 static int	comc_started;
 static int	comc_curspeed;
+static int	comc_port = COMPORT;
+static uint32_t	comc_locator;
 
 struct console comconsole = {
     "comconsole",
@@ -72,9 +82,10 @@
 static void
 comc_probe(struct console *cp)
 {
-    char speedbuf[16];
-    char *cons, *speedenv;
-    int speed;
+    char intbuf[16];
+    char *cons, *env;
+    int speed, port;
+    uint32_t locator;
 
     /* XXX check the BIOS equipment list? */
     cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
@@ -90,16 +101,40 @@
 	    getenv("boot_multicons") != NULL) {
 		comc_curspeed = comc_getspeed();
 	}
-	speedenv = getenv("comconsole_speed");
-	if (speedenv != NULL) {
-	    speed = comc_parsespeed(speedenv);
+
+	env = getenv("comconsole_speed");
+	if (env != NULL) {
+	    speed = comc_parseint(env);
 	    if (speed > 0)
 		comc_curspeed = speed;
 	}
 
-	sprintf(speedbuf, "%d", comc_curspeed);
+	sprintf(intbuf, "%d", comc_curspeed);
 	unsetenv("comconsole_speed");
-	env_setenv("comconsole_speed", EV_VOLATILE, speedbuf, comc_speed_set,
+	env_setenv("comconsole_speed", EV_VOLATILE, intbuf, comc_speed_set,
+	    env_nounset);
+
+	env = getenv("comconsole_port");
+	if (env != NULL) {
+	    port = comc_parseint(env);
+	    if (port > 0)
+		comc_port = port;
+	}
+
+	sprintf(intbuf, "%d", comc_port);
+	unsetenv("comconsole_port");
+	env_setenv("comconsole_port", EV_VOLATILE, intbuf, comc_port_set,
+	    env_nounset);
+
+	env = getenv("comconsole_pcidev");
+	if (env != NULL) {
+	    locator = comc_parse_pcidev(env);
+	    if (locator != 0)
+		    comc_pcidev_handle(locator);
+	}
+
+	unsetenv("comconsole_pcidev");
+	env_setenv("comconsole_pcidev", EV_VOLATILE, env, comc_pcidev_set,
 	    env_nounset);
     }
 }
@@ -111,7 +146,7 @@
 	return 0;
     comc_started = 1;
 
-    comc_setup(comc_curspeed);
+    comc_setup(comc_curspeed, comc_port);
 
     return(0);
 }
@@ -122,8 +157,8 @@
     int wait;
 
     for (wait = COMC_TXWAIT; wait > 0; wait--)
-        if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
-	    outb(COMPORT + com_data, (u_char)c);
+        if (inb(comc_port + com_lsr) & LSR_TXRDY) {
+	    outb(comc_port + com_data, (u_char)c);
 	    break;
 	}
 }
@@ -131,13 +166,13 @@
 static int
 comc_getchar(void)
 {
-    return(comc_ischar() ? inb(COMPORT + com_data) : -1);
+    return(comc_ischar() ? inb(comc_port + com_data) : -1);
 }
 
 static int
 comc_ischar(void)
 {
-    return(inb(COMPORT + com_lsr) & LSR_RXRDY);
+    return(inb(comc_port + com_lsr) & LSR_RXRDY);
 }
 
 static int
@@ -145,13 +180,33 @@
 {
     int speed;
 
-    if (value == NULL || (speed = comc_parsespeed(value)) <= 0) {
+    if (value == NULL || (speed = comc_parseint(value)) <= 0) {
 	printf("Invalid speed\n");
 	return (CMD_ERROR);
     }
 
     if (comc_started && comc_curspeed != speed)
-	comc_setup(speed);
+	comc_setup(speed, comc_port);
+
+    env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
+
+    return (CMD_OK);
+}
+
+static int
+comc_port_set(struct env_var *ev, int flags, const void *value)
+{
+    int port;
+
+    if (value == NULL || (port = comc_parseint(value)) <= 0) {
+	printf("Invalid port\n");
+	return (CMD_ERROR);
+    }
+
+    if (comc_started && comc_port != port) {
+	comc_setup(comc_curspeed, port);
+	set_hw_console_hint();
+    }
 
     env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
 
@@ -159,24 +214,126 @@
 }
 
 static void
-comc_setup(int speed)
+set_hw_console_hint(void)
+{
+	char intbuf[64];
+
+	unsetenv("hw.uart.console");
+	sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed);
+	env_setenv("hw.uart.console", EV_VOLATILE, intbuf,
+	    env_noset, env_nounset);
+}
+
+/*
+ * Input: bus:dev:func[:bar]. If bar is not specified, it is 0x10.
+ * Output: bar[24:16] bus[15:8] dev[7:3] func[2:0]
+ */
+static uint32_t
+comc_parse_pcidev(const char *string)
+{
+	char *p, *p1;
+	uint8_t bus, dev, func, bar;
+	uint32_t locator;
+	int pres;
+
+	pres = strtol(string, &p, 0);
+	if (p == string || *p != ':' || pres < 0 )
+		return (0);
+	bus = pres;
+	p1 = ++p;
+
+	pres = strtol(p1, &p, 0);
+	if (p == string || *p != ':' || pres < 0 )
+		return (0);
+	dev = pres;
+	p1 = ++p;
+
+	pres = strtol(p1, &p, 0);
+	if (p == string || (*p != ':' && *p != '\0') || pres < 0 )
+		return (0);
+	func = pres;
+
+	if (*p == ':') {
+		p1 = ++p;
+		pres = strtol(p1, &p, 0);
+		if (p == string || *p != '\0' || pres <= 0 )
+			return (0);
+		bar = pres;
+	} else
+		bar = 0x10;
+
+	locator = (bar << 16) | biospci_locator(bus, dev, func);
+	return (locator);
+}
+
+static int
+comc_pcidev_handle(uint32_t locator)
+{
+	char intbuf[64];
+	uint32_t port;
+
+	if (biospci_read_config(locator & 0xffff,
+				(locator & 0xff0000) >> 16, 2, &port) == -1) {
+		printf("Cannot read bar at 0x%x\n", locator);
+		return (CMD_ERROR);
+	}
+	if (!PCI_BAR_IO(port)) {
+		printf("Memory bar at 0x%x\n", locator);
+		return (CMD_ERROR);
+	}
+        port &= PCIM_BAR_IO_BASE;
+
+	sprintf(intbuf, "%d", port);
+	unsetenv("comconsole_port");
+	env_setenv("comconsole_port", EV_VOLATILE, intbuf,
+		   comc_port_set, env_nounset);
+
+	comc_setup(comc_curspeed, port);
+	set_hw_console_hint();
+	comc_locator = locator;
+
+	return (CMD_OK);
+}
+
+static int
+comc_pcidev_set(struct env_var *ev, int flags, const void *value)
+{
+	uint32_t locator;
+	int error;
+
+	if (value == NULL || (locator = comc_parse_pcidev(value)) <= 0) {
+		printf("Invalid pcidev\n");
+		return (CMD_ERROR);
+	}
+	if (comc_started && comc_locator != locator) {
+		error = comc_pcidev_handle(locator);
+		if (error != CMD_OK)
+			return (error);
+	}
+	env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
+	return (CMD_OK);
+}
+
+static void
+comc_setup(int speed, int port)
 {
 
     comc_curspeed = speed;
+    comc_port = port;
 
-    outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
-    outb(COMPORT + com_dlbl, COMC_BPS(speed) & 0xff);
-    outb(COMPORT + com_dlbh, COMC_BPS(speed) >> 8);
-    outb(COMPORT + com_cfcr, COMC_FMT);
-    outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
+    outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT);
+    outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff);
+    outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);
+    outb(comc_port + com_cfcr, COMC_FMT);
+    outb(comc_port + com_mcr, MCR_RTS | MCR_DTR);
 
     do
-        inb(COMPORT + com_data);
-    while (inb(COMPORT + com_lsr) & LSR_RXRDY);
+        inb(comc_port + com_data);
+    while (inb(comc_port + com_lsr) & LSR_RXRDY);
 }
 
 static int
-comc_parsespeed(const char *speedstr)
+comc_parseint(const char *speedstr)
 {
     char *p;
     int speed;
@@ -196,13 +353,13 @@
 	u_char	dlbl;
 	u_char	cfcr;
 
-	cfcr = inb(COMPORT + com_cfcr);
-	outb(COMPORT + com_cfcr, CFCR_DLAB | cfcr);
+	cfcr = inb(comc_port + com_cfcr);
+	outb(comc_port + com_cfcr, CFCR_DLAB | cfcr);
 
-	dlbl = inb(COMPORT + com_dlbl);
-	dlbh = inb(COMPORT + com_dlbh);
+	dlbl = inb(comc_port + com_dlbl);
+	dlbh = inb(comc_port + com_dlbh);
 
-	outb(COMPORT + com_cfcr, cfcr);
+	outb(comc_port + com_cfcr, cfcr);
 
 	divisor = dlbh << 8 | dlbl;
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/i386/libi386/libi386.h
--- a/head/sys/boot/i386/libi386/libi386.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/i386/libi386/libi386.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/boot/i386/libi386/libi386.h 226748 2011-10-25 19:54:06Z jhb $
+ * $FreeBSD: head/sys/boot/i386/libi386/libi386.h 229435 2012-01-03 22:36:12Z kib $
  */
 
 
@@ -97,6 +97,7 @@
 int biospci_find_devclass(uint32_t class, int index, uint32_t *locator);
 int biospci_write_config(uint32_t locator, int offset, int width, uint32_t val);
 int biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val);
+uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function);
 
 void	biosacpi_detect(void);
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/ofw/common/main.c
--- a/head/sys/boot/ofw/common/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/ofw/common/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/boot/ofw/common/main.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <stand.h>
 #include "openfirm.h"
@@ -133,7 +133,7 @@
 	printf("Memory: %lldKB\n", memsize() / 1024);
 
 	OF_getprop(chosen, "bootpath", bootpath, 64);
-	ch = index(bootpath, ':');
+	ch = strchr(bootpath, ':');
 	*ch = '\0';
 	printf("Booted from: %s\n", bootpath);
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/ofw/libofw/ofw_net.c
--- a/head/sys/boot/ofw/libofw/ofw_net.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/ofw/libofw/ofw_net.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/boot/ofw/libofw/ofw_net.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -185,7 +185,7 @@
 	int		pathlen;
 
 	pathlen = OF_getprop(chosen, "bootpath", path, 64);
-	if ((ch = index(path, ':')) != NULL)
+	if ((ch = strchr(path, ':')) != NULL)
 		*ch = '\0';
 	netdev = OF_finddevice(path);
 #ifdef __sparc64__
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/pc98/boot2/boot1.S
--- a/head/sys/boot/pc98/boot2/boot1.S	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/pc98/boot2/boot1.S	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/boot/pc98/boot2/boot1.S 229462 2012-01-04 03:49:41Z nyan $
  */
 
 /* Memory Locations */
@@ -219,7 +219,7 @@
 		jc read_load
 		and $0xff7f,%si		/* SCSI MO */
 		mov %di,%cx
-		shr $16,%di
+		shr $16,%edi
 		mov %di,%dx
 		jmp read_load
 read_fd:	or $0xd000,%si
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/pc98/libpc98/comconsole.c
--- a/head/sys/boot/pc98/libpc98/comconsole.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/pc98/libpc98/comconsole.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,12 +24,13 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/boot/pc98/libpc98/comconsole.c 229463 2012-01-04 03:54:30Z nyan $");
 
 #include <stand.h>
 #include <bootstrap.h>
 #include <machine/cpufunc.h>
 #include <dev/ic/ns16550.h>
+#include <dev/pci/pcireg.h>
 #include "libi386.h"
 
 #define COMC_FMT	0x3		/* 8N1 */
@@ -49,14 +50,23 @@
 static void	comc_putchar(int c);
 static int	comc_getchar(void);
 static int	comc_getspeed(void);
+static void	set_hw_console_hint(void);
 static int	comc_ischar(void);
-static int	comc_parsespeed(const char *string);
-static void	comc_setup(int speed);
+static int	comc_parseint(const char *string);
+static uint32_t comc_parse_pcidev(const char *string);
+static int	comc_pcidev_set(struct env_var *ev, int flags,
+		    const void *value);
+static int	comc_pcidev_handle(uint32_t locator);
+static int	comc_port_set(struct env_var *ev, int flags,
+		    const void *value);
+static void	comc_setup(int speed, int port);
 static int	comc_speed_set(struct env_var *ev, int flags,
 		    const void *value);
 
 static int	comc_started;
 static int	comc_curspeed;
+static int	comc_port = COMPORT;
+static uint32_t	comc_locator;
 
 struct console comconsole = {
     "comconsole",
@@ -72,9 +82,10 @@
 static void
 comc_probe(struct console *cp)
 {
-    char speedbuf[16];
-    char *cons, *speedenv;
-    int speed;
+    char intbuf[16];
+    char *cons, *env;
+    int speed, port;
+    uint32_t locator;
 
     /* XXX check the BIOS equipment list? */
     cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
@@ -90,16 +101,40 @@
 	    getenv("boot_multicons") != NULL) {
 		comc_curspeed = comc_getspeed();
 	}
-	speedenv = getenv("comconsole_speed");
-	if (speedenv != NULL) {
-	    speed = comc_parsespeed(speedenv);
+
+	env = getenv("comconsole_speed");
+	if (env != NULL) {
+	    speed = comc_parseint(env);
 	    if (speed > 0)
 		comc_curspeed = speed;
 	}
 
-	sprintf(speedbuf, "%d", comc_curspeed);
+	sprintf(intbuf, "%d", comc_curspeed);
 	unsetenv("comconsole_speed");
-	env_setenv("comconsole_speed", EV_VOLATILE, speedbuf, comc_speed_set,
+	env_setenv("comconsole_speed", EV_VOLATILE, intbuf, comc_speed_set,
+	    env_nounset);
+
+	env = getenv("comconsole_port");
+	if (env != NULL) {
+	    port = comc_parseint(env);
+	    if (port > 0)
+		comc_port = port;
+	}
+
+	sprintf(intbuf, "%d", comc_port);
+	unsetenv("comconsole_port");
+	env_setenv("comconsole_port", EV_VOLATILE, intbuf, comc_port_set,
+	    env_nounset);
+
+	env = getenv("comconsole_pcidev");
+	if (env != NULL) {
+	    locator = comc_parse_pcidev(env);
+	    if (locator != 0)
+		    comc_pcidev_handle(locator);
+	}
+
+	unsetenv("comconsole_pcidev");
+	env_setenv("comconsole_pcidev", EV_VOLATILE, env, comc_pcidev_set,
 	    env_nounset);
     }
 }
@@ -111,7 +146,7 @@
 	return 0;
     comc_started = 1;
 
-    comc_setup(comc_curspeed);
+    comc_setup(comc_curspeed, comc_port);
 
     return(0);
 }
@@ -122,8 +157,8 @@
     int wait;
 
     for (wait = COMC_TXWAIT; wait > 0; wait--)
-        if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
-	    outb(COMPORT + com_data, (u_char)c);
+        if (inb(comc_port + com_lsr) & LSR_TXRDY) {
+	    outb(comc_port + com_data, (u_char)c);
 	    break;
 	}
 }
@@ -131,13 +166,13 @@
 static int
 comc_getchar(void)
 {
-    return(comc_ischar() ? inb(COMPORT + com_data) : -1);
+    return(comc_ischar() ? inb(comc_port + com_data) : -1);
 }
 
 static int
 comc_ischar(void)
 {
-    return(inb(COMPORT + com_lsr) & LSR_RXRDY);
+    return(inb(comc_port + com_lsr) & LSR_RXRDY);
 }
 
 static int
@@ -145,13 +180,33 @@
 {
     int speed;
 
-    if (value == NULL || (speed = comc_parsespeed(value)) <= 0) {
+    if (value == NULL || (speed = comc_parseint(value)) <= 0) {
 	printf("Invalid speed\n");
 	return (CMD_ERROR);
     }
 
     if (comc_started && comc_curspeed != speed)
-	comc_setup(speed);
+	comc_setup(speed, comc_port);
+
+    env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
+
+    return (CMD_OK);
+}
+
+static int
+comc_port_set(struct env_var *ev, int flags, const void *value)
+{
+    int port;
+
+    if (value == NULL || (port = comc_parseint(value)) <= 0) {
+	printf("Invalid port\n");
+	return (CMD_ERROR);
+    }
+
+    if (comc_started && comc_port != port) {
+	comc_setup(comc_curspeed, port);
+	set_hw_console_hint();
+    }
 
     env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
 
@@ -159,24 +214,126 @@
 }
 
 static void
-comc_setup(int speed)
+set_hw_console_hint(void)
+{
+	char intbuf[64];
+
+	unsetenv("hw.uart.console");
+	sprintf(intbuf, "io:%d,br:%d", comc_port, comc_curspeed);
+	env_setenv("hw.uart.console", EV_VOLATILE, intbuf,
+	    env_noset, env_nounset);
+}
+
+/*
+ * Input: bus:dev:func[:bar]. If bar is not specified, it is 0x10.
+ * Output: bar[24:16] bus[15:8] dev[7:3] func[2:0]
+ */
+static uint32_t
+comc_parse_pcidev(const char *string)
+{
+	char *p, *p1;
+	uint8_t bus, dev, func, bar;
+	uint32_t locator;
+	int pres;
+
+	pres = strtol(string, &p, 0);
+	if (p == string || *p != ':' || pres < 0 )
+		return (0);
+	bus = pres;
+	p1 = ++p;
+
+	pres = strtol(p1, &p, 0);
+	if (p == string || *p != ':' || pres < 0 )
+		return (0);
+	dev = pres;
+	p1 = ++p;
+
+	pres = strtol(p1, &p, 0);
+	if (p == string || (*p != ':' && *p != '\0') || pres < 0 )
+		return (0);
+	func = pres;
+
+	if (*p == ':') {
+		p1 = ++p;
+		pres = strtol(p1, &p, 0);
+		if (p == string || *p != '\0' || pres <= 0 )
+			return (0);
+		bar = pres;
+	} else
+		bar = 0x10;
+
+	locator = (bar << 16) | biospci_locator(bus, dev, func);
+	return (locator);
+}
+
+static int
+comc_pcidev_handle(uint32_t locator)
+{
+	char intbuf[64];
+	uint32_t port;
+
+	if (biospci_read_config(locator & 0xffff,
+				(locator & 0xff0000) >> 16, 2, &port) == -1) {
+		printf("Cannot read bar at 0x%x\n", locator);
+		return (CMD_ERROR);
+	}
+	if (!PCI_BAR_IO(port)) {
+		printf("Memory bar at 0x%x\n", locator);
+		return (CMD_ERROR);
+	}
+        port &= PCIM_BAR_IO_BASE;
+
+	sprintf(intbuf, "%d", port);
+	unsetenv("comconsole_port");
+	env_setenv("comconsole_port", EV_VOLATILE, intbuf,
+		   comc_port_set, env_nounset);
+
+	comc_setup(comc_curspeed, port);
+	set_hw_console_hint();
+	comc_locator = locator;
+
+	return (CMD_OK);
+}
+
+static int
+comc_pcidev_set(struct env_var *ev, int flags, const void *value)
+{
+	uint32_t locator;
+	int error;
+
+	if (value == NULL || (locator = comc_parse_pcidev(value)) <= 0) {
+		printf("Invalid pcidev\n");
+		return (CMD_ERROR);
+	}
+	if (comc_started && comc_locator != locator) {
+		error = comc_pcidev_handle(locator);
+		if (error != CMD_OK)
+			return (error);
+	}
+	env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL);
+	return (CMD_OK);
+}
+
+static void
+comc_setup(int speed, int port)
 {
 
     comc_curspeed = speed;
+    comc_port = port;
 
-    outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
-    outb(COMPORT + com_dlbl, COMC_BPS(speed) & 0xff);
-    outb(COMPORT + com_dlbh, COMC_BPS(speed) >> 8);
-    outb(COMPORT + com_cfcr, COMC_FMT);
-    outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
+    outb(comc_port + com_cfcr, CFCR_DLAB | COMC_FMT);
+    outb(comc_port + com_dlbl, COMC_BPS(speed) & 0xff);
+    outb(comc_port + com_dlbh, COMC_BPS(speed) >> 8);
+    outb(comc_port + com_cfcr, COMC_FMT);
+    outb(comc_port + com_mcr, MCR_RTS | MCR_DTR);
 
     do
-        inb(COMPORT + com_data);
-    while (inb(COMPORT + com_lsr) & LSR_RXRDY);
+        inb(comc_port + com_data);
+    while (inb(comc_port + com_lsr) & LSR_RXRDY);
 }
 
 static int
-comc_parsespeed(const char *speedstr)
+comc_parseint(const char *speedstr)
 {
     char *p;
     int speed;
@@ -196,13 +353,13 @@
 	u_char	dlbl;
 	u_char	cfcr;
 
-	cfcr = inb(COMPORT + com_cfcr);
-	outb(COMPORT + com_cfcr, CFCR_DLAB | cfcr);
+	cfcr = inb(comc_port + com_cfcr);
+	outb(comc_port + com_cfcr, CFCR_DLAB | cfcr);
 
-	dlbl = inb(COMPORT + com_dlbl);
-	dlbh = inb(COMPORT + com_dlbh);
+	dlbl = inb(comc_port + com_dlbl);
+	dlbh = inb(comc_port + com_dlbh);
 
-	outb(COMPORT + com_cfcr, cfcr);
+	outb(comc_port + com_cfcr, cfcr);
 
 	divisor = dlbh << 8 | dlbl;
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/boot/userboot/libstand/Makefile
--- a/head/sys/boot/userboot/libstand/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/boot/userboot/libstand/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/sys/boot/userboot/libstand/Makefile 223695 2011-06-30 16:08:56Z dfr $
+# $FreeBSD: head/sys/boot/userboot/libstand/Makefile 229368 2012-01-03 07:14:01Z ed $
 # Originally from	$NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $
 #
 # Notes:
@@ -60,10 +60,10 @@
 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "powerpc" || \
 	${MACHINE_CPUARCH} == "sparc64" || ${MACHINE_CPUARCH} == "amd64" || \
 	${MACHINE_CPUARCH} == "arm"
-SRCS+=	bcmp.c bcopy.c bzero.c ffs.c index.c memccpy.c memchr.c memcmp.c \
-        memcpy.c memmove.c memset.c qdivrem.c rindex.c strcat.c strchr.c \
-        strcmp.c strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c \
-	strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
+SRCS+=	bcmp.c bcopy.c bzero.c ffs.c memccpy.c memchr.c memcmp.c memcpy.c \
+	memmove.c memset.c qdivrem.c strcat.c strchr.c strcmp.c strcpy.c \
+	strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
+	strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
 .endif
 .if ${MACHINE_CPUARCH} == "arm"
 .PATH: ${LIBC}/arm/gen
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/cam/ata/ata_da.c
--- a/head/sys/cam/ata/ata_da.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/cam/ata/ata_da.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/ata/ata_da.c 228819 2011-12-22 23:50:31Z mav $");
+__FBSDID("$FreeBSD: head/sys/cam/ata/ata_da.c 229288 2012-01-02 17:02:45Z mav $");
 
 #include "opt_ada.h"
 #include "opt_ata.h"
@@ -493,13 +493,6 @@
 
 		if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
 			xpt_print(periph->path, "Synchronize cache failed\n");
-
-		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-			cam_release_devq(ccb->ccb_h.path,
-					 /*relsim_flags*/0,
-					 /*reduction*/0,
-					 /*timeout*/0,
-					 /*getcount_only*/0);
 		xpt_release_ccb(ccb);
 	}
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/cam/scsi/scsi_cd.c
--- a/head/sys/cam/scsi/scsi_cd.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/cam/scsi/scsi_cd.c	Thu Jan 05 13:30:52 2012 +0200
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_cd.c 228847 2011-12-23 19:53:28Z mav $");
+__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_cd.c 229395 2012-01-03 17:04:09Z mav $");
 
 #include "opt_cd.h"
 
@@ -2685,6 +2685,16 @@
 		error = cdsetspeed(periph, CDR_MAX_SPEED, *(u_int32_t *)addr);
 		cam_periph_unlock(periph);
 		break;
+	case CDRIOCGETBLOCKSIZE:
+		*(int *)addr = softc->params.blksize;
+		break;
+	case CDRIOCSETBLOCKSIZE:
+		if (*(int *)addr <= 0) {
+			error = EINVAL;
+			break;
+		}
+		softc->disk->d_sectorsize = softc->params.blksize = *(int *)addr;
+		break;
 	case DVDIOCSENDKEY:
 	case DVDIOCREPORTKEY: {
 		struct dvd_authinfo *authinfo;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/cam/scsi/scsi_da.c
--- a/head/sys/cam/scsi/scsi_da.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/cam/scsi/scsi_da.c	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_da.c 228851 2011-12-23 20:59:13Z mav $");
+__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_da.c 229288 2012-01-02 17:02:45Z mav $");
 
 #include <sys/param.h>
 
@@ -990,13 +990,6 @@
 			}
 		}
 
-		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-			cam_release_devq(ccb->ccb_h.path,
-					 /*relsim_flags*/0,
-					 /*reduction*/0,
-					 /*timeout*/0,
-					 /*getcount_only*/0);
-
 		xpt_release_ccb(ccb);
 
 	}
@@ -2281,14 +2274,6 @@
 				  /*cam_flags*/CAM_RETRY_SELTO,
 				  sense_flags,
 				  softc->disk->d_devstat);
-
-		if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-			cam_release_devq(ccb->ccb_h.path,
-				 /*relsim_flags*/0,
-				 /*reduction*/0,
-				 /*timeout*/0,
-				 /*getcount_only*/0);
-
 		if (error == 0)
 			goto rc16ok;
 
@@ -2326,14 +2311,6 @@
 				  /*cam_flags*/CAM_RETRY_SELTO,
 				  sense_flags,
 				  softc->disk->d_devstat);
-
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path,
-				 /*relsim_flags*/0,
-				 /*reduction*/0,
-				 /*timeout*/0,
-				 /*getcount_only*/0);
-
 	if (error == 0) {
 		block_len = scsi_4btoul(rcap->length);
 		maxsector = scsi_4btoul(rcap->addr);
@@ -2360,14 +2337,6 @@
 				  /*cam_flags*/CAM_RETRY_SELTO,
 				  sense_flags,
 				  softc->disk->d_devstat);
-
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path,
-				 /*relsim_flags*/0,
-				 /*reduction*/0,
-				 /*timeout*/0,
-				 /*getcount_only*/0);
-
 	if (error == 0) {
 rc16ok:
 		block_len = scsi_4btoul(rcaplong->length);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/cam/scsi/scsi_sa.c
--- a/head/sys/cam/scsi/scsi_sa.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/cam/scsi/scsi_sa.c	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_sa.c 228344 2011-12-08 03:20:48Z eadler $");
+__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_sa.c 229288 2012-01-02 17:02:45Z mav $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -1853,14 +1853,12 @@
 		    MSG_SIMPLE_Q_TAG, SSD_FULL_SIZE, IO_TIMEOUT);
 		error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 		    softc->device_stats);
-		QFRLS(ccb);
 		if (error == ENXIO) {
 			softc->flags &= ~SA_FLAG_TAPE_MOUNTED;
 			scsi_test_unit_ready(&ccb->csio, 0, sadone,
 			    MSG_SIMPLE_Q_TAG, SSD_FULL_SIZE, IO_TIMEOUT);
 			error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 			    softc->device_stats);
-			QFRLS(ccb);
 		} else if (error) {
 			/*
 			 * We don't need to freeze the tape because we
@@ -1882,7 +1880,6 @@
 		    MSG_SIMPLE_Q_TAG, SSD_FULL_SIZE, IO_TIMEOUT);
 		error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 		    softc->device_stats);
-		QFRLS(ccb);
 	}
 
 	if ((softc->flags & SA_FLAG_TAPE_MOUNTED) == 0) {
@@ -1905,7 +1902,6 @@
 		    FALSE, FALSE, 1, SSD_FULL_SIZE, REWIND_TIMEOUT);
 		error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 		    softc->device_stats);
-		QFRLS(ccb);
 
 		/*
 		 * In case this doesn't work, do a REWIND instead
@@ -1915,7 +1911,6 @@
 			    FALSE, SSD_FULL_SIZE, REWIND_TIMEOUT);
 			error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 				softc->device_stats);
-			QFRLS(ccb);
 		}
 		if (error) {
 			xpt_release_ccb(ccb);
@@ -1945,13 +1940,11 @@
 			    IO_TIMEOUT);
 			(void) cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 			    softc->device_stats);
-			QFRLS(ccb);
 			scsi_rewind(&ccb->csio, 1, sadone, MSG_SIMPLE_Q_TAG,
 			    FALSE, SSD_FULL_SIZE, REWIND_TIMEOUT);
 			error = cam_periph_runccb(ccb, saerror, CAM_RETRY_SELTO,
 			    SF_NO_PRINT | SF_RETRY_UA,
 			    softc->device_stats);
-			QFRLS(ccb);
 			if (error) {
 				xpt_print(periph->path,
 				    "unable to rewind after test read\n");
@@ -1969,7 +1962,6 @@
 		error = cam_periph_runccb(ccb, saerror, CAM_RETRY_SELTO,
 		    SF_NO_PRINT | SF_RETRY_UA, softc->device_stats);
 
-		QFRLS(ccb);
 		xpt_release_ccb(ccb);
 
 		if (error != 0) {
@@ -2580,7 +2572,6 @@
 
 	error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 	    softc->device_stats);
-	QFRLS(ccb);
 
 	status = ccb->ccb_h.status & CAM_STATUS_MASK;
 
@@ -2644,7 +2635,6 @@
 
 		error = cam_periph_runccb(ccb, saerror, 0, SF_NO_PRINT,
 		    softc->device_stats);
-		QFRLS(ccb);
 
 		if (error != 0)
 			goto sagetparamsexit;
@@ -2956,7 +2946,6 @@
 
 	error = cam_periph_runccb(ccb, saerror, 0,
 	    sense_flags, softc->device_stats);
-	QFRLS(ccb);
 
 	if (CAM_DEBUGGED(periph->path, CAM_DEBUG_INFO)) {
 		int idx;
@@ -3014,7 +3003,6 @@
 		ccb->ccb_h.retry_count = 1;
 		cam_periph_runccb(ccb, saerror, 0, sense_flags,
 		    softc->device_stats);
-		QFRLS(ccb);
 	}
 
 	xpt_release_ccb(ccb);
@@ -3072,7 +3060,6 @@
 	    SSD_FULL_SIZE, SCSIOP_TIMEOUT);
 
 	error = cam_periph_runccb(ccb, saerror, 0, sf, softc->device_stats);
-	QFRLS(ccb);
 	if (error == 0) {
 		if (action == PR_ALLOW)
 			softc->flags &= ~SA_FLAG_TAPE_LOCKED;
@@ -3102,9 +3089,6 @@
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
 
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
-
 	xpt_release_ccb(ccb);
 	if (error == 0)
 		softc->fileno = softc->blkno = (daddr_t) 0;
@@ -3138,9 +3122,6 @@
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
 
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
-
 	xpt_release_ccb(ccb);
 
 	/*
@@ -3212,9 +3193,6 @@
 
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
-
 	if (error == 0 && nmarks) {
 		struct sa_softc *softc = (struct sa_softc *)periph->softc;
 		nwm = nmarks - softc->last_ctl_resid;
@@ -3265,8 +3243,6 @@
 	softc->dsreg = MTIO_DSREG_RBSY;
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
 
 	if (error == 0) {
 		if (loc.flags & SA_RPOS_UNCERTAIN) {
@@ -3306,8 +3282,6 @@
 	softc->dsreg = MTIO_DSREG_POS;
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, 0);
 	xpt_release_ccb(ccb);
 	/*
 	 * Note relative file && block number position as now unknown.
@@ -3335,8 +3309,6 @@
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
 
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
 	xpt_release_ccb(ccb);
 	if (error == 0)
 		softc->fileno = softc->blkno = (daddr_t) 0;
@@ -3362,7 +3334,6 @@
 	error = cam_periph_runccb(ccb, saerror, 0,
 	    SF_RETRY_UA | SF_NO_PRINT, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
-	QFRLS(ccb);
 	xpt_release_ccb(ccb);
 
 	/*
@@ -3394,7 +3365,6 @@
 	softc->dsreg = (load)? MTIO_DSREG_LD : MTIO_DSREG_UNL;
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
-	QFRLS(ccb);
 	xpt_release_ccb(ccb);
 
 	if (error || load == 0)
@@ -3425,8 +3395,6 @@
 	error = cam_periph_runccb(ccb, saerror, 0, 0, softc->device_stats);
 	softc->dsreg = MTIO_DSREG_REST;
 
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
 	xpt_release_ccb(ccb);
 	return (error);
 }
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/cam/scsi/scsi_ses.c
--- a/head/sys/cam/scsi/scsi_ses.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/cam/scsi/scsi_ses.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_ses.c 227489 2011-11-13 17:06:33Z eadler $");
+__FBSDID("$FreeBSD: head/sys/cam/scsi/scsi_ses.c 229288 2012-01-02 17:02:45Z mav $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -679,8 +679,6 @@
 	bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
 
 	error = cam_periph_runccb(ccb, seserror, SES_CFLAGS, SES_FLAGS, NULL);
-	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
-		cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
 	if (error) {
 		if (dptr) {
 			*dlenp = dlen;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
--- a/head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -2698,7 +2698,7 @@
 		links = zp->z_links + 1;
 	else
 		links = zp->z_links;
-	vap->va_nlink = MIN(links, UINT32_MAX);	/* nlink_t limit! */
+	vap->va_nlink = MIN(links, LINK_MAX);	/* nlink_t limit! */
 	vap->va_size = zp->z_size;
 #ifdef sun
 	vap->va_rdev = vp->v_rdev;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/compat/linux/linux_ioctl.c
--- a/head/sys/compat/linux/linux_ioctl.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/compat/linux/linux_ioctl.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 #include "opt_compat.h"
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ioctl.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ioctl.c 229402 2012-01-03 18:49:39Z dim $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2182,7 +2182,7 @@
 
 	CURVNET_SET(TD_TO_VNET(td));
 	/* handle the 'request buffer size' case */
-	if (ifc.ifc_buf == PTROUT(NULL)) {
+	if ((l_uintptr_t)ifc.ifc_buf == PTROUT(NULL)) {
 		ifc.ifc_len = 0;
 		IFNET_RLOCK();
 		TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/conf/files
--- a/head/sys/conf/files	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/conf/files	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/sys/conf/files 228994 2011-12-30 13:16:59Z dim $
+# $FreeBSD: head/sys/conf/files 229537 2012-01-04 23:39:11Z ray $
 #
 # The long compile-with and dependency lines are required because of
 # limitations in config: backslash-newline doesn't work in strings, and
@@ -50,7 +50,7 @@
 aic79xx_reg_print.o		optional ahd pci ahd_reg_pretty_print	   \
 	compile-with	"${NORMAL_C}"					   \
 	no-implicit-rule local
-emu10k1-alsa%diked.h		optional snd_emu10k1 | snd_emu10kx	   \
+emu10k1-alsa%diked.h		optional snd_emu10kx	   \
 	dependency	"$S/tools/sound/emu10k1-mkalsa.sh $S/gnu/dev/sound/pci/emu10k1-alsa.h" \
 	compile-with	"CC='${CC}' AWK=${AWK} sh $S/tools/sound/emu10k1-mkalsa.sh $S/gnu/dev/sound/pci/emu10k1-alsa.h emu10k1-alsa%diked.h" \
 	no-obj no-implicit-rule before-depend				   \
@@ -1743,9 +1743,7 @@
 	warning "kernel contains GPL contaminated csaimg.h header"
 dev/sound/pci/csapcm.c		optional snd_csa pci
 dev/sound/pci/ds1.c		optional snd_ds1 pci
-dev/sound/pci/emu10k1.c		optional snd_emu10k1 pci \
-	dependency "emu10k1-alsa%diked.h" \
-	warning "kernel contains GPL contaminated emu10k1 headers"
+dev/sound/pci/emu10k1.c		optional snd_emu10k1 pci
 dev/sound/pci/emu10kx.c		optional snd_emu10kx pci \
 	dependency "emu10k1-alsa%diked.h" \
 	dependency "p16v-alsa%diked.h" \
@@ -2294,21 +2292,21 @@
 geom/shsec/g_shsec.c		optional geom_shsec
 geom/stripe/g_stripe.c		optional geom_stripe
 geom/uncompress/g_uncompress.c	optional geom_uncompress
-contrib/xz-embedded/xz_malloc.c		optional geom_uncompress \
-	dependency "$S/contrib/xz-embedded/*.[ch]" \
-	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/"
-contrib/xz-embedded/xz_crc32.c		optional geom_uncompress \
-	dependency "$S/contrib/xz-embedded/*.[ch]" \
-	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/"
-contrib/xz-embedded/xz_dec_bcj.c	optional geom_uncompress \
-	dependency "$S/contrib/xz-embedded/*.[ch]" \
-	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/"
-contrib/xz-embedded/xz_dec_lzma2.c	optional geom_uncompress \
-	dependency "$S/contrib/xz-embedded/*.[ch]" \
-	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/"
-contrib/xz-embedded/xz_dec_stream.c	optional geom_uncompress \
-	dependency "$S/contrib/xz-embedded/*.[ch]" \
-	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/"
+contrib/xz-embedded/freebsd/xz_malloc.c	\
+	optional xz_embedded | geom_uncompress \
+	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
+contrib/xz-embedded/linux/lib/xz/xz_crc32.c \
+	optional xz_embedded | geom_uncompress \
+	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
+contrib/xz-embedded/linux/lib/xz/xz_dec_bcj.c \
+	optional xz_embedded | geom_uncompress \
+	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
+contrib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c \
+	optional xz_embedded | geom_uncompress \
+	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
+contrib/xz-embedded/linux/lib/xz/xz_dec_stream.c \
+	optional xz_embedded | geom_uncompress \
+	compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
 geom/uzip/g_uzip.c		optional geom_uzip
 geom/virstor/binstream.c	optional geom_virstor
 geom/virstor/g_virstor.c	optional geom_virstor
@@ -2592,21 +2590,20 @@
 libkern/iconv_ucs.c		optional libiconv
 libkern/iconv_xlat.c		optional libiconv
 libkern/iconv_xlat16.c		optional libiconv
-libkern/index.c			standard
 libkern/inet_aton.c		standard
 libkern/inet_ntoa.c		standard
 libkern/inet_ntop.c		standard
 libkern/inet_pton.c		standard
 libkern/mcount.c		optional profiling-routine
+libkern/memcchr.c		standard
 libkern/memcmp.c		standard
 libkern/qsort.c			standard
 libkern/qsort_r.c		standard
 libkern/random.c		standard
-libkern/rindex.c		standard
 libkern/scanc.c			standard
-libkern/skpc.c			standard
 libkern/strcasecmp.c		standard
 libkern/strcat.c		standard
+libkern/strchr.c		standard
 libkern/strcmp.c		standard
 libkern/strcpy.c		standard
 libkern/strcspn.c		standard
@@ -2617,6 +2614,7 @@
 libkern/strncmp.c		standard
 libkern/strncpy.c		standard
 libkern/strnlen.c		standard
+libkern/strrchr.c		standard
 libkern/strsep.c		standard
 libkern/strspn.c		standard
 libkern/strstr.c		standard
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/conf/kern.pre.mk
--- a/head/sys/conf/kern.pre.mk	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/conf/kern.pre.mk	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/sys/conf/kern.pre.mk 228868 2011-12-24 19:01:31Z dim $
+# $FreeBSD: head/sys/conf/kern.pre.mk 229353 2012-01-03 00:22:08Z gjb $
 
 # Part of a unified Makefile for building kernels.  This part contains all
 # of the definitions that need to be before %BEFORE_DEPEND.
@@ -71,10 +71,10 @@
 # ... and the same for the NgATM stuff
 INCLUDES+= -I$S/contrib/ngatm
 
-# .. and the same for twa
+# ... and the same for twa
 INCLUDES+= -I$S/dev/twa
 
-# ...  and XFS
+# ... and the same for XFS
 INCLUDES+= -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs
 
 # ... and the same for cxgb and cxgbe
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/conf/options
--- a/head/sys/conf/options	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/conf/options	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/sys/conf/options 227924 2011-11-24 07:32:52Z adrian $
+# $FreeBSD: head/sys/conf/options 229537 2012-01-04 23:39:11Z ray $
 #
 #        On the handling of kernel options
 #
@@ -112,6 +112,7 @@
 GEOM_SHSEC	opt_geom.h
 GEOM_STRIPE	opt_geom.h
 GEOM_SUNLABEL	opt_geom.h
+GEOM_UNCOMPRESS	opt_geom.h
 GEOM_UZIP	opt_geom.h
 GEOM_VIRSTOR	opt_geom.h
 GEOM_VOL	opt_geom.h
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/freebsd/xz_config.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/freebsd/xz_config.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2010-2012 Aleksandr Rybalko
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __FREEBSD_XZ_CONFIG_H__
+#define __FREEBSD_XZ_CONFIG_H__
+
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include <contrib/xz-embedded/linux/include/linux/xz.h>
+#include "xz_malloc.h"
+
+#define	XZ_DEC_SINGLE	1
+#define	XZ_PREBOOT	1
+
+#undef	XZ_EXTERN
+#define	XZ_EXTERN	extern
+
+#undef	STATIC
+#define	STATIC
+
+#undef	INIT
+#define	INIT
+
+#undef	bool
+#undef	true
+#undef	false
+#define	bool	int
+#define	true	1
+#define	false	0
+
+#define	kmalloc(size, flags)	xz_malloc(size)
+#define	kfree(ptr)		xz_free(ptr)
+#define	vmalloc(size)		xz_malloc(size)
+#define	vfree(ptr)		xz_free(ptr)
+
+#define	memeq(a, b, size)	(memcmp((a), (b), (size)) == 0)
+#define	memzero(buf, size)	bzero((buf), (size))
+
+#ifndef min
+#	define min(x, y)	MIN((x), (y))
+#endif
+
+#define	min_t(type, x, y)	min((x), (y))
+
+#define	get_le32(ptr)	le32toh(*(const uint32_t *)(ptr))
+
+#endif /* __FREEBSD_XZ_CONFIG_H__ */
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/freebsd/xz_malloc.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/freebsd/xz_malloc.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2010-2012 Aleksandr Rybalko
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include "xz_malloc.h"
+
+/* Wraper for XZ decompressor memmory pool */
+
+static MALLOC_DEFINE(XZ_DEC, "XZ_DEC", "XZ decompressor data");
+
+void *
+xz_malloc(unsigned long size)
+{
+	void *addr;
+
+	addr = malloc(size, XZ_DEC, M_NOWAIT);
+	return (addr);
+}
+
+void
+xz_free(void *addr)
+{
+
+	free(addr, XZ_DEC);
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/freebsd/xz_malloc.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/freebsd/xz_malloc.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2010-2012 Aleksandr Rybalko
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __XZ_MALLOC_H__
+#define __XZ_MALLOC_H__
+
+extern void *xz_malloc(unsigned long size);
+extern void xz_free(void *addr);
+
+#endif /* __XZ_MALLOC_H__ */
+
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/Documentation/xz.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/Documentation/xz.txt	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,122 @@
+
+XZ data compression in Linux
+============================
+
+Introduction
+
+    XZ is a general purpose data compression format with high compression
+    ratio and relatively fast decompression. The primary compression
+    algorithm (filter) is LZMA2. Additional filters can be used to improve
+    compression ratio even further. E.g. Branch/Call/Jump (BCJ) filters
+    improve compression ratio of executable data.
+
+    The XZ decompressor in Linux is called XZ Embedded. It supports
+    the LZMA2 filter and optionally also BCJ filters. CRC32 is supported
+    for integrity checking. The home page of XZ Embedded is at
+    <http://tukaani.org/xz/embedded.html>, where you can find the
+    latest version and also information about using the code outside
+    the Linux kernel.
+
+    For userspace, XZ Utils provide a zlib-like compression library
+    and a gzip-like command line tool. XZ Utils can be downloaded from
+    <http://tukaani.org/xz/>.
+
+XZ related components in the kernel
+
+    The xz_dec module provides XZ decompressor with single-call (buffer
+    to buffer) and multi-call (stateful) APIs. The usage of the xz_dec
+    module is documented in include/linux/xz.h.
+
+    The xz_dec_test module is for testing xz_dec. xz_dec_test is not
+    useful unless you are hacking the XZ decompressor. xz_dec_test
+    allocates a char device major dynamically to which one can write
+    .xz files from userspace. The decompressed output is thrown away.
+    Keep an eye on dmesg to see diagnostics printed by xz_dec_test.
+    See the xz_dec_test source code for the details.
+
+    For decompressing the kernel image, initramfs, and initrd, there
+    is a wrapper function in lib/decompress_unxz.c. Its API is the
+    same as in other decompress_*.c files, which is defined in
+    include/linux/decompress/generic.h.
+
+    scripts/xz_wrap.sh is a wrapper for the xz command line tool found
+    from XZ Utils. The wrapper sets compression options to values suitable
+    for compressing the kernel image.
+
+    For kernel makefiles, two commands are provided for use with
+    $(call if_needed). The kernel image should be compressed with
+    $(call if_needed,xzkern) which will use a BCJ filter and a big LZMA2
+    dictionary. It will also append a four-byte trailer containing the
+    uncompressed size of the file, which is needed by the boot code.
+    Other things should be compressed with $(call if_needed,xzmisc)
+    which will use no BCJ filter and 1 MiB LZMA2 dictionary.
+
+Notes on compression options
+
+    Since the XZ Embedded supports only streams with no integrity check or
+    CRC32, make sure that you don't use some other integrity check type
+    when encoding files that are supposed to be decoded by the kernel. With
+    liblzma, you need to use either LZMA_CHECK_NONE or LZMA_CHECK_CRC32
+    when encoding. With the xz command line tool, use --check=none or
+    --check=crc32.
+
+    Using CRC32 is strongly recommended unless there is some other layer
+    which will verify the integrity of the uncompressed data anyway.
+    Double checking the integrity would probably be waste of CPU cycles.
+    Note that the headers will always have a CRC32 which will be validated
+    by the decoder; you can only change the integrity check type (or
+    disable it) for the actual uncompressed data.
+
+    In userspace, LZMA2 is typically used with dictionary sizes of several
+    megabytes. The decoder needs to have the dictionary in RAM, thus big
+    dictionaries cannot be used for files that are intended to be decoded
+    by the kernel. 1 MiB is probably the maximum reasonable dictionary
+    size for in-kernel use (maybe more is OK for initramfs). The presets
+    in XZ Utils may not be optimal when creating files for the kernel,
+    so don't hesitate to use custom settings. Example:
+
+        xz --check=crc32 --lzma2=dict=512KiB inputfile
+
+    An exception to above dictionary size limitation is when the decoder
+    is used in single-call mode. Decompressing the kernel itself is an
+    example of this situation. In single-call mode, the memory usage
+    doesn't depend on the dictionary size, and it is perfectly fine to
+    use a big dictionary: for maximum compression, the dictionary should
+    be at least as big as the uncompressed data itself.
+
+Future plans
+
+    Creating a limited XZ encoder may be considered if people think it is
+    useful. LZMA2 is slower to compress than e.g. Deflate or LZO even at
+    the fastest settings, so it isn't clear if LZMA2 encoder is wanted
+    into the kernel.
+
+    Support for limited random-access reading is planned for the
+    decompression code. I don't know if it could have any use in the
+    kernel, but I know that it would be useful in some embedded projects
+    outside the Linux kernel.
+
+Conformance to the .xz file format specification
+
+    There are a couple of corner cases where things have been simplified
+    at expense of detecting errors as early as possible. These should not
+    matter in practice all, since they don't cause security issues. But
+    it is good to know this if testing the code e.g. with the test files
+    from XZ Utils.
+
+Reporting bugs
+
+    Before reporting a bug, please check that it's not fixed already
+    at upstream. See <http://tukaani.org/xz/embedded.html> to get the
+    latest code.
+
+    Report bugs to <lasse.collin at tukaani.org> or visit #tukaani on
+    Freenode and talk to Larhzu. I don't actively read LKML or other
+    kernel-related mailing lists, so if there's something I should know,
+    you should email to me personally or use IRC.
+
+    Don't bother Igor Pavlov with questions about the XZ implementation
+    in the kernel or about XZ Utils. While these two implementations
+    include essential code that is directly based on Igor Pavlov's code,
+    these implementations aren't maintained nor supported by him.
+
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/include/linux/decompress/unxz.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/include/linux/decompress/unxz.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,19 @@
+/*
+ * Wrapper for decompressing XZ-compressed kernel, initramfs, and initrd
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef DECOMPRESS_UNXZ_H
+#define DECOMPRESS_UNXZ_H
+
+int unxz(unsigned char *in, int in_size,
+	 int (*fill)(void *dest, unsigned int size),
+	 int (*flush)(void *src, unsigned int size),
+	 unsigned char *out, int *in_used,
+	 void (*error)(char *x));
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/include/linux/xz.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/include/linux/xz.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,278 @@
+/*
+ * XZ decompressor
+ *
+ * Authors: Lasse Collin <lasse.collin at tukaani.org>
+ *          Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef XZ_H
+#define XZ_H
+
+#ifdef __KERNEL__
+#	include <linux/stddef.h>
+#	include <linux/types.h>
+#else
+#ifdef __FreeBSD__
+#	include <sys/stddef.h>
+#	include <sys/types.h>
+#else
+#	include <stddef.h>
+#	include <stdint.h>
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* In Linux, this is used to make extern functions static when needed. */
+#ifndef XZ_EXTERN
+#	define XZ_EXTERN extern
+#endif
+
+/**
+ * enum xz_mode - Operation mode
+ *
+ * @XZ_SINGLE:              Single-call mode. This uses less RAM than
+ *                          than multi-call modes, because the LZMA2
+ *                          dictionary doesn't need to be allocated as
+ *                          part of the decoder state. All required data
+ *                          structures are allocated at initialization,
+ *                          so xz_dec_run() cannot return XZ_MEM_ERROR.
+ * @XZ_PREALLOC:            Multi-call mode with preallocated LZMA2
+ *                          dictionary buffer. All data structures are
+ *                          allocated at initialization, so xz_dec_run()
+ *                          cannot return XZ_MEM_ERROR.
+ * @XZ_DYNALLOC:            Multi-call mode. The LZMA2 dictionary is
+ *                          allocated once the required size has been
+ *                          parsed from the stream headers. If the
+ *                          allocation fails, xz_dec_run() will return
+ *                          XZ_MEM_ERROR.
+ *
+ * It is possible to enable support only for a subset of the above
+ * modes at compile time by defining XZ_DEC_SINGLE, XZ_DEC_PREALLOC,
+ * or XZ_DEC_DYNALLOC. The xz_dec kernel module is always compiled
+ * with support for all operation modes, but the preboot code may
+ * be built with fewer features to minimize code size.
+ */
+enum xz_mode {
+	XZ_SINGLE,
+	XZ_PREALLOC,
+	XZ_DYNALLOC
+};
+
+/**
+ * enum xz_ret - Return codes
+ * @XZ_OK:                  Everything is OK so far. More input or more
+ *                          output space is required to continue. This
+ *                          return code is possible only in multi-call mode
+ *                          (XZ_PREALLOC or XZ_DYNALLOC).
+ * @XZ_STREAM_END:          Operation finished successfully.
+ * @XZ_UNSUPPORTED_CHECK:   Integrity check type is not supported. Decoding
+ *                          is still possible in multi-call mode by simply
+ *                          calling xz_dec_run() again.
+ *                          Note that this return value is used only if
+ *                          XZ_DEC_ANY_CHECK was defined at build time,
+ *                          which is not used in the kernel. Unsupported
+ *                          check types return XZ_OPTIONS_ERROR if
+ *                          XZ_DEC_ANY_CHECK was not defined at build time.
+ * @XZ_MEM_ERROR:           Allocating memory failed. This return code is
+ *                          possible only if the decoder was initialized
+ *                          with XZ_DYNALLOC. The amount of memory that was
+ *                          tried to be allocated was no more than the
+ *                          dict_max argument given to xz_dec_init().
+ * @XZ_MEMLIMIT_ERROR:      A bigger LZMA2 dictionary would be needed than
+ *                          allowed by the dict_max argument given to
+ *                          xz_dec_init(). This return value is possible
+ *                          only in multi-call mode (XZ_PREALLOC or
+ *                          XZ_DYNALLOC); the single-call mode (XZ_SINGLE)
+ *                          ignores the dict_max argument.
+ * @XZ_FORMAT_ERROR:        File format was not recognized (wrong magic
+ *                          bytes).
+ * @XZ_OPTIONS_ERROR:       This implementation doesn't support the requested
+ *                          compression options. In the decoder this means
+ *                          that the header CRC32 matches, but the header
+ *                          itself specifies something that we don't support.
+ * @XZ_DATA_ERROR:          Compressed data is corrupt.
+ * @XZ_BUF_ERROR:           Cannot make any progress. Details are slightly
+ *                          different between multi-call and single-call
+ *                          mode; more information below.
+ *
+ * In multi-call mode, XZ_BUF_ERROR is returned when two consecutive calls
+ * to XZ code cannot consume any input and cannot produce any new output.
+ * This happens when there is no new input available, or the output buffer
+ * is full while at least one output byte is still pending. Assuming your
+ * code is not buggy, you can get this error only when decoding a compressed
+ * stream that is truncated or otherwise corrupt.
+ *
+ * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer
+ * is too small or the compressed input is corrupt in a way that makes the
+ * decoder produce more output than the caller expected. When it is
+ * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR
+ * is used instead of XZ_BUF_ERROR.
+ */
+enum xz_ret {
+	XZ_OK,
+	XZ_STREAM_END,
+	XZ_UNSUPPORTED_CHECK,
+	XZ_MEM_ERROR,
+	XZ_MEMLIMIT_ERROR,
+	XZ_FORMAT_ERROR,
+	XZ_OPTIONS_ERROR,
+	XZ_DATA_ERROR,
+	XZ_BUF_ERROR
+};
+
+/**
+ * struct xz_buf - Passing input and output buffers to XZ code
+ * @in:         Beginning of the input buffer. This may be NULL if and only
+ *              if in_pos is equal to in_size.
+ * @in_pos:     Current position in the input buffer. This must not exceed
+ *              in_size.
+ * @in_size:    Size of the input buffer
+ * @out:        Beginning of the output buffer. This may be NULL if and only
+ *              if out_pos is equal to out_size.
+ * @out_pos:    Current position in the output buffer. This must not exceed
+ *              out_size.
+ * @out_size:   Size of the output buffer
+ *
+ * Only the contents of the output buffer from out[out_pos] onward, and
+ * the variables in_pos and out_pos are modified by the XZ code.
+ */
+struct xz_buf {
+	const uint8_t *in;
+	size_t in_pos;
+	size_t in_size;
+
+	uint8_t *out;
+	size_t out_pos;
+	size_t out_size;
+};
+
+/**
+ * struct xz_dec - Opaque type to hold the XZ decoder state
+ */
+struct xz_dec;
+
+/**
+ * xz_dec_init() - Allocate and initialize a XZ decoder state
+ * @mode:       Operation mode
+ * @dict_max:   Maximum size of the LZMA2 dictionary (history buffer) for
+ *              multi-call decoding. This is ignored in single-call mode
+ *              (mode == XZ_SINGLE). LZMA2 dictionary is always 2^n bytes
+ *              or 2^n + 2^(n-1) bytes (the latter sizes are less common
+ *              in practice), so other values for dict_max don't make sense.
+ *              In the kernel, dictionary sizes of 64 KiB, 128 KiB, 256 KiB,
+ *              512 KiB, and 1 MiB are probably the only reasonable values,
+ *              except for kernel and initramfs images where a bigger
+ *              dictionary can be fine and useful.
+ *
+ * Single-call mode (XZ_SINGLE): xz_dec_run() decodes the whole stream at
+ * once. The caller must provide enough output space or the decoding will
+ * fail. The output space is used as the dictionary buffer, which is why
+ * there is no need to allocate the dictionary as part of the decoder's
+ * internal state.
+ *
+ * Because the output buffer is used as the workspace, streams encoded using
+ * a big dictionary are not a problem in single-call mode. It is enough that
+ * the output buffer is big enough to hold the actual uncompressed data; it
+ * can be smaller than the dictionary size stored in the stream headers.
+ *
+ * Multi-call mode with preallocated dictionary (XZ_PREALLOC): dict_max bytes
+ * of memory is preallocated for the LZMA2 dictionary. This way there is no
+ * risk that xz_dec_run() could run out of memory, since xz_dec_run() will
+ * never allocate any memory. Instead, if the preallocated dictionary is too
+ * small for decoding the given input stream, xz_dec_run() will return
+ * XZ_MEMLIMIT_ERROR. Thus, it is important to know what kind of data will be
+ * decoded to avoid allocating excessive amount of memory for the dictionary.
+ *
+ * Multi-call mode with dynamically allocated dictionary (XZ_DYNALLOC):
+ * dict_max specifies the maximum allowed dictionary size that xz_dec_run()
+ * may allocate once it has parsed the dictionary size from the stream
+ * headers. This way excessive allocations can be avoided while still
+ * limiting the maximum memory usage to a sane value to prevent running the
+ * system out of memory when decompressing streams from untrusted sources.
+ *
+ * On success, xz_dec_init() returns a pointer to struct xz_dec, which is
+ * ready to be used with xz_dec_run(). If memory allocation fails,
+ * xz_dec_init() returns NULL.
+ */
+XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max);
+
+/**
+ * xz_dec_run() - Run the XZ decoder
+ * @s:          Decoder state allocated using xz_dec_init()
+ * @b:          Input and output buffers
+ *
+ * The possible return values depend on build options and operation mode.
+ * See enum xz_ret for details.
+ *
+ * Note that if an error occurs in single-call mode (return value is not
+ * XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the
+ * contents of the output buffer from b->out[b->out_pos] onward are
+ * undefined. This is true even after XZ_BUF_ERROR, because with some filter
+ * chains, there may be a second pass over the output buffer, and this pass
+ * cannot be properly done if the output buffer is truncated. Thus, you
+ * cannot give the single-call decoder a too small buffer and then expect to
+ * get that amount valid data from the beginning of the stream. You must use
+ * the multi-call decoder if you don't want to uncompress the whole stream.
+ */
+XZ_EXTERN enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b);
+
+/**
+ * xz_dec_reset() - Reset an already allocated decoder state
+ * @s:          Decoder state allocated using xz_dec_init()
+ *
+ * This function can be used to reset the multi-call decoder state without
+ * freeing and reallocating memory with xz_dec_end() and xz_dec_init().
+ *
+ * In single-call mode, xz_dec_reset() is always called in the beginning of
+ * xz_dec_run(). Thus, explicit call to xz_dec_reset() is useful only in
+ * multi-call mode.
+ */
+XZ_EXTERN void xz_dec_reset(struct xz_dec *s);
+
+/**
+ * xz_dec_end() - Free the memory allocated for the decoder state
+ * @s:          Decoder state allocated using xz_dec_init(). If s is NULL,
+ *              this function does nothing.
+ */
+XZ_EXTERN void xz_dec_end(struct xz_dec *s);
+
+/*
+ * Standalone build (userspace build or in-kernel build for boot time use)
+ * needs a CRC32 implementation. For normal in-kernel use, kernel's own
+ * CRC32 module is used instead, and users of this module don't need to
+ * care about the functions below.
+ */
+#ifndef XZ_INTERNAL_CRC32
+#	ifdef __KERNEL__
+#		define XZ_INTERNAL_CRC32 0
+#	else
+#		define XZ_INTERNAL_CRC32 1
+#	endif
+#endif
+
+#if XZ_INTERNAL_CRC32
+/*
+ * This must be called before any other xz_* function to initialize
+ * the CRC32 lookup table.
+ */
+XZ_EXTERN void xz_crc32_init(void);
+
+/*
+ * Update CRC32 value using the polynomial from IEEE-802.3. To start a new
+ * calculation, the third argument must be zero. To continue the calculation,
+ * the previously returned value is passed as the third argument.
+ */
+XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/decompress_unxz.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/decompress_unxz.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,397 @@
+/*
+ * Wrapper for decompressing XZ-compressed kernel, initramfs, and initrd
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+/*
+ * Important notes about in-place decompression
+ *
+ * At least on x86, the kernel is decompressed in place: the compressed data
+ * is placed to the end of the output buffer, and the decompressor overwrites
+ * most of the compressed data. There must be enough safety margin to
+ * guarantee that the write position is always behind the read position.
+ *
+ * The safety margin for XZ with LZMA2 or BCJ+LZMA2 is calculated below.
+ * Note that the margin with XZ is bigger than with Deflate (gzip)!
+ *
+ * The worst case for in-place decompression is that the beginning of
+ * the file is compressed extremely well, and the rest of the file is
+ * uncompressible. Thus, we must look for worst-case expansion when the
+ * compressor is encoding uncompressible data.
+ *
+ * The structure of the .xz file in case of a compresed kernel is as follows.
+ * Sizes (as bytes) of the fields are in parenthesis.
+ *
+ *    Stream Header (12)
+ *    Block Header:
+ *      Block Header (8-12)
+ *      Compressed Data (N)
+ *      Block Padding (0-3)
+ *      CRC32 (4)
+ *    Index (8-20)
+ *    Stream Footer (12)
+ *
+ * Normally there is exactly one Block, but let's assume that there are
+ * 2-4 Blocks just in case. Because Stream Header and also Block Header
+ * of the first Block don't make the decompressor produce any uncompressed
+ * data, we can ignore them from our calculations. Block Headers of possible
+ * additional Blocks have to be taken into account still. With these
+ * assumptions, it is safe to assume that the total header overhead is
+ * less than 128 bytes.
+ *
+ * Compressed Data contains LZMA2 or BCJ+LZMA2 encoded data. Since BCJ
+ * doesn't change the size of the data, it is enough to calculate the
+ * safety margin for LZMA2.
+ *
+ * LZMA2 stores the data in chunks. Each chunk has a header whose size is
+ * a maximum of 6 bytes, but to get round 2^n numbers, let's assume that
+ * the maximum chunk header size is 8 bytes. After the chunk header, there
+ * may be up to 64 KiB of actual payload in the chunk. Often the payload is
+ * quite a bit smaller though; to be safe, let's assume that an average
+ * chunk has only 32 KiB of payload.
+ *
+ * The maximum uncompressed size of the payload is 2 MiB. The minimum
+ * uncompressed size of the payload is in practice never less than the
+ * payload size itself. The LZMA2 format would allow uncompressed size
+ * to be less than the payload size, but no sane compressor creates such
+ * files. LZMA2 supports storing uncompressible data in uncompressed form,
+ * so there's never a need to create payloads whose uncompressed size is
+ * smaller than the compressed size.
+ *
+ * The assumption, that the uncompressed size of the payload is never
+ * smaller than the payload itself, is valid only when talking about
+ * the payload as a whole. It is possible that the payload has parts where
+ * the decompressor consumes more input than it produces output. Calculating
+ * the worst case for this would be tricky. Instead of trying to do that,
+ * let's simply make sure that the decompressor never overwrites any bytes
+ * of the payload which it is currently reading.
+ *
+ * Now we have enough information to calculate the safety margin. We need
+ *   - 128 bytes for the .xz file format headers;
+ *   - 8 bytes per every 32 KiB of uncompressed size (one LZMA2 chunk header
+ *     per chunk, each chunk having average payload size of 32 KiB); and
+ *   - 64 KiB (biggest possible LZMA2 chunk payload size) to make sure that
+ *     the decompressor never overwrites anything from the LZMA2 chunk
+ *     payload it is currently reading.
+ *
+ * We get the following formula:
+ *
+ *    safety_margin = 128 + uncompressed_size * 8 / 32768 + 65536
+ *                  = 128 + (uncompressed_size >> 12) + 65536
+ *
+ * For comparision, according to arch/x86/boot/compressed/misc.c, the
+ * equivalent formula for Deflate is this:
+ *
+ *    safety_margin = 18 + (uncompressed_size >> 12) + 32768
+ *
+ * Thus, when updating Deflate-only in-place kernel decompressor to
+ * support XZ, the fixed overhead has to be increased from 18+32768 bytes
+ * to 128+65536 bytes.
+ */
+
+/*
+ * STATIC is defined to "static" if we are being built for kernel
+ * decompression (pre-boot code). <linux/decompress/mm.h> will define
+ * STATIC to empty if it wasn't already defined. Since we will need to
+ * know later if we are being used for kernel decompression, we define
+ * XZ_PREBOOT here.
+ */
+#ifdef STATIC
+#	define XZ_PREBOOT
+#endif
+#ifdef __KERNEL__
+#	include <linux/decompress/mm.h>
+#endif
+#define XZ_EXTERN STATIC
+
+#ifndef XZ_PREBOOT
+#	include <linux/slab.h>
+#	include <linux/xz.h>
+#else
+/*
+ * Use the internal CRC32 code instead of kernel's CRC32 module, which
+ * is not available in early phase of booting.
+ */
+#define XZ_INTERNAL_CRC32 1
+
+/*
+ * For boot time use, we enable only the BCJ filter of the current
+ * architecture or none if no BCJ filter is available for the architecture.
+ */
+#ifdef CONFIG_X86
+#	define XZ_DEC_X86
+#endif
+#ifdef CONFIG_PPC
+#	define XZ_DEC_POWERPC
+#endif
+#ifdef CONFIG_ARM
+#	define XZ_DEC_ARM
+#endif
+#ifdef CONFIG_IA64
+#	define XZ_DEC_IA64
+#endif
+#ifdef CONFIG_SPARC
+#	define XZ_DEC_SPARC
+#endif
+
+/*
+ * This will get the basic headers so that memeq() and others
+ * can be defined.
+ */
+#include "xz/xz_private.h"
+
+/*
+ * Replace the normal allocation functions with the versions from
+ * <linux/decompress/mm.h>. vfree() needs to support vfree(NULL)
+ * when XZ_DYNALLOC is used, but the pre-boot free() doesn't support it.
+ * Workaround it here because the other decompressors don't need it.
+ */
+#undef kmalloc
+#undef kfree
+#undef vmalloc
+#undef vfree
+#define kmalloc(size, flags) malloc(size)
+#define kfree(ptr) free(ptr)
+#define vmalloc(size) malloc(size)
+#define vfree(ptr) do { if (ptr != NULL) free(ptr); } while (0)
+
+/*
+ * FIXME: Not all basic memory functions are provided in architecture-specific
+ * files (yet). We define our own versions here for now, but this should be
+ * only a temporary solution.
+ *
+ * memeq and memzero are not used much and any remotely sane implementation
+ * is fast enough. memcpy/memmove speed matters in multi-call mode, but
+ * the kernel image is decompressed in single-call mode, in which only
+ * memcpy speed can matter and only if there is a lot of uncompressible data
+ * (LZMA2 stores uncompressible chunks in uncompressed form). Thus, the
+ * functions below should just be kept small; it's probably not worth
+ * optimizing for speed.
+ */
+
+#ifndef memeq
+static bool memeq(const void *a, const void *b, size_t size)
+{
+	const uint8_t *x = a;
+	const uint8_t *y = b;
+	size_t i;
+
+	for (i = 0; i < size; ++i)
+		if (x[i] != y[i])
+			return false;
+
+	return true;
+}
+#endif
+
+#ifndef memzero
+static void memzero(void *buf, size_t size)
+{
+	uint8_t *b = buf;
+	uint8_t *e = b + size;
+
+	while (b != e)
+		*b++ = '\0';
+}
+#endif
+
+#ifndef memmove
+/* Not static to avoid a conflict with the prototype in the Linux headers. */
+void *memmove(void *dest, const void *src, size_t size)
+{
+	uint8_t *d = dest;
+	const uint8_t *s = src;
+	size_t i;
+
+	if (d < s) {
+		for (i = 0; i < size; ++i)
+			d[i] = s[i];
+	} else if (d > s) {
+		i = size;
+		while (i-- > 0)
+			d[i] = s[i];
+	}
+
+	return dest;
+}
+#endif
+
+/*
+ * Since we need memmove anyway, would use it as memcpy too.
+ * Commented out for now to avoid breaking things.
+ */
+/*
+#ifndef memcpy
+#	define memcpy memmove
+#endif
+*/
+
+#include "xz/xz_crc32.c"
+#include "xz/xz_dec_stream.c"
+#include "xz/xz_dec_lzma2.c"
+#include "xz/xz_dec_bcj.c"
+
+#endif /* XZ_PREBOOT */
+
+/* Size of the input and output buffers in multi-call mode */
+#define XZ_IOBUF_SIZE 4096
+
+/*
+ * This function implements the API defined in <linux/decompress/generic.h>.
+ *
+ * This wrapper will automatically choose single-call or multi-call mode
+ * of the native XZ decoder API. The single-call mode can be used only when
+ * both input and output buffers are available as a single chunk, i.e. when
+ * fill() and flush() won't be used.
+ */
+STATIC int INIT unxz(unsigned char *in, int in_size,
+		     int (*fill)(void *dest, unsigned int size),
+		     int (*flush)(void *src, unsigned int size),
+		     unsigned char *out, int *in_used,
+		     void (*error)(char *x))
+{
+	struct xz_buf b;
+	struct xz_dec *s;
+	enum xz_ret ret;
+	bool must_free_in = false;
+
+#if XZ_INTERNAL_CRC32
+	xz_crc32_init();
+#endif
+
+	if (in_used != NULL)
+		*in_used = 0;
+
+	if (fill == NULL && flush == NULL)
+		s = xz_dec_init(XZ_SINGLE, 0);
+	else
+		s = xz_dec_init(XZ_DYNALLOC, (uint32_t)-1);
+
+	if (s == NULL)
+		goto error_alloc_state;
+
+	if (flush == NULL) {
+		b.out = out;
+		b.out_size = (size_t)-1;
+	} else {
+		b.out_size = XZ_IOBUF_SIZE;
+		b.out = malloc(XZ_IOBUF_SIZE);
+		if (b.out == NULL)
+			goto error_alloc_out;
+	}
+
+	if (in == NULL) {
+		must_free_in = true;
+		in = malloc(XZ_IOBUF_SIZE);
+		if (in == NULL)
+			goto error_alloc_in;
+	}
+
+	b.in = in;
+	b.in_pos = 0;
+	b.in_size = in_size;
+	b.out_pos = 0;
+
+	if (fill == NULL && flush == NULL) {
+		ret = xz_dec_run(s, &b);
+	} else {
+		do {
+			if (b.in_pos == b.in_size && fill != NULL) {
+				if (in_used != NULL)
+					*in_used += b.in_pos;
+
+				b.in_pos = 0;
+
+				in_size = fill(in, XZ_IOBUF_SIZE);
+				if (in_size < 0) {
+					/*
+					 * This isn't an optimal error code
+					 * but it probably isn't worth making
+					 * a new one either.
+					 */
+					ret = XZ_BUF_ERROR;
+					break;
+				}
+
+				b.in_size = in_size;
+			}
+
+			ret = xz_dec_run(s, &b);
+
+			if (flush != NULL && (b.out_pos == b.out_size
+					|| (ret != XZ_OK && b.out_pos > 0))) {
+				/*
+				 * Setting ret here may hide an error
+				 * returned by xz_dec_run(), but probably
+				 * it's not too bad.
+				 */
+				if (flush(b.out, b.out_pos) != (int)b.out_pos)
+					ret = XZ_BUF_ERROR;
+
+				b.out_pos = 0;
+			}
+		} while (ret == XZ_OK);
+
+		if (must_free_in)
+			free(in);
+
+		if (flush != NULL)
+			free(b.out);
+	}
+
+	if (in_used != NULL)
+		*in_used += b.in_pos;
+
+	xz_dec_end(s);
+
+	switch (ret) {
+	case XZ_STREAM_END:
+		return 0;
+
+	case XZ_MEM_ERROR:
+		/* This can occur only in multi-call mode. */
+		error("XZ decompressor ran out of memory");
+		break;
+
+	case XZ_FORMAT_ERROR:
+		error("Input is not in the XZ format (wrong magic bytes)");
+		break;
+
+	case XZ_OPTIONS_ERROR:
+		error("Input was encoded with settings that are not "
+				"supported by this XZ decoder");
+		break;
+
+	case XZ_DATA_ERROR:
+	case XZ_BUF_ERROR:
+		error("XZ-compressed data is corrupt");
+		break;
+
+	default:
+		error("Bug in the XZ decompressor");
+		break;
+	}
+
+	return -1;
+
+error_alloc_in:
+	if (flush != NULL)
+		free(b.out);
+
+error_alloc_out:
+	xz_dec_end(s);
+
+error_alloc_state:
+	error("XZ decompressor ran out of memory");
+	return -1;
+}
+
+/*
+ * This macro is used by architecture-specific files to decompress
+ * the kernel image.
+ */
+#define decompress unxz
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/Kconfig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/Kconfig	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,59 @@
+config XZ_DEC
+	tristate "XZ decompression support"
+	select CRC32
+	help
+	  LZMA2 compression algorithm and BCJ filters are supported using
+	  the .xz file format as the container. For integrity checking,
+	  CRC32 is supported. See Documentation/xz.txt for more information.
+
+config XZ_DEC_X86
+	bool "x86 BCJ filter decoder" if EXPERT
+	default y
+	depends on XZ_DEC
+	select XZ_DEC_BCJ
+
+config XZ_DEC_POWERPC
+	bool "PowerPC BCJ filter decoder" if EXPERT
+	default y
+	depends on XZ_DEC
+	select XZ_DEC_BCJ
+
+config XZ_DEC_IA64
+	bool "IA-64 BCJ filter decoder" if EXPERT
+	default y
+	depends on XZ_DEC
+	select XZ_DEC_BCJ
+
+config XZ_DEC_ARM
+	bool "ARM BCJ filter decoder" if EXPERT
+	default y
+	depends on XZ_DEC
+	select XZ_DEC_BCJ
+
+config XZ_DEC_ARMTHUMB
+	bool "ARM-Thumb BCJ filter decoder" if EXPERT
+	default y
+	depends on XZ_DEC
+	select XZ_DEC_BCJ
+
+config XZ_DEC_SPARC
+	bool "SPARC BCJ filter decoder" if EXPERT
+	default y
+	depends on XZ_DEC
+	select XZ_DEC_BCJ
+
+config XZ_DEC_BCJ
+	bool
+	default n
+
+config XZ_DEC_TEST
+	tristate "XZ decompressor tester"
+	default n
+	depends on XZ_DEC
+	help
+	  This allows passing .xz files to the in-kernel XZ decoder via
+	  a character special file. It calculates CRC32 of the decompressed
+	  data and writes diagnostics to the system log.
+
+	  Unless you are developing the XZ decoder, you don't need this
+	  and should say N.
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,5 @@
+obj-$(CONFIG_XZ_DEC) += xz_dec.o
+xz_dec-y := xz_dec_syms.o xz_dec_stream.o xz_dec_lzma2.o
+xz_dec-$(CONFIG_XZ_DEC_BCJ) += xz_dec_bcj.o
+
+obj-$(CONFIG_XZ_DEC_TEST) += xz_dec_test.o
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_crc32.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_crc32.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,59 @@
+/*
+ * CRC32 using the polynomial from IEEE-802.3
+ *
+ * Authors: Lasse Collin <lasse.collin at tukaani.org>
+ *          Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+/*
+ * This is not the fastest implementation, but it is pretty compact.
+ * The fastest versions of xz_crc32() on modern CPUs without hardware
+ * accelerated CRC instruction are 3-5 times as fast as this version,
+ * but they are bigger and use more memory for the lookup table.
+ */
+
+#include "xz_private.h"
+
+/*
+ * STATIC_RW_DATA is used in the pre-boot environment on some architectures.
+ * See <linux/decompress/mm.h> for details.
+ */
+#ifndef STATIC_RW_DATA
+#	define STATIC_RW_DATA static
+#endif
+
+STATIC_RW_DATA uint32_t xz_crc32_table[256];
+
+XZ_EXTERN void xz_crc32_init(void)
+{
+	const uint32_t poly = 0xEDB88320;
+
+	uint32_t i;
+	uint32_t j;
+	uint32_t r;
+
+	for (i = 0; i < 256; ++i) {
+		r = i;
+		for (j = 0; j < 8; ++j)
+			r = (r >> 1) ^ (poly & ~((r & 1) - 1));
+
+		xz_crc32_table[i] = r;
+	}
+
+	return;
+}
+
+XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
+{
+	crc = ~crc;
+
+	while (size != 0) {
+		crc = xz_crc32_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
+		--size;
+	}
+
+	return ~crc;
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_bcj.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_bcj.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,574 @@
+/*
+ * Branch/Call/Jump (BCJ) filter decoders
+ *
+ * Authors: Lasse Collin <lasse.collin at tukaani.org>
+ *          Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include "xz_private.h"
+
+/*
+ * The rest of the file is inside this ifdef. It makes things a little more
+ * convenient when building without support for any BCJ filters.
+ */
+#ifdef XZ_DEC_BCJ
+
+struct xz_dec_bcj {
+	/* Type of the BCJ filter being used */
+	enum {
+		BCJ_X86 = 4,        /* x86 or x86-64 */
+		BCJ_POWERPC = 5,    /* Big endian only */
+		BCJ_IA64 = 6,       /* Big or little endian */
+		BCJ_ARM = 7,        /* Little endian only */
+		BCJ_ARMTHUMB = 8,   /* Little endian only */
+		BCJ_SPARC = 9       /* Big or little endian */
+	} type;
+
+	/*
+	 * Return value of the next filter in the chain. We need to preserve
+	 * this information across calls, because we must not call the next
+	 * filter anymore once it has returned XZ_STREAM_END.
+	 */
+	enum xz_ret ret;
+
+	/* True if we are operating in single-call mode. */
+	bool single_call;
+
+	/*
+	 * Absolute position relative to the beginning of the uncompressed
+	 * data (in a single .xz Block). We care only about the lowest 32
+	 * bits so this doesn't need to be uint64_t even with big files.
+	 */
+	uint32_t pos;
+
+	/* x86 filter state */
+	uint32_t x86_prev_mask;
+
+	/* Temporary space to hold the variables from struct xz_buf */
+	uint8_t *out;
+	size_t out_pos;
+	size_t out_size;
+
+	struct {
+		/* Amount of already filtered data in the beginning of buf */
+		size_t filtered;
+
+		/* Total amount of data currently stored in buf  */
+		size_t size;
+
+		/*
+		 * Buffer to hold a mix of filtered and unfiltered data. This
+		 * needs to be big enough to hold Alignment + 2 * Look-ahead:
+		 *
+		 * Type         Alignment   Look-ahead
+		 * x86              1           4
+		 * PowerPC          4           0
+		 * IA-64           16           0
+		 * ARM              4           0
+		 * ARM-Thumb        2           2
+		 * SPARC            4           0
+		 */
+		uint8_t buf[16];
+	} temp;
+};
+
+#ifdef XZ_DEC_X86
+/*
+ * This is used to test the most significant byte of a memory address
+ * in an x86 instruction.
+ */
+static inline int bcj_x86_test_msbyte(uint8_t b)
+{
+	return b == 0x00 || b == 0xFF;
+}
+
+static size_t bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	static const bool mask_to_allowed_status[8]
+		= { true, true, true, false, true, false, false, false };
+
+	static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
+
+	size_t i;
+	size_t prev_pos = (size_t)-1;
+	uint32_t prev_mask = s->x86_prev_mask;
+	uint32_t src;
+	uint32_t dest;
+	uint32_t j;
+	uint8_t b;
+
+	if (size <= 4)
+		return 0;
+
+	size -= 4;
+	for (i = 0; i < size; ++i) {
+		if ((buf[i] & 0xFE) != 0xE8)
+			continue;
+
+		prev_pos = i - prev_pos;
+		if (prev_pos > 3) {
+			prev_mask = 0;
+		} else {
+			prev_mask = (prev_mask << (prev_pos - 1)) & 7;
+			if (prev_mask != 0) {
+				b = buf[i + 4 - mask_to_bit_num[prev_mask]];
+				if (!mask_to_allowed_status[prev_mask]
+						|| bcj_x86_test_msbyte(b)) {
+					prev_pos = i;
+					prev_mask = (prev_mask << 1) | 1;
+					continue;
+				}
+			}
+		}
+
+		prev_pos = i;
+
+		if (bcj_x86_test_msbyte(buf[i + 4])) {
+			src = get_unaligned_le32(buf + i + 1);
+			while (true) {
+				dest = src - (s->pos + (uint32_t)i + 5);
+				if (prev_mask == 0)
+					break;
+
+				j = mask_to_bit_num[prev_mask] * 8;
+				b = (uint8_t)(dest >> (24 - j));
+				if (!bcj_x86_test_msbyte(b))
+					break;
+
+				src = dest ^ (((uint32_t)1 << (32 - j)) - 1);
+			}
+
+			dest &= 0x01FFFFFF;
+			dest |= (uint32_t)0 - (dest & 0x01000000);
+			put_unaligned_le32(dest, buf + i + 1);
+			i += 4;
+		} else {
+			prev_mask = (prev_mask << 1) | 1;
+		}
+	}
+
+	prev_pos = i - prev_pos;
+	s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1);
+	return i;
+}
+#endif
+
+#ifdef XZ_DEC_POWERPC
+static size_t bcj_powerpc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	size_t i;
+	uint32_t instr;
+
+	for (i = 0; i + 4 <= size; i += 4) {
+		instr = get_unaligned_be32(buf + i);
+		if ((instr & 0xFC000003) == 0x48000001) {
+			instr &= 0x03FFFFFC;
+			instr -= s->pos + (uint32_t)i;
+			instr &= 0x03FFFFFC;
+			instr |= 0x48000001;
+			put_unaligned_be32(instr, buf + i);
+		}
+	}
+
+	return i;
+}
+#endif
+
+#ifdef XZ_DEC_IA64
+static size_t bcj_ia64(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	static const uint8_t branch_table[32] = {
+		0, 0, 0, 0, 0, 0, 0, 0,
+		0, 0, 0, 0, 0, 0, 0, 0,
+		4, 4, 6, 6, 0, 0, 7, 7,
+		4, 4, 0, 0, 4, 4, 0, 0
+	};
+
+	/*
+	 * The local variables take a little bit stack space, but it's less
+	 * than what LZMA2 decoder takes, so it doesn't make sense to reduce
+	 * stack usage here without doing that for the LZMA2 decoder too.
+	 */
+
+	/* Loop counters */
+	size_t i;
+	size_t j;
+
+	/* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
+	uint32_t slot;
+
+	/* Bitwise offset of the instruction indicated by slot */
+	uint32_t bit_pos;
+
+	/* bit_pos split into byte and bit parts */
+	uint32_t byte_pos;
+	uint32_t bit_res;
+
+	/* Address part of an instruction */
+	uint32_t addr;
+
+	/* Mask used to detect which instructions to convert */
+	uint32_t mask;
+
+	/* 41-bit instruction stored somewhere in the lowest 48 bits */
+	uint64_t instr;
+
+	/* Instruction normalized with bit_res for easier manipulation */
+	uint64_t norm;
+
+	for (i = 0; i + 16 <= size; i += 16) {
+		mask = branch_table[buf[i] & 0x1F];
+		for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
+			if (((mask >> slot) & 1) == 0)
+				continue;
+
+			byte_pos = bit_pos >> 3;
+			bit_res = bit_pos & 7;
+			instr = 0;
+			for (j = 0; j < 6; ++j)
+				instr |= (uint64_t)(buf[i + j + byte_pos])
+						<< (8 * j);
+
+			norm = instr >> bit_res;
+
+			if (((norm >> 37) & 0x0F) == 0x05
+					&& ((norm >> 9) & 0x07) == 0) {
+				addr = (norm >> 13) & 0x0FFFFF;
+				addr |= ((uint32_t)(norm >> 36) & 1) << 20;
+				addr <<= 4;
+				addr -= s->pos + (uint32_t)i;
+				addr >>= 4;
+
+				norm &= ~((uint64_t)0x8FFFFF << 13);
+				norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
+				norm |= (uint64_t)(addr & 0x100000)
+						<< (36 - 20);
+
+				instr &= (1 << bit_res) - 1;
+				instr |= norm << bit_res;
+
+				for (j = 0; j < 6; j++)
+					buf[i + j + byte_pos]
+						= (uint8_t)(instr >> (8 * j));
+			}
+		}
+	}
+
+	return i;
+}
+#endif
+
+#ifdef XZ_DEC_ARM
+static size_t bcj_arm(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	size_t i;
+	uint32_t addr;
+
+	for (i = 0; i + 4 <= size; i += 4) {
+		if (buf[i + 3] == 0xEB) {
+			addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8)
+					| ((uint32_t)buf[i + 2] << 16);
+			addr <<= 2;
+			addr -= s->pos + (uint32_t)i + 8;
+			addr >>= 2;
+			buf[i] = (uint8_t)addr;
+			buf[i + 1] = (uint8_t)(addr >> 8);
+			buf[i + 2] = (uint8_t)(addr >> 16);
+		}
+	}
+
+	return i;
+}
+#endif
+
+#ifdef XZ_DEC_ARMTHUMB
+static size_t bcj_armthumb(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	size_t i;
+	uint32_t addr;
+
+	for (i = 0; i + 4 <= size; i += 2) {
+		if ((buf[i + 1] & 0xF8) == 0xF0
+				&& (buf[i + 3] & 0xF8) == 0xF8) {
+			addr = (((uint32_t)buf[i + 1] & 0x07) << 19)
+					| ((uint32_t)buf[i] << 11)
+					| (((uint32_t)buf[i + 3] & 0x07) << 8)
+					| (uint32_t)buf[i + 2];
+			addr <<= 1;
+			addr -= s->pos + (uint32_t)i + 4;
+			addr >>= 1;
+			buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
+			buf[i] = (uint8_t)(addr >> 11);
+			buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
+			buf[i + 2] = (uint8_t)addr;
+			i += 2;
+		}
+	}
+
+	return i;
+}
+#endif
+
+#ifdef XZ_DEC_SPARC
+static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
+{
+	size_t i;
+	uint32_t instr;
+
+	for (i = 0; i + 4 <= size; i += 4) {
+		instr = get_unaligned_be32(buf + i);
+		if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
+			instr <<= 2;
+			instr -= s->pos + (uint32_t)i;
+			instr >>= 2;
+			instr = ((uint32_t)0x40000000 - (instr & 0x400000))
+					| 0x40000000 | (instr & 0x3FFFFF);
+			put_unaligned_be32(instr, buf + i);
+		}
+	}
+
+	return i;
+}
+#endif
+
+/*
+ * Apply the selected BCJ filter. Update *pos and s->pos to match the amount
+ * of data that got filtered.
+ *
+ * NOTE: This is implemented as a switch statement to avoid using function
+ * pointers, which could be problematic in the kernel boot code, which must
+ * avoid pointers to static data (at least on x86).
+ */
+static void bcj_apply(struct xz_dec_bcj *s,
+		      uint8_t *buf, size_t *pos, size_t size)
+{
+	size_t filtered;
+
+	buf += *pos;
+	size -= *pos;
+
+	switch (s->type) {
+#ifdef XZ_DEC_X86
+	case BCJ_X86:
+		filtered = bcj_x86(s, buf, size);
+		break;
+#endif
+#ifdef XZ_DEC_POWERPC
+	case BCJ_POWERPC:
+		filtered = bcj_powerpc(s, buf, size);
+		break;
+#endif
+#ifdef XZ_DEC_IA64
+	case BCJ_IA64:
+		filtered = bcj_ia64(s, buf, size);
+		break;
+#endif
+#ifdef XZ_DEC_ARM
+	case BCJ_ARM:
+		filtered = bcj_arm(s, buf, size);
+		break;
+#endif
+#ifdef XZ_DEC_ARMTHUMB
+	case BCJ_ARMTHUMB:
+		filtered = bcj_armthumb(s, buf, size);
+		break;
+#endif
+#ifdef XZ_DEC_SPARC
+	case BCJ_SPARC:
+		filtered = bcj_sparc(s, buf, size);
+		break;
+#endif
+	default:
+		/* Never reached but silence compiler warnings. */
+		filtered = 0;
+		break;
+	}
+
+	*pos += filtered;
+	s->pos += filtered;
+}
+
+/*
+ * Flush pending filtered data from temp to the output buffer.
+ * Move the remaining mixture of possibly filtered and unfiltered
+ * data to the beginning of temp.
+ */
+static void bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b)
+{
+	size_t copy_size;
+
+	copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
+	memcpy(b->out + b->out_pos, s->temp.buf, copy_size);
+	b->out_pos += copy_size;
+
+	s->temp.filtered -= copy_size;
+	s->temp.size -= copy_size;
+	memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size);
+}
+
+/*
+ * The BCJ filter functions are primitive in sense that they process the
+ * data in chunks of 1-16 bytes. To hide this issue, this function does
+ * some buffering.
+ */
+XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
+				     struct xz_dec_lzma2 *lzma2,
+				     struct xz_buf *b)
+{
+	size_t out_start;
+
+	/*
+	 * Flush pending already filtered data to the output buffer. Return
+	 * immediatelly if we couldn't flush everything, or if the next
+	 * filter in the chain had already returned XZ_STREAM_END.
+	 */
+	if (s->temp.filtered > 0) {
+		bcj_flush(s, b);
+		if (s->temp.filtered > 0)
+			return XZ_OK;
+
+		if (s->ret == XZ_STREAM_END)
+			return XZ_STREAM_END;
+	}
+
+	/*
+	 * If we have more output space than what is currently pending in
+	 * temp, copy the unfiltered data from temp to the output buffer
+	 * and try to fill the output buffer by decoding more data from the
+	 * next filter in the chain. Apply the BCJ filter on the new data
+	 * in the output buffer. If everything cannot be filtered, copy it
+	 * to temp and rewind the output buffer position accordingly.
+	 *
+	 * This needs to be always run when temp.size == 0 to handle a special
+	 * case where the output buffer is full and the next filter has no
+	 * more output coming but hasn't returned XZ_STREAM_END yet.
+	 */
+	if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
+		out_start = b->out_pos;
+		memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
+		b->out_pos += s->temp.size;
+
+		s->ret = xz_dec_lzma2_run(lzma2, b);
+		if (s->ret != XZ_STREAM_END
+				&& (s->ret != XZ_OK || s->single_call))
+			return s->ret;
+
+		bcj_apply(s, b->out, &out_start, b->out_pos);
+
+		/*
+		 * As an exception, if the next filter returned XZ_STREAM_END,
+		 * we can do that too, since the last few bytes that remain
+		 * unfiltered are meant to remain unfiltered.
+		 */
+		if (s->ret == XZ_STREAM_END)
+			return XZ_STREAM_END;
+
+		s->temp.size = b->out_pos - out_start;
+		b->out_pos -= s->temp.size;
+		memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
+
+		/*
+		 * If there wasn't enough input to the next filter to fill
+		 * the output buffer with unfiltered data, there's no point
+		 * to try decoding more data to temp.
+		 */
+		if (b->out_pos + s->temp.size < b->out_size)
+			return XZ_OK;
+	}
+
+	/*
+	 * We have unfiltered data in temp. If the output buffer isn't full
+	 * yet, try to fill the temp buffer by decoding more data from the
+	 * next filter. Apply the BCJ filter on temp. Then we hopefully can
+	 * fill the actual output buffer by copying filtered data from temp.
+	 * A mix of filtered and unfiltered data may be left in temp; it will
+	 * be taken care on the next call to this function.
+	 */
+	if (b->out_pos < b->out_size) {
+		/* Make b->out{,_pos,_size} temporarily point to s->temp. */
+		s->out = b->out;
+		s->out_pos = b->out_pos;
+		s->out_size = b->out_size;
+		b->out = s->temp.buf;
+		b->out_pos = s->temp.size;
+		b->out_size = sizeof(s->temp.buf);
+
+		s->ret = xz_dec_lzma2_run(lzma2, b);
+
+		s->temp.size = b->out_pos;
+		b->out = s->out;
+		b->out_pos = s->out_pos;
+		b->out_size = s->out_size;
+
+		if (s->ret != XZ_OK && s->ret != XZ_STREAM_END)
+			return s->ret;
+
+		bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size);
+
+		/*
+		 * If the next filter returned XZ_STREAM_END, we mark that
+		 * everything is filtered, since the last unfiltered bytes
+		 * of the stream are meant to be left as is.
+		 */
+		if (s->ret == XZ_STREAM_END)
+			s->temp.filtered = s->temp.size;
+
+		bcj_flush(s, b);
+		if (s->temp.filtered > 0)
+			return XZ_OK;
+	}
+
+	return s->ret;
+}
+
+XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call)
+{
+	struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL);
+	if (s != NULL)
+		s->single_call = single_call;
+
+	return s;
+}
+
+XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id)
+{
+	switch (id) {
+#ifdef XZ_DEC_X86
+	case BCJ_X86:
+#endif
+#ifdef XZ_DEC_POWERPC
+	case BCJ_POWERPC:
+#endif
+#ifdef XZ_DEC_IA64
+	case BCJ_IA64:
+#endif
+#ifdef XZ_DEC_ARM
+	case BCJ_ARM:
+#endif
+#ifdef XZ_DEC_ARMTHUMB
+	case BCJ_ARMTHUMB:
+#endif
+#ifdef XZ_DEC_SPARC
+	case BCJ_SPARC:
+#endif
+		break;
+
+	default:
+		/* Unsupported Filter ID */
+		return XZ_OPTIONS_ERROR;
+	}
+
+	s->type = id;
+	s->ret = XZ_OK;
+	s->pos = 0;
+	s->x86_prev_mask = 0;
+	s->temp.filtered = 0;
+	s->temp.size = 0;
+
+	return XZ_OK;
+}
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,1171 @@
+/*
+ * LZMA2 decoder
+ *
+ * Authors: Lasse Collin <lasse.collin at tukaani.org>
+ *          Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include "xz_private.h"
+#include "xz_lzma2.h"
+
+/*
+ * Range decoder initialization eats the first five bytes of each LZMA chunk.
+ */
+#define RC_INIT_BYTES 5
+
+/*
+ * Minimum number of usable input buffer to safely decode one LZMA symbol.
+ * The worst case is that we decode 22 bits using probabilities and 26
+ * direct bits. This may decode at maximum of 20 bytes of input. However,
+ * lzma_main() does an extra normalization before returning, thus we
+ * need to put 21 here.
+ */
+#define LZMA_IN_REQUIRED 21
+
+/*
+ * Dictionary (history buffer)
+ *
+ * These are always true:
+ *    start <= pos <= full <= end
+ *    pos <= limit <= end
+ *
+ * In multi-call mode, also these are true:
+ *    end == size
+ *    size <= size_max
+ *    allocated <= size
+ *
+ * Most of these variables are size_t to support single-call mode,
+ * in which the dictionary variables address the actual output
+ * buffer directly.
+ */
+struct dictionary {
+	/* Beginning of the history buffer */
+	uint8_t *buf;
+
+	/* Old position in buf (before decoding more data) */
+	size_t start;
+
+	/* Position in buf */
+	size_t pos;
+
+	/*
+	 * How full dictionary is. This is used to detect corrupt input that
+	 * would read beyond the beginning of the uncompressed stream.
+	 */
+	size_t full;
+
+	/* Write limit; we don't write to buf[limit] or later bytes. */
+	size_t limit;
+
+	/*
+	 * End of the dictionary buffer. In multi-call mode, this is
+	 * the same as the dictionary size. In single-call mode, this
+	 * indicates the size of the output buffer.
+	 */
+	size_t end;
+
+	/*
+	 * Size of the dictionary as specified in Block Header. This is used
+	 * together with "full" to detect corrupt input that would make us
+	 * read beyond the beginning of the uncompressed stream.
+	 */
+	uint32_t size;
+
+	/*
+	 * Maximum allowed dictionary size in multi-call mode.
+	 * This is ignored in single-call mode.
+	 */
+	uint32_t size_max;
+
+	/*
+	 * Amount of memory currently allocated for the dictionary.
+	 * This is used only with XZ_DYNALLOC. (With XZ_PREALLOC,
+	 * size_max is always the same as the allocated size.)
+	 */
+	uint32_t allocated;
+
+	/* Operation mode */
+	enum xz_mode mode;
+};
+
+/* Range decoder */
+struct rc_dec {
+	uint32_t range;
+	uint32_t code;
+
+	/*
+	 * Number of initializing bytes remaining to be read
+	 * by rc_read_init().
+	 */
+	uint32_t init_bytes_left;
+
+	/*
+	 * Buffer from which we read our input. It can be either
+	 * temp.buf or the caller-provided input buffer.
+	 */
+	const uint8_t *in;
+	size_t in_pos;
+	size_t in_limit;
+};
+
+/* Probabilities for a length decoder. */
+struct lzma_len_dec {
+	/* Probability of match length being at least 10 */
+	uint16_t choice;
+
+	/* Probability of match length being at least 18 */
+	uint16_t choice2;
+
+	/* Probabilities for match lengths 2-9 */
+	uint16_t low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
+
+	/* Probabilities for match lengths 10-17 */
+	uint16_t mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
+
+	/* Probabilities for match lengths 18-273 */
+	uint16_t high[LEN_HIGH_SYMBOLS];
+};
+
+struct lzma_dec {
+	/* Distances of latest four matches */
+	uint32_t rep0;
+	uint32_t rep1;
+	uint32_t rep2;
+	uint32_t rep3;
+
+	/* Types of the most recently seen LZMA symbols */
+	enum lzma_state state;
+
+	/*
+	 * Length of a match. This is updated so that dict_repeat can
+	 * be called again to finish repeating the whole match.
+	 */
+	uint32_t len;
+
+	/*
+	 * LZMA properties or related bit masks (number of literal
+	 * context bits, a mask dervied from the number of literal
+	 * position bits, and a mask dervied from the number
+	 * position bits)
+	 */
+	uint32_t lc;
+	uint32_t literal_pos_mask; /* (1 << lp) - 1 */
+	uint32_t pos_mask;         /* (1 << pb) - 1 */
+
+	/* If 1, it's a match. Otherwise it's a single 8-bit literal. */
+	uint16_t is_match[STATES][POS_STATES_MAX];
+
+	/* If 1, it's a repeated match. The distance is one of rep0 .. rep3. */
+	uint16_t is_rep[STATES];
+
+	/*
+	 * If 0, distance of a repeated match is rep0.
+	 * Otherwise check is_rep1.
+	 */
+	uint16_t is_rep0[STATES];
+
+	/*
+	 * If 0, distance of a repeated match is rep1.
+	 * Otherwise check is_rep2.
+	 */
+	uint16_t is_rep1[STATES];
+
+	/* If 0, distance of a repeated match is rep2. Otherwise it is rep3. */
+	uint16_t is_rep2[STATES];
+
+	/*
+	 * If 1, the repeated match has length of one byte. Otherwise
+	 * the length is decoded from rep_len_decoder.
+	 */
+	uint16_t is_rep0_long[STATES][POS_STATES_MAX];
+
+	/*
+	 * Probability tree for the highest two bits of the match
+	 * distance. There is a separate probability tree for match
+	 * lengths of 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273].
+	 */
+	uint16_t dist_slot[DIST_STATES][DIST_SLOTS];
+
+	/*
+	 * Probility trees for additional bits for match distance
+	 * when the distance is in the range [4, 127].
+	 */
+	uint16_t dist_special[FULL_DISTANCES - DIST_MODEL_END];
+
+	/*
+	 * Probability tree for the lowest four bits of a match
+	 * distance that is equal to or greater than 128.
+	 */
+	uint16_t dist_align[ALIGN_SIZE];
+
+	/* Length of a normal match */
+	struct lzma_len_dec match_len_dec;
+
+	/* Length of a repeated match */
+	struct lzma_len_dec rep_len_dec;
+
+	/* Probabilities of literals */
+	uint16_t literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
+};
+
+struct lzma2_dec {
+	/* Position in xz_dec_lzma2_run(). */
+	enum lzma2_seq {
+		SEQ_CONTROL,
+		SEQ_UNCOMPRESSED_1,
+		SEQ_UNCOMPRESSED_2,
+		SEQ_COMPRESSED_0,
+		SEQ_COMPRESSED_1,
+		SEQ_PROPERTIES,
+		SEQ_LZMA_PREPARE,
+		SEQ_LZMA_RUN,
+		SEQ_COPY
+	} sequence;
+
+	/* Next position after decoding the compressed size of the chunk. */
+	enum lzma2_seq next_sequence;
+
+	/* Uncompressed size of LZMA chunk (2 MiB at maximum) */
+	uint32_t uncompressed;
+
+	/*
+	 * Compressed size of LZMA chunk or compressed/uncompressed
+	 * size of uncompressed chunk (64 KiB at maximum)
+	 */
+	uint32_t compressed;
+
+	/*
+	 * True if dictionary reset is needed. This is false before
+	 * the first chunk (LZMA or uncompressed).
+	 */
+	bool need_dict_reset;
+
+	/*
+	 * True if new LZMA properties are needed. This is false
+	 * before the first LZMA chunk.
+	 */
+	bool need_props;
+};
+
+struct xz_dec_lzma2 {
+	/*
+	 * The order below is important on x86 to reduce code size and
+	 * it shouldn't hurt on other platforms. Everything up to and
+	 * including lzma.pos_mask are in the first 128 bytes on x86-32,
+	 * which allows using smaller instructions to access those
+	 * variables. On x86-64, fewer variables fit into the first 128
+	 * bytes, but this is still the best order without sacrificing
+	 * the readability by splitting the structures.
+	 */
+	struct rc_dec rc;
+	struct dictionary dict;
+	struct lzma2_dec lzma2;
+	struct lzma_dec lzma;
+
+	/*
+	 * Temporary buffer which holds small number of input bytes between
+	 * decoder calls. See lzma2_lzma() for details.
+	 */
+	struct {
+		uint32_t size;
+		uint8_t buf[3 * LZMA_IN_REQUIRED];
+	} temp;
+};
+
+/**************
+ * Dictionary *
+ **************/
+
+/*
+ * Reset the dictionary state. When in single-call mode, set up the beginning
+ * of the dictionary to point to the actual output buffer.
+ */
+static void dict_reset(struct dictionary *dict, struct xz_buf *b)
+{
+	if (DEC_IS_SINGLE(dict->mode)) {
+		dict->buf = b->out + b->out_pos;
+		dict->end = b->out_size - b->out_pos;
+	}
+
+	dict->start = 0;
+	dict->pos = 0;
+	dict->limit = 0;
+	dict->full = 0;
+}
+
+/* Set dictionary write limit */
+static void dict_limit(struct dictionary *dict, size_t out_max)
+{
+	if (dict->end - dict->pos <= out_max)
+		dict->limit = dict->end;
+	else
+		dict->limit = dict->pos + out_max;
+}
+
+/* Return true if at least one byte can be written into the dictionary. */
+static inline bool dict_has_space(const struct dictionary *dict)
+{
+	return dict->pos < dict->limit;
+}
+
+/*
+ * Get a byte from the dictionary at the given distance. The distance is
+ * assumed to valid, or as a special case, zero when the dictionary is
+ * still empty. This special case is needed for single-call decoding to
+ * avoid writing a '\0' to the end of the destination buffer.
+ */
+static inline uint32_t dict_get(const struct dictionary *dict, uint32_t dist)
+{
+	size_t offset = dict->pos - dist - 1;
+
+	if (dist >= dict->pos)
+		offset += dict->end;
+
+	return dict->full > 0 ? dict->buf[offset] : 0;
+}
+
+/*
+ * Put one byte into the dictionary. It is assumed that there is space for it.
+ */
+static inline void dict_put(struct dictionary *dict, uint8_t byte)
+{
+	dict->buf[dict->pos++] = byte;
+
+	if (dict->full < dict->pos)
+		dict->full = dict->pos;
+}
+
+/*
+ * Repeat given number of bytes from the given distance. If the distance is
+ * invalid, false is returned. On success, true is returned and *len is
+ * updated to indicate how many bytes were left to be repeated.
+ */
+static bool dict_repeat(struct dictionary *dict, uint32_t *len, uint32_t dist)
+{
+	size_t back;
+	uint32_t left;
+
+	if (dist >= dict->full || dist >= dict->size)
+		return false;
+
+	left = min_t(size_t, dict->limit - dict->pos, *len);
+	*len -= left;
+
+	back = dict->pos - dist - 1;
+	if (dist >= dict->pos)
+		back += dict->end;
+
+	do {
+		dict->buf[dict->pos++] = dict->buf[back++];
+		if (back == dict->end)
+			back = 0;
+	} while (--left > 0);
+
+	if (dict->full < dict->pos)
+		dict->full = dict->pos;
+
+	return true;
+}
+
+/* Copy uncompressed data as is from input to dictionary and output buffers. */
+static void dict_uncompressed(struct dictionary *dict, struct xz_buf *b,
+			      uint32_t *left)
+{
+	size_t copy_size;
+
+	while (*left > 0 && b->in_pos < b->in_size
+			&& b->out_pos < b->out_size) {
+		copy_size = min(b->in_size - b->in_pos,
+				b->out_size - b->out_pos);
+		if (copy_size > dict->end - dict->pos)
+			copy_size = dict->end - dict->pos;
+		if (copy_size > *left)
+			copy_size = *left;
+
+		*left -= copy_size;
+
+		memcpy(dict->buf + dict->pos, b->in + b->in_pos, copy_size);
+		dict->pos += copy_size;
+
+		if (dict->full < dict->pos)
+			dict->full = dict->pos;
+
+		if (DEC_IS_MULTI(dict->mode)) {
+			if (dict->pos == dict->end)
+				dict->pos = 0;
+
+			memcpy(b->out + b->out_pos, b->in + b->in_pos,
+					copy_size);
+		}
+
+		dict->start = dict->pos;
+
+		b->out_pos += copy_size;
+		b->in_pos += copy_size;
+	}
+}
+
+/*
+ * Flush pending data from dictionary to b->out. It is assumed that there is
+ * enough space in b->out. This is guaranteed because caller uses dict_limit()
+ * before decoding data into the dictionary.
+ */
+static uint32_t dict_flush(struct dictionary *dict, struct xz_buf *b)
+{
+	size_t copy_size = dict->pos - dict->start;
+
+	if (DEC_IS_MULTI(dict->mode)) {
+		if (dict->pos == dict->end)
+			dict->pos = 0;
+
+		memcpy(b->out + b->out_pos, dict->buf + dict->start,
+				copy_size);
+	}
+
+	dict->start = dict->pos;
+	b->out_pos += copy_size;
+	return copy_size;
+}
+
+/*****************
+ * Range decoder *
+ *****************/
+
+/* Reset the range decoder. */
+static void rc_reset(struct rc_dec *rc)
+{
+	rc->range = (uint32_t)-1;
+	rc->code = 0;
+	rc->init_bytes_left = RC_INIT_BYTES;
+}
+
+/*
+ * Read the first five initial bytes into rc->code if they haven't been
+ * read already. (Yes, the first byte gets completely ignored.)
+ */
+static bool rc_read_init(struct rc_dec *rc, struct xz_buf *b)
+{
+	while (rc->init_bytes_left > 0) {
+		if (b->in_pos == b->in_size)
+			return false;
+
+		rc->code = (rc->code << 8) + b->in[b->in_pos++];
+		--rc->init_bytes_left;
+	}
+
+	return true;
+}
+
+/* Return true if there may not be enough input for the next decoding loop. */
+static inline bool rc_limit_exceeded(const struct rc_dec *rc)
+{
+	return rc->in_pos > rc->in_limit;
+}
+
+/*
+ * Return true if it is possible (from point of view of range decoder) that
+ * we have reached the end of the LZMA chunk.
+ */
+static inline bool rc_is_finished(const struct rc_dec *rc)
+{
+	return rc->code == 0;
+}
+
+/* Read the next input byte if needed. */
+static __always_inline void rc_normalize(struct rc_dec *rc)
+{
+	if (rc->range < RC_TOP_VALUE) {
+		rc->range <<= RC_SHIFT_BITS;
+		rc->code = (rc->code << RC_SHIFT_BITS) + rc->in[rc->in_pos++];
+	}
+}
+
+/*
+ * Decode one bit. In some versions, this function has been splitted in three
+ * functions so that the compiler is supposed to be able to more easily avoid
+ * an extra branch. In this particular version of the LZMA decoder, this
+ * doesn't seem to be a good idea (tested with GCC 3.3.6, 3.4.6, and 4.3.3
+ * on x86). Using a non-splitted version results in nicer looking code too.
+ *
+ * NOTE: This must return an int. Do not make it return a bool or the speed
+ * of the code generated by GCC 3.x decreases 10-15 %. (GCC 4.3 doesn't care,
+ * and it generates 10-20 % faster code than GCC 3.x from this file anyway.)
+ */
+static __always_inline int rc_bit(struct rc_dec *rc, uint16_t *prob)
+{
+	uint32_t bound;
+	int bit;
+
+	rc_normalize(rc);
+	bound = (rc->range >> RC_BIT_MODEL_TOTAL_BITS) * *prob;
+	if (rc->code < bound) {
+		rc->range = bound;
+		*prob += (RC_BIT_MODEL_TOTAL - *prob) >> RC_MOVE_BITS;
+		bit = 0;
+	} else {
+		rc->range -= bound;
+		rc->code -= bound;
+		*prob -= *prob >> RC_MOVE_BITS;
+		bit = 1;
+	}
+
+	return bit;
+}
+
+/* Decode a bittree starting from the most significant bit. */
+static __always_inline uint32_t rc_bittree(struct rc_dec *rc,
+					   uint16_t *probs, uint32_t limit)
+{
+	uint32_t symbol = 1;
+
+	do {
+		if (rc_bit(rc, &probs[symbol]))
+			symbol = (symbol << 1) + 1;
+		else
+			symbol <<= 1;
+	} while (symbol < limit);
+
+	return symbol;
+}
+
+/* Decode a bittree starting from the least significant bit. */
+static __always_inline void rc_bittree_reverse(struct rc_dec *rc,
+					       uint16_t *probs,
+					       uint32_t *dest, uint32_t limit)
+{
+	uint32_t symbol = 1;
+	uint32_t i = 0;
+
+	do {
+		if (rc_bit(rc, &probs[symbol])) {
+			symbol = (symbol << 1) + 1;
+			*dest += 1 << i;
+		} else {
+			symbol <<= 1;
+		}
+	} while (++i < limit);
+}
+
+/* Decode direct bits (fixed fifty-fifty probability) */
+static inline void rc_direct(struct rc_dec *rc, uint32_t *dest, uint32_t limit)
+{
+	uint32_t mask;
+
+	do {
+		rc_normalize(rc);
+		rc->range >>= 1;
+		rc->code -= rc->range;
+		mask = (uint32_t)0 - (rc->code >> 31);
+		rc->code += rc->range & mask;
+		*dest = (*dest << 1) + (mask + 1);
+	} while (--limit > 0);
+}
+
+/********
+ * LZMA *
+ ********/
+
+/* Get pointer to literal coder probability array. */
+static uint16_t *lzma_literal_probs(struct xz_dec_lzma2 *s)
+{
+	uint32_t prev_byte = dict_get(&s->dict, 0);
+	uint32_t low = prev_byte >> (8 - s->lzma.lc);
+	uint32_t high = (s->dict.pos & s->lzma.literal_pos_mask) << s->lzma.lc;
+	return s->lzma.literal[low + high];
+}
+
+/* Decode a literal (one 8-bit byte) */
+static void lzma_literal(struct xz_dec_lzma2 *s)
+{
+	uint16_t *probs;
+	uint32_t symbol;
+	uint32_t match_byte;
+	uint32_t match_bit;
+	uint32_t offset;
+	uint32_t i;
+
+	probs = lzma_literal_probs(s);
+
+	if (lzma_state_is_literal(s->lzma.state)) {
+		symbol = rc_bittree(&s->rc, probs, 0x100);
+	} else {
+		symbol = 1;
+		match_byte = dict_get(&s->dict, s->lzma.rep0) << 1;
+		offset = 0x100;
+
+		do {
+			match_bit = match_byte & offset;
+			match_byte <<= 1;
+			i = offset + match_bit + symbol;
+
+			if (rc_bit(&s->rc, &probs[i])) {
+				symbol = (symbol << 1) + 1;
+				offset &= match_bit;
+			} else {
+				symbol <<= 1;
+				offset &= ~match_bit;
+			}
+		} while (symbol < 0x100);
+	}
+
+	dict_put(&s->dict, (uint8_t)symbol);
+	lzma_state_literal(&s->lzma.state);
+}
+
+/* Decode the length of the match into s->lzma.len. */
+static void lzma_len(struct xz_dec_lzma2 *s, struct lzma_len_dec *l,
+		     uint32_t pos_state)
+{
+	uint16_t *probs;
+	uint32_t limit;
+
+	if (!rc_bit(&s->rc, &l->choice)) {
+		probs = l->low[pos_state];
+		limit = LEN_LOW_SYMBOLS;
+		s->lzma.len = MATCH_LEN_MIN;
+	} else {
+		if (!rc_bit(&s->rc, &l->choice2)) {
+			probs = l->mid[pos_state];
+			limit = LEN_MID_SYMBOLS;
+			s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS;
+		} else {
+			probs = l->high;
+			limit = LEN_HIGH_SYMBOLS;
+			s->lzma.len = MATCH_LEN_MIN + LEN_LOW_SYMBOLS
+					+ LEN_MID_SYMBOLS;
+		}
+	}
+
+	s->lzma.len += rc_bittree(&s->rc, probs, limit) - limit;
+}
+
+/* Decode a match. The distance will be stored in s->lzma.rep0. */
+static void lzma_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
+{
+	uint16_t *probs;
+	uint32_t dist_slot;
+	uint32_t limit;
+
+	lzma_state_match(&s->lzma.state);
+
+	s->lzma.rep3 = s->lzma.rep2;
+	s->lzma.rep2 = s->lzma.rep1;
+	s->lzma.rep1 = s->lzma.rep0;
+
+	lzma_len(s, &s->lzma.match_len_dec, pos_state);
+
+	probs = s->lzma.dist_slot[lzma_get_dist_state(s->lzma.len)];
+	dist_slot = rc_bittree(&s->rc, probs, DIST_SLOTS) - DIST_SLOTS;
+
+	if (dist_slot < DIST_MODEL_START) {
+		s->lzma.rep0 = dist_slot;
+	} else {
+		limit = (dist_slot >> 1) - 1;
+		s->lzma.rep0 = 2 + (dist_slot & 1);
+
+		if (dist_slot < DIST_MODEL_END) {
+			s->lzma.rep0 <<= limit;
+			probs = s->lzma.dist_special + s->lzma.rep0
+					- dist_slot - 1;
+			rc_bittree_reverse(&s->rc, probs,
+					&s->lzma.rep0, limit);
+		} else {
+			rc_direct(&s->rc, &s->lzma.rep0, limit - ALIGN_BITS);
+			s->lzma.rep0 <<= ALIGN_BITS;
+			rc_bittree_reverse(&s->rc, s->lzma.dist_align,
+					&s->lzma.rep0, ALIGN_BITS);
+		}
+	}
+}
+
+/*
+ * Decode a repeated match. The distance is one of the four most recently
+ * seen matches. The distance will be stored in s->lzma.rep0.
+ */
+static void lzma_rep_match(struct xz_dec_lzma2 *s, uint32_t pos_state)
+{
+	uint32_t tmp;
+
+	if (!rc_bit(&s->rc, &s->lzma.is_rep0[s->lzma.state])) {
+		if (!rc_bit(&s->rc, &s->lzma.is_rep0_long[
+				s->lzma.state][pos_state])) {
+			lzma_state_short_rep(&s->lzma.state);
+			s->lzma.len = 1;
+			return;
+		}
+	} else {
+		if (!rc_bit(&s->rc, &s->lzma.is_rep1[s->lzma.state])) {
+			tmp = s->lzma.rep1;
+		} else {
+			if (!rc_bit(&s->rc, &s->lzma.is_rep2[s->lzma.state])) {
+				tmp = s->lzma.rep2;
+			} else {
+				tmp = s->lzma.rep3;
+				s->lzma.rep3 = s->lzma.rep2;
+			}
+
+			s->lzma.rep2 = s->lzma.rep1;
+		}
+
+		s->lzma.rep1 = s->lzma.rep0;
+		s->lzma.rep0 = tmp;
+	}
+
+	lzma_state_long_rep(&s->lzma.state);
+	lzma_len(s, &s->lzma.rep_len_dec, pos_state);
+}
+
+/* LZMA decoder core */
+static bool lzma_main(struct xz_dec_lzma2 *s)
+{
+	uint32_t pos_state;
+
+	/*
+	 * If the dictionary was reached during the previous call, try to
+	 * finish the possibly pending repeat in the dictionary.
+	 */
+	if (dict_has_space(&s->dict) && s->lzma.len > 0)
+		dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0);
+
+	/*
+	 * Decode more LZMA symbols. One iteration may consume up to
+	 * LZMA_IN_REQUIRED - 1 bytes.
+	 */
+	while (dict_has_space(&s->dict) && !rc_limit_exceeded(&s->rc)) {
+		pos_state = s->dict.pos & s->lzma.pos_mask;
+
+		if (!rc_bit(&s->rc, &s->lzma.is_match[
+				s->lzma.state][pos_state])) {
+			lzma_literal(s);
+		} else {
+			if (rc_bit(&s->rc, &s->lzma.is_rep[s->lzma.state]))
+				lzma_rep_match(s, pos_state);
+			else
+				lzma_match(s, pos_state);
+
+			if (!dict_repeat(&s->dict, &s->lzma.len, s->lzma.rep0))
+				return false;
+		}
+	}
+
+	/*
+	 * Having the range decoder always normalized when we are outside
+	 * this function makes it easier to correctly handle end of the chunk.
+	 */
+	rc_normalize(&s->rc);
+
+	return true;
+}
+
+/*
+ * Reset the LZMA decoder and range decoder state. Dictionary is nore reset
+ * here, because LZMA state may be reset without resetting the dictionary.
+ */
+static void lzma_reset(struct xz_dec_lzma2 *s)
+{
+	uint16_t *probs;
+	size_t i;
+
+	s->lzma.state = STATE_LIT_LIT;
+	s->lzma.rep0 = 0;
+	s->lzma.rep1 = 0;
+	s->lzma.rep2 = 0;
+	s->lzma.rep3 = 0;
+
+	/*
+	 * All probabilities are initialized to the same value. This hack
+	 * makes the code smaller by avoiding a separate loop for each
+	 * probability array.
+	 *
+	 * This could be optimized so that only that part of literal
+	 * probabilities that are actually required. In the common case
+	 * we would write 12 KiB less.
+	 */
+	probs = s->lzma.is_match[0];
+	for (i = 0; i < PROBS_TOTAL; ++i)
+		probs[i] = RC_BIT_MODEL_TOTAL / 2;
+
+	rc_reset(&s->rc);
+}
+
+/*
+ * Decode and validate LZMA properties (lc/lp/pb) and calculate the bit masks
+ * from the decoded lp and pb values. On success, the LZMA decoder state is
+ * reset and true is returned.
+ */
+static bool lzma_props(struct xz_dec_lzma2 *s, uint8_t props)
+{
+	if (props > (4 * 5 + 4) * 9 + 8)
+		return false;
+
+	s->lzma.pos_mask = 0;
+	while (props >= 9 * 5) {
+		props -= 9 * 5;
+		++s->lzma.pos_mask;
+	}
+
+	s->lzma.pos_mask = (1 << s->lzma.pos_mask) - 1;
+
+	s->lzma.literal_pos_mask = 0;
+	while (props >= 9) {
+		props -= 9;
+		++s->lzma.literal_pos_mask;
+	}
+
+	s->lzma.lc = props;
+
+	if (s->lzma.lc + s->lzma.literal_pos_mask > 4)
+		return false;
+
+	s->lzma.literal_pos_mask = (1 << s->lzma.literal_pos_mask) - 1;
+
+	lzma_reset(s);
+
+	return true;
+}
+
+/*********
+ * LZMA2 *
+ *********/
+
+/*
+ * The LZMA decoder assumes that if the input limit (s->rc.in_limit) hasn't
+ * been exceeded, it is safe to read up to LZMA_IN_REQUIRED bytes. This
+ * wrapper function takes care of making the LZMA decoder's assumption safe.
+ *
+ * As long as there is plenty of input left to be decoded in the current LZMA
+ * chunk, we decode directly from the caller-supplied input buffer until
+ * there's LZMA_IN_REQUIRED bytes left. Those remaining bytes are copied into
+ * s->temp.buf, which (hopefully) gets filled on the next call to this
+ * function. We decode a few bytes from the temporary buffer so that we can
+ * continue decoding from the caller-supplied input buffer again.
+ */
+static bool lzma2_lzma(struct xz_dec_lzma2 *s, struct xz_buf *b)
+{
+	size_t in_avail;
+	uint32_t tmp;
+
+	in_avail = b->in_size - b->in_pos;
+	if (s->temp.size > 0 || s->lzma2.compressed == 0) {
+		tmp = 2 * LZMA_IN_REQUIRED - s->temp.size;
+		if (tmp > s->lzma2.compressed - s->temp.size)
+			tmp = s->lzma2.compressed - s->temp.size;
+		if (tmp > in_avail)
+			tmp = in_avail;
+
+		memcpy(s->temp.buf + s->temp.size, b->in + b->in_pos, tmp);
+
+		if (s->temp.size + tmp == s->lzma2.compressed) {
+			memzero(s->temp.buf + s->temp.size + tmp,
+					sizeof(s->temp.buf)
+						- s->temp.size - tmp);
+			s->rc.in_limit = s->temp.size + tmp;
+		} else if (s->temp.size + tmp < LZMA_IN_REQUIRED) {
+			s->temp.size += tmp;
+			b->in_pos += tmp;
+			return true;
+		} else {
+			s->rc.in_limit = s->temp.size + tmp - LZMA_IN_REQUIRED;
+		}
+
+		s->rc.in = s->temp.buf;
+		s->rc.in_pos = 0;
+
+		if (!lzma_main(s) || s->rc.in_pos > s->temp.size + tmp)
+			return false;
+
+		s->lzma2.compressed -= s->rc.in_pos;
+
+		if (s->rc.in_pos < s->temp.size) {
+			s->temp.size -= s->rc.in_pos;
+			memmove(s->temp.buf, s->temp.buf + s->rc.in_pos,
+					s->temp.size);
+			return true;
+		}
+
+		b->in_pos += s->rc.in_pos - s->temp.size;
+		s->temp.size = 0;
+	}
+
+	in_avail = b->in_size - b->in_pos;
+	if (in_avail >= LZMA_IN_REQUIRED) {
+		s->rc.in = b->in;
+		s->rc.in_pos = b->in_pos;
+
+		if (in_avail >= s->lzma2.compressed + LZMA_IN_REQUIRED)
+			s->rc.in_limit = b->in_pos + s->lzma2.compressed;
+		else
+			s->rc.in_limit = b->in_size - LZMA_IN_REQUIRED;
+
+		if (!lzma_main(s))
+			return false;
+
+		in_avail = s->rc.in_pos - b->in_pos;
+		if (in_avail > s->lzma2.compressed)
+			return false;
+
+		s->lzma2.compressed -= in_avail;
+		b->in_pos = s->rc.in_pos;
+	}
+
+	in_avail = b->in_size - b->in_pos;
+	if (in_avail < LZMA_IN_REQUIRED) {
+		if (in_avail > s->lzma2.compressed)
+			in_avail = s->lzma2.compressed;
+
+		memcpy(s->temp.buf, b->in + b->in_pos, in_avail);
+		s->temp.size = in_avail;
+		b->in_pos += in_avail;
+	}
+
+	return true;
+}
+
+/*
+ * Take care of the LZMA2 control layer, and forward the job of actual LZMA
+ * decoding or copying of uncompressed chunks to other functions.
+ */
+XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
+				       struct xz_buf *b)
+{
+	uint32_t tmp;
+
+	while (b->in_pos < b->in_size || s->lzma2.sequence == SEQ_LZMA_RUN) {
+		switch (s->lzma2.sequence) {
+		case SEQ_CONTROL:
+			/*
+			 * LZMA2 control byte
+			 *
+			 * Exact values:
+			 *   0x00   End marker
+			 *   0x01   Dictionary reset followed by
+			 *          an uncompressed chunk
+			 *   0x02   Uncompressed chunk (no dictionary reset)
+			 *
+			 * Highest three bits (s->control & 0xE0):
+			 *   0xE0   Dictionary reset, new properties and state
+			 *          reset, followed by LZMA compressed chunk
+			 *   0xC0   New properties and state reset, followed
+			 *          by LZMA compressed chunk (no dictionary
+			 *          reset)
+			 *   0xA0   State reset using old properties,
+			 *          followed by LZMA compressed chunk (no
+			 *          dictionary reset)
+			 *   0x80   LZMA chunk (no dictionary or state reset)
+			 *
+			 * For LZMA compressed chunks, the lowest five bits
+			 * (s->control & 1F) are the highest bits of the
+			 * uncompressed size (bits 16-20).
+			 *
+			 * A new LZMA2 stream must begin with a dictionary
+			 * reset. The first LZMA chunk must set new
+			 * properties and reset the LZMA state.
+			 *
+			 * Values that don't match anything described above
+			 * are invalid and we return XZ_DATA_ERROR.
+			 */
+			tmp = b->in[b->in_pos++];
+
+			if (tmp == 0x00)
+				return XZ_STREAM_END;
+
+			if (tmp >= 0xE0 || tmp == 0x01) {
+				s->lzma2.need_props = true;
+				s->lzma2.need_dict_reset = false;
+				dict_reset(&s->dict, b);
+			} else if (s->lzma2.need_dict_reset) {
+				return XZ_DATA_ERROR;
+			}
+
+			if (tmp >= 0x80) {
+				s->lzma2.uncompressed = (tmp & 0x1F) << 16;
+				s->lzma2.sequence = SEQ_UNCOMPRESSED_1;
+
+				if (tmp >= 0xC0) {
+					/*
+					 * When there are new properties,
+					 * state reset is done at
+					 * SEQ_PROPERTIES.
+					 */
+					s->lzma2.need_props = false;
+					s->lzma2.next_sequence
+							= SEQ_PROPERTIES;
+
+				} else if (s->lzma2.need_props) {
+					return XZ_DATA_ERROR;
+
+				} else {
+					s->lzma2.next_sequence
+							= SEQ_LZMA_PREPARE;
+					if (tmp >= 0xA0)
+						lzma_reset(s);
+				}
+			} else {
+				if (tmp > 0x02)
+					return XZ_DATA_ERROR;
+
+				s->lzma2.sequence = SEQ_COMPRESSED_0;
+				s->lzma2.next_sequence = SEQ_COPY;
+			}
+
+			break;
+
+		case SEQ_UNCOMPRESSED_1:
+			s->lzma2.uncompressed
+					+= (uint32_t)b->in[b->in_pos++] << 8;
+			s->lzma2.sequence = SEQ_UNCOMPRESSED_2;
+			break;
+
+		case SEQ_UNCOMPRESSED_2:
+			s->lzma2.uncompressed
+					+= (uint32_t)b->in[b->in_pos++] + 1;
+			s->lzma2.sequence = SEQ_COMPRESSED_0;
+			break;
+
+		case SEQ_COMPRESSED_0:
+			s->lzma2.compressed
+					= (uint32_t)b->in[b->in_pos++] << 8;
+			s->lzma2.sequence = SEQ_COMPRESSED_1;
+			break;
+
+		case SEQ_COMPRESSED_1:
+			s->lzma2.compressed
+					+= (uint32_t)b->in[b->in_pos++] + 1;
+			s->lzma2.sequence = s->lzma2.next_sequence;
+			break;
+
+		case SEQ_PROPERTIES:
+			if (!lzma_props(s, b->in[b->in_pos++]))
+				return XZ_DATA_ERROR;
+
+			s->lzma2.sequence = SEQ_LZMA_PREPARE;
+
+		case SEQ_LZMA_PREPARE:
+			if (s->lzma2.compressed < RC_INIT_BYTES)
+				return XZ_DATA_ERROR;
+
+			if (!rc_read_init(&s->rc, b))
+				return XZ_OK;
+
+			s->lzma2.compressed -= RC_INIT_BYTES;
+			s->lzma2.sequence = SEQ_LZMA_RUN;
+
+		case SEQ_LZMA_RUN:
+			/*
+			 * Set dictionary limit to indicate how much we want
+			 * to be encoded at maximum. Decode new data into the
+			 * dictionary. Flush the new data from dictionary to
+			 * b->out. Check if we finished decoding this chunk.
+			 * In case the dictionary got full but we didn't fill
+			 * the output buffer yet, we may run this loop
+			 * multiple times without changing s->lzma2.sequence.
+			 */
+			dict_limit(&s->dict, min_t(size_t,
+					b->out_size - b->out_pos,
+					s->lzma2.uncompressed));
+			if (!lzma2_lzma(s, b))
+				return XZ_DATA_ERROR;
+
+			s->lzma2.uncompressed -= dict_flush(&s->dict, b);
+
+			if (s->lzma2.uncompressed == 0) {
+				if (s->lzma2.compressed > 0 || s->lzma.len > 0
+						|| !rc_is_finished(&s->rc))
+					return XZ_DATA_ERROR;
+
+				rc_reset(&s->rc);
+				s->lzma2.sequence = SEQ_CONTROL;
+
+			} else if (b->out_pos == b->out_size
+					|| (b->in_pos == b->in_size
+						&& s->temp.size
+						< s->lzma2.compressed)) {
+				return XZ_OK;
+			}
+
+			break;
+
+		case SEQ_COPY:
+			dict_uncompressed(&s->dict, b, &s->lzma2.compressed);
+			if (s->lzma2.compressed > 0)
+				return XZ_OK;
+
+			s->lzma2.sequence = SEQ_CONTROL;
+			break;
+		}
+	}
+
+	return XZ_OK;
+}
+
+XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
+						   uint32_t dict_max)
+{
+	struct xz_dec_lzma2 *s = kmalloc(sizeof(*s), GFP_KERNEL);
+	if (s == NULL)
+		return NULL;
+
+	s->dict.mode = mode;
+	s->dict.size_max = dict_max;
+
+	if (DEC_IS_PREALLOC(mode)) {
+		s->dict.buf = vmalloc(dict_max);
+		if (s->dict.buf == NULL) {
+			kfree(s);
+			return NULL;
+		}
+	} else if (DEC_IS_DYNALLOC(mode)) {
+		s->dict.buf = NULL;
+		s->dict.allocated = 0;
+	}
+
+	return s;
+}
+
+XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s, uint8_t props)
+{
+	/* This limits dictionary size to 3 GiB to keep parsing simpler. */
+	if (props > 39)
+		return XZ_OPTIONS_ERROR;
+
+	s->dict.size = 2 + (props & 1);
+	s->dict.size <<= (props >> 1) + 11;
+
+	if (DEC_IS_MULTI(s->dict.mode)) {
+		if (s->dict.size > s->dict.size_max)
+			return XZ_MEMLIMIT_ERROR;
+
+		s->dict.end = s->dict.size;
+
+		if (DEC_IS_DYNALLOC(s->dict.mode)) {
+			if (s->dict.allocated < s->dict.size) {
+				vfree(s->dict.buf);
+				s->dict.buf = vmalloc(s->dict.size);
+				if (s->dict.buf == NULL) {
+					s->dict.allocated = 0;
+					return XZ_MEM_ERROR;
+				}
+			}
+		}
+	}
+
+	s->lzma.len = 0;
+
+	s->lzma2.sequence = SEQ_CONTROL;
+	s->lzma2.need_dict_reset = true;
+
+	s->temp.size = 0;
+
+	return XZ_OK;
+}
+
+XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s)
+{
+	if (DEC_IS_MULTI(s->dict.mode))
+		vfree(s->dict.buf);
+
+	kfree(s);
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_stream.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_stream.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,821 @@
+/*
+ * .xz Stream decoder
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include "xz_private.h"
+#include "xz_stream.h"
+
+/* Hash used to validate the Index field */
+struct xz_dec_hash {
+	vli_type unpadded;
+	vli_type uncompressed;
+	uint32_t crc32;
+};
+
+struct xz_dec {
+	/* Position in dec_main() */
+	enum {
+		SEQ_STREAM_HEADER,
+		SEQ_BLOCK_START,
+		SEQ_BLOCK_HEADER,
+		SEQ_BLOCK_UNCOMPRESS,
+		SEQ_BLOCK_PADDING,
+		SEQ_BLOCK_CHECK,
+		SEQ_INDEX,
+		SEQ_INDEX_PADDING,
+		SEQ_INDEX_CRC32,
+		SEQ_STREAM_FOOTER
+	} sequence;
+
+	/* Position in variable-length integers and Check fields */
+	uint32_t pos;
+
+	/* Variable-length integer decoded by dec_vli() */
+	vli_type vli;
+
+	/* Saved in_pos and out_pos */
+	size_t in_start;
+	size_t out_start;
+
+	/* CRC32 value in Block or Index */
+	uint32_t crc32;
+
+	/* Type of the integrity check calculated from uncompressed data */
+	enum xz_check check_type;
+
+	/* Operation mode */
+	enum xz_mode mode;
+
+	/*
+	 * True if the next call to xz_dec_run() is allowed to return
+	 * XZ_BUF_ERROR.
+	 */
+	bool allow_buf_error;
+
+	/* Information stored in Block Header */
+	struct {
+		/*
+		 * Value stored in the Compressed Size field, or
+		 * VLI_UNKNOWN if Compressed Size is not present.
+		 */
+		vli_type compressed;
+
+		/*
+		 * Value stored in the Uncompressed Size field, or
+		 * VLI_UNKNOWN if Uncompressed Size is not present.
+		 */
+		vli_type uncompressed;
+
+		/* Size of the Block Header field */
+		uint32_t size;
+	} block_header;
+
+	/* Information collected when decoding Blocks */
+	struct {
+		/* Observed compressed size of the current Block */
+		vli_type compressed;
+
+		/* Observed uncompressed size of the current Block */
+		vli_type uncompressed;
+
+		/* Number of Blocks decoded so far */
+		vli_type count;
+
+		/*
+		 * Hash calculated from the Block sizes. This is used to
+		 * validate the Index field.
+		 */
+		struct xz_dec_hash hash;
+	} block;
+
+	/* Variables needed when verifying the Index field */
+	struct {
+		/* Position in dec_index() */
+		enum {
+			SEQ_INDEX_COUNT,
+			SEQ_INDEX_UNPADDED,
+			SEQ_INDEX_UNCOMPRESSED
+		} sequence;
+
+		/* Size of the Index in bytes */
+		vli_type size;
+
+		/* Number of Records (matches block.count in valid files) */
+		vli_type count;
+
+		/*
+		 * Hash calculated from the Records (matches block.hash in
+		 * valid files).
+		 */
+		struct xz_dec_hash hash;
+	} index;
+
+	/*
+	 * Temporary buffer needed to hold Stream Header, Block Header,
+	 * and Stream Footer. The Block Header is the biggest (1 KiB)
+	 * so we reserve space according to that. buf[] has to be aligned
+	 * to a multiple of four bytes; the size_t variables before it
+	 * should guarantee this.
+	 */
+	struct {
+		size_t pos;
+		size_t size;
+		uint8_t buf[1024];
+	} temp;
+
+	struct xz_dec_lzma2 *lzma2;
+
+#ifdef XZ_DEC_BCJ
+	struct xz_dec_bcj *bcj;
+	bool bcj_active;
+#endif
+};
+
+#ifdef XZ_DEC_ANY_CHECK
+/* Sizes of the Check field with different Check IDs */
+static const uint8_t check_sizes[16] = {
+	0,
+	4, 4, 4,
+	8, 8, 8,
+	16, 16, 16,
+	32, 32, 32,
+	64, 64, 64
+};
+#endif
+
+/*
+ * Fill s->temp by copying data starting from b->in[b->in_pos]. Caller
+ * must have set s->temp.pos to indicate how much data we are supposed
+ * to copy into s->temp.buf. Return true once s->temp.pos has reached
+ * s->temp.size.
+ */
+static bool fill_temp(struct xz_dec *s, struct xz_buf *b)
+{
+	size_t copy_size = min_t(size_t,
+			b->in_size - b->in_pos, s->temp.size - s->temp.pos);
+
+	memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size);
+	b->in_pos += copy_size;
+	s->temp.pos += copy_size;
+
+	if (s->temp.pos == s->temp.size) {
+		s->temp.pos = 0;
+		return true;
+	}
+
+	return false;
+}
+
+/* Decode a variable-length integer (little-endian base-128 encoding) */
+static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *in,
+			   size_t *in_pos, size_t in_size)
+{
+	uint8_t byte;
+
+	if (s->pos == 0)
+		s->vli = 0;
+
+	while (*in_pos < in_size) {
+		byte = in[*in_pos];
+		++*in_pos;
+
+		s->vli |= (vli_type)(byte & 0x7F) << s->pos;
+
+		if ((byte & 0x80) == 0) {
+			/* Don't allow non-minimal encodings. */
+			if (byte == 0 && s->pos != 0)
+				return XZ_DATA_ERROR;
+
+			s->pos = 0;
+			return XZ_STREAM_END;
+		}
+
+		s->pos += 7;
+		if (s->pos == 7 * VLI_BYTES_MAX)
+			return XZ_DATA_ERROR;
+	}
+
+	return XZ_OK;
+}
+
+/*
+ * Decode the Compressed Data field from a Block. Update and validate
+ * the observed compressed and uncompressed sizes of the Block so that
+ * they don't exceed the values possibly stored in the Block Header
+ * (validation assumes that no integer overflow occurs, since vli_type
+ * is normally uint64_t). Update the CRC32 if presence of the CRC32
+ * field was indicated in Stream Header.
+ *
+ * Once the decoding is finished, validate that the observed sizes match
+ * the sizes possibly stored in the Block Header. Update the hash and
+ * Block count, which are later used to validate the Index field.
+ */
+static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
+{
+	enum xz_ret ret;
+
+	s->in_start = b->in_pos;
+	s->out_start = b->out_pos;
+
+#ifdef XZ_DEC_BCJ
+	if (s->bcj_active)
+		ret = xz_dec_bcj_run(s->bcj, s->lzma2, b);
+	else
+#endif
+		ret = xz_dec_lzma2_run(s->lzma2, b);
+
+	s->block.compressed += b->in_pos - s->in_start;
+	s->block.uncompressed += b->out_pos - s->out_start;
+
+	/*
+	 * There is no need to separately check for VLI_UNKNOWN, since
+	 * the observed sizes are always smaller than VLI_UNKNOWN.
+	 */
+	if (s->block.compressed > s->block_header.compressed
+			|| s->block.uncompressed
+				> s->block_header.uncompressed)
+		return XZ_DATA_ERROR;
+
+	if (s->check_type == XZ_CHECK_CRC32)
+		s->crc32 = xz_crc32(b->out + s->out_start,
+				b->out_pos - s->out_start, s->crc32);
+
+	if (ret == XZ_STREAM_END) {
+		if (s->block_header.compressed != VLI_UNKNOWN
+				&& s->block_header.compressed
+					!= s->block.compressed)
+			return XZ_DATA_ERROR;
+
+		if (s->block_header.uncompressed != VLI_UNKNOWN
+				&& s->block_header.uncompressed
+					!= s->block.uncompressed)
+			return XZ_DATA_ERROR;
+
+		s->block.hash.unpadded += s->block_header.size
+				+ s->block.compressed;
+
+#ifdef XZ_DEC_ANY_CHECK
+		s->block.hash.unpadded += check_sizes[s->check_type];
+#else
+		if (s->check_type == XZ_CHECK_CRC32)
+			s->block.hash.unpadded += 4;
+#endif
+
+		s->block.hash.uncompressed += s->block.uncompressed;
+		s->block.hash.crc32 = xz_crc32(
+				(const uint8_t *)&s->block.hash,
+				sizeof(s->block.hash), s->block.hash.crc32);
+
+		++s->block.count;
+	}
+
+	return ret;
+}
+
+/* Update the Index size and the CRC32 value. */
+static void index_update(struct xz_dec *s, const struct xz_buf *b)
+{
+	size_t in_used = b->in_pos - s->in_start;
+	s->index.size += in_used;
+	s->crc32 = xz_crc32(b->in + s->in_start, in_used, s->crc32);
+}
+
+/*
+ * Decode the Number of Records, Unpadded Size, and Uncompressed Size
+ * fields from the Index field. That is, Index Padding and CRC32 are not
+ * decoded by this function.
+ *
+ * This can return XZ_OK (more input needed), XZ_STREAM_END (everything
+ * successfully decoded), or XZ_DATA_ERROR (input is corrupt).
+ */
+static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b)
+{
+	enum xz_ret ret;
+
+	do {
+		ret = dec_vli(s, b->in, &b->in_pos, b->in_size);
+		if (ret != XZ_STREAM_END) {
+			index_update(s, b);
+			return ret;
+		}
+
+		switch (s->index.sequence) {
+		case SEQ_INDEX_COUNT:
+			s->index.count = s->vli;
+
+			/*
+			 * Validate that the Number of Records field
+			 * indicates the same number of Records as
+			 * there were Blocks in the Stream.
+			 */
+			if (s->index.count != s->block.count)
+				return XZ_DATA_ERROR;
+
+			s->index.sequence = SEQ_INDEX_UNPADDED;
+			break;
+
+		case SEQ_INDEX_UNPADDED:
+			s->index.hash.unpadded += s->vli;
+			s->index.sequence = SEQ_INDEX_UNCOMPRESSED;
+			break;
+
+		case SEQ_INDEX_UNCOMPRESSED:
+			s->index.hash.uncompressed += s->vli;
+			s->index.hash.crc32 = xz_crc32(
+					(const uint8_t *)&s->index.hash,
+					sizeof(s->index.hash),
+					s->index.hash.crc32);
+			--s->index.count;
+			s->index.sequence = SEQ_INDEX_UNPADDED;
+			break;
+		}
+	} while (s->index.count > 0);
+
+	return XZ_STREAM_END;
+}
+
+/*
+ * Validate that the next four input bytes match the value of s->crc32.
+ * s->pos must be zero when starting to validate the first byte.
+ */
+static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b)
+{
+	do {
+		if (b->in_pos == b->in_size)
+			return XZ_OK;
+
+		if (((s->crc32 >> s->pos) & 0xFF) != b->in[b->in_pos++])
+			return XZ_DATA_ERROR;
+
+		s->pos += 8;
+
+	} while (s->pos < 32);
+
+	s->crc32 = 0;
+	s->pos = 0;
+
+	return XZ_STREAM_END;
+}
+
+#ifdef XZ_DEC_ANY_CHECK
+/*
+ * Skip over the Check field when the Check ID is not supported.
+ * Returns true once the whole Check field has been skipped over.
+ */
+static bool check_skip(struct xz_dec *s, struct xz_buf *b)
+{
+	while (s->pos < check_sizes[s->check_type]) {
+		if (b->in_pos == b->in_size)
+			return false;
+
+		++b->in_pos;
+		++s->pos;
+	}
+
+	s->pos = 0;
+
+	return true;
+}
+#endif
+
+/* Decode the Stream Header field (the first 12 bytes of the .xz Stream). */
+static enum xz_ret dec_stream_header(struct xz_dec *s)
+{
+	if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE))
+		return XZ_FORMAT_ERROR;
+
+	if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0)
+			!= get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2))
+		return XZ_DATA_ERROR;
+
+	if (s->temp.buf[HEADER_MAGIC_SIZE] != 0)
+		return XZ_OPTIONS_ERROR;
+
+	/*
+	 * Of integrity checks, we support only none (Check ID = 0) and
+	 * CRC32 (Check ID = 1). However, if XZ_DEC_ANY_CHECK is defined,
+	 * we will accept other check types too, but then the check won't
+	 * be verified and a warning (XZ_UNSUPPORTED_CHECK) will be given.
+	 */
+	s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1];
+
+#ifdef XZ_DEC_ANY_CHECK
+	if (s->check_type > XZ_CHECK_MAX)
+		return XZ_OPTIONS_ERROR;
+
+	if (s->check_type > XZ_CHECK_CRC32)
+		return XZ_UNSUPPORTED_CHECK;
+#else
+	if (s->check_type > XZ_CHECK_CRC32)
+		return XZ_OPTIONS_ERROR;
+#endif
+
+	return XZ_OK;
+}
+
+/* Decode the Stream Footer field (the last 12 bytes of the .xz Stream) */
+static enum xz_ret dec_stream_footer(struct xz_dec *s)
+{
+	if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE))
+		return XZ_DATA_ERROR;
+
+	if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf))
+		return XZ_DATA_ERROR;
+
+	/*
+	 * Validate Backward Size. Note that we never added the size of the
+	 * Index CRC32 field to s->index.size, thus we use s->index.size / 4
+	 * instead of s->index.size / 4 - 1.
+	 */
+	if ((s->index.size >> 2) != get_le32(s->temp.buf + 4))
+		return XZ_DATA_ERROR;
+
+	if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type)
+		return XZ_DATA_ERROR;
+
+	/*
+	 * Use XZ_STREAM_END instead of XZ_OK to be more convenient
+	 * for the caller.
+	 */
+	return XZ_STREAM_END;
+}
+
+/* Decode the Block Header and initialize the filter chain. */
+static enum xz_ret dec_block_header(struct xz_dec *s)
+{
+	enum xz_ret ret;
+
+	/*
+	 * Validate the CRC32. We know that the temp buffer is at least
+	 * eight bytes so this is safe.
+	 */
+	s->temp.size -= 4;
+	if (xz_crc32(s->temp.buf, s->temp.size, 0)
+			!= get_le32(s->temp.buf + s->temp.size))
+		return XZ_DATA_ERROR;
+
+	s->temp.pos = 2;
+
+	/*
+	 * Catch unsupported Block Flags. We support only one or two filters
+	 * in the chain, so we catch that with the same test.
+	 */
+#ifdef XZ_DEC_BCJ
+	if (s->temp.buf[1] & 0x3E)
+#else
+	if (s->temp.buf[1] & 0x3F)
+#endif
+		return XZ_OPTIONS_ERROR;
+
+	/* Compressed Size */
+	if (s->temp.buf[1] & 0x40) {
+		if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
+					!= XZ_STREAM_END)
+			return XZ_DATA_ERROR;
+
+		s->block_header.compressed = s->vli;
+	} else {
+		s->block_header.compressed = VLI_UNKNOWN;
+	}
+
+	/* Uncompressed Size */
+	if (s->temp.buf[1] & 0x80) {
+		if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size)
+				!= XZ_STREAM_END)
+			return XZ_DATA_ERROR;
+
+		s->block_header.uncompressed = s->vli;
+	} else {
+		s->block_header.uncompressed = VLI_UNKNOWN;
+	}
+
+#ifdef XZ_DEC_BCJ
+	/* If there are two filters, the first one must be a BCJ filter. */
+	s->bcj_active = s->temp.buf[1] & 0x01;
+	if (s->bcj_active) {
+		if (s->temp.size - s->temp.pos < 2)
+			return XZ_OPTIONS_ERROR;
+
+		ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]);
+		if (ret != XZ_OK)
+			return ret;
+
+		/*
+		 * We don't support custom start offset,
+		 * so Size of Properties must be zero.
+		 */
+		if (s->temp.buf[s->temp.pos++] != 0x00)
+			return XZ_OPTIONS_ERROR;
+	}
+#endif
+
+	/* Valid Filter Flags always take at least two bytes. */
+	if (s->temp.size - s->temp.pos < 2)
+		return XZ_DATA_ERROR;
+
+	/* Filter ID = LZMA2 */
+	if (s->temp.buf[s->temp.pos++] != 0x21)
+		return XZ_OPTIONS_ERROR;
+
+	/* Size of Properties = 1-byte Filter Properties */
+	if (s->temp.buf[s->temp.pos++] != 0x01)
+		return XZ_OPTIONS_ERROR;
+
+	/* Filter Properties contains LZMA2 dictionary size. */
+	if (s->temp.size - s->temp.pos < 1)
+		return XZ_DATA_ERROR;
+
+	ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]);
+	if (ret != XZ_OK)
+		return ret;
+
+	/* The rest must be Header Padding. */
+	while (s->temp.pos < s->temp.size)
+		if (s->temp.buf[s->temp.pos++] != 0x00)
+			return XZ_OPTIONS_ERROR;
+
+	s->temp.pos = 0;
+	s->block.compressed = 0;
+	s->block.uncompressed = 0;
+
+	return XZ_OK;
+}
+
+static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
+{
+	enum xz_ret ret;
+
+	/*
+	 * Store the start position for the case when we are in the middle
+	 * of the Index field.
+	 */
+	s->in_start = b->in_pos;
+
+	while (true) {
+		switch (s->sequence) {
+		case SEQ_STREAM_HEADER:
+			/*
+			 * Stream Header is copied to s->temp, and then
+			 * decoded from there. This way if the caller
+			 * gives us only little input at a time, we can
+			 * still keep the Stream Header decoding code
+			 * simple. Similar approach is used in many places
+			 * in this file.
+			 */
+			if (!fill_temp(s, b))
+				return XZ_OK;
+
+			/*
+			 * If dec_stream_header() returns
+			 * XZ_UNSUPPORTED_CHECK, it is still possible
+			 * to continue decoding if working in multi-call
+			 * mode. Thus, update s->sequence before calling
+			 * dec_stream_header().
+			 */
+			s->sequence = SEQ_BLOCK_START;
+
+			ret = dec_stream_header(s);
+			if (ret != XZ_OK)
+				return ret;
+
+		case SEQ_BLOCK_START:
+			/* We need one byte of input to continue. */
+			if (b->in_pos == b->in_size)
+				return XZ_OK;
+
+			/* See if this is the beginning of the Index field. */
+			if (b->in[b->in_pos] == 0) {
+				s->in_start = b->in_pos++;
+				s->sequence = SEQ_INDEX;
+				break;
+			}
+
+			/*
+			 * Calculate the size of the Block Header and
+			 * prepare to decode it.
+			 */
+			s->block_header.size
+				= ((uint32_t)b->in[b->in_pos] + 1) * 4;
+
+			s->temp.size = s->block_header.size;
+			s->temp.pos = 0;
+			s->sequence = SEQ_BLOCK_HEADER;
+
+		case SEQ_BLOCK_HEADER:
+			if (!fill_temp(s, b))
+				return XZ_OK;
+
+			ret = dec_block_header(s);
+			if (ret != XZ_OK)
+				return ret;
+
+			s->sequence = SEQ_BLOCK_UNCOMPRESS;
+
+		case SEQ_BLOCK_UNCOMPRESS:
+			ret = dec_block(s, b);
+			if (ret != XZ_STREAM_END)
+				return ret;
+
+			s->sequence = SEQ_BLOCK_PADDING;
+
+		case SEQ_BLOCK_PADDING:
+			/*
+			 * Size of Compressed Data + Block Padding
+			 * must be a multiple of four. We don't need
+			 * s->block.compressed for anything else
+			 * anymore, so we use it here to test the size
+			 * of the Block Padding field.
+			 */
+			while (s->block.compressed & 3) {
+				if (b->in_pos == b->in_size)
+					return XZ_OK;
+
+				if (b->in[b->in_pos++] != 0)
+					return XZ_DATA_ERROR;
+
+				++s->block.compressed;
+			}
+
+			s->sequence = SEQ_BLOCK_CHECK;
+
+		case SEQ_BLOCK_CHECK:
+			if (s->check_type == XZ_CHECK_CRC32) {
+				ret = crc32_validate(s, b);
+				if (ret != XZ_STREAM_END)
+					return ret;
+			}
+#ifdef XZ_DEC_ANY_CHECK
+			else if (!check_skip(s, b)) {
+				return XZ_OK;
+			}
+#endif
+
+			s->sequence = SEQ_BLOCK_START;
+			break;
+
+		case SEQ_INDEX:
+			ret = dec_index(s, b);
+			if (ret != XZ_STREAM_END)
+				return ret;
+
+			s->sequence = SEQ_INDEX_PADDING;
+
+		case SEQ_INDEX_PADDING:
+			while ((s->index.size + (b->in_pos - s->in_start))
+					& 3) {
+				if (b->in_pos == b->in_size) {
+					index_update(s, b);
+					return XZ_OK;
+				}
+
+				if (b->in[b->in_pos++] != 0)
+					return XZ_DATA_ERROR;
+			}
+
+			/* Finish the CRC32 value and Index size. */
+			index_update(s, b);
+
+			/* Compare the hashes to validate the Index field. */
+			if (!memeq(&s->block.hash, &s->index.hash,
+					sizeof(s->block.hash)))
+				return XZ_DATA_ERROR;
+
+			s->sequence = SEQ_INDEX_CRC32;
+
+		case SEQ_INDEX_CRC32:
+			ret = crc32_validate(s, b);
+			if (ret != XZ_STREAM_END)
+				return ret;
+
+			s->temp.size = STREAM_HEADER_SIZE;
+			s->sequence = SEQ_STREAM_FOOTER;
+
+		case SEQ_STREAM_FOOTER:
+			if (!fill_temp(s, b))
+				return XZ_OK;
+
+			return dec_stream_footer(s);
+		}
+	}
+
+	/* Never reached */
+}
+
+/*
+ * xz_dec_run() is a wrapper for dec_main() to handle some special cases in
+ * multi-call and single-call decoding.
+ *
+ * In multi-call mode, we must return XZ_BUF_ERROR when it seems clear that we
+ * are not going to make any progress anymore. This is to prevent the caller
+ * from calling us infinitely when the input file is truncated or otherwise
+ * corrupt. Since zlib-style API allows that the caller fills the input buffer
+ * only when the decoder doesn't produce any new output, we have to be careful
+ * to avoid returning XZ_BUF_ERROR too easily: XZ_BUF_ERROR is returned only
+ * after the second consecutive call to xz_dec_run() that makes no progress.
+ *
+ * In single-call mode, if we couldn't decode everything and no error
+ * occurred, either the input is truncated or the output buffer is too small.
+ * Since we know that the last input byte never produces any output, we know
+ * that if all the input was consumed and decoding wasn't finished, the file
+ * must be corrupt. Otherwise the output buffer has to be too small or the
+ * file is corrupt in a way that decoding it produces too big output.
+ *
+ * If single-call decoding fails, we reset b->in_pos and b->out_pos back to
+ * their original values. This is because with some filter chains there won't
+ * be any valid uncompressed data in the output buffer unless the decoding
+ * actually succeeds (that's the price to pay of using the output buffer as
+ * the workspace).
+ */
+XZ_EXTERN enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b)
+{
+	size_t in_start;
+	size_t out_start;
+	enum xz_ret ret;
+
+	if (DEC_IS_SINGLE(s->mode))
+		xz_dec_reset(s);
+
+	in_start = b->in_pos;
+	out_start = b->out_pos;
+	ret = dec_main(s, b);
+
+	if (DEC_IS_SINGLE(s->mode)) {
+		if (ret == XZ_OK)
+			ret = b->in_pos == b->in_size
+					? XZ_DATA_ERROR : XZ_BUF_ERROR;
+
+		if (ret != XZ_STREAM_END) {
+			b->in_pos = in_start;
+			b->out_pos = out_start;
+		}
+
+	} else if (ret == XZ_OK && in_start == b->in_pos
+			&& out_start == b->out_pos) {
+		if (s->allow_buf_error)
+			ret = XZ_BUF_ERROR;
+
+		s->allow_buf_error = true;
+	} else {
+		s->allow_buf_error = false;
+	}
+
+	return ret;
+}
+
+XZ_EXTERN struct xz_dec *xz_dec_init(enum xz_mode mode, uint32_t dict_max)
+{
+	struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL);
+	if (s == NULL)
+		return NULL;
+
+	s->mode = mode;
+
+#ifdef XZ_DEC_BCJ
+	s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode));
+	if (s->bcj == NULL)
+		goto error_bcj;
+#endif
+
+	s->lzma2 = xz_dec_lzma2_create(mode, dict_max);
+	if (s->lzma2 == NULL)
+		goto error_lzma2;
+
+	xz_dec_reset(s);
+	return s;
+
+error_lzma2:
+#ifdef XZ_DEC_BCJ
+	xz_dec_bcj_end(s->bcj);
+error_bcj:
+#endif
+	kfree(s);
+	return NULL;
+}
+
+XZ_EXTERN void xz_dec_reset(struct xz_dec *s)
+{
+	s->sequence = SEQ_STREAM_HEADER;
+	s->allow_buf_error = false;
+	s->pos = 0;
+	s->crc32 = 0;
+	memzero(&s->block, sizeof(s->block));
+	memzero(&s->index, sizeof(s->index));
+	s->temp.pos = 0;
+	s->temp.size = STREAM_HEADER_SIZE;
+}
+
+XZ_EXTERN void xz_dec_end(struct xz_dec *s)
+{
+	if (s != NULL) {
+		xz_dec_lzma2_end(s->lzma2);
+#ifdef XZ_DEC_BCJ
+		xz_dec_bcj_end(s->bcj);
+#endif
+		kfree(s);
+	}
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_syms.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_syms.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,26 @@
+/*
+ * XZ decoder module information
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include <linux/module.h>
+#include <linux/xz.h>
+
+EXPORT_SYMBOL(xz_dec_init);
+EXPORT_SYMBOL(xz_dec_reset);
+EXPORT_SYMBOL(xz_dec_run);
+EXPORT_SYMBOL(xz_dec_end);
+
+MODULE_DESCRIPTION("XZ decompressor");
+MODULE_VERSION("1.0");
+MODULE_AUTHOR("Lasse Collin <lasse.collin at tukaani.org> and Igor Pavlov");
+
+/*
+ * This code is in the public domain, but in Linux it's simplest to just
+ * say it's GPL and consider the authors as the copyright holders.
+ */
+MODULE_LICENSE("GPL");
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_test.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_dec_test.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,220 @@
+/*
+ * XZ decoder tester
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/uaccess.h>
+#include <linux/crc32.h>
+#include <linux/xz.h>
+
+/* Maximum supported dictionary size */
+#define DICT_MAX (1 << 20)
+
+/* Device name to pass to register_chrdev(). */
+#define DEVICE_NAME "xz_dec_test"
+
+/* Dynamically allocated device major number */
+static int device_major;
+
+/*
+ * We reuse the same decoder state, and thus can decode only one
+ * file at a time.
+ */
+static bool device_is_open;
+
+/* XZ decoder state */
+static struct xz_dec *state;
+
+/*
+ * Return value of xz_dec_run(). We need to avoid calling xz_dec_run() after
+ * it has returned XZ_STREAM_END, so we make this static.
+ */
+static enum xz_ret ret;
+
+/*
+ * Input and output buffers. The input buffer is used as a temporary safe
+ * place for the data coming from the userspace.
+ */
+static uint8_t buffer_in[1024];
+static uint8_t buffer_out[1024];
+
+/*
+ * Structure to pass the input and output buffers to the XZ decoder.
+ * A few of the fields are never modified so we initialize them here.
+ */
+static struct xz_buf buffers = {
+	.in = buffer_in,
+	.out = buffer_out,
+	.out_size = sizeof(buffer_out)
+};
+
+/*
+ * CRC32 of uncompressed data. This is used to give the user a simple way
+ * to check that the decoder produces correct output.
+ */
+static uint32_t crc;
+
+static int xz_dec_test_open(struct inode *i, struct file *f)
+{
+	if (device_is_open)
+		return -EBUSY;
+
+	device_is_open = true;
+
+	xz_dec_reset(state);
+	ret = XZ_OK;
+	crc = 0xFFFFFFFF;
+
+	buffers.in_pos = 0;
+	buffers.in_size = 0;
+	buffers.out_pos = 0;
+
+	printk(KERN_INFO DEVICE_NAME ": opened\n");
+	return 0;
+}
+
+static int xz_dec_test_release(struct inode *i, struct file *f)
+{
+	device_is_open = false;
+
+	if (ret == XZ_OK)
+		printk(KERN_INFO DEVICE_NAME ": input was truncated\n");
+
+	printk(KERN_INFO DEVICE_NAME ": closed\n");
+	return 0;
+}
+
+/*
+ * Decode the data given to us from the userspace. CRC32 of the uncompressed
+ * data is calculated and is printed at the end of successful decoding. The
+ * uncompressed data isn't stored anywhere for further use.
+ *
+ * The .xz file must have exactly one Stream and no Stream Padding. The data
+ * after the first Stream is considered to be garbage.
+ */
+static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
+				 size_t size, loff_t *pos)
+{
+	size_t remaining;
+
+	if (ret != XZ_OK) {
+		if (size > 0)
+			printk(KERN_INFO DEVICE_NAME ": %zu bytes of "
+					"garbage at the end of the file\n",
+					size);
+
+		return -ENOSPC;
+	}
+
+	printk(KERN_INFO DEVICE_NAME ": decoding %zu bytes of input\n",
+			size);
+
+	remaining = size;
+	while ((remaining > 0 || buffers.out_pos == buffers.out_size)
+			&& ret == XZ_OK) {
+		if (buffers.in_pos == buffers.in_size) {
+			buffers.in_pos = 0;
+			buffers.in_size = min(remaining, sizeof(buffer_in));
+			if (copy_from_user(buffer_in, buf, buffers.in_size))
+				return -EFAULT;
+
+			buf += buffers.in_size;
+			remaining -= buffers.in_size;
+		}
+
+		buffers.out_pos = 0;
+		ret = xz_dec_run(state, &buffers);
+		crc = crc32(crc, buffer_out, buffers.out_pos);
+	}
+
+	switch (ret) {
+	case XZ_OK:
+		printk(KERN_INFO DEVICE_NAME ": XZ_OK\n");
+		return size;
+
+	case XZ_STREAM_END:
+		printk(KERN_INFO DEVICE_NAME ": XZ_STREAM_END, "
+				"CRC32 = 0x%08X\n", ~crc);
+		return size - remaining - (buffers.in_size - buffers.in_pos);
+
+	case XZ_MEMLIMIT_ERROR:
+		printk(KERN_INFO DEVICE_NAME ": XZ_MEMLIMIT_ERROR\n");
+		break;
+
+	case XZ_FORMAT_ERROR:
+		printk(KERN_INFO DEVICE_NAME ": XZ_FORMAT_ERROR\n");
+		break;
+
+	case XZ_OPTIONS_ERROR:
+		printk(KERN_INFO DEVICE_NAME ": XZ_OPTIONS_ERROR\n");
+		break;
+
+	case XZ_DATA_ERROR:
+		printk(KERN_INFO DEVICE_NAME ": XZ_DATA_ERROR\n");
+		break;
+
+	case XZ_BUF_ERROR:
+		printk(KERN_INFO DEVICE_NAME ": XZ_BUF_ERROR\n");
+		break;
+
+	default:
+		printk(KERN_INFO DEVICE_NAME ": Bug detected!\n");
+		break;
+	}
+
+	return -EIO;
+}
+
+/* Allocate the XZ decoder state and register the character device. */
+static int __init xz_dec_test_init(void)
+{
+	static const struct file_operations fileops = {
+		.owner = THIS_MODULE,
+		.open = &xz_dec_test_open,
+		.release = &xz_dec_test_release,
+		.write = &xz_dec_test_write
+	};
+
+	state = xz_dec_init(XZ_PREALLOC, DICT_MAX);
+	if (state == NULL)
+		return -ENOMEM;
+
+	device_major = register_chrdev(0, DEVICE_NAME, &fileops);
+	if (device_major < 0) {
+		xz_dec_end(state);
+		return device_major;
+	}
+
+	printk(KERN_INFO DEVICE_NAME ": module loaded\n");
+	printk(KERN_INFO DEVICE_NAME ": Create a device node with "
+			"'mknod " DEVICE_NAME " c %d 0' and write .xz files "
+			"to it.\n", device_major);
+	return 0;
+}
+
+static void __exit xz_dec_test_exit(void)
+{
+	unregister_chrdev(device_major, DEVICE_NAME);
+	xz_dec_end(state);
+	printk(KERN_INFO DEVICE_NAME ": module unloaded\n");
+}
+
+module_init(xz_dec_test_init);
+module_exit(xz_dec_test_exit);
+
+MODULE_DESCRIPTION("XZ decompressor tester");
+MODULE_VERSION("1.0");
+MODULE_AUTHOR("Lasse Collin <lasse.collin at tukaani.org>");
+
+/*
+ * This code is in the public domain, but in Linux it's simplest to just
+ * say it's GPL and consider the authors as the copyright holders.
+ */
+MODULE_LICENSE("GPL");
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_lzma2.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_lzma2.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,204 @@
+/*
+ * LZMA2 definitions
+ *
+ * Authors: Lasse Collin <lasse.collin at tukaani.org>
+ *          Igor Pavlov <http://7-zip.org/>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef XZ_LZMA2_H
+#define XZ_LZMA2_H
+
+/* Range coder constants */
+#define RC_SHIFT_BITS 8
+#define RC_TOP_BITS 24
+#define RC_TOP_VALUE (1 << RC_TOP_BITS)
+#define RC_BIT_MODEL_TOTAL_BITS 11
+#define RC_BIT_MODEL_TOTAL (1 << RC_BIT_MODEL_TOTAL_BITS)
+#define RC_MOVE_BITS 5
+
+/*
+ * Maximum number of position states. A position state is the lowest pb
+ * number of bits of the current uncompressed offset. In some places there
+ * are different sets of probabilities for different position states.
+ */
+#define POS_STATES_MAX (1 << 4)
+
+/*
+ * This enum is used to track which LZMA symbols have occurred most recently
+ * and in which order. This information is used to predict the next symbol.
+ *
+ * Symbols:
+ *  - Literal: One 8-bit byte
+ *  - Match: Repeat a chunk of data at some distance
+ *  - Long repeat: Multi-byte match at a recently seen distance
+ *  - Short repeat: One-byte repeat at a recently seen distance
+ *
+ * The symbol names are in from STATE_oldest_older_previous. REP means
+ * either short or long repeated match, and NONLIT means any non-literal.
+ */
+enum lzma_state {
+	STATE_LIT_LIT,
+	STATE_MATCH_LIT_LIT,
+	STATE_REP_LIT_LIT,
+	STATE_SHORTREP_LIT_LIT,
+	STATE_MATCH_LIT,
+	STATE_REP_LIT,
+	STATE_SHORTREP_LIT,
+	STATE_LIT_MATCH,
+	STATE_LIT_LONGREP,
+	STATE_LIT_SHORTREP,
+	STATE_NONLIT_MATCH,
+	STATE_NONLIT_REP
+};
+
+/* Total number of states */
+#define STATES 12
+
+/* The lowest 7 states indicate that the previous state was a literal. */
+#define LIT_STATES 7
+
+/* Indicate that the latest symbol was a literal. */
+static inline void lzma_state_literal(enum lzma_state *state)
+{
+	if (*state <= STATE_SHORTREP_LIT_LIT)
+		*state = STATE_LIT_LIT;
+	else if (*state <= STATE_LIT_SHORTREP)
+		*state -= 3;
+	else
+		*state -= 6;
+}
+
+/* Indicate that the latest symbol was a match. */
+static inline void lzma_state_match(enum lzma_state *state)
+{
+	*state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH;
+}
+
+/* Indicate that the latest state was a long repeated match. */
+static inline void lzma_state_long_rep(enum lzma_state *state)
+{
+	*state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
+}
+
+/* Indicate that the latest symbol was a short match. */
+static inline void lzma_state_short_rep(enum lzma_state *state)
+{
+	*state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
+}
+
+/* Test if the previous symbol was a literal. */
+static inline bool lzma_state_is_literal(enum lzma_state state)
+{
+	return state < LIT_STATES;
+}
+
+/* Each literal coder is divided in three sections:
+ *   - 0x001-0x0FF: Without match byte
+ *   - 0x101-0x1FF: With match byte; match bit is 0
+ *   - 0x201-0x2FF: With match byte; match bit is 1
+ *
+ * Match byte is used when the previous LZMA symbol was something else than
+ * a literal (that is, it was some kind of match).
+ */
+#define LITERAL_CODER_SIZE 0x300
+
+/* Maximum number of literal coders */
+#define LITERAL_CODERS_MAX (1 << 4)
+
+/* Minimum length of a match is two bytes. */
+#define MATCH_LEN_MIN 2
+
+/* Match length is encoded with 4, 5, or 10 bits.
+ *
+ * Length   Bits
+ *  2-9      4 = Choice=0 + 3 bits
+ * 10-17     5 = Choice=1 + Choice2=0 + 3 bits
+ * 18-273   10 = Choice=1 + Choice2=1 + 8 bits
+ */
+#define LEN_LOW_BITS 3
+#define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
+#define LEN_MID_BITS 3
+#define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
+#define LEN_HIGH_BITS 8
+#define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
+#define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
+
+/*
+ * Maximum length of a match is 273 which is a result of the encoding
+ * described above.
+ */
+#define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
+
+/*
+ * Different sets of probabilities are used for match distances that have
+ * very short match length: Lengths of 2, 3, and 4 bytes have a separate
+ * set of probabilities for each length. The matches with longer length
+ * use a shared set of probabilities.
+ */
+#define DIST_STATES 4
+
+/*
+ * Get the index of the appropriate probability array for decoding
+ * the distance slot.
+ */
+static inline uint32_t lzma_get_dist_state(uint32_t len)
+{
+	return len < DIST_STATES + MATCH_LEN_MIN
+			? len - MATCH_LEN_MIN : DIST_STATES - 1;
+}
+
+/*
+ * The highest two bits of a 32-bit match distance are encoded using six bits.
+ * This six-bit value is called a distance slot. This way encoding a 32-bit
+ * value takes 6-36 bits, larger values taking more bits.
+ */
+#define DIST_SLOT_BITS 6
+#define DIST_SLOTS (1 << DIST_SLOT_BITS)
+
+/* Match distances up to 127 are fully encoded using probabilities. Since
+ * the highest two bits (distance slot) are always encoded using six bits,
+ * the distances 0-3 don't need any additional bits to encode, since the
+ * distance slot itself is the same as the actual distance. DIST_MODEL_START
+ * indicates the first distance slot where at least one additional bit is
+ * needed.
+ */
+#define DIST_MODEL_START 4
+
+/*
+ * Match distances greater than 127 are encoded in three pieces:
+ *   - distance slot: the highest two bits
+ *   - direct bits: 2-26 bits below the highest two bits
+ *   - alignment bits: four lowest bits
+ *
+ * Direct bits don't use any probabilities.
+ *
+ * The distance slot value of 14 is for distances 128-191.
+ */
+#define DIST_MODEL_END 14
+
+/* Distance slots that indicate a distance <= 127. */
+#define FULL_DISTANCES_BITS (DIST_MODEL_END / 2)
+#define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
+
+/*
+ * For match distances greater than 127, only the highest two bits and the
+ * lowest four bits (alignment) is encoded using probabilities.
+ */
+#define ALIGN_BITS 4
+#define ALIGN_SIZE (1 << ALIGN_BITS)
+#define ALIGN_MASK (ALIGN_SIZE - 1)
+
+/* Total number of all probability variables */
+#define PROBS_TOTAL (1846 + LITERAL_CODERS_MAX * LITERAL_CODER_SIZE)
+
+/*
+ * LZMA remembers the four most recent match distances. Reusing these
+ * distances tends to take less space than re-encoding the actual
+ * distance value.
+ */
+#define REPS 4
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_private.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_private.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,156 @@
+/*
+ * Private includes and definitions
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef XZ_PRIVATE_H
+#define XZ_PRIVATE_H
+
+#ifdef __KERNEL__
+#	include <linux/xz.h>
+#	include <linux/kernel.h>
+#	include <asm/unaligned.h>
+	/* XZ_PREBOOT may be defined only via decompress_unxz.c. */
+#	ifndef XZ_PREBOOT
+#		include <linux/slab.h>
+#		include <linux/vmalloc.h>
+#		include <linux/string.h>
+#		ifdef CONFIG_XZ_DEC_X86
+#			define XZ_DEC_X86
+#		endif
+#		ifdef CONFIG_XZ_DEC_POWERPC
+#			define XZ_DEC_POWERPC
+#		endif
+#		ifdef CONFIG_XZ_DEC_IA64
+#			define XZ_DEC_IA64
+#		endif
+#		ifdef CONFIG_XZ_DEC_ARM
+#			define XZ_DEC_ARM
+#		endif
+#		ifdef CONFIG_XZ_DEC_ARMTHUMB
+#			define XZ_DEC_ARMTHUMB
+#		endif
+#		ifdef CONFIG_XZ_DEC_SPARC
+#			define XZ_DEC_SPARC
+#		endif
+#		define memeq(a, b, size) (memcmp(a, b, size) == 0)
+#		define memzero(buf, size) memset(buf, 0, size)
+#	endif
+#	define get_le32(p) le32_to_cpup((const uint32_t *)(p))
+#else
+	/*
+	 * For userspace builds, use a separate header to define the required
+	 * macros and functions. This makes it easier to adapt the code into
+	 * different environments and avoids clutter in the Linux kernel tree.
+	 */
+#	include <contrib/xz-embedded/freebsd/xz_config.h>
+#endif
+
+/* If no specific decoding mode is requested, enable support for all modes. */
+#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
+		&& !defined(XZ_DEC_DYNALLOC)
+#	define XZ_DEC_SINGLE
+#	define XZ_DEC_PREALLOC
+#	define XZ_DEC_DYNALLOC
+#endif
+
+/*
+ * The DEC_IS_foo(mode) macros are used in "if" statements. If only some
+ * of the supported modes are enabled, these macros will evaluate to true or
+ * false at compile time and thus allow the compiler to omit unneeded code.
+ */
+#ifdef XZ_DEC_SINGLE
+#	define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
+#else
+#	define DEC_IS_SINGLE(mode) (false)
+#endif
+
+#ifdef XZ_DEC_PREALLOC
+#	define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
+#else
+#	define DEC_IS_PREALLOC(mode) (false)
+#endif
+
+#ifdef XZ_DEC_DYNALLOC
+#	define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
+#else
+#	define DEC_IS_DYNALLOC(mode) (false)
+#endif
+
+#if !defined(XZ_DEC_SINGLE)
+#	define DEC_IS_MULTI(mode) (true)
+#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
+#	define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
+#else
+#	define DEC_IS_MULTI(mode) (false)
+#endif
+
+/*
+ * If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
+ * XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
+ */
+#ifndef XZ_DEC_BCJ
+#	if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
+			|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
+			|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
+			|| defined(XZ_DEC_SPARC)
+#		define XZ_DEC_BCJ
+#	endif
+#endif
+
+/*
+ * Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
+ * before calling xz_dec_lzma2_run().
+ */
+XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
+						   uint32_t dict_max);
+
+/*
+ * Decode the LZMA2 properties (one byte) and reset the decoder. Return
+ * XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
+ * big enough, and XZ_OPTIONS_ERROR if props indicates something that this
+ * decoder doesn't support.
+ */
+XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
+					 uint8_t props);
+
+/* Decode raw LZMA2 stream from b->in to b->out. */
+XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
+				       struct xz_buf *b);
+
+/* Free the memory allocated for the LZMA2 decoder. */
+XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
+
+#ifdef XZ_DEC_BCJ
+/*
+ * Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
+ * calling xz_dec_bcj_run().
+ */
+XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call);
+
+/*
+ * Decode the Filter ID of a BCJ filter. This implementation doesn't
+ * support custom start offsets, so no decoding of Filter Properties
+ * is needed. Returns XZ_OK if the given Filter ID is supported.
+ * Otherwise XZ_OPTIONS_ERROR is returned.
+ */
+XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
+
+/*
+ * Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
+ * a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
+ * must be called directly.
+ */
+XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
+				     struct xz_dec_lzma2 *lzma2,
+				     struct xz_buf *b);
+
+/* Free the memory allocated for the BCJ filters. */
+#define xz_dec_bcj_end(s) kfree(s)
+#endif
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/lib/xz/xz_stream.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/lib/xz/xz_stream.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,62 @@
+/*
+ * Definitions for handling the .xz file format
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef XZ_STREAM_H
+#define XZ_STREAM_H
+
+#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
+#	include <linux/crc32.h>
+#	undef crc32
+#	define xz_crc32(buf, size, crc) \
+		(~crc32_le(~(uint32_t)(crc), buf, size))
+#endif
+
+/*
+ * See the .xz file format specification at
+ * http://tukaani.org/xz/xz-file-format.txt
+ * to understand the container format.
+ */
+
+#define STREAM_HEADER_SIZE 12
+
+#define HEADER_MAGIC "\3757zXZ"
+#define HEADER_MAGIC_SIZE 6
+
+#define FOOTER_MAGIC "YZ"
+#define FOOTER_MAGIC_SIZE 2
+
+/*
+ * Variable-length integer can hold a 63-bit unsigned integer or a special
+ * value indicating that the value is unknown.
+ *
+ * Experimental: vli_type can be defined to uint32_t to save a few bytes
+ * in code size (no effect on speed). Doing so limits the uncompressed and
+ * compressed size of the file to less than 256 MiB and may also weaken
+ * error detection slightly.
+ */
+typedef uint64_t vli_type;
+
+#define VLI_MAX ((vli_type)-1 / 2)
+#define VLI_UNKNOWN ((vli_type)-1)
+
+/* Maximum encoded size of a VLI */
+#define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7)
+
+/* Integrity Check types */
+enum xz_check {
+	XZ_CHECK_NONE = 0,
+	XZ_CHECK_CRC32 = 1,
+	XZ_CHECK_CRC64 = 4,
+	XZ_CHECK_SHA256 = 10
+};
+
+/* Maximum possible Check ID */
+#define XZ_CHECK_MAX 15
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/linux/scripts/xz_wrap.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/linux/scripts/xz_wrap.sh	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# This is a wrapper for xz to compress the kernel image using appropriate
+# compression options depending on the architecture.
+#
+# Author: Lasse Collin <lasse.collin at tukaani.org>
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+
+BCJ=
+LZMA2OPTS=
+
+case $ARCH in
+	x86|x86_64)     BCJ=--x86 ;;
+	powerpc)        BCJ=--powerpc ;;
+	ia64)           BCJ=--ia64; LZMA2OPTS=pb=4 ;;
+	arm)            BCJ=--arm ;;
+	sparc)          BCJ=--sparc ;;
+esac
+
+exec xz --check=crc32 $BCJ --lzma2=$LZMA2OPTS,dict=32MiB
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/userspace/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/userspace/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,48 @@
+#
+# Makefile
+#
+# Author: Lasse Collin <lasse.collin at tukaani.org>
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+
+CC = gcc -std=gnu89
+BCJ_CPPFLAGS = -DXZ_DEC_X86 -DXZ_DEC_POWERPC -DXZ_DEC_IA64 \
+		-DXZ_DEC_ARM -DXZ_DEC_ARMTHUMB -DXZ_DEC_SPARC
+CPPFLAGS = -DXZ_DEC_ANY_CHECK
+CFLAGS = -ggdb3 -O2 -pedantic -Wall -Wextra
+RM = rm -f
+VPATH = ../linux/include/linux ../linux/lib/xz
+COMMON_SRCS = xz_crc32.c xz_dec_stream.c xz_dec_lzma2.c xz_dec_bcj.c
+COMMON_OBJS = $(COMMON_SRCS:.c=.o)
+XZMINIDEC_OBJS = xzminidec.o
+BYTETEST_OBJS = bytetest.o
+BUFTEST_OBJS = buftest.o
+BOOTTEST_OBJS = boottest.o
+XZ_HEADERS = xz.h xz_private.h xz_stream.h xz_lzma2.h xz_config.h
+PROGRAMS = xzminidec bytetest buftest boottest
+
+ALL_CPPFLAGS = -I../linux/include/linux -I. $(BCJ_CPPFLAGS) $(CPPFLAGS)
+
+all: $(PROGRAMS)
+
+%.o: %.c $(XZ_HEADERS)
+	$(CC) $(ALL_CPPFLAGS) $(CFLAGS) -c -o [email protected] $<
+
+xzminidec: $(COMMON_OBJS) $(XZMINIDEC_OBJS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o [email protected] $(COMMON_OBJS) $(XZMINIDEC_OBJS)
+
+bytetest: $(COMMON_OBJS) $(BYTETEST_OBJS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o [email protected] $(COMMON_OBJS) $(BYTETEST_OBJS)
+
+buftest: $(COMMON_OBJS) $(BUFTEST_OBJS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o [email protected] $(COMMON_OBJS) $(BUFTEST_OBJS)
+
+boottest: $(BOOTTEST_OBJS) $(COMMON_SRCS)
+	$(CC) $(ALL_CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o [email protected] $(BOOTTEST_OBJS)
+
+.PHONY: clean
+clean:
+	-$(RM) $(COMMON_OBJS) $(XZMINIDEC_OBJS) $(BUFTEST_OBJS) \
+		$(BOOTTEST_OBJS) $(PROGRAMS)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/userspace/boottest.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/userspace/boottest.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,93 @@
+/*
+ * Test application for xz_boot.c
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#define STATIC static
+#define INIT
+
+static void error(/*const*/ char *msg)
+{
+	fprintf(stderr, "%s\n", msg);
+}
+
+#include "../linux/lib/decompress_unxz.c"
+
+static uint8_t in[1024 * 1024];
+static uint8_t out[1024 * 1024];
+
+static int fill(void *buf, unsigned int size)
+{
+	return fread(buf, 1, size, stdin);
+}
+
+static int flush(/*const*/ void *buf, unsigned int size)
+{
+	return fwrite(buf, 1, size, stdout);
+}
+
+static void test_buf_to_buf(void)
+{
+	size_t in_size;
+	int ret;
+	in_size = fread(in, 1, sizeof(in), stdin);
+	ret = decompress(in, in_size, NULL, NULL, out, NULL, &error);
+	/* fwrite(out, 1, FIXME, stdout); */
+	fprintf(stderr, "ret = %d\n", ret);
+}
+
+static void test_buf_to_cb(void)
+{
+	size_t in_size;
+	int in_used;
+	int ret;
+	in_size = fread(in, 1, sizeof(in), stdin);
+	ret = decompress(in, in_size, NULL, &flush, NULL, &in_used, &error);
+	fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);
+}
+
+static void test_cb_to_cb(void)
+{
+	int ret;
+	ret = decompress(NULL, 0, &fill, &flush, NULL, NULL, &error);
+	fprintf(stderr, "ret = %d\n", ret);
+}
+
+/*
+ * Not used by Linux <= 2.6.37-rc4 and newer probably won't use it either,
+ * but this kind of use case is still required to be supported by the API.
+ */
+static void test_cb_to_buf(void)
+{
+	int in_used;
+	int ret;
+	ret = decompress(in, 0, &fill, NULL, out, &in_used, &error);
+	/* fwrite(out, 1, FIXME, stdout); */
+	fprintf(stderr, "ret = %d; in_used = %d\n", ret, in_used);
+}
+
+int main(int argc, char **argv)
+{
+	if (argc != 2)
+		fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
+	else if (strcmp(argv[1], "bb") == 0)
+		test_buf_to_buf();
+	else if (strcmp(argv[1], "bc") == 0)
+		test_buf_to_cb();
+	else if (strcmp(argv[1], "cc") == 0)
+		test_cb_to_cb();
+	else if (strcmp(argv[1], "cb") == 0)
+		test_cb_to_buf();
+	else
+		fprintf(stderr, "Usage: %s [bb|bc|cc|cb]\n", argv[0]);
+
+	return 0;
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/userspace/buftest.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/userspace/buftest.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,48 @@
+/*
+ * Test application to test buffer-to-buffer decoding
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include "xz.h"
+
+#define BUFFER_SIZE (1024 * 1024)
+
+static uint8_t in[BUFFER_SIZE];
+static uint8_t out[BUFFER_SIZE];
+
+int main(void)
+{
+	struct xz_buf b;
+	struct xz_dec *s;
+	enum xz_ret ret;
+
+	xz_crc32_init();
+
+	s = xz_dec_init(XZ_SINGLE, 0);
+	if (s == NULL) {
+		fputs("Initialization failed", stderr);
+		return 1;
+	}
+
+	b.in = in;
+	b.in_pos = 0;
+	b.in_size = fread(in, 1, sizeof(in), stdin);
+	b.out = out;
+	b.out_pos = 0;
+	b.out_size = sizeof(out);
+
+	ret = xz_dec_run(s, &b);
+	xz_dec_end(s);
+
+	fwrite(out, 1, b.out_pos, stdout);
+	fprintf(stderr, "%d\n", ret);
+
+	return 0;
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/userspace/xz_config.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/userspace/xz_config.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,109 @@
+/*
+ * Private includes and definitions for userspace use of XZ Embedded
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+#ifndef XZ_CONFIG_H
+#define XZ_CONFIG_H
+
+/* Uncomment as needed to enable BCJ filter decoders. */
+/* #define XZ_DEC_X86 */
+/* #define XZ_DEC_POWERPC */
+/* #define XZ_DEC_IA64 */
+/* #define XZ_DEC_ARM */
+/* #define XZ_DEC_ARMTHUMB */
+/* #define XZ_DEC_SPARC */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "xz.h"
+
+#define kmalloc(size, flags) malloc(size)
+#define kfree(ptr) free(ptr)
+#define vmalloc(size) malloc(size)
+#define vfree(ptr) free(ptr)
+
+#define memeq(a, b, size) (memcmp(a, b, size) == 0)
+#define memzero(buf, size) memset(buf, 0, size)
+
+#ifndef min
+#	define min(x, y) ((x) < (y) ? (x) : (y))
+#endif
+#define min_t(type, x, y) min(x, y)
+
+/*
+ * Some functions have been marked with __always_inline to keep the
+ * performance reasonable even when the compiler is optimizing for
+ * small code size. You may be able to save a few bytes by #defining
+ * __always_inline to plain inline, but don't complain if the code
+ * becomes slow.
+ *
+ * NOTE: System headers on GNU/Linux may #define this macro already,
+ * so if you want to change it, you need to #undef it first.
+ */
+#ifndef __always_inline
+#	ifdef __GNUC__
+#		define __always_inline \
+			inline __attribute__((__always_inline__))
+#	else
+#		define __always_inline inline
+#	endif
+#endif
+
+/* Inline functions to access unaligned unsigned 32-bit integers */
+#ifndef get_unaligned_le32
+static inline uint32_t get_unaligned_le32(const uint8_t *buf)
+{
+	return (uint32_t)buf[0]
+			| ((uint32_t)buf[1] << 8)
+			| ((uint32_t)buf[2] << 16)
+			| ((uint32_t)buf[3] << 24);
+}
+#endif
+
+#ifndef get_unaligned_be32
+static inline uint32_t get_unaligned_be32(const uint8_t *buf)
+{
+	return (uint32_t)(buf[0] << 24)
+			| ((uint32_t)buf[1] << 16)
+			| ((uint32_t)buf[2] << 8)
+			| (uint32_t)buf[3];
+}
+#endif
+
+#ifndef put_unaligned_le32
+static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
+{
+	buf[0] = (uint8_t)val;
+	buf[1] = (uint8_t)(val >> 8);
+	buf[2] = (uint8_t)(val >> 16);
+	buf[3] = (uint8_t)(val >> 24);
+}
+#endif
+
+#ifndef put_unaligned_be32
+static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
+{
+	buf[0] = (uint8_t)(val >> 24);
+	buf[1] = (uint8_t)(val >> 16);
+	buf[2] = (uint8_t)(val >> 8);
+	buf[3] = (uint8_t)val;
+}
+#endif
+
+/*
+ * Use get_unaligned_le32() also for aligned access for simplicity. On
+ * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
+ * could save a few bytes in code size.
+ */
+#ifndef get_le32
+#	define get_le32 get_unaligned_le32
+#endif
+
+#endif
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/contrib/xz-embedded/userspace/xzminidec.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/contrib/xz-embedded/userspace/xzminidec.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,132 @@
+/*
+ * Simple XZ decoder command line tool
+ *
+ * Author: Lasse Collin <lasse.collin at tukaani.org>
+ *
+ * This file has been put into the public domain.
+ * You can do whatever you want with this file.
+ */
+
+/*
+ * This is really limited: Not all filters from .xz format are supported,
+ * only CRC32 is supported as the integrity check, and decoding of
+ * concatenated .xz streams is not supported. Thus, you may want to look
+ * at xzdec from XZ Utils if a few KiB bigger tool is not a problem.
+ */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include "xz.h"
+
+static uint8_t in[BUFSIZ];
+static uint8_t out[BUFSIZ];
+
+int main(int argc, char **argv)
+{
+	struct xz_buf b;
+	struct xz_dec *s;
+	enum xz_ret ret;
+	const char *msg;
+
+	if (argc >= 2 && strcmp(argv[1], "--help") == 0) {
+		fputs("Uncompress a .xz file from stdin to stdout.\n"
+				"Arguments other than `--help' are ignored.\n",
+				stdout);
+		return 0;
+	}
+
+	xz_crc32_init();
+
+	/*
+	 * Support up to 64 MiB dictionary. The actually needed memory
+	 * is allocated once the headers have been parsed.
+	 */
+	s = xz_dec_init(XZ_DYNALLOC, 1 << 26);
+	if (s == NULL) {
+		msg = "Memory allocation failed\n";
+		goto error;
+	}
+
+	b.in = in;
+	b.in_pos = 0;
+	b.in_size = 0;
+	b.out = out;
+	b.out_pos = 0;
+	b.out_size = BUFSIZ;
+
+	while (true) {
+		if (b.in_pos == b.in_size) {
+			b.in_size = fread(in, 1, sizeof(in), stdin);
+			b.in_pos = 0;
+		}
+
+		ret = xz_dec_run(s, &b);
+
+		if (b.out_pos == sizeof(out)) {
+			if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos) {
+				msg = "Write error\n";
+				goto error;
+			}
+
+			b.out_pos = 0;
+		}
+
+		if (ret == XZ_OK)
+			continue;
+
+#ifdef XZ_DEC_ANY_CHECK
+		if (ret == XZ_UNSUPPORTED_CHECK) {
+			fputs(argv[0], stderr);
+			fputs(": ", stderr);
+			fputs("Unsupported check; not verifying "
+					"file integrity\n", stderr);
+			continue;
+		}
+#endif
+
+		if (fwrite(out, 1, b.out_pos, stdout) != b.out_pos
+				|| fclose(stdout)) {
+			msg = "Write error\n";
+			goto error;
+		}
+
+		switch (ret) {
+		case XZ_STREAM_END:
+			xz_dec_end(s);
+			return 0;
+
+		case XZ_MEM_ERROR:
+			msg = "Memory allocation failed\n";
+			goto error;
+
+		case XZ_MEMLIMIT_ERROR:
+			msg = "Memory usage limit reached\n";
+			goto error;
+
+		case XZ_FORMAT_ERROR:
+			msg = "Not a .xz file\n";
+			goto error;
+
+		case XZ_OPTIONS_ERROR:
+			msg = "Unsupported options in the .xz headers\n";
+			goto error;
+
+		case XZ_DATA_ERROR:
+		case XZ_BUF_ERROR:
+			msg = "File is corrupt\n";
+			goto error;
+
+		default:
+			msg = "Bug!\n";
+			goto error;
+		}
+	}
+
+error:
+	xz_dec_end(s);
+	fputs(argv[0], stderr);
+	fputs(": ", stderr);
+	fputs(msg, stderr);
+	return 1;
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/ddb/db_input.c
--- a/head/sys/ddb/db_input.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/ddb/db_input.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/ddb/db_input.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -253,7 +253,7 @@
 		db_putnchars(BACKUP, db_lc - db_lbuf_start);
 		db_putnchars(BLANK, db_le - db_lbuf_start);
 		db_putnchars(BACKUP, db_le - db_lbuf_start);
-		db_le = index(db_lbuf_start, '\0');
+		db_le = strchr(db_lbuf_start, '\0');
 		if (db_le[-1] == '\r' || db_le[-1] == '\n')
 		    *--db_le = '\0';
 		db_lc = db_le;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/ata/ata-disk.c
--- a/head/sys/dev/ata/ata-disk.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/ata/ata-disk.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/ata/ata-disk.c 227849 2011-11-22 21:56:55Z hselasky $");
+__FBSDID("$FreeBSD: head/sys/dev/ata/ata-disk.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include "opt_ata.h"
 #include <sys/param.h>
@@ -532,8 +532,8 @@
     u_int8_t *marker, vendor[64], product[64];
 
     /* try to separate the ATA model string into vendor and model parts */
-    if ((marker = index(atadev->param.model, ' ')) ||
-	(marker = index(atadev->param.model, '-'))) {
+    if ((marker = strchr(atadev->param.model, ' ')) ||
+	(marker = strchr(atadev->param.model, '-'))) {
 	int len = (marker - atadev->param.model);
 
 	strncpy(vendor, atadev->param.model, len);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/flash/mx25l.c
--- a/head/sys/dev/flash/mx25l.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/flash/mx25l.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/dev/flash/mx25l.c 229464 2012-01-04 04:17:03Z adrian $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -123,6 +123,7 @@
 	{ "mx25ll64",    0xc2, 0x2017, 64 * 1024, 128, 256, FL_NONE },
 	{ "mx25ll128",   0xc2, 0x2018, 64 * 1024, 256, 256, FL_ERASE_4K | FL_ERASE_32K },
 	{ "s25fl128",    0x01, 0x2018, 64 * 1024, 256, 256, FL_NONE },
+	{ "s25s1032",    0x01, 0x0215, 64 * 1024, 64,  256, FL_NONE },
 	{ "s25sl064a",   0x01, 0x0216, 64 * 1024, 128, 256, FL_NONE },
 	/* EON -- en25pxx */
 	{ "en25p32",     0x1c, 0x2016, 64 * 1024,  64, 256, FL_NONE },
@@ -133,6 +134,7 @@
 	{ "at25128",        0,      0,        64, 256,  64, FL_NONE },
 	{ "at25256",        0,      0,        64, 512,  64, FL_NONE },
 	{ "w25q64", 	 0xef, 0x4017, 64 * 1024, 128, 256, FL_ERASE_4K },
+	{ "w25q64bv",  0xef, 0x4017, 64 * 1024, 128, FL_ERASE_4K },
 };
 
 #define MX25L_IDENT_SIZE (sizeof(flash_devices)/sizeof(struct mx25l_flash_ident))
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/hwpmc/hwpmc_core.c
--- a/head/sys/dev/hwpmc/hwpmc_core.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/hwpmc/hwpmc_core.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_core.c 228787 2011-12-21 17:51:49Z eadler $");
+__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_core.c 229470 2012-01-04 07:58:36Z fabient $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -642,7 +642,7 @@
     IAPDESCR(08H_09H, 0x08, 0x09, IAP_F_FM | IAP_F_CA),
     IAPDESCR(08H_10H, 0x08, 0x10, IAP_F_FM | IAP_F_I7 | IAP_F_WM),
     IAPDESCR(08H_20H, 0x08, 0x20, IAP_F_FM | IAP_F_I7 | IAP_F_WM),
-    IAPDESCR(08H_40H, 0x08, 0x40, IAP_F_FM | IAP_F_I7),
+    IAPDESCR(08H_40H, 0x08, 0x40, IAP_F_FM | IAP_F_I7O),
     IAPDESCR(08H_80H, 0x08, 0x80, IAP_F_FM | IAP_F_I7),
 
     IAPDESCR(09H_01H, 0x09, 0x01, IAP_F_FM | IAP_F_CA | IAP_F_CC2 | IAP_F_I7O),
@@ -845,7 +845,7 @@
     IAPDESCR(47H_00H, 0x47, 0x00, IAP_F_FM | IAP_F_ALLCPUSCORE2),
 
     IAPDESCR(48H_00H, 0x48, 0x00, IAP_F_FM | IAP_F_ALLCPUSCORE2),
-    IAPDESCR(48H_02H, 0x48, 0x02, IAP_F_FM | IAP_F_I7),
+    IAPDESCR(48H_02H, 0x48, 0x02, IAP_F_FM | IAP_F_I7O),
 
     IAPDESCR(49H_00H, 0x49, 0x00, IAP_F_FM | IAP_F_CC),
     IAPDESCR(49H_01H, 0x49, 0x01, IAP_F_FM | IAP_F_CA | IAP_F_CC2 |
@@ -854,9 +854,9 @@
         IAP_F_I7 | IAP_F_WM),
     IAPDESCR(49H_04H, 0x49, 0x04, IAP_F_FM | IAP_F_WM),
     IAPDESCR(49H_10H, 0x49, 0x10, IAP_F_FM | IAP_F_I7 | IAP_F_WM),
-    IAPDESCR(49H_20H, 0x49, 0x20, IAP_F_FM | IAP_F_I7O),
+    IAPDESCR(49H_20H, 0x49, 0x20, IAP_F_FM | IAP_F_I7),
     IAPDESCR(49H_40H, 0x49, 0x40, IAP_F_FM | IAP_F_I7O),
-    IAPDESCR(49H_80H, 0x49, 0x80, IAP_F_FM | IAP_F_WM | IAP_F_I7O),
+    IAPDESCR(49H_80H, 0x49, 0x80, IAP_F_FM | IAP_F_WM | IAP_F_I7),
 
     IAPDESCR(4BH_00H, 0x4B, 0x00, IAP_F_FM | IAP_F_ALLCPUSCORE2),
     IAPDESCR(4BH_01H, 0x4B, 0x01, IAP_F_FM | IAP_F_ALLCPUSCORE2 | IAP_F_I7O),
@@ -1306,7 +1306,7 @@
 
     IAPDESCR(E8H_01H, 0xE8, 0x01, IAP_F_FM | IAP_F_I7 | IAP_F_WM),
     IAPDESCR(E8H_02H, 0xE8, 0x02, IAP_F_FM | IAP_F_I7 | IAP_F_WM),
-    IAPDESCR(E8H_03H, 0xE8, 0x03, IAP_F_FM | IAP_F_I7),
+    IAPDESCR(E8H_03H, 0xE8, 0x03, IAP_F_FM | IAP_F_I7O),
 
     IAPDESCR(ECH_01H, 0xEC, 0x01, IAP_F_FM | IAP_F_WM),
 
@@ -1454,7 +1454,6 @@
 	case PMC_EV_IAP_EVENT_42H_08H:
 	case PMC_EV_IAP_EVENT_43H_01H:
 	case PMC_EV_IAP_EVENT_43H_02H:
-	case PMC_EV_IAP_EVENT_48H_02H:
 	case PMC_EV_IAP_EVENT_51H_01H:
 	case PMC_EV_IAP_EVENT_51H_02H:
 	case PMC_EV_IAP_EVENT_51H_04H:
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/hwpmc/hwpmc_uncore.c
--- a/head/sys/dev/hwpmc/hwpmc_uncore.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/hwpmc/hwpmc_uncore.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/dev/hwpmc/hwpmc_uncore.c 229469 2012-01-04 07:33:06Z fabient $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -545,8 +545,14 @@
 
     UCPDESCR(0CH_01H, 0x0C, 0x01, UCP_F_FM | UCP_F_WM),
     UCPDESCR(0CH_02H, 0x0C, 0x02, UCP_F_FM | UCP_F_WM),
-    UCPDESCR(0CH_04H, 0x0C, 0x04, UCP_F_FM | UCP_F_WM),
-    UCPDESCR(0CH_08H, 0x0C, 0x08, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_04H_E, 0x0C, 0x04, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_04H_F, 0x0C, 0x04, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_04H_M, 0x0C, 0x04, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_04H_S, 0x0C, 0x04, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_08H_E, 0x0C, 0x08, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_08H_F, 0x0C, 0x08, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_08H_M, 0x0C, 0x08, UCP_F_FM | UCP_F_WM),
+    UCPDESCR(0CH_08H_S, 0x0C, 0x08, UCP_F_FM | UCP_F_WM),
 
     UCPDESCR(20H_01H, 0x20, 0x01, UCP_F_FM | UCP_F_I7 | UCP_F_WM),
     UCPDESCR(20H_02H, 0x20, 0x02, UCP_F_FM | UCP_F_I7 | UCP_F_WM),
@@ -965,6 +971,36 @@
 	PMCDBG(MDP,STA,2, "ucp-start/2 cpu=%d ri=%d evselmsr=0x%x evsel=0x%x",
 	    cpu, ri, UCP_EVSEL0 + ri, evsel);
 
+	/* Event specific configuration. */
+	switch (pm->pm_event) {
+	case PMC_EV_UCP_EVENT_0CH_04H_E:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x2);
+		break;
+	case PMC_EV_UCP_EVENT_0CH_04H_F:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x8);
+		break;
+	case PMC_EV_UCP_EVENT_0CH_04H_M:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x1);
+		break;
+	case PMC_EV_UCP_EVENT_0CH_04H_S:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x4);
+		break;
+	case PMC_EV_UCP_EVENT_0CH_08H_E:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x2);
+		break;
+	case PMC_EV_UCP_EVENT_0CH_08H_F:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x8);
+		break;	
+	case PMC_EV_UCP_EVENT_0CH_08H_M:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x1);
+		break;
+	case PMC_EV_UCP_EVENT_0CH_08H_S:
+		wrmsr(MSR_GQ_SNOOP_MESF,0x4);
+		break;
+	default:	
+		break;
+	}
+
 	wrmsr(UCP_EVSEL0 + ri, evsel);
 
 	do {
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/hwpmc/hwpmc_uncore.h
--- a/head/sys/dev/hwpmc/hwpmc_uncore.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/hwpmc/hwpmc_uncore.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/dev/hwpmc/hwpmc_uncore.h 229469 2012-01-04 07:33:06Z fabient $
  */
 
 #ifndef _DEV_HWPMC_UNCORE_H_
@@ -87,11 +87,18 @@
 #define	UC_GLOBAL_CTRL				0x391
 #define	UC_GLOBAL_OVF_CTRL			0x393
 
+
 #define	UC_GLOBAL_STATUS_FLAG_CLRCHG		(1ULL << 63)
 #define	UC_GLOBAL_STATUS_FLAG_OVFPMI		(1ULL << 61)
 #define	UC_GLOBAL_CTRL_FLAG_FRZ			(1ULL << 63)
 #define	UC_GLOBAL_CTRL_FLAG_ENPMICORE0		(1ULL << 48)
 
+/*
+ * Model specific registers.
+ */
+
+#define MSR_GQ_SNOOP_MESF			0x301
+
 struct pmc_md_ucf_pmc {
 	uint64_t	pm_ucf_ctrl;
 };
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/hwpmc/pmc_events.h
--- a/head/sys/dev/hwpmc/pmc_events.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/hwpmc/pmc_events.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/dev/hwpmc/pmc_events.h 228869 2011-12-24 19:34:52Z jhibbits $
+ * $FreeBSD: head/sys/dev/hwpmc/pmc_events.h 229470 2012-01-04 07:58:36Z fabient $
  */
 
 #ifndef _DEV_HWPMC_PMC_EVENTS_H_
@@ -1669,7 +1669,7 @@
 
 /*
  * Core i7 and Xeon 5500 events removed between 253669-031US June 2009
- * and 253669-033US December 2009.
+ * and 253669-040US October 2011.
  */
 #define	__PMC_EV_ALIAS_COREI7_OLD()					\
 __PMC_EV_ALIAS("SB_FORWARD.ANY", IAP_EVENT_02H_01H)			\
@@ -1682,6 +1682,7 @@
 __PMC_EV_ALIAS("STORE_BLOCKS.NOT_STA", IAP_EVENT_06H_01H)		\
 __PMC_EV_ALIAS("STORE_BLOCKS.STA", IAP_EVENT_06H_02H)			\
 __PMC_EV_ALIAS("STORE_BLOCKS.ANY", IAP_EVENT_06H_0FH)			\
+__PMC_EV_ALIAS("DTLB_LOAD_MISSES.PDP_MISS", IAP_EVENT_08H_40H)		\
 __PMC_EV_ALIAS("MEMORY_DISAMBIGURATION.RESET", IAP_EVENT_09H_01H)	\
 __PMC_EV_ALIAS("MEMORY_DISAMBIGURATION.SUCCESS", IAP_EVENT_09H_02H)	\
 __PMC_EV_ALIAS("MEMORY_DISAMBIGURATION.WATCHDOG", IAP_EVENT_09H_04H)	\
@@ -1693,9 +1694,8 @@
 __PMC_EV_ALIAS("UOPS_DECODED.DEC0", IAP_EVENT_3DH_01H)			\
 __PMC_EV_ALIAS("L1D_CACHE_ST.I_STATE", IAP_EVENT_41H_01H)		\
 __PMC_EV_ALIAS("L1D_CACHE_ST.MESI", IAP_EVENT_41H_0FH)			\
-__PMC_EV_ALIAS("DTLB_MISSES.PDE_MISS", IAP_EVENT_49H_20H)		\
+__PMC_EV_ALIAS("L1D_PEND_MISS.LOAD_BUFFERS_FULL", IAP_EVENT_48H_02H)	\
 __PMC_EV_ALIAS("DTLB_MISSES.PDP_MISS", IAP_EVENT_49H_40H)		\
-__PMC_EV_ALIAS("DTLB_MISSES.LARGE_WALK_COMPLETED", IAP_EVENT_49H_80H)	\
 __PMC_EV_ALIAS("SSE_MEM_EXEC.NTA", IAP_EVENT_4BH_01H)			\
 __PMC_EV_ALIAS("SSE_MEM_EXEC.STREAMING_STORES", IAP_EVENT_4BH_08H)	\
 __PMC_EV_ALIAS("SFENCE_CYCLES", IAP_EVENT_4DH_01H)			\
@@ -1734,6 +1734,7 @@
 __PMC_EV_ALIAS("PIC_ACCESSES.TPR_WRITES", IAP_EVENT_BAH_02H)		\
 __PMC_EV_ALIAS("MACHINE_CLEARS.FUSION_ASSIST", IAP_EVENT_C3H_10H)	\
 __PMC_EV_ALIAS("BOGUS_BR", IAP_EVENT_E4H_01H)				\
+__PMC_EV_ALIAS("BPU_CLEARS.ANY", IAP_EVENT_E8H_03H)			\
 __PMC_EV_ALIAS("L2_HW_PREFETCH.HIT", IAP_EVENT_F3H_01H)			\
 __PMC_EV_ALIAS("L2_HW_PREFETCH.ALLOC", IAP_EVENT_F3H_02H)		\
 __PMC_EV_ALIAS("L2_HW_PREFETCH.DATA_TRIGGER", IAP_EVENT_F3H_04H)	\
@@ -1759,7 +1760,6 @@
 __PMC_EV_ALIAS("DTLB_LOAD_MISSES.WALK_COMPLETED", IAP_EVENT_08H_02H)	\
 __PMC_EV_ALIAS("DTLB_LOAD_MISSES.STLB_HIT", IAP_EVENT_08H_10H)		\
 __PMC_EV_ALIAS("DTLB_LOAD_MISSES.PDE_MISS", IAP_EVENT_08H_20H)		\
-__PMC_EV_ALIAS("DTLB_LOAD_MISSES.PDP_MISS", IAP_EVENT_08H_40H)		\
 __PMC_EV_ALIAS("DTLB_LOAD_MISSES.LARGE_WALK_COMPLETED",			\
     IAP_EVENT_08H_80H) 							\
 __PMC_EV_ALIAS("MEM_INST_RETIRED.LOADS", IAP_EVENT_0BH_01H)		\
@@ -1867,10 +1867,11 @@
 __PMC_EV_ALIAS("L1D_CACHE_LOCK.M_STATE", IAP_EVENT_42H_08H)		\
 __PMC_EV_ALIAS("L1D_ALL_REF.ANY", IAP_EVENT_43H_01H)			\
 __PMC_EV_ALIAS("L1D_ALL_REF.CACHEABLE", IAP_EVENT_43H_02H)		\
-__PMC_EV_ALIAS("L1D_PEND_MISS.LOAD_BUFFERS_FULL", IAP_EVENT_48H_02H)	\
 __PMC_EV_ALIAS("DTLB_MISSES.ANY", IAP_EVENT_49H_01H)			\
 __PMC_EV_ALIAS("DTLB_MISSES.WALK_COMPLETED", IAP_EVENT_49H_02H)		\
 __PMC_EV_ALIAS("DTLB_MISSES.STLB_HIT", IAP_EVENT_49H_10H)		\
+__PMC_EV_ALIAS("DTLB_MISSES.PDE_MISS", IAP_EVENT_49H_20H)		\
+__PMC_EV_ALIAS("DTLB_MISSES.LARGE_WALK_COMPLETED", IAP_EVENT_49H_80H)	\
 __PMC_EV_ALIAS("LOAD_HIT_PRE", IAP_EVENT_4CH_01H)			\
 __PMC_EV_ALIAS("L1D_PREFETCH.REQUESTS", IAP_EVENT_4EH_01H)		\
 __PMC_EV_ALIAS("L1D_PREFETCH.MISS", IAP_EVENT_4EH_02H)			\
@@ -1996,7 +1997,6 @@
 __PMC_EV_ALIAS("BACLEAR.BAD_TARGET", IAP_EVENT_E6H_02H)			\
 __PMC_EV_ALIAS("BPU_CLEARS.EARLY", IAP_EVENT_E8H_01H)			\
 __PMC_EV_ALIAS("BPU_CLEARS.LATE", IAP_EVENT_E8H_02H)			\
-__PMC_EV_ALIAS("BPU_CLEARS.ANY", IAP_EVENT_E8H_03H)			\
 __PMC_EV_ALIAS("L2_TRANSACTIONS.LOAD", IAP_EVENT_F0H_01H)		\
 __PMC_EV_ALIAS("L2_TRANSACTIONS.RFO", IAP_EVENT_F0H_02H)		\
 __PMC_EV_ALIAS("L2_TRANSACTIONS.IFETCH", IAP_EVENT_F0H_04H)		\
@@ -2388,8 +2388,14 @@
 __PMC_EV(UCP, EVENT_0BH_1FH)			\
 __PMC_EV(UCP, EVENT_0CH_01H)			\
 __PMC_EV(UCP, EVENT_0CH_02H)			\
-__PMC_EV(UCP, EVENT_0CH_04H)			\
-__PMC_EV(UCP, EVENT_0CH_08H)			\
+__PMC_EV(UCP, EVENT_0CH_04H_E)			\
+__PMC_EV(UCP, EVENT_0CH_04H_F)			\
+__PMC_EV(UCP, EVENT_0CH_04H_M)			\
+__PMC_EV(UCP, EVENT_0CH_04H_S)			\
+__PMC_EV(UCP, EVENT_0CH_08H_E)			\
+__PMC_EV(UCP, EVENT_0CH_08H_F)			\
+__PMC_EV(UCP, EVENT_0CH_08H_M)			\
+__PMC_EV(UCP, EVENT_0CH_08H_S)			\
 __PMC_EV(UCP, EVENT_20H_01H)			\
 __PMC_EV(UCP, EVENT_20H_02H)			\
 __PMC_EV(UCP, EVENT_20H_04H)			\
@@ -2789,8 +2795,14 @@
 __PMC_EV_ALIAS("L3_LINES_OUT.ANY", UCP_EVENT_0BH_1FH)	\
 __PMC_EV_ALIAS("GQ_SNOOP.GOTO_S", UCP_EVENT_0CH_01H)	\
 __PMC_EV_ALIAS("GQ_SNOOP.GOTO_I", UCP_EVENT_0CH_02H)	\
-__PMC_EV_ALIAS("GQ_SNOOP.GOTO_S_HIT", UCP_EVENT_0CH_04H)	\
-__PMC_EV_ALIAS("GQ_SNOOP.GOTO_I_HIT", UCP_EVENT_0CH_08H)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_S_HIT_E", UCP_EVENT_0CH_04H_E)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_S_HIT_F", UCP_EVENT_0CH_04H_F)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_S_HIT_M", UCP_EVENT_0CH_04H_M)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_S_HIT_S", UCP_EVENT_0CH_04H_S)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_I_HIT_E", UCP_EVENT_0CH_08H_E)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_I_HIT_F", UCP_EVENT_0CH_08H_F)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_I_HIT_M", UCP_EVENT_0CH_08H_M)	\
+__PMC_EV_ALIAS("GQ_SNOOP.GOTO_I_HIT_S", UCP_EVENT_0CH_08H_S)	\
 __PMC_EV_ALIAS("QHL_REQUESTS.IOH_READS", UCP_EVENT_20H_01H)	\
 __PMC_EV_ALIAS("QHL_REQUESTS.IOH_WRITES", UCP_EVENT_20H_02H)	\
 __PMC_EV_ALIAS("QHL_REQUESTS.REMOTE_READS", UCP_EVENT_20H_04H)	\
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/if_ndis/if_ndis_pccard.c
--- a/head/sys/dev/if_ndis/if_ndis_pccard.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/if_ndis/if_ndis_pccard.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/dev/if_ndis/if_ndis_pccard.c 229401 2012-01-03 18:40:41Z dim $");
 
 #include <sys/ctype.h>
 #include <sys/param.h>
@@ -207,7 +207,7 @@
 		goto fail;
 	}
 	sc->ndis_rescnt++;
-	resource_list_add(&sc->ndis_rl, SYS_RES_IOPORT, rid,
+	resource_list_add(&sc->ndis_rl, SYS_RES_IOPORT, sc->ndis_io_rid,
 	    rman_get_start(sc->ndis_res_io), rman_get_end(sc->ndis_res_io),
 	    rman_get_size(sc->ndis_res_io));
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/iwn/if_iwn.c
--- a/head/sys/dev/iwn/if_iwn.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/iwn/if_iwn.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/iwn/if_iwn.c 228621 2011-12-17 10:23:17Z bschmidt $");
+__FBSDID("$FreeBSD: head/sys/dev/iwn/if_iwn.c 229375 2012-01-03 09:42:31Z bschmidt $");
 
 #include <sys/param.h>
 #include <sys/sockio.h>
@@ -2128,7 +2128,7 @@
 					plcp |= IWN_RFLAG_SGI;
 			} else if (ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20)
 				plcp |= IWN_RFLAG_SGI;
-			if (i > 7)
+			if (RV(ni->ni_htrates.rs_rates[i]) > 7)
 				plcp |= IWN_RFLAG_ANT(txant1 | txant2);
 			else
 				plcp |= IWN_RFLAG_ANT(txant1);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/mxge/if_mxge.c
--- a/head/sys/dev/mxge/if_mxge.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/mxge/if_mxge.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 ***************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/mxge/if_mxge.c 223957 2011-07-12 14:43:49Z gallatin $");
+__FBSDID("$FreeBSD: head/sys/dev/mxge/if_mxge.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2827,7 +2827,7 @@
 	}
 
 	for (i = 0; i < 3; i++, ptr++) {
-		ptr = index(ptr, '-');
+		ptr = strchr(ptr, '-');
 		if (ptr == NULL) {
 			device_printf(sc->dev,
 				      "only %d dashes in PC?!?\n", i);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/qlxgb/qla_misc.c
--- a/head/sys/dev/qlxgb/qla_misc.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/qlxgb/qla_misc.c	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/qlxgb/qla_misc.c 227064 2011-11-03 21:20:22Z bz $");
+__FBSDID("$FreeBSD: head/sys/dev/qlxgb/qla_misc.c 229423 2012-01-03 20:51:26Z dim $");
 
 #include "qla_os.h"
 #include "qla_reg.h"
@@ -407,7 +407,7 @@
 	addr_val_t *addr_val_map, *avmap;
 
 	qla_rd_flash32(ha, 0, &sig);
-	QL_DPRINT2((ha->pci_dev, "%s: val[0] = 0x%08x\n", __func__, val));
+	QL_DPRINT2((ha->pci_dev, "%s: val[0] = 0x%08x\n", __func__, sig));
 
 	qla_rd_flash32(ha, 4, &val);
 	QL_DPRINT2((ha->pci_dev, "%s: val[4] = 0x%08x\n", __func__, val));
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/sound/pci/emu10k1.c
--- a/head/sys/dev/sound/pci/emu10k1.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/sound/pci/emu10k1.c	Thu Jan 05 13:30:52 2012 +0200
@@ -32,7 +32,7 @@
 
 #include <dev/sound/pcm/sound.h>
 #include <dev/sound/pcm/ac97.h>
-#include "emu10k1-alsa%diked.h"
+#include <dev/sound/pci/emuxkireg.h>
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
@@ -41,7 +41,7 @@
 #include <dev/sound/midi/mpu401.h>
 #include "mpufoi_if.h"
 
-SND_DECLARE_FILE("$FreeBSD$");
+SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pci/emu10k1.c 229430 2012-01-03 21:04:54Z pfg $");
 
 /* -------------------------------------------------------------------- */
 
@@ -66,12 +66,94 @@
 
 #define	ENABLE		0xffffffff
 #define	DISABLE		0x00000000
-#define	ENV_ON		DCYSUSV_CHANNELENABLE_MASK
+#define	ENV_ON		EMU_CHAN_DCYSUSV_CHANNELENABLE_MASK
 #define	ENV_OFF		0x00	/* XXX: should this be 1? */
 
-#define	A_IOCFG_GPOUT_A	0x40	/* Analog Output */
-#define	A_IOCFG_GPOUT_D	0x04	/* Digital Output */
-#define	A_IOCFG_GPOUT_AD (A_IOCFG_GPOUT_A|A_IOCFG_GPOUT_D)  /* A_IOCFG_GPOUT0 */
+#define	EMU_A_IOCFG_GPOUT_A	0x40
+#define	EMU_A_IOCFG_GPOUT_D	0x04
+#define	EMU_A_IOCFG_GPOUT_AD (EMU_A_IOCFG_GPOUT_A|EMU_A_IOCFG_GPOUT_D)  /* EMU_A_IOCFG_GPOUT0 */
+
+#define	EMU_HCFG_GPOUT1		0x00000800
+
+/* instruction set */
+#define iACC3	 0x06
+#define iMACINT0 0x04
+#define iINTERP  0x0e
+
+#define C_00000000	0x40
+#define C_00000001	0x41
+#define C_00000004	0x44
+#define C_40000000	0x4d
+/* Audigy constants */
+#define A_C_00000000	0xc0
+#define A_C_40000000	0xcd
+
+/* GPRs */
+#define FXBUS(x)	(0x00 + (x))
+#define EXTIN(x)	(0x10 + (x))
+#define EXTOUT(x)	(0x20 + (x))
+
+#define GPR(x)		(EMU_FXGPREGBASE + (x))
+#define A_EXTIN(x)	(0x40 + (x))
+#define A_FXBUS(x)	(0x00 + (x))
+#define A_EXTOUT(x)	(0x60 + (x))
+#define A_GPR(x)	(EMU_A_FXGPREGBASE + (x))
+
+/* FX buses */
+#define FXBUS_PCM_LEFT		0x00
+#define FXBUS_PCM_RIGHT		0x01
+#define FXBUS_MIDI_LEFT		0x04
+#define FXBUS_MIDI_RIGHT	0x05
+#define FXBUS_MIDI_REVERB	0x0c
+#define FXBUS_MIDI_CHORUS	0x0d
+
+/* Inputs */
+#define EXTIN_AC97_L		0x00
+#define EXTIN_AC97_R		0x01
+#define EXTIN_SPDIF_CD_L	0x02
+#define EXTIN_SPDIF_CD_R	0x03
+#define EXTIN_TOSLINK_L		0x06
+#define EXTIN_TOSLINK_R		0x07
+#define EXTIN_COAX_SPDIF_L	0x0a
+#define EXTIN_COAX_SPDIF_R	0x0b
+/* Audigy Inputs */
+#define A_EXTIN_AC97_L		0x00
+#define A_EXTIN_AC97_R		0x01
+
+/* Outputs */
+#define EXTOUT_AC97_L	   0x00
+#define EXTOUT_AC97_R	   0x01
+#define EXTOUT_TOSLINK_L   0x02
+#define EXTOUT_TOSLINK_R   0x03
+#define EXTOUT_AC97_CENTER 0x04
+#define EXTOUT_AC97_LFE	   0x05
+#define EXTOUT_HEADPHONE_L 0x06
+#define EXTOUT_HEADPHONE_R 0x07
+#define EXTOUT_REAR_L	   0x08
+#define EXTOUT_REAR_R	   0x09
+#define EXTOUT_ADC_CAP_L   0x0a
+#define EXTOUT_ADC_CAP_R   0x0b
+#define EXTOUT_ACENTER	   0x11
+#define EXTOUT_ALFE	   0x12
+/* Audigy Outputs */
+#define A_EXTOUT_FRONT_L	0x00
+#define A_EXTOUT_FRONT_R	0x01
+#define A_EXTOUT_CENTER		0x02
+#define A_EXTOUT_LFE		0x03
+#define A_EXTOUT_HEADPHONE_L	0x04
+#define A_EXTOUT_HEADPHONE_R	0x05
+#define A_EXTOUT_REAR_L		0x06
+#define A_EXTOUT_REAR_R		0x07
+#define A_EXTOUT_AFRONT_L	0x08
+#define A_EXTOUT_AFRONT_R	0x09
+#define A_EXTOUT_ACENTER	0x0a
+#define A_EXTOUT_ALFE		0x0b
+#define A_EXTOUT_AREAR_L	0x0e
+#define A_EXTOUT_AREAR_R	0x0f
+#define A_EXTOUT_AC97_L		0x10
+#define A_EXTOUT_AC97_R		0x11
+#define A_EXTOUT_ADC_CAP_L	0x16
+#define A_EXTOUT_ADC_CAP_R	0x17
 
 struct emu_memblk {
 	SLIST_ENTRY(emu_memblk) link;
@@ -247,9 +329,9 @@
 {
 	u_int32_t ptr, val, mask, size, offset;
 
-	ptr = ((reg << 16) & sc->addrmask) | (chn & PTR_CHANNELNUM_MASK);
-	emu_wr(sc, PTR, ptr, 4);
-	val = emu_rd(sc, DATA, 4);
+	ptr = ((reg << 16) & sc->addrmask) | (chn & EMU_PTR_CHNO_MASK);
+	emu_wr(sc, EMU_PTR, ptr, 4);
+	val = emu_rd(sc, EMU_DATA, 4);
 	if (reg & 0xff000000) {
 		size = (reg >> 24) & 0x3f;
 		offset = (reg >> 16) & 0x1f;
@@ -265,23 +347,23 @@
 {
 	u_int32_t ptr, mask, size, offset;
 
-	ptr = ((reg << 16) & sc->addrmask) | (chn & PTR_CHANNELNUM_MASK);
-	emu_wr(sc, PTR, ptr, 4);
+	ptr = ((reg << 16) & sc->addrmask) | (chn & EMU_PTR_CHNO_MASK);
+	emu_wr(sc, EMU_PTR, ptr, 4);
 	if (reg & 0xff000000) {
 		size = (reg >> 24) & 0x3f;
 		offset = (reg >> 16) & 0x1f;
 		mask = ((1 << size) - 1) << offset;
 		data <<= offset;
 		data &= mask;
-		data |= emu_rd(sc, DATA, 4) & ~mask;
+		data |= emu_rd(sc, EMU_DATA, 4) & ~mask;
 	}
-	emu_wr(sc, DATA, data, 4);
+	emu_wr(sc, EMU_DATA, data, 4);
 }
 
 static void
 emu_wrefx(struct sc_info *sc, unsigned int pc, unsigned int data)
 {
-	pc += sc->audigy ? A_MICROCODEBASE : MICROCODEBASE;
+	pc += sc->audigy ? EMU_A_MICROCODEBASE : EMU_MICROCODEBASE;
 	emu_wrptr(sc, 0, pc, data);
 }
 
@@ -294,8 +376,8 @@
 {
 	struct sc_info *sc = (struct sc_info *)devinfo;
 
-	emu_wr(sc, AC97ADDRESS, regno, 1);
-	return emu_rd(sc, AC97DATA, 2);
+	emu_wr(sc, EMU_AC97ADDR, regno, 1);
+	return emu_rd(sc, EMU_AC97DATA, 2);
 }
 
 static int
@@ -303,8 +385,8 @@
 {
 	struct sc_info *sc = (struct sc_info *)devinfo;
 
-	emu_wr(sc, AC97ADDRESS, regno, 1);
-	emu_wr(sc, AC97DATA, data, 2);
+	emu_wr(sc, EMU_AC97ADDR, regno, 1);
+	emu_wr(sc, EMU_AC97DATA, data, 2);
 	return 0;
 }
 
@@ -346,7 +428,7 @@
 	}
 	RANGE(rate, 48, 9600);
 	sc->timerinterval = 48000 / rate;
-	emu_wr(sc, TIMER, sc->timerinterval & 0x03ff, 2);
+	emu_wr(sc, EMU_TIMER, sc->timerinterval & 0x03ff, 2);
 
 	return sc->timerinterval;
 }
@@ -357,15 +439,15 @@
 	u_int32_t x;
 	if (go) {
 		if (sc->timer++ == 0) {
-			x = emu_rd(sc, INTE, 4);
-			x |= INTE_INTERVALTIMERENB;
-			emu_wr(sc, INTE, x, 4);
+			x = emu_rd(sc, EMU_INTE, 4);
+			x |= EMU_INTE_INTERTIMERENB;
+			emu_wr(sc, EMU_INTE, x, 4);
 		}
 	} else {
 		sc->timer = 0;
-		x = emu_rd(sc, INTE, 4);
-		x &= ~INTE_INTERVALTIMERENB;
-		emu_wr(sc, INTE, x, 4);
+		x = emu_rd(sc, EMU_INTE, 4);
+		x &= ~EMU_INTE_INTERTIMERENB;
+		emu_wr(sc, EMU_INTE, x, 4);
 	}
 	return 0;
 }
@@ -373,7 +455,7 @@
 static void
 emu_enastop(struct sc_info *sc, char channel, int enable)
 {
-	int reg = (channel & 0x20) ? SOLEH : SOLEL;
+	int reg = (channel & 0x20) ? EMU_SOLEH : EMU_SOLEL;
 	channel &= 0x1f;
 	reg |= 1 << 24;
 	reg |= channel << 16;
@@ -568,49 +650,49 @@
 		r = v->ismaster ? 0 : r;
 	}
 
-	emu_wrptr(sc, v->vnum, CPF, v->stereo ? CPF_STEREO_MASK : 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_CPF, v->stereo ? EMU_CHAN_CPF_STEREO_MASK : 0);
 	val = v->stereo ? 28 : 30;
 	val *= v->b16 ? 1 : 2;
 	start = sa + val;
 
 	if (sc->audigy) {
-		emu_wrptr(sc, v->vnum, A_FXRT1, v->fxrt1);
-		emu_wrptr(sc, v->vnum, A_FXRT2, v->fxrt2);
-		emu_wrptr(sc, v->vnum, A_SENDAMOUNTS, 0);
+		emu_wrptr(sc, v->vnum, EMU_A_CHAN_FXRT1, v->fxrt1);
+		emu_wrptr(sc, v->vnum, EMU_A_CHAN_FXRT2, v->fxrt2);
+		emu_wrptr(sc, v->vnum, EMU_A_CHAN_SENDAMOUNTS, 0);
 	}
 	else
-		emu_wrptr(sc, v->vnum, FXRT, v->fxrt1 << 16);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_FXRT, v->fxrt1 << 16);
 
-	emu_wrptr(sc, v->vnum, PTRX, (x << 8) | r);
-	emu_wrptr(sc, v->vnum, DSL, ea | (y << 24));
-	emu_wrptr(sc, v->vnum, PSST, sa | (l << 24));
-	emu_wrptr(sc, v->vnum, CCCA, start | (v->b16 ? 0 : CCCA_8BITSELECT));
+	emu_wrptr(sc, v->vnum, EMU_CHAN_PTRX, (x << 8) | r);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_DSL, ea | (y << 24));
+	emu_wrptr(sc, v->vnum, EMU_CHAN_PSST, sa | (l << 24));
+	emu_wrptr(sc, v->vnum, EMU_CHAN_CCCA, start | (v->b16 ? 0 : EMU_CHAN_CCCA_8BITSELECT));
 
-	emu_wrptr(sc, v->vnum, Z1, 0);
-	emu_wrptr(sc, v->vnum, Z2, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_Z1, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_Z2, 0);
 
 	silent_page = ((u_int32_t)(sc->mem.silent_page_addr) << 1)
-	    | MAP_PTI_MASK;
-	emu_wrptr(sc, v->vnum, MAPA, silent_page);
-	emu_wrptr(sc, v->vnum, MAPB, silent_page);
+	    | EMU_CHAN_MAP_PTI_MASK;
+	emu_wrptr(sc, v->vnum, EMU_CHAN_MAPA, silent_page);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_MAPB, silent_page);
 
-	emu_wrptr(sc, v->vnum, CVCF, CVCF_CURRENTFILTER_MASK);
-	emu_wrptr(sc, v->vnum, VTFT, VTFT_FILTERTARGET_MASK);
-	emu_wrptr(sc, v->vnum, ATKHLDM, 0);
-	emu_wrptr(sc, v->vnum, DCYSUSM, DCYSUSM_DECAYTIME_MASK);
-	emu_wrptr(sc, v->vnum, LFOVAL1, 0x8000);
-	emu_wrptr(sc, v->vnum, LFOVAL2, 0x8000);
-	emu_wrptr(sc, v->vnum, FMMOD, 0);
-	emu_wrptr(sc, v->vnum, TREMFRQ, 0);
-	emu_wrptr(sc, v->vnum, FM2FRQ2, 0);
-	emu_wrptr(sc, v->vnum, ENVVAL, 0x8000);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_CVCF, EMU_CHAN_CVCF_CURRFILTER_MASK);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_VTFT, EMU_CHAN_VTFT_FILTERTARGET_MASK);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_ATKHLDM, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_DCYSUSM, EMU_CHAN_DCYSUSM_DECAYTIME_MASK);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_LFOVAL1, 0x8000);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_LFOVAL2, 0x8000);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_FMMOD, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_TREMFRQ, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_FM2FRQ2, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_ENVVAL, 0x8000);
 
-	emu_wrptr(sc, v->vnum, ATKHLDV,
-	    ATKHLDV_HOLDTIME_MASK | ATKHLDV_ATTACKTIME_MASK);
-	emu_wrptr(sc, v->vnum, ENVVOL, 0x8000);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_ATKHLDV,
+	    EMU_CHAN_ATKHLDV_HOLDTIME_MASK | EMU_CHAN_ATKHLDV_ATTACKTIME_MASK);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_ENVVOL, 0x8000);
 
-	emu_wrptr(sc, v->vnum, PEFE_FILTERAMOUNT, 0x7f);
-	emu_wrptr(sc, v->vnum, PEFE_PITCHAMOUNT, 0);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_PEFE_FILTERAMOUNT, 0x7f);
+	emu_wrptr(sc, v->vnum, EMU_CHAN_PEFE_PITCHAMOUNT, 0);
 
 	if (v->slave != NULL)
 		emu_vwrite(sc, v->slave);
@@ -631,29 +713,29 @@
 		sample = v->b16 ? 0x00000000 : 0x80808080;
 
 		for (i = 0; i < cs; i++)
-			emu_wrptr(sc, v->vnum, CD0 + i, sample);
-		emu_wrptr(sc, v->vnum, CCR_CACHEINVALIDSIZE, 0);
-		emu_wrptr(sc, v->vnum, CCR_READADDRESS, cra);
-		emu_wrptr(sc, v->vnum, CCR_CACHEINVALIDSIZE, ccis);
+			emu_wrptr(sc, v->vnum, EMU_CHAN_CD0 + i, sample);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CCR_CACHEINVALIDSIZE, 0);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CCR_READADDRESS, cra);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CCR_CACHEINVALIDSIZE, ccis);
 
-		emu_wrptr(sc, v->vnum, IFATN, 0xff00);
-		emu_wrptr(sc, v->vnum, VTFT, 0xffffffff);
-		emu_wrptr(sc, v->vnum, CVCF, 0xffffffff);
-		emu_wrptr(sc, v->vnum, DCYSUSV, 0x00007f7f);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_IFATN, 0xff00);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_VTFT, 0xffffffff);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CVCF, 0xffffffff);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_DCYSUSV, 0x00007f7f);
 		emu_enastop(sc, v->vnum, 0);
 
 		pitch_target = emu_rate_to_linearpitch(v->speed);
 		initial_pitch = emu_rate_to_pitch(v->speed) >> 8;
-		emu_wrptr(sc, v->vnum, PTRX_PITCHTARGET, pitch_target);
-		emu_wrptr(sc, v->vnum, CPF_CURRENTPITCH, pitch_target);
-		emu_wrptr(sc, v->vnum, IP, initial_pitch);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_PTRX_PITCHTARGET, pitch_target);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CPF_PITCH, pitch_target);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_IP, initial_pitch);
 	} else {
-		emu_wrptr(sc, v->vnum, PTRX_PITCHTARGET, 0);
-		emu_wrptr(sc, v->vnum, CPF_CURRENTPITCH, 0);
-		emu_wrptr(sc, v->vnum, IFATN, 0xffff);
-		emu_wrptr(sc, v->vnum, VTFT, 0x0000ffff);
-		emu_wrptr(sc, v->vnum, CVCF, 0x0000ffff);
-		emu_wrptr(sc, v->vnum, IP, 0);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_PTRX_PITCHTARGET, 0);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CPF_PITCH, 0);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_IFATN, 0xffff);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_VTFT, 0x0000ffff);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_CVCF, 0x0000ffff);
+		emu_wrptr(sc, v->vnum, EMU_CHAN_IP, 0);
 		emu_enastop(sc, v->vnum, 1);
 	}
 	if (v->slave != NULL)
@@ -666,7 +748,7 @@
 	int s, ptr;
 
 	s = (v->b16 ? 1 : 0) + (v->stereo ? 1 : 0);
-	ptr = (emu_rdptr(sc, v->vnum, CCCA_CURRADDR) - (v->start >> s)) << s;
+	ptr = (emu_rdptr(sc, v->vnum, EMU_CHAN_CCCA_CURRADDR) - (v->start >> s)) << s;
 	return ptr & ~0x0000001f;
 }
 
@@ -875,27 +957,27 @@
 	ch->num = sc->rnum;
 	switch(sc->rnum) {
 	case 0:
-		ch->idxreg = sc->audigy ? A_ADCIDX : ADCIDX;
-		ch->basereg = ADCBA;
-		ch->sizereg = ADCBS;
-		ch->setupreg = ADCCR;
-		ch->irqmask = INTE_ADCBUFENABLE;
+		ch->idxreg = sc->audigy ? EMU_A_ADCIDX : EMU_ADCIDX;
+		ch->basereg = EMU_ADCBA;
+		ch->sizereg = EMU_ADCBS;
+		ch->setupreg = EMU_ADCCR;
+		ch->irqmask = EMU_INTE_ADCBUFENABLE;
 		break;
 
 	case 1:
-		ch->idxreg = FXIDX;
-		ch->basereg = FXBA;
-		ch->sizereg = FXBS;
-		ch->setupreg = FXWC;
-		ch->irqmask = INTE_EFXBUFENABLE;
+		ch->idxreg = EMU_FXIDX;
+		ch->basereg = EMU_FXBA;
+		ch->sizereg = EMU_FXBS;
+		ch->setupreg = EMU_FXWC;
+		ch->irqmask = EMU_INTE_EFXBUFENABLE;
 		break;
 
 	case 2:
-		ch->idxreg = MICIDX;
-		ch->basereg = MICBA;
-		ch->sizereg = MICBS;
+		ch->idxreg = EMU_MICIDX;
+		ch->basereg = EMU_MICBA;
+		ch->sizereg = EMU_MICBS;
 		ch->setupreg = 0;
-		ch->irqmask = INTE_MICBUFENABLE;
+		ch->irqmask = EMU_INTE_MICBUFENABLE;
 		break;
 	}
 	sc->rnum++;
@@ -967,27 +1049,27 @@
 
 	switch(sc->bufsz) {
 	case 4096:
-		sz = ADCBS_BUFSIZE_4096;
+		sz = EMU_RECBS_BUFSIZE_4096;
 		break;
 
 	case 8192:
-		sz = ADCBS_BUFSIZE_8192;
+		sz = EMU_RECBS_BUFSIZE_8192;
 		break;
 
 	case 16384:
-		sz = ADCBS_BUFSIZE_16384;
+		sz = EMU_RECBS_BUFSIZE_16384;
 		break;
 
 	case 32768:
-		sz = ADCBS_BUFSIZE_32768;
+		sz = EMU_RECBS_BUFSIZE_32768;
 		break;
 
 	case 65536:
-		sz = ADCBS_BUFSIZE_65536;
+		sz = EMU_RECBS_BUFSIZE_65536;
 		break;
 
 	default:
-		sz = ADCBS_BUFSIZE_4096;
+		sz = EMU_RECBS_BUFSIZE_4096;
 	}
 
 	snd_mtxlock(sc->lock);
@@ -997,23 +1079,23 @@
 		emu_wrptr(sc, 0, ch->sizereg, sz);
 		if (ch->num == 0) {
 			if (sc->audigy) {
-				val = A_ADCCR_LCHANENABLE;
+				val = EMU_ADCCR_LCHANENABLE;
 				if (AFMT_CHANNEL(ch->fmt) > 1)
-					val |= A_ADCCR_RCHANENABLE;
+					val |= EMU_ADCCR_RCHANENABLE;
 				val |= audigy_recval(ch->spd);
 			} else {
-				val = ADCCR_LCHANENABLE;
+				val = EMU_ADCCR_LCHANENABLE;
 				if (AFMT_CHANNEL(ch->fmt) > 1)
-					val |= ADCCR_RCHANENABLE;
+					val |= EMU_ADCCR_RCHANENABLE;
 				val |= emu_recval(ch->spd);
 			}
 
 			emu_wrptr(sc, 0, ch->setupreg, 0);
 			emu_wrptr(sc, 0, ch->setupreg, val);
 		}
-		val = emu_rd(sc, INTE, 4);
+		val = emu_rd(sc, EMU_INTE, 4);
 		val |= ch->irqmask;
-		emu_wr(sc, INTE, val, 4);
+		emu_wr(sc, EMU_INTE, val, 4);
 		break;
 
 	case PCMTRIG_STOP:
@@ -1022,9 +1104,9 @@
 		emu_wrptr(sc, 0, ch->sizereg, 0);
 		if (ch->setupreg)
 			emu_wrptr(sc, 0, ch->setupreg, 0);
-		val = emu_rd(sc, INTE, 4);
+		val = emu_rd(sc, EMU_INTE, 4);
 		val &= ~ch->irqmask;
-		emu_wr(sc, INTE, val, 4);
+		emu_wr(sc, EMU_INTE, val, 4);
 		break;
 
 	case PCMTRIG_EMLDMAWR:
@@ -1122,9 +1204,9 @@
 {
 	int i;
 
-	i = emu_rd(sc, INTE, 4);
-	i |= INTE_MIDIRXENABLE;
-	emu_wr(sc, INTE, i, 4);
+	i = emu_rd(sc, EMU_INTE, 4);
+	i |= EMU_INTE_MIDIRXENABLE;
+	emu_wr(sc, EMU_INTE, i, 4);
 
 	sc->mpu = mpu401_init(&emu_mpu_class, sc, emu_intr2, &sc->mpu_intr);
 }
@@ -1139,52 +1221,52 @@
 
 	snd_mtxlock(sc->lock);
 	while (1) {
-		stat = emu_rd(sc, IPR, 4);
+		stat = emu_rd(sc, EMU_IPR, 4);
 		if (stat == 0)
 			break;
 		ack = 0;
 
 		/* process irq */
-		if (stat & IPR_INTERVALTIMER)
-			ack |= IPR_INTERVALTIMER;
+		if (stat & EMU_IPR_INTERVALTIMER)
+			ack |= EMU_IPR_INTERVALTIMER;
 
-		if (stat & (IPR_ADCBUFFULL | IPR_ADCBUFHALFFULL))
-			ack |= stat & (IPR_ADCBUFFULL | IPR_ADCBUFHALFFULL);
+		if (stat & (EMU_IPR_ADCBUFFULL | EMU_IPR_ADCBUFHALFFULL))
+			ack |= stat & (EMU_IPR_ADCBUFFULL | EMU_IPR_ADCBUFHALFFULL);
 
-		if (stat & (IPR_EFXBUFFULL | IPR_EFXBUFHALFFULL))
-			ack |= stat & (IPR_EFXBUFFULL | IPR_EFXBUFHALFFULL);
+		if (stat & (EMU_IPR_EFXBUFFULL | EMU_IPR_EFXBUFHALFFULL))
+			ack |= stat & (EMU_IPR_EFXBUFFULL | EMU_IPR_EFXBUFHALFFULL);
 
-		if (stat & (IPR_MICBUFFULL | IPR_MICBUFHALFFULL))
-			ack |= stat & (IPR_MICBUFFULL | IPR_MICBUFHALFFULL);
+		if (stat & (EMU_IPR_MICBUFFULL | EMU_IPR_MICBUFHALFFULL))
+			ack |= stat & (EMU_IPR_MICBUFFULL | EMU_IPR_MICBUFHALFFULL);
 
-		if (stat & IPR_PCIERROR) {
-			ack |= IPR_PCIERROR;
+		if (stat & EMU_PCIERROR) {
+			ack |= EMU_PCIERROR;
 			device_printf(sc->dev, "pci error\n");
 			/* we still get an nmi with ecc ram even if we ack this */
 		}
-		if (stat & IPR_SAMPLERATETRACKER) {
-			ack |= IPR_SAMPLERATETRACKER;
+		if (stat & EMU_IPR_RATETRCHANGE) {
+			ack |= EMU_IPR_RATETRCHANGE;
 #ifdef EMUDEBUG
 			device_printf(sc->dev,
 			    "sample rate tracker lock status change\n");
 #endif
 		}
 
-	    if (stat & IPR_MIDIRECVBUFEMPTY)
+	    if (stat & EMU_IPR_MIDIRECVBUFE)
 		if (sc->mpu_intr) {
 		    (sc->mpu_intr)(sc->mpu);
-		    ack |= IPR_MIDIRECVBUFEMPTY | IPR_MIDITRANSBUFEMPTY;
+		    ack |= EMU_IPR_MIDIRECVBUFE | EMU_IPR_MIDITRANSBUFE;
  		}
 		if (stat & ~ack)
 			device_printf(sc->dev, "dodgy irq: %x (harmless)\n",
 			    stat & ~ack);
 
-		emu_wr(sc, IPR, stat, 4);
+		emu_wr(sc, EMU_IPR, stat, 4);
 
 		if (ack) {
 			snd_mtxunlock(sc->lock);
 
-			if (ack & IPR_INTERVALTIMER) {
+			if (ack & EMU_IPR_INTERVALTIMER) {
 				x = 0;
 				for (i = 0; i < sc->nchans; i++) {
 					if (sc->pch[i].run) {
@@ -1197,15 +1279,15 @@
 			}
 
 
-			if (ack & (IPR_ADCBUFFULL | IPR_ADCBUFHALFFULL)) {
+			if (ack & (EMU_IPR_ADCBUFFULL | EMU_IPR_ADCBUFHALFFULL)) {
 				if (sc->rch[0].channel)
 					chn_intr(sc->rch[0].channel);
 			}
-			if (ack & (IPR_EFXBUFFULL | IPR_EFXBUFHALFFULL)) {
+			if (ack & (EMU_IPR_EFXBUFFULL | EMU_IPR_EFXBUFHALFFULL)) {
 				if (sc->rch[1].channel)
 					chn_intr(sc->rch[1].channel);
 			}
-			if (ack & (IPR_MICBUFFULL | IPR_MICBUFHALFFULL)) {
+			if (ack & (EMU_IPR_MICBUFFULL | EMU_IPR_MICBUFHALFFULL)) {
 				if (sc->rch[2].channel)
 					chn_intr(sc->rch[2].channel);
 			}
@@ -1378,12 +1460,12 @@
 		audigy_addefxop(sc, 0x0f, 0x0c0, 0x0c0, 0x0cf, 0x0c0, &pc);
 
 	for (i = 0; i < 512; i++)
-		emu_wrptr(sc, 0, A_FXGPREGBASE + i, 0x0);
+		emu_wrptr(sc, 0, EMU_A_FXGPREGBASE + i, 0x0);
 
 	pc = 16;
 
 	/* stop fx processor */
-	emu_wrptr(sc, 0, A_DBG, A_DBG_SINGLE_STEP);
+	emu_wrptr(sc, 0, EMU_A_DBG, EMU_A_DBG_SINGLE_STEP);
 
 	/* Audigy 2 (EMU10K2) DSP Registers:
 	   FX Bus
@@ -1518,7 +1600,7 @@
 			A_C_00000000, A_EXTIN(A_EXTIN_AC97_R), &pc);
 
 	/* resume normal operations */
-	emu_wrptr(sc, 0, A_DBG, 0);
+	emu_wrptr(sc, 0, EMU_A_DBG, 0);
 }
 
 static void
@@ -1534,7 +1616,7 @@
 	}
 
 	for (i = 0; i < 256; i++)
-		emu_wrptr(sc, 0, FXGPREGBASE + i, 0);
+		emu_wrptr(sc, 0, EMU_FXGPREGBASE + i, 0);
 
 	/* FX-8010 DSP Registers:
 	   FX Bus
@@ -1654,7 +1736,7 @@
 			C_00000000, EXTIN(EXTIN_AC97_R), &pc);
 
 	/* resume normal operations */
-	emu_wrptr(sc, 0, DBG, 0);
+	emu_wrptr(sc, 0, EMU_DBG, 0);
 }
 
 /* Probe and attach the card */
@@ -1665,69 +1747,69 @@
 
 	if (sc->audigy) {
 		/* enable additional AC97 slots */
-		emu_wrptr(sc, 0, AC97SLOT, AC97SLOT_CNTR | AC97SLOT_LFE);
+		emu_wrptr(sc, 0, EMU_AC97SLOT, EMU_AC97SLOT_CENTER | EMU_AC97SLOT_LFE);
 	}
 
 	/* disable audio and lock cache */
-	emu_wr(sc, HCFG,
-	    HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
+	emu_wr(sc, EMU_HCFG,
+	    EMU_HCFG_LOCKSOUNDCACHE | EMU_HCFG_LOCKTANKCACHE_MASK | EMU_HCFG_MUTEBUTTONENABLE,
 	    4);
 
 	/* reset recording buffers */
-	emu_wrptr(sc, 0, MICBS, ADCBS_BUFSIZE_NONE);
-	emu_wrptr(sc, 0, MICBA, 0);
-	emu_wrptr(sc, 0, FXBS, ADCBS_BUFSIZE_NONE);
-	emu_wrptr(sc, 0, FXBA, 0);
-	emu_wrptr(sc, 0, ADCBS, ADCBS_BUFSIZE_NONE);
-	emu_wrptr(sc, 0, ADCBA, 0);
+	emu_wrptr(sc, 0, EMU_MICBS, EMU_RECBS_BUFSIZE_NONE);
+	emu_wrptr(sc, 0, EMU_MICBA, 0);
+	emu_wrptr(sc, 0, EMU_FXBS, EMU_RECBS_BUFSIZE_NONE);
+	emu_wrptr(sc, 0, EMU_FXBA, 0);
+	emu_wrptr(sc, 0, EMU_ADCBS, EMU_RECBS_BUFSIZE_NONE);
+	emu_wrptr(sc, 0, EMU_ADCBA, 0);
 
 	/* disable channel interrupt */
-	emu_wr(sc, INTE,
-	    INTE_INTERVALTIMERENB | INTE_SAMPLERATETRACKER | INTE_PCIERRORENABLE,
+	emu_wr(sc, EMU_INTE,
+	    EMU_INTE_INTERTIMERENB | EMU_INTE_SAMPLERATER | EMU_INTE_PCIERRENABLE,
 	    4);
-	emu_wrptr(sc, 0, CLIEL, 0);
-	emu_wrptr(sc, 0, CLIEH, 0);
-	emu_wrptr(sc, 0, SOLEL, 0);
-	emu_wrptr(sc, 0, SOLEH, 0);
+	emu_wrptr(sc, 0, EMU_CLIEL, 0);
+	emu_wrptr(sc, 0, EMU_CLIEH, 0);
+	emu_wrptr(sc, 0, EMU_SOLEL, 0);
+	emu_wrptr(sc, 0, EMU_SOLEH, 0);
 
 	/* wonder what these do... */
 	if (sc->audigy) {
-		emu_wrptr(sc, 0, SPBYPASS, 0xf00);
-		emu_wrptr(sc, 0, AC97SLOT, 0x3);
+		emu_wrptr(sc, 0, EMU_SPBYPASS, 0xf00);
+		emu_wrptr(sc, 0, EMU_AC97SLOT, 0x3);
 	}
 
 	/* init envelope engine */
 	for (ch = 0; ch < NUM_G; ch++) {
-		emu_wrptr(sc, ch, DCYSUSV, ENV_OFF);
-		emu_wrptr(sc, ch, IP, 0);
-		emu_wrptr(sc, ch, VTFT, 0xffff);
-		emu_wrptr(sc, ch, CVCF, 0xffff);
-		emu_wrptr(sc, ch, PTRX, 0);
-		emu_wrptr(sc, ch, CPF, 0);
-		emu_wrptr(sc, ch, CCR, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_DCYSUSV, ENV_OFF);
+		emu_wrptr(sc, ch, EMU_CHAN_IP, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_VTFT, 0xffff);
+		emu_wrptr(sc, ch, EMU_CHAN_CVCF, 0xffff);
+		emu_wrptr(sc, ch, EMU_CHAN_PTRX, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_CPF, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_CCR, 0);
 
-		emu_wrptr(sc, ch, PSST, 0);
-		emu_wrptr(sc, ch, DSL, 0x10);
-		emu_wrptr(sc, ch, CCCA, 0);
-		emu_wrptr(sc, ch, Z1, 0);
-		emu_wrptr(sc, ch, Z2, 0);
-		emu_wrptr(sc, ch, FXRT, 0xd01c0000);
+		emu_wrptr(sc, ch, EMU_CHAN_PSST, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_DSL, 0x10);
+		emu_wrptr(sc, ch, EMU_CHAN_CCCA, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_Z1, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_Z2, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_FXRT, 0xd01c0000);
 
-		emu_wrptr(sc, ch, ATKHLDM, 0);
-		emu_wrptr(sc, ch, DCYSUSM, 0);
-		emu_wrptr(sc, ch, IFATN, 0xffff);
-		emu_wrptr(sc, ch, PEFE, 0);
-		emu_wrptr(sc, ch, FMMOD, 0);
-		emu_wrptr(sc, ch, TREMFRQ, 24);	/* 1 Hz */
-		emu_wrptr(sc, ch, FM2FRQ2, 24);	/* 1 Hz */
-		emu_wrptr(sc, ch, TEMPENV, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_ATKHLDM, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_DCYSUSM, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_IFATN, 0xffff);
+		emu_wrptr(sc, ch, EMU_CHAN_PEFE, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_FMMOD, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_TREMFRQ, 24);	/* 1 Hz */
+		emu_wrptr(sc, ch, EMU_CHAN_FM2FRQ2, 24);	/* 1 Hz */
+		emu_wrptr(sc, ch, EMU_CHAN_TEMPENV, 0);
 
 		/*** these are last so OFF prevents writing ***/
-		emu_wrptr(sc, ch, LFOVAL2, 0);
-		emu_wrptr(sc, ch, LFOVAL1, 0);
-		emu_wrptr(sc, ch, ATKHLDV, 0);
-		emu_wrptr(sc, ch, ENVVOL, 0);
-		emu_wrptr(sc, ch, ENVVAL, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_LFOVAL2, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_LFOVAL1, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_ATKHLDV, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_ENVVOL, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_ENVVAL, 0);
 
 		if (sc->audigy) {
 			/* audigy cards need this to initialize correctly */
@@ -1736,9 +1818,9 @@
 			emu_wrptr(sc, ch, 0x4e, 0);
 			emu_wrptr(sc, ch, 0x4f, 0);
 			/* set default routing */
-			emu_wrptr(sc, ch, A_FXRT1, 0x03020100);
-			emu_wrptr(sc, ch, A_FXRT2, 0x3f3f3f3f);
-			emu_wrptr(sc, ch, A_SENDAMOUNTS, 0);
+			emu_wrptr(sc, ch, EMU_A_CHAN_FXRT1, 0x03020100);
+			emu_wrptr(sc, ch, EMU_A_CHAN_FXRT2, 0x3f3f3f3f);
+			emu_wrptr(sc, ch, EMU_A_CHAN_SENDAMOUNTS, 0);
 		}
 
 		sc->voice[ch].vnum = ch;
@@ -1769,13 +1851,13 @@
 	 *  AN                = 0     (Audio data)
 	 *  P                 = 0     (Consumer)
 	 */
-	spcs = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
-	    SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
-	    SPCS_GENERATIONSTATUS | 0x00001200 | 0x00000000 |
-	    SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
-	emu_wrptr(sc, 0, SPCS0, spcs);
-	emu_wrptr(sc, 0, SPCS1, spcs);
-	emu_wrptr(sc, 0, SPCS2, spcs);
+	spcs = EMU_SPCS_CLKACCY_1000PPM | EMU_SPCS_SAMPLERATE_48 |
+	    EMU_SPCS_CHANNELNUM_LEFT | EMU_SPCS_SOURCENUM_UNSPEC |
+	    EMU_SPCS_GENERATIONSTATUS | 0x00001200 | 0x00000000 |
+	    EMU_SPCS_EMPHASIS_NONE | EMU_SPCS_COPYRIGHT;
+	emu_wrptr(sc, 0, EMU_SPCS0, spcs);
+	emu_wrptr(sc, 0, EMU_SPCS1, spcs);
+	emu_wrptr(sc, 0, EMU_SPCS2, spcs);
 
 	if (!sc->audigy)
 		emu_initefx(sc);
@@ -1786,8 +1868,8 @@
 		u_int32_t tmp;
 
 		/* Setup SRCMulti_I2S SamplingRate */
-		tmp = emu_rdptr(sc, 0, A_SPDIF_SAMPLERATE) & 0xfffff1ff;
-		emu_wrptr(sc, 0, A_SPDIF_SAMPLERATE, tmp | 0x400);
+		tmp = emu_rdptr(sc, 0, EMU_A_SPDIF_SAMPLERATE) & 0xfffff1ff;
+		emu_wrptr(sc, 0, EMU_A_SPDIF_SAMPLERATE, tmp | 0x400);
 
 		/* Setup SRCSel (Enable SPDIF, I2S SRCMulti) */
 		emu_wr(sc, 0x20, 0x00600000, 4);
@@ -1816,13 +1898,13 @@
 	for (i = 0; i < EMUMAXPAGES; i++)
 		sc->mem.ptb_pages[i] = tmp | i;
 
-	emu_wrptr(sc, 0, PTB, (sc->mem.ptb_pages_addr));
-	emu_wrptr(sc, 0, TCB, 0);	/* taken from original driver */
-	emu_wrptr(sc, 0, TCBS, 0);	/* taken from original driver */
+	emu_wrptr(sc, 0, EMU_PTB, (sc->mem.ptb_pages_addr));
+	emu_wrptr(sc, 0, EMU_TCB, 0);	/* taken from original driver */
+	emu_wrptr(sc, 0, EMU_TCBS, 0);	/* taken from original driver */
 
 	for (ch = 0; ch < NUM_G; ch++) {
-		emu_wrptr(sc, ch, MAPA, tmp | MAP_PTI_MASK);
-		emu_wrptr(sc, ch, MAPB, tmp | MAP_PTI_MASK);
+		emu_wrptr(sc, ch, EMU_CHAN_MAPA, tmp | EMU_CHAN_MAP_PTI_MASK);
+		emu_wrptr(sc, ch, EMU_CHAN_MAPB, tmp | EMU_CHAN_MAP_PTI_MASK);
 	}
 
 	/* emu_memalloc(sc, EMUPAGESIZE); */
@@ -1850,19 +1932,19 @@
 	 */
 
 	if (sc->audigy) {
-		tmp = HCFG_AUTOMUTE | HCFG_JOYENABLE;
+		tmp = EMU_HCFG_AUTOMUTE | EMU_HCFG_JOYENABLE;
 		if (sc->audigy2)	/* Audigy 2 */
-			tmp = HCFG_AUDIOENABLE | HCFG_AC3ENABLE_CDSPDIF |
-			    HCFG_AC3ENABLE_GPSPDIF;
-		emu_wr(sc, HCFG, tmp, 4);
+			tmp = EMU_HCFG_AUDIOENABLE | EMU_HCFG_AC3ENABLE_CDSPDIF |
+			    EMU_HCFG_AC3ENABLE_GPSPDIF;
+		emu_wr(sc, EMU_HCFG, tmp, 4);
 
 		audigy_initefx(sc);
 
 		/* from ALSA initialization code: */
 
 		/* enable audio and disable both audio/digital outputs */
-		emu_wr(sc, HCFG, emu_rd(sc, HCFG, 4) | HCFG_AUDIOENABLE, 4);
-		emu_wr(sc, A_IOCFG, emu_rd(sc, A_IOCFG, 4) & ~A_IOCFG_GPOUT_AD,
+		emu_wr(sc, EMU_HCFG, emu_rd(sc, EMU_HCFG, 4) | EMU_HCFG_AUDIOENABLE, 4);
+		emu_wr(sc, EMU_A_IOCFG, emu_rd(sc, EMU_A_IOCFG, 4) & ~EMU_A_IOCFG_GPOUT_AD,
 		    4);
 		if (sc->audigy2) {	/* Audigy 2 */
 			/* Unmute Analog.
@@ -1870,27 +1952,27 @@
 			 * init Alice3 I2SOut beyond 48kHz.
 			 * So, sequence is important.
 			 */
-			emu_wr(sc, A_IOCFG,
-			    emu_rd(sc, A_IOCFG, 4) | A_IOCFG_GPOUT_A, 4);
+			emu_wr(sc, EMU_A_IOCFG,
+			    emu_rd(sc, EMU_A_IOCFG, 4) | EMU_A_IOCFG_GPOUT_A, 4);
 		}
 	} else {
 		/* EMU10K1 initialization code */
-		tmp = HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK 
-		    | HCFG_AUTOMUTE;
+		tmp = EMU_HCFG_AUDIOENABLE | EMU_HCFG_LOCKTANKCACHE_MASK 
+		    | EMU_HCFG_AUTOMUTE;
 		if (sc->rev >= 6)
-			tmp |= HCFG_JOYENABLE;
+			tmp |= EMU_HCFG_JOYENABLE;
 
-		emu_wr(sc, HCFG, tmp, 4);
+		emu_wr(sc, EMU_HCFG, tmp, 4);
 
 		/* TOSLink detection */
 		sc->tos_link = 0;
-		tmp = emu_rd(sc, HCFG, 4);
-		if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
-			emu_wr(sc, HCFG, tmp | HCFG_GPOUT1, 4);
+		tmp = emu_rd(sc, EMU_HCFG, 4);
+		if (tmp & (EMU_HCFG_GPINPUT0 | EMU_HCFG_GPINPUT1)) {
+			emu_wr(sc, EMU_HCFG, tmp | EMU_HCFG_GPOUT1, 4);
 			DELAY(50);
-			if (tmp != (emu_rd(sc, HCFG, 4) & ~HCFG_GPOUT1)) {
+			if (tmp != (emu_rd(sc, EMU_HCFG, 4) & ~EMU_HCFG_GPOUT1)) {
 				sc->tos_link = 1;
-				emu_wr(sc, HCFG, tmp, 4);
+				emu_wr(sc, EMU_HCFG, tmp, 4);
 			}
 		}
 	}
@@ -1903,42 +1985,42 @@
 {
 	u_int32_t ch;
 
-	emu_wr(sc, INTE, 0, 4);
+	emu_wr(sc, EMU_INTE, 0, 4);
 	for (ch = 0; ch < NUM_G; ch++)
-		emu_wrptr(sc, ch, DCYSUSV, ENV_OFF);
+		emu_wrptr(sc, ch, EMU_CHAN_DCYSUSV, ENV_OFF);
 	for (ch = 0; ch < NUM_G; ch++) {
-		emu_wrptr(sc, ch, VTFT, 0);
-		emu_wrptr(sc, ch, CVCF, 0);
-		emu_wrptr(sc, ch, PTRX, 0);
-		emu_wrptr(sc, ch, CPF, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_VTFT, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_CVCF, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_PTRX, 0);
+		emu_wrptr(sc, ch, EMU_CHAN_CPF, 0);
 	}
 
 	if (sc->audigy) {	/* stop fx processor */
-		emu_wrptr(sc, 0, A_DBG, A_DBG_SINGLE_STEP);
+		emu_wrptr(sc, 0, EMU_A_DBG, EMU_A_DBG_SINGLE_STEP);
 	}
 
 	/* disable audio and lock cache */
-	emu_wr(sc, HCFG,
-	    HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
+	emu_wr(sc, EMU_HCFG,
+	    EMU_HCFG_LOCKSOUNDCACHE | EMU_HCFG_LOCKTANKCACHE_MASK | EMU_HCFG_MUTEBUTTONENABLE,
 	    4);
 
-	emu_wrptr(sc, 0, PTB, 0);
+	emu_wrptr(sc, 0, EMU_PTB, 0);
 	/* reset recording buffers */
-	emu_wrptr(sc, 0, MICBS, ADCBS_BUFSIZE_NONE);
-	emu_wrptr(sc, 0, MICBA, 0);
-	emu_wrptr(sc, 0, FXBS, ADCBS_BUFSIZE_NONE);
-	emu_wrptr(sc, 0, FXBA, 0);
-	emu_wrptr(sc, 0, FXWC, 0);
-	emu_wrptr(sc, 0, ADCBS, ADCBS_BUFSIZE_NONE);
-	emu_wrptr(sc, 0, ADCBA, 0);
-	emu_wrptr(sc, 0, TCB, 0);
-	emu_wrptr(sc, 0, TCBS, 0);
+	emu_wrptr(sc, 0, EMU_MICBS, EMU_RECBS_BUFSIZE_NONE);
+	emu_wrptr(sc, 0, EMU_MICBA, 0);
+	emu_wrptr(sc, 0, EMU_FXBS, EMU_RECBS_BUFSIZE_NONE);
+	emu_wrptr(sc, 0, EMU_FXBA, 0);
+	emu_wrptr(sc, 0, EMU_FXWC, 0);
+	emu_wrptr(sc, 0, EMU_ADCBS, EMU_RECBS_BUFSIZE_NONE);
+	emu_wrptr(sc, 0, EMU_ADCBA, 0);
+	emu_wrptr(sc, 0, EMU_TCB, 0);
+	emu_wrptr(sc, 0, EMU_TCBS, 0);
 
 	/* disable channel interrupt */
-	emu_wrptr(sc, 0, CLIEL, 0);
-	emu_wrptr(sc, 0, CLIEH, 0);
-	emu_wrptr(sc, 0, SOLEL, 0);
-	emu_wrptr(sc, 0, SOLEH, 0);
+	emu_wrptr(sc, 0, EMU_CLIEL, 0);
+	emu_wrptr(sc, 0, EMU_CLIEH, 0);
+	emu_wrptr(sc, 0, EMU_SOLEL, 0);
+	emu_wrptr(sc, 0, EMU_SOLEH, 0);
 
 	/* init envelope engine */
 	if (!SLIST_EMPTY(&sc->mem.blocks))
@@ -1997,7 +2079,7 @@
 	sc->audigy = sc->type == EMU10K2_PCI_ID || sc->type == EMU10K3_PCI_ID;
 	sc->audigy2 = (sc->audigy && sc->rev == 0x04);
 	sc->nchans = sc->audigy ? 8 : 4;
-	sc->addrmask = sc->audigy ? A_PTR_ADDRESS_MASK : PTR_ADDRESS_MASK;
+	sc->addrmask = sc->audigy ? EMU_A_PTR_ADDR_MASK : EMU_PTR_ADDR_MASK;
 
 	data = pci_read_config(dev, PCIR_COMMAND, 2);
 	data |= (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/sound/pci/emuxkireg.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/dev/sound/pci/emuxkireg.h	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,689 @@
+/* $FreeBSD: head/sys/dev/sound/pci/emuxkireg.h 229430 2012-01-03 21:04:54Z pfg $ */
+/*	$NetBSD: emuxkireg.h,v 1.8 2008/04/28 20:23:54 martin Exp $	*/
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Yannick Montulet.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _DEV_PCI_EMUXKIREG_H_
+#define _DEV_PCI_EMUXKIREG_H_
+
+/*
+ * Register values for Creative EMU10000. The register values have been
+ * taken from GPLed SBLive! header file published by Creative. The comments
+ * have been stripped to avoid GPL pollution in kernel. The Creative version
+ * including comments is available in Linux 2.4.* kernel as file
+ *	drivers/sound/emu10k1/8010.h
+ */
+
+/*
+ * Audigy specific registers contain an '_A_'
+ * Audigy2 specific registers contain an '_A2_'
+ */
+
+#define	EMU_MKSUBREG(sz, idx, reg)	(((sz) << 24) | ((idx) << 16) | (reg))
+
+#define EMU_PTR	0x00
+#define  EMU_PTR_CHNO_MASK	0x0000003f
+#define  EMU_PTR_ADDR_MASK	0x07ff0000
+#define  EMU_A_PTR_ADDR_MASK	0x0fff0000
+
+#define EMU_DATA	0x04
+
+#define EMU_IPR	0x08
+#define  EMU_IPR_RATETRCHANGE	0x01000000
+#define  EMU_IPR_FXDSP		0x00800000
+#define  EMU_IPR_FORCEINT	0x00400000
+#define  EMU_PCIERROR		0x00200000
+#define  EMU_IPR_VOLINCR	0x00100000
+#define  EMU_IPR_VOLDECR	0x00080000
+#define  EMU_IPR_MUTE		0x00040000
+#define  EMU_IPR_MICBUFFULL	0x00020000
+#define  EMU_IPR_MICBUFHALFFULL	0x00010000
+#define  EMU_IPR_ADCBUFFULL	0x00008000
+#define  EMU_IPR_ADCBUFHALFFULL	0x00004000
+#define  EMU_IPR_EFXBUFFULL	0x00002000
+#define  EMU_IPR_EFXBUFHALFFULL	0x00001000
+#define  EMU_IPR_GPSPDIFSTCHANGE 0x00000800
+#define  EMU_IPR_CDROMSTCHANGE	0x00000400
+#define  EMU_IPR_INTERVALTIMER	0x00000200
+#define  EMU_IPR_MIDITRANSBUFE	0x00000100
+#define  EMU_IPR_MIDIRECVBUFE	0x00000080
+#define  EMU_IPR_A_MIDITRANSBUFE2 0x10000000
+#define  EMU_IPR_A_MIDIRECBUFE2	0x08000000
+#define  EMU_IPR_CHANNELLOOP	0x00000040
+#define  EMU_IPR_CHNOMASK	0x0000003f
+
+#define EMU_INTE	0x0c
+
+#define  EMU_INTE_VSB_MASK	0xc0000000
+#define   EMU_INTE_VSB_220	0x00000000
+#define   EMU_INTE_VSB_240	0x40000000
+#define   EMU_INTE_VSB_260	0x80000000
+#define   EMU_INTE_VSB_280	0xc0000000
+
+#define  EMU_INTE_VMPU_MASK	0x30000000
+#define   EMU_INTE_VMPU_300	0x00000000
+#define   EMU_INTE_VMPU_310	0x10000000
+#define   EMU_INTE_VMPU_320	0x20000000
+#define   EMU_INTE_VMPU_330	0x30000000
+#define  EMU_INTE_MDMAENABLE	0x08000000
+#define  EMU_INTE_SDMAENABLE	0x04000000
+#define  EMU_INTE_MPICENABLE	0x02000000
+#define  EMU_INTE_SPICENABLE	0x01000000
+#define  EMU_INTE_VSBENABLE	0x00800000
+#define  EMU_INTE_ADLIBENABLE	0x00400000
+#define  EMU_INTE_MPUENABLE	0x00200000
+#define  EMU_INTE_FORCEINT	0x00100000
+#define  EMU_INTE_MRHANDENABLE	0x00080000
+#define  EMU_INTE_SAMPLERATER	0x00002000
+#define  EMU_INTE_FXDSPENABLE	0x00001000
+#define  EMU_INTE_PCIERRENABLE	0x00000800
+#define  EMU_INTE_VOLINCRENABLE	0x00000400
+#define  EMU_INTE_VOLDECRENABLE	0x00000200
+#define  EMU_INTE_MUTEENABLE	0x00000100
+#define  EMU_INTE_MICBUFENABLE	0x00000080
+#define  EMU_INTE_ADCBUFENABLE	0x00000040
+#define  EMU_INTE_EFXBUFENABLE	0x00000020
+#define  EMU_INTE_GPSPDIFENABLE	0x00000010
+#define  EMU_INTE_CDSPDIFENABLE	0x00000008
+#define  EMU_INTE_INTERTIMERENB	0x00000004
+#define  EMU_INTE_MIDITXENABLE	0x00000002
+#define  EMU_INTE_MIDIRXENABLE	0x00000001
+#define  EMU_INTE_A_MIDITXENABLE2 0x00020000
+#define  EMU_INTE_A_MIDIRXENABLE2 0x00010000
+
+#define EMU_WC	0x10
+#define  EMU_WC_SAMPLECOUNTER_MASK	0x03FFFFC0
+#define  EMU_WC_SAMPLECOUNTER		EMU_MKSUBREG(20, 6, EMU_WC)
+#define  EMU_WC_CURRENTCHANNEL		0x0000003F
+
+#define EMU_HCFG	0x14
+#define  EMU_HCFG_LEGACYFUNC_MASK	0xe0000000
+#define  EMU_HCFG_LEGACYFUNC_MPU	0x00000000
+#define  EMU_HCFG_LEGACYFUNC_SB		0x40000000
+#define  EMU_HCFG_LEGACYFUNC_AD		0x60000000
+#define  EMU_HCFG_LEGACYFUNC_MPIC	0x80000000
+#define  EMU_HCFG_LEGACYFUNC_MDMA	0xa0000000
+#define  EMU_HCFG_LEGACYFUNC_SPCI	0xc0000000
+#define  EMU_HCFG_LEGACYFUNC_SDMA	0xe0000000
+#define  EMU_HCFG_IOCAPTUREADDR		0x1f000000
+#define  EMU_HCFG_LEGACYWRITE		0x00800000
+#define  EMU_HCFG_LEGACYWORD		0x00400000
+#define  EMU_HCFG_LEGACYINT		0x00200000
+
+#define  EMU_HCFG_CODECFMT_MASK		0x00070000
+#define  EMU_HCFG_CODECFMT_AC97		0x00000000
+#define  EMU_HCFG_CODECFMT_I2S		0x00010000
+#define  EMU_HCFG_GPINPUT0		0x00004000
+#define  EMU_HCFG_GPINPUT1		0x00002000
+#define  EMU_HCFG_GPOUTPUT_MASK		0x00001c00
+#define  EMU_HCFG_JOYENABLE		0x00000200
+#define  EMU_HCFG_PHASETRACKENABLE	0x00000100
+#define  EMU_HCFG_AC3ENABLE_MASK	0x000000e0
+#define  EMU_HCFG_AC3ENABLE_ZVIDEO	0x00000080
+#define  EMU_HCFG_AC3ENABLE_CDSPDIF	0x00000040
+#define  EMU_HCFG_AC3ENABLE_GPSPDIF	0x00000020
+#define  EMU_HCFG_AUTOMUTE		0x00000010
+#define  EMU_HCFG_LOCKSOUNDCACHE	0x00000008
+#define  EMU_HCFG_LOCKTANKCACHE_MASK	0x00000004
+#define  EMU_HCFG_LOCKTANKCACHE		EMU_MKSUBREG(1, 2, EMU_HCFG)
+#define  EMU_HCFG_MUTEBUTTONENABLE	0x00000002
+#define  EMU_HCFG_AUDIOENABLE		0x00000001
+
+#define EMU_MUDATA	0x18
+#define EMU_MUCMD	0x19
+#define  EMU_MUCMD_RESET		0xff
+#define  EMU_MUCMD_ENTERUARTMODE	0x3f
+
+#define EMU_MUSTAT	EMU_MUCMD
+#define  EMU_MUSTAT_IRDYN		0x80
+#define  EMU_MUSTAT_ORDYN		0x40
+
+#define EMU_A_IOCFG			0x18
+#define EMU_A_GPINPUT_MASK		0xff00
+#define EMU_A_GPOUTPUT_MASK		0x00ff
+#define EMU_A_IOCFG_GPOUT0		0x0040
+#define EMU_A_IOCFG_GPOUT1		0x0004
+
+#define EMU_TIMER	0x1a
+#define  EMU_TIMER_RATE_MASK	0x000003ff
+#define  EMU_TIMER_RATE		EMU_MKSUBREG(10, 0, EMU_TIMER)
+
+#define EMU_AC97DATA	0x1c
+#define EMU_AC97ADDR	0x1e
+#define  EMU_AC97ADDR_RDY	0x80
+#define  EMU_AC97ADDR_ADDR	0x7f
+
+#define EMU_A2_PTR		0x20
+#define EMU_A2_DATA		0x24
+
+#define EMU_A2_SRCSEL			0x600000
+#define EMU_A2_SRCSEL_ENABLE_SPDIF	0x00000004
+#define EMU_A2_SRCSEL_ENABLE_SRCMULTI	0x00000010
+#define EMU_A2_SRCMULTI			0x6e0000
+#define EMU_A2_SRCMULTI_ENABLE_INPUT	0xff00ff00
+
+/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
+
+#define EMU_CHAN_CPF	0x00
+
+#define  EMU_CHAN_CPF_PITCH_MASK	0xffff0000
+#define  EMU_CHAN_CPF_PITCH	EMU_MKSUBREG(16, 16, EMU_CHAN_CPF)
+#define  EMU_CHAN_CPF_STEREO_MASK	0x00008000
+#define  EMU_CHAN_CPF_STEREO	EMU_MKSUBREG(1, 15, EMU_CHAN_CPF)
+#define  EMU_CHAN_CPF_STOP_MASK	0x00004000
+#define  EMU_CHAN_CPF_FRACADDRESS_MASK	0x00003fff
+
+
+#define EMU_CHAN_PTRX	0x01
+#define  EMU_CHAN_PTRX_PITCHTARGET_MASK	0xffff0000
+#define  EMU_CHAN_PTRX_PITCHTARGET	EMU_MKSUBREG(16, 16, EMU_CHAN_PTRX)
+#define  EMU_CHAN_PTRX_FXSENDAMOUNT_A_MASK	0x0000ff00
+#define  EMU_CHAN_PTRX_FXSENDAMOUNT_A EMU_MKSUBREG(8, 8, EMU_CHAN_PTRX)
+#define  EMU_CHAN_PTRX_FXSENDAMOUNT_B_MASK	0x000000ff
+#define  EMU_CHAN_PTRX_FXSENDAMOUNT_B EMU_MKSUBREG(8, 0, EMU_CHAN_PTRX)
+
+#define EMU_CHAN_CVCF	0x02
+#define  EMU_CHAN_CVCF_CURRVOL_MASK	0xffff0000
+#define  EMU_CHAN_CVCF_CURRVOL	EMU_MKSUBREG(16, 16, EMU_CHAN_CVCF)
+#define  EMU_CHAN_CVCF_CURRFILTER_MASK	0x0000ffff
+#define  EMU_CHAN_CVCF_CURRFILTER EMU_MKSUBREG(16, 0, EMU_CHAN_CVCF)
+
+#define EMU_CHAN_VTFT	0x03
+#define  EMU_CHAN_VTFT_VOLUMETARGET_MASK	0xffff0000
+#define  EMU_CHAN_VTFT_VOLUMETARGET	EMU_MKSUBREG(16, 16, EMU_CHAN_VTFT)
+#define  EMU_CHAN_VTFT_FILTERTARGET_MASK	0x0000ffff
+#define	 EMU_CHAN_VTFT_FILTERTARGET	EMU_MKSUBREG(16, 0, EMU_CHAN_VTFT)
+
+#define EMU_CHAN_Z1	0x05
+#define EMU_CHAN_Z2	0x04
+
+#define EMU_CHAN_PSST	0x06
+#define  EMU_CHAN_PSST_FXSENDAMOUNT_C_MASK	0xff000000
+#define  EMU_CHAN_PSST_FXSENDAMOUNT_C EMU_MKSUBREG(8, 24, EMU_CHAN_PSST)
+#define  EMU_CHAN_PSST_LOOPSTARTADDR_MASK	0x00ffffff
+#define  EMU_CHAN_PSST_LOOPSTARTADDR  EMU_MKSUBREG(24, 0, EMU_CHAN_PSST)
+
+#define EMU_CHAN_DSL	0x07
+#define  EMU_CHAN_DSL_FXSENDAMOUNT_D_MASK	0xff000000
+#define  EMU_CHAN_DSL_FXSENDAMOUNT_D  EMU_MKSUBREG(8, 24, EMU_CHAN_DSL)
+#define  EMU_CHAN_DSL_LOOPENDADDR_MASK	0x00ffffff
+#define  EMU_CHAN_DSL_LOOPENDADDR	 EMU_MKSUBREG(24, 0, EMU_CHAN_DSL)
+
+#define EMU_CHAN_CCCA	0x08
+#define  EMU_CHAN_CCCA_RESONANCE		0xf0000000
+#define  EMU_CHAN_CCCA_INTERPROMMASK		0x0e000000
+#define   EMU_CHAN_CCCA_INTERPROM_0		0x00000000
+#define   EMU_CHAN_CCCA_INTERPROM_1		0x02000000
+#define   EMU_CHAN_CCCA_INTERPROM_2		0x04000000
+#define   EMU_CHAN_CCCA_INTERPROM_3		0x06000000
+#define   EMU_CHAN_CCCA_INTERPROM_4		0x08000000
+#define   EMU_CHAN_CCCA_INTERPROM_5		0x0a000000
+#define   EMU_CHAN_CCCA_INTERPROM_6		0x0c000000
+#define   EMU_CHAN_CCCA_INTERPROM_7		0x0e000000
+#define   EMU_CHAN_CCCA_8BITSELECT		0x01000000
+#define  EMU_CHAN_CCCA_CURRADDR_MASK		0x00ffffff
+#define  EMU_CHAN_CCCA_CURRADDR	EMU_MKSUBREG(24, 0, EMU_CHAN_CCCA)
+
+#define EMU_CHAN_CCR	0x09
+#define  EMU_CHAN_CCR_CACHEINVALIDSIZE_MASK	0xfe000000
+#define  EMU_CHAN_CCR_CACHEINVALIDSIZE EMU_MKSUBREG(7, 25, EMU_CHAN_CCR)
+#define  EMU_CHAN_CCR_CACHELOOPFLAG		0x01000000
+#define  EMU_CHAN_CCR_INTERLEAVEDSAMPLES	0x00800000
+#define  EMU_CHAN_CCR_WORDSIZEDSAMPLES	0x00400000
+#define  EMU_CHAN_CCR_READADDRESS_MASK	0x003f0000
+#define  EMU_CHAN_CCR_READADDRESS	EMU_MKSUBREG(6, 16, EMU_CHAN_CCR)
+#define  EMU_CHAN_CCR_LOOPINVALSIZE	0x0000fe00
+#define  EMU_CHAN_CCR_LOOPFLAG		0x00000100
+#define  EMU_CHAN_CCR_CACHELOOPADDRHI	0x000000ff
+
+#define EMU_CHAN_CLP	0x0a
+#define  EMU_CHAN_CLP_CACHELOOPADDR	0x0000ffff
+
+#define EMU_CHAN_FXRT	0x0b
+#define  EMU_CHAN_FXRT_CHANNELA		0x000f0000
+#define  EMU_CHAN_FXRT_CHANNELB		0x00f00000
+#define  EMU_CHAN_FXRT_CHANNELC		0x0f000000
+#define  EMU_CHAN_FXRT_CHANNELD		0xf0000000
+
+#define EMU_CHAN_MAPA	0x0c
+#define EMU_CHAN_MAPB	0x0d
+
+#define  EMU_CHAN_MAP_PTE_MASK		0xffffe000
+#define  EMU_CHAN_MAP_PTI_MASK		0x00001fff
+
+
+#define EMU_CHAN_ENVVOL	0x10
+#define  EMU_CHAN_ENVVOL_MASK		0x0000ffff
+
+
+#define EMU_CHAN_ATKHLDV 0x11
+#define  EMU_CHAN_ATKHLDV_PHASE0	0x00008000
+#define  EMU_CHAN_ATKHLDV_HOLDTIME_MASK	0x00007f00
+#define  EMU_CHAN_ATKHLDV_ATTACKTIME_MASK	0x0000007f
+
+
+#define EMU_CHAN_DCYSUSV	0x12
+#define  EMU_CHAN_DCYSUSV_PHASE1_MASK		0x00008000
+#define  EMU_CHAN_DCYSUSV_SUSTAINLEVEL_MASK	0x00007f00
+#define  EMU_CHAN_DCYSUSV_CHANNELENABLE_MASK	0x00000080
+#define  EMU_CHAN_DCYSUSV_DECAYTIME_MASK	0x0000007f
+
+
+#define EMU_CHAN_LFOVAL1	0x13
+#define  EMU_CHAN_LFOVAL_MASK		0x0000ffff
+
+#define EMU_CHAN_ENVVAL		0x14
+#define  EMU_CHAN_ENVVAL_MASK		0x0000ffff
+
+#define EMU_CHAN_ATKHLDM	0x15
+#define  EMU_CHAN_ATKHLDM_PHASE0	0x00008000
+#define  EMU_CHAN_ATKHLDM_HOLDTIME	0x00007f00
+#define  EMU_CHAN_ATKHLDM_ATTACKTIME	0x0000007f
+
+#define EMU_CHAN_DCYSUSM	0x16
+#define  EMU_CHAN_DCYSUSM_PHASE1_MASK		0x00008000
+#define  EMU_CHAN_DCYSUSM_SUSTAINLEVEL_MASK	0x00007f00
+#define  EMU_CHAN_DCYSUSM_DECAYTIME_MASK	0x0000007f
+
+#define EMU_CHAN_LFOVAL2	0x17
+#define  EMU_CHAN_LFOVAL2_MASK		0x0000ffff
+
+#define EMU_CHAN_IP		0x18
+#define  EMU_CHAN_IP_MASK			0x0000ffff
+#define  EMU_CHAN_IP_UNITY			0x0000e000
+
+#define EMU_CHAN_IFATN		0x19
+#define  EMU_CHAN_IFATN_FILTERCUTOFF_MASK	0x0000ff00
+#define  EMU_CHAN_IFATN_FILTERCUTOFF EMU_MKSUBREG(8, 8,	EMU_CHAN_IFATN)
+#define  EMU_CHAN_IFATN_ATTENUATION_MASK	0x000000ff
+#define  EMU_CHAN_IFATN_ATTENUATION	 EMU_MKSUBREG(8, 0, EMU_CHAN_IFATN)
+
+#define EMU_CHAN_PEFE		0x1a
+#define  EMU_CHAN_PEFE_PITCHAMOUNT_MASK	0x0000ff00
+#define  EMU_CHAN_PEFE_PITCHAMOUNT	EMU_MKSUBREG(8, 8, EMU_CHAN_PEFE)
+#define  EMU_CHAN_PEFE_FILTERAMOUNT_MASK	0x000000ff
+#define  EMU_CHAN_PEFE_FILTERAMOUNT	EMU_MKSUBREG(8, 0, EMU_CHAN_PEFE)
+
+#define EMU_CHAN_FMMOD	0x1b
+#define  EMU_CHAN_FMMOD_MODVIBRATO	0x0000ff00
+#define EMU_CHAN_FMMOD_MOFILTER		0x000000ff
+
+#define EMU_CHAN_TREMFRQ	0x1c
+#define  EMU_CHAN_TREMFRQ_DEPTH		0x0000ff00
+
+#define EMU_CHAN_FM2FRQ2	0x1d
+#define  EMU_CHAN_FM2FRQ2_DEPTH		0x0000ff00
+#define  EMU_CHAN_FM2FRQ2_FREQUENCY	0x000000ff
+
+#define EMU_CHAN_TEMPENV	0x1e
+#define  EMU_CHAN_TEMPENV_MASK		0x0000ffff
+
+#define EMU_CHAN_CD0	0x20
+#define EMU_CHAN_CD1	0x21
+#define EMU_CHAN_CD2	0x22
+#define EMU_CHAN_CD3	0x23
+#define EMU_CHAN_CD4	0x24
+#define EMU_CHAN_CD5	0x25
+#define EMU_CHAN_CD6	0x26
+#define EMU_CHAN_CD7	0x27
+#define EMU_CHAN_CD8	0x28
+#define EMU_CHAN_CD9	0x29
+#define EMU_CHAN_CDA	0x2a
+#define EMU_CHAN_CDB	0x2b
+#define EMU_CHAN_CDC	0x2c
+#define EMU_CHAN_CDD	0x2d
+#define EMU_CHAN_CDE	0x2e
+#define EMU_CHAN_CDF	0x2f
+
+/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
+
+#define EMU_PTB		0x40
+#define  EMU_PTB_MASK			0xfffff000
+
+#define EMU_TCB		0x41
+#define  EMU_TCB_MASK			0xfffff000
+
+#define EMU_ADCCR	0x42
+#define  EMU_ADCCR_RCHANENABLE		0x00000010
+#define  EMU_A_ADCCR_RCHANENABLE	0x00000020
+#define  EMU_ADCCR_LCHANENABLE		0x00000008
+#define  EMU_A_ADCCR_LCHANENABLE	0x00000010
+#define  EMU_ADCCR_SAMPLERATE_MASK	0x00000007
+#define  EMU_A_ADCCR_SAMPLERATE_MASK    0x0000000f
+#define   EMU_ADCCR_SAMPLERATE_48	0x00000000
+#define   EMU_ADCCR_SAMPLERATE_44	0x00000001
+#define   EMU_ADCCR_SAMPLERATE_32	0x00000002
+#define   EMU_ADCCR_SAMPLERATE_24	0x00000003
+#define   EMU_ADCCR_SAMPLERATE_22	0x00000004
+#define   EMU_ADCCR_SAMPLERATE_16	0x00000005
+#define   EMU_A_ADCCR_SAMPLERATE_12	0x00000006
+#define   EMU_ADCCR_SAMPLERATE_11	0x00000006
+#define   EMU_A_ADCCR_SAMPLERATE_11	0x00000007
+#define   EMU_ADCCR_SAMPLERATE_8	0x00000007
+#define   EMU_A_ADCCR_SAMPLERATE_8	0x00000008
+
+#define EMU_FXWC	0x43
+#define EMU_TCBS	0x44
+#define  EMU_TCBS_MASK			0x00000007
+#define   EMU_TCBS_BUFFSIZE_16K		0x00000000
+#define   EMU_TCBS_BUFFSIZE_32K		0x00000001
+#define   EMU_TCBS_BUFFSIZE_64K		0x00000002
+#define   EMU_TCBS_BUFFSIZE_128K	0x00000003
+#define   EMU_TCBS_BUFFSIZE_256K	0x00000004
+#define   EMU_TCBS_BUFFSIZE_512K	0x00000005
+#define   EMU_TCBS_BUFFSIZE_1024K	0x00000006
+#define   EMU_TCBS_BUFFSIZE_2048K	0x00000007
+
+#define EMU_MICBA	0x45
+#define EMU_ADCBA	0x46
+#define EMU_FXBA	0x47
+#define  EMU_RECBA_MASK			0xfffff000
+
+#define EMU_MICBS	0x49
+#define EMU_ADCBS	0x4a
+#define EMU_FXBS	0x4b
+#define  EMU_RECBS_BUFSIZE_NONE		0x00000000
+#define  EMU_RECBS_BUFSIZE_384		0x00000001
+#define  EMU_RECBS_BUFSIZE_448		0x00000002
+#define  EMU_RECBS_BUFSIZE_512		0x00000003
+#define  EMU_RECBS_BUFSIZE_640		0x00000004
+#define  EMU_RECBS_BUFSIZE_768		0x00000005
+#define  EMU_RECBS_BUFSIZE_896		0x00000006
+#define  EMU_RECBS_BUFSIZE_1024		0x00000007
+#define  EMU_RECBS_BUFSIZE_1280		0x00000008
+#define  EMU_RECBS_BUFSIZE_1536		0x00000009
+#define  EMU_RECBS_BUFSIZE_1792		0x0000000a
+#define  EMU_RECBS_BUFSIZE_2048		0x0000000b
+#define  EMU_RECBS_BUFSIZE_2560		0x0000000c
+#define  EMU_RECBS_BUFSIZE_3072		0x0000000d
+#define  EMU_RECBS_BUFSIZE_3584		0x0000000e
+#define  EMU_RECBS_BUFSIZE_4096		0x0000000f
+#define  EMU_RECBS_BUFSIZE_5120		0x00000010
+#define  EMU_RECBS_BUFSIZE_6144		0x00000011
+#define  EMU_RECBS_BUFSIZE_7168		0x00000012
+#define  EMU_RECBS_BUFSIZE_8192		0x00000013
+#define  EMU_RECBS_BUFSIZE_10240	0x00000014
+#define  EMU_RECBS_BUFSIZE_12288	0x00000015
+#define  EMU_RECBS_BUFSIZE_14366	0x00000016
+#define  EMU_RECBS_BUFSIZE_16384	0x00000017
+#define  EMU_RECBS_BUFSIZE_20480	0x00000018
+#define  EMU_RECBS_BUFSIZE_24576	0x00000019
+#define  EMU_RECBS_BUFSIZE_28672	0x0000001a
+#define  EMU_RECBS_BUFSIZE_32768	0x0000001b
+#define  EMU_RECBS_BUFSIZE_40960	0x0000001c
+#define  EMU_RECBS_BUFSIZE_49152	0x0000001d
+#define  EMU_RECBS_BUFSIZE_57344	0x0000001e
+#define  EMU_RECBS_BUFSIZE_65536	0x0000001f
+
+#define EMU_CDCS	0x50
+#define EMU_GPSCS	0x51
+
+#define EMU_DBG		0x52
+#define EMU_DBG_ZC			0x80000000
+#define  EMU_DBG_SATURATION_OCCURRED	0x02000000
+#define  EMU_DBG_SATURATION_ADDR	0x01ff0000
+#define  EMU_DBG_SINGLE_STEP		0x00008000
+#define  EMU_DBG_STEP			0x00004000
+#define  EMU_DBG_CONDITION_CODE		0x00003e00
+#define  EMU_DBG_SINGLE_STEP_ADDR	0x000001ff
+
+#define EMU_A_DBG			0x53
+#define EMU_A_DBG_SINGLE_STEP		0x00020000
+#define EMU_A_DBG_ZC			0x40000000
+#define EMU_A_DBG_STEP_ADDR		0x000003ff
+#define EMU_A_DBG_SATURATION_OCCRD	0x20000000
+#define EMU_A_DBG_SATURATION_ADDR	0x0ffc0000
+
+#define EMU_SPCS0	0x54
+#define EMU_SPCS1	0x55
+#define EMU_SPCS2	0x56
+#define  EMU_SPCS_CLKACCYMASK		0x30000000
+#define   EMU_SPCS_CLKACCY_1000PPM	0x00000000
+#define   EMU_SPCS_CLKACCY_50PPM	0x10000000
+#define   EMU_SPCS_CLKACCY_VARIABLE	0x20000000
+#define  EMU_SPCS_SAMPLERATEMASK	0x0f000000
+#define   EMU_SPCS_SAMPLERATE_44	0x00000000
+#define   EMU_SPCS_SAMPLERATE_48	0x02000000
+#define   EMU_SPCS_SAMPLERATE_32	0x03000000
+#define  EMU_SPCS_CHANNELNUMMASK	0x00f00000
+#define   EMU_SPCS_CHANNELNUM_UNSPEC	0x00000000
+#define   EMU_SPCS_CHANNELNUM_LEFT	0x00100000
+#define   EMU_SPCS_CHANNELNUM_RIGHT	0x00200000
+#define  EMU_SPCS_SOURCENUMMASK		0x000f0000
+#define   EMU_SPCS_SOURCENUM_UNSPEC	0x00000000
+#define  EMU_SPCS_GENERATIONSTATUS	0x00008000
+#define  EMU_SPCS_CATEGORYCODEMASK	0x00007f00
+#define  EMU_SPCS_MODEMASK		0x000000c0
+#define  EMU_SPCS_EMPHASISMASK		0x00000038
+#define   EMU_SPCS_EMPHASIS_NONE	0x00000000
+#define   EMU_SPCS_EMPHASIS_50_15	0x00000008
+#define  EMU_SPCS_COPYRIGHT		0x00000004
+#define  EMU_SPCS_NOTAUDIODATA		0x00000002
+#define  EMU_SPCS_PROFESSIONAL		0x00000001
+
+#define EMU_CLIEL	0x58
+#define EMU_CLIEH	0x59
+#define EMU_CLIPL	0x5a
+#define EMU_CLIPH	0x5b
+#define EMU_SOLEL	0x5c
+#define EMU_SOLEH	0x5d
+
+#define	EMU_SPBYPASS		0x5e
+#define	EMU_SPBYPASS_ENABLE	0x00000001
+#define	EMU_SPBYPASS_24_BITS	0x00000f00
+
+#define	EMU_AC97SLOT		0x5f
+#define	EMU_AC97SLOT_CENTER	0x00000010
+#define	EMU_AC97SLOT_LFE	0x00000020
+
+#define EMU_CDSRCS	0x60
+#define EMU_GPSRCS	0x61
+#define EMU_ZVSRCS	0x62
+#define  EMU_SRCS_SPDIFLOCKED		0x02000000
+#define  EMU_SRCS_RATELOCKED		0x01000000
+#define  EMU_SRCS_ESTSAMPLERATE		0x0007ffff
+
+#define EMU_MICIDX	0x63
+#define EMU_A_MICIDX	0x64
+#define EMU_ADCIDX	0x64
+#define EMU_A_ADCIDX	0x63
+#define EMU_FXIDX	0x65
+#define  EMU_RECIDX_MASK		0x0000ffff
+#define	 EMU_RECIDX(idxreg)	       (0x10000000|(idxreg))
+/*
+#define  EMU_MICIDX_IDX			0x10000063
+#define  EMU_ADCIDX_IDX			0x10000064
+#define  EMU_FXIDX_IDX			0x10000065
+*/
+
+#define EMU_A_MUDATA1		0x70
+#define EMU_A_MUCMD1		0x71
+#define EMU_A_MUSTAT1		EMU_A_MUCMD1
+#define EMU_A_MUDATA2		0x72
+#define EMU_A_MUCMD2		0x73
+#define EMU_A_MUSTAT2		EMU_A_MUCMD2
+#define EMU_A_FXWC1		0x74
+#define EMU_A_FXWC2		0x75
+#define EMU_A_SPDIF_SAMPLERATE	0x76
+#define EMU_A_SPDIF_48000	0x00000080
+#define EMU_A_SPDIF_44100	0x00000000
+#define EMU_A_SPDIF_96000	0x00000040
+#define EMU_A2_SPDIF_SAMPLERATE	EMU_MKSUBREG(3, 9, EMU_A_SPDIF_SAMPLERATE)
+#define EMU_A2_SPDIF_MASK	0x00000e00
+#define EMU_A2_SPDIF_UNKNOWN	0x2
+
+#define EMU_A_CHAN_FXRT2		0x7c
+#define EMU_A_CHAN_FXRT_CHANNELE	0x0000003f
+#define EMU_A_CHAN_FXRT_CHANNELF	0x00003f00
+#define EMU_A_CHAN_FXRT_CHANNELG	0x003f0000
+#define EMU_A_CHAN_FXRT_CHANNELH	0x3f000000
+#define EMU_A_CHAN_SENDAMOUNTS		0x7d
+#define EMU_A_CHAN_FXSENDAMOUNTS_E_MASK	0xff000000
+#define EMU_A_CHAN_FXSENDAMOUNTS_F_MASK	0x00ff0000
+#define EMU_A_CHAN_FXSENDAMOUNTS_G_MASK	0x0000ff00
+#define EMU_A_CHAN_FXSENDAMOUNTS_H_MASK	0x000000ff
+#define EMU_A_CHAN_FXRT1		0x7e
+#define EMU_A_CHAN_FXRT_CHANNELA	0x0000003f
+#define EMU_A_CHAN_FXRT_CHANNELB	0x00003f00
+#define EMU_A_CHAN_FXRT_CHANNELC	0x003f0000
+#define EMU_A_CHAN_FXRT_CHANNELD	0x3f000000
+
+#define EMU_FXGPREGBASE		0x100
+#define EMU_A_FXGPREGBASE	0x400
+
+#define EMU_TANKMEMDATAREGBASE	0x200
+#define  EMU_TANKMEMDATAREG_MASK	0x000fffff
+
+#define EMU_TANKMEMADDRREGBASE	0x300
+#define  EMU_TANKMEMADDRREG_ADDR_MASK	0x000fffff
+#define  EMU_TANKMEMADDRREG_CLEAR	0x00800000
+#define  EMU_TANKMEMADDRREG_ALIGN	0x00400000
+#define  EMU_TANKMEMADDRREG_WRITE	0x00200000
+#define  EMU_TANKMEMADDRREG_READ	0x00100000
+
+#define  EMU_MICROCODEBASE	0x400
+#define  EMU_A_MICROCODEBASE		0x600
+#define  EMU_DSP_LOWORD_OPX_MASK	0x000ffc00
+#define  EMU_DSP_LOWORD_OPY_MASK	0x000003ff
+#define  EMU_DSP_HIWORD_OPCODE_MASK	0x00f00000
+#define  EMU_DSP_HIWORD_RESULT_MASK	0x000ffc00
+#define  EMU_DSP_HIWORD_OPA_MASK	0x000003ff
+#define  EMU_A_DSP_LOWORD_OPX_MASK	0x007ff000
+#define  EMU_A_DSP_LOWORD_OPY_MASK	0x000007ff
+#define  EMU_A_DSP_HIWORD_OPCODE_MASK	0x0f000000
+#define  EMU_A_DSP_HIWORD_RESULT_MASK	0x007ff000
+#define  EMU_A_DSP_HIWORD_OPA_MASK	0x000007ff
+
+#define	EMU_DSP_OP_MACS		0x0
+#define	EMU_DSP_OP_MACS1	0x1
+#define	EMU_DSP_OP_MACW		0x2
+#define	EMU_DSP_OP_MACW1	0x3
+#define	EMU_DSP_OP_MACINTS	0x4
+#define	EMU_DSP_OP_MACINTW	0x5
+#define	EMU_DSP_OP_ACC3		0x6
+#define	EMU_DSP_OP_MACMV	0x7
+#define	EMU_DSP_OP_ANDXOR	0x8
+#define	EMU_DSP_OP_TSTNEG	0x9
+#define	EMU_DSP_OP_LIMIT	0xA
+#define	EMU_DSP_OP_LIMIT1	0xB
+#define	EMU_DSP_OP_LOG		0xC
+#define	EMU_DSP_OP_EXP		0xD
+#define	EMU_DSP_OP_INTERP	0xE
+#define	EMU_DSP_OP_SKIP		0xF
+
+
+#define	EMU_DSP_FX(num)	(num)
+
+#define	EMU_DSP_IOL(base, num)	(base + (num << 1))
+#define	EMU_DSP_IOR(base, num)	(EMU_DSP_IOL(base, num) + 1)
+
+#define	EMU_DSP_INL_BASE	0x010
+#define	EMU_DSP_INL(num)	(EMU_DSP_IOL(EMU_DSP_INL_BASE, num))
+#define	EMU_DSP_INR(num)	(EMU_DSP_IOR(EMU_DSP_INL_BASE, num))
+#define	EMU_A_DSP_INL_BASE	0x040
+#define	EMU_A_DSP_INL(num)	(EMU_DSP_IOL(EMU_A_DSP_INL_BASE, num))
+#define	EMU_A_DSP_INR(num)	(EMU_DSP_IOR(EMU_A_DSP_INL_BASE, num))
+#define	 EMU_DSP_IN_AC97	0
+#define	 EMU_DSP_IN_CDSPDIF	1
+#define  EMU_DSP_IN_ZOOM	2
+#define	 EMU_DSP_IN_TOSOPT	3
+#define	 EMU_DSP_IN_LVDLM1	4
+#define	 EMU_DSP_IN_LVDCOS	5
+#define	 EMU_DSP_IN_LVDLM2	6
+#define	EMU_DSP_IN_UNKNOWN	7
+
+#define	EMU_DSP_OUTL_BASE	0x020
+#define	EMU_DSP_OUTL(num)	(EMU_DSP_IOL(EMU_DSP_OUTL_BASE, num))
+#define	EMU_DSP_OUTR(num)	(EMU_DSP_IOR(EMU_DSP_OUTL_BASE, num))
+#define	EMU_DSP_OUT_A_FRONT	0
+#define	EMU_DSP_OUT_D_FRONT	1
+#define	EMU_DSP_OUT_D_CENTER	2
+#define	EMU_DSP_OUT_DRIVE_HP	3
+#define	EMU_DSP_OUT_AD_REAR	4
+#define	EMU_DSP_OUT_ADC		5
+#define	EMU_DSP_OUTL_MIC	6
+
+#define	EMU_A_DSP_OUTL_BASE	0x060
+#define	EMU_A_DSP_OUTL(num)	(EMU_DSP_IOL(EMU_A_DSP_OUTL_BASE, num))
+#define	EMU_A_DSP_OUTR(num)	(EMU_DSP_IOR(EMU_A_DSP_OUTL_BASE, num))
+#define	EMU_A_DSP_OUT_D_FRONT	0
+#define	EMU_A_DSP_OUT_D_CENTER	1
+#define	EMU_A_DSP_OUT_DRIVE_HP	2
+#define	EMU_A_DSP_OUT_DREAR	3
+#define	EMU_A_DSP_OUT_A_FRONT	4
+#define	EMU_A_DSP_OUT_A_CENTER	5
+#define	EMU_A_DSP_OUT_A_REAR	7
+#define EMU_A_DSP_OUT_ADC	11
+
+#define	EMU_DSP_CST_BASE	0x40
+#define	EMU_A_DSP_CST_BASE	0xc0
+#define	EMU_DSP_CST(num)	(EMU_DSP_CST_BASE + num)
+#define	EMU_A_DSP_CST(num)	(EMU_A_DSP_CST_BASE + num)
+/*
+00	= 0x00000000
+01	= 0x00000001
+02	= 0x00000002
+03	= 0x00000003
+04	= 0x00000004
+05	= 0x00000008
+06	= 0x00000010
+07	= 0x00000020
+08	= 0x00000100
+09	= 0x00010000
+0A	= 0x00080000
+0B	= 0x10000000
+0C	= 0x20000000
+0D	= 0x40000000
+0E	= 0x80000000
+0F	= 0x7FFFFFFF
+10	= 0xFFFFFFFF
+11	= 0xFFFFFFFE
+12	= 0xC0000000
+13	= 0x4F1BBCDC
+14	= 0x5A7EF9DB
+15	= 0x00100000
+*/
+
+#define	EMU_DSP_HWR_ACC		0x056
+#define EMU_DSP_HWR_CCR		0x057
+#define	 EMU_DSP_HWR_CCR_S	0x04
+#define	 EMU_DSP_HWR_CCR_Z	0x03
+#define	 EMU_DSP_HWR_CCR_M	0x02
+#define	 EMU_DSP_HWR_CCR_N	0x01
+#define	 EMU_DSP_HWR_CCR_B	0x00
+#define	EMU_DSP_HWR_NOISE0	0x058
+#define	EMU_DSP_HWR_NOISE1	0x059
+#define	EMU_DSP_HWR_INTR	0x05A
+#define	EMU_DSP_HWR_DBAC	0x05B
+
+#define EMU_DSP_GPR(num)	(EMU_FXGPREGBASE + num)
+#define EMU_A_DSP_GPR(num)	(EMU_A_FXGPREGBASE + num)
+
+#endif /* _DEV_PCI_EMUXKIREG_H_ */
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/tws/tws.c
--- a/head/sys/dev/tws/tws.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/tws/tws.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/tws/tws.c 227843 2011-11-22 21:28:20Z marius $");
+__FBSDID("$FreeBSD: head/sys/dev/tws/tws.c 229416 2012-01-03 20:17:35Z delphij $");
 
 #include <dev/tws/tws.h>
 #include <dev/tws/tws_services.h>
@@ -685,6 +685,7 @@
     {
         if (bus_dmamap_create(sc->data_tag, 0, &sc->reqs[i].dma_map)) {
             /* log a ENOMEM failure msg here */
+	    mtx_unlock(&sc->q_lock);
             return(FAILURE);
         } 
         sc->reqs[i].cmd_pkt =  &cmd_buf[i];
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/uart/uart_bus_pci.c
--- a/head/sys/dev/uart/uart_bus_pci.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/uart/uart_bus_pci.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_pci.c 228947 2011-12-29 08:27:37Z kib $");
+__FBSDID("$FreeBSD: head/sys/dev/uart/uart_bus_pci.c 229379 2012-01-03 10:01:12Z kevlo $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -112,6 +112,10 @@
 	0x10, 16384000 },
 { 0x151f, 0x0000, 0xffff, 0, "TOPIC Semiconductor TP560 56k modem", 0x10 },
 { 0x8086, 0x1c3d, 0xffff, 0, "Intel AMT - KT Controller", 0x10 },
+{ 0x8086, 0x8811, 0xffff, 0, "Intel EG20T Serial Port 0", 0x10 },
+{ 0x8086, 0x8812, 0xffff, 0, "Intel EG20T Serial Port 1", 0x10 },
+{ 0x8086, 0x8813, 0xffff, 0, "Intel EG20T Serial Port 2", 0x10 },
+{ 0x8086, 0x8814, 0xffff, 0, "Intel EG20T Serial Port 3", 0x10 },
 { 0x9710, 0x9820, 0x1000, 1, "NetMos NM9820 Serial Port", 0x10 },
 { 0x9710, 0x9835, 0x1000, 1, "NetMos NM9835 Serial Port", 0x10 },
 { 0x9710, 0x9865, 0xa000, 0x1000, "NetMos NM9865 Serial Port", 0x10 },
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/uart/uart_cpu_sparc64.c
--- a/head/sys/dev/uart/uart_cpu_sparc64.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/uart/uart_cpu_sparc64.c	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/dev/uart/uart_cpu_sparc64.c 221960 2011-05-15 13:27:38Z marius $");
+__FBSDID("$FreeBSD: head/sys/dev/uart/uart_cpu_sparc64.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -71,7 +71,7 @@
 	if ((aliases = OF_finddevice("/aliases")) != -1)
 		(void)OF_getprop(aliases, dev, alias, sizeof(alias));
 	len = strlen(alias);
-	if ((p = rindex(alias, ':')) == NULL)
+	if ((p = strrchr(alias, ':')) == NULL)
 		return (0);
 	p++;
 	if (p - alias == len - 1 && (*p == 'a' || *p == 'b'))
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/dev/usb/controller/usb_controller.c
--- a/head/sys/dev/usb/controller/usb_controller.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/dev/usb/controller/usb_controller.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-/* $FreeBSD: head/sys/dev/usb/controller/usb_controller.c 228854 2011-12-24 00:22:21Z gonzo $ */
+/* $FreeBSD: head/sys/dev/usb/controller/usb_controller.c 229317 2012-01-02 20:28:33Z hselasky $ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -474,10 +474,18 @@
 	if (bus->methods->set_hw_power != NULL)
 		(bus->methods->set_hw_power) (bus);
 
+	/* restore USB configuration to index 0 */
 	err = usbd_set_config_index(udev, 0);
 	if (err)
 		device_printf(bus->bdev, "Could not configure root HUB\n");
 
+	/* probe and attach */
+	err = usb_probe_and_attach(udev, USB_IFACE_INDEX_ANY);
+	if (err) {
+		device_printf(bus->bdev, "Could not probe and "
+		    "attach root HUB\n");
+	}
+
 	usbd_enum_unlock(udev);
 
 	USB_BUS_LOCK(bus);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/ext2fs/ext2_alloc.c
--- a/head/sys/fs/ext2fs/ext2_alloc.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/ext2fs/ext2_alloc.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)ffs_alloc.c	8.8 (Berkeley) 2/21/94
- * $FreeBSD: head/sys/fs/ext2fs/ext2_alloc.c 228583 2011-12-16 15:47:43Z pfg $
+ * $FreeBSD: head/sys/fs/ext2fs/ext2_alloc.c 229200 2012-01-01 20:47:33Z ed $
  */
 
 #include <sys/param.h>
@@ -886,8 +886,8 @@
 	struct m_ext2fs *fs;
 	struct buf *bp;
 	struct ext2mount *ump;
-	int error, start, len, loc, map, i;
-	char *ibp;
+	int error, start, len;
+	char *ibp, *loc;
 	ipref--; /* to avoid a lot of (ipref -1) */
 	if (ipref == -1)
 		ipref = 0;
@@ -921,25 +921,19 @@
 	}
 	start = ipref / NBBY;
 	len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY);
-	loc = skpc(0xff, len, &ibp[start]);
-	if (loc == 0) {
+	loc = memcchr(&ibp[start], 0xff, len);
+	if (loc == NULL) {
 		len = start + 1;
 		start = 0;
-		loc = skpc(0xff, len, &ibp[0]);
-		if (loc == 0) {
+		loc = memcchr(&ibp[start], 0xff, len);
+		if (loc == NULL) {
 			printf("cg = %d, ipref = %lld, fs = %s\n",
 				cg, (long long)ipref, fs->e2fs_fsmnt);
 			panic("ext2fs_nodealloccg: map corrupted");
 			/* NOTREACHED */
 		}
 	} 
-	i = start + len - loc;
-	map = ibp[i] ^ 0xff;
-	if (map == 0) {
-		printf("fs = %s\n", fs->e2fs_fsmnt);
-		panic("ext2fs_nodealloccg: block not in map");
-	}
-	ipref = i * NBBY + ffs(map) - 1;
+	ipref = (loc - ibp) * NBBY + ffs(~*loc) - 1;
 gotit:
 	setbit(ibp, ipref);
 	EXT2_LOCK(ump);
@@ -1068,7 +1062,8 @@
 static daddr_t
 ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t bpref)
 {
-	int start, len, loc, i, map;
+	char *loc;
+	int start, len;
 
 	/*
 	 * find the fragment by searching through the free block
@@ -1079,25 +1074,19 @@
 	else
 		start = 0;
 	len = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
-	loc = skpc(0xff, len, &bbp[start]);
-	if (loc == 0) {
+	loc = memcchr(&bbp[start], 0xff, len);
+	if (loc == NULL) {
 		len = start + 1;
 		start = 0;
-		loc = skpc(0xff, len, &bbp[start]);
-		if (loc == 0) {
+		loc = memcchr(&bbp[start], 0xff, len);
+		if (loc == NULL) {
 			printf("start = %d, len = %d, fs = %s\n",
 				start, len, fs->e2fs_fsmnt);
 			panic("ext2fs_alloccg: map corrupted");
 			/* NOTREACHED */
 		}
 	}
-	i = start + len - loc;
-	map = bbp[i] ^ 0xff;
-	if (map == 0) {
-		printf("fs = %s\n", fs->e2fs_fsmnt);
-		panic("ext2fs_mapsearch: block not in map");
-	}
-	return (i * NBBY + ffs(map) - 1);
+	return ((loc - bbp) * NBBY + ffs(~*loc) - 1);
 }
 
 /*
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/nfs/nfsport.h
--- a/head/sys/fs/nfs/nfsport.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/nfs/nfsport.h	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/fs/nfs/nfsport.h 224080 2011-07-16 08:05:26Z zack $
+ * $FreeBSD: head/sys/fs/nfs/nfsport.h 229272 2012-01-02 12:12:10Z ed $
  */
 
 #ifndef _NFS_NFSPORT_H_
@@ -712,7 +712,7 @@
 /*
  * Set this macro to index() or strchr(), whichever is supported.
  */
-#define	STRCHR(s, c)	index((s), (c))
+#define	STRCHR(s, c)		strchr((s), (c))
 
 /*
  * Set the n_time in the client write rpc, as required.
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/ntfs/ntfs_compr.c
--- a/head/sys/fs/ntfs/ntfs_compr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/ntfs/ntfs_compr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/fs/ntfs/ntfs_compr.c 229407 2012-01-03 19:09:01Z pfg $
  */
 
 #include <sys/param.h>
@@ -42,7 +42,7 @@
 
 int
 ntfs_uncompblock(
-	u_int8_t * buf,
+	u_int8_t * dbuf,
 	u_int8_t * cbuf)
 {
 	u_int32_t       ctag;
@@ -60,8 +60,8 @@
 			dprintf(("ntfs_uncompblock: len: %x instead of %d\n",
 			    len, 0xfff));
 		}
-		memcpy(buf, cbuf + 2, len + 1);
-		bzero(buf + len + 1, NTFS_COMPBLOCK_SIZE - 1 - len);
+		memcpy(dbuf, cbuf + 2, len + 1);
+		memset(dbuf + len + 1, 0, NTFS_COMPBLOCK_SIZE - 1 - len);
 		return len + 3;
 	}
 	cpos = 2;
@@ -78,12 +78,12 @@
 				boff = -1 - (GET_UINT16(cbuf + cpos) >> dshift);
 				blen = 3 + (GET_UINT16(cbuf + cpos) & lmask);
 				for (j = 0; (j < blen) && (pos < NTFS_COMPBLOCK_SIZE); j++) {
-					buf[pos] = buf[pos + boff];
+					dbuf[pos] = dbuf[pos + boff];
 					pos++;
 				}
 				cpos += 2;
 			} else {
-				buf[pos++] = cbuf[cpos++];
+				dbuf[pos++] = cbuf[cpos++];
 			}
 			ctag >>= 1;
 		}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/ntfs/ntfs_subr.c
--- a/head/sys/fs/ntfs/ntfs_subr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/ntfs/ntfs_subr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/fs/ntfs/ntfs_subr.c 228864 2011-12-24 15:49:52Z kevlo $
+ * $FreeBSD: head/sys/fs/ntfs/ntfs_subr.c 229407 2012-01-03 19:09:01Z pfg $
  */
 
 #include <sys/param.h>
@@ -1636,7 +1636,7 @@
 					for(; remains; remains--)
 						uiomove("", 1, uio);
 				} else 
-					bzero(data, tocopy);
+					memset(data, 0, tocopy);
 				data = data + tocopy;
 			}
 			cnt++;
@@ -1783,7 +1783,7 @@
 						uiomove("", 1, uio);
 				}
 				else
-					bzero(data, tocopy);
+					memset(data, 0, tocopy);
 			} else {
 				error = ntfs_uncompunit(ntmp, uup, cup);
 				if (error)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/nullfs/null_subr.c
--- a/head/sys/fs/nullfs/null_subr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/nullfs/null_subr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
  *
  *	@(#)null_subr.c	8.7 (Berkeley) 5/14/95
  *
- * $FreeBSD: head/sys/fs/nullfs/null_subr.c 227695 2011-11-19 07:40:13Z kib $
+ * $FreeBSD: head/sys/fs/nullfs/null_subr.c 229431 2012-01-03 21:09:07Z kib $
  */
 
 #include <sys/param.h>
@@ -171,6 +171,8 @@
 static void
 null_insmntque_dtr(struct vnode *vp, void *xp)
 {
+
+	vput(((struct null_node *)xp)->null_lowervp);
 	vp->v_data = NULL;
 	vp->v_vnlock = &vp->v_lock;
 	free(xp, M_NULLFSNODE);
@@ -198,6 +200,9 @@
 	struct vnode *vp;
 	int error;
 
+	ASSERT_VOP_LOCKED(lowervp, "lowervp");
+	KASSERT(lowervp->v_usecount >= 1, ("Unreferenced vnode %p\n", vp));
+
 	/* Lookup the hash firstly */
 	*vpp = null_hashget(mp, lowervp);
 	if (*vpp != NULL) {
@@ -223,6 +228,7 @@
 
 	error = getnewvnode("null", mp, &null_vnodeops, &vp);
 	if (error) {
+		vput(lowervp);
 		free(xp, M_NULLFSNODE);
 		return (error);
 	}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/nullfs/null_vfsops.c
--- a/head/sys/fs/nullfs/null_vfsops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/nullfs/null_vfsops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -32,7 +32,7 @@
  *	@(#)null_vfsops.c	8.2 (Berkeley) 1/21/94
  *
  * @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
- * $FreeBSD: head/sys/fs/nullfs/null_vfsops.c 226688 2011-10-24 13:56:31Z kib $
+ * $FreeBSD: head/sys/fs/nullfs/null_vfsops.c 229431 2012-01-03 21:09:07Z kib $
  */
 
 /*
@@ -157,8 +157,7 @@
 	 * Make sure the node alias worked
 	 */
 	if (error) {
-		vrele(lowerrootvp);
-		free(xmp, M_NULLFSMNT);	/* XXX */
+		free(xmp, M_NULLFSMNT);
 		return (error);
 	}
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/nullfs/null_vnops.c
--- a/head/sys/fs/nullfs/null_vnops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/nullfs/null_vnops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
  *	...and...
  *	@(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
  *
- * $FreeBSD: head/sys/fs/nullfs/null_vnops.c 227697 2011-11-19 07:50:49Z kib $
+ * $FreeBSD: head/sys/fs/nullfs/null_vnops.c 229431 2012-01-03 21:09:07Z kib $
  */
 
 /*
@@ -365,9 +365,7 @@
 			vrele(lvp);
 		} else {
 			error = null_nodeget(dvp->v_mount, lvp, &vp);
-			if (error)
-				vput(lvp);
-			else
+			if (error == 0)
 				*ap->a_vpp = vp;
 		}
 	}
@@ -809,9 +807,7 @@
 		NULLVPTOLOWERVP(*dvp);
 #endif
 		VOP_UNLOCK(*dvp, 0); /* keep reference on *dvp */
-	} else
-		vput(ldvp);
-
+	}
 	vn_lock(vp, locked | LK_RETRY);
 	return (error);
 }
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/nwfs/nwfs_vfsops.c
--- a/head/sys/fs/nwfs/nwfs_vfsops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/nwfs/nwfs_vfsops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/fs/nwfs/nwfs_vfsops.c 229272 2012-01-02 12:12:10Z ed $
  */
 
 #include <sys/param.h>
@@ -206,10 +206,10 @@
 	pe = pc+sizeof(mp->mnt_stat.f_mntfromname);
 	bzero(pc, MNAMELEN);
 	*(pc++) = '/';
-	pc = index(strncpy(pc, conn->li.server, pe-pc-2),0);
+	pc = strchr(strncpy(pc, conn->li.server, pe - pc - 2), 0);
 	if (pc < pe-1) {
 		*(pc++) = ':';
-		pc=index(strncpy(pc, conn->li.user, pe-pc-2),0);
+		pc = strchr(strncpy(pc, conn->li.user, pe - pc - 2), 0);
 		if (pc < pe-1) {
 			*(pc++) = '/';
 			strncpy(pc, nmp->m.mounted_vol, pe-pc-2);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/smbfs/smbfs_vfsops.c
--- a/head/sys/fs/smbfs/smbfs_vfsops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/smbfs/smbfs_vfsops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/fs/smbfs/smbfs_vfsops.c 229272 2012-01-02 12:12:10Z ed $
  */
 
 #include <sys/param.h>
@@ -234,10 +234,10 @@
 	bzero(pc, MNAMELEN);
 	*pc++ = '/';
 	*pc++ = '/';
-	pc=index(strncpy(pc, vcp->vc_username, pe - pc - 2), 0);
+	pc = strchr(strncpy(pc, vcp->vc_username, pe - pc - 2), 0);
 	if (pc < pe-1) {
 		*(pc++) = '@';
-		pc = index(strncpy(pc, vcp->vc_srvname, pe - pc - 2), 0);
+		pc = strchr(strncpy(pc, vcp->vc_srvname, pe - pc - 2), 0);
 		if (pc < pe - 1) {
 			*(pc++) = '/';
 			strncpy(pc, ssp->ss_name, pe - pc - 2);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/smbfs/smbfs_vnops.c
--- a/head/sys/fs/smbfs/smbfs_vnops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/smbfs/smbfs_vnops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/fs/smbfs/smbfs_vnops.c 229272 2012-01-02 12:12:10Z ed $
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1039,7 +1039,7 @@
 	 * Backslash characters, being a path delimiter, are prohibited
 	 * within a path component even for LOOKUP operations.
 	 */
-	if (index(name, '\\') != NULL)
+	if (strchr(name, '\\') != NULL)
 		return ENOENT;
 
 	if (nameiop == LOOKUP)
@@ -1051,20 +1051,20 @@
 		 */
 		if (nmlen > 12)
 			return ENAMETOOLONG;
-		cp = index(name, '.');
+		cp = strchr(name, '.');
 		if (cp == NULL)
 			return error;
 		if (cp == name || (cp - name) > 8)
 			return error;
-		cp = index(cp + 1, '.');
+		cp = strchr(cp + 1, '.');
 		if (cp != NULL)
 			return error;
 		for (cp = name, i = 0; i < nmlen; i++, cp++)
-			if (index(badchars83, *cp) != NULL)
+			if (strchr(badchars83, *cp) != NULL)
 				return error;
 	}
 	for (cp = name, i = 0; i < nmlen; i++, cp++)
-		if (index(badchars, *cp) != NULL)
+		if (strchr(badchars, *cp) != NULL)
 			return error;
 	return 0;
 }
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/fs/tmpfs/tmpfs_vnops.c
--- a/head/sys/fs/tmpfs/tmpfs_vnops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/fs/tmpfs/tmpfs_vnops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
  * tmpfs vnode interface.
  */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 227822 2011-11-22 16:18:12Z ivoras $");
+__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 229363 2012-01-03 03:29:01Z alc $");
 
 #include <sys/param.h>
 #include <sys/fcntl.h>
@@ -442,7 +442,7 @@
 	VM_OBJECT_LOCK(tobj);
 	vm_object_pip_add(tobj, 1);
 	m = vm_page_grab(tobj, idx, VM_ALLOC_WIRED |
-	    VM_ALLOC_ZERO | VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
+	    VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
 	if (m->valid != VM_PAGE_BITS_ALL) {
 		if (vm_pager_has_page(tobj, idx, NULL, NULL)) {
 			error = vm_pager_get_pages(tobj, &m, 1, 0);
@@ -666,7 +666,7 @@
 	VM_OBJECT_LOCK(tobj);
 	vm_object_pip_add(tobj, 1);
 	tpg = vm_page_grab(tobj, idx, VM_ALLOC_WIRED |
-	    VM_ALLOC_ZERO | VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
+	    VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
 	if (tpg->valid != VM_PAGE_BITS_ALL) {
 		if (vm_pager_has_page(tobj, idx, NULL, NULL)) {
 			error = vm_pager_get_pages(tobj, &tpg, 1, 0);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/geom/uncompress/g_uncompress.c
--- a/head/sys/geom/uncompress/g_uncompress.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/geom/uncompress/g_uncompress.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2010,2011 Aleksandr Rybalko
+ * Copyright (c) 2010-2012 Aleksandr Rybalko
  * Copyright (c) 2004 Max Khon
  * All rights reserved.
  *
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/geom/uncompress/g_uncompress.c 229537 2012-01-04 23:39:11Z ray $");
 
 #include <sys/param.h>
 #include <sys/bio.h>
@@ -49,26 +49,26 @@
 #include <geom/geom.h>
 
 #include <net/zlib.h>
-#include <contrib/xz-embedded/xz.h>
+#include <contrib/xz-embedded/linux/include/linux/xz.h>
 
 #ifdef GEOM_UNCOMPRESS_DEBUG
-#define DPRINTF(a)	printf a
+#define	DPRINTF(a)	printf a
 extern int g_debugflags;
 #else
-#define DPRINTF(a)
+#define	DPRINTF(a)
 #endif
 
 static MALLOC_DEFINE(M_GEOM_UNCOMPRESS, "geom_uncompress",
-		     "GEOM UNCOMPRESS data structures");
+    "GEOM UNCOMPRESS data structures");
 
-#define UNCOMPRESS_CLASS_NAME	"UNCOMPRESS"
-#define GEOM_UZIP_MAJVER '2'
-#define GEOM_ULZMA_MAJVER '3'
+#define	UNCOMPRESS_CLASS_NAME	"UNCOMPRESS"
+#define	GEOM_UZIP_MAJVER '2'
+#define	GEOM_ULZMA_MAJVER '3'
 
 /*
  * Maximum allowed valid block size (to prevent foot-shooting)
  */
-#define MAX_BLKSZ	(MAXPHYS)
+#define	MAX_BLKSZ	(MAXPHYS)
 
 /*
  * Integer values (block size, number of blocks, offsets)
@@ -76,7 +76,7 @@
  * and in native order in struct g_uncompress_softc
  */
 
-#define CLOOP_MAGIC_LEN 128
+#define	CLOOP_MAGIC_LEN	128
 static char CLOOP_MAGIC_START[] = "#!/bin/sh\n";
 
 struct cloop_header {
@@ -100,7 +100,7 @@
 	int req_total;			/* total requests */
 	int req_cached;			/* cached requests */
 
-	/* XZ decoder struct`s */
+	/* XZ decoder structs */
 	struct xz_buf *b;
 	struct xz_dec *s;
 	z_stream *zs;
@@ -109,6 +109,7 @@
 static void
 g_uncompress_softc_free(struct g_uncompress_softc *sc, struct g_geom *gp)
 {
+
 	if (gp != NULL) {
 		printf("%s: %d requests, %d cached\n",
 		    gp->name, sc->req_total, sc->req_cached);
@@ -149,28 +150,30 @@
 	void *ptr;
 
 	ptr = malloc(type * size, M_GEOM_UNCOMPRESS, M_NOWAIT);
-	return ptr;
+	return (ptr);
 }
 
 static void
 z_free(void *nil, void *ptr)
 {
+
 	free(ptr, M_GEOM_UNCOMPRESS);
 }
 
 static void
 g_uncompress_done(struct bio *bp)
 {
-	int err = 0;
-	struct bio *bp2;
+	struct g_uncompress_softc *sc;
 	struct g_provider *pp, *pp2;
 	struct g_consumer *cp;
 	struct g_geom *gp;
-	struct g_uncompress_softc *sc;
+	struct bio *bp2;
+	uint32_t start_blk, i;
 	off_t pos, upos;
-	uint32_t start_blk, i;
 	size_t bsize;
+	int err;
 
+	err = 0;
 	bp2 = bp->bio_parent;
 	pp = bp2->bio_to;
 	gp = pp->geom;
@@ -305,11 +308,11 @@
 static void
 g_uncompress_start(struct bio *bp)
 {
+	struct g_uncompress_softc *sc;
+	struct g_provider *pp, *pp2;
+	struct g_consumer *cp;
+	struct g_geom *gp;
 	struct bio *bp2;
-	struct g_provider *pp, *pp2;
-	struct g_geom *gp;
-	struct g_consumer *cp;
-	struct g_uncompress_softc *sc;
 	uint32_t start_blk, end_blk;
 	size_t bsize;
 
@@ -415,15 +418,15 @@
 static int
 g_uncompress_access(struct g_provider *pp, int dr, int dw, int de)
 {
+	struct g_consumer *cp;
 	struct g_geom *gp;
-	struct g_consumer *cp;
 
 	gp = pp->geom;
 	cp = LIST_FIRST(&gp->consumer);
 	KASSERT (cp != NULL, ("g_uncompress_access but no consumer"));
 
 	if (cp->acw + dw > 0)
-		return EROFS;
+		return (EROFS);
 
 	return (g_access(cp, dr, dw, de));
 }
@@ -445,14 +448,14 @@
 static struct g_geom *
 g_uncompress_taste(struct g_class *mp, struct g_provider *pp, int flags)
 {
-	int error;
+	struct cloop_header *header;
+	struct g_uncompress_softc *sc;
+	struct g_provider *pp2;
+	struct g_consumer *cp;
+	struct g_geom *gp;
 	uint32_t i, total_offsets, offsets_read, type;
 	uint8_t *buf;
-	struct cloop_header *header;
-	struct g_consumer *cp;
-	struct g_geom *gp;
-	struct g_provider *pp2;
-	struct g_uncompress_softc *sc;
+	int error;
 
 	g_trace(G_T_TOPOLOGY, "%s(%s,%s)", __func__, mp->name, pp->name);
 	g_topology_assert();
@@ -486,7 +489,7 @@
 	DPRINTF(("%s: media sectorsize %u, mediasize %lld\n",
 	    gp->name, pp->sectorsize, pp->mediasize));
 
-        i = roundup(sizeof(struct cloop_header), pp->sectorsize);
+	i = roundup(sizeof(struct cloop_header), pp->sectorsize);
 	buf = g_read_data(cp, 0, i, NULL);
 	if (buf == NULL)
 		goto err;
@@ -542,7 +545,7 @@
 	if (sizeof(struct cloop_header) +
 	    total_offsets * sizeof(uint64_t) > pp->mediasize) {
 		printf("%s: media too small for %u blocks\n",
-		       gp->name, sc->nblocks);
+		    gp->name, sc->nblocks);
 		goto err;
 	}
 	sc->offsets = malloc(
@@ -552,7 +555,7 @@
 	for (i = 0; i < offsets_read; i++)
 		sc->offsets[i] = be64toh(((uint64_t *) (header + 1))[i]);
 	DPRINTF(("%s: %u offsets in the first sector\n",
-	       gp->name, offsets_read));
+	    gp->name, offsets_read));
 
 	free(buf, M_GEOM);
 	i = roundup((sizeof(struct cloop_header) +
@@ -561,8 +564,8 @@
 	if (buf == NULL)
 		goto err;
 	for (i = 0; i <= total_offsets; i++) {
-		sc->offsets[i] =
-		 be64toh(((uint64_t *) (buf+sizeof(struct cloop_header)))[i]);
+		sc->offsets[i] = be64toh(((uint64_t *)
+		    (buf+sizeof(struct cloop_header)))[i]);
 	}
 	DPRINTF(("%s: done reading offsets\n", gp->name));
 	mtx_init(&sc->last_mtx, "geom_uncompress cache", NULL, MTX_DEF);
@@ -593,11 +596,11 @@
 	pp2 = g_new_providerf(gp, "%s", gp->name);
 	pp2->sectorsize = 512;
 	pp2->mediasize = (off_t)sc->nblocks * sc->blksz;
-        pp2->flags = pp->flags & G_PF_CANDELETE;
-        if (pp->stripesize > 0) {
-                pp2->stripesize = pp->stripesize;
-                pp2->stripeoffset = pp->stripeoffset;
-        }
+	pp2->flags = pp->flags & G_PF_CANDELETE;
+	if (pp->stripesize > 0) {
+		pp2->stripesize = pp->stripesize;
+		pp2->stripeoffset = pp->stripeoffset;
+	}
 	g_error_provider(pp2, 0);
 	free(buf, M_GEOM);
 	g_access(cp, -1, 0, 0);
@@ -607,7 +610,7 @@
 	    pp2->sectorsize, pp2->mediasize,
 	    pp2->stripeoffset, pp2->stripesize, pp2->flags));
 	printf("%s: %u x %u blocks\n",
-	       gp->name, sc->nblocks, sc->blksz);
+	    gp->name, sc->nblocks, sc->blksz);
 	return (gp);
 
 err:
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/gnu/fs/xfs/xfs_vfsops.c
--- a/head/sys/gnu/fs/xfs/xfs_vfsops.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/gnu/fs/xfs/xfs_vfsops.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1743,8 +1743,7 @@
 	while ((this_char = strsep(&options, ",")) != NULL) {
 		if (!*this_char)
 			continue;
-
-		if ((value = index(this_char, '=')) != NULL)
+		if ((value = strchr(this_char, '=')) != NULL)
 			*value++ = 0;
 
 		if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/i386/ibcs2/ibcs2_socksys.c
--- a/head/sys/i386/ibcs2/ibcs2_socksys.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/i386/ibcs2/ibcs2_socksys.c	Thu Jan 05 13:30:52 2012 +0200
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_socksys.c 225617 2011-09-16 13:58:51Z kmacy $");
+__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_socksys.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -152,7 +152,7 @@
 	/* Get the domain name. */
 	getcredhostname(td->td_ucred, hname, sizeof(hname));
 
-	dptr = index(hname, '.');
+	dptr = strchr(hname, '.');
 	if ( dptr )
 		dptr++;
 	else
@@ -182,7 +182,7 @@
 		return EINVAL;
 
 	/* Get the host's unqualified name (strip off the domain) */
-	ptr = index(hname, '.');
+	ptr = strchr(hname, '.');
 	if ( ptr != NULL ) {
 		ptr++;
 		*ptr = '\0';
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/i386/ibcs2/ibcs2_stat.c
--- a/head/sys/i386/ibcs2/ibcs2_stat.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/i386/ibcs2/ibcs2_stat.c	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/i386/ibcs2/ibcs2_stat.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -212,7 +212,7 @@
 			IBCS2_UNAME_VERSION, sizeof(sut.version) - 1);
 		getcredhostname(td->td_ucred, machine_name,
 		    sizeof(machine_name) - 1);
-		p = index(machine_name, '.');
+		p = strchr(machine_name, '.');
 		if ( p )
 			*p = '\0';
 		strncpy(sut.nodename, machine_name, sizeof(sut.nodename) - 1);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/i386/include/asm.h
--- a/head/sys/i386/include/asm.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/i386/include/asm.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)DEFS.h	5.1 (Berkeley) 4/23/90
- * $FreeBSD$
+ * $FreeBSD: head/sys/i386/include/asm.h 229562 2012-01-05 08:51:06Z ed $
  */
 
 #ifndef _MACHINE_ASM_H_
@@ -89,6 +89,20 @@
 #define	ENTRY(x)	_ENTRY(x)
 #endif
 
+/*
+ * WEAK_ALIAS: create a weak alias.
+ */
+#define	WEAK_ALIAS(alias,sym)						\
+	.weak alias;							\
+	alias = sym
+
+/*
+ * STRONG_ALIAS: create a strong alias.
+ */
+#define	STRONG_ALIAS(alias,sym)						\
+	.globl alias;							\
+	alias = sym
+
 #define RCSID(x)	.text; .asciz x
 
 #undef __FBSDID
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/kern_intr.c
--- a/head/sys/kern/kern_intr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/kern_intr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_intr.c 224187 2011-07-18 15:19:40Z attilio $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_intr.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include "opt_ddb.h"
 
@@ -693,9 +693,9 @@
 	 * description at that point.  If one is not found, find the
 	 * end of the name to use as the insertion point.
 	 */
-	start = index(ih->ih_name, ':');
+	start = strchr(ih->ih_name, ':');
 	if (start == NULL)
-		start = index(ih->ih_name, 0);
+		start = strchr(ih->ih_name, 0);
 
 	/*
 	 * See if there is enough remaining room in the string for the
@@ -1832,8 +1832,8 @@
 	struct intr_event *ie;
 	int all, verbose;
 
-	verbose = index(modif, 'v') != NULL;
-	all = index(modif, 'a') != NULL;
+	verbose = strchr(modif, 'v') != NULL;
+	all = strchr(modif, 'a') != NULL;
 	TAILQ_FOREACH(ie, &event_list, ie_list) {
 		if (!all && TAILQ_EMPTY(&ie->ie_handlers))
 			continue;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/kern_ktr.c
--- a/head/sys/kern/kern_ktr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/kern_ktr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_ktr.c 227309 2011-11-07 15:43:11Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_ktr.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include "opt_ddb.h"
 #include "opt_ktr.h"
@@ -341,9 +341,9 @@
 	tstate.cur = (ktr_idx - 1) & (KTR_ENTRIES - 1);
 	tstate.first = -1;
 	db_ktr_verbose = 0;
-	db_ktr_verbose |= (index(modif, 'v') != NULL) ? 2 : 0;
-	db_ktr_verbose |= (index(modif, 'V') != NULL) ? 1 : 0; /* just timestap please */
-	if (index(modif, 'a') != NULL) {
+	db_ktr_verbose |= (strchr(modif, 'v') != NULL) ? 2 : 0;
+	db_ktr_verbose |= (strchr(modif, 'V') != NULL) ? 1 : 0; /* just timestap please */
+	if (strchr(modif, 'a') != NULL) {
 		db_disable_pager();
 		while (cncheckc() != -1)
 			if (db_mach_vtrace() == 0)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/kern_linker.c
--- a/head/sys/kern/kern_linker.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/kern_linker.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 227151 2011-11-06 08:10:41Z fjoe $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_linker.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include "opt_ddb.h"
 #include "opt_kld.h"
@@ -1013,7 +1013,7 @@
 	 * (kldname.ko, or kldname.ver.ko) treat it as an interface
 	 * name.
 	 */
-	if (index(file, '/') || index(file, '.')) {
+	if (strchr(file, '/') || strchr(file, '.')) {
 		kldname = file;
 		modname = NULL;
 	} else {
@@ -1906,7 +1906,7 @@
 	int len;
 
 	/* qualified at all? */
-	if (index(name, '/'))
+	if (strchr(name, '/'))
 		return (linker_strdup(name));
 
 	/* traverse the linker path */
@@ -1927,7 +1927,7 @@
 {
 	const char *filename;
 
-	filename = rindex(path, '/');
+	filename = strrchr(path, '/');
 	if (filename == NULL)
 		return path;
 	if (filename[1])
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/kern_thread.c
--- a/head/sys/kern/kern_thread.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/kern_thread.c	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
 #include "opt_hwpmc_hooks.h"
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/kern_thread.c 227657 2011-11-18 09:12:26Z kib $");
+__FBSDID("$FreeBSD: head/sys/kern/kern_thread.c 229429 2012-01-03 21:03:28Z jhb $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -381,7 +381,7 @@
 void
 thread_exit(void)
 {
-	uint64_t new_switchtime;
+	uint64_t runtime, new_switchtime;
 	struct thread *td;
 	struct thread *td2;
 	struct proc *p;
@@ -410,15 +410,6 @@
 	 */
 	cpu_thread_exit(td);	/* XXXSMP */
 
-	/* Do the same timestamp bookkeeping that mi_switch() would do. */
-	new_switchtime = cpu_ticks();
-	p->p_rux.rux_runtime += (new_switchtime - PCPU_GET(switchtime));
-	PCPU_SET(switchtime, new_switchtime);
-	PCPU_SET(switchticks, ticks);
-	PCPU_INC(cnt.v_swtch);
-	/* Save our resource usage in our process. */
-	td->td_ru.ru_nvcsw++;
-	rucollect(&p->p_ru, &td->td_ru);
 	/*
 	 * The last thread is left attached to the process
 	 * So that the whole bundle gets recycled. Skip
@@ -467,7 +458,21 @@
 		PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_OUT);
 #endif
 	PROC_UNLOCK(p);
+
+	/* Do the same timestamp bookkeeping that mi_switch() would do. */
+	new_switchtime = cpu_ticks();
+	runtime = new_switchtime - PCPU_GET(switchtime);
+	td->td_runtime += runtime;
+	td->td_incruntime += runtime;
+	PCPU_SET(switchtime, new_switchtime);
+	PCPU_SET(switchticks, ticks);
+	PCPU_INC(cnt.v_swtch);
+
+	/* Save our resource usage in our process. */
+	td->td_ru.ru_nvcsw++;
 	ruxagg(p, td);
+	rucollect(&p->p_ru, &td->td_ru);
+
 	thread_lock(td);
 	PROC_SUNLOCK(p);
 	td->td_state = TDS_INACTIVE;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/sched_4bsd.c
--- a/head/sys/kern/sched_4bsd.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/sched_4bsd.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sched_4bsd.c 227309 2011-11-07 15:43:11Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/sched_4bsd.c 229429 2012-01-03 21:03:28Z jhb $");
 
 #include "opt_hwpmc_hooks.h"
 #include "opt_sched.h"
@@ -1572,14 +1572,14 @@
 	if (td == NULL) {
 		mtx_lock_spin(&sched_lock);
 		spinlock_exit();
+		PCPU_SET(switchtime, cpu_ticks());
+		PCPU_SET(switchticks, ticks);
 	} else {
 		lock_profile_release_lock(&sched_lock.lock_object);
 		MPASS(td->td_lock == &sched_lock);
 	}
 	mtx_assert(&sched_lock, MA_OWNED);
 	KASSERT(curthread->td_md.md_spinlock_count == 1, ("invalid count"));
-	PCPU_SET(switchtime, cpu_ticks());
-	PCPU_SET(switchticks, ticks);
 	cpu_throw(td, choosethread());	/* doesn't return */
 }
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/sched_ule.c
--- a/head/sys/kern/sched_ule.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/sched_ule.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/sched_ule.c 228960 2011-12-29 16:17:16Z jhb $");
+__FBSDID("$FreeBSD: head/sys/kern/sched_ule.c 229429 2012-01-03 21:03:28Z jhb $");
 
 #include "opt_hwpmc_hooks.h"
 #include "opt_kdtrace.h"
@@ -2587,6 +2587,8 @@
 		/* Correct spinlock nesting and acquire the correct lock. */
 		TDQ_LOCK(tdq);
 		spinlock_exit();
+		PCPU_SET(switchtime, cpu_ticks());
+		PCPU_SET(switchticks, ticks);
 	} else {
 		MPASS(td->td_lock == TDQ_LOCKPTR(tdq));
 		tdq_load_rem(tdq, td);
@@ -2595,8 +2597,6 @@
 	KASSERT(curthread->td_md.md_spinlock_count == 1, ("invalid count"));
 	newtd = choosethread();
 	TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd;
-	PCPU_SET(switchtime, cpu_ticks());
-	PCPU_SET(switchticks, ticks);
 	cpu_throw(td, newtd);		/* doesn't return */
 }
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/subr_hints.c
--- a/head/sys/kern/subr_hints.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/subr_hints.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/kern/subr_hints.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/lock.h>
@@ -133,8 +133,7 @@
 			    r_name, &r_unit, r_resname, r_value);
 		if (hit && n != 4) {
 			printf("CONFIG: invalid hint '%s'\n", cp);
-			/* XXX: abuse bogus index() declaration */
-			p = index(cp, 'h');
+			p = strchr(cp, 'h');
 			*p = 'H';
 			hit = 0;
 		}
@@ -172,18 +171,18 @@
 	s = cp;
 	/* This is a bit of a hack, but at least is reentrant */
 	/* Note that it returns some !unterminated! strings. */
-	s = index(s, '.') + 1;		/* start of device */
+	s = strchr(s, '.') + 1;		/* start of device */
 	if (ret_name)
 		*ret_name = s;
-	s = index(s, '.') + 1;		/* start of unit */
+	s = strchr(s, '.') + 1;		/* start of unit */
 	if (ret_namelen && ret_name)
 		*ret_namelen = s - *ret_name - 1; /* device length */
 	if (ret_unit)
 		*ret_unit = r_unit;
-	s = index(s, '.') + 1;		/* start of resname */
+	s = strchr(s, '.') + 1;		/* start of resname */
 	if (ret_resname)
 		*ret_resname = s;
-	s = index(s, '=') + 1;		/* start of value */
+	s = strchr(s, '=') + 1;		/* start of value */
 	if (ret_resnamelen && ret_resname)
 		*ret_resnamelen = s - *ret_resname - 1; /* value len */
 	if (ret_value)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/tty_inq.c
--- a/head/sys/kern/tty_inq.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/tty_inq.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/tty_inq.c 223575 2011-06-26 18:26:20Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/tty_inq.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -355,7 +355,7 @@
 		return (0);
 
 	while (boff < bend) {
-		if (index(breakc, tib->tib_data[boff]) && !GETBIT(tib, boff)) {
+		if (strchr(breakc, tib->tib_data[boff]) && !GETBIT(tib, boff)) {
 			*lastc = tib->tib_data[boff];
 			return (boff - ti->ti_begin + 1);
 		}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/uipc_mqueue.c
--- a/head/sys/kern/uipc_mqueue.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/uipc_mqueue.c	Thu Jan 05 13:30:52 2012 +0200
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/uipc_mqueue.c 227309 2011-11-07 15:43:11Z ed $");
+__FBSDID("$FreeBSD: head/sys/kern/uipc_mqueue.c 229272 2012-01-02 12:12:10Z ed $");
 
 #include "opt_compat.h"
 
@@ -1974,7 +1974,7 @@
 	 * characters. 
 	 */
 	len = strlen(path);
-	if (len < 2  || path[0] != '/' || index(path + 1, '/') != NULL)
+	if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
 		return (EINVAL);
 
 	error = falloc(td, &fp, &fd, 0);
@@ -2077,7 +2077,7 @@
 		return (error);
 
 	len = strlen(path);
-	if (len < 2  || path[0] != '/' || index(path + 1, '/') != NULL)
+	if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL)
 		return (EINVAL);
 
 	sx_xlock(&mqfs_data.mi_lock);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/kern/vfs_lookup.c
--- a/head/sys/kern/vfs_lookup.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/kern/vfs_lookup.c	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/kern/vfs_lookup.c 226495 2011-10-18 07:28:58Z des $");
+__FBSDID("$FreeBSD: head/sys/kern/vfs_lookup.c 229185 2012-01-01 18:45:59Z kib $");
 
 #include "opt_capsicum.h"
 #include "opt_kdtrace.h"
@@ -508,12 +508,14 @@
 	int dvfslocked;			/* VFS Giant state for parent */
 	int tvfslocked;
 	int lkflags_save;
+	int ni_dvp_unlocked;
 	
 	/*
 	 * Setup: break out flag bits into variables.
 	 */
 	dvfslocked = (ndp->ni_cnd.cn_flags & GIANTHELD) != 0;
 	vfslocked = 0;
+	ni_dvp_unlocked = 0;
 	ndp->ni_cnd.cn_flags &= ~GIANTHELD;
 	wantparent = cnp->cn_flags & (LOCKPARENT | WANTPARENT);
 	KASSERT(cnp->cn_nameiop == LOOKUP || wantparent,
@@ -861,8 +863,10 @@
 		/*
 		 * Symlink code always expects an unlocked dvp.
 		 */
-		if (ndp->ni_dvp != ndp->ni_vp)
+		if (ndp->ni_dvp != ndp->ni_vp) {
 			VOP_UNLOCK(ndp->ni_dvp, 0);
+			ni_dvp_unlocked = 1;
+		}
 		goto success;
 	}
 
@@ -909,14 +913,17 @@
 		VREF(ndp->ni_startdir);
 	}
 	if (!wantparent) {
+		ni_dvp_unlocked = 2;
 		if (ndp->ni_dvp != dp)
 			vput(ndp->ni_dvp);
 		else
 			vrele(ndp->ni_dvp);
 		VFS_UNLOCK_GIANT(dvfslocked);
 		dvfslocked = 0;
-	} else if ((cnp->cn_flags & LOCKPARENT) == 0 && ndp->ni_dvp != dp)
+	} else if ((cnp->cn_flags & LOCKPARENT) == 0 && ndp->ni_dvp != dp) {
 		VOP_UNLOCK(ndp->ni_dvp, 0);
+		ni_dvp_unlocked = 1;
+	}
 
 	if (cnp->cn_flags & AUDITVNODE1)
 		AUDIT_ARG_VNODE1(dp);
@@ -945,10 +952,12 @@
 	return (0);
 
 bad2:
-	if (dp != ndp->ni_dvp)
-		vput(ndp->ni_dvp);
-	else
-		vrele(ndp->ni_dvp);
+	if (ni_dvp_unlocked != 2) {
+		if (dp != ndp->ni_dvp && !ni_dvp_unlocked)
+			vput(ndp->ni_dvp);
+		else
+			vrele(ndp->ni_dvp);
+	}
 bad:
 	if (!dpunlocked)
 		vput(dp);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/fnmatch.c
--- a/head/sys/libkern/fnmatch.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/libkern/fnmatch.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/libkern/fnmatch.c 229272 2012-01-02 12:12:10Z ed $");
 
 /*
  * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
@@ -89,12 +89,12 @@
 			if (c == EOS)
 				if (flags & FNM_PATHNAME)
 					return ((flags & FNM_LEADING_DIR) ||
-					    index(string, '/') == NULL ?
+					    strchr(string, '/') == NULL ?
 					    0 : FNM_NOMATCH);
 				else
 					return (0);
 			else if (c == '/' && flags & FNM_PATHNAME) {
-				if ((string = index(string, '/')) == NULL)
+				if ((string = strchr(string, '/')) == NULL)
 					return (FNM_NOMATCH);
 				break;
 			}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/index.c
--- a/head/sys/libkern/index.c	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/libkern.h>
-
-/*
- * index() is also present as the strchr() in the kernel; it does exactly the
- * same thing as it's userland equivalent.
- */
-char *
-index(p, ch)
-	const char *p;
-	int ch;
-{
-	union {
-		const char *cp;
-		char *p;
-	} u;
-
-	u.cp = p;
-	for (;; ++u.p) {
-		if (*u.p == ch)
-			return(u.p);
-		if (*u.p == '\0')
-			return(NULL);
-	}
-	/* NOTREACHED */
-}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/memcchr.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/libkern/memcchr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,115 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/sys/libkern/memcchr.c 229198 2012-01-01 20:26:11Z ed $");
+
+#include <sys/libkern.h>
+#include <sys/limits.h>
+#include <sys/param.h>
+
+/*
+ * memcchr(): find first character in buffer not matching `c'.
+ *
+ * This function performs the complement of memchr().  To provide decent
+ * performance, this function compares data from the buffer one word at
+ * a time.
+ *
+ * This code is inspired by libc's strlen(), written by Xin Li.
+ */
+
+#if LONG_BIT != 32 && LONG_BIT != 64
+#error Unsupported word size
+#endif
+
+#define	LONGPTR_MASK (sizeof(long) - 1)
+
+#define	TESTBYTE				\
+	do {					\
+		if (*p != (unsigned char)c)	\
+			goto done;		\
+		p++;				\
+	} while (0)
+
+void *
+memcchr(const void *begin, int c, size_t n)
+{
+	const unsigned long *lp;
+	const unsigned char *p, *end;
+	unsigned long word;
+
+	/* Four or eight repetitions of `c'. */
+	word = (unsigned char)c;
+	word |= word << 8;
+	word |= word << 16;
+#if LONG_BIT >= 64
+	word |= word << 32;
+#endif
+
+	/* Don't perform memory I/O when passing a zero-length buffer. */
+	if (n == 0)
+		return (NULL);
+
+	/*
+	 * First determine whether there is a character unequal to `c'
+	 * in the first word.  As this word may contain bytes before
+	 * `begin', we may execute this loop spuriously.
+	 */
+	lp = (const unsigned long *)((uintptr_t)begin & ~LONGPTR_MASK);
+	end = (const unsigned char *)begin + n;
+	if (*lp++ != word)
+		for (p = begin; p < (const unsigned char *)lp;)
+			TESTBYTE;
+
+	/* Now compare the data one word at a time. */
+	for (; (const unsigned char *)lp < end; lp++) {
+		if (*lp != word) {
+			p = (const unsigned char *)lp;
+			TESTBYTE;
+			TESTBYTE;
+			TESTBYTE;
+#if LONG_BIT >= 64
+			TESTBYTE;
+			TESTBYTE;
+			TESTBYTE;
+			TESTBYTE;
+#endif
+			goto done;
+		}
+	}
+
+	return (NULL);
+
+done:
+	/*
+	 * If the end of the buffer is not word aligned, the previous
+	 * loops may obtain an address that's beyond the end of the
+	 * buffer.
+	 */
+	if (p < end)
+		return (__DECONST(void *, p));
+	return (NULL);
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/rindex.c
--- a/head/sys/libkern/rindex.c	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*-
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/libkern.h>
-
-/*
- * rindex() is also present as the strrchr() in the kernel; it does exactly the
- * same thing as it's userland equivalent.
- */
-char *
-rindex(p, ch)
-	const char *p;
-	int ch;
-{
-	union {
-		const char *cp;
-		char *p;
-	} u;
-	char *save;
-
-	u.cp = p;
-	for (save = NULL;; ++u.p) {
-		if (*u.p == ch)
-			save = u.p;
-		if (*u.p == '\0')
-			return(save);
-	}
-	/* NOTREACHED */
-}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/skpc.c
--- a/head/sys/libkern/skpc.c	Thu Jan 05 12:46:30 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)skpc.c	8.1 (Berkeley) 6/10/93
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/libkern.h>
-
-int
-skpc(mask0, size, cp0)
-	int mask0;
-	int size;
-	char *cp0;
-{
-	register u_char *cp, *end, mask;
-
-	mask = mask0;
-	cp = (u_char *)cp0;
-	for (end = &cp[size]; cp < end && *cp == mask; ++cp);
-	return (end - cp);
-}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/strchr.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/libkern/strchr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,52 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/sys/libkern/strchr.c 229366 2012-01-03 07:05:30Z ed $");
+
+#include <sys/param.h>
+#include <sys/libkern.h>
+
+char *
+strchr(const char *p, int ch)
+{
+	union {
+		const char *cp;
+		char *p;
+	} u;
+
+	u.cp = p;
+	for (;; ++u.p) {
+		if (*u.p == ch)
+			return(u.p);
+		if (*u.p == '\0')
+			return(NULL);
+	}
+	/* NOTREACHED */
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/libkern/strrchr.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/sys/libkern/strrchr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/sys/libkern/strrchr.c 229366 2012-01-03 07:05:30Z ed $");
+
+#include <sys/param.h>
+#include <sys/libkern.h>
+
+char *
+strrchr(const char *p, int ch)
+{
+	union {
+		const char *cp;
+		char *p;
+	} u;
+	char *save;
+
+	u.cp = p;
+	for (save = NULL;; ++u.p) {
+		if (*u.p == ch)
+			save = u.p;
+		if (*u.p == '\0')
+			return(save);
+	}
+	/* NOTREACHED */
+}
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/ciu.c
--- a/head/sys/mips/cavium/ciu.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/ciu.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,11 +23,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/ciu.c 217214 2011-01-10 03:48:41Z jmallett $
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/ciu.c 217214 2011-01-10 03:48:41Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/cryptocteon/cavium_crypto.c
--- a/head/sys/mips/cavium/cryptocteon/cavium_crypto.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/cryptocteon/cavium_crypto.c	Thu Jan 05 13:30:52 2012 +0200
@@ -42,7 +42,7 @@
 /****************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/cryptocteon/cavium_crypto.c 217620 2011-01-20 05:44:36Z gonzo $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/cryptocteon/cryptocteon.c
--- a/head/sys/mips/cavium/cryptocteon/cryptocteon.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/cryptocteon/cryptocteon.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/cryptocteon/cryptocteon.c 210312 2010-07-20 19:32:25Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/cryptocteon/cryptocteonvar.h
--- a/head/sys/mips/cavium/cryptocteon/cryptocteonvar.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/cryptocteon/cryptocteonvar.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
  * and/or fitness for purpose.
  * ---------------------------------------------------------------------------
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/cryptocteon/cryptocteonvar.h 210312 2010-07-20 19:32:25Z jmallett $
  */
 
 #ifndef	_MIPS_CAVIUM_CRYPTOCTEON_CRYPTOCTEONVAR_H_
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/cvmx_config.h
--- a/head/sys/mips/cavium/cvmx_config.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/cvmx_config.h	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
  * For any questions regarding licensing please contact marketing at caviumnetworks.com
  *
  ***********************license end**************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/cvmx_config.h 217214 2011-01-10 03:48:41Z jmallett $ */
 
 #ifndef	_CVMX_CONFIG_H
 #define	_CVMX_CONFIG_H
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/files.octeon1
--- a/head/sys/mips/cavium/files.octeon1	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/files.octeon1	Thu Jan 05 13:30:52 2012 +0200
@@ -46,13 +46,8 @@
 
 mips/cavium/usb/octusb.c			optional usb octusb
 mips/cavium/usb/octusb_octeon.c			optional usb octusb
-contrib/octeon-sdk/cvmx-usb.c			optional usb octusb
 
-contrib/octeon-sdk/cvmx-usb.c			optional usb cndotg
-dev/usb/controller/dotg_octeon.c		optional usb cndotg
-dev/usb/controller/dotg_cn50xx.c		optional usb cndotg
-
-dev/cfi/cfi_bus_ciu.c				optional cfi
+contrib/octeon-sdk/cvmx-usb.c			optional octusb
 
 mips/cavium/octeon_gpio.c			optional gpio
 
@@ -101,4 +96,3 @@
 contrib/octeon-sdk/cvmx-twsi.c			standard
 contrib/octeon-sdk/cvmx-warn.c			standard
 contrib/octeon-sdk/octeon-model.c		standard
-
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/obio.c
--- a/head/sys/mips/cavium/obio.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/obio.c	Thu Jan 05 13:30:52 2012 +0200
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/obio.c 212843 2010-09-19 09:18:27Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/obiovar.h
--- a/head/sys/mips/cavium/obiovar.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/obiovar.h	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/obiovar.h 203128 2010-01-28 20:38:52Z imp $
  *
  */
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/cavium-ethernet.h
--- a/head/sys/mips/cavium/octe/cavium-ethernet.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/cavium-ethernet.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/cavium-ethernet.h 213762 2010-10-13 09:17:44Z jmallett $ */
 
 /**
  * @file
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-common.h
--- a/head/sys/mips/cavium/octe/ethernet-common.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-common.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-common.h 219706 2011-03-16 22:51:34Z jmallett $ */
 
 int cvm_oct_common_open(struct ifnet *ifp);
 int cvm_oct_common_stop(struct ifnet *ifp);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-defines.h
--- a/head/sys/mips/cavium/octe/ethernet-defines.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-defines.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-defines.h 217664 2011-01-20 23:34:59Z jmallett $ */
 
 /*
  * A few defines are used to control the operation of this driver:
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-headers.h
--- a/head/sys/mips/cavium/octe/ethernet-headers.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-headers.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-headers.h 213346 2010-10-02 05:43:17Z jmallett $ */
 
 #ifndef __ETHERNET_HEADERS_H__
 #define __ETHERNET_HEADERS_H__
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-mdio.c
--- a/head/sys/mips/cavium/octe/ethernet-mdio.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-mdio.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-mdio.c 215974 2010-11-28 05:57:24Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-mdio.h
--- a/head/sys/mips/cavium/octe/ethernet-mdio.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-mdio.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-mdio.h 210311 2010-07-20 19:25:11Z jmallett $ */
 
 extern struct mtx cvm_oct_mdio_mtx;
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-mem.c
--- a/head/sys/mips/cavium/octe/ethernet-mem.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-mem.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-mem.c 215974 2010-11-28 05:57:24Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-mem.h
--- a/head/sys/mips/cavium/octe/ethernet-mem.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-mem.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-mem.h 210311 2010-07-20 19:25:11Z jmallett $ */
 
 int cvm_oct_mem_fill_fpa(int pool, int size, int elements);
 void cvm_oct_mem_empty_fpa(int pool, int size, int elements);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-mv88e61xx.c
--- a/head/sys/mips/cavium/octe/ethernet-mv88e61xx.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-mv88e61xx.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octe/ethernet-mv88e61xx.c 213762 2010-10-13 09:17:44Z jmallett $
  */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-mv88e61xx.c 213762 2010-10-13 09:17:44Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-mv88e61xx.h
--- a/head/sys/mips/cavium/octe/ethernet-mv88e61xx.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-mv88e61xx.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octe/ethernet-mv88e61xx.h 213346 2010-10-02 05:43:17Z jmallett $
  */
 
 #ifndef	_CAVIUM_OCTE_ETHERNET_MV88E61XX_H_
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-rgmii.c
--- a/head/sys/mips/cavium/octe/ethernet-rgmii.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-rgmii.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-rgmii.c 216071 2010-11-30 07:14:05Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -216,15 +216,6 @@
 	int rid;
 
 	cvm_oct_common_init(ifp);
-
-//	char mac[6] = {
-//		cvmx_sysinfo_get()->mac_addr_base[0],
-//		cvmx_sysinfo_get()->mac_addr_base[1],
-//		cvmx_sysinfo_get()->mac_addr_base[2],
-//		cvmx_sysinfo_get()->mac_addr_base[3],
-//		cvmx_sysinfo_get()->mac_addr_base[4],
-//		cvmx_sysinfo_get()->mac_addr_base[5] };
-//	mac[5] += cvm_oct_mac_addr_offset++;
 	priv->open = cvm_oct_common_open;
 	priv->stop = cvm_oct_common_stop;
 	priv->stop(ifp);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-rx.c
--- a/head/sys/mips/cavium/octe/ethernet-rx.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-rx.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-rx.c 217664 2011-01-20 23:34:59Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-rx.h
--- a/head/sys/mips/cavium/octe/ethernet-rx.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-rx.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-rx.h 210311 2010-07-20 19:25:11Z jmallett $ */
 
 int cvm_oct_do_interrupt(void *dev_id);
 void cvm_oct_poll_controller(struct ifnet *ifp);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-sgmii.c
--- a/head/sys/mips/cavium/octe/ethernet-sgmii.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-sgmii.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-sgmii.c 216071 2010-11-30 07:14:05Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-spi.c
--- a/head/sys/mips/cavium/octe/ethernet-spi.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-spi.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-spi.c 210311 2010-07-20 19:25:11Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-tx.c
--- a/head/sys/mips/cavium/octe/ethernet-tx.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-tx.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-tx.c 217665 2011-01-20 23:51:03Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-tx.h
--- a/head/sys/mips/cavium/octe/ethernet-tx.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-tx.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-tx.h 215959 2010-11-28 00:26:08Z jmallett $ */
 
 int cvm_oct_xmit(struct mbuf *m, struct ifnet *ifp);
 void cvm_oct_tx_shutdown(struct ifnet *ifp);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-util.h
--- a/head/sys/mips/cavium/octe/ethernet-util.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-util.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/ethernet-util.h 210311 2010-07-20 19:25:11Z jmallett $ */
 
 #define DEBUGPRINT(format, ...) printf(format, ##__VA_ARGS__)
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/ethernet-xaui.c
--- a/head/sys/mips/cavium/octe/ethernet-xaui.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/ethernet-xaui.c	Thu Jan 05 13:30:52 2012 +0200
@@ -28,7 +28,7 @@
 *************************************************************************/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/ethernet-xaui.c 216071 2010-11-30 07:14:05Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/mv88e61xxphy.c
--- a/head/sys/mips/cavium/octe/mv88e61xxphy.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/mv88e61xxphy.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,11 +23,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octe/mv88e61xxphy.c 213762 2010-10-13 09:17:44Z jmallett $
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octe/mv88e61xxphy.c 213762 2010-10-13 09:17:44Z jmallett $");
 
 /*
  * Driver for the Marvell 88E61xx family of switch PHYs
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/mv88e61xxphyreg.h
--- a/head/sys/mips/cavium/octe/mv88e61xxphyreg.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/mv88e61xxphyreg.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octe/mv88e61xxphyreg.h 213762 2010-10-13 09:17:44Z jmallett $
  */
 
 /*
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/octe.c
--- a/head/sys/mips/cavium/octe/octe.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/octe.c	Thu Jan 05 13:30:52 2012 +0200
@@ -145,7 +145,7 @@
 
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
 
-	if (priv->phy_id != -1 && 0) {
+	if (priv->phy_id != -1) {
 		if (priv->phy_device == NULL) {
 			error = mii_attach(dev, &priv->miibus, ifp,
 			    octe_mii_medchange, octe_mii_medstat,
@@ -157,12 +157,6 @@
 			if (child == NULL)
 				device_printf(dev, "missing phy %u device %s\n", priv->phy_id, priv->phy_device);
 		}
-	} else {
-		error = mii_attach(dev, &priv->miibus, ifp,
-		    octe_mii_medchange, octe_mii_medstat,
-		    BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
-		if (error != 0)
-			device_printf(dev, "attaching PHYs failed\n");
 	}
 
 	if (priv->miibus == NULL) {
@@ -190,18 +184,7 @@
 		mtx_init(&priv->tx_free_queue[qos].ifq_mtx, ifp->if_xname, "octe tx free queue", MTX_DEF);
 		IFQ_SET_MAXLEN(&priv->tx_free_queue[qos], MAX_OUT_QUEUE_DEPTH);
 	}
-	priv->mac[0] = 0x00;
-	priv->mac[1] = 0xDE;
-	priv->mac[2] = 0xAD;
-	priv->mac[3] = 0x20;
-	priv->mac[4] = 0x75;
-	priv->mac[5] = 0x00;
 
-	printf("\tMAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
-	    priv->mac[0], priv->mac[1],
-	    priv->mac[2], priv->mac[3],
-	    priv->mac[4], priv->mac[5]
-	    );
 	ether_ifattach(ifp, priv->mac);
 
 	ifp->if_transmit = octe_transmit;
@@ -248,8 +231,8 @@
 	/*
 	 * Try generic MII routine.
 	 */
-//	KASSERT(phy == priv->phy_id,
-//	    ("read from phy %u but our phy is %u", phy, priv->phy_id));
+	KASSERT(phy == priv->phy_id,
+	    ("read from phy %u but our phy is %u", phy, priv->phy_id));
 	return (cvm_oct_mdio_read(priv->ifp, phy, reg));
 }
 
@@ -271,8 +254,8 @@
 	/*
 	 * Try generic MII routine.
 	 */
-//	KASSERT(phy == priv->phy_id,
-//	    ("write to phy %u but our phy is %u", phy, priv->phy_id));
+	KASSERT(phy == priv->phy_id,
+	    ("write to phy %u but our phy is %u", phy, priv->phy_id));
 	cvm_oct_mdio_write(priv->ifp, phy, reg, val);
 
 	return (0);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/octebus.c
--- a/head/sys/mips/cavium/octe/octebus.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/octebus.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octe/octebus.c 219695 2011-03-16 08:56:22Z jmallett $
  */
 
 /*
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/octebusvar.h
--- a/head/sys/mips/cavium/octe/octebusvar.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/octebusvar.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octe/octebusvar.h 219695 2011-03-16 08:56:22Z jmallett $
  */
 
 #ifndef	_CAVIUM_OCTE_OCTEBUSVAR_H_
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octe/wrapper-cvmx-includes.h
--- a/head/sys/mips/cavium/octe/wrapper-cvmx-includes.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octe/wrapper-cvmx-includes.h	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
 
 *************************************************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octe/wrapper-cvmx-includes.h 219694 2011-03-16 08:51:36Z jmallett $ */
 
 #ifndef __WRAPPER_CVMX_INCLUDES_H__
 #define __WRAPPER_CVMX_INCLUDES_H__
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octeon_ds1337.c
--- a/head/sys/mips/cavium/octeon_ds1337.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octeon_ds1337.c	Thu Jan 05 13:30:52 2012 +0200
@@ -69,7 +69,6 @@
                 rc = -1; \
             } \
         } while(0);
-#define	DS1337_BIT_CENTURY	0x80	/* in REG_MONTH */
 
 static int validate_ct_struct(struct clocktime *ct)
 {
@@ -78,11 +77,6 @@
     if (!ct)
 	return -1;
 
-#ifdef CVMX_RTC_DEBUG
-    printf("%s: %04d-%02d-%02d WD%d %02d:%02d:%02d\n", __func__,
-	ct->year + 1900, ct->mon+1, ct->day, ct->dow+1,
-	ct->hour, ct->min, ct->sec);
-#endif /* CVMX_RTC_DEBUG */
     CT_CHECK(ct->sec < 0  || ct->sec > 60,  "second"); /* + Leap sec */
     CT_CHECK(ct->min < 0  || ct->min > 59,  "minute");
     CT_CHECK(ct->hour < 0 || ct->hour > 23, "hour");
@@ -170,7 +164,6 @@
     ts.tv_nsec = 0;
 
     clock_ts_to_ct(&ts, &ct);
-    ct.year -= 1900;
 
     if (validate_ct_struct(&ct))
     {
@@ -186,7 +179,7 @@
     reg[5] = bin2bcd(ct.mon);
     if (ct.year >= 2000)             /* Set century bit*/
     {
-	reg[5] |= DS1337_BIT_CENTURY;
+	reg[5] |= 0x80;
     }
     reg[6] = bin2bcd(ct.year % 100);
 
@@ -211,7 +204,6 @@
 }
 
 #ifdef CVMX_RTC_DEBUG
-void cvmx_rtc_ds1337_dump_state(void);
 
 void cvmx_rtc_ds1337_dump_state(void)
 {
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octeon_nmi.S
--- a/head/sys/mips/cavium/octeon_nmi.S	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octeon_nmi.S	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octeon_nmi.S 215989 2010-11-28 08:11:05Z gonzo $
  */
 
 #include <machine/asm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octeon_rnd.c
--- a/head/sys/mips/cavium/octeon_rnd.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octeon_rnd.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,11 +23,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octeon_rnd.c 210311 2010-07-20 19:25:11Z jmallett $
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octeon_rnd.c 210311 2010-07-20 19:25:11Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octeon_rtc.c
--- a/head/sys/mips/cavium/octeon_rtc.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octeon_rtc.c	Thu Jan 05 13:30:52 2012 +0200
@@ -23,11 +23,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octeon_rtc.c 210311 2010-07-20 19:25:11Z jmallett $
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octeon_rtc.c 210311 2010-07-20 19:25:11Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octeon_wdog.c
--- a/head/sys/mips/cavium/octeon_wdog.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octeon_wdog.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octeon_wdog.c 217243 2011-01-10 22:14:08Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octopci.c
--- a/head/sys/mips/cavium/octopci.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octopci.c	Thu Jan 05 13:30:52 2012 +0200
@@ -715,8 +715,6 @@
 	for (s = 0; s <= PCI_SLOTMAX; s++) {
 		for (f = 0; f <= PCI_FUNCMAX; f++) {
 			hdrtype = octopci_read_config(dev, b, s, f, PCIR_HDRTYPE, 1);
-			printf("%s: b=%d, s=%d, f=%d PCIR_HDRTYPE=%02x\n",
-			    __func__, b, s, f, hdrtype);
 
 			if (hdrtype == 0xff) {
 				if (f == 0)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octopci_bus_space.c
--- a/head/sys/mips/cavium/octopci_bus_space.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octopci_bus_space.c	Thu Jan 05 13:30:52 2012 +0200
@@ -69,10 +69,10 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  *	from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octopci_bus_space.c 210311 2010-07-20 19:25:11Z jmallett $
  */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/octopci_bus_space.c 210311 2010-07-20 19:25:11Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octopcireg.h
--- a/head/sys/mips/cavium/octopcireg.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octopcireg.h	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
  * For any questions regarding licensing please contact marketing at caviumnetworks.com
  *
  ***********************license end**************************************/
-/* $FreeBSD$ */
+/* $FreeBSD: head/sys/mips/cavium/octopcireg.h 213089 2010-09-24 00:14:24Z jmallett $ */
 
 #ifndef	_CAVIUM_OCTOPCIREG_H_
 #define	_CAVIUM_OCTOPCIREG_H_
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/octopcivar.h
--- a/head/sys/mips/cavium/octopcivar.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/octopcivar.h	Thu Jan 05 13:30:52 2012 +0200
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/cavium/octopcivar.h 210311 2010-07-20 19:25:11Z jmallett $
  */
 #ifndef	_MIPS_CAVIUM_OCTOPCIVAR_H
 #define	_MIPS_CAVIUM_OCTOPCIVAR_H
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/std.octeon1
--- a/head/sys/mips/cavium/std.octeon1	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/std.octeon1	Thu Jan 05 13:30:52 2012 +0200
@@ -2,7 +2,7 @@
 #  *    This product includes software developed by the University of
 #  *    California, Berkeley and its contributors."
 # */
-# $FreeBSD$
+# $FreeBSD: head/sys/mips/cavium/std.octeon1 215270 2010-11-13 22:34:12Z imp $
 # 
 files	"../cavium/files.octeon1"
 machine	mips mips64eb
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/uart_bus_octeonusart.c
--- a/head/sys/mips/cavium/uart_bus_octeonusart.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/uart_bus_octeonusart.c	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
 #include "opt_uart.h"
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/uart_bus_octeonusart.c 217573 2011-01-19 07:06:28Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/uart_cpu_octeonusart.c
--- a/head/sys/mips/cavium/uart_cpu_octeonusart.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/uart_cpu_octeonusart.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 #include "opt_uart.h"
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/uart_cpu_octeonusart.c 213345 2010-10-02 05:38:45Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/uart_dev_oct16550.c
--- a/head/sys/mips/cavium/uart_dev_oct16550.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/uart_dev_oct16550.c	Thu Jan 05 13:30:52 2012 +0200
@@ -55,7 +55,7 @@
 
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/uart_dev_oct16550.c 213345 2010-10-02 05:38:45Z jmallett $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/cavium/usb/octusb.c
--- a/head/sys/mips/cavium/usb/octusb.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/cavium/usb/octusb.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,5 @@
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/mips/cavium/usb/octusb.c 229072 2011-12-31 05:45:10Z gonzo $");
+__FBSDID("$FreeBSD: head/sys/mips/cavium/usb/octusb.c 229408 2012-01-03 19:10:37Z gonzo $");
 
 /*-
  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
@@ -169,7 +169,7 @@
 	    (td->qh->ep_num & UE_DIR_IN) ? CVMX_USB_DIRECTION_IN :
 	    CVMX_USB_DIRECTION_OUT,
 	    td->qh->ep_interval,
-	    td->qh->ep_mult,
+	    (td->qh->dev_speed == USB_SPEED_HIGH) ? td->qh->ep_mult : 0,
 	    td->qh->hs_hub_addr,
 	    td->qh->hs_hub_port);
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/conf/PB47
--- a/head/sys/mips/conf/PB47	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/conf/PB47	Thu Jan 05 13:30:52 2012 +0200
@@ -10,7 +10,7 @@
 # * 8MB NOR SPI flash
 # * 64MB RAM
 #
-# $FreeBSD: head/sys/mips/conf/PB47 228988 2011-12-30 09:48:35Z adrian $
+# $FreeBSD: head/sys/mips/conf/PB47 229561 2012-01-05 07:19:05Z adrian $
 #
 
 include		"AR71XX_BASE"
@@ -24,28 +24,19 @@
 # XXX TODO: add uboot boot parameter parsing to extract MAC, RAM.
 # Right now it will just detect 32mb out of 64mb, as well as
 # return a garbage MAC address.
-
-# don't compile these in - the default flash area for kernel space
-# is only 1.2 megabytes.  To keep the flash allocation in line with
-# what the documentation says for this board, we'll just have to keep
-# the kernel smaller than that.
-nodevice wlan, wlan_wep, wlan_ccmp, wlan_tkip, wlan_xauth
-nodevice ath, ath_pci, ath_hal, ath_rate_sample
-
-# Since the module build doesn't like TDMA..
-nooptions	IEEE80211_SUPPORT_TDMA
+options		AR71XX_REALMEM=64*1024*1024
 
 # For DOS - enable if required
-#options		GEOM_PART_BSD
-#options		GEOM_PART_MBR
-#options		MSDOSFS
+options		GEOM_PART_BSD
+options		GEOM_PART_MBR
+options		MSDOSFS
 
-# uzip - to boot natively from flash
-device		geom_uzip
-options		GEOM_UZIP
+# uncompress - to boot read-only lzma natively from flash
+device		geom_uncompress
+options		GEOM_UNCOMPRESS
 
 # Used for the static uboot partition map
 device		geom_map
 
 # Boot off of the rootfs, as defined in the geom_map setup.
-options		ROOTDEVNAME=\"ufs:map/rootfs.uzip\"
+options		ROOTDEVNAME=\"ufs:map/rootfs.uncompress\"
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/mips/include/_stdint.h
--- a/head/sys/mips/include/_stdint.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/mips/include/_stdint.h	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  *
  *	from: src/sys/i386/include/_stdint.h,v 1.2 2004/05/18 16:04:57 stefanf
- * $FreeBSD$
+ * $FreeBSD: head/sys/mips/include/_stdint.h 229496 2012-01-04 16:07:16Z andreast $
  */
 
 #ifndef _MACHINE__STDINT_H_
@@ -66,6 +66,14 @@
 
 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
 
+#ifdef __mips_n64
+#define __INT64_C(c)              (c ## L)
+#define __UINT64_C(c)             (c ## UL)
+#else
+#define __INT64_C(c)              (c ## LL)
+#define __UINT64_C(c)             (c ## ULL)
+#endif
+
 /*
  * ISO/IEC 9899:1999
  * 7.18.2.1 Limits of exact-width integer types
@@ -74,19 +82,19 @@
 #define	INT8_MIN	(-0x7f-1)
 #define	INT16_MIN	(-0x7fff-1)
 #define	INT32_MIN	(-0x7fffffff-1)
-#define	INT64_MIN	(-INT64_C(0x7fffffffffffffff)-1)
+#define	INT64_MIN	(-__INT64_C(0x7fffffffffffffff)-1)
 
 /* Maximum values of exact-width signed integer types. */
 #define	INT8_MAX	0x7f
 #define	INT16_MAX	0x7fff
 #define	INT32_MAX	0x7fffffff
-#define	INT64_MAX	INT64_C(0x7fffffffffffffff)
+#define	INT64_MAX	__INT64_C(0x7fffffffffffffff)
 
 /* Maximum values of exact-width unsigned integer types. */
 #define	UINT8_MAX	0xff
 #define	UINT16_MAX	0xffff
 #define	UINT32_MAX	0xffffffff
-#define	UINT64_MAX	UINT64_C(0xffffffffffffffff)
+#define	UINT64_MAX	__UINT64_C(0xffffffffffffffff)
 
 /*
  * ISO/IEC 9899:1999
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/modules/ath/Makefile
--- a/head/sys/modules/ath/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/modules/ath/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGES.
 #
-# $FreeBSD: head/sys/modules/ath/Makefile 228887 2011-12-26 05:37:09Z adrian $
+# $FreeBSD: head/sys/modules/ath/Makefile 229560 2012-01-05 06:22:09Z adrian $
 #
 
 ATH_RATE?=	sample		# tx rate control algorithm
@@ -140,8 +140,10 @@
 
 CFLAGS+=  -I. -I${.CURDIR}/../../dev/ath -I${.CURDIR}/../../dev/ath/ath_hal
 
+.if !defined(KERNBUILDDIR)
 opt_ah.h:
 	echo '#define AH_SUPPORT_AR5416 1' > [email protected]
+.endif
 
 .include <bsd.kmod.mk>
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/modules/geom/geom_uncompress/Makefile
--- a/head/sys/modules/geom/geom_uncompress/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/modules/geom/geom_uncompress/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,13 +1,18 @@
-# $FreeBSD$
+# $FreeBSD: head/sys/modules/geom/geom_uncompress/Makefile 229537 2012-01-04 23:39:11Z ray $
 
 .PATH: ${.CURDIR}/../../../geom/uncompress \
-    ${.CURDIR}/../../../contrib/xz-embedded \
+    ${.CURDIR}/../../../contrib/xz-embedded/freebsd/ \
+    ${.CURDIR}/../../../contrib/xz-embedded/linux/lib/xz/ \
+    ${.CURDIR}/../../../contrib/xz-embedded/linux/include/linux/ \
     ${.CURDIR}/../../../net
 
 KMOD=	geom_uncompress
-CFLAGS= -I${.CURDIR}/../../../contrib/xz-embedded/
+CFLAGS= -I${.CURDIR}/../../../geom/uncompress/ \
+	-I${.CURDIR}/../../../contrib/xz-embedded/freebsd \
+	-I${.CURDIR}/../../../contrib/xz-embedded/linux/lib/xz/
 SRCS=	g_uncompress.c xz_crc32.c xz_dec_bcj.c xz_dec_lzma2.c xz_dec_stream.c \
     xz_malloc.c zlib.c
 SRCS+=	xz.h xz_config.h xz_lzma2.h xz_malloc.h xz_private.h xz_stream.h zlib.h
 
 .include <bsd.kmod.mk>
+
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/modules/kgssapi_krb5/Makefile
--- a/head/sys/modules/kgssapi_krb5/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/modules/kgssapi_krb5/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD: head/sys/modules/kgssapi_krb5/Makefile 223309 2011-06-19 22:08:55Z rmacklem $
+# $FreeBSD: head/sys/modules/kgssapi_krb5/Makefile 229519 2012-01-04 21:14:22Z jhb $
 
 .PATH: ${.CURDIR}/../../kgssapi/krb5
 KMOD=	kgssapi_krb5
@@ -13,6 +13,7 @@
 
 SRCS+=		kgss_if.h gssd.h
 MFILES=		kgssapi/kgss_if.m
+CLEANFILES=	gssd.h
 
 S=		${.CURDIR}/../..
 
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/modules/sound/driver/emu10k1/Makefile
--- a/head/sys/modules/sound/driver/emu10k1/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/modules/sound/driver/emu10k1/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,19 +1,11 @@
-# $FreeBSD$
+# $FreeBSD: head/sys/modules/sound/driver/emu10k1/Makefile 229430 2012-01-03 21:04:54Z pfg $
 
 .PATH: ${.CURDIR}/../../../../dev/sound/pci \
        ${.CURDIR}/../../../../gnu/dev/sound/pci
 
 KMOD=	snd_emu10k1
-SRCS=	device_if.h bus_if.h pci_if.h emu10k1-alsa%diked.h
+SRCS=	device_if.h bus_if.h emuxkireg.h pci_if.h
 SRCS+= mpufoi_if.h
 SRCS+=	emu10k1.c
 
-CLEANFILES+= emu10k1-alsa%diked.h
-
-emu10k1-alsa%diked.h: emu10k1-alsa.h
-	grep -v '#include' ${.OODATE} | $(CC) -E -D__KERNEL__ -dM - \
-	    | awk -F"[ 	(]" '/define/ \
-	    { print "#ifndef " $$2 ; print ; print "#endif" }' \
-	    >${.TARGET}
-
 .include <bsd.kmod.mk>
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/net80211/ieee80211_ht.c
--- a/head/sys/net80211/ieee80211_ht.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/net80211/ieee80211_ht.c	Thu Jan 05 13:30:52 2012 +0200
@@ -25,7 +25,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __FreeBSD__
-__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_ht.c 228621 2011-12-17 10:23:17Z bschmidt $");
+__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_ht.c 229284 2012-01-02 16:02:30Z bschmidt $");
 #endif
 
 /*
@@ -433,7 +433,7 @@
 		ADDRATE(i);
 	if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) &&
 	    (ic->ic_htcaps & IEEE80211_HTC_TXMCS32))
-		ADDRATE(i);
+		ADDRATE(32);
 	if (ic->ic_htcaps & IEEE80211_HTC_TXUNEQUAL) {
 		if (ic->ic_txstream >= 2) {
 			 for (i = 33; i <= 38; i++)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netgraph/ng_ksocket.c
--- a/head/sys/netgraph/ng_ksocket.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netgraph/ng_ksocket.c	Thu Jan 05 13:30:52 2012 +0200
@@ -37,7 +37,7 @@
  *
  * Author: Archie Cobbs <archie at freebsd.org>
  *
- * $FreeBSD: head/sys/netgraph/ng_ksocket.c 227293 2011-11-07 06:44:47Z ed $
+ * $FreeBSD: head/sys/netgraph/ng_ksocket.c 229272 2012-01-02 12:12:10Z ed $
  * $Whistle: ng_ksocket.c,v 1.1 1999/11/16 20:04:40 archie Exp $
  */
 
@@ -223,7 +223,7 @@
 	/* Get socket address family followed by a slash */
 	while (isspace(s[*off]))
 		(*off)++;
-	if ((t = index(s + *off, '/')) == NULL)
+	if ((t = strchr(s + *off, '/')) == NULL)
 		return (EINVAL);
 	if ((len = t - (s + *off)) > sizeof(fambuf) - 1)
 		return (EINVAL);
@@ -565,14 +565,14 @@
 		/* Extract family, type, and protocol from hook name */
 		snprintf(name, sizeof(name), "%s", name0);
 		s1 = name;
-		if ((s2 = index(s1, '/')) == NULL)
+		if ((s2 = strchr(s1, '/')) == NULL)
 			return (EINVAL);
 		*s2++ = '\0';
 		family = ng_ksocket_parse(ng_ksocket_families, s1, 0);
 		if (family == -1)
 			return (EINVAL);
 		s1 = s2;
-		if ((s2 = index(s1, '/')) == NULL)
+		if ((s2 = strchr(s1, '/')) == NULL)
 			return (EINVAL);
 		*s2++ = '\0';
 		type = ng_ksocket_parse(ng_ksocket_types, s1, 0);
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet/igmp.c
--- a/head/sys/netinet/igmp.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet/igmp.c	Thu Jan 05 13:30:52 2012 +0200
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/igmp.c 227309 2011-11-07 15:43:11Z ed $");
+__FBSDID("$FreeBSD: head/sys/netinet/igmp.c 229420 2012-01-03 20:34:52Z jhb $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1642,7 +1642,7 @@
 	struct ifqueue		 qrq;	/* Query response packets */
 	struct ifnet		*ifp;
 	struct igmp_ifinfo	*igi;
-	struct ifmultiaddr	*ifma, *tifma;
+	struct ifmultiaddr	*ifma;
 	struct in_multi		*inm;
 	int			 loop, uri_fasthz;
 
@@ -1709,8 +1709,7 @@
 		}
 
 		IF_ADDR_LOCK(ifp);
-		TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link,
-		    tifma) {
+		TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
 			if (ifma->ifma_addr->sa_family != AF_INET ||
 			    ifma->ifma_protospec == NULL)
 				continue;
@@ -2004,7 +2003,7 @@
 {
 	struct ifmultiaddr	*ifma;
 	struct ifnet		*ifp;
-	struct in_multi		*inm;
+	struct in_multi		*inm, *tinm;
 
 	CTR3(KTR_IGMPV3, "%s: cancel v3 timers on ifp %p(%s)", __func__,
 	    igi->igi_ifp, igi->igi_ifp->if_xname);
@@ -2050,14 +2049,8 @@
 			 * transition to REPORTING to ensure the host leave
 			 * message is sent upstream to the old querier --
 			 * transition to NOT would lose the leave and race.
-			 *
-			 * SMPNG: Must drop and re-acquire IF_ADDR_LOCK
-			 * around inm_release_locked(), as it is not
-			 * a recursive mutex.
 			 */
-			IF_ADDR_UNLOCK(ifp);
-			inm_release_locked(inm);
-			IF_ADDR_LOCK(ifp);
+			SLIST_INSERT_HEAD(&igi->igi_relinmhead, inm, inm_nrele);
 			/* FALLTHROUGH */
 		case IGMP_G_QUERY_PENDING_MEMBER:
 		case IGMP_SG_QUERY_PENDING_MEMBER:
@@ -2076,6 +2069,10 @@
 		_IF_DRAIN(&inm->inm_scq);
 	}
 	IF_ADDR_UNLOCK(ifp);
+	SLIST_FOREACH_SAFE(inm, &igi->igi_relinmhead, inm_nrele, tinm) {
+		SLIST_REMOVE_HEAD(&igi->igi_relinmhead, inm_nrele);
+		inm_release_locked(inm);
+	}
 }
 
 /*
@@ -3321,7 +3318,7 @@
 static void
 igmp_v3_dispatch_general_query(struct igmp_ifinfo *igi)
 {
-	struct ifmultiaddr	*ifma, *tifma;
+	struct ifmultiaddr	*ifma;
 	struct ifnet		*ifp;
 	struct in_multi		*inm;
 	int			 retval, loop;
@@ -3335,7 +3332,7 @@
 	ifp = igi->igi_ifp;
 
 	IF_ADDR_LOCK(ifp);
-	TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, tifma) {
+	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
 		if (ifma->ifma_addr->sa_family != AF_INET ||
 		    ifma->ifma_protospec == NULL)
 			continue;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet/in.c
--- a/head/sys/netinet/in.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet/in.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/in.c 228768 2011-12-21 12:39:08Z glebius $");
+__FBSDID("$FreeBSD: head/sys/netinet/in.c 229478 2012-01-04 13:29:26Z jhb $");
 
 #include "opt_mpath.h"
 
@@ -735,7 +735,7 @@
 		if (iflr->flags & IFLR_PREFIX)
 			return (EINVAL);
 
-		/* copy args to in_aliasreq, perform ioctl(SIOCAIFADDR_IN6). */
+		/* copy args to in_aliasreq, perform ioctl(SIOCAIFADDR). */
 		bzero(&ifra, sizeof(ifra));
 		bcopy(iflr->iflr_name, ifra.ifra_name,
 			sizeof(ifra.ifra_name));
@@ -784,16 +784,21 @@
 			}
 		}
 
+		IF_ADDR_LOCK(ifp);
 		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)	{
-			if (ifa->ifa_addr->sa_family != AF_INET6)
+			if (ifa->ifa_addr->sa_family != AF_INET)
 				continue;
 			if (match.s_addr == 0)
 				break;
-			candidate.s_addr = ((struct sockaddr_in *)&ifa->ifa_addr)->sin_addr.s_addr;
+			sin = (struct sockaddr_in *)&ifa->ifa_addr;
+			candidate.s_addr = sin->sin_addr.s_addr;
 			candidate.s_addr &= mask.s_addr;
 			if (candidate.s_addr == match.s_addr)
 				break;
 		}
+		if (ifa != NULL)
+			ifa_ref(ifa);
+		IF_ADDR_UNLOCK(ifp);
 		if (ifa == NULL)
 			return (EADDRNOTAVAIL);
 		ia = (struct in_ifaddr *)ifa;
@@ -812,12 +817,13 @@
 				in_mask2len(&ia->ia_sockmask.sin_addr);
 
 			iflr->flags = 0;	/*XXX*/
+			ifa_free(ifa);
 
 			return (0);
 		} else {
 			struct in_aliasreq ifra;
 
-			/* fill in_aliasreq and do ioctl(SIOCDIFADDR_IN6) */
+			/* fill in_aliasreq and do ioctl(SIOCDIFADDR) */
 			bzero(&ifra, sizeof(ifra));
 			bcopy(iflr->iflr_name, ifra.ifra_name,
 				sizeof(ifra.ifra_name));
@@ -830,6 +836,7 @@
 			}
 			bcopy(&ia->ia_sockmask, &ifra.ifra_dstaddr,
 				ia->ia_sockmask.sin_len);
+			ifa_free(ifa);
 
 			return (in_control(so, SIOCDIFADDR, (caddr_t)&ifra,
 			    ifp, td));
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet/raw_ip.c
--- a/head/sys/netinet/raw_ip.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet/raw_ip.c	Thu Jan 05 13:30:52 2012 +0200
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/raw_ip.c 226105 2011-10-07 13:43:01Z andre $");
+__FBSDID("$FreeBSD: head/sys/netinet/raw_ip.c 229265 2012-01-02 09:18:58Z bz $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -544,6 +544,8 @@
  *
  * When adding new socket options here, make sure to add access control
  * checks here as necessary.
+ *
+ * XXX-BZ inp locking?
  */
 int
 rip_ctloutput(struct socket *so, struct sockopt *sopt)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet6/in6.c
--- a/head/sys/netinet6/in6.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet6/in6.c	Thu Jan 05 13:30:52 2012 +0200
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet6/in6.c 228966 2011-12-29 18:25:18Z jhb $");
+__FBSDID("$FreeBSD: head/sys/netinet6/in6.c 229465 2012-01-04 07:01:23Z glebius $");
 
 #include "opt_compat.h"
 #include "opt_inet.h"
@@ -1325,7 +1325,7 @@
 	struct sockaddr_in6 mltaddr, mltmask;
 	int plen, error;
 	struct rtentry *rt;
-	struct ifaddr *ifa0, *nifa;
+	struct ifaddr *ifa0;
 
 	if (ifa->ifa_carp)
 		(*carp_detach_p)(ifa);
@@ -1336,7 +1336,7 @@
 	 * address routes
 	 */
 	IF_ADDR_LOCK(ifp);
-	TAILQ_FOREACH_SAFE(ifa0, &ifp->if_addrhead, ifa_link, nifa) {
+	TAILQ_FOREACH(ifa0, &ifp->if_addrhead, ifa_link) {
 		if ((ifa0->ifa_addr->sa_family != AF_INET6) ||
 		    memcmp(&satosin6(ifa0->ifa_addr)->sin6_addr,
 			   &ia->ia_addr.sin6_addr, 
@@ -1767,6 +1767,8 @@
 			if (IN6_ARE_ADDR_EQUAL(&candidate, &match))
 				break;
 		}
+		if (ifa != NULL)
+			ifa_ref(ifa);
 		IF_ADDR_UNLOCK(ifp);
 		if (!ifa)
 			return EADDRNOTAVAIL;
@@ -1779,16 +1781,20 @@
 			bcopy(&ia->ia_addr, &iflr->addr, ia->ia_addr.sin6_len);
 			error = sa6_recoverscope(
 			    (struct sockaddr_in6 *)&iflr->addr);
-			if (error != 0)
+			if (error != 0) {
+				ifa_free(ifa);
 				return (error);
+			}
 
 			if ((ifp->if_flags & IFF_POINTOPOINT) != 0) {
 				bcopy(&ia->ia_dstaddr, &iflr->dstaddr,
 				    ia->ia_dstaddr.sin6_len);
 				error = sa6_recoverscope(
 				    (struct sockaddr_in6 *)&iflr->dstaddr);
-				if (error != 0)
+				if (error != 0) {
+					ifa_free(ifa);
 					return (error);
+				}
 			} else
 				bzero(&iflr->dstaddr, sizeof(iflr->dstaddr));
 
@@ -1796,6 +1802,7 @@
 			    in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL);
 
 			iflr->flags = ia->ia6_flags;	/* XXX */
+			ifa_free(ifa);
 
 			return 0;
 		} else {
@@ -1819,6 +1826,7 @@
 			    ia->ia_prefixmask.sin6_len);
 
 			ifra.ifra_flags = ia->ia6_flags;
+			ifa_free(ifa);
 			return in6_control(so, SIOCDIFADDR_IN6, (caddr_t)&ifra,
 			    ifp, td);
 		}
@@ -2236,9 +2244,7 @@
 		IF_ADDR_UNLOCK(ifp);
 		return (besta);
 	}
-	IF_ADDR_UNLOCK(ifp);
 
-	IN6_IFADDR_RLOCK();
 	TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
 		if (ifa->ifa_addr->sa_family != AF_INET6)
 			continue;
@@ -2256,10 +2262,10 @@
 
 		if (ifa != NULL)
 			ifa_ref(ifa);
-		IN6_IFADDR_RUNLOCK();
+		IF_ADDR_UNLOCK(ifp);
 		return (struct in6_ifaddr *)ifa;
 	}
-	IN6_IFADDR_RUNLOCK();
+	IF_ADDR_UNLOCK(ifp);
 
 	/* use the last-resort values, that are, deprecated addresses */
 	if (dep[0])
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet6/in6_ifattach.c
--- a/head/sys/netinet6/in6_ifattach.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet6/in6_ifattach.c	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet6/in6_ifattach.c 228966 2011-12-29 18:25:18Z jhb $");
+__FBSDID("$FreeBSD: head/sys/netinet6/in6_ifattach.c 229546 2012-01-05 01:13:25Z bz $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -513,12 +513,8 @@
 	}
 
 	ia = in6ifa_ifpforlinklocal(ifp, 0); /* ia must not be NULL */
-#ifdef DIAGNOSTIC
-	if (!ia) {
-		panic("ia == NULL in in6_ifattach_linklocal");
-		/* NOTREACHED */
-	}
-#endif
+	KASSERT(ia != NULL, ("%s: ia == NULL, ifp=%p", __func__, ifp));
+
 	ifa_free(&ia->ia_ifa);
 
 	/*
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet6/in6_var.h
--- a/head/sys/netinet6/in6_var.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet6/in6_var.h	Thu Jan 05 13:30:52 2012 +0200
@@ -58,7 +58,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)in_var.h	8.1 (Berkeley) 6/10/93
- * $FreeBSD: head/sys/netinet6/in6_var.h 228768 2011-12-21 12:39:08Z glebius $
+ * $FreeBSD: head/sys/netinet6/in6_var.h 229276 2012-01-02 13:03:13Z bz $
  */
 
 #ifndef _NETINET6_IN6_VAR_H_
@@ -791,8 +791,7 @@
 void	in6_ifaddloop(struct ifaddr *);
 
 int	in6_is_addr_deprecated __P((struct sockaddr_in6 *));
-struct inpcb;
-int in6_src_ioctl __P((u_long, caddr_t));
+int	in6_src_ioctl __P((u_long, caddr_t));
 #endif /* _KERNEL */
 
 #endif /* _NETINET6_IN6_VAR_H_ */
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet6/mld6.c
--- a/head/sys/netinet6/mld6.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet6/mld6.c	Thu Jan 05 13:30:52 2012 +0200
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet6/mld6.c 228321 2011-12-07 13:37:42Z glebius $");
+__FBSDID("$FreeBSD: head/sys/netinet6/mld6.c 229479 2012-01-04 13:35:20Z jhb $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -121,7 +121,8 @@
 		    /*const*/ struct mld_hdr *);
 static int	mld_v1_input_report(struct ifnet *, const struct ip6_hdr *,
 		    /*const*/ struct mld_hdr *);
-static void	mld_v1_process_group_timer(struct in6_multi *, const int);
+static void	mld_v1_process_group_timer(struct mld_ifinfo *,
+		    struct in6_multi *);
 static void	mld_v1_process_querier_timers(struct mld_ifinfo *);
 static int	mld_v1_transmit_report(struct in6_multi *, const int);
 static void	mld_v1_update_group(struct in6_multi *, const int);
@@ -1336,8 +1337,8 @@
 	struct ifqueue		 qrq;	/* Query response packets */
 	struct ifnet		*ifp;
 	struct mld_ifinfo	*mli;
-	struct ifmultiaddr	*ifma, *tifma;
-	struct in6_multi	*inm;
+	struct ifmultiaddr	*ifma;
+	struct in6_multi	*inm, *tinm;
 	int			 uri_fasthz;
 
 	uri_fasthz = 0;
@@ -1401,24 +1402,14 @@
 		}
 
 		IF_ADDR_LOCK(ifp);
-		TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link,
-		    tifma) {
+		TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
 			if (ifma->ifma_addr->sa_family != AF_INET6 ||
 			    ifma->ifma_protospec == NULL)
 				continue;
 			inm = (struct in6_multi *)ifma->ifma_protospec;
 			switch (mli->mli_version) {
 			case MLD_VERSION_1:
-				/*
-				 * XXX Drop IF_ADDR lock temporarily to
-				 * avoid recursion caused by a potential
-				 * call by in6ifa_ifpforlinklocal().
-				 * rwlock candidate?
-				 */
-				IF_ADDR_UNLOCK(ifp);
-				mld_v1_process_group_timer(inm,
-				    mli->mli_version);
-				IF_ADDR_LOCK(ifp);
+				mld_v1_process_group_timer(mli, inm);
 				break;
 			case MLD_VERSION_2:
 				mld_v2_process_group_timers(mli, &qrq,
@@ -1428,9 +1419,25 @@
 		}
 		IF_ADDR_UNLOCK(ifp);
 
-		if (mli->mli_version == MLD_VERSION_2) {
-			struct in6_multi		*tinm;
-
+		switch (mli->mli_version) {
+		case MLD_VERSION_1:
+			/*
+			 * Transmit reports for this lifecycle.  This
+			 * is done while not holding IF_ADDR_LOCK
+			 * since this can call
+			 * in6ifa_ifpforlinklocal() which locks
+			 * IF_ADDR_LOCK internally as well as
+			 * ip6_output() to transmit a packet.
+			 */
+			SLIST_FOREACH_SAFE(inm, &mli->mli_relinmhead,
+			    in6m_nrele, tinm) {
+				SLIST_REMOVE_HEAD(&mli->mli_relinmhead,
+				    in6m_nrele);
+				(void)mld_v1_transmit_report(inm,
+				    MLD_LISTENER_REPORT);
+			}
+			break;
+		case MLD_VERSION_2:
 			mld_dispatch_queue(&qrq, 0);
 			mld_dispatch_queue(&scq, 0);
 
@@ -1444,6 +1451,7 @@
 				    in6m_nrele);
 				in6m_release_locked(inm);
 			}
+			break;
 		}
 	}
 
@@ -1457,7 +1465,7 @@
  * Will update the global pending timer flags.
  */
 static void
-mld_v1_process_group_timer(struct in6_multi *inm, const int version)
+mld_v1_process_group_timer(struct mld_ifinfo *mli, struct in6_multi *inm)
 {
 	int report_timer_expired;
 
@@ -1484,8 +1492,8 @@
 	case MLD_REPORTING_MEMBER:
 		if (report_timer_expired) {
 			inm->in6m_state = MLD_IDLE_MEMBER;
-			(void)mld_v1_transmit_report(inm,
-			     MLD_LISTENER_REPORT);
+			SLIST_INSERT_HEAD(&mli->mli_relinmhead, inm,
+			    in6m_nrele);
 		}
 		break;
 	case MLD_G_QUERY_PENDING_MEMBER:
@@ -1656,7 +1664,7 @@
 {
 	struct ifmultiaddr	*ifma;
 	struct ifnet		*ifp;
-	struct in6_multi		*inm;
+	struct in6_multi	*inm, *tinm;
 
 	CTR3(KTR_MLD, "%s: cancel v2 timers on ifp %p(%s)", __func__,
 	    mli->mli_ifp, mli->mli_ifp->if_xname);
@@ -1695,14 +1703,9 @@
 			 * If we are leaving the group and switching
 			 * version, we need to release the final
 			 * reference held for issuing the INCLUDE {}.
-			 *
-			 * SMPNG: Must drop and re-acquire IF_ADDR_LOCK
-			 * around in6m_release_locked(), as it is not
-			 * a recursive mutex.
 			 */
-			IF_ADDR_UNLOCK(ifp);
-			in6m_release_locked(inm);
-			IF_ADDR_LOCK(ifp);
+			SLIST_INSERT_HEAD(&mli->mli_relinmhead, inm,
+			    in6m_nrele);
 			/* FALLTHROUGH */
 		case MLD_G_QUERY_PENDING_MEMBER:
 		case MLD_SG_QUERY_PENDING_MEMBER:
@@ -1720,6 +1723,10 @@
 		}
 	}
 	IF_ADDR_UNLOCK(ifp);
+	SLIST_FOREACH_SAFE(inm, &mli->mli_relinmhead, in6m_nrele, tinm) {
+		SLIST_REMOVE_HEAD(&mli->mli_relinmhead, in6m_nrele);
+		in6m_release_locked(inm);
+	}
 }
 
 /*
@@ -2976,7 +2983,7 @@
 static void
 mld_v2_dispatch_general_query(struct mld_ifinfo *mli)
 {
-	struct ifmultiaddr	*ifma, *tifma;
+	struct ifmultiaddr	*ifma;
 	struct ifnet		*ifp;
 	struct in6_multi	*inm;
 	int			 retval;
@@ -2990,7 +2997,7 @@
 	ifp = mli->mli_ifp;
 
 	IF_ADDR_LOCK(ifp);
-	TAILQ_FOREACH_SAFE(ifma, &ifp->if_multiaddrs, ifma_link, tifma) {
+	TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
 		if (ifma->ifma_addr->sa_family != AF_INET6 ||
 		    ifma->ifma_protospec == NULL)
 			continue;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet6/nd6.h
--- a/head/sys/netinet6/nd6.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet6/nd6.h	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	$KAME: nd6.h,v 1.76 2001/12/18 02:10:31 itojun Exp $
- * $FreeBSD: head/sys/netinet6/nd6.h 228966 2011-12-29 18:25:18Z jhb $
+ * $FreeBSD: head/sys/netinet6/nd6.h 229547 2012-01-05 01:14:35Z bz $
  */
 
 #ifndef _NETINET6_ND6_H_
@@ -434,15 +434,12 @@
 void nd6_rs_input __P((struct mbuf *, int, int));
 void nd6_ra_input __P((struct mbuf *, int, int));
 void prelist_del __P((struct nd_prefix *));
-void defrouter_addreq __P((struct nd_defrouter *));
 void defrouter_reset __P((void));
 void defrouter_select __P((void));
 void defrtrlist_del __P((struct nd_defrouter *));
 void prelist_remove __P((struct nd_prefix *));
 int nd6_prelist_add __P((struct nd_prefixctl *, struct nd_defrouter *,
 	struct nd_prefix **));
-int nd6_prefix_onlink __P((struct nd_prefix *));
-int nd6_prefix_offlink __P((struct nd_prefix *));
 void pfxlist_onlink_check __P((void));
 struct nd_defrouter *defrouter_lookup __P((struct in6_addr *, struct ifnet *));
 struct nd_prefix *nd6_prefix_lookup __P((struct nd_prefixctl *));
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/netinet6/nd6_rtr.c
--- a/head/sys/netinet6/nd6_rtr.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/netinet6/nd6_rtr.c	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet6/nd6_rtr.c 228966 2011-12-29 18:25:18Z jhb $");
+__FBSDID("$FreeBSD: head/sys/netinet6/nd6_rtr.c 229547 2012-01-05 01:14:35Z bz $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -84,6 +84,9 @@
 static void in6_init_address_ltimes __P((struct nd_prefix *,
 	struct in6_addrlifetime *));
 
+static int nd6_prefix_onlink(struct nd_prefix *);
+static int nd6_prefix_offlink(struct nd_prefix *);
+
 static int rt6_deleteroute(struct radix_node *, void *);
 
 VNET_DECLARE(int, nd6_recalc_reachtm_interval);
@@ -465,7 +468,7 @@
 		ifa_free(ifa);
 }
 
-void
+static void
 defrouter_addreq(struct nd_defrouter *new)
 {
 	struct sockaddr_in6 def, mask, gate;
@@ -1537,7 +1540,7 @@
 	}
 }
 
-int
+static int
 nd6_prefix_onlink(struct nd_prefix *pr)
 {
 	struct ifaddr *ifa;
@@ -1662,7 +1665,7 @@
 	return (error);
 }
 
-int
+static int
 nd6_prefix_offlink(struct nd_prefix *pr)
 {
 	int error = 0;
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/powerpc/include/_stdint.h
--- a/head/sys/powerpc/include/_stdint.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/powerpc/include/_stdint.h	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/sys/powerpc/include/_stdint.h 229494 2012-01-04 16:02:52Z andreast $
  */
 
 #ifndef _MACHINE__STDINT_H_
@@ -65,6 +65,14 @@
 
 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
 
+#ifdef __LP64__
+#define	__INT64_C(c)		(c ## L)
+#define	__UINT64_C(c)		(c ## UL)
+#else
+#define	__INT64_C(c)		(c ## LL)
+#define	__UINT64_C(c)		(c ## ULL)
+#endif
+
 /*
  * ISO/IEC 9899:1999
  * 7.18.2.1 Limits of exact-width integer types
@@ -73,19 +81,19 @@
 #define	INT8_MIN	(-0x7f-1)
 #define	INT16_MIN	(-0x7fff-1)
 #define	INT32_MIN	(-0x7fffffff-1)
-#define	INT64_MIN	(-INT64_C(0x7fffffffffffffff)-1)
+#define	INT64_MIN	(-__INT64_C(0x7fffffffffffffff)-1)
 
 /* Maximum values of exact-width signed integer types. */
 #define	INT8_MAX	0x7f
 #define	INT16_MAX	0x7fff
 #define	INT32_MAX	0x7fffffff
-#define	INT64_MAX	INT64_C(0x7fffffffffffffff)
+#define	INT64_MAX	__INT64_C(0x7fffffffffffffff)
 
 /* Maximum values of exact-width unsigned integer types. */
 #define	UINT8_MAX	0xff
 #define	UINT16_MAX	0xffff
 #define	UINT32_MAX	0xffffffff
-#define	UINT64_MAX	UINT64_C(0xffffffffffffffff)
+#define	UINT64_MAX	__UINT64_C(0xffffffffffffffff)
 
 /*
  * ISO/IEC 9899:1999
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/security/mac_lomac/mac_lomac.c
--- a/head/sys/security/mac_lomac/mac_lomac.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/security/mac_lomac/mac_lomac.c	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/sys/security/mac_lomac/mac_lomac.c 227309 2011-11-07 15:43:11Z ed $
+ * $FreeBSD: head/sys/security/mac_lomac/mac_lomac.c 229272 2012-01-02 12:12:10Z ed $
  */
 
 /*
@@ -762,10 +762,10 @@
 
 	/* Do we have a range? */
 	single = string;
-	range = index(string, '(');
+	range = strchr(string, '(');
 	if (range == single)
 		single = NULL;
-	auxsingle = index(string, '[');
+	auxsingle = strchr(string, '[');
 	if (auxsingle == single)
 		single = NULL;
 	if (range != NULL && auxsingle != NULL)
@@ -776,13 +776,13 @@
 		*range = '\0';
 		range++;
 		rangelow = range;
-		rangehigh = index(rangelow, '-');
+		rangehigh = strchr(rangelow, '-');
 		if (rangehigh == NULL)
 			return (EINVAL);
 		rangehigh++;
 		if (*rangelow == '\0' || *rangehigh == '\0')
 			return (EINVAL);
-		rangeend = index(rangehigh, ')');
+		rangeend = strchr(rangehigh, ')');
 		if (rangeend == NULL)
 			return (EINVAL);
 		if (*(rangeend + 1) != '\0')
@@ -798,7 +798,7 @@
 		/* Nul terminate the end of the single string. */
 		*auxsingle = '\0';
 		auxsingle++;
-		auxsingleend = index(auxsingle, ']');
+		auxsingleend = strchr(auxsingle, ']');
 		if (auxsingleend == NULL)
 			return (EINVAL);
 		if (*(auxsingleend + 1) != '\0')
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/sys/cdefs.h
--- a/head/sys/sys/cdefs.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/sys/cdefs.h	Thu Jan 05 13:30:52 2012 +0200
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
- * $FreeBSD: head/sys/sys/cdefs.h 228900 2011-12-26 18:49:56Z ed $
+ * $FreeBSD: head/sys/sys/cdefs.h 229574 2012-01-05 10:43:03Z ed $
  */
 
 #ifndef	_SYS_CDEFS_H_
@@ -248,6 +248,24 @@
 #endif
 #endif
 
+/*
+ * Emulation of C11 _Generic().  Unlike the previously defined C11
+ * keywords, it is not possible to implement this using exactly the same
+ * syntax.  Therefore implement something similar under the name
+ * __generic().  Unlike _Generic(), this macro can only distinguish
+ * between a single type, so it requires nested invocations to
+ * distinguish multiple cases.
+ */
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#define	__generic(expr, t, yes, no)					\
+	_Generic(expr, t: yes, default: no)
+#elif __GNUC_PREREQ__(3, 1)
+#define	__generic(expr, t, yes, no)					\
+	__builtin_choose_expr(						\
+	    __builtin_types_compatible_p(__typeof(expr), t), yes, no)
+#endif
+
 #if __GNUC_PREREQ__(2, 96)
 #define	__malloc_like	__attribute__((__malloc__))
 #define	__pure		__attribute__((__pure__))
@@ -450,7 +468,7 @@
  * Embed the rcs id of a source file in the resulting library.  Note that in
  * more recent ELF binutils, we use .ident allowing the ID to be stripped.
  * Usage:
- *	__FBSDID("$FreeBSD: head/sys/sys/cdefs.h 228900 2011-12-26 18:49:56Z ed $");
+ *	__FBSDID("$FreeBSD: head/sys/sys/cdefs.h 229574 2012-01-05 10:43:03Z ed $");
  */
 #ifndef	__FBSDID
 #if !defined(lint) && !defined(STRIP_FBSDID)
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/sys/libkern.h
--- a/head/sys/sys/libkern.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/sys/libkern.h	Thu Jan 05 13:30:52 2012 +0200
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)libkern.h	8.1 (Berkeley) 6/10/93
- * $FreeBSD: head/sys/sys/libkern.h 228642 2011-12-17 15:48:55Z avg $
+ * $FreeBSD: head/sys/sys/libkern.h 229366 2012-01-03 07:05:30Z ed $
  */
 
 #ifndef _SYS_LIBKERN_H_
@@ -92,19 +92,18 @@
 int	 fnmatch(const char *, const char *, int);
 int	 locc(int, char *, u_int);
 void	*memchr(const void *s, int c, size_t n);
+void	*memcchr(const void *s, int c, size_t n);
 int	 memcmp(const void *b1, const void *b2, size_t len);
 void	 qsort(void *base, size_t nmemb, size_t size,
 	    int (*compar)(const void *, const void *));
 void	 qsort_r(void *base, size_t nmemb, size_t size, void *thunk,
 	    int (*compar)(void *, const void *, const void *));
 u_long	 random(void);
-char	*index(const char *, int);
-char	*rindex(const char *, int);
 int	 scanc(u_int, const u_char *, const u_char *, int);
-int	 skpc(int, int, char *);
 void	 srandom(u_long);
 int	 strcasecmp(const char *, const char *);
 char	*strcat(char * __restrict, const char * __restrict);
+char	*strchr(const char *, int);
 int	 strcmp(const char *, const char *);
 char	*strcpy(char * __restrict, const char * __restrict);
 size_t	 strcspn(const char * __restrict, const char * __restrict) __pure;
@@ -116,6 +115,7 @@
 int	 strncmp(const char *, const char *, size_t);
 char	*strncpy(char * __restrict, const char * __restrict, size_t);
 size_t	 strnlen(const char *, size_t);
+char	*strrchr(const char *, int);
 char	*strsep(char **, const char *delim);
 size_t	 strspn(const char *, const char *);
 char	*strstr(const char *, const char *);
@@ -164,15 +164,17 @@
 #endif
 
 static __inline char *
-strchr(const char *p, int ch)
+index(const char *p, int ch)
 {
-	return (index(p, ch));
+
+	return (strchr(p, ch));
 }
 
 static __inline char *
-strrchr(const char *p, int ch)
+rindex(const char *p, int ch)
 {
-	return (rindex(p, ch));
+
+	return (strrchr(p, ch));
 }
 
 /* fnmatch() return values. */
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/sys/param.h
--- a/head/sys/sys/param.h	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/sys/param.h	Thu Jan 05 13:30:52 2012 +0200
@@ -32,7 +32,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)param.h	8.3 (Berkeley) 4/4/95
- * $FreeBSD: head/sys/sys/param.h 228571 2011-12-16 12:16:56Z glebius $
+ * $FreeBSD: head/sys/sys/param.h 229204 2012-01-01 20:54:44Z ed $
  */
 
 #ifndef _SYS_PARAM_H_
@@ -58,7 +58,7 @@
  *		in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1000003	/* Master, propagated to newvers */
+#define __FreeBSD_version 1000004	/* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/ufs/ffs/ffs_alloc.c
--- a/head/sys/ufs/ffs/ffs_alloc.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/ufs/ffs/ffs_alloc.c	Thu Jan 05 13:30:52 2012 +0200
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/ufs/ffs/ffs_alloc.c 224876 2011-08-15 07:32:44Z rwatson $");
+__FBSDID("$FreeBSD: head/sys/ufs/ffs/ffs_alloc.c 229200 2012-01-01 20:47:33Z ed $");
 
 #include "opt_quota.h"
 
@@ -1745,9 +1745,9 @@
 	struct cg *cgp;
 	struct buf *bp, *ibp;
 	struct ufsmount *ump;
-	u_int8_t *inosused;
+	u_int8_t *inosused, *loc;
 	struct ufs2_dinode *dp2;
-	int error, start, len, loc, map, i;
+	int error, start, len, i;
 
 	fs = ip->i_fs;
 	ump = ip->i_ump;
@@ -1777,25 +1777,19 @@
 	}
 	start = cgp->cg_irotor / NBBY;
 	len = howmany(fs->fs_ipg - cgp->cg_irotor, NBBY);
-	loc = skpc(0xff, len, &inosused[start]);
-	if (loc == 0) {
+	loc = memcchr(&inosused[start], 0xff, len);
+	if (loc == NULL) {
 		len = start + 1;
 		start = 0;
-		loc = skpc(0xff, len, &inosused[0]);
-		if (loc == 0) {
+		loc = memcchr(&inosused[start], 0xff, len);
+		if (loc == NULL) {
 			printf("cg = %d, irotor = %ld, fs = %s\n",
 			    cg, (long)cgp->cg_irotor, fs->fs_fsmnt);
 			panic("ffs_nodealloccg: map corrupted");
 			/* NOTREACHED */
 		}
 	}
-	i = start + len - loc;
-	map = inosused[i] ^ 0xff;
-	if (map == 0) {
-		printf("fs = %s\n", fs->fs_fsmnt);
-		panic("ffs_nodealloccg: block not in map");
-	}
-	ipref = i * NBBY + ffs(map) - 1;
+	ipref = (loc - inosused) * NBBY + ffs(~*loc) - 1;
 	cgp->cg_irotor = ipref;
 gotit:
 	/*
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/vm/vm_object.c
--- a/head/sys/vm/vm_object.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/vm/vm_object.c	Thu Jan 05 13:30:52 2012 +0200
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/vm/vm_object.c 228936 2011-12-28 20:27:18Z alc $");
+__FBSDID("$FreeBSD: head/sys/vm/vm_object.c 229495 2012-01-04 16:04:20Z kib $");
 
 #include "opt_vm.h"
 
@@ -841,8 +841,12 @@
 		if (p->valid == 0)
 			continue;
 		if (vm_page_sleep_if_busy(p, TRUE, "vpcwai")) {
-			if (object->generation != curgeneration)
-				goto rescan;
+			if (object->generation != curgeneration) {
+				if ((flags & OBJPC_SYNC) != 0)
+					goto rescan;
+				else
+					clearobjflags = 0;
+			}
 			np = vm_page_find_least(object, pi);
 			continue;
 		}
@@ -851,8 +855,12 @@
 
 		n = vm_object_page_collect_flush(object, p, pagerflags,
 		    flags, &clearobjflags);
-		if (object->generation != curgeneration)
-			goto rescan;
+		if (object->generation != curgeneration) {
+			if ((flags & OBJPC_SYNC) != 0)
+				goto rescan;
+			else
+				clearobjflags = 0;
+		}
 
 		/*
 		 * If the VOP_PUTPAGES() did a truncated write, so
diff -r 9f40516392fd -r 77905f94b3a7 head/sys/x86/acpica/srat.c
--- a/head/sys/x86/acpica/srat.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/sys/x86/acpica/srat.c	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/x86/acpica/srat.c 226039 2011-10-05 16:03:47Z jhb $");
+__FBSDID("$FreeBSD: head/sys/x86/acpica/srat.c 229427 2012-01-03 20:53:58Z jhb $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -45,6 +45,7 @@
 
 #include <dev/acpica/acpivar.h>
 
+#if VM_NDOMAIN > 1
 struct cpu_info {
 	int enabled:1;
 	int has_memory:1;
@@ -237,9 +238,9 @@
 
 /*
  * Renumber the memory domains to be compact and zero-based if not
- * already.
+ * already.  Returns an error if there are too many domains.
  */
-static void
+static int
 renumber_domains(void)
 {
 	int domains[VM_PHYSSEG_MAX];
@@ -261,6 +262,11 @@
 		for (j = ndomain; j > slot; j--)
 			domains[j] = domains[j - 1];
 		domains[slot] = mem_info[i].domain;
+		ndomain++;
+		if (ndomain > VM_NDOMAIN) {
+			printf("SRAT: Too many memory domains\n");
+			return (EFBIG);
+		}
 	}
 
 	/* Renumber each domain to its index in the sorted 'domains' list. */
@@ -280,6 +286,7 @@
 			if (cpus[j].enabled && cpus[j].domain == domains[i])
 				cpus[j].domain = i;
 	}
+	return (0);
 }
 
 /*
@@ -306,13 +313,12 @@
 	srat_walk_table(srat_parse_entry, &error);
 	acpi_unmap_table(srat);
 	srat = NULL;
-	if (error || check_domains() != 0 || check_phys_avail() != 0) {
+	if (error || check_domains() != 0 || check_phys_avail() != 0 ||
+	    renumber_domains() != 0) {
 		srat_physaddr = 0;
 		return;
 	}
 
-	renumber_domains();
-
 	/* Point vm_phys at our memory affinity table. */
 	mem_affinity = mem_info;
 }
@@ -354,3 +360,4 @@
 	}
 }
 SYSINIT(srat_set_cpus, SI_SUB_CPU, SI_ORDER_ANY, srat_set_cpus, NULL);
+#endif /* VM_NDOMAIN > 1 */
diff -r 9f40516392fd -r 77905f94b3a7 head/tools/build/options/WITHOUT_CAPSICUM
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/build/options/WITHOUT_CAPSICUM	Thu Jan 05 13:30:52 2012 +0200
@@ -0,0 +1,2 @@
+.\" $FreeBSD: head/tools/build/options/WITHOUT_CAPSICUM 229319 2012-01-02 21:57:58Z rwatson $
+Set to not build Capsicum support into system programs.
diff -r 9f40516392fd -r 77905f94b3a7 head/tools/tools/net80211/wesside/wesside/wesside.c
--- a/head/tools/tools/net80211/wesside/wesside/wesside.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/tools/tools/net80211/wesside/wesside/wesside.c	Thu Jan 05 13:30:52 2012 +0200
@@ -5,7 +5,7 @@
  * XXX GENERAL: I DON'T CHECK FOR PACKET LENGTHS AND STUFF LIKE THAT and buffer
  * overflows.  this whole thing is experimental n e way.
  *
- * $FreeBSD$
+ * $FreeBSD: head/tools/tools/net80211/wesside/wesside/wesside.c 229436 2012-01-03 22:52:29Z pjd $
  */
 
 #include <sys/types.h>
@@ -2091,7 +2091,7 @@
 			strcat(k, ":");
 	}
 
-	fd = open(KEY_FILE, O_WRONLY | O_CREAT | 0644);
+	fd = open(KEY_FILE, O_WRONLY | O_CREAT, 0644);
 	if (fd == -1)
 		err(1, "open()");
 
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/cksum/cksum.c
--- a/head/usr.bin/cksum/cksum.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/cksum/cksum.c	Thu Jan 05 13:30:52 2012 +0200
@@ -43,7 +43,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/cksum/cksum.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 
@@ -68,7 +68,7 @@
 	int (*cfncn)(int, uint32_t *, off_t *);
 	void (*pfncn)(char *, uint32_t, off_t);
 
-	if ((p = rindex(argv[0], '/')) == NULL)
+	if ((p = strrchr(argv[0], '/')) == NULL)
 		p = argv[0];
 	else
 		++p;
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/compress/compress.c
--- a/head/usr.bin/compress/compress.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/compress/compress.c	Thu Jan 05 13:30:52 2012 +0200
@@ -40,7 +40,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/compress/compress.c 227236 2011-11-06 18:49:16Z ed $");
+__FBSDID("$FreeBSD: head/usr.bin/compress/compress.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -75,7 +75,7 @@
 	char *p, newname[MAXPATHLEN];
 
 	cat = 0;
-	if ((p = rindex(argv[0], '/')) == NULL)
+	if ((p = strrchr(argv[0], '/')) == NULL)
 		p = argv[0];
 	else
 		++p;
@@ -141,7 +141,7 @@
 				compress(*argv, "/dev/stdout", bits);
 				break;
 			}
-			if ((p = rindex(*argv, '.')) != NULL &&
+			if ((p = strrchr(*argv, '.')) != NULL &&
 			    !strcmp(p, ".Z")) {
 				cwarnx("%s: name already has trailing .Z",
 				    *argv);
@@ -164,7 +164,7 @@
 				break;
 			}
 			len = strlen(*argv);
-			if ((p = rindex(*argv, '.')) == NULL ||
+			if ((p = strrchr(*argv, '.')) == NULL ||
 			    strcmp(p, ".Z")) {
 				if (len > sizeof(newname) - 3) {
 					cwarnx("%s: name too long", *argv);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/finger/finger.c
--- a/head/usr.bin/finger/finger.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/finger/finger.c	Thu Jan 05 13:30:52 2012 +0200
@@ -53,7 +53,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/finger/finger.c 228992 2011-12-30 11:02:40Z uqs $");
+__FBSDID("$FreeBSD: head/usr.bin/finger/finger.c 229403 2012-01-03 18:51:58Z ed $");
 
 /*
  * Finger prints out information about users.  It is not portable since
@@ -287,7 +287,7 @@
 
 	/* Pull out all network requests. */
 	for (ap = p = argv, np = nargv; *p; ++p)
-		if (index(*p, '@'))
+		if (strchr(*p, '@'))
 			*np++ = *p;
 		else
 			*ap++ = *p;
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/hexdump/display.c
--- a/head/usr.bin/hexdump/display.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/hexdump/display.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/hexdump/display.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -220,7 +220,7 @@
 	pr->cchar[0] = 's';
 	pr->cchar[1] = '\0';
 	for (p1 = pr->fmt; *p1 != '%'; ++p1);
-	for (p2 = ++p1; *p1 && index(spec, *p1); ++p1);
+	for (p2 = ++p1; *p1 && strchr(spec, *p1); ++p1);
 	while ((*p2++ = *p1++));
 }
 
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/hexdump/hexdump.c
--- a/head/usr.bin/hexdump/hexdump.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/hexdump/hexdump.c	Thu Jan 05 13:30:52 2012 +0200
@@ -39,7 +39,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/hexdump/hexdump.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 #include <locale.h>
@@ -61,7 +61,7 @@
 
 	(void)setlocale(LC_ALL, "");
 
-	if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od"))
+	if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od"))
 		newsyntax(argc, &argv);
 	else
 		oldsyntax(argc, &argv);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/hexdump/hexsyntax.c
--- a/head/usr.bin/hexdump/hexsyntax.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/hexdump/hexsyntax.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/hexdump/hexsyntax.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 
@@ -54,7 +54,7 @@
 	char *p, **argv;
 
 	argv = *argvp;
-	if ((p = rindex(argv[0], 'h')) != NULL &&
+	if ((p = strrchr(argv[0], 'h')) != NULL &&
 	    strcmp(p, "hd") == 0) {
 		/* "Canonical" format, implies -C. */
 		add("\"%08.8_Ax\n\"");
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/hexdump/parse.c
--- a/head/usr.bin/hexdump/parse.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/hexdump/parse.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
 #endif
 #endif /* not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/hexdump/parse.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 
@@ -58,7 +58,7 @@
 	if ((fp = fopen(name, "r")) == NULL)
 		err(1, "%s", name);
 	while (fgets(buf, sizeof(buf), fp)) {
-		if (!(p = index(buf, '\n'))) {
+		if (!(p = strchr(buf, '\n'))) {
 			warnx("line too long");
 			while ((ch = getchar()) != '\n' && ch != EOF);
 			continue;
@@ -167,7 +167,7 @@
 			 * skip any special chars -- save precision in
 			 * case it's a %s format.
 			 */
-			while (index(spec + 1, *++fmt));
+			while (strchr(spec + 1, *++fmt));
 			if (*fmt == '.' && isdigit(*++fmt)) {
 				prec = atoi(fmt);
 				while (isdigit(*++fmt));
@@ -243,10 +243,10 @@
 			if (fu->bcnt) {
 				sokay = USEBCNT;
 				/* Skip to conversion character. */
-				for (++p1; index(spec, *p1); ++p1);
+				for (++p1; strchr(spec, *p1); ++p1);
 			} else {
 				/* Skip any special chars, field width. */
-				while (index(spec + 1, *++p1));
+				while (strchr(spec + 1, *++p1));
 				if (*p1 == '.' && isdigit(*++p1)) {
 					sokay = USEPREC;
 					prec = atoi(p1);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/locate/locate/fastfind.c
--- a/head/usr.bin/locate/locate/fastfind.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/locate/locate/fastfind.c	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/usr.bin/locate/locate/fastfind.c 229403 2012-01-03 18:51:58Z ed $
  */
 
 
@@ -167,7 +167,7 @@
 
 	/* find optimal (last) char for searching */
 	for (p = pathpart; *p != '\0'; p++)
-		if (index(LOCATE_REG, *p) != NULL)
+		if (strchr(LOCATE_REG, *p) != NULL)
 			break;
 
 	if (*p == '\0')
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/locate/locate/util.c
--- a/head/usr.bin/locate/locate/util.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/locate/locate/util.c	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: head/usr.bin/locate/locate/util.c 228992 2011-12-30 11:02:40Z uqs $
+ * $FreeBSD: head/usr.bin/locate/locate/util.c 229403 2012-01-03 18:51:58Z ed $
  */
 
 
@@ -162,7 +162,7 @@
 
 	/* skip trailing metacharacters */
 	for (; p >= name; p--)
-		if (index(LOCATE_REG, *p) == NULL)
+		if (strchr(LOCATE_REG, *p) == NULL)
 			break;
 
 	/* 
@@ -172,7 +172,7 @@
 	 *        |----< p
 	 */
 	if (p >= name && 
-	    (index(p, '[') != NULL || index(p, ']') != NULL)) {
+	    (strchr(p, '[') != NULL || strchr(p, ']') != NULL)) {
 		for (p = name; *p != '\0'; p++)
 			if (*p == ']' || *p == '[')
 				break;
@@ -183,7 +183,7 @@
 		 * '*\*[a-z]'
 		 *    |-------< p
 		 */
-		if (p >= name && index(LOCATE_REG, *p) != NULL)
+		if (p >= name && strchr(LOCATE_REG, *p) != NULL)
 			p = name - 1;
 	}
 	
@@ -193,7 +193,7 @@
 
 	else {
 		for (endmark = p; p >= name; p--)
-			if (index(LOCATE_REG, *p) != NULL)
+			if (strchr(LOCATE_REG, *p) != NULL)
 				break;
 		for (++p;
 		    (p <= endmark) && subp < (globfree + sizeof(globfree));)
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/mkulzma/Makefile
--- a/head/usr.bin/mkulzma/Makefile	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/mkulzma/Makefile	Thu Jan 05 13:30:52 2012 +0200
@@ -1,4 +1,4 @@
-# $FreeBSD$
+# $FreeBSD: head/usr.bin/mkulzma/Makefile 229538 2012-01-04 23:45:10Z ray $
 
 PROG=	mkulzma
 MAN=	mkulzma.8
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/mkulzma/mkulzma.8
--- a/head/usr.bin/mkulzma/mkulzma.8	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/mkulzma/mkulzma.8	Thu Jan 05 13:30:52 2012 +0200
@@ -7,7 +7,7 @@
 .\" this stuff is worth it, you can buy me a beer in return.       Maxim Sobolev
 .\" ----------------------------------------------------------------------------
 .\"
-.\" $FreeBSD$
+.\" $FreeBSD: head/usr.bin/mkulzma/mkulzma.8 229538 2012-01-04 23:45:10Z ray $
 .\"
 .Dd March 17, 2006
 .Dt mkulzma 8
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/mkulzma/mkulzma.c
--- a/head/usr.bin/mkulzma/mkulzma.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/mkulzma/mkulzma.c	Thu Jan 05 13:30:52 2012 +0200
@@ -8,11 +8,10 @@
  * this stuff is worth it, you can buy me a beer in return.       Maxim Sobolev
  * ----------------------------------------------------------------------------
  *
- * $FreeBSD$
+ * $FreeBSD: head/usr.bin/mkulzma/mkulzma.c 229538 2012-01-04 23:45:10Z ray $
  *
  */
 
-#include <sys/types.h>
 #include <sys/disk.h>
 #include <sys/endian.h>
 #include <sys/param.h>
@@ -21,7 +20,6 @@
 #include <netinet/in.h>
 #include <err.h>
 #include <fcntl.h>
-#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -29,13 +27,11 @@
 
 #include <lzma.h>
 
-
 #define CLSTSIZE	16384
 #define DEFAULT_SUFX	".ulzma"
 
 #define USED_BLOCKSIZE DEV_BSIZE
 
-
 #define CLOOP_MAGIC_LEN 128
 /* Format L3.0, since we move to XZ API */
 static char CLOOP_MAGIC_START[] =
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/netstat/if.c
--- a/head/usr.bin/netstat/if.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/netstat/if.c	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/netstat/if.c 223947 2011-07-12 11:47:08Z tuexen $");
+__FBSDID("$FreeBSD: head/usr.bin/netstat/if.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 #include <sys/protosw.h>
@@ -256,7 +256,7 @@
 			ifnetaddr = (u_long)TAILQ_NEXT(&ifnet, if_link);
 			if (interface != 0 && strcmp(name, interface) != 0)
 				continue;
-			cp = index(name, '\0');
+			cp = strchr(name, '\0');
 
 			if (pfunc) {
 				(*pfunc)(name);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/netstat/inet.c
--- a/head/usr.bin/netstat/inet.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/netstat/inet.c	Thu Jan 05 13:30:52 2012 +0200
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/netstat/inet.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -1247,7 +1247,7 @@
 	    sprintf(line, "%s.", inetname(in));
 	else
 	    sprintf(line, "%.*s.", (Aflag && !num_port) ? 12 : 16, inetname(in));
-	cp = index(line, '\0');
+	cp = strchr(line, '\0');
 	if (!num_port && port)
 		sp = getservbyport((int)port, proto);
 	if (sp || port == 0)
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/netstat/inet6.c
--- a/head/usr.bin/netstat/inet6.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/netstat/inet6.c	Thu Jan 05 13:30:52 2012 +0200
@@ -35,7 +35,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/netstat/inet6.c 228700 2011-12-19 05:50:34Z maxim $");
+__FBSDID("$FreeBSD: head/usr.bin/netstat/inet6.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifdef INET6
 #include <sys/param.h>
@@ -1100,7 +1100,7 @@
 
 	sprintf(line, "%.*s.", Wflag ? 39 :
 		(Aflag && !numeric) ? 12 : 16, inet6name(in6));
-	cp = index(line, '\0');
+	cp = strchr(line, '\0');
 	if (!numeric && port)
 		GETSERVBYPORT6(port, proto, sp);
 	if (sp || port == 0)
@@ -1129,7 +1129,7 @@
 	if (first && !numeric_addr) {
 		first = 0;
 		if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
-		    (cp = index(domain, '.')))
+		    (cp = strchr(domain, '.')))
 			(void) strcpy(domain, cp + 1);
 		else
 			domain[0] = 0;
@@ -1138,7 +1138,7 @@
 	if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
 		hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
 		if (hp) {
-			if ((cp = index(hp->h_name, '.')) &&
+			if ((cp = strchr(hp->h_name, '.')) &&
 			    !strcmp(cp + 1, domain))
 				*cp = 0;
 			cp = hp->h_name;
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/netstat/sctp.c
--- a/head/usr.bin/netstat/sctp.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/netstat/sctp.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/netstat/sctp.c 224271 2011-07-22 16:42:12Z tuexen $");
+__FBSDID("$FreeBSD: head/usr.bin/netstat/sctp.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -162,7 +162,7 @@
 	if (first && !numeric_addr) {
 		first = 0;
 		if (gethostname(domain, MAXHOSTNAMELEN) == 0 &&
-		    (cp = index(domain, '.')))
+		    (cp = strchr(domain, '.')))
 			(void) strcpy(domain, cp + 1);
 		else
 			domain[0] = 0;
@@ -171,7 +171,7 @@
 	if (!numeric_addr && !IN6_IS_ADDR_UNSPECIFIED(in6p)) {
 		hp = gethostbyaddr((char *)in6p, sizeof(*in6p), AF_INET6);
 		if (hp) {
-			if ((cp = index(hp->h_name, '.')) &&
+			if ((cp = strchr(hp->h_name, '.')) &&
 			    !strcmp(cp + 1, domain))
 				*cp = 0;
 			cp = hp->h_name;
@@ -209,7 +209,7 @@
 		sprintf(line, "%.*s.", Wflag ? 39 : 16, "");
 		break;
 	}
-	cp = index(line, '\0');
+	cp = strchr(line, '\0');
 	if (!num_port && port)
 		sp = getservbyport((int)port, "sctp");
 	if (sp || port == 0)
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/rlogin/rlogin.c
--- a/head/usr.bin/rlogin/rlogin.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/rlogin/rlogin.c	Thu Jan 05 13:30:52 2012 +0200
@@ -51,7 +51,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/rlogin/rlogin.c 221079 2011-04-26 20:14:29Z jhb $");
+__FBSDID("$FreeBSD: head/usr.bin/rlogin/rlogin.c 229403 2012-01-03 18:51:58Z ed $");
 
 /*
  * rlogin - remote login
@@ -142,7 +142,7 @@
 	one = 1;
 	host = localname = user = NULL;
 
-	if ((p = rindex(argv[0], '/')))
+	if ((p = strrchr(argv[0], '/')))
 		++p;
 	else
 		p = argv[0];
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/rpcgen/rpc_main.c
--- a/head/usr.bin/rpcgen/rpc_main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/rpcgen/rpc_main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -36,7 +36,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_main.c 229403 2012-01-03 18:51:58Z ed $");
 
 /*
  * rpc_main.c, Top level of the RPC protocol compiler.
@@ -64,10 +64,6 @@
 static char *generate_guard(const char *);
 static void c_initialize(void);
 
-#if !defined(__FreeBSD__) && !defined(__NetBSD__)
-char * rindex();
-#endif
-
 static void usage(void);
 static void options_usage(void);
 static int do_registers(int, const char **);
@@ -233,7 +229,7 @@
 	const char *p;
 	const char *file;
 
-	if ((file = rindex(path, '/')) == NULL)
+	if ((file = strrchr(path, '/')) == NULL)
 		file = path;
 	else
 		file++;
@@ -821,7 +817,7 @@
 	if (allfiles){
 		mkftemp = xmalloc(strlen("makefile.") +
 		                     strlen(cmd->infile) + 1);
-		temp = (char *)rindex(cmd->infile, '.');
+		temp = strrchr(cmd->infile, '.');
 		strcpy(mkftemp, "makefile.");
 		(void) strncat(mkftemp, cmd->infile,
 			(temp - cmd->infile));
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/systat/devs.c
--- a/head/usr.bin/systat/devs.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/systat/devs.c	Thu Jan 05 13:30:52 2012 +0200
@@ -56,7 +56,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD: head/usr.bin/systat/devs.c 226396 2011-10-15 13:20:36Z ed $");
+__FBSDID("$FreeBSD: head/usr.bin/systat/devs.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifdef lint
 static const char sccsid[] = "@(#)disks.c	8.1 (Berkeley) 6/6/93";
@@ -265,7 +265,7 @@
 	specified_devices = (char **)malloc(sizeof(char *));
 
 	tmpstr = tmpstr1 = strdup(args);
-	cp = index(tmpstr1, '\n');
+	cp = strchr(tmpstr1, '\n');
 	if (cp)
 		*cp = '\0';
 	for (;;) {
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/systat/netcmds.c
--- a/head/usr.bin/systat/netcmds.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/systat/netcmds.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/systat/netcmds.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifdef lint
 static const char sccsid[] = "@(#)netcmds.c	8.1 (Berkeley) 6/6/93";
@@ -131,7 +131,7 @@
 	struct in_addr in;
 
 	tmpstr = tmpstr1 = strdup(args);
-	cp = index(tmpstr1, '\n');
+	cp = strchr(tmpstr1, '\n');
 	if (cp)
 		*cp = '\0';
 	for (;;tmpstr1 = cp) {
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/systat/netstat.c
--- a/head/usr.bin/systat/netstat.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/systat/netstat.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD: head/usr.bin/systat/netstat.c 226396 2011-10-15 13:20:36Z ed $");
+__FBSDID("$FreeBSD: head/usr.bin/systat/netstat.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifdef lint
 static const char sccsid[] = "@(#)netstat.c	8.1 (Berkeley) 6/6/93";
@@ -554,7 +554,7 @@
 		break;
 	}
 	snprintf(line, sizeof(line), "%.*s.", 16, inetname(sa));
-	cp = index(line, '\0');
+	cp = strchr(line, '\0');
 	if (!nflag && port)
 		sp = getservbyport(port, proto);
 	if (sp || port == 0)
@@ -564,7 +564,7 @@
 		snprintf(cp, sizeof(line) - (cp - line), "%d",
 		    ntohs((u_short)port));
 	/* pad to full column to clear any garbage */
-	cp = index(line, '\0');
+	cp = strchr(line, '\0');
 	while (cp - line < 22)
 		*cp++ = ' ';
 	line[22] = '\0';
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/talk/get_names.c
--- a/head/usr.bin/talk/get_names.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/talk/get_names.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/talk/get_names.c 229386 2012-01-03 11:13:07Z ed $");
 
 #ifndef lint
 static const char sccsid[] = "@(#)get_names.c	8.1 (Berkeley) 6/6/93";
@@ -80,8 +80,7 @@
 	gethostname(hostname, sizeof (hostname));
 	my_machine_name = hostname;
 	/* check for, and strip out, the machine name of the target */
-	for (cp = argv[1]; *cp && !index("@:!", *cp); cp++)
-		;
+	cp = argv[1] + strcspn(argv[1], "@:!");
 	if (*cp == '\0') {
 		/* this is a local to local talk */
 		his_name = argv[1];
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/tftp/main.c
--- a/head/usr.bin/tftp/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/tftp/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -40,7 +40,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.bin/tftp/main.c 223926 2011-07-11 05:57:49Z delphij $");
+__FBSDID("$FreeBSD: head/usr.bin/tftp/main.c 229403 2012-01-03 18:51:58Z ed $");
 
 /* Many bug fixes are from Jim Guyton <guyton at rand-unix> */
 
@@ -437,16 +437,16 @@
 		return;
 	}
 	targ = argv[argc - 1];
-	if (rindex(argv[argc - 1], ':')) {
+	if (strrchr(argv[argc - 1], ':')) {
 		char *lcp;
 
 		for (n = 1; n < argc - 1; n++)
-			if (index(argv[n], ':')) {
+			if (strchr(argv[n], ':')) {
 				putusage(argv[0]);
 				return;
 			}
 		lcp = argv[argc - 1];
-		targ = rindex(lcp, ':');
+		targ = strrchr(lcp, ':');
 		*targ++ = 0;
 		if (lcp[0] == '[' && lcp[strlen(lcp) - 1] == ']') {
 			lcp[strlen(lcp) - 1] = '\0';
@@ -477,7 +477,7 @@
 	}
 				/* this assumes the target is a directory */
 				/* on a remote unix system.  hmmmm.  */
-	cp = index(targ, '\0');
+	cp = strchr(targ, '\0');
 	*cp++ = '/';
 	for (n = 1; n < argc - 1; n++) {
 		strcpy(cp, tail(argv[n]));
@@ -532,7 +532,7 @@
 	}
 	if (!connected) {
 		for (n = 1; n < argc ; n++)
-			if (rindex(argv[n], ':') == 0) {
+			if (strrchr(argv[n], ':') == 0) {
 				printf("No remote host specified and "
 				    "no host given for file '%s'\n", argv[n]);
 				getusage(argv[0]);
@@ -540,7 +540,7 @@
 			}
 	}
 	for (n = 1; n < argc ; n++) {
-		src = rindex(argv[n], ':');
+		src = strrchr(argv[n], ':');
 		if (src == NULL)
 			src = argv[n];
 		else {
@@ -681,7 +681,7 @@
 	char *s;
 
 	while (*filename) {
-		s = rindex(filename, '/');
+		s = strrchr(filename, '/');
 		if (s == NULL)
 			break;
 		if (s[1])
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/tr/str.c
--- a/head/usr.bin/tr/str.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/tr/str.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD: head/usr.bin/tr/str.c 226360 2011-10-14 07:25:20Z ed $");
+__FBSDID("$FreeBSD: head/usr.bin/tr/str.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifndef lint
 static const char sccsid[] = "@(#)str.c	8.2 (Berkeley) 4/28/95";
@@ -161,7 +161,7 @@
 	repeat:
 		if ((p = strpbrk(s->str + 2, "*]")) == NULL)
 			return (0);
-		if (p[0] != '*' || index(p, ']') == NULL)
+		if (p[0] != '*' || strchr(p, ']') == NULL)
 			return (0);
 		s->str += 1;
 		genseq(s);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/tset/map.c
--- a/head/usr.bin/tset/map.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/tset/map.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/tset/map.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifndef lint
 static const char sccsid[] = "@(#)map.c	8.1 (Berkeley) 6/9/93";
@@ -132,7 +132,7 @@
 			goto badmopt;
 		++arg;
 	} else {				/* Optional baudrate. */
-		arg = index(p = arg, ':');
+		arg = strchr(p = arg, ':');
 		if (arg == NULL)
 			goto badmopt;
 		*arg++ = '\0';
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/tset/term.c
--- a/head/usr.bin/tset/term.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/tset/term.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/tset/term.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifndef lint
 static const char sccsid[] = "@(#)term.c	8.1 (Berkeley) 6/9/93";
@@ -74,7 +74,7 @@
 
 	/* Try ttyname(3); check for dialup or other mapping. */
 	if ((ttypath = ttyname(STDERR_FILENO))) {
-		if ((p = rindex(ttypath, '/')))
+		if ((p = strrchr(ttypath, '/')))
 			++p;
 		else
 			p = ttypath;
@@ -146,7 +146,7 @@
 			return (dflt);
 		}
 
-		if ((p = index(answer, '\n')))
+		if ((p = strchr(answer, '\n')))
 			*p = '\0';
 		if (answer[0])
 			return (answer);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.bin/tset/wrterm.c
--- a/head/usr.bin/tset/wrterm.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.bin/tset/wrterm.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.bin/tset/wrterm.c 229403 2012-01-03 18:51:58Z ed $");
 
 #ifndef lint
 static const char sccsid[] = "@(#)wrterm.c	8.1 (Berkeley) 6/9/93";
@@ -56,7 +56,7 @@
 	char *t, *sep;
 
 	/* Find the end of the terminal names. */
-	if ((t = index(bp, ':')) == NULL)
+	if ((t = strchr(bp, ':')) == NULL)
 		errx(1, "termcap names not colon terminated");
 	*t++ = '\0';
 
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/bootparamd/bootparamd/bootparamd.c
--- a/head/usr.sbin/bootparamd/bootparamd/bootparamd.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/bootparamd/bootparamd/bootparamd.c	Thu Jan 05 13:30:52 2012 +0200
@@ -9,7 +9,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-  "$FreeBSD$";
+  "$FreeBSD: head/usr.sbin/bootparamd/bootparamd/bootparamd.c 229403 2012-01-03 18:51:58Z ed $";
 #endif /* not lint */
 
 #ifdef YP
@@ -114,7 +114,7 @@
 bp_getfile_arg *getfile;
 struct svc_req *req;
 {
-  char *where, *index();
+  char *where;
   static bp_getfile_res res;
 
   if (debug)
@@ -133,7 +133,7 @@
   askname[sizeof(askname)-1] = 0;
 
   if (getthefile(askname, getfile->file_id,buffer,sizeof(buffer))) {
-    if ( (where = index(buffer,':')) ) {
+    if ( (where = strchr(buffer,':')) ) {
       /* buffer is re-written to contain the name of the info of file */
       strncpy(hostname, buffer, where - buffer);
       hostname[where - buffer] = '\0';
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c
--- a/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c	Thu Jan 05 13:30:52 2012 +0200
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c 229385 2012-01-03 11:10:15Z ed $
  */
 
 #include <sys/param.h> 
@@ -469,7 +469,7 @@
 static int32_t
 snmp_index_insert(struct snmp_idxlist *headp, struct index *idx)
 {
-	if (headp == NULL || index == NULL)
+	if (headp == NULL || idx == NULL)
 		return (-1);
 
 	STAILQ_INSERT_TAIL(headp, idx, link);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/config/main.c
--- a/head/usr.sbin/config/main.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/config/main.c	Thu Jan 05 13:30:52 2012 +0200
@@ -38,7 +38,7 @@
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: head/usr.sbin/config/main.c 223744 2011-07-03 20:59:57Z ed $";
+  "$FreeBSD: head/usr.sbin/config/main.c 229403 2012-01-03 18:51:58Z ed $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -626,7 +626,7 @@
 	else
 		s = ns(file);
 
-	if (index(s, '_') && strncmp(s, "opt_", 4) != 0) {
+	if (strchr(s, '_') && strncmp(s, "opt_", 4) != 0) {
 		free(s);
 		return;
 	}
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/config/mkmakefile.c
--- a/head/usr.sbin/config/mkmakefile.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/config/mkmakefile.c	Thu Jan 05 13:30:52 2012 +0200
@@ -32,7 +32,7 @@
 static char sccsid[] = "@(#)mkmakefile.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: head/usr.sbin/config/mkmakefile.c 228153 2011-11-30 13:33:09Z fjoe $";
+  "$FreeBSD: head/usr.sbin/config/mkmakefile.c 229403 2012-01-03 18:51:58Z ed $";
 #endif /* not lint */
 
 /*
@@ -207,12 +207,12 @@
 			err(1, "%s", hint->hint_name);
 		while (fgets(line, BUFSIZ, ifp) != 0) {
 			/* zap trailing CR and/or LF */
-			while ((s = rindex(line, '\n')) != NULL)
+			while ((s = strrchr(line, '\n')) != NULL)
 				*s = '\0';
-			while ((s = rindex(line, '\r')) != NULL)
+			while ((s = strrchr(line, '\r')) != NULL)
 				*s = '\0';
 			/* remove # comments */
-			s = index(line, '#');
+			s = strchr(line, '#');
 			if (s)
 				*s = '\0';
 			/* remove any whitespace and " characters */
@@ -269,12 +269,12 @@
 	if (ifp) {
 		while (fgets(line, BUFSIZ, ifp) != 0) {
 			/* zap trailing CR and/or LF */
-			while ((s = rindex(line, '\n')) != NULL)
+			while ((s = strrchr(line, '\n')) != NULL)
 				*s = '\0';
-			while ((s = rindex(line, '\r')) != NULL)
+			while ((s = strrchr(line, '\r')) != NULL)
 				*s = '\0';
 			/* remove # comments */
-			s = index(line, '#');
+			s = strchr(line, '#');
 			if (s)
 				*s = '\0';
 			/* remove any whitespace and " characters */
@@ -690,7 +690,7 @@
 {
 	char *cp;
 
-	cp = rindex(fn, '/');
+	cp = strrchr(fn, '/');
 	if (cp == 0)
 		return (fn);
 	return (cp+1);
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/inetd/inetd.c
--- a/head/usr.sbin/inetd/inetd.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/inetd/inetd.c	Thu Jan 05 13:30:52 2012 +0200
@@ -40,7 +40,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.sbin/inetd/inetd.c 229403 2012-01-03 18:51:58Z ed $");
 
 /*
  * Inetd - Internet super-server
@@ -1764,7 +1764,7 @@
 			sep->se_rpc_lowvers = 0;
 		memcpy(&sep->se_ctrladdr4, bind_sa4,
 		       sizeof(sep->se_ctrladdr4));
-                if ((versp = rindex(sep->se_service, '/'))) {
+                if ((versp = strrchr(sep->se_service, '/'))) {
                         *versp++ = '\0';
                         switch (sscanf(versp, "%u-%u",
                                        &sep->se_rpc_lowvers,
@@ -1936,7 +1936,7 @@
 	} else
 		sep->se_group = NULL;
 	sep->se_server = newstr(sskip(&cp));
-	if ((sep->se_server_name = rindex(sep->se_server, '/')))
+	if ((sep->se_server_name = strrchr(sep->se_server, '/')))
 		sep->se_server_name++;
 	if (strcmp(sep->se_server, "internal") == 0) {
 		struct biltin *bi;
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/ipfwpcap/ipfwpcap.c
--- a/head/usr.sbin/ipfwpcap/ipfwpcap.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/ipfwpcap/ipfwpcap.c	Thu Jan 05 13:30:52 2012 +0200
@@ -21,7 +21,7 @@
  *
  * From: Header: /local/src/local.lib/SRC/ipfwpcap/RCS/ipfwpcap.c,v 1.4 2004/01/15 16:19:07 pkern Exp
  *
- * $FreeBSD$
+ * $FreeBSD: head/usr.sbin/ipfwpcap/ipfwpcap.c 229403 2012-01-03 18:51:58Z ed $
  */
 
 #include <stdio.h>
@@ -87,7 +87,7 @@
 	char *p, numbuf[80];
 
 	if (pidfile[0] == '\0') {
-		p = rindex(prog, '/');
+		p = strrchr(prog, '/');
 		p = (p == NULL) ? prog : p + 1;
 
 		snprintf(pidfile, sizeof pidfile,
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/mptable/mptable.c
--- a/head/usr.sbin/mptable/mptable.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/mptable/mptable.c	Thu Jan 05 13:30:52 2012 +0200
@@ -29,7 +29,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-  "$FreeBSD: head/usr.sbin/mptable/mptable.c 227224 2011-11-06 16:47:50Z ed $";
+  "$FreeBSD: head/usr.sbin/mptable/mptable.c 229466 2012-01-04 07:04:43Z pjd $";
 #endif /* not lint */
 
 /*
@@ -828,7 +828,7 @@
     int		ofd;
     u_char	dumpbuf[ 4096 ];
 
-    ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR );
+    ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
     seekEntry( paddr );
     readEntry( dumpbuf, 1024 );
     write( ofd, dumpbuf, 1024 );
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/mtree/spec.c
--- a/head/usr.sbin/mtree/spec.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/mtree/spec.c	Thu Jan 05 13:30:52 2012 +0200
@@ -33,7 +33,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.sbin/mtree/spec.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -73,7 +73,7 @@
 			continue;
 
 		/* Find end of line. */
-		if ((p = index(buf, '\n')) == NULL)
+		if ((p = strchr(buf, '\n')) == NULL)
 			errx(1, "line %d too long", lineno);
 
 		/* See if next line is continuation line. */
@@ -118,7 +118,7 @@
 				continue;
 			}
 
-		if (index(p, '/'))
+		if (strchr(p, '/'))
 			errx(1, "line %d: slash character in file name",
 			lineno);
 
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/newsyslog/newsyslog.c
--- a/head/usr.sbin/newsyslog/newsyslog.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/newsyslog/newsyslog.c	Thu Jan 05 13:30:52 2012 +0200
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/newsyslog/newsyslog.c 228990 2011-12-30 10:58:14Z uqs $");
+__FBSDID("$FreeBSD: head/usr.sbin/newsyslog/newsyslog.c 229403 2012-01-03 18:51:58Z ed $");
 
 #define	OSF
 
@@ -1710,7 +1710,7 @@
 		} else {	/* relative */
 			/* get directory part of logfile */
 			strlcpy(dirpart, ent->log, sizeof(dirpart));
-			if ((p = rindex(dirpart, '/')) == NULL)
+			if ((p = strrchr(dirpart, '/')) == NULL)
 				dirpart[0] = '\0';
 			else
 				*(p + 1) = '\0';
@@ -1722,7 +1722,7 @@
 			createdir(ent, dirpart);
 
 		/* get filename part of logfile */
-		if ((p = rindex(ent->log, '/')) == NULL)
+		if ((p = strrchr(ent->log, '/')) == NULL)
 			strlcpy(namepart, ent->log, sizeof(namepart));
 		else
 			strlcpy(namepart, p + 1, sizeof(namepart));
@@ -2255,7 +2255,7 @@
 		} else {	/* relative */
 			/* get directory part of logfile */
 			strlcpy(tmp, file, sizeof(tmp));
-			if ((p = rindex(tmp, '/')) == NULL)
+			if ((p = strrchr(tmp, '/')) == NULL)
 				tmp[0] = '\0';
 			else
 				*(p + 1) = '\0';
@@ -2265,7 +2265,7 @@
 		strlcat(tmp, "/", sizeof(tmp));
 
 		/* get filename part of logfile */
-		if ((p = rindex(file, '/')) == NULL)
+		if ((p = strrchr(file, '/')) == NULL)
 			strlcat(tmp, file, sizeof(tmp));
 		else
 			strlcat(tmp, p + 1, sizeof(tmp));
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/quotaon/quotaon.c
--- a/head/usr.sbin/quotaon/quotaon.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/quotaon/quotaon.c	Thu Jan 05 13:30:52 2012 +0200
@@ -42,7 +42,7 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/usr.sbin/quotaon/quotaon.c 229384 2012-01-03 11:08:58Z ed $");
 
 /*
  * Turn quota on/off for a filesystem.
@@ -75,13 +75,11 @@
 main(int argc, char **argv)
 {
 	struct fstab *fs;
-	char *whoami;
+	const char *whoami;
 	long argnum, done = 0;
 	int ch, i, offmode = 0, errs = 0;
 
-	whoami = rindex(*argv, '/') + 1;
-	if (whoami == (char *)1)
-		whoami = *argv;
+	whoami = getprogname();
 	if (strcmp(whoami, "quotaoff") == 0)
 		offmode++;
 	else if (strcmp(whoami, "quotaon") != 0)
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/rwhod/rwhod.c
--- a/head/usr.sbin/rwhod/rwhod.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/rwhod/rwhod.c	Thu Jan 05 13:30:52 2012 +0200
@@ -40,7 +40,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/usr.sbin/rwhod/rwhod.c 220969 2011-04-23 13:42:03Z simon $");
+__FBSDID("$FreeBSD: head/usr.sbin/rwhod/rwhod.c 229403 2012-01-03 18:51:58Z ed $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -227,7 +227,7 @@
 		syslog(LOG_ERR, "gethostname: %m");
 		exit(1);
 	}
-	if ((cp = index(myname, '.')) != NULL)
+	if ((cp = strchr(myname, '.')) != NULL)
 		*cp = '\0';
 	strncpy(mywd.wd_hostname, myname, sizeof(mywd.wd_hostname) - 1);
 	mywd.wd_hostname[sizeof(mywd.wd_hostname) - 1] = '\0';
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/sade/variable.c
--- a/head/usr.sbin/sade/variable.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/sade/variable.c	Thu Jan 05 13:30:52 2012 +0200
@@ -1,5 +1,5 @@
 /*
- * $FreeBSD$
+ * $FreeBSD: head/usr.sbin/sade/variable.c 229403 2012-01-03 18:51:58Z ed $
  *
  * Copyright (c) 1995
  *	Jordan Hubbard.  All rights reserved.
@@ -83,7 +83,7 @@
     else if (!*var)
 	msgDebug("Warning:  Zero length name & value passed to variable_set()\n");
     SAFE_STRCPY(tmp, var);
-    if ((cp = index(tmp, '=')) == NULL)
+    if ((cp = strchr(tmp, '=')) == NULL)
 	msgFatal("Invalid variable format: %s", var);
     *(cp++) = '\0';
     make_variable(tmp, string_skipwhite(cp), dirty);
@@ -123,7 +123,7 @@
     Variable *vp;
     char name[512], *cp;
 
-    if ((cp = index(var, '=')) != NULL)
+    if ((cp = strchr(var, '=')) != NULL)
 	sstrncpy(name, var, cp - var);
     else
 	SAFE_STRCPY(name, var);
@@ -189,14 +189,14 @@
     if (data == NULL)
 	return -1;
     SAFE_STRCPY(tmp, data);
-    if ((cp = index(tmp, '=')) != NULL) {
+    if ((cp = strchr(tmp, '=')) != NULL) {
         *(cp++) = '\0';
 	if (*cp == '"') {	/* smash quotes if present */
 	    ++cp;
-	    if ((cp3 = index(cp, '"')) != NULL)
+	    if ((cp3 = strchr(cp, '"')) != NULL)
 		*cp3 = '\0';
 	}
-	else if ((cp3 = index(cp, ',')) != NULL)
+	else if ((cp3 = strchr(cp, ',')) != NULL)
 	    *cp3 = '\0';
         cp2 = variable_get(tmp);
         if (cp2 != NULL) {
@@ -305,7 +305,7 @@
 	msgDebug("Warning:  Zero length name & value passed to variable_set()\n");
     /* Add a trivial namespace to whatever name the caller chooses. */
     SAFE_STRCPY(tmp, "SYSINSTALL_PVAR");
-    if (index(var, '=') == NULL)
+    if (strchr(var, '=') == NULL)
 	msgFatal("Invalid variable format: %s", var);
     strlcat(tmp, var, 1024); 
     p = strchr(tmp, '=');
diff -r 9f40516392fd -r 77905f94b3a7 head/usr.sbin/uhsoctl/uhsoctl.c
--- a/head/usr.sbin/uhsoctl/uhsoctl.c	Thu Jan 05 12:46:30 2012 +0200
+++ b/head/usr.sbin/uhsoctl/uhsoctl.c	Thu Jan 05 13:30:52 2012 +0200
@@ -22,7 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: head/usr.sbin/uhsoctl/uhsoctl.c 228721 2011-12-19 20:38:26Z dim $
+ * $FreeBSD: head/usr.sbin/uhsoctl/uhsoctl.c 229467 2012-01-04 07:21:37Z pjd $
  */
 
 #include <sys/types.h>
@@ -455,7 +455,7 @@
 		free(ctx->ns);
 	}
 
-	fd = open(respath, O_RDWR | O_CREAT | O_NOFOLLOW);
+	fd = open(respath, O_RDWR | O_CREAT | O_NOFOLLOW, 0666);
 	if (fd < 0)
 		return (-1);
 


More information about the Zrouter-src-freebsd mailing list