1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * relocate - common relocation function for ARM U-Boot
5 * Copyright (c) 2013 Albert ARIBAUD <albert.u.boot@aribaud.net>
8 #include <asm-offsets.h>
11 #include <linux/linkage.h>
13 #include <asm/armv7m.h>
17 * Default/weak exception vectors relocation routine
19 * This routine covers the standard ARM cases: normal (0x00000000),
20 * high (0xffff0000) and VBAR. SoCs which do not comply with any of
21 * the standard cases must provide their own, strong, version.
24 .section .text.relocate_vectors,"ax",%progbits
25 .weak relocate_vectors
27 ENTRY(relocate_vectors)
31 * On ARMv7-M we only have to write the new vector address
34 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
36 str r0, [r1, V7M_SCB_VTOR]
38 #ifdef CONFIG_HAS_VBAR
40 * If the ARM processor has the security extensions,
41 * use VBAR to relocate the exception vectors.
43 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
44 mcr p15, 0, r0, c12, c0, 0 /* Set VBAR */
47 * Copy the relocated exception vectors to the
49 * CP15 c1 V bit gives us the location of the vectors:
50 * 0x00000000 or 0xFFFF0000.
52 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
53 mrc p15, 0, r2, c1, c0, 0 /* V bit (bit[13]) in CP15 c1 */
54 ands r2, r2, #(1 << 13)
55 ldreq r1, =0x00000000 /* If V=0 */
56 ldrne r1, =0xFFFF0000 /* If V=1 */
57 ldmia r0!, {r2-r8,r10}
58 stmia r1!, {r2-r8,r10}
59 ldmia r0!, {r2-r8,r10}
60 stmia r1!, {r2-r8,r10}
65 ENDPROC(relocate_vectors)
68 * void relocate_code(addr_moni)
70 * This function relocates the monitor code.
73 * To prevent the code below from containing references with an R_ARM_ABS32
74 * relocation record type, we never refer to linker-defined symbols directly.
75 * Instead, we declare literals which contain their relative location with
76 * respect to relocate_code, and at run time, add relocate_code back to them.
80 ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
81 subs r4, r0, r1 /* r4 <- relocation offset */
82 beq relocate_done /* skip relocation */
83 ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */
86 ldmia r1!, {r10-r11} /* copy from source address [r1] */
87 stmia r0!, {r10-r11} /* copy to target address [r0] */
88 cmp r1, r2 /* until source end address [r2] */
92 * fix .rel.dyn relocations
94 ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
95 ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
97 ldmia r2!, {r0-r1} /* (r0,r1) <- (SRC location,fixup) */
99 cmp r1, #R_ARM_RELATIVE
102 /* relative fix: increase location by offset */
115 * On xscale, icache must be invalidated and write buffers drained,
116 * even with cache disabled - 4.2.7 of xscale core developer's manual
118 mcr p15, 0, r0, c7, c7, 0 /* invalidate icache */
119 mcr p15, 0, r0, c7, c10, 4 /* drain write buffer */
122 /* ARMv4- don't know bx lr but the assembler fails to see that */
124 #ifdef __ARM_ARCH_4__
130 ENDPROC(relocate_code)