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 * computes the checksum of a memory block at buff, length len,
45 * and adds in "sum" (32-bit)
47 * csum_partial(buff, len, sum)
53 beq 3f /* if we're doing < 4 bytes */
54 andi. r5,r3,2 /* Align buffer to longword boundary */
56 lhz r5,4(r3) /* do 2 bytes to get aligned */
60 srwi. r6,r4,2 /* # words to do */
63 2: lwzu r5,4(r3) /* the bdnz has zero overhead, so it should */
64 adde r0,r0,r5 /* be unnecessary to unroll this loop */
76 slwi r5,r5,8 /* Upper byte of word */
78 5: addze r3,r0 /* add in final carry */
82 * Computes the checksum of a memory block at src, length len,
83 * and adds in "sum" (32-bit), while copying the block to dst.
84 * If an access exception occurs on src or dst, it stores -EFAULT
85 * to *src_err or *dst_err respectively, and (for an error on
86 * src) zeroes the rest of dst.
88 * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
90 _GLOBAL(csum_partial_copy_generic)
95 beq 3f /* if we're doing < 4 bytes */
96 andi. r9,r4,2 /* Align dst to longword boundary */
98 81: lhz r6,4(r3) /* do 2 bytes to get aligned */
104 srwi. r6,r5,2 /* # words to do */
106 1: srwi. r6,r5,4 /* # groups of 4 words to do */
122 10: rlwinm. r6,r5,30,30,31 /* # words left to do */
142 slwi r6,r6,8 /* Upper byte of word */
144 5: addze r3,r0 /* add in final carry */
147 /* These shouldn't go in the fixup section, since that would
148 cause the ex_table addresses to get out of order. */
151 mfctr r6 /* update # bytes remaining from ctr */
190 .section __ex_table,"a"
191 .long 81b,src_error_1
193 .long 71b,src_error_4
194 .long 72b,src_error_4
195 .long 73b,src_error_4
196 .long 74b,src_error_4
201 .long 82b,src_error_2
203 .long 83b,src_error_3
205 .long 84b,src_error_3