checksum_32.S 17 KB

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