head.S 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*****************************************************************************/
  3. /*
  4. * head.S -- common startup code for ColdFire CPUs.
  5. *
  6. * (C) Copyright 1999-2011, Greg Ungerer <gerg@snapgear.com>.
  7. */
  8. /*****************************************************************************/
  9. #include <linux/linkage.h>
  10. #include <linux/init.h>
  11. #include <asm/asm-offsets.h>
  12. #include <asm/coldfire.h>
  13. #include <asm/mcfsim.h>
  14. #include <asm/mcfmmu.h>
  15. #include <asm/thread_info.h>
  16. /*****************************************************************************/
  17. /*
  18. * If we don't have a fixed memory size, then lets build in code
  19. * to auto detect the DRAM size. Obviously this is the preferred
  20. * method, and should work for most boards. It won't work for those
  21. * that do not have their RAM starting at address 0, and it only
  22. * works on SDRAM (not boards fitted with SRAM).
  23. */
  24. #if CONFIG_RAMSIZE != 0
  25. .macro GET_MEM_SIZE
  26. movel #CONFIG_RAMSIZE,%d0 /* hard coded memory size */
  27. .endm
  28. #elif defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
  29. defined(CONFIG_M5249) || defined(CONFIG_M525x) || \
  30. defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
  31. defined(CONFIG_M5307) || defined(CONFIG_M5407)
  32. /*
  33. * Not all these devices have exactly the same DRAM controller,
  34. * but the DCMR register is virtually identical - give or take
  35. * a couple of bits. The only exception is the 5272 devices, their
  36. * DRAM controller is quite different.
  37. */
  38. .macro GET_MEM_SIZE
  39. movel MCFSIM_DMR0,%d0 /* get mask for 1st bank */
  40. btst #0,%d0 /* check if region enabled */
  41. beq 1f
  42. andl #0xfffc0000,%d0
  43. beq 1f
  44. addl #0x00040000,%d0 /* convert mask to size */
  45. 1:
  46. movel MCFSIM_DMR1,%d1 /* get mask for 2nd bank */
  47. btst #0,%d1 /* check if region enabled */
  48. beq 2f
  49. andl #0xfffc0000,%d1
  50. beq 2f
  51. addl #0x00040000,%d1
  52. addl %d1,%d0 /* total mem size in d0 */
  53. 2:
  54. .endm
  55. #elif defined(CONFIG_M5272)
  56. .macro GET_MEM_SIZE
  57. movel MCFSIM_CSOR7,%d0 /* get SDRAM address mask */
  58. andil #0xfffff000,%d0 /* mask out chip select options */
  59. negl %d0 /* negate bits */
  60. .endm
  61. #elif defined(CONFIG_M520x)
  62. .macro GET_MEM_SIZE
  63. clrl %d0
  64. movel MCFSIM_SDCS0, %d2 /* Get SDRAM chip select 0 config */
  65. andl #0x1f, %d2 /* Get only the chip select size */
  66. beq 3f /* Check if it is enabled */
  67. addql #1, %d2 /* Form exponent */
  68. moveql #1, %d0
  69. lsll %d2, %d0 /* 2 ^ exponent */
  70. 3:
  71. movel MCFSIM_SDCS1, %d2 /* Get SDRAM chip select 1 config */
  72. andl #0x1f, %d2 /* Get only the chip select size */
  73. beq 4f /* Check if it is enabled */
  74. addql #1, %d2 /* Form exponent */
  75. moveql #1, %d1
  76. lsll %d2, %d1 /* 2 ^ exponent */
  77. addl %d1, %d0 /* Total size of SDRAM in d0 */
  78. 4:
  79. .endm
  80. #else
  81. #error "ERROR: I don't know how to probe your boards memory size?"
  82. #endif
  83. /*****************************************************************************/
  84. /*
  85. * Boards and platforms can do specific early hardware setup if
  86. * they need to. Most don't need this, define away if not required.
  87. */
  88. #ifndef PLATFORM_SETUP
  89. #define PLATFORM_SETUP
  90. #endif
  91. /*****************************************************************************/
  92. .global _start
  93. .global _rambase
  94. .global _ramvec
  95. .global _ramstart
  96. .global _ramend
  97. #if defined(CONFIG_UBOOT)
  98. .global _init_sp
  99. #endif
  100. /*****************************************************************************/
  101. .data
  102. /*
  103. * During startup we store away the RAM setup. These are not in the
  104. * bss, since their values are determined and written before the bss
  105. * has been cleared.
  106. */
  107. _rambase:
  108. .long 0
  109. _ramvec:
  110. .long 0
  111. _ramstart:
  112. .long 0
  113. _ramend:
  114. .long 0
  115. #if defined(CONFIG_UBOOT)
  116. _init_sp:
  117. .long 0
  118. #endif
  119. /*****************************************************************************/
  120. __HEAD
  121. #ifdef CONFIG_MMU
  122. _start0:
  123. jmp _start
  124. .global kernel_pg_dir
  125. .equ kernel_pg_dir,_start0
  126. .equ .,_start0+0x1000
  127. #endif
  128. /*
  129. * This is the codes first entry point. This is where it all
  130. * begins...
  131. */
  132. _start:
  133. nop /* filler */
  134. movew #0x2700, %sr /* no interrupts */
  135. movel #CACHE_INIT,%d0 /* disable cache */
  136. movec %d0,%CACR
  137. nop
  138. #if defined(CONFIG_UBOOT)
  139. movel %sp,_init_sp /* save initial stack pointer */
  140. #endif
  141. #ifdef CONFIG_MBAR
  142. movel #CONFIG_MBAR+1,%d0 /* configured MBAR address */
  143. movec %d0,%MBAR /* set it */
  144. #endif
  145. /*
  146. * Do any platform or board specific setup now. Most boards
  147. * don't need anything. Those exceptions are define this in
  148. * their board specific includes.
  149. */
  150. PLATFORM_SETUP
  151. /*
  152. * Create basic memory configuration. Set VBR accordingly,
  153. * and size memory.
  154. */
  155. movel #CONFIG_VECTORBASE,%a7
  156. movec %a7,%VBR /* set vectors addr */
  157. movel %a7,_ramvec
  158. movel #CONFIG_RAMBASE,%a7 /* mark the base of RAM */
  159. movel %a7,_rambase
  160. GET_MEM_SIZE /* macro code determines size */
  161. addl %a7,%d0
  162. movel %d0,_ramend /* set end ram addr */
  163. /*
  164. * Now that we know what the memory is, lets enable cache
  165. * and get things moving. This is Coldfire CPU specific. Not
  166. * all version cores have identical cache register setup. But
  167. * it is very similar. Define the exact settings in the headers
  168. * then the code here is the same for all.
  169. */
  170. movel #ACR0_MODE,%d0 /* set RAM region for caching */
  171. movec %d0,%ACR0
  172. movel #ACR1_MODE,%d0 /* anything else to cache? */
  173. movec %d0,%ACR1
  174. #ifdef ACR2_MODE
  175. movel #ACR2_MODE,%d0
  176. movec %d0,%ACR2
  177. movel #ACR3_MODE,%d0
  178. movec %d0,%ACR3
  179. #endif
  180. movel #CACHE_MODE,%d0 /* enable cache */
  181. movec %d0,%CACR
  182. nop
  183. #ifdef CONFIG_MMU
  184. /*
  185. * Identity mapping for the kernel region.
  186. */
  187. movel #(MMUBASE+1),%d0 /* enable MMUBAR registers */
  188. movec %d0,%MMUBAR
  189. movel #MMUOR_CA,%d0 /* clear TLB entries */
  190. movel %d0,MMUOR
  191. movel #0,%d0 /* set ASID to 0 */
  192. movec %d0,%asid
  193. movel #MMUCR_EN,%d0 /* Enable the identity map */
  194. movel %d0,MMUCR
  195. nop /* sync i-pipeline */
  196. movel #_vstart,%a0 /* jump to "virtual" space */
  197. jmp %a0@
  198. _vstart:
  199. #endif /* CONFIG_MMU */
  200. #ifdef CONFIG_ROMFS_FS
  201. /*
  202. * Move ROM filesystem above bss :-)
  203. */
  204. lea __bss_start,%a0 /* get start of bss */
  205. lea __bss_stop,%a1 /* set up destination */
  206. movel %a0,%a2 /* copy of bss start */
  207. movel 8(%a0),%d0 /* get size of ROMFS */
  208. addql #8,%d0 /* allow for rounding */
  209. andl #0xfffffffc, %d0 /* whole words */
  210. addl %d0,%a0 /* copy from end */
  211. addl %d0,%a1 /* copy from end */
  212. movel %a1,_ramstart /* set start of ram */
  213. _copy_romfs:
  214. movel -(%a0),%d0 /* copy dword */
  215. movel %d0,-(%a1)
  216. cmpl %a0,%a2 /* check if at end */
  217. bne _copy_romfs
  218. #else /* CONFIG_ROMFS_FS */
  219. lea __bss_stop,%a1
  220. movel %a1,_ramstart
  221. #endif /* CONFIG_ROMFS_FS */
  222. /*
  223. * Zero out the bss region.
  224. */
  225. lea __bss_start,%a0 /* get start of bss */
  226. lea __bss_stop,%a1 /* get end of bss */
  227. clrl %d0 /* set value */
  228. _clear_bss:
  229. movel %d0,(%a0)+ /* clear each word */
  230. cmpl %a0,%a1 /* check if at end */
  231. bne _clear_bss
  232. /*
  233. * Load the current task pointer and stack.
  234. */
  235. lea init_thread_union,%a0
  236. lea THREAD_SIZE(%a0),%sp
  237. #ifdef CONFIG_MMU
  238. .global m68k_cputype
  239. .global m68k_mmutype
  240. .global m68k_fputype
  241. .global m68k_machtype
  242. movel #CPU_COLDFIRE,%d0
  243. movel %d0,m68k_cputype /* Mark us as a ColdFire */
  244. movel #MMU_COLDFIRE,%d0
  245. movel %d0,m68k_mmutype
  246. movel #FPUTYPE,%d0
  247. movel %d0,m68k_fputype /* Mark FPU type */
  248. movel #MACHINE,%d0
  249. movel %d0,m68k_machtype /* Mark machine type */
  250. lea init_task,%a2 /* Set "current" init task */
  251. #endif
  252. /*
  253. * Assembler start up done, start code proper.
  254. */
  255. jsr start_kernel /* start Linux kernel */
  256. _exit:
  257. jmp _exit /* should never get here */
  258. /*****************************************************************************/