reloc_64.S 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Code to process dynamic relocations in the kernel.
  3. *
  4. * Copyright 2008 Paul Mackerras, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <asm/ppc_asm.h>
  12. RELA = 7
  13. RELACOUNT = 0x6ffffff9
  14. R_PPC64_RELATIVE = 22
  15. /*
  16. * r3 = desired final address of kernel
  17. */
  18. _GLOBAL(relocate)
  19. mflr r0
  20. bcl 20,31,$+4
  21. 0: mflr r12 /* r12 has runtime addr of label 0 */
  22. mtlr r0
  23. ld r11,(p_dyn - 0b)(r12)
  24. add r11,r11,r12 /* r11 has runtime addr of .dynamic section */
  25. ld r9,(p_rela - 0b)(r12)
  26. add r9,r9,r12 /* r9 has runtime addr of .rela.dyn section */
  27. ld r10,(p_st - 0b)(r12)
  28. add r10,r10,r12 /* r10 has runtime addr of _stext */
  29. /*
  30. * Scan the dynamic section for the RELA and RELACOUNT entries.
  31. */
  32. li r7,0
  33. li r8,0
  34. 1: ld r6,0(r11) /* get tag */
  35. cmpdi r6,0
  36. beq 4f /* end of list */
  37. cmpdi r6,RELA
  38. bne 2f
  39. ld r7,8(r11) /* get RELA pointer in r7 */
  40. b 3f
  41. 2: addis r6,r6,(-RELACOUNT)@ha
  42. cmpdi r6,RELACOUNT@l
  43. bne 3f
  44. ld r8,8(r11) /* get RELACOUNT value in r8 */
  45. 3: addi r11,r11,16
  46. b 1b
  47. 4: cmpdi r7,0 /* check we have both RELA and RELACOUNT */
  48. cmpdi cr1,r8,0
  49. beq 6f
  50. beq cr1,6f
  51. /*
  52. * Work out linktime address of _stext and hence the
  53. * relocation offset to be applied.
  54. * cur_offset [r7] = rela.run [r9] - rela.link [r7]
  55. * _stext.link [r10] = _stext.run [r10] - cur_offset [r7]
  56. * final_offset [r3] = _stext.final [r3] - _stext.link [r10]
  57. */
  58. subf r7,r7,r9 /* cur_offset */
  59. subf r10,r7,r10
  60. subf r3,r10,r3 /* final_offset */
  61. /*
  62. * Run through the list of relocations and process the
  63. * R_PPC64_RELATIVE ones.
  64. */
  65. mtctr r8
  66. 5: ld r0,8(9) /* ELF64_R_TYPE(reloc->r_info) */
  67. cmpdi r0,R_PPC64_RELATIVE
  68. bne 6f
  69. ld r6,0(r9) /* reloc->r_offset */
  70. ld r0,16(r9) /* reloc->r_addend */
  71. add r0,r0,r3
  72. stdx r0,r7,r6
  73. addi r9,r9,24
  74. bdnz 5b
  75. 6: blr
  76. .balign 8
  77. p_dyn: .llong __dynamic_start - 0b
  78. p_rela: .llong __rela_dyn_start - 0b
  79. p_st: .llong _stext - 0b