head.S 7.2 KB

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