head.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*****************************************************************************/
  2. /*
  3. * head.S -- common startup code for ColdFire CPUs.
  4. *
  5. * (C) Copyright 1999-2004, Greg Ungerer (gerg@snapgear.com).
  6. */
  7. /*****************************************************************************/
  8. #include <linux/config.h>
  9. #include <linux/sys.h>
  10. #include <linux/linkage.h>
  11. #include <asm/asm-offsets.h>
  12. #include <asm/coldfire.h>
  13. #include <asm/mcfcache.h>
  14. #include <asm/mcfsim.h>
  15. /*****************************************************************************/
  16. /*
  17. * Define fixed memory sizes. Configuration of a fixed memory size
  18. * overrides everything else. If the user defined a size we just
  19. * blindly use it (they know what they are doing right :-)
  20. */
  21. #if defined(CONFIG_RAM32MB)
  22. #define MEM_SIZE 0x02000000 /* memory size 32Mb */
  23. #elif defined(CONFIG_RAM16MB)
  24. #define MEM_SIZE 0x01000000 /* memory size 16Mb */
  25. #elif defined(CONFIG_RAM8MB)
  26. #define MEM_SIZE 0x00800000 /* memory size 8Mb */
  27. #elif defined(CONFIG_RAM4MB)
  28. #define MEM_SIZE 0x00400000 /* memory size 4Mb */
  29. #elif defined(CONFIG_RAM1MB)
  30. #define MEM_SIZE 0x00100000 /* memory size 1Mb */
  31. #endif
  32. /*
  33. * Memory size exceptions for special cases. Some boards may be set
  34. * for auto memory sizing, but we can't do it that way for some reason.
  35. * For example the 5206eLITE board has static RAM, and auto-detecting
  36. * the SDRAM will do you no good at all. Same goes for the MOD5272.
  37. */
  38. #ifdef CONFIG_RAMAUTO
  39. #if defined(CONFIG_M5206eLITE)
  40. #define MEM_SIZE 0x00100000 /* 1MiB default memory */
  41. #endif
  42. #if defined(CONFIG_MOD5272)
  43. #define MEM_SIZE 0x00800000 /* 8MiB default memory */
  44. #endif
  45. #endif /* CONFIG_RAMAUTO */
  46. /*
  47. * If we don't have a fixed memory size now, then lets build in code
  48. * to auto detect the DRAM size. Obviously this is the prefered
  49. * method, and should work for most boards (it won't work for those
  50. * that do not have their RAM starting at address 0).
  51. */
  52. #if defined(MEM_SIZE)
  53. .macro GET_MEM_SIZE
  54. movel #MEM_SIZE,%d0 /* hard coded memory size */
  55. .endm
  56. #elif defined(CONFIG_M5206) || defined(CONFIG_M5206e) || \
  57. defined(CONFIG_M5249) || defined(CONFIG_M527x) || \
  58. defined(CONFIG_M528x) || defined(CONFIG_M5307) || \
  59. defined(CONFIG_M5407)
  60. /*
  61. * Not all these devices have exactly the same DRAM controller,
  62. * but the DCMR register is virtually identical - give or take
  63. * a couple of bits. The only exception is the 5272 devices, their
  64. * DRAM controller is quite different.
  65. */
  66. .macro GET_MEM_SIZE
  67. movel MCF_MBAR+MCFSIM_DMR0,%d0 /* get mask for 1st bank */
  68. btst #0,%d0 /* check if region enabled */
  69. beq 1f
  70. andl #0xfffc0000,%d0
  71. beq 1f
  72. addl #0x00040000,%d0 /* convert mask to size */
  73. 1:
  74. movel MCF_MBAR+MCFSIM_DMR1,%d1 /* get mask for 2nd bank */
  75. btst #0,%d1 /* check if region enabled */
  76. beq 2f
  77. andl #0xfffc0000, %d1
  78. beq 2f
  79. addl #0x00040000,%d1
  80. addl %d1,%d0 /* total mem size in d0 */
  81. 2:
  82. .endm
  83. #elif defined(CONFIG_M5272)
  84. .macro GET_MEM_SIZE
  85. movel MCF_MBAR+MCFSIM_CSOR7,%d0 /* get SDRAM address mask */
  86. andil #0xfffff000,%d0 /* mask out chip select options */
  87. negl %d0 /* negate bits */
  88. .endm
  89. #else
  90. #error "ERROR: I don't know how to determine your boards memory size?"
  91. #endif
  92. /*
  93. * Most ColdFire boards have their DRAM starting at address 0.
  94. * Notable exception is the 5206eLITE board, another is the MOD5272.
  95. */
  96. #if defined(CONFIG_M5206eLITE)
  97. #define MEM_BASE 0x30000000
  98. #endif
  99. #if defined(CONFIG_MOD5272)
  100. #define MEM_BASE 0x02000000
  101. #define VBR_BASE 0x20000000 /* vectors in SRAM */
  102. #endif
  103. #ifndef MEM_BASE
  104. #define MEM_BASE 0x00000000 /* memory base at address 0 */
  105. #endif
  106. /*
  107. * The default location for the vectors is at the base of RAM.
  108. * Some boards might like to use internal SRAM or something like
  109. * that. If no board specific header defines an alternative then
  110. * use the base of RAM.
  111. */
  112. #ifndef VBR_BASE
  113. #define VBR_BASE MEM_BASE /* vector address */
  114. #endif
  115. /*****************************************************************************/
  116. /*
  117. * Boards and platforms can do specific early hardware setup if
  118. * they need to. Most don't need this, define away if not required.
  119. */
  120. #ifndef PLATFORM_SETUP
  121. #define PLATFORM_SETUP
  122. #endif
  123. /*****************************************************************************/
  124. .global _start
  125. .global _rambase
  126. .global _ramvec
  127. .global _ramstart
  128. .global _ramend
  129. /*****************************************************************************/
  130. .data
  131. /*
  132. * During startup we store away the RAM setup. These are not in the
  133. * bss, since their values are determined and written before the bss
  134. * has been cleared.
  135. */
  136. _rambase:
  137. .long 0
  138. _ramvec:
  139. .long 0
  140. _ramstart:
  141. .long 0
  142. _ramend:
  143. .long 0
  144. /*****************************************************************************/
  145. .text
  146. /*
  147. * This is the codes first entry point. This is where it all
  148. * begins...
  149. */
  150. _start:
  151. nop /* filler */
  152. movew #0x2700, %sr /* no interrupts */
  153. /*
  154. * Do any platform or board specific setup now. Most boards
  155. * don't need anything. Those exceptions are define this in
  156. * their board specific includes.
  157. */
  158. PLATFORM_SETUP
  159. /*
  160. * Create basic memory configuration. Set VBR accordingly,
  161. * and size memory.
  162. */
  163. movel #VBR_BASE,%a7
  164. movec %a7,%VBR /* set vectors addr */
  165. movel %a7,_ramvec
  166. movel #MEM_BASE,%a7 /* mark the base of RAM */
  167. movel %a7,_rambase
  168. GET_MEM_SIZE /* macro code determines size */
  169. addl %a7,%d0
  170. movel %d0,_ramend /* set end ram addr */
  171. /*
  172. * Now that we know what the memory is, lets enable cache
  173. * and get things moving. This is Coldfire CPU specific.
  174. */
  175. CACHE_ENABLE /* enable CPU cache */
  176. #ifdef CONFIG_ROMFS_FS
  177. /*
  178. * Move ROM filesystem above bss :-)
  179. */
  180. lea _sbss,%a0 /* get start of bss */
  181. lea _ebss,%a1 /* set up destination */
  182. movel %a0,%a2 /* copy of bss start */
  183. movel 8(%a0),%d0 /* get size of ROMFS */
  184. addql #8,%d0 /* allow for rounding */
  185. andl #0xfffffffc, %d0 /* whole words */
  186. addl %d0,%a0 /* copy from end */
  187. addl %d0,%a1 /* copy from end */
  188. movel %a1,_ramstart /* set start of ram */
  189. _copy_romfs:
  190. movel -(%a0),%d0 /* copy dword */
  191. movel %d0,-(%a1)
  192. cmpl %a0,%a2 /* check if at end */
  193. bne _copy_romfs
  194. #else /* CONFIG_ROMFS_FS */
  195. lea _ebss,%a1
  196. movel %a1,_ramstart
  197. #endif /* CONFIG_ROMFS_FS */
  198. /*
  199. * Zero out the bss region.
  200. */
  201. lea _sbss,%a0 /* get start of bss */
  202. lea _ebss,%a1 /* get end of bss */
  203. clrl %d0 /* set value */
  204. _clear_bss:
  205. movel %d0,(%a0)+ /* clear each word */
  206. cmpl %a0,%a1 /* check if at end */
  207. bne _clear_bss
  208. /*
  209. * Load the current task pointer and stack.
  210. */
  211. lea init_thread_union,%a0
  212. lea THREAD_SIZE(%a0),%sp
  213. /*
  214. * Assember start up done, start code proper.
  215. */
  216. jsr start_kernel /* start Linux kernel */
  217. _exit:
  218. jmp _exit /* should never get here */
  219. /*****************************************************************************/