You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reloc.S 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* reloc.S - position independent IA-64 ELF shared object relocator
  2. Copyright (C) 1999 Hewlett-Packard Co.
  3. Contributed by David Mosberger <davidm@hpl.hp.com>.
  4. Copyright (C) 2002 Eric Biederman sponsored by Linux Networx
  5. This file is part of etherboot.
  6. This file was derived from reloc_ia64.S from GNU-EFI, the GNU EFI development environment.
  7. GNU EFI is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. GNU EFI 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
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with GNU EFI; see the file COPYING. If not, write to the Free
  17. Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. 02111-1307, USA. */
  19. /*
  20. * This is written in assembly because the entire code needs to be position
  21. * independent. Note that the compiler does not generate code that's position
  22. * independent by itself because it relies on the global offset table being
  23. * relocated.
  24. *
  25. * This code assumes the code was compiled with -mconstant-gp -mauto-pic -static -shared
  26. * Which generates position independent code, but not position indepedent data.
  27. * This code assumes in the linker script the rela entries are bracked with:
  28. * _rela, _erela and _rela_size gives the total size of the rela entries.
  29. * This gives a much smaller binary than when compiled as a true shared object.
  30. *
  31. * This code assumes the original shared object was initially relocated,
  32. * So that it only needs to apply changes for the new address the code is linked
  33. * at.
  34. */
  35. .text
  36. .psr abi64
  37. .psr lsb
  38. .lsb
  39. #define ST_VALUE_OFF 8 /* offset of st_value in elf sym */
  40. #define RET_SUCCESS 0
  41. #define RET_LOAD_ERROR 1
  42. #define R_IA64_NONE 0
  43. #define R_IA64_REL64MSB 0x6e
  44. #define R_IA64_REL64LSB 0x6f
  45. #define R_IA64_DIR64MSB 0x26
  46. #define R_IA64_DIR64LSB 0x27
  47. #define R_IA64_FPTR64MSB 0x46
  48. #define R_IA64_FPTR64LSB 0x47
  49. #define delta in0 /* Chaing in load address (address of .text) */
  50. #define ldbase r15
  51. #define target r16
  52. #define val r17
  53. #define rela r18
  54. #define relasz r19
  55. #define relaent r20
  56. #define addr r21
  57. #define r_info r22
  58. #define r_offset r23
  59. #define r_type r25
  60. #define Pmore p6
  61. #define Pnone p6
  62. #define Prel p7
  63. #define Pdir p8
  64. .global _relocate
  65. _relocate:
  66. alloc r2=ar.pfs,1,0,0,0
  67. add rela=@gprel(_rela),gp
  68. add ldbase=@gprel(_text),gp
  69. add r3=@ltoff(_rela_size),gp
  70. ;;
  71. ld8 relasz = [r3]
  72. mov relaent=24
  73. br.sptk.few apply_relocs
  74. apply_loop:
  75. ld8 r_offset = [rela]
  76. add addr = 8,rela
  77. sub relasz = relasz,relaent
  78. ;;
  79. ld8 r_info = [addr], 8
  80. ;;
  81. add target = ldbase, r_offset
  82. add rela = rela,relaent
  83. extr.u r_type = r_info, 0, 32
  84. ;;
  85. cmp.eq Pnone,p0 = R_IA64_NONE, r_type
  86. cmp.eq Prel,p0 = R_IA64_REL64LSB, r_type
  87. cmp.eq Pdir,p0 = R_IA64_DIR64LSB, r_type /* Needed? */
  88. ;;
  89. (Pnone) br.cond.sptk.few apply_relocs
  90. (Prel) br.cond.sptk.few apply_REL64
  91. (Pdir) br.cond.sptk.few apply_DIR64 /* Needed? */
  92. ;;
  93. apply_error:
  94. mov r8 = RET_LOAD_ERROR
  95. br.ret.sptk.few rp
  96. apply_REL64:
  97. apply_DIR64:
  98. ld8 val = [target]
  99. ;;
  100. add val = val, delta
  101. ;;
  102. st8 [target] = val
  103. ;;
  104. /* fall through to apply_relocs */
  105. apply_relocs:
  106. cmp.ltu Pmore,p0=0,relasz
  107. (Pmore) br.cond.sptk.few apply_loop
  108. ;;
  109. mov r8 = RET_SUCCESS
  110. br.ret.sptk.few rp
  111. .size _relocate, . - _relocate
  112. .endp _relocate