mmap64.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Copyright (C) 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <features.h>
  16. #define _ERRNO_H
  17. #include <bits/errno.h>
  18. #include <sys/syscall.h>
  19. #include <bits/arm_asm.h>
  20. #if defined __UCLIBC_HAS_LFS__ && defined __NR_mmap2
  21. /* The mmap2 system call takes six arguments, all in registers. */
  22. .text
  23. .global mmap64
  24. .type mmap64,%function
  25. .align 2
  26. #ifdef __ARM_EABI__
  27. #if defined(THUMB1_ONLY)
  28. .thumb_func
  29. mmap64:
  30. #ifdef __ARMEB__
  31. /* Offsets are after pushing 3 words. */
  32. # define LOW_OFFSET 12 + 8 + 4
  33. # define HIGH_OFFSET 12 + 8 + 0
  34. #else
  35. # define LOW_OFFSET 12 + 8 + 0
  36. # define HIGH_OFFSET 12 + 8 + 4
  37. #endif
  38. push {r4, r5, r6}
  39. ldr r6, [sp, $LOW_OFFSET]
  40. ldr r5, [sp, $HIGH_OFFSET]
  41. lsl r4, r6, #20 @ check that offset is page-aligned
  42. bne .Linval
  43. lsr r4, r5, #12 @ check for overflow
  44. bne .Linval
  45. @ compose page offset
  46. lsr r6, r6, #12
  47. lsl r5, r5, #20
  48. orr r5, r5, r6
  49. ldr r4, [sp, #8] @ load fd
  50. DO_CALL (mmap2)
  51. ldr r1, =0xfffff000
  52. cmp r0, r1
  53. bcs .Lerror
  54. bx lr
  55. .Linval:
  56. ldr r0, =-EINVAL
  57. pop {r4, r5, r6}
  58. .Lerror:
  59. push {r3, lr}
  60. bl __syscall_error
  61. POP_RET
  62. .pool
  63. #else /* !THUMB1_ONLY */
  64. mmap64:
  65. #ifdef __ARMEB__
  66. # define LOW_OFFSET 8 + 4
  67. /* The initial + 4 is for the stack postdecrement. */
  68. # define HIGH_OFFSET 4 + 8 + 0
  69. #else
  70. # define LOW_OFFSET 8 + 0
  71. # define HIGH_OFFSET 4 + 8 + 4
  72. #endif
  73. ldr ip, [sp, $LOW_OFFSET]
  74. str r5, [sp, #-4]!
  75. ldr r5, [sp, $HIGH_OFFSET]
  76. str r4, [sp, #-4]!
  77. movs r4, ip, lsl $20 @ check that offset is page-aligned
  78. mov ip, ip, lsr $12
  79. IT(t, eq)
  80. moveqs r4, r5, lsr $12 @ check for overflow
  81. bne .Linval
  82. ldr r4, [sp, $8] @ load fd
  83. orr r5, ip, r5, lsl $20 @ compose page offset
  84. DO_CALL (mmap2)
  85. cmn r0, $4096
  86. ldmfd sp!, {r4, r5}
  87. IT(t, cc)
  88. #if defined(__USE_BX__)
  89. bxcc lr
  90. #else
  91. movcc pc, lr
  92. #endif
  93. b __syscall_error
  94. .Linval:
  95. mov r0, $-EINVAL
  96. ldmfd sp!, {r4, r5}
  97. b __syscall_error
  98. #endif
  99. #else /* !__ARM_EABI__ */
  100. mmap64:
  101. stmfd sp!, {r4, r5, lr}
  102. ldr r5, [sp, $16]
  103. ldr r4, [sp, $12]
  104. movs ip, r5, lsl $20 @ check that offset is page-aligned
  105. bne .Linval
  106. ldr ip, [sp, $20]
  107. mov r5, r5, lsr $12
  108. orr r5, r5, ip, lsl $20 @ compose page offset
  109. movs ip, ip, lsr $12
  110. bne .Linval @ check for overflow
  111. mov ip, r0
  112. DO_CALL (mmap2)
  113. cmn r0, $4096
  114. ldmccfd sp!, {r4, r5, pc}
  115. cmn r0, $ENOSYS
  116. ldmnefd sp!, {r4, r5, lr}
  117. bne __error
  118. /* The current kernel does not support mmap2. Fall back to plain
  119. mmap if the offset is small enough. */
  120. ldr r5, [sp, $20]
  121. mov r0, ip @ first arg was clobbered
  122. teq r5, $0
  123. ldmeqfd sp!, {r4, r5, lr}
  124. beq HIDDEN_JUMPTARGET(mmap)
  125. .Linval:
  126. mov r0, $-EINVAL
  127. ldmfd sp!, {r4, r5, lr}
  128. b __error
  129. __error:
  130. b __syscall_error
  131. #endif
  132. .size mmap64,.-mmap64
  133. #endif