BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / vax / vax / in_cksum.c
index 6f912ac..7462c4e 100644 (file)
@@ -1,12 +1,44 @@
-/*     in_cksum.c      1.16    82/10/31        */
+/*
+ * Copyright (c) 1982, 1986 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 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.
+ *
+ *     @(#)in_cksum.c  7.6 (Berkeley) 12/16/90
+ */
 
 
-#include <sys/types.h>
-#include "../h/mbuf.h"
-#include "../netinet/in.h"
-#include "../netinet/in_systm.h"
+#include "sys/param.h"
+#include "sys/mbuf.h"
 
 /*
 
 /*
- * Checksum routine for Internet Protocol family headers.
+ * Checksum routine for Internet Protocol family headers (VAX Version).
+ *
  * This routine is very heavily used in the network
  * code and should be modified for each CPU to be as fast as possible.
  */
  * This routine is very heavily used in the network
  * code and should be modified for each CPU to be as fast as possible.
  */
@@ -32,12 +64,7 @@ in_cksum(m, len)
                         * about a carry-out here because we make sure
                         * that high part of (32 bit) sum is small below.
                         */
                         * about a carry-out here because we make sure
                         * that high part of (32 bit) sum is small below.
                         */
-#ifdef sun
-                       sum += *(u_char *)w;
-#endif
-#ifdef vax
                        sum += *(u_char *)w << 8;
                        sum += *(u_char *)w << 8;
-#endif
                        w = (u_short *)((char *)w + 1);
                        mlen = m->m_len - 1;
                        len--;
                        w = (u_short *)((char *)w + 1);
                        mlen = m->m_len - 1;
                        len--;
@@ -47,11 +74,6 @@ in_cksum(m, len)
                if (len < mlen)
                        mlen = len;
                len -= mlen;
                if (len < mlen)
                        mlen = len;
                len -= mlen;
-#ifdef sun
-               sum += ocsum(w, mlen>>1);
-               w += mlen>>1;
-#endif
-#ifdef vax
                /*
                 * Force to long boundary so we do longword aligned
                 * memory operations.  It is too hard to do byte
                /*
                 * Force to long boundary so we do longword aligned
                 * memory operations.  It is too hard to do byte
@@ -79,14 +101,18 @@ in_cksum(m, len)
                 */
                while ((mlen -= 32) >= 0) {
 #undef ADD
                 */
                while ((mlen -= 32) >= 0) {
 #undef ADD
-                       asm("clrl r0");         /* clears carry */
+#ifdef unneeded                 /* The loop construct clears carry for us... */
+                       asm("bicpsr $1");               /* clears carry */
+#endif
 #define ADD            asm("adwc (r9)+,r8;");
                        ADD; ADD; ADD; ADD; ADD; ADD; ADD; ADD;
                        asm("adwc $0,r8");
                }
                mlen += 32;
                while ((mlen -= 8) >= 0) {
 #define ADD            asm("adwc (r9)+,r8;");
                        ADD; ADD; ADD; ADD; ADD; ADD; ADD; ADD;
                        asm("adwc $0,r8");
                }
                mlen += 32;
                while ((mlen -= 8) >= 0) {
-                       asm("clrl r0");
+#ifdef unneeded                 /* The loop construct clears carry for us... */
+                       asm("bicpsr $1");               /* clears carry */
+#endif
                        ADD; ADD;
                        asm("adwc $0,r8");
                }
                        ADD; ADD;
                        asm("adwc $0,r8");
                }
@@ -105,13 +131,6 @@ in_cksum(m, len)
                if (mlen == -1) {
                        sum += *(u_char *)w;
                }
                if (mlen == -1) {
                        sum += *(u_char *)w;
                }
-#endif vax
-#ifdef sun
-               if (mlen & 1) {
-                       sum += *(u_char *)w << 8;
-                       mlen = -1;
-               }
-#endif
                if (len == 0)
                        break;
                /*
                if (len == 0)
                        break;
                /*
@@ -137,14 +156,7 @@ done:
         * Have to be careful to not drop the last
         * carry here.
         */
         * Have to be careful to not drop the last
         * carry here.
         */
-#ifdef sun
-       sum = (sum & 0xFFFF) + (sum >> 16);
-       sum = (sum & 0xFFFF) + (sum >> 16);
-       sum = (~sum) & 0xFFFF;
-#endif
-#ifdef vax
        { asm("ashl $-16,r8,r0; addw2 r0,r8; adwc $0,r8");
          asm("mcoml r8,r8; movzwl r8,r8"); }
        { asm("ashl $-16,r8,r0; addw2 r0,r8; adwc $0,r8");
          asm("mcoml r8,r8; movzwl r8,r8"); }
-#endif
        return (sum);
 }
        return (sum);
 }