mmap64.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include <bits/arm_bx.h>
  20. #ifdef __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. BXC(cc, lr)
  89. b __syscall_error
  90. .Linval:
  91. mov r0, $-EINVAL
  92. ldmfd sp!, {r4, r5}
  93. b __syscall_error
  94. #endif
  95. #else /* !__ARM_EABI__ */
  96. mmap64:
  97. stmfd sp!, {r4, r5, lr}
  98. ldr r5, [sp, $16]
  99. ldr r4, [sp, $12]
  100. movs ip, r5, lsl $20 @ check that offset is page-aligned
  101. bne .Linval
  102. ldr ip, [sp, $20]
  103. mov r5, r5, lsr $12
  104. orr r5, r5, ip, lsl $20 @ compose page offset
  105. movs ip, ip, lsr $12
  106. bne .Linval @ check for overflow
  107. mov ip, r0
  108. DO_CALL (mmap2)
  109. cmn r0, $4096
  110. ldmccfd sp!, {r4, r5, pc}
  111. cmn r0, $ENOSYS
  112. ldmnefd sp!, {r4, r5, lr}
  113. bne __error
  114. /* The current kernel does not support mmap2. Fall back to plain
  115. mmap if the offset is small enough. */
  116. ldr r5, [sp, $20]
  117. mov r0, ip @ first arg was clobbered
  118. teq r5, $0
  119. ldmeqfd sp!, {r4, r5, lr}
  120. beq HIDDEN_JUMPTARGET(mmap)
  121. .Linval:
  122. mov r0, $-EINVAL
  123. ldmfd sp!, {r4, r5, lr}
  124. b __error
  125. __error:
  126. b __syscall_error
  127. #endif
  128. .size mmap64,.-mmap64
  129. #endif