relocate.S 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. mov r6, r0 /* save addr of destination */
  38. ldr r0, =__image_copy_start /* r0 <- SRC &__image_copy_start */
  39. subs r9, r6, r0 /* r9 <- relocation offset */
  40. beq relocate_done /* skip relocation */
  41. mov r1, r6 /* r1 <- scratch for copy loop */
  42. adr r7, relocate_code /* r7 <- SRC &relocate_code */
  43. ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */
  44. copy_loop:
  45. ldmia r0!, {r10-r11} /* copy from source address [r0] */
  46. stmia r1!, {r10-r11} /* copy to target address [r1] */
  47. cmp r0, r2 /* until source end address [r2] */
  48. blo copy_loop
  49. /*
  50. * fix .rel.dyn relocations
  51. */
  52. ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
  53. ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
  54. fixloop:
  55. ldr r0, [r2] /* r0 <- SRC location to fix up */
  56. add r0, r0, r9 /* r0 <- DST location to fix up */
  57. ldr r1, [r2, #4]
  58. and r7, r1, #0xff
  59. cmp r7, #23 /* relative fixup? */
  60. beq fixrel
  61. /* ignore unknown type of fixup */
  62. b fixnext
  63. fixrel:
  64. /* relative fix: increase location by offset */
  65. ldr r1, [r0]
  66. add r1, r1, r9
  67. fixnext:
  68. str r1, [r0]
  69. add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
  70. cmp r2, r3
  71. blo fixloop
  72. relocate_done:
  73. /* ARMv4- don't know bx lr but the assembler fails to see that */
  74. #ifdef __ARM_ARCH_4__
  75. mov pc, lr
  76. #else
  77. bx lr
  78. #endif
  79. ENDPROC(relocate_code)