checksum_32.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * This file contains assembly-language implementations
  3. * of IP-style 1's complement checksum routines.
  4. *
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. *
  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.
  11. *
  12. * Severely hacked about by Paul Mackerras (paulus@cs.anu.edu.au).
  13. */
  14. #include <linux/sys.h>
  15. #include <asm/processor.h>
  16. #include <asm/errno.h>
  17. #include <asm/ppc_asm.h>
  18. .text
  19. /*
  20. * ip_fast_csum(buf, len) -- Optimized for IP header
  21. * len is in words and is always >= 5.
  22. */
  23. _GLOBAL(ip_fast_csum)
  24. lwz r0,0(r3)
  25. lwzu r5,4(r3)
  26. addic. r4,r4,-2
  27. addc r0,r0,r5
  28. mtctr r4
  29. blelr-
  30. 1: lwzu r4,4(r3)
  31. adde r0,r0,r4
  32. bdnz 1b
  33. addze r0,r0 /* add in final carry */
  34. rlwinm r3,r0,16,0,31 /* fold two halves together */
  35. add r3,r0,r3
  36. not r3,r3
  37. srwi r3,r3,16
  38. blr
  39. /*
  40. * computes the checksum of a memory block at buff, length len,
  41. * and adds in "sum" (32-bit)
  42. *
  43. * csum_partial(buff, len, sum)
  44. */
  45. _GLOBAL(csum_partial)
  46. addic r0,r5,0
  47. subi r3,r3,4
  48. srwi. r6,r4,2
  49. beq 3f /* if we're doing < 4 bytes */
  50. andi. r5,r3,2 /* Align buffer to longword boundary */
  51. beq+ 1f
  52. lhz r5,4(r3) /* do 2 bytes to get aligned */
  53. addi r3,r3,2
  54. subi r4,r4,2
  55. addc r0,r0,r5
  56. srwi. r6,r4,2 /* # words to do */
  57. beq 3f
  58. 1: mtctr r6
  59. 2: lwzu r5,4(r3) /* the bdnz has zero overhead, so it should */
  60. adde r0,r0,r5 /* be unnecessary to unroll this loop */
  61. bdnz 2b
  62. andi. r4,r4,3
  63. 3: cmpwi 0,r4,2
  64. blt+ 4f
  65. lhz r5,4(r3)
  66. addi r3,r3,2
  67. subi r4,r4,2
  68. adde r0,r0,r5
  69. 4: cmpwi 0,r4,1
  70. bne+ 5f
  71. lbz r5,4(r3)
  72. slwi r5,r5,8 /* Upper byte of word */
  73. adde r0,r0,r5
  74. 5: addze r3,r0 /* add in final carry */
  75. blr
  76. /*
  77. * Computes the checksum of a memory block at src, length len,
  78. * and adds in "sum" (32-bit), while copying the block to dst.
  79. * If an access exception occurs on src or dst, it stores -EFAULT
  80. * to *src_err or *dst_err respectively, and (for an error on
  81. * src) zeroes the rest of dst.
  82. *
  83. * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
  84. */
  85. _GLOBAL(csum_partial_copy_generic)
  86. addic r0,r6,0
  87. subi r3,r3,4
  88. subi r4,r4,4
  89. srwi. r6,r5,2
  90. beq 3f /* if we're doing < 4 bytes */
  91. andi. r9,r4,2 /* Align dst to longword boundary */
  92. beq+ 1f
  93. 81: lhz r6,4(r3) /* do 2 bytes to get aligned */
  94. addi r3,r3,2
  95. subi r5,r5,2
  96. 91: sth r6,4(r4)
  97. addi r4,r4,2
  98. addc r0,r0,r6
  99. srwi. r6,r5,2 /* # words to do */
  100. beq 3f
  101. 1: srwi. r6,r5,4 /* # groups of 4 words to do */
  102. beq 10f
  103. mtctr r6
  104. 71: lwz r6,4(r3)
  105. 72: lwz r9,8(r3)
  106. 73: lwz r10,12(r3)
  107. 74: lwzu r11,16(r3)
  108. adde r0,r0,r6
  109. 75: stw r6,4(r4)
  110. adde r0,r0,r9
  111. 76: stw r9,8(r4)
  112. adde r0,r0,r10
  113. 77: stw r10,12(r4)
  114. adde r0,r0,r11
  115. 78: stwu r11,16(r4)
  116. bdnz 71b
  117. 10: rlwinm. r6,r5,30,30,31 /* # words left to do */
  118. beq 13f
  119. mtctr r6
  120. 82: lwzu r9,4(r3)
  121. 92: stwu r9,4(r4)
  122. adde r0,r0,r9
  123. bdnz 82b
  124. 13: andi. r5,r5,3
  125. 3: cmpwi 0,r5,2
  126. blt+ 4f
  127. 83: lhz r6,4(r3)
  128. addi r3,r3,2
  129. subi r5,r5,2
  130. 93: sth r6,4(r4)
  131. addi r4,r4,2
  132. adde r0,r0,r6
  133. 4: cmpwi 0,r5,1
  134. bne+ 5f
  135. 84: lbz r6,4(r3)
  136. 94: stb r6,4(r4)
  137. slwi r6,r6,8 /* Upper byte of word */
  138. adde r0,r0,r6
  139. 5: addze r3,r0 /* add in final carry */
  140. blr
  141. /* These shouldn't go in the fixup section, since that would
  142. cause the ex_table addresses to get out of order. */
  143. src_error_4:
  144. mfctr r6 /* update # bytes remaining from ctr */
  145. rlwimi r5,r6,4,0,27
  146. b 79f
  147. src_error_1:
  148. li r6,0
  149. subi r5,r5,2
  150. 95: sth r6,4(r4)
  151. addi r4,r4,2
  152. 79: srwi. r6,r5,2
  153. beq 3f
  154. mtctr r6
  155. src_error_2:
  156. li r6,0
  157. 96: stwu r6,4(r4)
  158. bdnz 96b
  159. 3: andi. r5,r5,3
  160. beq src_error
  161. src_error_3:
  162. li r6,0
  163. mtctr r5
  164. addi r4,r4,3
  165. 97: stbu r6,1(r4)
  166. bdnz 97b
  167. src_error:
  168. cmpwi 0,r7,0
  169. beq 1f
  170. li r6,-EFAULT
  171. stw r6,0(r7)
  172. 1: addze r3,r0
  173. blr
  174. dst_error:
  175. cmpwi 0,r8,0
  176. beq 1f
  177. li r6,-EFAULT
  178. stw r6,0(r8)
  179. 1: addze r3,r0
  180. blr
  181. .section __ex_table,"a"
  182. .long 81b,src_error_1
  183. .long 91b,dst_error
  184. .long 71b,src_error_4
  185. .long 72b,src_error_4
  186. .long 73b,src_error_4
  187. .long 74b,src_error_4
  188. .long 75b,dst_error
  189. .long 76b,dst_error
  190. .long 77b,dst_error
  191. .long 78b,dst_error
  192. .long 82b,src_error_2
  193. .long 92b,dst_error
  194. .long 83b,src_error_3
  195. .long 93b,dst_error
  196. .long 84b,src_error_3
  197. .long 94b,dst_error
  198. .long 95b,dst_error
  199. .long 96b,dst_error
  200. .long 97b,dst_error