2 * BK Id: SCCS/s.checksum.S 1.11 08/13/02 21:52:53 paulus
5 * This file contains assembly-language implementations
6 * of IP-style 1's complement checksum routines.
8 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * Severely hacked about by Paul Mackerras (paulus@cs.anu.edu.au).
18 #include <linux/sys.h>
19 #include <asm/processor.h>
20 #include <asm/errno.h>
21 #include <asm/ppc_asm.h>
26 * ip_fast_csum(buf, len) -- Optimized for IP header
27 * len is in words and is always >= 5.
39 addze r0,r0 /* add in final carry */
40 rlwinm r3,r0,16,0,31 /* fold two halves together */
47 * Compute checksum of TCP or UDP pseudo-header:
48 * csum_tcpudp_magic(saddr, daddr, len, proto, sum)
50 _GLOBAL(csum_tcpudp_magic)
51 rlwimi r5,r6,16,0,15 /* put proto in upper half of len */
52 addc r0,r3,r4 /* add 4 32-bit words together */
55 addze r0,r0 /* add in final carry */
56 rlwinm r3,r0,16,0,31 /* fold two halves together */
63 * computes the checksum of a memory block at buff, length len,
64 * and adds in "sum" (32-bit)
66 * csum_partial(buff, len, sum)
72 beq 3f /* if we're doing < 4 bytes */
73 andi. r5,r3,2 /* Align buffer to longword boundary */
75 lhz r5,4(r3) /* do 2 bytes to get aligned */
79 srwi. r6,r4,2 /* # words to do */
82 2: lwzu r5,4(r3) /* the bdnz has zero overhead, so it should */
83 adde r0,r0,r5 /* be unnecessary to unroll this loop */
95 slwi r5,r5,8 /* Upper byte of word */
97 5: addze r3,r0 /* add in final carry */
101 * Computes the checksum of a memory block at src, length len,
102 * and adds in "sum" (32-bit), while copying the block to dst.
103 * If an access exception occurs on src or dst, it stores -EFAULT
104 * to *src_err or *dst_err respectively, and (for an error on
105 * src) zeroes the rest of dst.
107 * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
109 _GLOBAL(csum_partial_copy_generic)
114 beq 3f /* if we're doing < 4 bytes */
115 andi. r9,r4,2 /* Align dst to longword boundary */
117 81: lhz r6,4(r3) /* do 2 bytes to get aligned */
123 srwi. r6,r5,2 /* # words to do */
125 1: srwi. r6,r5,4 /* # groups of 4 words to do */
141 10: rlwinm. r6,r5,30,30,31 /* # words left to do */
161 slwi r6,r6,8 /* Upper byte of word */
163 5: addze r3,r0 /* add in final carry */
166 /* These shouldn't go in the fixup section, since that would
167 cause the ex_table addresses to get out of order. */
170 mfctr r6 /* update # bytes remaining from ctr */
209 .section __ex_table,"a"
210 .long 81b,src_error_1
212 .long 71b,src_error_4
213 .long 72b,src_error_4
214 .long 73b,src_error_4
215 .long 74b,src_error_4
220 .long 82b,src_error_2
222 .long 83b,src_error_3
224 .long 84b,src_error_3