2 * relocate - common relocation function for AArch64 U-Boot
5 * Albert ARIBAUD <albert.u.boot@aribaud.net>
6 * David Feng <fenghua@phytium.com.cn>
8 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm-offsets.h>
14 #include <linux/linkage.h>
15 #include <asm/macro.h>
18 * void relocate_code (addr_moni)
20 * This function relocates the monitor code.
21 * x0 holds the destination address.
24 stp x29, x30, [sp, #-32]! /* create a stack frame */
28 * Copy u-boot from flash to RAM
30 ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */
31 subs x9, x0, x1 /* x9 <- relocation offset */
32 b.eq relocate_done /* skip relocation */
33 ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */
36 ldp x10, x11, [x1], #16 /* copy from source address [x1] */
37 stp x10, x11, [x0], #16 /* copy to target address [x0] */
38 cmp x1, x2 /* until source end address [x2] */
43 * Fix .rela.dyn relocations
45 ldr x2, =__rel_dyn_start /* x2 <- SRC &__rel_dyn_start */
46 ldr x3, =__rel_dyn_end /* x3 <- SRC &__rel_dyn_end */
48 ldp x0, x1, [x2], #16 /* (x0,x1) <- (SRC location, fixup) */
49 ldr x4, [x2], #8 /* x4 <- addend */
50 and x1, x1, #0xffffffff
51 cmp x1, #R_AARCH64_RELATIVE
54 /* relative fix: store addend plus offset at dest location */
63 switch_el x1, 3f, 2f, 1f
70 0: tbz w0, #2, 5f /* skip flushing cache if disabled */
71 tbz w0, #12, 4f /* invalide i-cache is enabled */
72 ic iallu /* i-cache invalidate all */
74 4: ldp x0, x1, [sp, #16]
75 bl __asm_flush_dcache_range
76 5: ldp x29, x30, [sp],#16
78 ENDPROC(relocate_code)