resolve.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Linux dynamic resolving code for MIPS. Fixes up the GOT entry as
  3. * indicated in register t8 and jumps to the resolved address. Shamelessly
  4. * ripped from 'sysdeps/mips/dl-machine.h' in glibc-2.2.5.
  5. *
  6. * This file is subject to the terms and conditions of the GNU Lesser General
  7. * Public License. See the file "COPYING.LIB" in the main directory of this
  8. * archive for more details.
  9. *
  10. * Copyright (C) 1996-2001 Kazumoto Kojima <kkojima@info.kanagawa-u.ac.jp>
  11. * Copyright (C) 2002 Steven J. Hill <sjhill@realitydiluted.com>
  12. *
  13. */
  14. #include <sgidefs.h>
  15. .text
  16. .align 2
  17. .globl _dl_runtime_resolve
  18. .type _dl_runtime_resolve,@function
  19. .ent _dl_runtime_resolve
  20. _dl_runtime_resolve:
  21. #if _MIPS_SIM == _MIPS_SIM_ABI32
  22. .frame $29, 40, $31
  23. .set noreorder
  24. /* Save GP. */
  25. move $3, $28
  26. /* Save arguments and sp value on stack. */
  27. subu $29, 40
  28. /* Modify t9 ($25) so as to point .cpload instruction. */
  29. addiu $25, 12
  30. /* Compute GP. */
  31. .set noreorder
  32. .cpload $25
  33. .set reorder
  34. /* Save slot call pc. */
  35. move $2, $31
  36. .cprestore 32
  37. /* Store function arguments from registers to stack */
  38. sw $15, 36($29)
  39. sw $4, 16($29)
  40. sw $5, 20($29)
  41. sw $6, 24($29)
  42. sw $7, 28($29)
  43. /* Setup functions args and call __dl_runtime_resolve */
  44. move $4, $24
  45. move $5, $3
  46. jal __dl_runtime_resolve
  47. /* Restore function arguments from stack to registers */
  48. lw $31, 36($29)
  49. lw $4, 16($29)
  50. lw $5, 20($29)
  51. lw $6, 24($29)
  52. lw $7, 28($29)
  53. /* Do a tail call to the original function */
  54. addiu $29, 40
  55. #else /* N32 || N64 */
  56. .set noreorder
  57. /* Save GP. */
  58. move $3, $28
  59. /* Save arguments and sp value on stack. */
  60. dsubu $29, 80
  61. /* Compute GP. */
  62. .set noreorder
  63. .cpsetup $25, 0, _dl_runtime_resolve
  64. .set reorder
  65. /* Store function arguments from registers to stack */
  66. sd $15, 72($29)
  67. sd $4, 8($29)
  68. sd $5, 16($29)
  69. sd $6, 24($29)
  70. sd $7, 32($29)
  71. sd $8, 40($29)
  72. sd $9, 48($29)
  73. sd $10, 56($29)
  74. sd $11, 64($29)
  75. /* Setup functions args and call __dl_runtime_resolve */
  76. move $4, $24
  77. move $5, $3
  78. jal __dl_runtime_resolve
  79. /* Restore function arguments from stack to registers */
  80. ld $31, 72($29)
  81. ld $4, 8($29)
  82. ld $5, 16($29)
  83. ld $6, 24($29)
  84. ld $7, 32($29)
  85. ld $8, 40($29)
  86. ld $9, 48($29)
  87. ld $10, 56($29)
  88. ld $11, 64($29)
  89. /* Do a tail call to the original function */
  90. .cpreturn
  91. daddu $29, 80
  92. #endif /* N32 || N64 */
  93. move $25, $2
  94. jr $25
  95. .end _dl_runtime_resolve
  96. .previous
  97. /* Assembler veneer called from the PLT header code when using the
  98. non-PIC ABI.
  99. Code in each PLT entry puts the caller's return address into t7 ($15),
  100. the PLT entry index into t8 ($24), the address of _dl_runtime_pltresolve
  101. into t9 ($25) and the address of .got.plt into gp ($28). __dl_runtime_pltresolve
  102. needs a0 ($4) to hold the link map and a1 ($5) to hold the index into
  103. .rel.plt (== PLT entry index * 4). */
  104. .text
  105. .align 2
  106. .globl _dl_runtime_pltresolve
  107. .type _dl_runtime_pltresolve,@function
  108. .ent _dl_runtime_pltresolve
  109. _dl_runtime_pltresolve:
  110. .frame $29, 40, $31
  111. .set noreorder
  112. # Save arguments and sp value in stack.
  113. subu $29, 40
  114. lw $10, 4($28)
  115. # Modify t9 ($25) so as to point .cpload instruction.
  116. addiu $25, 12
  117. # Compute GP.
  118. .cpload $25
  119. .set reorder
  120. /* Store function arguments from registers to stack */
  121. sw $15, 36($29)
  122. sw $4, 16($29)
  123. sw $5, 20($29)
  124. sw $6, 24($29)
  125. sw $7, 28($29)
  126. /* Setup functions args and call __dl_runtime_pltresolve. */
  127. move $4, $10
  128. sll $5, $24, 3
  129. jal __dl_runtime_pltresolve
  130. /* Restore function arguments from stack to registers */
  131. lw $31, 36($29)
  132. lw $4, 16($29)
  133. lw $5, 20($29)
  134. lw $6, 24($29)
  135. lw $7, 28($29)
  136. /* Do a tail call to the original function */
  137. addiu $29, 40
  138. move $25, $2
  139. jr $25
  140. .end _dl_runtime_pltresolve
  141. .previous