start.S 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <asm-offsets.h>
  7. #include <config.h>
  8. #include <linux/linkage.h>
  9. #include <asm/arcregs.h>
  10. ENTRY(_start)
  11. /* Setup interrupt vector base that matches "__text_start" */
  12. sr __ivt_start, [ARC_AUX_INTR_VEC_BASE]
  13. /* Setup stack pointer */
  14. mov %sp, CONFIG_SYS_INIT_SP_ADDR
  15. mov %fp, %sp
  16. /* Clear bss */
  17. mov %r0, __bss_start
  18. mov %r1, __bss_end
  19. clear_bss:
  20. st.ab 0, [%r0, 4]
  21. brlt %r0, %r1, clear_bss
  22. /* Zero the one and only argument of "board_init_f" */
  23. mov_s %r0, 0
  24. j board_init_f
  25. ENDPROC(_start)
  26. /*
  27. * void relocate_code (addr_sp, gd, addr_moni)
  28. *
  29. * This "function" does not return, instead it continues in RAM
  30. * after relocating the monitor code.
  31. *
  32. * r0 = start_addr_sp
  33. * r1 = new__gd
  34. * r2 = relocaddr
  35. */
  36. ENTRY(relocate_code)
  37. /*
  38. * r0-r12 might be clobbered by C functions
  39. * so we use r13-r16 for storage here
  40. */
  41. mov %r13, %r0 /* save addr_sp */
  42. mov %r14, %r1 /* save addr of gd */
  43. mov %r15, %r2 /* save addr of destination */
  44. mov %r16, %r2 /* %r9 - relocation offset */
  45. sub %r16, %r16, __image_copy_start
  46. /* Set up the stack */
  47. stack_setup:
  48. mov %sp, %r13
  49. mov %fp, %sp
  50. /* Check if monitor is loaded right in place for relocation */
  51. mov %r0, __image_copy_start
  52. cmp %r0, %r15 /* skip relocation if code loaded */
  53. bz do_board_init_r /* in target location already */
  54. /* Copy data (__image_copy_start - __image_copy_end) to new location */
  55. mov %r1, %r15
  56. mov %r2, __image_copy_end
  57. sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
  58. asr %r2, %r2, 2 /* r3 <- amount of words to copy */
  59. mov %lp_count, %r2
  60. lp copy_end
  61. ld.ab %r2,[%r0,4]
  62. st.ab %r2,[%r1,4]
  63. copy_end:
  64. /* Fix relocations related issues */
  65. bl do_elf_reloc_fixups
  66. #ifndef CONFIG_SYS_ICACHE_OFF
  67. bl invalidate_icache_all
  68. #endif
  69. #ifndef CONFIG_SYS_DCACHE_OFF
  70. bl flush_dcache_all
  71. #endif
  72. /* Update position of intterupt vector table */
  73. lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
  74. add %r0, %r0, %r16 /* Update address */
  75. sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
  76. do_board_init_r:
  77. /* Prepare for exection of "board_init_r" in relocated monitor */
  78. mov %r2, board_init_r /* old address of "board_init_r()" */
  79. add %r2, %r2, %r16 /* new address of "board_init_r()" */
  80. mov %r0, %r14 /* 1-st parameter: gd_t */
  81. mov %r1, %r15 /* 2-nd parameter: dest_addr */
  82. j [%r2]
  83. ENDPROC(relocate_code)