head.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*****************************************************************************/
  2. /*
  3. * head.S -- common startup code for ColdFire CPUs.
  4. *
  5. * (C) Copyright 1999-2006, Greg Ungerer <gerg@snapgear.com>.
  6. */
  7. /*****************************************************************************/
  8. #include <linux/sys.h>
  9. #include <linux/linkage.h>
  10. #include <linux/init.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. * 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 prefered
  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 MCF_MBAR+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 MCF_MBAR+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 MCF_MBAR+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 MCF_MBAR+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. /*
  121. * This is the codes first entry point. This is where it all
  122. * begins...
  123. */
  124. _start:
  125. nop /* filler */
  126. movew #0x2700, %sr /* no interrupts */
  127. #if defined(CONFIG_UBOOT)
  128. movel %sp,_init_sp /* save initial stack pointer */
  129. #endif
  130. /*
  131. * Do any platform or board specific setup now. Most boards
  132. * don't need anything. Those exceptions are define this in
  133. * their board specific includes.
  134. */
  135. PLATFORM_SETUP
  136. /*
  137. * Create basic memory configuration. Set VBR accordingly,
  138. * and size memory.
  139. */
  140. movel #CONFIG_VECTORBASE,%a7
  141. movec %a7,%VBR /* set vectors addr */
  142. movel %a7,_ramvec
  143. movel #CONFIG_RAMBASE,%a7 /* mark the base of RAM */
  144. movel %a7,_rambase
  145. GET_MEM_SIZE /* macro code determines size */
  146. addl %a7,%d0
  147. movel %d0,_ramend /* set end ram addr */
  148. /*
  149. * Now that we know what the memory is, lets enable cache
  150. * and get things moving. This is Coldfire CPU specific.
  151. */
  152. CACHE_ENABLE /* enable CPU cache */
  153. #ifdef CONFIG_ROMFS_FS
  154. /*
  155. * Move ROM filesystem above bss :-)
  156. */
  157. lea _sbss,%a0 /* get start of bss */
  158. lea _ebss,%a1 /* set up destination */
  159. movel %a0,%a2 /* copy of bss start */
  160. movel 8(%a0),%d0 /* get size of ROMFS */
  161. addql #8,%d0 /* allow for rounding */
  162. andl #0xfffffffc, %d0 /* whole words */
  163. addl %d0,%a0 /* copy from end */
  164. addl %d0,%a1 /* copy from end */
  165. movel %a1,_ramstart /* set start of ram */
  166. _copy_romfs:
  167. movel -(%a0),%d0 /* copy dword */
  168. movel %d0,-(%a1)
  169. cmpl %a0,%a2 /* check if at end */
  170. bne _copy_romfs
  171. #else /* CONFIG_ROMFS_FS */
  172. lea _ebss,%a1
  173. movel %a1,_ramstart
  174. #endif /* CONFIG_ROMFS_FS */
  175. /*
  176. * Zero out the bss region.
  177. */
  178. lea _sbss,%a0 /* get start of bss */
  179. lea _ebss,%a1 /* get end of bss */
  180. clrl %d0 /* set value */
  181. _clear_bss:
  182. movel %d0,(%a0)+ /* clear each word */
  183. cmpl %a0,%a1 /* check if at end */
  184. bne _clear_bss
  185. /*
  186. * Load the current task pointer and stack.
  187. */
  188. lea init_thread_union,%a0
  189. lea THREAD_SIZE(%a0),%sp
  190. /*
  191. * Assember start up done, start code proper.
  192. */
  193. jsr start_kernel /* start Linux kernel */
  194. _exit:
  195. jmp _exit /* should never get here */
  196. /*****************************************************************************/