relocate_64.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <asm-offsets.h>
  11. #include <config.h>
  12. #include <linux/linkage.h>
  13. /*
  14. * void relocate_code (addr_moni)
  15. *
  16. * This function relocates the monitor code.
  17. * x0 holds the destination address.
  18. */
  19. ENTRY(relocate_code)
  20. /*
  21. * Copy u-boot from flash to RAM
  22. */
  23. ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */
  24. subs x9, x0, x1 /* x9 <- relocation offset */
  25. b.eq relocate_done /* skip relocation */
  26. ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */
  27. copy_loop:
  28. ldp x10, x11, [x1], #16 /* copy from source address [x1] */
  29. stp x10, x11, [x0], #16 /* copy to target address [x0] */
  30. cmp x1, x2 /* until source end address [x2] */
  31. b.lo copy_loop
  32. /*
  33. * Fix .rela.dyn relocations
  34. */
  35. ldr x2, =__rel_dyn_start /* x2 <- SRC &__rel_dyn_start */
  36. ldr x3, =__rel_dyn_end /* x3 <- SRC &__rel_dyn_end */
  37. fixloop:
  38. ldp x0, x1, [x2], #16 /* (x0,x1) <- (SRC location, fixup) */
  39. ldr x4, [x2], #8 /* x4 <- addend */
  40. and x1, x1, #0xffffffff
  41. cmp x1, #1027 /* relative fixup? */
  42. bne fixnext
  43. /* relative fix: store addend plus offset at dest location */
  44. add x0, x0, x9
  45. add x4, x4, x9
  46. str x4, [x0]
  47. fixnext:
  48. cmp x2, x3
  49. b.lo fixloop
  50. relocate_done:
  51. ret
  52. ENDPROC(relocate_code)