checksum.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /* checksum.S: Sparc optimized checksum code.
  2. *
  3. * Copyright(C) 1995 Linus Torvalds
  4. * Copyright(C) 1995 Miguel de Icaza
  5. * Copyright(C) 1996 David S. Miller
  6. * Copyright(C) 1997 Jakub Jelinek
  7. *
  8. * derived from:
  9. * Linux/Alpha checksum c-code
  10. * Linux/ix86 inline checksum assembly
  11. * RFC1071 Computing the Internet Checksum (esp. Jacobsons m68k code)
  12. * David Mosberger-Tang for optimized reference c-code
  13. * BSD4.4 portable checksum routine
  14. */
  15. #include <asm/errno.h>
  16. #define CSUM_BIGCHUNK(buf, offset, sum, t0, t1, t2, t3, t4, t5) \
  17. ldd [buf + offset + 0x00], t0; \
  18. ldd [buf + offset + 0x08], t2; \
  19. addxcc t0, sum, sum; \
  20. addxcc t1, sum, sum; \
  21. ldd [buf + offset + 0x10], t4; \
  22. addxcc t2, sum, sum; \
  23. addxcc t3, sum, sum; \
  24. ldd [buf + offset + 0x18], t0; \
  25. addxcc t4, sum, sum; \
  26. addxcc t5, sum, sum; \
  27. addxcc t0, sum, sum; \
  28. addxcc t1, sum, sum;
  29. #define CSUM_LASTCHUNK(buf, offset, sum, t0, t1, t2, t3) \
  30. ldd [buf - offset - 0x08], t0; \
  31. ldd [buf - offset - 0x00], t2; \
  32. addxcc t0, sum, sum; \
  33. addxcc t1, sum, sum; \
  34. addxcc t2, sum, sum; \
  35. addxcc t3, sum, sum;
  36. /* Do end cruft out of band to get better cache patterns. */
  37. csum_partial_end_cruft:
  38. be 1f ! caller asks %o1 & 0x8
  39. andcc %o1, 4, %g0 ! nope, check for word remaining
  40. ldd [%o0], %g2 ! load two
  41. addcc %g2, %o2, %o2 ! add first word to sum
  42. addxcc %g3, %o2, %o2 ! add second word as well
  43. add %o0, 8, %o0 ! advance buf ptr
  44. addx %g0, %o2, %o2 ! add in final carry
  45. andcc %o1, 4, %g0 ! check again for word remaining
  46. 1: be 1f ! nope, skip this code
  47. andcc %o1, 3, %o1 ! check for trailing bytes
  48. ld [%o0], %g2 ! load it
  49. addcc %g2, %o2, %o2 ! add to sum
  50. add %o0, 4, %o0 ! advance buf ptr
  51. addx %g0, %o2, %o2 ! add in final carry
  52. andcc %o1, 3, %g0 ! check again for trailing bytes
  53. 1: be 1f ! no trailing bytes, return
  54. addcc %o1, -1, %g0 ! only one byte remains?
  55. bne 2f ! at least two bytes more
  56. subcc %o1, 2, %o1 ! only two bytes more?
  57. b 4f ! only one byte remains
  58. or %g0, %g0, %o4 ! clear fake hword value
  59. 2: lduh [%o0], %o4 ! get hword
  60. be 6f ! jmp if only hword remains
  61. add %o0, 2, %o0 ! advance buf ptr either way
  62. sll %o4, 16, %o4 ! create upper hword
  63. 4: ldub [%o0], %o5 ! get final byte
  64. sll %o5, 8, %o5 ! put into place
  65. or %o5, %o4, %o4 ! coalese with hword (if any)
  66. 6: addcc %o4, %o2, %o2 ! add to sum
  67. 1: retl ! get outta here
  68. addx %g0, %o2, %o0 ! add final carry into retval
  69. /* Also do alignment out of band to get better cache patterns. */
  70. csum_partial_fix_alignment:
  71. cmp %o1, 6
  72. bl cpte - 0x4
  73. andcc %o0, 0x2, %g0
  74. be 1f
  75. andcc %o0, 0x4, %g0
  76. lduh [%o0 + 0x00], %g2
  77. sub %o1, 2, %o1
  78. add %o0, 2, %o0
  79. sll %g2, 16, %g2
  80. addcc %g2, %o2, %o2
  81. srl %o2, 16, %g3
  82. addx %g0, %g3, %g2
  83. sll %o2, 16, %o2
  84. sll %g2, 16, %g3
  85. srl %o2, 16, %o2
  86. andcc %o0, 0x4, %g0
  87. or %g3, %o2, %o2
  88. 1: be cpa
  89. andcc %o1, 0xffffff80, %o3
  90. ld [%o0 + 0x00], %g2
  91. sub %o1, 4, %o1
  92. addcc %g2, %o2, %o2
  93. add %o0, 4, %o0
  94. addx %g0, %o2, %o2
  95. b cpa
  96. andcc %o1, 0xffffff80, %o3
  97. /* The common case is to get called with a nicely aligned
  98. * buffer of size 0x20. Follow the code path for that case.
  99. */
  100. .globl csum_partial
  101. csum_partial: /* %o0=buf, %o1=len, %o2=sum */
  102. andcc %o0, 0x7, %g0 ! alignment problems?
  103. bne csum_partial_fix_alignment ! yep, handle it
  104. sethi %hi(cpte - 8), %g7 ! prepare table jmp ptr
  105. andcc %o1, 0xffffff80, %o3 ! num loop iterations
  106. cpa: be 3f ! none to do
  107. andcc %o1, 0x70, %g1 ! clears carry flag too
  108. 5: CSUM_BIGCHUNK(%o0, 0x00, %o2, %o4, %o5, %g2, %g3, %g4, %g5)
  109. CSUM_BIGCHUNK(%o0, 0x20, %o2, %o4, %o5, %g2, %g3, %g4, %g5)
  110. CSUM_BIGCHUNK(%o0, 0x40, %o2, %o4, %o5, %g2, %g3, %g4, %g5)
  111. CSUM_BIGCHUNK(%o0, 0x60, %o2, %o4, %o5, %g2, %g3, %g4, %g5)
  112. addx %g0, %o2, %o2 ! sink in final carry
  113. subcc %o3, 128, %o3 ! detract from loop iters
  114. bne 5b ! more to do
  115. add %o0, 128, %o0 ! advance buf ptr
  116. andcc %o1, 0x70, %g1 ! clears carry flag too
  117. 3: be cpte ! nope
  118. andcc %o1, 0xf, %g0 ! anything left at all?
  119. srl %g1, 1, %o4 ! compute offset
  120. sub %g7, %g1, %g7 ! adjust jmp ptr
  121. sub %g7, %o4, %g7 ! final jmp ptr adjust
  122. jmp %g7 + %lo(cpte - 8) ! enter the table
  123. add %o0, %g1, %o0 ! advance buf ptr
  124. cptbl: CSUM_LASTCHUNK(%o0, 0x68, %o2, %g2, %g3, %g4, %g5)
  125. CSUM_LASTCHUNK(%o0, 0x58, %o2, %g2, %g3, %g4, %g5)
  126. CSUM_LASTCHUNK(%o0, 0x48, %o2, %g2, %g3, %g4, %g5)
  127. CSUM_LASTCHUNK(%o0, 0x38, %o2, %g2, %g3, %g4, %g5)
  128. CSUM_LASTCHUNK(%o0, 0x28, %o2, %g2, %g3, %g4, %g5)
  129. CSUM_LASTCHUNK(%o0, 0x18, %o2, %g2, %g3, %g4, %g5)
  130. CSUM_LASTCHUNK(%o0, 0x08, %o2, %g2, %g3, %g4, %g5)
  131. addx %g0, %o2, %o2 ! fetch final carry
  132. andcc %o1, 0xf, %g0 ! anything left at all?
  133. cpte: bne csum_partial_end_cruft ! yep, handle it
  134. andcc %o1, 8, %g0 ! check how much
  135. cpout: retl ! get outta here
  136. mov %o2, %o0 ! return computed csum
  137. .globl __csum_partial_copy_start, __csum_partial_copy_end
  138. __csum_partial_copy_start:
  139. /* Work around cpp -rob */
  140. #define ALLOC #alloc
  141. #define EXECINSTR #execinstr
  142. #define EX(x,y,a,b) \
  143. 98: x,y; \
  144. .section .fixup,ALLOC,EXECINSTR; \
  145. .align 4; \
  146. 99: ba 30f; \
  147. a, b, %o3; \
  148. .section __ex_table,ALLOC; \
  149. .align 4; \
  150. .word 98b, 99b; \
  151. .text; \
  152. .align 4
  153. #define EX2(x,y) \
  154. 98: x,y; \
  155. .section __ex_table,ALLOC; \
  156. .align 4; \
  157. .word 98b, 30f; \
  158. .text; \
  159. .align 4
  160. #define EX3(x,y) \
  161. 98: x,y; \
  162. .section __ex_table,ALLOC; \
  163. .align 4; \
  164. .word 98b, 96f; \
  165. .text; \
  166. .align 4
  167. #define EXT(start,end,handler) \
  168. .section __ex_table,ALLOC; \
  169. .align 4; \
  170. .word start, 0, end, handler; \
  171. .text; \
  172. .align 4
  173. /* This aligned version executes typically in 8.5 superscalar cycles, this
  174. * is the best I can do. I say 8.5 because the final add will pair with
  175. * the next ldd in the main unrolled loop. Thus the pipe is always full.
  176. * If you change these macros (including order of instructions),
  177. * please check the fixup code below as well.
  178. */
  179. #define CSUMCOPY_BIGCHUNK_ALIGNED(src, dst, sum, off, t0, t1, t2, t3, t4, t5, t6, t7) \
  180. ldd [src + off + 0x00], t0; \
  181. ldd [src + off + 0x08], t2; \
  182. addxcc t0, sum, sum; \
  183. ldd [src + off + 0x10], t4; \
  184. addxcc t1, sum, sum; \
  185. ldd [src + off + 0x18], t6; \
  186. addxcc t2, sum, sum; \
  187. std t0, [dst + off + 0x00]; \
  188. addxcc t3, sum, sum; \
  189. std t2, [dst + off + 0x08]; \
  190. addxcc t4, sum, sum; \
  191. std t4, [dst + off + 0x10]; \
  192. addxcc t5, sum, sum; \
  193. std t6, [dst + off + 0x18]; \
  194. addxcc t6, sum, sum; \
  195. addxcc t7, sum, sum;
  196. /* 12 superscalar cycles seems to be the limit for this case,
  197. * because of this we thus do all the ldd's together to get
  198. * Viking MXCC into streaming mode. Ho hum...
  199. */
  200. #define CSUMCOPY_BIGCHUNK(src, dst, sum, off, t0, t1, t2, t3, t4, t5, t6, t7) \
  201. ldd [src + off + 0x00], t0; \
  202. ldd [src + off + 0x08], t2; \
  203. ldd [src + off + 0x10], t4; \
  204. ldd [src + off + 0x18], t6; \
  205. st t0, [dst + off + 0x00]; \
  206. addxcc t0, sum, sum; \
  207. st t1, [dst + off + 0x04]; \
  208. addxcc t1, sum, sum; \
  209. st t2, [dst + off + 0x08]; \
  210. addxcc t2, sum, sum; \
  211. st t3, [dst + off + 0x0c]; \
  212. addxcc t3, sum, sum; \
  213. st t4, [dst + off + 0x10]; \
  214. addxcc t4, sum, sum; \
  215. st t5, [dst + off + 0x14]; \
  216. addxcc t5, sum, sum; \
  217. st t6, [dst + off + 0x18]; \
  218. addxcc t6, sum, sum; \
  219. st t7, [dst + off + 0x1c]; \
  220. addxcc t7, sum, sum;
  221. /* Yuck, 6 superscalar cycles... */
  222. #define CSUMCOPY_LASTCHUNK(src, dst, sum, off, t0, t1, t2, t3) \
  223. ldd [src - off - 0x08], t0; \
  224. ldd [src - off - 0x00], t2; \
  225. addxcc t0, sum, sum; \
  226. st t0, [dst - off - 0x08]; \
  227. addxcc t1, sum, sum; \
  228. st t1, [dst - off - 0x04]; \
  229. addxcc t2, sum, sum; \
  230. st t2, [dst - off - 0x00]; \
  231. addxcc t3, sum, sum; \
  232. st t3, [dst - off + 0x04];
  233. /* Handle the end cruft code out of band for better cache patterns. */
  234. cc_end_cruft:
  235. be 1f
  236. andcc %o3, 4, %g0
  237. EX(ldd [%o0 + 0x00], %g2, and %o3, 0xf)
  238. add %o1, 8, %o1
  239. addcc %g2, %g7, %g7
  240. add %o0, 8, %o0
  241. addxcc %g3, %g7, %g7
  242. EX2(st %g2, [%o1 - 0x08])
  243. addx %g0, %g7, %g7
  244. andcc %o3, 4, %g0
  245. EX2(st %g3, [%o1 - 0x04])
  246. 1: be 1f
  247. andcc %o3, 3, %o3
  248. EX(ld [%o0 + 0x00], %g2, add %o3, 4)
  249. add %o1, 4, %o1
  250. addcc %g2, %g7, %g7
  251. EX2(st %g2, [%o1 - 0x04])
  252. addx %g0, %g7, %g7
  253. andcc %o3, 3, %g0
  254. add %o0, 4, %o0
  255. 1: be 1f
  256. addcc %o3, -1, %g0
  257. bne 2f
  258. subcc %o3, 2, %o3
  259. b 4f
  260. or %g0, %g0, %o4
  261. 2: EX(lduh [%o0 + 0x00], %o4, add %o3, 2)
  262. add %o0, 2, %o0
  263. EX2(sth %o4, [%o1 + 0x00])
  264. be 6f
  265. add %o1, 2, %o1
  266. sll %o4, 16, %o4
  267. 4: EX(ldub [%o0 + 0x00], %o5, add %g0, 1)
  268. EX2(stb %o5, [%o1 + 0x00])
  269. sll %o5, 8, %o5
  270. or %o5, %o4, %o4
  271. 6: addcc %o4, %g7, %g7
  272. 1: retl
  273. addx %g0, %g7, %o0
  274. /* Also, handle the alignment code out of band. */
  275. cc_dword_align:
  276. cmp %g1, 6
  277. bl,a ccte
  278. andcc %g1, 0xf, %o3
  279. andcc %o0, 0x1, %g0
  280. bne ccslow
  281. andcc %o0, 0x2, %g0
  282. be 1f
  283. andcc %o0, 0x4, %g0
  284. EX(lduh [%o0 + 0x00], %g4, add %g1, 0)
  285. sub %g1, 2, %g1
  286. EX2(sth %g4, [%o1 + 0x00])
  287. add %o0, 2, %o0
  288. sll %g4, 16, %g4
  289. addcc %g4, %g7, %g7
  290. add %o1, 2, %o1
  291. srl %g7, 16, %g3
  292. addx %g0, %g3, %g4
  293. sll %g7, 16, %g7
  294. sll %g4, 16, %g3
  295. srl %g7, 16, %g7
  296. andcc %o0, 0x4, %g0
  297. or %g3, %g7, %g7
  298. 1: be 3f
  299. andcc %g1, 0xffffff80, %g0
  300. EX(ld [%o0 + 0x00], %g4, add %g1, 0)
  301. sub %g1, 4, %g1
  302. EX2(st %g4, [%o1 + 0x00])
  303. add %o0, 4, %o0
  304. addcc %g4, %g7, %g7
  305. add %o1, 4, %o1
  306. addx %g0, %g7, %g7
  307. b 3f
  308. andcc %g1, 0xffffff80, %g0
  309. /* Sun, you just can't beat me, you just can't. Stop trying,
  310. * give up. I'm serious, I am going to kick the living shit
  311. * out of you, game over, lights out.
  312. */
  313. .align 8
  314. .globl __csum_partial_copy_sparc_generic
  315. __csum_partial_copy_sparc_generic:
  316. /* %o0=src, %o1=dest, %g1=len, %g7=sum */
  317. xor %o0, %o1, %o4 ! get changing bits
  318. andcc %o4, 3, %g0 ! check for mismatched alignment
  319. bne ccslow ! better this than unaligned/fixups
  320. andcc %o0, 7, %g0 ! need to align things?
  321. bne cc_dword_align ! yes, we check for short lengths there
  322. andcc %g1, 0xffffff80, %g0 ! can we use unrolled loop?
  323. 3: be 3f ! nope, less than one loop remains
  324. andcc %o1, 4, %g0 ! dest aligned on 4 or 8 byte boundary?
  325. be ccdbl + 4 ! 8 byte aligned, kick ass
  326. 5: CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x00,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  327. CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x20,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  328. CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x40,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  329. CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x60,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  330. 10: EXT(5b, 10b, 20f) ! note for exception handling
  331. sub %g1, 128, %g1 ! detract from length
  332. addx %g0, %g7, %g7 ! add in last carry bit
  333. andcc %g1, 0xffffff80, %g0 ! more to csum?
  334. add %o0, 128, %o0 ! advance src ptr
  335. bne 5b ! we did not go negative, continue looping
  336. add %o1, 128, %o1 ! advance dest ptr
  337. 3: andcc %g1, 0x70, %o2 ! can use table?
  338. ccmerge:be ccte ! nope, go and check for end cruft
  339. andcc %g1, 0xf, %o3 ! get low bits of length (clears carry btw)
  340. srl %o2, 1, %o4 ! begin negative offset computation
  341. sethi %hi(12f), %o5 ! set up table ptr end
  342. add %o0, %o2, %o0 ! advance src ptr
  343. sub %o5, %o4, %o5 ! continue table calculation
  344. sll %o2, 1, %g2 ! constant multiplies are fun...
  345. sub %o5, %g2, %o5 ! some more adjustments
  346. jmp %o5 + %lo(12f) ! jump into it, duff style, wheee...
  347. add %o1, %o2, %o1 ! advance dest ptr (carry is clear btw)
  348. cctbl: CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x68,%g2,%g3,%g4,%g5)
  349. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x58,%g2,%g3,%g4,%g5)
  350. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x48,%g2,%g3,%g4,%g5)
  351. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x38,%g2,%g3,%g4,%g5)
  352. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x28,%g2,%g3,%g4,%g5)
  353. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x18,%g2,%g3,%g4,%g5)
  354. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x08,%g2,%g3,%g4,%g5)
  355. 12: EXT(cctbl, 12b, 22f) ! note for exception table handling
  356. addx %g0, %g7, %g7
  357. andcc %o3, 0xf, %g0 ! check for low bits set
  358. ccte: bne cc_end_cruft ! something left, handle it out of band
  359. andcc %o3, 8, %g0 ! begin checks for that code
  360. retl ! return
  361. mov %g7, %o0 ! give em the computed checksum
  362. ccdbl: CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x00,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  363. CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x20,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  364. CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x40,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  365. CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x60,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  366. 11: EXT(ccdbl, 11b, 21f) ! note for exception table handling
  367. sub %g1, 128, %g1 ! detract from length
  368. addx %g0, %g7, %g7 ! add in last carry bit
  369. andcc %g1, 0xffffff80, %g0 ! more to csum?
  370. add %o0, 128, %o0 ! advance src ptr
  371. bne ccdbl ! we did not go negative, continue looping
  372. add %o1, 128, %o1 ! advance dest ptr
  373. b ccmerge ! finish it off, above
  374. andcc %g1, 0x70, %o2 ! can use table? (clears carry btw)
  375. ccslow: cmp %g1, 0
  376. mov 0, %g5
  377. bleu 4f
  378. andcc %o0, 1, %o5
  379. be,a 1f
  380. srl %g1, 1, %g4
  381. sub %g1, 1, %g1
  382. EX(ldub [%o0], %g5, add %g1, 1)
  383. add %o0, 1, %o0
  384. EX2(stb %g5, [%o1])
  385. srl %g1, 1, %g4
  386. add %o1, 1, %o1
  387. 1: cmp %g4, 0
  388. be,a 3f
  389. andcc %g1, 1, %g0
  390. andcc %o0, 2, %g0
  391. be,a 1f
  392. srl %g4, 1, %g4
  393. EX(lduh [%o0], %o4, add %g1, 0)
  394. sub %g1, 2, %g1
  395. srl %o4, 8, %g2
  396. sub %g4, 1, %g4
  397. EX2(stb %g2, [%o1])
  398. add %o4, %g5, %g5
  399. EX2(stb %o4, [%o1 + 1])
  400. add %o0, 2, %o0
  401. srl %g4, 1, %g4
  402. add %o1, 2, %o1
  403. 1: cmp %g4, 0
  404. be,a 2f
  405. andcc %g1, 2, %g0
  406. EX3(ld [%o0], %o4)
  407. 5: srl %o4, 24, %g2
  408. srl %o4, 16, %g3
  409. EX2(stb %g2, [%o1])
  410. srl %o4, 8, %g2
  411. EX2(stb %g3, [%o1 + 1])
  412. add %o0, 4, %o0
  413. EX2(stb %g2, [%o1 + 2])
  414. addcc %o4, %g5, %g5
  415. EX2(stb %o4, [%o1 + 3])
  416. addx %g5, %g0, %g5 ! I am now to lazy to optimize this (question it
  417. add %o1, 4, %o1 ! is worthy). Maybe some day - with the sll/srl
  418. subcc %g4, 1, %g4 ! tricks
  419. bne,a 5b
  420. EX3(ld [%o0], %o4)
  421. sll %g5, 16, %g2
  422. srl %g5, 16, %g5
  423. srl %g2, 16, %g2
  424. andcc %g1, 2, %g0
  425. add %g2, %g5, %g5
  426. 2: be,a 3f
  427. andcc %g1, 1, %g0
  428. EX(lduh [%o0], %o4, and %g1, 3)
  429. andcc %g1, 1, %g0
  430. srl %o4, 8, %g2
  431. add %o0, 2, %o0
  432. EX2(stb %g2, [%o1])
  433. add %g5, %o4, %g5
  434. EX2(stb %o4, [%o1 + 1])
  435. add %o1, 2, %o1
  436. 3: be,a 1f
  437. sll %g5, 16, %o4
  438. EX(ldub [%o0], %g2, add %g0, 1)
  439. sll %g2, 8, %o4
  440. EX2(stb %g2, [%o1])
  441. add %g5, %o4, %g5
  442. sll %g5, 16, %o4
  443. 1: addcc %o4, %g5, %g5
  444. srl %g5, 16, %o4
  445. addx %g0, %o4, %g5
  446. orcc %o5, %g0, %g0
  447. be 4f
  448. srl %g5, 8, %o4
  449. and %g5, 0xff, %g2
  450. and %o4, 0xff, %o4
  451. sll %g2, 8, %g2
  452. or %g2, %o4, %g5
  453. 4: addcc %g7, %g5, %g7
  454. retl
  455. addx %g0, %g7, %o0
  456. __csum_partial_copy_end:
  457. /* We do these strange calculations for the csum_*_from_user case only, ie.
  458. * we only bother with faults on loads... */
  459. /* o2 = ((g2%20)&3)*8
  460. * o3 = g1 - (g2/20)*32 - o2 */
  461. 20:
  462. cmp %g2, 20
  463. blu,a 1f
  464. and %g2, 3, %o2
  465. sub %g1, 32, %g1
  466. b 20b
  467. sub %g2, 20, %g2
  468. 1:
  469. sll %o2, 3, %o2
  470. b 31f
  471. sub %g1, %o2, %o3
  472. /* o2 = (!(g2 & 15) ? 0 : (((g2 & 15) + 1) & ~1)*8)
  473. * o3 = g1 - (g2/16)*32 - o2 */
  474. 21:
  475. andcc %g2, 15, %o3
  476. srl %g2, 4, %g2
  477. be,a 1f
  478. clr %o2
  479. add %o3, 1, %o3
  480. and %o3, 14, %o3
  481. sll %o3, 3, %o2
  482. 1:
  483. sll %g2, 5, %g2
  484. sub %g1, %g2, %o3
  485. b 31f
  486. sub %o3, %o2, %o3
  487. /* o0 += (g2/10)*16 - 0x70
  488. * 01 += (g2/10)*16 - 0x70
  489. * o2 = (g2 % 10) ? 8 : 0
  490. * o3 += 0x70 - (g2/10)*16 - o2 */
  491. 22:
  492. cmp %g2, 10
  493. blu,a 1f
  494. sub %o0, 0x70, %o0
  495. add %o0, 16, %o0
  496. add %o1, 16, %o1
  497. sub %o3, 16, %o3
  498. b 22b
  499. sub %g2, 10, %g2
  500. 1:
  501. sub %o1, 0x70, %o1
  502. add %o3, 0x70, %o3
  503. clr %o2
  504. tst %g2
  505. bne,a 1f
  506. mov 8, %o2
  507. 1:
  508. b 31f
  509. sub %o3, %o2, %o3
  510. 96:
  511. and %g1, 3, %g1
  512. sll %g4, 2, %g4
  513. add %g1, %g4, %o3
  514. 30:
  515. /* %o1 is dst
  516. * %o3 is # bytes to zero out
  517. * %o4 is faulting address
  518. * %o5 is %pc where fault occurred */
  519. clr %o2
  520. 31:
  521. /* %o0 is src
  522. * %o1 is dst
  523. * %o2 is # of bytes to copy from src to dst
  524. * %o3 is # bytes to zero out
  525. * %o4 is faulting address
  526. * %o5 is %pc where fault occurred */
  527. save %sp, -104, %sp
  528. mov %i5, %o0
  529. mov %i7, %o1
  530. mov %i4, %o2
  531. call lookup_fault
  532. mov %g7, %i4
  533. cmp %o0, 2
  534. bne 1f
  535. add %g0, -EFAULT, %i5
  536. tst %i2
  537. be 2f
  538. mov %i0, %o1
  539. mov %i1, %o0
  540. 5:
  541. call __memcpy
  542. mov %i2, %o2
  543. tst %o0
  544. bne,a 2f
  545. add %i3, %i2, %i3
  546. add %i1, %i2, %i1
  547. 2:
  548. mov %i1, %o0
  549. 6:
  550. call __bzero
  551. mov %i3, %o1
  552. 1:
  553. ld [%sp + 168], %o2 ! struct_ptr of parent
  554. st %i5, [%o2]
  555. ret
  556. restore
  557. .section __ex_table,#alloc
  558. .align 4
  559. .word 5b,2
  560. .word 6b,2