csum_partial.S 16 KB

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