start.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * Startup Code for MIPS32 CPU-core
  3. *
  4. * Copyright (c) 2003 Wolfgang Denk <wd@denx.de>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <asm-offsets.h>
  9. #include <config.h>
  10. #include <asm/asm.h>
  11. #include <asm/regdef.h>
  12. #include <asm/mipsregs.h>
  13. #ifndef CONFIG_SYS_INIT_SP_ADDR
  14. #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
  15. CONFIG_SYS_INIT_SP_OFFSET)
  16. #endif
  17. #ifdef CONFIG_32BIT
  18. # define MIPS_RELOC 3
  19. # define STATUS_SET 0
  20. #endif
  21. #ifdef CONFIG_64BIT
  22. # ifdef CONFIG_SYS_LITTLE_ENDIAN
  23. # define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
  24. (((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym))
  25. # else
  26. # define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
  27. ((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24)
  28. # endif
  29. # define MIPS_RELOC MIPS64_R_INFO(0x00, 0x00, 0x12, 0x03)
  30. # define STATUS_SET ST0_KX
  31. #endif
  32. .set noreorder
  33. .macro init_wr sel
  34. MTC0 zero, CP0_WATCHLO,\sel
  35. mtc0 t1, CP0_WATCHHI,\sel
  36. mfc0 t0, CP0_WATCHHI,\sel
  37. bgez t0, wr_done
  38. nop
  39. .endm
  40. .macro uhi_mips_exception
  41. move k0, t9 # preserve t9 in k0
  42. move k1, a0 # preserve a0 in k1
  43. li t9, 15 # UHI exception operation
  44. li a0, 0 # Use hard register context
  45. sdbbp 1 # Invoke UHI operation
  46. .endm
  47. .macro setup_stack_gd
  48. li t0, -16
  49. PTR_LI t1, CONFIG_SYS_INIT_SP_ADDR
  50. and sp, t1, t0 # force 16 byte alignment
  51. PTR_SUBU \
  52. sp, sp, GD_SIZE # reserve space for gd
  53. and sp, sp, t0 # force 16 byte alignment
  54. move k0, sp # save gd pointer
  55. #ifdef CONFIG_SYS_MALLOC_F_LEN
  56. li t2, CONFIG_SYS_MALLOC_F_LEN
  57. PTR_SUBU \
  58. sp, sp, t2 # reserve space for early malloc
  59. and sp, sp, t0 # force 16 byte alignment
  60. #endif
  61. move fp, sp
  62. /* Clear gd */
  63. move t0, k0
  64. 1:
  65. PTR_S zero, 0(t0)
  66. blt t0, t1, 1b
  67. PTR_ADDIU t0, PTRSIZE
  68. #ifdef CONFIG_SYS_MALLOC_F_LEN
  69. PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset
  70. #endif
  71. .endm
  72. ENTRY(_start)
  73. /* U-Boot entry point */
  74. b reset
  75. mtc0 zero, CP0_COUNT # clear cp0 count for most accurate boot timing
  76. #if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
  77. /*
  78. * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
  79. * access external NOR flashes. If the board boots from NOR flash the
  80. * internal BootROM does a blind read at address 0xB0000010 to read the
  81. * initial configuration for that EBU in order to access the flash
  82. * device with correct parameters. This config option is board-specific.
  83. */
  84. .org 0x10
  85. .word CONFIG_SYS_XWAY_EBU_BOOTCFG
  86. .word 0x0
  87. #endif
  88. #if defined(CONFIG_MALTA)
  89. /*
  90. * Linux expects the Board ID here.
  91. */
  92. .org 0x10
  93. .word 0x00000420 # 0x420 (Malta Board with CoreLV)
  94. .word 0x00000000
  95. #endif
  96. #if defined(CONFIG_ROM_EXCEPTION_VECTORS)
  97. /*
  98. * Exception vector entry points. When running from ROM, an exception
  99. * cannot be handled. Halt execution and transfer control to debugger,
  100. * if one is attached.
  101. */
  102. .org 0x200
  103. /* TLB refill, 32 bit task */
  104. uhi_mips_exception
  105. .org 0x280
  106. /* XTLB refill, 64 bit task */
  107. uhi_mips_exception
  108. .org 0x300
  109. /* Cache error exception */
  110. uhi_mips_exception
  111. .org 0x380
  112. /* General exception */
  113. uhi_mips_exception
  114. .org 0x400
  115. /* Catch interrupt exceptions */
  116. uhi_mips_exception
  117. .org 0x480
  118. /* EJTAG debug exception */
  119. 1: b 1b
  120. nop
  121. .org 0x500
  122. #endif
  123. reset:
  124. #if __mips_isa_rev >= 6
  125. mfc0 t0, CP0_CONFIG, 5
  126. and t0, t0, MIPS_CONF5_VP
  127. beqz t0, 1f
  128. nop
  129. b 2f
  130. mfc0 t0, CP0_GLOBALNUMBER
  131. #endif
  132. #ifdef CONFIG_ARCH_BMIPS
  133. 1: mfc0 t0, CP0_DIAGNOSTIC, 3
  134. and t0, t0, (1 << 31)
  135. #else
  136. 1: mfc0 t0, CP0_EBASE
  137. and t0, t0, EBASE_CPUNUM
  138. #endif
  139. /* Hang if this isn't the first CPU in the system */
  140. 2: beqz t0, 4f
  141. nop
  142. 3: wait
  143. b 3b
  144. nop
  145. /* Init CP0 Status */
  146. 4: mfc0 t0, CP0_STATUS
  147. and t0, ST0_IMPL
  148. or t0, ST0_BEV | ST0_ERL | STATUS_SET
  149. mtc0 t0, CP0_STATUS
  150. /*
  151. * Check whether CP0 Config1 is implemented. If not continue
  152. * with legacy Watch register initialization.
  153. */
  154. mfc0 t0, CP0_CONFIG
  155. bgez t0, wr_legacy
  156. nop
  157. /*
  158. * Check WR bit in CP0 Config1 to determine if Watch registers
  159. * are implemented.
  160. */
  161. mfc0 t0, CP0_CONFIG, 1
  162. andi t0, (1 << 3)
  163. beqz t0, wr_done
  164. nop
  165. /* Clear Watch Status bits and disable watch exceptions */
  166. li t1, 0x7 # Clear I, R and W conditions
  167. init_wr 0
  168. init_wr 1
  169. init_wr 2
  170. init_wr 3
  171. init_wr 4
  172. init_wr 5
  173. init_wr 6
  174. init_wr 7
  175. b wr_done
  176. nop
  177. wr_legacy:
  178. MTC0 zero, CP0_WATCHLO
  179. mtc0 zero, CP0_WATCHHI
  180. wr_done:
  181. /* Clear WP, IV and SW interrupts */
  182. mtc0 zero, CP0_CAUSE
  183. /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
  184. mtc0 zero, CP0_COMPARE
  185. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  186. mfc0 t0, CP0_CONFIG
  187. and t0, t0, MIPS_CONF_IMPL
  188. or t0, t0, CONF_CM_UNCACHED
  189. mtc0 t0, CP0_CONFIG
  190. ehb
  191. #endif
  192. #ifdef CONFIG_MIPS_CM
  193. PTR_LA t9, mips_cm_map
  194. jalr t9
  195. nop
  196. #endif
  197. #ifdef CONFIG_MIPS_INIT_STACK_IN_SRAM
  198. /* Set up initial stack and global data */
  199. setup_stack_gd
  200. # ifdef CONFIG_DEBUG_UART
  201. /* Earliest point to set up debug uart */
  202. PTR_LA t9, debug_uart_init
  203. jalr t9
  204. nop
  205. # endif
  206. #endif
  207. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  208. # ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
  209. /* Initialize any external memory */
  210. PTR_LA t9, lowlevel_init
  211. jalr t9
  212. nop
  213. # endif
  214. /* Initialize caches... */
  215. PTR_LA t9, mips_cache_reset
  216. jalr t9
  217. nop
  218. # ifndef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
  219. /* Initialize any external memory */
  220. PTR_LA t9, lowlevel_init
  221. jalr t9
  222. nop
  223. # endif
  224. #endif
  225. #ifndef CONFIG_MIPS_INIT_STACK_IN_SRAM
  226. /* Set up initial stack and global data */
  227. setup_stack_gd
  228. # ifdef CONFIG_DEBUG_UART
  229. /* Earliest point to set up debug uart */
  230. PTR_LA t9, debug_uart_init
  231. jalr t9
  232. nop
  233. # endif
  234. #endif
  235. move a0, zero # a0 <-- boot_flags = 0
  236. PTR_LA t9, board_init_f
  237. jr t9
  238. move ra, zero
  239. END(_start)