mem.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * String handling functions.
  3. *
  4. * Copyright IBM Corp. 2012
  5. */
  6. #include <linux/linkage.h>
  7. #include <asm/export.h>
  8. #include <asm/nospec-insn.h>
  9. GEN_BR_THUNK %r14
  10. /*
  11. * memset implementation
  12. *
  13. * This code corresponds to the C construct below. We do distinguish
  14. * between clearing (c == 0) and setting a memory array (c != 0) simply
  15. * because nearly all memset invocations in the kernel clear memory and
  16. * the xc instruction is preferred in such cases.
  17. *
  18. * void *memset(void *s, int c, size_t n)
  19. * {
  20. * if (likely(c == 0))
  21. * return __builtin_memset(s, 0, n);
  22. * return __builtin_memset(s, c, n);
  23. * }
  24. */
  25. ENTRY(memset)
  26. ltgr %r4,%r4
  27. bzr %r14
  28. ltgr %r3,%r3
  29. jnz .Lmemset_fill
  30. aghi %r4,-1
  31. srlg %r3,%r4,8
  32. ltgr %r3,%r3
  33. lgr %r1,%r2
  34. jz .Lmemset_clear_rest
  35. .Lmemset_clear_loop:
  36. xc 0(256,%r1),0(%r1)
  37. la %r1,256(%r1)
  38. brctg %r3,.Lmemset_clear_loop
  39. .Lmemset_clear_rest:
  40. larl %r3,.Lmemset_xc
  41. ex %r4,0(%r3)
  42. BR_EX %r14
  43. .Lmemset_fill:
  44. stc %r3,0(%r2)
  45. cghi %r4,1
  46. lgr %r1,%r2
  47. ber %r14
  48. aghi %r4,-2
  49. srlg %r3,%r4,8
  50. ltgr %r3,%r3
  51. jz .Lmemset_fill_rest
  52. .Lmemset_fill_loop:
  53. mvc 1(256,%r1),0(%r1)
  54. la %r1,256(%r1)
  55. brctg %r3,.Lmemset_fill_loop
  56. .Lmemset_fill_rest:
  57. larl %r3,.Lmemset_mvc
  58. ex %r4,0(%r3)
  59. BR_EX %r14
  60. .Lmemset_xc:
  61. xc 0(1,%r1),0(%r1)
  62. .Lmemset_mvc:
  63. mvc 1(1,%r1),0(%r1)
  64. EXPORT_SYMBOL(memset)
  65. /*
  66. * memcpy implementation
  67. *
  68. * void *memcpy(void *dest, const void *src, size_t n)
  69. */
  70. ENTRY(memcpy)
  71. ltgr %r4,%r4
  72. bzr %r14
  73. aghi %r4,-1
  74. srlg %r5,%r4,8
  75. ltgr %r5,%r5
  76. lgr %r1,%r2
  77. jnz .Lmemcpy_loop
  78. .Lmemcpy_rest:
  79. larl %r5,.Lmemcpy_mvc
  80. ex %r4,0(%r5)
  81. BR_EX %r14
  82. .Lmemcpy_loop:
  83. mvc 0(256,%r1),0(%r3)
  84. la %r1,256(%r1)
  85. la %r3,256(%r3)
  86. brctg %r5,.Lmemcpy_loop
  87. j .Lmemcpy_rest
  88. .Lmemcpy_mvc:
  89. mvc 0(1,%r1),0(%r3)
  90. EXPORT_SYMBOL(memcpy)