2 * relocate - common relocation function for ARM U-Boot
4 * Copyright (c) 2013 Albert ARIBAUD <albert.u.boot@aribaud.net>
6 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/linkage.h>
12 * void relocate_code(addr_moni)
14 * This function relocates the monitor code.
17 * To prevent the code below from containing references with an R_ARM_ABS32
18 * relocation record type, we never refer to linker-defined symbols directly.
19 * Instead, we declare literals which contain their relative location with
20 * respect to relocate_code, and at run time, add relocate_code back to them.
24 ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
25 subs r4, r0, r1 /* r4 <- relocation offset */
26 beq relocate_done /* skip relocation */
27 ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */
30 ldmia r1!, {r10-r11} /* copy from source address [r1] */
31 stmia r0!, {r10-r11} /* copy to target address [r0] */
32 cmp r1, r2 /* until source end address [r2] */
36 * fix .rel.dyn relocations
38 ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
39 ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
41 ldmia r2!, {r0-r1} /* (r0,r1) <- (SRC location,fixup) */
43 cmp r1, #23 /* relative fixup? */
46 /* relative fix: increase location by offset */
59 * On xscale, icache must be invalidated and write buffers drained,
60 * even with cache disabled - 4.2.7 of xscale core developer's manual
62 mcr p15, 0, r0, c7, c7, 0 /* invalidate icache */
63 mcr p15, 0, r0, c7, c10, 4 /* drain write buffer */
66 /* ARMv4- don't know bx lr but the assembler fails to see that */
74 ENDPROC(relocate_code)