start.S 5.5 KB

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