checksum_32.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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, 16
  277. bge 1f
  278. srl %g1, 1, %o3
  279. 2: cmp %o3, 0
  280. be,a ccte
  281. andcc %g1, 0xf, %o3
  282. andcc %o3, %o0, %g0 ! Check %o0 only (%o1 has the same last 2 bits)
  283. be,a 2b
  284. srl %o3, 1, %o3
  285. 1: andcc %o0, 0x1, %g0
  286. bne ccslow
  287. andcc %o0, 0x2, %g0
  288. be 1f
  289. andcc %o0, 0x4, %g0
  290. EX(lduh [%o0 + 0x00], %g4, add %g1, 0)
  291. sub %g1, 2, %g1
  292. EX2(sth %g4, [%o1 + 0x00])
  293. add %o0, 2, %o0
  294. sll %g4, 16, %g4
  295. addcc %g4, %g7, %g7
  296. add %o1, 2, %o1
  297. srl %g7, 16, %g3
  298. addx %g0, %g3, %g4
  299. sll %g7, 16, %g7
  300. sll %g4, 16, %g3
  301. srl %g7, 16, %g7
  302. andcc %o0, 0x4, %g0
  303. or %g3, %g7, %g7
  304. 1: be 3f
  305. andcc %g1, 0xffffff80, %g0
  306. EX(ld [%o0 + 0x00], %g4, add %g1, 0)
  307. sub %g1, 4, %g1
  308. EX2(st %g4, [%o1 + 0x00])
  309. add %o0, 4, %o0
  310. addcc %g4, %g7, %g7
  311. add %o1, 4, %o1
  312. addx %g0, %g7, %g7
  313. b 3f
  314. andcc %g1, 0xffffff80, %g0
  315. /* Sun, you just can't beat me, you just can't. Stop trying,
  316. * give up. I'm serious, I am going to kick the living shit
  317. * out of you, game over, lights out.
  318. */
  319. .align 8
  320. .globl __csum_partial_copy_sparc_generic
  321. __csum_partial_copy_sparc_generic:
  322. /* %o0=src, %o1=dest, %g1=len, %g7=sum */
  323. xor %o0, %o1, %o4 ! get changing bits
  324. andcc %o4, 3, %g0 ! check for mismatched alignment
  325. bne ccslow ! better this than unaligned/fixups
  326. andcc %o0, 7, %g0 ! need to align things?
  327. bne cc_dword_align ! yes, we check for short lengths there
  328. andcc %g1, 0xffffff80, %g0 ! can we use unrolled loop?
  329. 3: be 3f ! nope, less than one loop remains
  330. andcc %o1, 4, %g0 ! dest aligned on 4 or 8 byte boundary?
  331. be ccdbl + 4 ! 8 byte aligned, kick ass
  332. 5: CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x00,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  333. CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x20,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  334. CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x40,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  335. CSUMCOPY_BIGCHUNK(%o0,%o1,%g7,0x60,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  336. 10: EXT(5b, 10b, 20f) ! note for exception handling
  337. sub %g1, 128, %g1 ! detract from length
  338. addx %g0, %g7, %g7 ! add in last carry bit
  339. andcc %g1, 0xffffff80, %g0 ! more to csum?
  340. add %o0, 128, %o0 ! advance src ptr
  341. bne 5b ! we did not go negative, continue looping
  342. add %o1, 128, %o1 ! advance dest ptr
  343. 3: andcc %g1, 0x70, %o2 ! can use table?
  344. ccmerge:be ccte ! nope, go and check for end cruft
  345. andcc %g1, 0xf, %o3 ! get low bits of length (clears carry btw)
  346. srl %o2, 1, %o4 ! begin negative offset computation
  347. sethi %hi(12f), %o5 ! set up table ptr end
  348. add %o0, %o2, %o0 ! advance src ptr
  349. sub %o5, %o4, %o5 ! continue table calculation
  350. sll %o2, 1, %g2 ! constant multiplies are fun...
  351. sub %o5, %g2, %o5 ! some more adjustments
  352. jmp %o5 + %lo(12f) ! jump into it, duff style, wheee...
  353. add %o1, %o2, %o1 ! advance dest ptr (carry is clear btw)
  354. cctbl: CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x68,%g2,%g3,%g4,%g5)
  355. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x58,%g2,%g3,%g4,%g5)
  356. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x48,%g2,%g3,%g4,%g5)
  357. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x38,%g2,%g3,%g4,%g5)
  358. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x28,%g2,%g3,%g4,%g5)
  359. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x18,%g2,%g3,%g4,%g5)
  360. CSUMCOPY_LASTCHUNK(%o0,%o1,%g7,0x08,%g2,%g3,%g4,%g5)
  361. 12: EXT(cctbl, 12b, 22f) ! note for exception table handling
  362. addx %g0, %g7, %g7
  363. andcc %o3, 0xf, %g0 ! check for low bits set
  364. ccte: bne cc_end_cruft ! something left, handle it out of band
  365. andcc %o3, 8, %g0 ! begin checks for that code
  366. retl ! return
  367. mov %g7, %o0 ! give em the computed checksum
  368. ccdbl: CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x00,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  369. CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x20,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  370. CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x40,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  371. CSUMCOPY_BIGCHUNK_ALIGNED(%o0,%o1,%g7,0x60,%o4,%o5,%g2,%g3,%g4,%g5,%o2,%o3)
  372. 11: EXT(ccdbl, 11b, 21f) ! note for exception table handling
  373. sub %g1, 128, %g1 ! detract from length
  374. addx %g0, %g7, %g7 ! add in last carry bit
  375. andcc %g1, 0xffffff80, %g0 ! more to csum?
  376. add %o0, 128, %o0 ! advance src ptr
  377. bne ccdbl ! we did not go negative, continue looping
  378. add %o1, 128, %o1 ! advance dest ptr
  379. b ccmerge ! finish it off, above
  380. andcc %g1, 0x70, %o2 ! can use table? (clears carry btw)
  381. ccslow: cmp %g1, 0
  382. mov 0, %g5
  383. bleu 4f
  384. andcc %o0, 1, %o5
  385. be,a 1f
  386. srl %g1, 1, %g4
  387. sub %g1, 1, %g1
  388. EX(ldub [%o0], %g5, add %g1, 1)
  389. add %o0, 1, %o0
  390. EX2(stb %g5, [%o1])
  391. srl %g1, 1, %g4
  392. add %o1, 1, %o1
  393. 1: cmp %g4, 0
  394. be,a 3f
  395. andcc %g1, 1, %g0
  396. andcc %o0, 2, %g0
  397. be,a 1f
  398. srl %g4, 1, %g4
  399. EX(lduh [%o0], %o4, add %g1, 0)
  400. sub %g1, 2, %g1
  401. srl %o4, 8, %g2
  402. sub %g4, 1, %g4
  403. EX2(stb %g2, [%o1])
  404. add %o4, %g5, %g5
  405. EX2(stb %o4, [%o1 + 1])
  406. add %o0, 2, %o0
  407. srl %g4, 1, %g4
  408. add %o1, 2, %o1
  409. 1: cmp %g4, 0
  410. be,a 2f
  411. andcc %g1, 2, %g0
  412. EX3(ld [%o0], %o4)
  413. 5: srl %o4, 24, %g2
  414. srl %o4, 16, %g3
  415. EX2(stb %g2, [%o1])
  416. srl %o4, 8, %g2
  417. EX2(stb %g3, [%o1 + 1])
  418. add %o0, 4, %o0
  419. EX2(stb %g2, [%o1 + 2])
  420. addcc %o4, %g5, %g5
  421. EX2(stb %o4, [%o1 + 3])
  422. addx %g5, %g0, %g5 ! I am now to lazy to optimize this (question it
  423. add %o1, 4, %o1 ! is worthy). Maybe some day - with the sll/srl
  424. subcc %g4, 1, %g4 ! tricks
  425. bne,a 5b
  426. EX3(ld [%o0], %o4)
  427. sll %g5, 16, %g2
  428. srl %g5, 16, %g5
  429. srl %g2, 16, %g2
  430. andcc %g1, 2, %g0
  431. add %g2, %g5, %g5
  432. 2: be,a 3f
  433. andcc %g1, 1, %g0
  434. EX(lduh [%o0], %o4, and %g1, 3)
  435. andcc %g1, 1, %g0
  436. srl %o4, 8, %g2
  437. add %o0, 2, %o0
  438. EX2(stb %g2, [%o1])
  439. add %g5, %o4, %g5
  440. EX2(stb %o4, [%o1 + 1])
  441. add %o1, 2, %o1
  442. 3: be,a 1f
  443. sll %g5, 16, %o4
  444. EX(ldub [%o0], %g2, add %g0, 1)
  445. sll %g2, 8, %o4
  446. EX2(stb %g2, [%o1])
  447. add %g5, %o4, %g5
  448. sll %g5, 16, %o4
  449. 1: addcc %o4, %g5, %g5
  450. srl %g5, 16, %o4
  451. addx %g0, %o4, %g5
  452. orcc %o5, %g0, %g0
  453. be 4f
  454. srl %g5, 8, %o4
  455. and %g5, 0xff, %g2
  456. and %o4, 0xff, %o4
  457. sll %g2, 8, %g2
  458. or %g2, %o4, %g5
  459. 4: addcc %g7, %g5, %g7
  460. retl
  461. addx %g0, %g7, %o0
  462. __csum_partial_copy_end:
  463. /* We do these strange calculations for the csum_*_from_user case only, ie.
  464. * we only bother with faults on loads... */
  465. /* o2 = ((g2%20)&3)*8
  466. * o3 = g1 - (g2/20)*32 - o2 */
  467. 20:
  468. cmp %g2, 20
  469. blu,a 1f
  470. and %g2, 3, %o2
  471. sub %g1, 32, %g1
  472. b 20b
  473. sub %g2, 20, %g2
  474. 1:
  475. sll %o2, 3, %o2
  476. b 31f
  477. sub %g1, %o2, %o3
  478. /* o2 = (!(g2 & 15) ? 0 : (((g2 & 15) + 1) & ~1)*8)
  479. * o3 = g1 - (g2/16)*32 - o2 */
  480. 21:
  481. andcc %g2, 15, %o3
  482. srl %g2, 4, %g2
  483. be,a 1f
  484. clr %o2
  485. add %o3, 1, %o3
  486. and %o3, 14, %o3
  487. sll %o3, 3, %o2
  488. 1:
  489. sll %g2, 5, %g2
  490. sub %g1, %g2, %o3
  491. b 31f
  492. sub %o3, %o2, %o3
  493. /* o0 += (g2/10)*16 - 0x70
  494. * 01 += (g2/10)*16 - 0x70
  495. * o2 = (g2 % 10) ? 8 : 0
  496. * o3 += 0x70 - (g2/10)*16 - o2 */
  497. 22:
  498. cmp %g2, 10
  499. blu,a 1f
  500. sub %o0, 0x70, %o0
  501. add %o0, 16, %o0
  502. add %o1, 16, %o1
  503. sub %o3, 16, %o3
  504. b 22b
  505. sub %g2, 10, %g2
  506. 1:
  507. sub %o1, 0x70, %o1
  508. add %o3, 0x70, %o3
  509. clr %o2
  510. tst %g2
  511. bne,a 1f
  512. mov 8, %o2
  513. 1:
  514. b 31f
  515. sub %o3, %o2, %o3
  516. 96:
  517. and %g1, 3, %g1
  518. sll %g4, 2, %g4
  519. add %g1, %g4, %o3
  520. 30:
  521. /* %o1 is dst
  522. * %o3 is # bytes to zero out
  523. * %o4 is faulting address
  524. * %o5 is %pc where fault occurred */
  525. clr %o2
  526. 31:
  527. /* %o0 is src
  528. * %o1 is dst
  529. * %o2 is # of bytes to copy from src to dst
  530. * %o3 is # bytes to zero out
  531. * %o4 is faulting address
  532. * %o5 is %pc where fault occurred */
  533. save %sp, -104, %sp
  534. mov %i5, %o0
  535. mov %i7, %o1
  536. mov %i4, %o2
  537. call lookup_fault
  538. mov %g7, %i4
  539. cmp %o0, 2
  540. bne 1f
  541. add %g0, -EFAULT, %i5
  542. tst %i2
  543. be 2f
  544. mov %i0, %o1
  545. mov %i1, %o0
  546. 5:
  547. call memcpy
  548. mov %i2, %o2
  549. tst %o0
  550. bne,a 2f
  551. add %i3, %i2, %i3
  552. add %i1, %i2, %i1
  553. 2:
  554. mov %i1, %o0
  555. 6:
  556. call __bzero
  557. mov %i3, %o1
  558. 1:
  559. ld [%sp + 168], %o2 ! struct_ptr of parent
  560. st %i5, [%o2]
  561. ret
  562. restore
  563. .section __ex_table,#alloc
  564. .align 4
  565. .word 5b,2
  566. .word 6b,2