head.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. /*****************************************************************************/
  97. .data
  98. /*
  99. * During startup we store away the RAM setup. These are not in the
  100. * bss, since their values are determined and written before the bss
  101. * has been cleared.
  102. */
  103. _rambase:
  104. .long 0
  105. _ramvec:
  106. .long 0
  107. _ramstart:
  108. .long 0
  109. _ramend:
  110. .long 0
  111. /*****************************************************************************/
  112. __HEAD
  113. /*
  114. * This is the codes first entry point. This is where it all
  115. * begins...
  116. */
  117. _start:
  118. nop /* filler */
  119. movew #0x2700, %sr /* no interrupts */
  120. /*
  121. * Do any platform or board specific setup now. Most boards
  122. * don't need anything. Those exceptions are define this in
  123. * their board specific includes.
  124. */
  125. PLATFORM_SETUP
  126. /*
  127. * Create basic memory configuration. Set VBR accordingly,
  128. * and size memory.
  129. */
  130. movel #CONFIG_VECTORBASE,%a7
  131. movec %a7,%VBR /* set vectors addr */
  132. movel %a7,_ramvec
  133. movel #CONFIG_RAMBASE,%a7 /* mark the base of RAM */
  134. movel %a7,_rambase
  135. GET_MEM_SIZE /* macro code determines size */
  136. addl %a7,%d0
  137. movel %d0,_ramend /* set end ram addr */
  138. /*
  139. * Now that we know what the memory is, lets enable cache
  140. * and get things moving. This is Coldfire CPU specific.
  141. */
  142. CACHE_ENABLE /* enable CPU cache */
  143. #ifdef CONFIG_ROMFS_FS
  144. /*
  145. * Move ROM filesystem above bss :-)
  146. */
  147. lea _sbss,%a0 /* get start of bss */
  148. lea _ebss,%a1 /* set up destination */
  149. movel %a0,%a2 /* copy of bss start */
  150. movel 8(%a0),%d0 /* get size of ROMFS */
  151. addql #8,%d0 /* allow for rounding */
  152. andl #0xfffffffc, %d0 /* whole words */
  153. addl %d0,%a0 /* copy from end */
  154. addl %d0,%a1 /* copy from end */
  155. movel %a1,_ramstart /* set start of ram */
  156. _copy_romfs:
  157. movel -(%a0),%d0 /* copy dword */
  158. movel %d0,-(%a1)
  159. cmpl %a0,%a2 /* check if at end */
  160. bne _copy_romfs
  161. #else /* CONFIG_ROMFS_FS */
  162. lea _ebss,%a1
  163. movel %a1,_ramstart
  164. #endif /* CONFIG_ROMFS_FS */
  165. /*
  166. * Zero out the bss region.
  167. */
  168. lea _sbss,%a0 /* get start of bss */
  169. lea _ebss,%a1 /* get end of bss */
  170. clrl %d0 /* set value */
  171. _clear_bss:
  172. movel %d0,(%a0)+ /* clear each word */
  173. cmpl %a0,%a1 /* check if at end */
  174. bne _clear_bss
  175. /*
  176. * Load the current task pointer and stack.
  177. */
  178. lea init_thread_union,%a0
  179. lea THREAD_SIZE(%a0),%sp
  180. /*
  181. * Assember start up done, start code proper.
  182. */
  183. jsr start_kernel /* start Linux kernel */
  184. _exit:
  185. jmp _exit /* should never get here */
  186. /*****************************************************************************/