head.S 6.3 KB

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