checksum_32.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * Compute checksum of TCP or UDP pseudo-header:
  41. * csum_tcpudp_magic(saddr, daddr, len, proto, sum)
  42. */
  43. _GLOBAL(csum_tcpudp_magic)
  44. rlwimi r5,r6,16,0,15 /* put proto in upper half of len */
  45. addc r0,r3,r4 /* add 4 32-bit words together */
  46. adde r0,r0,r5
  47. adde r0,r0,r7
  48. addze r0,r0 /* add in final carry */
  49. rlwinm r3,r0,16,0,31 /* fold two halves together */
  50. add r3,r0,r3
  51. not r3,r3
  52. srwi r3,r3,16
  53. blr
  54. /*
  55. * computes the checksum of a memory block at buff, length len,
  56. * and adds in "sum" (32-bit)
  57. *
  58. * csum_partial(buff, len, sum)
  59. */
  60. _GLOBAL(csum_partial)
  61. addic r0,r5,0
  62. subi r3,r3,4
  63. srwi. r6,r4,2
  64. beq 3f /* if we're doing < 4 bytes */
  65. andi. r5,r3,2 /* Align buffer to longword boundary */
  66. beq+ 1f
  67. lhz r5,4(r3) /* do 2 bytes to get aligned */
  68. addi r3,r3,2
  69. subi r4,r4,2
  70. addc r0,r0,r5
  71. srwi. r6,r4,2 /* # words to do */
  72. beq 3f
  73. 1: mtctr r6
  74. 2: lwzu r5,4(r3) /* the bdnz has zero overhead, so it should */
  75. adde r0,r0,r5 /* be unnecessary to unroll this loop */
  76. bdnz 2b
  77. andi. r4,r4,3
  78. 3: cmpwi 0,r4,2
  79. blt+ 4f
  80. lhz r5,4(r3)
  81. addi r3,r3,2
  82. subi r4,r4,2
  83. adde r0,r0,r5
  84. 4: cmpwi 0,r4,1
  85. bne+ 5f
  86. lbz r5,4(r3)
  87. slwi r5,r5,8 /* Upper byte of word */
  88. adde r0,r0,r5
  89. 5: addze r3,r0 /* add in final carry */
  90. blr
  91. /*
  92. * Computes the checksum of a memory block at src, length len,
  93. * and adds in "sum" (32-bit), while copying the block to dst.
  94. * If an access exception occurs on src or dst, it stores -EFAULT
  95. * to *src_err or *dst_err respectively, and (for an error on
  96. * src) zeroes the rest of dst.
  97. *
  98. * csum_partial_copy_generic(src, dst, len, sum, src_err, dst_err)
  99. */
  100. _GLOBAL(csum_partial_copy_generic)
  101. addic r0,r6,0
  102. subi r3,r3,4
  103. subi r4,r4,4
  104. srwi. r6,r5,2
  105. beq 3f /* if we're doing < 4 bytes */
  106. andi. r9,r4,2 /* Align dst to longword boundary */
  107. beq+ 1f
  108. 81: lhz r6,4(r3) /* do 2 bytes to get aligned */
  109. addi r3,r3,2
  110. subi r5,r5,2
  111. 91: sth r6,4(r4)
  112. addi r4,r4,2
  113. addc r0,r0,r6
  114. srwi. r6,r5,2 /* # words to do */
  115. beq 3f
  116. 1: srwi. r6,r5,4 /* # groups of 4 words to do */
  117. beq 10f
  118. mtctr r6
  119. 71: lwz r6,4(r3)
  120. 72: lwz r9,8(r3)
  121. 73: lwz r10,12(r3)
  122. 74: lwzu r11,16(r3)
  123. adde r0,r0,r6
  124. 75: stw r6,4(r4)
  125. adde r0,r0,r9
  126. 76: stw r9,8(r4)
  127. adde r0,r0,r10
  128. 77: stw r10,12(r4)
  129. adde r0,r0,r11
  130. 78: stwu r11,16(r4)
  131. bdnz 71b
  132. 10: rlwinm. r6,r5,30,30,31 /* # words left to do */
  133. beq 13f
  134. mtctr r6
  135. 82: lwzu r9,4(r3)
  136. 92: stwu r9,4(r4)
  137. adde r0,r0,r9
  138. bdnz 82b
  139. 13: andi. r5,r5,3
  140. 3: cmpwi 0,r5,2
  141. blt+ 4f
  142. 83: lhz r6,4(r3)
  143. addi r3,r3,2
  144. subi r5,r5,2
  145. 93: sth r6,4(r4)
  146. addi r4,r4,2
  147. adde r0,r0,r6
  148. 4: cmpwi 0,r5,1
  149. bne+ 5f
  150. 84: lbz r6,4(r3)
  151. 94: stb r6,4(r4)
  152. slwi r6,r6,8 /* Upper byte of word */
  153. adde r0,r0,r6
  154. 5: addze r3,r0 /* add in final carry */
  155. blr
  156. /* These shouldn't go in the fixup section, since that would
  157. cause the ex_table addresses to get out of order. */
  158. src_error_4:
  159. mfctr r6 /* update # bytes remaining from ctr */
  160. rlwimi r5,r6,4,0,27
  161. b 79f
  162. src_error_1:
  163. li r6,0
  164. subi r5,r5,2
  165. 95: sth r6,4(r4)
  166. addi r4,r4,2
  167. 79: srwi. r6,r5,2
  168. beq 3f
  169. mtctr r6
  170. src_error_2:
  171. li r6,0
  172. 96: stwu r6,4(r4)
  173. bdnz 96b
  174. 3: andi. r5,r5,3
  175. beq src_error
  176. src_error_3:
  177. li r6,0
  178. mtctr r5
  179. addi r4,r4,3
  180. 97: stbu r6,1(r4)
  181. bdnz 97b
  182. src_error:
  183. cmpwi 0,r7,0
  184. beq 1f
  185. li r6,-EFAULT
  186. stw r6,0(r7)
  187. 1: addze r3,r0
  188. blr
  189. dst_error:
  190. cmpwi 0,r8,0
  191. beq 1f
  192. li r6,-EFAULT
  193. stw r6,0(r8)
  194. 1: addze r3,r0
  195. blr
  196. .section __ex_table,"a"
  197. .long 81b,src_error_1
  198. .long 91b,dst_error
  199. .long 71b,src_error_4
  200. .long 72b,src_error_4
  201. .long 73b,src_error_4
  202. .long 74b,src_error_4
  203. .long 75b,dst_error
  204. .long 76b,dst_error
  205. .long 77b,dst_error
  206. .long 78b,dst_error
  207. .long 82b,src_error_2
  208. .long 92b,dst_error
  209. .long 83b,src_error_3
  210. .long 93b,dst_error
  211. .long 84b,src_error_3
  212. .long 94b,dst_error
  213. .long 95b,dst_error
  214. .long 96b,dst_error
  215. .long 97b,dst_error