1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: static char sccsid[] = "@(#)cksum.c	1.2 (Berkeley) 9/18/85";
   9: #endif not lint
  10: 
  11: #include <sys/types.h>
  12: 
  13: #define ADD asm("adwc (r9)+,r8;");
  14: 
  15: /* computes the checksum for ip packets for the VAX */
  16: 
  17: in_cksum(addr, len)
  18: u_short *addr;
  19: int len;
  20: {
  21:     register int nleft = len;   /* on vax, (user mode), r11 */
  22: #ifndef lint
  23:     register int xxx;       /* on vax, (user mode), r10 */
  24: #endif not lint
  25:     register u_short *w = addr; /* on vax, known to be r9 */
  26:     register int sum = 0;       /* on vax, known to be r8 */
  27: 
  28:     if (((int)w&0x2) && nleft >= 2) {
  29:         sum += *w++;
  30:         nleft -= 2;
  31:     }
  32:     while ((nleft -= 32) >= 0) {
  33:         asm("clrl r0");     /* clears carry */
  34:         ADD; ADD; ADD; ADD; ADD; ADD; ADD; ADD;
  35:         asm("adwc $0,r8");
  36:     }
  37:     nleft += 32;
  38:     while ((nleft -= 8) >= 0) {
  39:         asm("clrl r0");
  40:         ADD; ADD;
  41:         asm("adwc $0,r8");
  42:     }
  43:     nleft += 8;
  44:     { asm("ashl $-16,r8,r0; addw2 r0,r8");
  45:       asm("adwc $0,r8; movzwl r8,r8"); }
  46:     while ((nleft -= 2) >= 0) {
  47:         asm("movzwl (r9)+,r0; addl2 r0,r8");
  48:     }
  49:     if (nleft == -1) {
  50:         sum += *(u_char *)w;
  51:     }
  52: 
  53:     { asm("ashl $-16,r8,r0; addw2 r0,r8; adwc $0,r8");
  54:       asm("mcoml r8,r8; movzwl r8,r8"); }
  55:     return (sum);
  56: }

Defined functions

in_cksum defined in line 17; never used

Defined variables

sccsid defined in line 8; never used

Defined macros

ADD defined in line 13; used 10 times
  • in line 34(8), 40(2)
Last modified: 1985-09-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 560
Valid CSS Valid XHTML 1.0 Strict