mmap64.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <_lfs_64.h>
  15. #define _ERRNO_H
  16. #include <bits/errno.h>
  17. #include <sys/syscall.h>
  18. #include <bits/arm_asm.h>
  19. #ifdef __NR_mmap2
  20. /* The mmap2 system call takes six arguments, all in registers. */
  21. .text
  22. .global mmap64
  23. .type mmap64,%function
  24. .align 2
  25. #ifdef __ARM_EABI__
  26. #if defined(THUMB1_ONLY)
  27. .thumb_func
  28. mmap64:
  29. #ifdef __ARMEB__
  30. /* Offsets are after pushing 3 words. */
  31. # define LOW_OFFSET 12 + 8 + 4
  32. # define HIGH_OFFSET 12 + 8 + 0
  33. #else
  34. # define LOW_OFFSET 12 + 8 + 0
  35. # define HIGH_OFFSET 12 + 8 + 4
  36. #endif
  37. push {r4, r5, r6}
  38. ldr r6, [sp, $LOW_OFFSET]
  39. ldr r5, [sp, $HIGH_OFFSET]
  40. lsl r4, r6, #20 @ check that offset is page-aligned
  41. bne .Linval
  42. lsr r4, r5, #12 @ check for overflow
  43. bne .Linval
  44. @ compose page offset
  45. lsr r6, r6, #12
  46. lsl r5, r5, #20
  47. orr r5, r5, r6
  48. ldr r4, [sp, #8] @ load fd
  49. DO_CALL (mmap2)
  50. ldr r1, =0xfffff000
  51. cmp r0, r1
  52. bcs .Lerror
  53. bx lr
  54. .Linval:
  55. ldr r0, =-EINVAL
  56. pop {r4, r5, r6}
  57. .Lerror:
  58. push {r3, lr}
  59. bl __syscall_error
  60. POP_RET
  61. .pool
  62. #else /* !THUMB1_ONLY */
  63. mmap64:
  64. #ifdef __ARMEB__
  65. # define LOW_OFFSET 8 + 4
  66. /* The initial + 4 is for the stack postdecrement. */
  67. # define HIGH_OFFSET 4 + 8 + 0
  68. #else
  69. # define LOW_OFFSET 8 + 0
  70. # define HIGH_OFFSET 4 + 8 + 4
  71. #endif
  72. ldr ip, [sp, $LOW_OFFSET]
  73. str r5, [sp, #-4]!
  74. ldr r5, [sp, $HIGH_OFFSET]
  75. str r4, [sp, #-4]!
  76. movs r4, ip, lsl $20 @ check that offset is page-aligned
  77. mov ip, ip, lsr $12
  78. IT(t, eq)
  79. moveqs r4, r5, lsr $12 @ check for overflow
  80. bne .Linval
  81. ldr r4, [sp, $8] @ load fd
  82. orr r5, ip, r5, lsl $20 @ compose page offset
  83. DO_CALL (mmap2)
  84. cmn r0, $4096
  85. ldmfd sp!, {r4, r5}
  86. IT(t, cc)
  87. #if defined(__USE_BX__)
  88. bxcc lr
  89. #else
  90. movcc pc, lr
  91. #endif
  92. b __syscall_error
  93. .Linval:
  94. mov r0, $-EINVAL
  95. ldmfd sp!, {r4, r5}
  96. b __syscall_error
  97. #endif
  98. #else /* !__ARM_EABI__ */
  99. mmap64:
  100. stmfd sp!, {r4, r5, lr}
  101. ldr r5, [sp, $16]
  102. ldr r4, [sp, $12]
  103. movs ip, r5, lsl $20 @ check that offset is page-aligned
  104. bne .Linval
  105. ldr ip, [sp, $20]
  106. mov r5, r5, lsr $12
  107. orr r5, r5, ip, lsl $20 @ compose page offset
  108. movs ip, ip, lsr $12
  109. bne .Linval @ check for overflow
  110. mov ip, r0
  111. DO_CALL (mmap2)
  112. cmn r0, $4096
  113. ldmccfd sp!, {r4, r5, pc}
  114. cmn r0, $ENOSYS
  115. ldmnefd sp!, {r4, r5, lr}
  116. bne __error
  117. /* The current kernel does not support mmap2. Fall back to plain
  118. mmap if the offset is small enough. */
  119. ldr r5, [sp, $20]
  120. mov r0, ip @ first arg was clobbered
  121. teq r5, $0
  122. ldmeqfd sp!, {r4, r5, lr}
  123. beq HIDDEN_JUMPTARGET(mmap)
  124. .Linval:
  125. mov r0, $-EINVAL
  126. ldmfd sp!, {r4, r5, lr}
  127. b __error
  128. __error:
  129. b __syscall_error
  130. #endif
  131. .size mmap64,.-mmap64
  132. #endif