2 * Code to process dynamic relocations in the kernel.
4 * Copyright 2008 Paul Mackerras, IBM Corp.
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.
12 #include <asm/ppc_asm.h>
15 RELACOUNT = 0x6ffffff9
19 * r3 = desired final address of kernel
24 0: mflr r12 /* r12 has runtime addr of label 0 */
26 ld r11,(p_dyn - 0b)(r12)
27 add r11,r11,r12 /* r11 has runtime addr of .dynamic section */
28 ld r9,(p_rela - 0b)(r12)
29 add r9,r9,r12 /* r9 has runtime addr of .rela.dyn section */
30 ld r10,(p_st - 0b)(r12)
31 add r10,r10,r12 /* r10 has runtime addr of _stext */
34 * Scan the dynamic section for the RELA and RELACOUNT entries.
38 1: ld r6,0(r11) /* get tag */
40 beq 4f /* end of list */
43 ld r7,8(r11) /* get RELA pointer in r7 */
45 2: addis r6,r6,(-RELACOUNT)@ha
48 ld r8,8(r11) /* get RELACOUNT value in r8 */
51 4: cmpdi r7,0 /* check we have both RELA and RELACOUNT */
57 * Work out linktime address of _stext and hence the
58 * relocation offset to be applied.
59 * cur_offset [r7] = rela.run [r9] - rela.link [r7]
60 * _stext.link [r10] = _stext.run [r10] - cur_offset [r7]
61 * final_offset [r3] = _stext.final [r3] - _stext.link [r10]
63 subf r7,r7,r9 /* cur_offset */
65 subf r3,r10,r3 /* final_offset */
68 * Run through the list of relocations and process the
69 * R_PPC64_RELATIVE ones.
72 5: ld r0,8(9) /* ELF64_R_TYPE(reloc->r_info) */
73 cmpdi r0,R_PPC64_RELATIVE
75 ld r6,0(r9) /* reloc->r_offset */
76 ld r0,16(r9) /* reloc->r_addend */
85 p_dyn: .llong __dynamic_start - 0b
86 p_rela: .llong __rela_dyn_start - 0b
87 p_st: .llong _stext - 0b