strncpy_from_user.S 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * linux/arch/unicore32/lib/strncpy_from_user.S
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/linkage.h>
  13. #include <asm/assembler.h>
  14. #include <asm/errno.h>
  15. .text
  16. .align 5
  17. /*
  18. * Copy a string from user space to kernel space.
  19. * r0 = dst, r1 = src, r2 = byte length
  20. * returns the number of characters copied (strlen of copied string),
  21. * -EFAULT on exception, or "len" if we fill the whole buffer
  22. */
  23. ENTRY(__strncpy_from_user)
  24. mov ip, r1
  25. 1: sub.a r2, r2, #1
  26. ldrusr r3, r1, 1, ns
  27. bfs 2f
  28. stb.w r3, [r0]+, #1
  29. cxor.a r3, #0
  30. bne 1b
  31. sub r1, r1, #1 @ take NUL character out of count
  32. 2: sub r0, r1, ip
  33. mov pc, lr
  34. ENDPROC(__strncpy_from_user)
  35. .pushsection .fixup,"ax"
  36. .align 0
  37. 9001: mov r3, #0
  38. stb r3, [r0+], #0 @ null terminate
  39. mov r0, #-EFAULT
  40. mov pc, lr
  41. .popsection