head.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Common Blackfin startup code
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Enter bugs at http://blackfin.uclinux.org/
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <linux/linkage.h>
  11. #include <linux/init.h>
  12. #include <asm/blackfin.h>
  13. #include <asm/thread_info.h>
  14. #include <asm/trace.h>
  15. #include <asm/asm-offsets.h>
  16. __INIT
  17. ENTRY(__init_clear_bss)
  18. r2 = r2 - r1;
  19. cc = r2 == 0;
  20. if cc jump .L_bss_done;
  21. r2 >>= 2;
  22. p1 = r1;
  23. p2 = r2;
  24. lsetup (1f, 1f) lc0 = p2;
  25. 1: [p1++] = r0;
  26. .L_bss_done:
  27. rts;
  28. ENDPROC(__init_clear_bss)
  29. ENTRY(__start)
  30. /* R0: argument of command line string, passed from uboot, save it */
  31. R7 = R0;
  32. /* Enable Cycle Counter and Nesting Of Interrupts */
  33. #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
  34. R0 = SYSCFG_SNEN;
  35. #else
  36. R0 = SYSCFG_SNEN | SYSCFG_CCEN;
  37. #endif
  38. SYSCFG = R0;
  39. R0 = 0;
  40. /* Clear Out All the data and pointer Registers */
  41. R1 = R0;
  42. R2 = R0;
  43. R3 = R0;
  44. R4 = R0;
  45. R5 = R0;
  46. R6 = R0;
  47. P0 = R0;
  48. P1 = R0;
  49. P2 = R0;
  50. P3 = R0;
  51. P4 = R0;
  52. P5 = R0;
  53. LC0 = r0;
  54. LC1 = r0;
  55. L0 = r0;
  56. L1 = r0;
  57. L2 = r0;
  58. L3 = r0;
  59. /* Clear Out All the DAG Registers */
  60. B0 = r0;
  61. B1 = r0;
  62. B2 = r0;
  63. B3 = r0;
  64. I0 = r0;
  65. I1 = r0;
  66. I2 = r0;
  67. I3 = r0;
  68. M0 = r0;
  69. M1 = r0;
  70. M2 = r0;
  71. M3 = r0;
  72. /*
  73. * Clear ITEST_COMMAND and DTEST_COMMAND registers,
  74. * Leaving these as non-zero can confuse the emulator
  75. */
  76. p0.L = LO(DTEST_COMMAND);
  77. p0.H = HI(DTEST_COMMAND);
  78. [p0] = R0;
  79. [p0 + (ITEST_COMMAND - DTEST_COMMAND)] = R0;
  80. CSYNC;
  81. trace_buffer_init(p0,r0);
  82. P0 = R1;
  83. R0 = R1;
  84. /* Turn off the icache */
  85. p0.l = LO(IMEM_CONTROL);
  86. p0.h = HI(IMEM_CONTROL);
  87. R1 = [p0];
  88. R0 = ~ENICPLB;
  89. R0 = R0 & R1;
  90. [p0] = R0;
  91. SSYNC;
  92. /* Turn off the dcache */
  93. p0.l = LO(DMEM_CONTROL);
  94. p0.h = HI(DMEM_CONTROL);
  95. R1 = [p0];
  96. R0 = ~ENDCPLB;
  97. R0 = R0 & R1;
  98. [p0] = R0;
  99. SSYNC;
  100. /* in case of double faults, save a few things */
  101. p0.l = _init_retx;
  102. p0.h = _init_retx;
  103. R0 = RETX;
  104. [P0] = R0;
  105. #ifdef CONFIG_DEBUG_DOUBLEFAULT
  106. /* Only save these if we are storing them,
  107. * This happens here, since L1 gets clobbered
  108. * below
  109. */
  110. GET_PDA(p0, r0);
  111. r6 = [p0 + PDA_RETX];
  112. p1.l = _init_saved_retx;
  113. p1.h = _init_saved_retx;
  114. [p1] = r6;
  115. r6 = [p0 + PDA_DCPLB];
  116. p1.l = _init_saved_dcplb_fault_addr;
  117. p1.h = _init_saved_dcplb_fault_addr;
  118. [p1] = r6;
  119. r6 = [p0 + PDA_ICPLB];
  120. p1.l = _init_saved_icplb_fault_addr;
  121. p1.h = _init_saved_icplb_fault_addr;
  122. [p1] = r6;
  123. r6 = [p0 + PDA_SEQSTAT];
  124. p1.l = _init_saved_seqstat;
  125. p1.h = _init_saved_seqstat;
  126. [p1] = r6;
  127. #endif
  128. /* Initialize stack pointer */
  129. sp.l = _init_thread_union;
  130. sp.h = _init_thread_union;
  131. fp = sp;
  132. usp = sp;
  133. #ifdef CONFIG_EARLY_PRINTK
  134. call _init_early_exception_vectors;
  135. #endif
  136. r0 = 0 (x);
  137. /* Zero out all of the fun bss regions */
  138. #if L1_DATA_A_LENGTH > 0
  139. r1.l = __sbss_l1;
  140. r1.h = __sbss_l1;
  141. r2.l = __ebss_l1;
  142. r2.h = __ebss_l1;
  143. call __init_clear_bss
  144. #endif
  145. #if L1_DATA_B_LENGTH > 0
  146. r1.l = __sbss_b_l1;
  147. r1.h = __sbss_b_l1;
  148. r2.l = __ebss_b_l1;
  149. r2.h = __ebss_b_l1;
  150. call __init_clear_bss
  151. #endif
  152. #if L2_LENGTH > 0
  153. r1.l = __sbss_l2;
  154. r1.h = __sbss_l2;
  155. r2.l = __ebss_l2;
  156. r2.h = __ebss_l2;
  157. call __init_clear_bss
  158. #endif
  159. r1.l = ___bss_start;
  160. r1.h = ___bss_start;
  161. r2.l = ___bss_stop;
  162. r2.h = ___bss_stop;
  163. call __init_clear_bss
  164. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  165. call _bfin_relocate_l1_mem;
  166. #ifdef CONFIG_BFIN_KERNEL_CLOCK
  167. /* Only use on-chip scratch space for stack when absolutely required
  168. * to avoid Anomaly 05000227 ... we know the init_clocks() func only
  169. * uses L1 text and stack space and no other memory region.
  170. */
  171. # define KERNEL_CLOCK_STACK (L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12)
  172. sp.l = lo(KERNEL_CLOCK_STACK);
  173. sp.h = hi(KERNEL_CLOCK_STACK);
  174. call _init_clocks;
  175. sp = usp; /* usp hasnt been touched, so restore from there */
  176. #endif
  177. /* This section keeps the processor in supervisor mode
  178. * during kernel boot. Switches to user mode at end of boot.
  179. * See page 3-9 of Hardware Reference manual for documentation.
  180. */
  181. /* EVT15 = _real_start */
  182. p0.l = lo(EVT15);
  183. p0.h = hi(EVT15);
  184. p1.l = _real_start;
  185. p1.h = _real_start;
  186. [p0] = p1;
  187. csync;
  188. r0 = EVT_IVG15 (z);
  189. sti r0;
  190. raise 15;
  191. p0.l = .LWAIT_HERE;
  192. p0.h = .LWAIT_HERE;
  193. reti = p0;
  194. #if ANOMALY_05000281
  195. nop; nop; nop;
  196. #endif
  197. rti;
  198. .LWAIT_HERE:
  199. jump .LWAIT_HERE;
  200. ENDPROC(__start)
  201. /* A little BF561 glue ... */
  202. #ifndef WDOG_CTL
  203. # define WDOG_CTL WDOGA_CTL
  204. #endif
  205. ENTRY(_real_start)
  206. /* Enable nested interrupts */
  207. [--sp] = reti;
  208. /* watchdog off for now */
  209. p0.l = lo(WDOG_CTL);
  210. p0.h = hi(WDOG_CTL);
  211. r0 = 0xAD6(z);
  212. w[p0] = r0;
  213. ssync;
  214. /* Pass the u-boot arguments to the global value command line */
  215. R0 = R7;
  216. call _cmdline_init;
  217. /* Load the current thread pointer and stack */
  218. p1 = THREAD_SIZE + 4 (z); /* +4 is for reti loading */
  219. sp = sp + p1;
  220. usp = sp;
  221. fp = sp;
  222. sp += -12;
  223. call _init_pda
  224. sp += 12;
  225. jump.l _start_kernel;
  226. ENDPROC(_real_start)
  227. __FINIT