Annotation of sys/arch/sparc64/sparc64/in4_cksum.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: in4_cksum.c,v 1.2 2007/04/10 17:47:55 miod Exp $ */
2: /* $NetBSD: in4_cksum.c,v 1.5 2003/10/13 14:22:20 agc Exp $ */
3:
4: /*
5: * Copyright (c) 1995 Matthew R. Green.
6: * Copyright (c) 1992, 1993
7: * The Regents of the University of California. All rights reserved.
8: *
9: * All advertising materials mentioning features or use of this software
10: * must display the following acknowledgement:
11: * This product includes software developed by the University of
12: * California, and its contributors.
13: *
14: * Redistribution and use in source and binary forms, with or without
15: * modification, are permitted provided that the following conditions
16: * are met:
17: * 1. Redistributions of source code must retain the above copyright
18: * notice, this list of conditions and the following disclaimer.
19: * 2. Redistributions in binary form must reproduce the above copyright
20: * notice, this list of conditions and the following disclaimer in the
21: * documentation and/or other materials provided with the distribution.
22: * 3. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
38: * @(#)in_cksum.c 8.1 (Berkeley) 6/11/93
39: */
40:
41: /*
42: * Copyright (c) 2001 Eduardo Horvath.
43: * Copyright (c) 1995 Zubin Dittia.
44: * Copyright (c) 1994, 1998 Charles M. Hannum.
45: *
46: * All advertising materials mentioning features or use of this software
47: * must display the following acknowledgement:
48: * This product includes software developed by the University of
49: * California, and its contributors.
50: *
51: * Redistribution and use in source and binary forms, with or without
52: * modification, are permitted provided that the following conditions
53: * are met:
54: * 1. Redistributions of source code must retain the above copyright
55: * notice, this list of conditions and the following disclaimer.
56: * 2. Redistributions in binary form must reproduce the above copyright
57: * notice, this list of conditions and the following disclaimer in the
58: * documentation and/or other materials provided with the distribution.
59: * 3. All advertising materials mentioning features or use of this software
60: * must display the following acknowledgement:
61: * This product includes software developed by the University of
62: * California, Berkeley and its contributors.
63: * 4. Neither the name of the University nor the names of its contributors
64: * may be used to endorse or promote products derived from this software
65: * without specific prior written permission.
66: *
67: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77: * SUCH DAMAGE.
78: *
79: * @(#)in_cksum.c 8.1 (Berkeley) 6/11/93
80: */
81:
82: #if 0
83: #include <sys/cdefs.h>
84: __KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.5 2003/10/13 14:22:20 agc Exp $");
85: #endif
86:
87: #include <sys/param.h>
88: #include <sys/systm.h>
89: #include <sys/mbuf.h>
90: #include <sys/socketvar.h>
91: #include <netinet/in.h>
92: #include <netinet/in_systm.h>
93: #include <netinet/ip.h>
94: #include <netinet/ip_var.h>
95:
96: extern int in_cksum_internal(struct mbuf *, int len, int offset, int sum);
97:
98: int
99: in4_cksum(struct mbuf *m, u_int8_t nxt, int off, int len)
100: {
101: u_char *w;
102: u_int sum = 0;
103: struct ipovly ipov;
104:
105: /*
106: * Declare three temporary registers for use by the asm code. We
107: * allow the compiler to pick which specific machine registers to
108: * use, instead of hard-coding this in the asm code.
109: */
110: u_int tmp1, tmp2, tmp3;
111:
112: if (nxt != 0) {
113: /* pseudo header */
114: memset(&ipov, 0, sizeof(ipov));
115: ipov.ih_len = htons(len);
116: ipov.ih_pr = nxt;
117: ipov.ih_src = mtod(m, struct ip *)->ip_src;
118: ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
119: w = (u_char *)&ipov;
120: /* assumes sizeof(ipov) == 20 */
121: __asm __volatile(" lduw [%5 + 0], %1; "
122: " lduw [%5 + 4], %2; "
123: " lduw [%5 + 8], %3; add %0, %1, %0; "
124: " lduw [%5 + 12], %1; add %0, %2, %0; "
125: " lduw [%5 + 16], %2; add %0, %3, %0; "
126: " mov -1, %3; add %0, %1, %0; "
127: " srl %3, 0, %3; add %0, %2, %0; "
128: " srlx %0, 32, %2; and %0, %3, %1; "
129: " add %0, %2, %0; "
130: : "=r" (sum), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3)
131: : "0" (sum), "r" (w));
132: }
133:
134: /* skip unnecessary part */
135: while (m && off > 0) {
136: if (m->m_len > off)
137: break;
138: off -= m->m_len;
139: m = m->m_next;
140: }
141: return (in_cksum_internal(m, len, off, sum));
142: }
CVSweb