.
.
.
arch/arm/lib/relocate.S
1 /*
2 * void relocate_code(addr_moni)
3 *
4 * This function relocates the monitor code.
5 *
6 * NOTE:
7 * To prevent the code below from containing references with an R_ARM_ABS32
8 * relocation record type, we never refer to linker-defined symbols directly.
9 * Instead, we declare literals which contain their relative location with
10 * respect to relocate_code, and at run time, add relocate_code back to them.
11 */
12
13 ENTRY(relocate_code)
14 ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
15 subs r4, r0, r1 /* r4 <- relocation offset */
16 beq relocate_done /* skip relocation */
17 ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */
18
19 copy_loop:
20 ldmia r1!, {r10-r11} /* copy from source address [r1] */
21 stmia r0!, {r10-r11} /* copy to target address [r0] */
22 cmp r1, r2 /* until source end address [r2] */
23 blo copy_loop
24
25 /*
26 * fix .rel.dyn relocations
27 */
28 ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
29 ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
30 fixloop:
31 ldmia r2!, {r0-r1} /* (r0,r1) <- (SRC location,fixup) */
32 and r1, r1, #0xff
33 cmp r1, #R_ARM_RELATIVE
34 bne fixnext
35
36 /* relative fix: increase location by offset */
37 add r0, r0, r4
38 ldr r1, [r0]
39 add r1, r1, r4
40 str r1, [r0]
41 fixnext:
42 cmp r2, r3
43 blo fixloop
44
45 relocate_done:
46
47 #ifdef __XSCALE__
48 /*
49 * On xscale, icache must be invalidated and write buffers drained,
50 * even with cache disabled - 4.2.7 of xscale core developer's manual
51 */
52 mcr p15, 0, r0, c7, c7, 0 /* invalidate icache */
53 mcr p15, 0, r0, c7, c10, 4 /* drain write buffer */
54 #endif
55
56 /* ARMv4- don't know bx lr but the assembler fails to see that */
57
58 #ifdef __ARM_ARCH_4__
59 mov pc, lr
60 #else
61 bx lr
62 #endif
63
64 ENDPROC(relocate_code)
.
.
.