2 * This file contains assembly-language implementations
3 * of IP-style 1's complement checksum routines.
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * Severely hacked about by Paul Mackerras (paulus@cs.anu.edu.au).
15 #include <linux/sys.h>
16 #include <asm/processor.h>
17 #include <asm/errno.h>
18 #include <asm/ppc_asm.h>
23 * ip_fast_csum(buf, len) -- Optimized for IP header
24 * len is in words and is always >= 5.
36 addze r0,r0 /* add in final carry */
37 rlwinm r3,r0,16,0,31 /* fold two halves together */
44 * Compute checksum of TCP or UDP pseudo-header:
45 * csum_tcpudp_magic(saddr, daddr, len, proto, sum)
47 _GLOBAL(csum_tcpudp_magic)
48 rlwimi r5,r6,16,0,15 /* put proto in upper half of len */
49 addc r0,r3,r4 /* add 4 32-bit words together */
52 addze r0,r0 /* add in final carry */
53 rlwinm r3,r0,16,0,31 /* fold two halves together */
60 * computes the checksum of a memory block at buff, length len,
61 * and adds in "sum" (32-bit)
63 * csum_partial(buff, len, sum)
69 beq 3f /* if we're doing < 4 bytes */
70 andi. r5,r3,2 /* Align buffer to longword boundary */
72 lhz r5,4(r3) /* do 2 bytes to get aligned */
76 srwi. r6,r4,2 /* # words to do */
79 2: lwzu r5,4(r3) /* the bdnz has zero overhead, so it should */
80 adde r0,r0,r5 /* be unnecessary to unroll this loop */
92 slwi r5,r5,8 /* Upper byte of word */
94 5: addze r3,r0 /* add in final carry */
98 * Computes the checksum of a memory block at src, length len,
99 * and adds in "sum" (32-bit), while copying the block to dst.
100 * If an access exception occurs on src or dst, it stores -EFAULT
101 * to *src_err or *dst_err respectively, and (for an error on
102 * src) zeroes the rest of dst.
104 * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
106 _GLOBAL(csum_partial_copy_generic)
111 beq 3f /* if we're doing < 4 bytes */
112 andi. r9,r4,2 /* Align dst to longword boundary */
114 81: lhz r6,4(r3) /* do 2 bytes to get aligned */
120 srwi. r6,r5,2 /* # words to do */
122 1: srwi. r6,r5,4 /* # groups of 4 words to do */
138 10: rlwinm. r6,r5,30,30,31 /* # words left to do */
158 slwi r6,r6,8 /* Upper byte of word */
160 5: addze r3,r0 /* add in final carry */
163 /* These shouldn't go in the fixup section, since that would
164 cause the ex_table addresses to get out of order. */
167 mfctr r6 /* update # bytes remaining from ctr */
206 .section __ex_table,"a"
207 .long 81b,src_error_1
209 .long 71b,src_error_4
210 .long 72b,src_error_4
211 .long 73b,src_error_4
212 .long 74b,src_error_4
217 .long 82b,src_error_2
219 .long 83b,src_error_3
221 .long 84b,src_error_3