mmap.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2016 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /* Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, write to the Free
  16. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  17. 02111-1307 USA. */
  18. #include <sys/syscall.h>
  19. #include <sysdep.h>
  20. .text
  21. .globl __mmap
  22. ENTRY (__mmap)
  23. #ifdef PIC
  24. .pic
  25. #endif
  26. // reserve space for r0, r1
  27. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP)
  28. #else
  29. addi $sp, $sp, -8
  30. #endif
  31. // change to units of the system page size
  32. srli $r5, $r5, 0xc
  33. syscall SYS_ify(mmap2)
  34. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP)
  35. #else
  36. addi $sp, $sp, 8
  37. #endif
  38. /* r0 is < -4096 if there was an error. */
  39. bgez $r0, 1f
  40. sltsi $r1,$r0,-4096
  41. beqz $r1,2f
  42. 1:
  43. ret
  44. 2:
  45. #ifdef PIC
  46. #ifdef __NDS32_N1213_43U1H__
  47. ! save lp
  48. addi $r2, $lp, 0
  49. ! set r1 as gp
  50. jal 1b
  51. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_)
  52. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_+4)
  53. add $r1, $lp, $r1
  54. ! restore lp
  55. addi $lp, $r2, 0
  56. ! r15=SYSCALL_ERROR@PLT
  57. sethi $r15, hi20(SYSCALL_ERROR@PLT)
  58. ori $r15, $r15, lo12(SYSCALL_ERROR@PLT)
  59. add $r15, $r15, $r1
  60. ! jump to SYSCALL_ERROR
  61. jr $r15
  62. #else
  63. ! set r1 as gp
  64. mfusr $r15, $PC
  65. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_+4)
  66. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_+8)
  67. add $r1, $r1, $r15
  68. ! r15=SYSCALL_ERROR@PLT
  69. sethi $r15, hi20(SYSCALL_ERROR@PLT)
  70. ori $r15, $r15, lo12(SYSCALL_ERROR@PLT)
  71. add $r15, $r15, $r1
  72. ! jump to SYSCALL_ERROR
  73. jr $r15
  74. #endif
  75. #else
  76. j SYSCALL_ERROR
  77. #endif
  78. ret
  79. PSEUDO_END (__mmap)
  80. weak_alias (__mmap, mmap)
  81. libc_hidden_def(mmap)