David Feng | 0ae7653 | 2013-12-14 11:47:35 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * relocate - common relocation function for AArch64 U-Boot |
| 3 | * |
| 4 | * (C) Copyright 2013 |
| 5 | * Albert ARIBAUD <albert.u.boot@aribaud.net> |
| 6 | * David Feng <fenghua@phytium.com.cn> |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | */ |
| 10 | |
| 11 | #include <asm-offsets.h> |
| 12 | #include <config.h> |
| 13 | #include <linux/linkage.h> |
| 14 | |
| 15 | /* |
| 16 | * void relocate_code (addr_moni) |
| 17 | * |
| 18 | * This function relocates the monitor code. |
| 19 | * x0 holds the destination address. |
| 20 | */ |
| 21 | ENTRY(relocate_code) |
| 22 | /* |
| 23 | * Copy u-boot from flash to RAM |
| 24 | */ |
| 25 | ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */ |
| 26 | subs x9, x0, x1 /* x9 <- relocation offset */ |
| 27 | b.eq relocate_done /* skip relocation */ |
| 28 | ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */ |
| 29 | |
| 30 | copy_loop: |
| 31 | ldp x10, x11, [x1], #16 /* copy from source address [x1] */ |
| 32 | stp x10, x11, [x0], #16 /* copy to target address [x0] */ |
| 33 | cmp x1, x2 /* until source end address [x2] */ |
| 34 | b.lo copy_loop |
| 35 | |
| 36 | /* |
| 37 | * Fix .rela.dyn relocations |
| 38 | */ |
| 39 | ldr x2, =__rel_dyn_start /* x2 <- SRC &__rel_dyn_start */ |
| 40 | ldr x3, =__rel_dyn_end /* x3 <- SRC &__rel_dyn_end */ |
| 41 | fixloop: |
| 42 | ldp x0, x1, [x2], #16 /* (x0,x1) <- (SRC location, fixup) */ |
| 43 | ldr x4, [x2], #8 /* x4 <- addend */ |
| 44 | and x1, x1, #0xffffffff |
| 45 | cmp x1, #1027 /* relative fixup? */ |
| 46 | bne fixnext |
| 47 | |
| 48 | /* relative fix: store addend plus offset at dest location */ |
| 49 | add x0, x0, x9 |
| 50 | add x4, x4, x9 |
| 51 | str x4, [x0] |
| 52 | fixnext: |
| 53 | cmp x2, x3 |
| 54 | b.lo fixloop |
| 55 | |
| 56 | relocate_done: |
| 57 | ret |
| 58 | ENDPROC(relocate_code) |