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>
17 * r3 = desired final address of kernel
22 0: mflr r12 /* r12 has runtime addr of label 0 */
24 ld r11,(p_dyn - 0b)(r12)
25 add r11,r11,r12 /* r11 has runtime addr of .dynamic section */
26 ld r9,(p_rela - 0b)(r12)
27 add r9,r9,r12 /* r9 has runtime addr of .rela.dyn section */
28 ld r10,(p_st - 0b)(r12)
29 add r10,r10,r12 /* r10 has runtime addr of _stext */
30 ld r4,(p_sym - 0b)(r12)
31 add r4,r4,r12 /* r4 has runtime addr of .dynsym */
34 * Scan the dynamic section for the RELA, RELASZ and RELAENT entries.
39 ld r6,0(r11) /* get tag */
41 beq .Lend_of_list /* end of list */
44 ld r7,8(r11) /* get RELA pointer in r7 */
48 ld r8,8(r11) /* get RELASZ value in r8 */
52 ld r12,8(r11) /* get RELAENT value in r12 */
56 cmpdi r7,0 /* check we have RELA, RELASZ, RELAENT */
64 * Work out linktime address of _stext and hence the
65 * relocation offset to be applied.
66 * cur_offset [r7] = rela.run [r9] - rela.link [r7]
67 * _stext.link [r10] = _stext.run [r10] - cur_offset [r7]
68 * final_offset [r3] = _stext.final [r3] - _stext.link [r10]
70 subf r7,r7,r9 /* cur_offset */
72 subf r3,r10,r3 /* final_offset */
75 * Run through the list of relocations and process the
76 * R_PPC64_RELATIVE and R_PPC64_UADDR64 ones.
78 divd r8,r8,r12 /* RELASZ / RELAENT */
80 .Lrels: ld r0,8(r9) /* ELF64_R_TYPE(reloc->r_info) */
81 cmpdi r0,R_PPC64_RELATIVE
83 ld r6,0(r9) /* reloc->r_offset */
84 ld r0,16(r9) /* reloc->r_addend */
87 srdi r5,r0,32 /* ELF64_R_SYM(reloc->r_info) */
89 cmpdi r0,R_PPC64_UADDR64
93 mulli r5,r5,24 /* 24 == sizeof(elf64_sym) */
94 add r5,r5,r4 /* elf64_sym[ELF64_R_SYM] */
107 p_dyn: .8byte __dynamic_start - 0b
108 p_rela: .8byte __rela_dyn_start - 0b
109 p_sym: .8byte __dynamic_symtab - 0b
110 p_st: .8byte _stext - 0b