1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Code to process dynamic relocations in the kernel.
5 * Copyright 2008 Paul Mackerras, IBM Corp.
8 #include <asm/ppc_asm.h>
11 RELACOUNT = 0x6ffffff9
15 * r3 = desired final address of kernel
20 0: mflr r12 /* r12 has runtime addr of label 0 */
22 ld r11,(p_dyn - 0b)(r12)
23 add r11,r11,r12 /* r11 has runtime addr of .dynamic section */
24 ld r9,(p_rela - 0b)(r12)
25 add r9,r9,r12 /* r9 has runtime addr of .rela.dyn section */
26 ld r10,(p_st - 0b)(r12)
27 add r10,r10,r12 /* r10 has runtime addr of _stext */
30 * Scan the dynamic section for the RELA and RELACOUNT entries.
34 1: ld r6,0(r11) /* get tag */
36 beq 4f /* end of list */
39 ld r7,8(r11) /* get RELA pointer in r7 */
41 2: addis r6,r6,(-RELACOUNT)@ha
44 ld r8,8(r11) /* get RELACOUNT value in r8 */
47 4: cmpdi r7,0 /* check we have both RELA and RELACOUNT */
53 * Work out linktime address of _stext and hence the
54 * relocation offset to be applied.
55 * cur_offset [r7] = rela.run [r9] - rela.link [r7]
56 * _stext.link [r10] = _stext.run [r10] - cur_offset [r7]
57 * final_offset [r3] = _stext.final [r3] - _stext.link [r10]
59 subf r7,r7,r9 /* cur_offset */
61 subf r3,r10,r3 /* final_offset */
64 * Run through the list of relocations and process the
65 * R_PPC64_RELATIVE ones.
68 5: ld r0,8(9) /* ELF64_R_TYPE(reloc->r_info) */
69 cmpdi r0,R_PPC64_RELATIVE
71 ld r6,0(r9) /* reloc->r_offset */
72 ld r0,16(r9) /* reloc->r_addend */
81 p_dyn: .8byte __dynamic_start - 0b
82 p_rela: .8byte __rela_dyn_start - 0b
83 p_st: .8byte _stext - 0b