csum_partial.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Quick'n'dirty IP checksum ...
  7. *
  8. * Copyright (C) 1998, 1999 Ralf Baechle
  9. * Copyright (C) 1999 Silicon Graphics, Inc.
  10. */
  11. #include <linux/errno.h>
  12. #include <asm/asm.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/regdef.h>
  15. #ifdef CONFIG_64BIT
  16. /*
  17. * As we are sharing code base with the mips32 tree (which use the o32 ABI
  18. * register definitions). We need to redefine the register definitions from
  19. * the n64 ABI register naming to the o32 ABI register naming.
  20. */
  21. #undef t0
  22. #undef t1
  23. #undef t2
  24. #undef t3
  25. #define t0 $8
  26. #define t1 $9
  27. #define t2 $10
  28. #define t3 $11
  29. #define t4 $12
  30. #define t5 $13
  31. #define t6 $14
  32. #define t7 $15
  33. #define USE_DOUBLE
  34. #endif
  35. #ifdef USE_DOUBLE
  36. #define LOAD ld
  37. #define ADD daddu
  38. #define NBYTES 8
  39. #else
  40. #define LOAD lw
  41. #define ADD addu
  42. #define NBYTES 4
  43. #endif /* USE_DOUBLE */
  44. #define UNIT(unit) ((unit)*NBYTES)
  45. #define ADDC(sum,reg) \
  46. ADD sum, reg; \
  47. sltu v1, sum, reg; \
  48. ADD sum, v1
  49. #define CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3) \
  50. LOAD _t0, (offset + UNIT(0))(src); \
  51. LOAD _t1, (offset + UNIT(1))(src); \
  52. LOAD _t2, (offset + UNIT(2))(src); \
  53. LOAD _t3, (offset + UNIT(3))(src); \
  54. ADDC(sum, _t0); \
  55. ADDC(sum, _t1); \
  56. ADDC(sum, _t2); \
  57. ADDC(sum, _t3)
  58. #ifdef USE_DOUBLE
  59. #define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \
  60. CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3)
  61. #else
  62. #define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \
  63. CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3); \
  64. CSUM_BIGCHUNK1(src, offset + 0x10, sum, _t0, _t1, _t2, _t3)
  65. #endif
  66. /*
  67. * a0: source address
  68. * a1: length of the area to checksum
  69. * a2: partial checksum
  70. */
  71. #define src a0
  72. #define sum v0
  73. .text
  74. .set noreorder
  75. .align 5
  76. LEAF(csum_partial)
  77. move sum, zero
  78. move t7, zero
  79. sltiu t8, a1, 0x8
  80. bnez t8, small_csumcpy /* < 8 bytes to copy */
  81. move t2, a1
  82. andi t7, src, 0x1 /* odd buffer? */
  83. hword_align:
  84. beqz t7, word_align
  85. andi t8, src, 0x2
  86. lbu t0, (src)
  87. LONG_SUBU a1, a1, 0x1
  88. #ifdef __MIPSEL__
  89. sll t0, t0, 8
  90. #endif
  91. ADDC(sum, t0)
  92. PTR_ADDU src, src, 0x1
  93. andi t8, src, 0x2
  94. word_align:
  95. beqz t8, dword_align
  96. sltiu t8, a1, 56
  97. lhu t0, (src)
  98. LONG_SUBU a1, a1, 0x2
  99. ADDC(sum, t0)
  100. sltiu t8, a1, 56
  101. PTR_ADDU src, src, 0x2
  102. dword_align:
  103. bnez t8, do_end_words
  104. move t8, a1
  105. andi t8, src, 0x4
  106. beqz t8, qword_align
  107. andi t8, src, 0x8
  108. lw t0, 0x00(src)
  109. LONG_SUBU a1, a1, 0x4
  110. ADDC(sum, t0)
  111. PTR_ADDU src, src, 0x4
  112. andi t8, src, 0x8
  113. qword_align:
  114. beqz t8, oword_align
  115. andi t8, src, 0x10
  116. #ifdef USE_DOUBLE
  117. ld t0, 0x00(src)
  118. LONG_SUBU a1, a1, 0x8
  119. ADDC(sum, t0)
  120. #else
  121. lw t0, 0x00(src)
  122. lw t1, 0x04(src)
  123. LONG_SUBU a1, a1, 0x8
  124. ADDC(sum, t0)
  125. ADDC(sum, t1)
  126. #endif
  127. PTR_ADDU src, src, 0x8
  128. andi t8, src, 0x10
  129. oword_align:
  130. beqz t8, begin_movement
  131. LONG_SRL t8, a1, 0x7
  132. #ifdef USE_DOUBLE
  133. ld t0, 0x00(src)
  134. ld t1, 0x08(src)
  135. ADDC(sum, t0)
  136. ADDC(sum, t1)
  137. #else
  138. CSUM_BIGCHUNK1(src, 0x00, sum, t0, t1, t3, t4)
  139. #endif
  140. LONG_SUBU a1, a1, 0x10
  141. PTR_ADDU src, src, 0x10
  142. LONG_SRL t8, a1, 0x7
  143. begin_movement:
  144. beqz t8, 1f
  145. andi t2, a1, 0x40
  146. move_128bytes:
  147. CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4)
  148. CSUM_BIGCHUNK(src, 0x20, sum, t0, t1, t3, t4)
  149. CSUM_BIGCHUNK(src, 0x40, sum, t0, t1, t3, t4)
  150. CSUM_BIGCHUNK(src, 0x60, sum, t0, t1, t3, t4)
  151. LONG_SUBU t8, t8, 0x01
  152. bnez t8, move_128bytes
  153. PTR_ADDU src, src, 0x80
  154. 1:
  155. beqz t2, 1f
  156. andi t2, a1, 0x20
  157. move_64bytes:
  158. CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4)
  159. CSUM_BIGCHUNK(src, 0x20, sum, t0, t1, t3, t4)
  160. PTR_ADDU src, src, 0x40
  161. 1:
  162. beqz t2, do_end_words
  163. andi t8, a1, 0x1c
  164. move_32bytes:
  165. CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4)
  166. andi t8, a1, 0x1c
  167. PTR_ADDU src, src, 0x20
  168. do_end_words:
  169. beqz t8, small_csumcpy
  170. andi t2, a1, 0x3
  171. LONG_SRL t8, t8, 0x2
  172. end_words:
  173. lw t0, (src)
  174. LONG_SUBU t8, t8, 0x1
  175. ADDC(sum, t0)
  176. bnez t8, end_words
  177. PTR_ADDU src, src, 0x4
  178. /* unknown src alignment and < 8 bytes to go */
  179. small_csumcpy:
  180. move a1, t2
  181. andi t0, a1, 4
  182. beqz t0, 1f
  183. andi t0, a1, 2
  184. /* Still a full word to go */
  185. ulw t1, (src)
  186. PTR_ADDIU src, 4
  187. ADDC(sum, t1)
  188. 1: move t1, zero
  189. beqz t0, 1f
  190. andi t0, a1, 1
  191. /* Still a halfword to go */
  192. ulhu t1, (src)
  193. PTR_ADDIU src, 2
  194. 1: beqz t0, 1f
  195. sll t1, t1, 16
  196. lbu t2, (src)
  197. nop
  198. #ifdef __MIPSEB__
  199. sll t2, t2, 8
  200. #endif
  201. or t1, t2
  202. 1: ADDC(sum, t1)
  203. /* fold checksum */
  204. #ifdef USE_DOUBLE
  205. dsll32 v1, sum, 0
  206. daddu sum, v1
  207. sltu v1, sum, v1
  208. dsra32 sum, sum, 0
  209. addu sum, v1
  210. #endif
  211. sll v1, sum, 16
  212. addu sum, v1
  213. sltu v1, sum, v1
  214. srl sum, sum, 16
  215. addu sum, v1
  216. /* odd buffer alignment? */
  217. beqz t7, 1f
  218. nop
  219. sll v1, sum, 8
  220. srl sum, sum, 8
  221. or sum, v1
  222. andi sum, 0xffff
  223. 1:
  224. .set reorder
  225. /* Add the passed partial csum. */
  226. ADDC(sum, a2)
  227. jr ra
  228. .set noreorder
  229. END(csum_partial)
  230. /*
  231. * checksum and copy routines based on memcpy.S
  232. *
  233. * csum_partial_copy_nocheck(src, dst, len, sum)
  234. * __csum_partial_copy_user(src, dst, len, sum, errp)
  235. *
  236. * See "Spec" in memcpy.S for details. Unlike __copy_user, all
  237. * function in this file use the standard calling convention.
  238. */
  239. #define src a0
  240. #define dst a1
  241. #define len a2
  242. #define psum a3
  243. #define sum v0
  244. #define odd t8
  245. #define errptr t9
  246. /*
  247. * The exception handler for loads requires that:
  248. * 1- AT contain the address of the byte just past the end of the source
  249. * of the copy,
  250. * 2- src_entry <= src < AT, and
  251. * 3- (dst - src) == (dst_entry - src_entry),
  252. * The _entry suffix denotes values when __copy_user was called.
  253. *
  254. * (1) is set up up by __csum_partial_copy_from_user and maintained by
  255. * not writing AT in __csum_partial_copy
  256. * (2) is met by incrementing src by the number of bytes copied
  257. * (3) is met by not doing loads between a pair of increments of dst and src
  258. *
  259. * The exception handlers for stores stores -EFAULT to errptr and return.
  260. * These handlers do not need to overwrite any data.
  261. */
  262. #define EXC(inst_reg,addr,handler) \
  263. 9: inst_reg, addr; \
  264. .section __ex_table,"a"; \
  265. PTR 9b, handler; \
  266. .previous
  267. #ifdef USE_DOUBLE
  268. #define LOAD ld
  269. #define LOADL ldl
  270. #define LOADR ldr
  271. #define STOREL sdl
  272. #define STORER sdr
  273. #define STORE sd
  274. #define ADD daddu
  275. #define SUB dsubu
  276. #define SRL dsrl
  277. #define SLL dsll
  278. #define SLLV dsllv
  279. #define SRLV dsrlv
  280. #define NBYTES 8
  281. #define LOG_NBYTES 3
  282. #else
  283. #define LOAD lw
  284. #define LOADL lwl
  285. #define LOADR lwr
  286. #define STOREL swl
  287. #define STORER swr
  288. #define STORE sw
  289. #define ADD addu
  290. #define SUB subu
  291. #define SRL srl
  292. #define SLL sll
  293. #define SLLV sllv
  294. #define SRLV srlv
  295. #define NBYTES 4
  296. #define LOG_NBYTES 2
  297. #endif /* USE_DOUBLE */
  298. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  299. #define LDFIRST LOADR
  300. #define LDREST LOADL
  301. #define STFIRST STORER
  302. #define STREST STOREL
  303. #define SHIFT_DISCARD SLLV
  304. #define SHIFT_DISCARD_REVERT SRLV
  305. #else
  306. #define LDFIRST LOADL
  307. #define LDREST LOADR
  308. #define STFIRST STOREL
  309. #define STREST STORER
  310. #define SHIFT_DISCARD SRLV
  311. #define SHIFT_DISCARD_REVERT SLLV
  312. #endif
  313. #define FIRST(unit) ((unit)*NBYTES)
  314. #define REST(unit) (FIRST(unit)+NBYTES-1)
  315. #define ADDRMASK (NBYTES-1)
  316. .set noat
  317. LEAF(__csum_partial_copy_user)
  318. PTR_ADDU AT, src, len /* See (1) above. */
  319. #ifdef CONFIG_64BIT
  320. move errptr, a4
  321. #else
  322. lw errptr, 16(sp)
  323. #endif
  324. FEXPORT(csum_partial_copy_nocheck)
  325. move sum, zero
  326. move odd, zero
  327. /*
  328. * Note: dst & src may be unaligned, len may be 0
  329. * Temps
  330. */
  331. /*
  332. * The "issue break"s below are very approximate.
  333. * Issue delays for dcache fills will perturb the schedule, as will
  334. * load queue full replay traps, etc.
  335. *
  336. * If len < NBYTES use byte operations.
  337. */
  338. sltu t2, len, NBYTES
  339. and t1, dst, ADDRMASK
  340. bnez t2, copy_bytes_checklen
  341. and t0, src, ADDRMASK
  342. andi odd, dst, 0x1 /* odd buffer? */
  343. bnez t1, dst_unaligned
  344. nop
  345. bnez t0, src_unaligned_dst_aligned
  346. /*
  347. * use delay slot for fall-through
  348. * src and dst are aligned; need to compute rem
  349. */
  350. both_aligned:
  351. SRL t0, len, LOG_NBYTES+3 # +3 for 8 units/iter
  352. beqz t0, cleanup_both_aligned # len < 8*NBYTES
  353. nop
  354. SUB len, 8*NBYTES # subtract here for bgez loop
  355. .align 4
  356. 1:
  357. EXC( LOAD t0, UNIT(0)(src), l_exc)
  358. EXC( LOAD t1, UNIT(1)(src), l_exc_copy)
  359. EXC( LOAD t2, UNIT(2)(src), l_exc_copy)
  360. EXC( LOAD t3, UNIT(3)(src), l_exc_copy)
  361. EXC( LOAD t4, UNIT(4)(src), l_exc_copy)
  362. EXC( LOAD t5, UNIT(5)(src), l_exc_copy)
  363. EXC( LOAD t6, UNIT(6)(src), l_exc_copy)
  364. EXC( LOAD t7, UNIT(7)(src), l_exc_copy)
  365. SUB len, len, 8*NBYTES
  366. ADD src, src, 8*NBYTES
  367. EXC( STORE t0, UNIT(0)(dst), s_exc)
  368. ADDC(sum, t0)
  369. EXC( STORE t1, UNIT(1)(dst), s_exc)
  370. ADDC(sum, t1)
  371. EXC( STORE t2, UNIT(2)(dst), s_exc)
  372. ADDC(sum, t2)
  373. EXC( STORE t3, UNIT(3)(dst), s_exc)
  374. ADDC(sum, t3)
  375. EXC( STORE t4, UNIT(4)(dst), s_exc)
  376. ADDC(sum, t4)
  377. EXC( STORE t5, UNIT(5)(dst), s_exc)
  378. ADDC(sum, t5)
  379. EXC( STORE t6, UNIT(6)(dst), s_exc)
  380. ADDC(sum, t6)
  381. EXC( STORE t7, UNIT(7)(dst), s_exc)
  382. ADDC(sum, t7)
  383. bgez len, 1b
  384. ADD dst, dst, 8*NBYTES
  385. ADD len, 8*NBYTES # revert len (see above)
  386. /*
  387. * len == the number of bytes left to copy < 8*NBYTES
  388. */
  389. cleanup_both_aligned:
  390. #define rem t7
  391. beqz len, done
  392. sltu t0, len, 4*NBYTES
  393. bnez t0, less_than_4units
  394. and rem, len, (NBYTES-1) # rem = len % NBYTES
  395. /*
  396. * len >= 4*NBYTES
  397. */
  398. EXC( LOAD t0, UNIT(0)(src), l_exc)
  399. EXC( LOAD t1, UNIT(1)(src), l_exc_copy)
  400. EXC( LOAD t2, UNIT(2)(src), l_exc_copy)
  401. EXC( LOAD t3, UNIT(3)(src), l_exc_copy)
  402. SUB len, len, 4*NBYTES
  403. ADD src, src, 4*NBYTES
  404. EXC( STORE t0, UNIT(0)(dst), s_exc)
  405. ADDC(sum, t0)
  406. EXC( STORE t1, UNIT(1)(dst), s_exc)
  407. ADDC(sum, t1)
  408. EXC( STORE t2, UNIT(2)(dst), s_exc)
  409. ADDC(sum, t2)
  410. EXC( STORE t3, UNIT(3)(dst), s_exc)
  411. ADDC(sum, t3)
  412. beqz len, done
  413. ADD dst, dst, 4*NBYTES
  414. less_than_4units:
  415. /*
  416. * rem = len % NBYTES
  417. */
  418. beq rem, len, copy_bytes
  419. nop
  420. 1:
  421. EXC( LOAD t0, 0(src), l_exc)
  422. ADD src, src, NBYTES
  423. SUB len, len, NBYTES
  424. EXC( STORE t0, 0(dst), s_exc)
  425. ADDC(sum, t0)
  426. bne rem, len, 1b
  427. ADD dst, dst, NBYTES
  428. /*
  429. * src and dst are aligned, need to copy rem bytes (rem < NBYTES)
  430. * A loop would do only a byte at a time with possible branch
  431. * mispredicts. Can't do an explicit LOAD dst,mask,or,STORE
  432. * because can't assume read-access to dst. Instead, use
  433. * STREST dst, which doesn't require read access to dst.
  434. *
  435. * This code should perform better than a simple loop on modern,
  436. * wide-issue mips processors because the code has fewer branches and
  437. * more instruction-level parallelism.
  438. */
  439. #define bits t2
  440. beqz len, done
  441. ADD t1, dst, len # t1 is just past last byte of dst
  442. li bits, 8*NBYTES
  443. SLL rem, len, 3 # rem = number of bits to keep
  444. EXC( LOAD t0, 0(src), l_exc)
  445. SUB bits, bits, rem # bits = number of bits to discard
  446. SHIFT_DISCARD t0, t0, bits
  447. EXC( STREST t0, -1(t1), s_exc)
  448. SHIFT_DISCARD_REVERT t0, t0, bits
  449. .set reorder
  450. ADDC(sum, t0)
  451. b done
  452. .set noreorder
  453. dst_unaligned:
  454. /*
  455. * dst is unaligned
  456. * t0 = src & ADDRMASK
  457. * t1 = dst & ADDRMASK; T1 > 0
  458. * len >= NBYTES
  459. *
  460. * Copy enough bytes to align dst
  461. * Set match = (src and dst have same alignment)
  462. */
  463. #define match rem
  464. EXC( LDFIRST t3, FIRST(0)(src), l_exc)
  465. ADD t2, zero, NBYTES
  466. EXC( LDREST t3, REST(0)(src), l_exc_copy)
  467. SUB t2, t2, t1 # t2 = number of bytes copied
  468. xor match, t0, t1
  469. EXC( STFIRST t3, FIRST(0)(dst), s_exc)
  470. SLL t4, t1, 3 # t4 = number of bits to discard
  471. SHIFT_DISCARD t3, t3, t4
  472. /* no SHIFT_DISCARD_REVERT to handle odd buffer properly */
  473. ADDC(sum, t3)
  474. beq len, t2, done
  475. SUB len, len, t2
  476. ADD dst, dst, t2
  477. beqz match, both_aligned
  478. ADD src, src, t2
  479. src_unaligned_dst_aligned:
  480. SRL t0, len, LOG_NBYTES+2 # +2 for 4 units/iter
  481. beqz t0, cleanup_src_unaligned
  482. and rem, len, (4*NBYTES-1) # rem = len % 4*NBYTES
  483. 1:
  484. /*
  485. * Avoid consecutive LD*'s to the same register since some mips
  486. * implementations can't issue them in the same cycle.
  487. * It's OK to load FIRST(N+1) before REST(N) because the two addresses
  488. * are to the same unit (unless src is aligned, but it's not).
  489. */
  490. EXC( LDFIRST t0, FIRST(0)(src), l_exc)
  491. EXC( LDFIRST t1, FIRST(1)(src), l_exc_copy)
  492. SUB len, len, 4*NBYTES
  493. EXC( LDREST t0, REST(0)(src), l_exc_copy)
  494. EXC( LDREST t1, REST(1)(src), l_exc_copy)
  495. EXC( LDFIRST t2, FIRST(2)(src), l_exc_copy)
  496. EXC( LDFIRST t3, FIRST(3)(src), l_exc_copy)
  497. EXC( LDREST t2, REST(2)(src), l_exc_copy)
  498. EXC( LDREST t3, REST(3)(src), l_exc_copy)
  499. ADD src, src, 4*NBYTES
  500. #ifdef CONFIG_CPU_SB1
  501. nop # improves slotting
  502. #endif
  503. EXC( STORE t0, UNIT(0)(dst), s_exc)
  504. ADDC(sum, t0)
  505. EXC( STORE t1, UNIT(1)(dst), s_exc)
  506. ADDC(sum, t1)
  507. EXC( STORE t2, UNIT(2)(dst), s_exc)
  508. ADDC(sum, t2)
  509. EXC( STORE t3, UNIT(3)(dst), s_exc)
  510. ADDC(sum, t3)
  511. bne len, rem, 1b
  512. ADD dst, dst, 4*NBYTES
  513. cleanup_src_unaligned:
  514. beqz len, done
  515. and rem, len, NBYTES-1 # rem = len % NBYTES
  516. beq rem, len, copy_bytes
  517. nop
  518. 1:
  519. EXC( LDFIRST t0, FIRST(0)(src), l_exc)
  520. EXC( LDREST t0, REST(0)(src), l_exc_copy)
  521. ADD src, src, NBYTES
  522. SUB len, len, NBYTES
  523. EXC( STORE t0, 0(dst), s_exc)
  524. ADDC(sum, t0)
  525. bne len, rem, 1b
  526. ADD dst, dst, NBYTES
  527. copy_bytes_checklen:
  528. beqz len, done
  529. nop
  530. copy_bytes:
  531. /* 0 < len < NBYTES */
  532. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  533. #define SHIFT_START 0
  534. #define SHIFT_INC 8
  535. #else
  536. #define SHIFT_START 8*(NBYTES-1)
  537. #define SHIFT_INC -8
  538. #endif
  539. move t2, zero # partial word
  540. li t3, SHIFT_START # shift
  541. /* use l_exc_copy here to return correct sum on fault */
  542. #define COPY_BYTE(N) \
  543. EXC( lbu t0, N(src), l_exc_copy); \
  544. SUB len, len, 1; \
  545. EXC( sb t0, N(dst), s_exc); \
  546. SLLV t0, t0, t3; \
  547. addu t3, SHIFT_INC; \
  548. beqz len, copy_bytes_done; \
  549. or t2, t0
  550. COPY_BYTE(0)
  551. COPY_BYTE(1)
  552. #ifdef USE_DOUBLE
  553. COPY_BYTE(2)
  554. COPY_BYTE(3)
  555. COPY_BYTE(4)
  556. COPY_BYTE(5)
  557. #endif
  558. EXC( lbu t0, NBYTES-2(src), l_exc_copy)
  559. SUB len, len, 1
  560. EXC( sb t0, NBYTES-2(dst), s_exc)
  561. SLLV t0, t0, t3
  562. or t2, t0
  563. copy_bytes_done:
  564. ADDC(sum, t2)
  565. done:
  566. /* fold checksum */
  567. #ifdef USE_DOUBLE
  568. dsll32 v1, sum, 0
  569. daddu sum, v1
  570. sltu v1, sum, v1
  571. dsra32 sum, sum, 0
  572. addu sum, v1
  573. #endif
  574. sll v1, sum, 16
  575. addu sum, v1
  576. sltu v1, sum, v1
  577. srl sum, sum, 16
  578. addu sum, v1
  579. /* odd buffer alignment? */
  580. beqz odd, 1f
  581. nop
  582. sll v1, sum, 8
  583. srl sum, sum, 8
  584. or sum, v1
  585. andi sum, 0xffff
  586. 1:
  587. .set reorder
  588. ADDC(sum, psum)
  589. jr ra
  590. .set noreorder
  591. l_exc_copy:
  592. /*
  593. * Copy bytes from src until faulting load address (or until a
  594. * lb faults)
  595. *
  596. * When reached by a faulting LDFIRST/LDREST, THREAD_BUADDR($28)
  597. * may be more than a byte beyond the last address.
  598. * Hence, the lb below may get an exception.
  599. *
  600. * Assumes src < THREAD_BUADDR($28)
  601. */
  602. LOAD t0, TI_TASK($28)
  603. li t2, SHIFT_START
  604. LOAD t0, THREAD_BUADDR(t0)
  605. 1:
  606. EXC( lbu t1, 0(src), l_exc)
  607. ADD src, src, 1
  608. sb t1, 0(dst) # can't fault -- we're copy_from_user
  609. SLLV t1, t1, t2
  610. addu t2, SHIFT_INC
  611. ADDC(sum, t1)
  612. bne src, t0, 1b
  613. ADD dst, dst, 1
  614. l_exc:
  615. LOAD t0, TI_TASK($28)
  616. nop
  617. LOAD t0, THREAD_BUADDR(t0) # t0 is just past last good address
  618. nop
  619. SUB len, AT, t0 # len number of uncopied bytes
  620. /*
  621. * Here's where we rely on src and dst being incremented in tandem,
  622. * See (3) above.
  623. * dst += (fault addr - src) to put dst at first byte to clear
  624. */
  625. ADD dst, t0 # compute start address in a1
  626. SUB dst, src
  627. /*
  628. * Clear len bytes starting at dst. Can't call __bzero because it
  629. * might modify len. An inefficient loop for these rare times...
  630. */
  631. beqz len, done
  632. SUB src, len, 1
  633. 1: sb zero, 0(dst)
  634. ADD dst, dst, 1
  635. bnez src, 1b
  636. SUB src, src, 1
  637. li v1, -EFAULT
  638. b done
  639. sw v1, (errptr)
  640. s_exc:
  641. li v0, -1 /* invalid checksum */
  642. li v1, -EFAULT
  643. jr ra
  644. sw v1, (errptr)
  645. END(__csum_partial_copy_user)