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 "../kernel/ppc_asm.tmpl"
23 * ip_fast_csum(buf, len) -- Optimized for IP header
24 * len is in words and is always >= 5.
37 addze r0,r0 /* add in final carry */
38 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 */
126 82: lwzu r6,4(r3) /* the bdnz has zero overhead, so it should */
127 92: stwu r6,4(r4) /* be unnecessary to unroll this loop */
143 slwi r6,r6,8 /* Upper byte of word */
145 5: addze r3,r0 /* add in final carry */
148 /* These shouldn't go in the fixup section, since that would
149 cause the ex_table addresses to get out of order. */
187 .section __ex_table,"a"
188 .long 81b,src_error_1
190 .long 82b,src_error_2
192 .long 83b,src_error_3
194 .long 84b,src_error_3