Module Name: src Committed By: tls Date: Wed Mar 25 18:41:06 UTC 2009
Modified Files: src/common/dist/zlib: zlib.h src/sys/lib/libkern: crc32.c libkern.h src/sys/lib/libsa: cread.c src/sys/lib/libz: Makefile Log Message: Fix build problems caused by crc32 addition to libkern. Also, this makes the i386 bootblocks about 2K smaller than they were before we monkeyed with crc32 at all. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/common/dist/zlib/zlib.h cvs rdiff -u -r1.1 -r1.2 src/sys/lib/libkern/crc32.c cvs rdiff -u -r1.89 -r1.90 src/sys/lib/libkern/libkern.h cvs rdiff -u -r1.22 -r1.23 src/sys/lib/libsa/cread.c cvs rdiff -u -r1.15 -r1.16 src/sys/lib/libz/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/dist/zlib/zlib.h diff -u src/common/dist/zlib/zlib.h:1.2 src/common/dist/zlib/zlib.h:1.3 --- src/common/dist/zlib/zlib.h:1.2 Mon Jan 16 17:02:29 2006 +++ src/common/dist/zlib/zlib.h Wed Mar 25 18:41:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: zlib.h,v 1.2 2006/01/16 17:02:29 christos Exp $ */ +/* $NetBSD: zlib.h,v 1.3 2009/03/25 18:41:06 tls Exp $ */ /* zlib.h -- interface of the 'zlib' general purpose compression library version 1.2.3, July 18th, 2005 @@ -1284,7 +1284,9 @@ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. */ +#if !defined(_KERNEL) && !defined(_STANDALONE) ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +#endif /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. If buf is NULL, this function returns the required initial Index: src/sys/lib/libkern/crc32.c diff -u src/sys/lib/libkern/crc32.c:1.1 src/sys/lib/libkern/crc32.c:1.2 --- src/sys/lib/libkern/crc32.c:1.1 Wed Mar 25 01:26:13 2009 +++ src/sys/lib/libkern/crc32.c Wed Mar 25 18:41:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: crc32.c,v 1.1 2009/03/25 01:26:13 darran Exp $ */ +/* $NetBSD: crc32.c,v 1.2 2009/03/25 18:41:06 tls Exp $ */ /* crc32.c -- compute the CRC-32 of a data stream * @@ -30,6 +30,7 @@ /* ======================================================================== * Tables of CRC-32s of all single-byte values, made by make_crc_table(). */ +#include <lib/libkern/libkern.h> #include "crc32.h" #if BYTE_ORDER == LITTLE_ENDIAN @@ -40,10 +41,7 @@ #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 /* ========================================================================= */ -uint32_t crc32( - uint32_t crc, - const unsigned char *buf, - unsigned len) +uint32_t crc32(uint32_t crc, const uint8_t *buf, size_t len) { register u4 c; register const u4 *buf4; Index: src/sys/lib/libkern/libkern.h diff -u src/sys/lib/libkern/libkern.h:1.89 src/sys/lib/libkern/libkern.h:1.90 --- src/sys/lib/libkern/libkern.h:1.89 Wed Mar 25 01:26:13 2009 +++ src/sys/lib/libkern/libkern.h Wed Mar 25 18:41:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: libkern.h,v 1.89 2009/03/25 01:26:13 darran Exp $ */ +/* $NetBSD: libkern.h,v 1.90 2009/03/25 18:41:06 tls Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -337,5 +337,5 @@ int snprintb(char *, size_t, const char *, uint64_t); int kheapsort(void *, size_t, size_t, int (*)(const void *, const void *), void *); -uint32_t crc32(uint32_t, const unsigned char *, unsigned); +uint32_t crc32(uint32_t, const uint8_t *, size_t); #endif /* !_LIB_LIBKERN_LIBKERN_H_ */ Index: src/sys/lib/libsa/cread.c diff -u src/sys/lib/libsa/cread.c:1.22 src/sys/lib/libsa/cread.c:1.23 --- src/sys/lib/libsa/cread.c:1.22 Sat Jan 17 14:00:36 2009 +++ src/sys/lib/libsa/cread.c Wed Mar 25 18:41:06 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: cread.c,v 1.22 2009/01/17 14:00:36 tsutsui Exp $ */ +/* $NetBSD: cread.c,v 1.23 2009/03/25 18:41:06 tls Exp $ */ /* * Copyright (c) 1996 @@ -86,6 +86,35 @@ void zcfree(void *, void *); void zmemcpy(unsigned char *, unsigned char *, unsigned int); +/* + * The libkern version of this function uses an 8K set of tables. + * This is the double-loop version of LE CRC32 from if_ethersubr, + * lightly modified -- it is 200 bytes smaller than the version using + * a 4-bit table and at least 8K smaller than the libkern version. + */ +#ifndef ETHER_CRC_POLY_LE +#define ETHER_CRC_POLY_LE 0xedb88320 +#endif +uint32_t +crc32(uint32_t crc, const uint8_t *const buf, size_t len) +{ + uint32_t c, carry; + size_t i, j; + + crc = 0xffffffffU ^ crc; + for (i = 0; i < len; i++) { + c = buf[i]; + for (j = 0; j < 8; j++) { + carry = ((crc & 0x01) ? 1 : 0) ^ (c & 0x01); + crc >>= 1; + c >>= 1; + if (carry) { + crc = (crc ^ ETHER_CRC_POLY_LE); + } + } + } + return (crc ^ 0xffffffffU); +} /* * compression utilities Index: src/sys/lib/libz/Makefile diff -u src/sys/lib/libz/Makefile:1.15 src/sys/lib/libz/Makefile:1.16 --- src/sys/lib/libz/Makefile:1.15 Sat Jun 23 10:50:24 2007 +++ src/sys/lib/libz/Makefile Wed Mar 25 18:41:06 2009 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.15 2007/06/23 10:50:24 isaki Exp $ +# $NetBSD: Makefile,v 1.16 2009/03/25 18:41:06 tls Exp $ LIB= z NOPIC= # defined @@ -11,9 +11,9 @@ .PATH.c: ${ZDISTDIR} ${.PARSEDIR} # files to be copied down from libz. -LIBZSRCS= adler32.c compress.c crc32.c deflate.c infback.c inffast.c \ +LIBZSRCS= adler32.c compress.c deflate.c infback.c inffast.c \ inflate.c inftrees.c trees.c uncompr.c -LIBZHDRS= crc32.h deflate.h inffast.h inffixed.h inflate.h inftrees.h \ +LIBZHDRS= deflate.h inffast.h inffixed.h inflate.h inftrees.h \ trees.h zconf.h zlib.h # Other stuff