start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 <asm/arcregs.h>
  9. /*
  10. * Note on the LD/ST addressing modes with address register write-back
  11. *
  12. * LD.a same as LD.aw
  13. *
  14. * LD.a reg1, [reg2, x] => Pre Incr
  15. * Eff Addr for load = [reg2 + x]
  16. *
  17. * LD.ab reg1, [reg2, x] => Post Incr
  18. * Eff Addr for load = [reg2]
  19. */
  20. .macro PUSH reg
  21. st.a \reg, [%sp, -4]
  22. .endm
  23. .macro PUSHAX aux
  24. lr %r9, [\aux]
  25. PUSH %r9
  26. .endm
  27. .macro SAVE_R1_TO_R24
  28. PUSH %r1
  29. PUSH %r2
  30. PUSH %r3
  31. PUSH %r4
  32. PUSH %r5
  33. PUSH %r6
  34. PUSH %r7
  35. PUSH %r8
  36. PUSH %r9
  37. PUSH %r10
  38. PUSH %r11
  39. PUSH %r12
  40. PUSH %r13
  41. PUSH %r14
  42. PUSH %r15
  43. PUSH %r16
  44. PUSH %r17
  45. PUSH %r18
  46. PUSH %r19
  47. PUSH %r20
  48. PUSH %r21
  49. PUSH %r22
  50. PUSH %r23
  51. PUSH %r24
  52. .endm
  53. .macro SAVE_ALL_SYS
  54. /* saving %r0 to reg->r0 in advance since we read %ecr into it */
  55. st %r0, [%sp, -8]
  56. lr %r0, [%ecr] /* all stack addressing is manual so far */
  57. st %r0, [%sp]
  58. st %sp, [%sp, -4]
  59. /* now move %sp to reg->r0 position so we can do "push" automatically */
  60. sub %sp, %sp, 8
  61. SAVE_R1_TO_R24
  62. PUSH %r25
  63. PUSH %gp
  64. PUSH %fp
  65. PUSH %blink
  66. PUSHAX %eret
  67. PUSHAX %erstatus
  68. PUSH %lp_count
  69. PUSHAX %lp_end
  70. PUSHAX %lp_start
  71. PUSHAX %erbta
  72. .endm
  73. .macro SAVE_EXCEPTION_SOURCE
  74. #ifdef CONFIG_MMU
  75. /* If MMU exists exception faulting address is loaded in EFA reg */
  76. lr %r0, [%efa]
  77. #else
  78. /* Otherwise in ERET (exception return) reg */
  79. lr %r0, [%eret]
  80. #endif
  81. .endm
  82. .section .ivt, "ax",@progbits
  83. .align 4
  84. _ivt:
  85. /* Critical system events */
  86. j _start /* 0 - 0x000 */
  87. j memory_error /* 1 - 0x008 */
  88. j instruction_error /* 2 - 0x010 */
  89. /* Device interrupts */
  90. .rept 29
  91. j interrupt_handler /* 3:31 - 0x018:0xF8 */
  92. .endr
  93. /* Exceptions */
  94. j EV_MachineCheck /* 0x100, Fatal Machine check (0x20) */
  95. j EV_TLBMissI /* 0x108, Intruction TLB miss (0x21) */
  96. j EV_TLBMissD /* 0x110, Data TLB miss (0x22) */
  97. j EV_TLBProtV /* 0x118, Protection Violation (0x23)
  98. or Misaligned Access */
  99. j EV_PrivilegeV /* 0x120, Privilege Violation (0x24) */
  100. j EV_Trap /* 0x128, Trap exception (0x25) */
  101. j EV_Extension /* 0x130, Extn Intruction Excp (0x26) */
  102. .text
  103. .globl _start
  104. _start:
  105. /* Setup interrupt vector base that matches "__text_start" */
  106. sr __ivt_start, [ARC_AUX_INTR_VEC_BASE]
  107. /* Setup stack pointer */
  108. mov %sp, CONFIG_SYS_INIT_SP_ADDR
  109. mov %fp, %sp
  110. /* Clear bss */
  111. mov %r0, __bss_start
  112. mov %r1, __bss_end
  113. clear_bss:
  114. st.ab 0, [%r0, 4]
  115. brlt %r0, %r1, clear_bss
  116. /* Zero the one and only argument of "board_init_f" */
  117. mov_s %r0, 0
  118. j board_init_f
  119. memory_error:
  120. SAVE_ALL_SYS
  121. SAVE_EXCEPTION_SOURCE
  122. mov %r1, %sp
  123. j do_memory_error
  124. instruction_error:
  125. SAVE_ALL_SYS
  126. SAVE_EXCEPTION_SOURCE
  127. mov %r1, %sp
  128. j do_instruction_error
  129. interrupt_handler:
  130. /* Todo - save and restore CPU context when interrupts will be in use */
  131. bl do_interrupt_handler
  132. rtie
  133. EV_MachineCheck:
  134. SAVE_ALL_SYS
  135. SAVE_EXCEPTION_SOURCE
  136. mov %r1, %sp
  137. j do_machine_check_fault
  138. EV_TLBMissI:
  139. SAVE_ALL_SYS
  140. mov %r0, %sp
  141. j do_itlb_miss
  142. EV_TLBMissD:
  143. SAVE_ALL_SYS
  144. mov %r0, %sp
  145. j do_dtlb_miss
  146. EV_TLBProtV:
  147. SAVE_ALL_SYS
  148. SAVE_EXCEPTION_SOURCE
  149. mov %r1, %sp
  150. j do_tlb_prot_violation
  151. EV_PrivilegeV:
  152. SAVE_ALL_SYS
  153. mov %r0, %sp
  154. j do_privilege_violation
  155. EV_Trap:
  156. SAVE_ALL_SYS
  157. mov %r0, %sp
  158. j do_trap
  159. EV_Extension:
  160. SAVE_ALL_SYS
  161. mov %r0, %sp
  162. j do_extension
  163. /*
  164. * void relocate_code (addr_sp, gd, addr_moni)
  165. *
  166. * This "function" does not return, instead it continues in RAM
  167. * after relocating the monitor code.
  168. *
  169. * r0 = start_addr_sp
  170. * r1 = new__gd
  171. * r2 = relocaddr
  172. */
  173. .align 4
  174. .globl relocate_code
  175. relocate_code:
  176. /*
  177. * r0-r12 might be clobbered by C functions
  178. * so we use r13-r16 for storage here
  179. */
  180. mov %r13, %r0 /* save addr_sp */
  181. mov %r14, %r1 /* save addr of gd */
  182. mov %r15, %r2 /* save addr of destination */
  183. mov %r16, %r2 /* %r9 - relocation offset */
  184. sub %r16, %r16, __image_copy_start
  185. /* Set up the stack */
  186. stack_setup:
  187. mov %sp, %r13
  188. mov %fp, %sp
  189. /* Check if monitor is loaded right in place for relocation */
  190. mov %r0, __image_copy_start
  191. cmp %r0, %r15 /* skip relocation if code loaded */
  192. bz do_board_init_r /* in target location already */
  193. /* Copy data (__image_copy_start - __image_copy_end) to new location */
  194. mov %r1, %r15
  195. mov %r2, __image_copy_end
  196. sub %r2, %r2, %r0 /* r3 <- amount of bytes to copy */
  197. asr %r2, %r2, 2 /* r3 <- amount of words to copy */
  198. mov %lp_count, %r2
  199. lp copy_end
  200. ld.ab %r2,[%r0,4]
  201. st.ab %r2,[%r1,4]
  202. copy_end:
  203. /* Fix relocations related issues */
  204. bl do_elf_reloc_fixups
  205. #ifndef CONFIG_SYS_ICACHE_OFF
  206. bl invalidate_icache_all
  207. #endif
  208. #ifndef CONFIG_SYS_DCACHE_OFF
  209. bl flush_dcache_all
  210. #endif
  211. /* Update position of intterupt vector table */
  212. lr %r0, [ARC_AUX_INTR_VEC_BASE] /* Read current position */
  213. add %r0, %r0, %r16 /* Update address */
  214. sr %r0, [ARC_AUX_INTR_VEC_BASE] /* Write new position */
  215. do_board_init_r:
  216. /* Prepare for exection of "board_init_r" in relocated monitor */
  217. mov %r2, board_init_r /* old address of "board_init_r()" */
  218. add %r2, %r2, %r16 /* new address of "board_init_r()" */
  219. mov %r0, %r14 /* 1-st parameter: gd_t */
  220. mov %r1, %r15 /* 2-nd parameter: dest_addr */
  221. j [%r2]