head.S 5.8 KB

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