resolve.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2019 by Waldemar Brodkorb <wbx@uclibc-ng.org>
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. * ported from GNU libc
  5. */
  6. /* Copyright (C) 2017-2019 Free Software Foundation, Inc.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public License as
  9. published by the Free Software Foundation; either version 2.1 of the
  10. License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library. If not, see
  17. <https://www.gnu.org/licenses/>. */
  18. #include <features.h>
  19. #include <sysdep.h>
  20. #include <sys/asm.h>
  21. /* Assembler veneer called from the PLT header code for lazy loading.
  22. The PLT header passes its own args in t0-t2. */
  23. #ifdef __riscv_float_abi_soft
  24. # define FRAME_SIZE (-((-10 * SZREG) & ALMASK))
  25. #else
  26. # define FRAME_SIZE (-((-10 * SZREG - 8 * SZFREG) & ALMASK))
  27. #endif
  28. ENTRY (_dl_linux_resolve)
  29. # Save arguments to stack.
  30. addi sp, sp, -FRAME_SIZE
  31. REG_S ra, 9*SZREG(sp)
  32. REG_S a0, 1*SZREG(sp)
  33. REG_S a1, 2*SZREG(sp)
  34. REG_S a2, 3*SZREG(sp)
  35. REG_S a3, 4*SZREG(sp)
  36. REG_S a4, 5*SZREG(sp)
  37. REG_S a5, 6*SZREG(sp)
  38. REG_S a6, 7*SZREG(sp)
  39. REG_S a7, 8*SZREG(sp)
  40. #ifndef __riscv_float_abi_soft
  41. FREG_S fa0, (10*SZREG + 0*SZFREG)(sp)
  42. FREG_S fa1, (10*SZREG + 1*SZFREG)(sp)
  43. FREG_S fa2, (10*SZREG + 2*SZFREG)(sp)
  44. FREG_S fa3, (10*SZREG + 3*SZFREG)(sp)
  45. FREG_S fa4, (10*SZREG + 4*SZFREG)(sp)
  46. FREG_S fa5, (10*SZREG + 5*SZFREG)(sp)
  47. FREG_S fa6, (10*SZREG + 6*SZFREG)(sp)
  48. FREG_S fa7, (10*SZREG + 7*SZFREG)(sp)
  49. #endif
  50. # Update .got.plt and obtain runtime address of callee.
  51. slli a1, t1, 1
  52. mv a0, t0 # link map
  53. add a1, a1, t1 # reloc offset (== thrice the .got.plt offset)
  54. la a2, _dl_fixup
  55. jalr a2
  56. mv t1, a0
  57. # Restore arguments from stack.
  58. REG_L ra, 9*SZREG(sp)
  59. REG_L a0, 1*SZREG(sp)
  60. REG_L a1, 2*SZREG(sp)
  61. REG_L a2, 3*SZREG(sp)
  62. REG_L a3, 4*SZREG(sp)
  63. REG_L a4, 5*SZREG(sp)
  64. REG_L a5, 6*SZREG(sp)
  65. REG_L a6, 7*SZREG(sp)
  66. REG_L a7, 8*SZREG(sp)
  67. #ifndef __riscv_float_abi_soft
  68. FREG_L fa0, (10*SZREG + 0*SZFREG)(sp)
  69. FREG_L fa1, (10*SZREG + 1*SZFREG)(sp)
  70. FREG_L fa2, (10*SZREG + 2*SZFREG)(sp)
  71. FREG_L fa3, (10*SZREG + 3*SZFREG)(sp)
  72. FREG_L fa4, (10*SZREG + 4*SZFREG)(sp)
  73. FREG_L fa5, (10*SZREG + 5*SZFREG)(sp)
  74. FREG_L fa6, (10*SZREG + 6*SZFREG)(sp)
  75. FREG_L fa7, (10*SZREG + 7*SZFREG)(sp)
  76. #endif
  77. addi sp, sp, FRAME_SIZE
  78. # Invoke the callee.
  79. jr t1
  80. END (_dl_linux_resolve)