head.S 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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_M525x) || \
  29. defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
  30. defined(CONFIG_M5307) || 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 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. #ifdef CONFIG_MBAR
  141. movel #CONFIG_MBAR+1,%d0 /* configured MBAR address */
  142. movec %d0,%MBAR /* set it */
  143. #endif
  144. /*
  145. * Do any platform or board specific setup now. Most boards
  146. * don't need anything. Those exceptions are define this in
  147. * their board specific includes.
  148. */
  149. PLATFORM_SETUP
  150. /*
  151. * Create basic memory configuration. Set VBR accordingly,
  152. * and size memory.
  153. */
  154. movel #CONFIG_VECTORBASE,%a7
  155. movec %a7,%VBR /* set vectors addr */
  156. movel %a7,_ramvec
  157. movel #CONFIG_RAMBASE,%a7 /* mark the base of RAM */
  158. movel %a7,_rambase
  159. GET_MEM_SIZE /* macro code determines size */
  160. addl %a7,%d0
  161. movel %d0,_ramend /* set end ram addr */
  162. /*
  163. * Now that we know what the memory is, lets enable cache
  164. * and get things moving. This is Coldfire CPU specific. Not
  165. * all version cores have identical cache register setup. But
  166. * it is very similar. Define the exact settings in the headers
  167. * then the code here is the same for all.
  168. */
  169. movel #ACR0_MODE,%d0 /* set RAM region for caching */
  170. movec %d0,%ACR0
  171. movel #ACR1_MODE,%d0 /* anything else to cache? */
  172. movec %d0,%ACR1
  173. #ifdef ACR2_MODE
  174. movel #ACR2_MODE,%d0
  175. movec %d0,%ACR2
  176. movel #ACR3_MODE,%d0
  177. movec %d0,%ACR3
  178. #endif
  179. movel #CACHE_MODE,%d0 /* enable cache */
  180. movec %d0,%CACR
  181. nop
  182. #ifdef CONFIG_MMU
  183. /*
  184. * Identity mapping for the kernel region.
  185. */
  186. movel #(MMUBASE+1),%d0 /* enable MMUBAR registers */
  187. movec %d0,%MMUBAR
  188. movel #MMUOR_CA,%d0 /* clear TLB entries */
  189. movel %d0,MMUOR
  190. movel #0,%d0 /* set ASID to 0 */
  191. movec %d0,%asid
  192. movel #MMUCR_EN,%d0 /* Enable the identity map */
  193. movel %d0,MMUCR
  194. nop /* sync i-pipeline */
  195. movel #_vstart,%a0 /* jump to "virtual" space */
  196. jmp %a0@
  197. _vstart:
  198. #endif /* CONFIG_MMU */
  199. #ifdef CONFIG_ROMFS_FS
  200. /*
  201. * Move ROM filesystem above bss :-)
  202. */
  203. lea __bss_start,%a0 /* get start of bss */
  204. lea __bss_stop,%a1 /* set up destination */
  205. movel %a0,%a2 /* copy of bss start */
  206. movel 8(%a0),%d0 /* get size of ROMFS */
  207. addql #8,%d0 /* allow for rounding */
  208. andl #0xfffffffc, %d0 /* whole words */
  209. addl %d0,%a0 /* copy from end */
  210. addl %d0,%a1 /* copy from end */
  211. movel %a1,_ramstart /* set start of ram */
  212. _copy_romfs:
  213. movel -(%a0),%d0 /* copy dword */
  214. movel %d0,-(%a1)
  215. cmpl %a0,%a2 /* check if at end */
  216. bne _copy_romfs
  217. #else /* CONFIG_ROMFS_FS */
  218. lea __bss_stop,%a1
  219. movel %a1,_ramstart
  220. #endif /* CONFIG_ROMFS_FS */
  221. /*
  222. * Zero out the bss region.
  223. */
  224. lea __bss_start,%a0 /* get start of bss */
  225. lea __bss_stop,%a1 /* get end of bss */
  226. clrl %d0 /* set value */
  227. _clear_bss:
  228. movel %d0,(%a0)+ /* clear each word */
  229. cmpl %a0,%a1 /* check if at end */
  230. bne _clear_bss
  231. /*
  232. * Load the current task pointer and stack.
  233. */
  234. lea init_thread_union,%a0
  235. lea THREAD_SIZE(%a0),%sp
  236. #ifdef CONFIG_MMU
  237. .global m68k_cputype
  238. .global m68k_mmutype
  239. .global m68k_fputype
  240. .global m68k_machtype
  241. movel #CPU_COLDFIRE,%d0
  242. movel %d0,m68k_cputype /* Mark us as a ColdFire */
  243. movel #MMU_COLDFIRE,%d0
  244. movel %d0,m68k_mmutype
  245. movel #FPUTYPE,%d0
  246. movel %d0,m68k_fputype /* Mark FPU type */
  247. movel #MACHINE,%d0
  248. movel %d0,m68k_machtype /* Mark machine type */
  249. lea init_task,%a2 /* Set "current" init task */
  250. #endif
  251. /*
  252. * Assembler start up done, start code proper.
  253. */
  254. jsr start_kernel /* start Linux kernel */
  255. _exit:
  256. jmp _exit /* should never get here */
  257. /*****************************************************************************/