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.vax.c	1.1 (Berkeley) 06/22/85";
9 #endif not lint
10 
11 #include "../globals.h"
12 #include <protocols/timed.h>
13 
14 #define ADD	asm("adwc (r9)+,r8;");
15 
16 /* computes the checksum for ip packets for the VAX */
17 
18 in_cksum(addr, len)
19 u_short *addr;
20 int len;
21 {
22 	register int nleft = len;	/* on vax, (user mode), r11 */
23 #ifndef lint
24 	register int xxx;		/* on vax, (user mode), r10 */
25 #endif not lint
26 	register u_short *w = addr;	/* on vax, known to be r9 */
27 	register int sum = 0;		/* on vax, known to be r8 */
28 
29 	if (((int)w&0x2) && nleft >= 2) {
30 		sum += *w++;
31 		nleft -= 2;
32 	}
33 	while ((nleft -= 32) >= 0) {
34 		asm("clrl r0");		/* clears carry */
35 		ADD; ADD; ADD; ADD; ADD; ADD; ADD; ADD;
36 		asm("adwc $0,r8");
37 	}
38 	nleft += 32;
39 	while ((nleft -= 8) >= 0) {
40 		asm("clrl r0");
41 		ADD; ADD;
42 		asm("adwc $0,r8");
43 	}
44 	nleft += 8;
45 	{ asm("ashl $-16,r8,r0; addw2 r0,r8");
46 	  asm("adwc $0,r8; movzwl r8,r8"); }
47 	while ((nleft -= 2) >= 0) {
48 		asm("movzwl (r9)+,r0; addl2 r0,r8");
49 	}
50 	if (nleft == -1) {
51 		sum += *(u_char *)w;
52 	}
53 
54 	{ asm("ashl $-16,r8,r0; addw2 r0,r8; adwc $0,r8");
55 	  asm("mcoml r8,r8; movzwl r8,r8"); }
56 	return (sum);
57 }
58