relocate.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * relocate - common relocation function for ARM U-Boot
  3. *
  4. * Copyright (c) 2013 Albert ARIBAUD <albert.u.boot@aribaud.net>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <linux/linkage.h>
  25. /*
  26. * void relocate_code(addr_moni)
  27. *
  28. * This function relocates the monitor code.
  29. *
  30. * NOTE:
  31. * To prevent the code below from containing references with an R_ARM_ABS32
  32. * relocation record type, we never refer to linker-defined symbols directly.
  33. * Instead, we declare literals which contain their relative location with
  34. * respect to relocate_code, and at run time, add relocate_code back to them.
  35. */
  36. ENTRY(relocate_code)
  37. ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
  38. subs r9, r0, r1 /* r9 <- relocation offset */
  39. beq relocate_done /* skip relocation */
  40. ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */
  41. copy_loop:
  42. ldmia r1!, {r10-r11} /* copy from source address [r1] */
  43. stmia r0!, {r10-r11} /* copy to target address [r0] */
  44. cmp r1, r2 /* until source end address [r2] */
  45. blo copy_loop
  46. /*
  47. * fix .rel.dyn relocations
  48. */
  49. ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
  50. ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
  51. fixloop:
  52. ldmia r2!, {r0-r1} /* (r0,r1) <- (SRC location,fixup) */
  53. and r1, r1, #0xff
  54. cmp r1, #23 /* relative fixup? */
  55. bne fixnext
  56. /* relative fix: increase location by offset */
  57. add r0, r0, r9
  58. ldr r1, [r0]
  59. add r1, r1, r9
  60. str r1, [r0]
  61. fixnext:
  62. cmp r2, r3
  63. blo fixloop
  64. relocate_done:
  65. /* ARMv4- don't know bx lr but the assembler fails to see that */
  66. #ifdef __ARM_ARCH_4__
  67. mov pc, lr
  68. #else
  69. bx lr
  70. #endif
  71. ENDPROC(relocate_code)