relocate_64.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <elf.h>
  13. #include <linux/linkage.h>
  14. #include <asm/macro.h>
  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. stp x29, x30, [sp, #-32]! /* create a stack frame */
  23. mov x29, sp
  24. str x0, [sp, #16]
  25. /*
  26. * Copy u-boot from flash to RAM
  27. */
  28. ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */
  29. subs x9, x0, x1 /* x9 <- relocation offset */
  30. b.eq relocate_done /* skip relocation */
  31. ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */
  32. copy_loop:
  33. ldp x10, x11, [x1], #16 /* copy from source address [x1] */
  34. stp x10, x11, [x0], #16 /* copy to target address [x0] */
  35. cmp x1, x2 /* until source end address [x2] */
  36. b.lo copy_loop
  37. str x0, [sp, #24]
  38. /*
  39. * Fix .rela.dyn relocations
  40. */
  41. ldr x2, =__rel_dyn_start /* x2 <- SRC &__rel_dyn_start */
  42. ldr x3, =__rel_dyn_end /* x3 <- SRC &__rel_dyn_end */
  43. fixloop:
  44. ldp x0, x1, [x2], #16 /* (x0,x1) <- (SRC location, fixup) */
  45. ldr x4, [x2], #8 /* x4 <- addend */
  46. and x1, x1, #0xffffffff
  47. cmp x1, #R_AARCH64_RELATIVE
  48. bne fixnext
  49. /* relative fix: store addend plus offset at dest location */
  50. add x0, x0, x9
  51. add x4, x4, x9
  52. str x4, [x0]
  53. fixnext:
  54. cmp x2, x3
  55. b.lo fixloop
  56. relocate_done:
  57. switch_el x1, 3f, 2f, 1f
  58. bl hang
  59. 3: mrs x0, sctlr_el3
  60. b 0f
  61. 2: mrs x0, sctlr_el2
  62. b 0f
  63. 1: mrs x0, sctlr_el1
  64. 0: tbz w0, #2, 5f /* skip flushing cache if disabled */
  65. tbz w0, #12, 4f /* skip invalidating i-cache if disabled */
  66. ic iallu /* i-cache invalidate all */
  67. isb sy
  68. 4: ldp x0, x1, [sp, #16]
  69. bl __asm_flush_dcache_range
  70. 5: ldp x29, x30, [sp],#16
  71. ret
  72. ENDPROC(relocate_code)