head.S 5.6 KB

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