csum_partial_copy_generic.S 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <asm/errno.h>
  9. #include <asm/asm.h>
  10. /*
  11. * unsigned int csum_partial_copy_generic(const char *src, char *dst, int len
  12. * int sum, int *src_err_ptr,
  13. * int *dst_err_ptr)
  14. *
  15. * Copy src to dst while checksumming, otherwise like csum_partial.
  16. */
  17. .macro ld_src size, reg, ptr
  18. 9999: ld.\size \reg, \ptr
  19. .section __ex_table, "a"
  20. .long 9999b, fixup_ld_src
  21. .previous
  22. .endm
  23. .macro st_dst size, ptr, reg
  24. 9999: st.\size \ptr, \reg
  25. .section __ex_table, "a"
  26. .long 9999b, fixup_st_dst
  27. .previous
  28. .endm
  29. .text
  30. .global csum_partial_copy_generic
  31. .type csum_partial_copy_generic,"function"
  32. .align 1
  33. csum_partial_copy_generic:
  34. pushm r4-r7,lr
  35. /* The inner loop */
  36. 1: sub r10, 4
  37. brlt 5f
  38. 2: ld_src w, r5, r12++
  39. st_dst w, r11++, r5
  40. add r9, r5
  41. acr r9
  42. sub r10, 4
  43. brge 2b
  44. /* return if we had a whole number of words */
  45. 5: sub r10, -4
  46. brne 7f
  47. 6: mov r12, r9
  48. popm r4-r7,pc
  49. /* handle additional bytes at the tail */
  50. 7: mov r5, 0
  51. mov r4, 32
  52. 8: ld_src ub, r6, r12++
  53. st_dst b, r11++, r6
  54. lsl r5, 8
  55. sub r4, 8
  56. bfins r5, r6, 0, 8
  57. sub r10, 1
  58. brne 8b
  59. lsl r5, r5, r4
  60. add r9, r5
  61. acr r9
  62. rjmp 6b
  63. /* Exception handler */
  64. .section .fixup,"ax"
  65. .align 1
  66. fixup_ld_src:
  67. mov r9, -EFAULT
  68. cp.w r8, 0
  69. breq 1f
  70. st.w r8[0], r9
  71. 1: /*
  72. * TODO: zero the complete destination - computing the rest
  73. * is too much work
  74. */
  75. mov r9, 0
  76. rjmp 6b
  77. fixup_st_dst:
  78. mov r9, -EFAULT
  79. lddsp r8, sp[20]
  80. cp.w r8, 0
  81. breq 1f
  82. st.w r8[0], r9
  83. 1: mov r9, 0
  84. rjmp 6b
  85. .previous