checksum_32.S 17 KB

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