head.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Common Blackfin startup code
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/linkage.h>
  9. #include <linux/init.h>
  10. #include <asm/blackfin.h>
  11. #include <asm/thread_info.h>
  12. #include <asm/trace.h>
  13. #include <asm/asm-offsets.h>
  14. __INIT
  15. ENTRY(__init_clear_bss)
  16. r2 = r2 - r1;
  17. cc = r2 == 0;
  18. if cc jump .L_bss_done;
  19. r2 >>= 2;
  20. p1 = r1;
  21. p2 = r2;
  22. lsetup (1f, 1f) lc0 = p2;
  23. 1: [p1++] = r0;
  24. .L_bss_done:
  25. rts;
  26. ENDPROC(__init_clear_bss)
  27. ENTRY(__start)
  28. /* R0: argument of command line string, passed from uboot, save it */
  29. R7 = R0;
  30. /* Enable Cycle Counter and Nesting Of Interrupts */
  31. #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
  32. R0 = SYSCFG_SNEN;
  33. #else
  34. R0 = SYSCFG_SNEN | SYSCFG_CCEN;
  35. #endif
  36. SYSCFG = R0;
  37. /* Optimization register tricks: keep a base value in the
  38. * reserved P registers so we use the load/store with an
  39. * offset syntax. R0 = [P5 + <constant>];
  40. * P5 - core MMR base
  41. * R6 - 0
  42. */
  43. r6 = 0;
  44. p5.l = 0;
  45. p5.h = hi(COREMMR_BASE);
  46. /* Zero out registers required by Blackfin ABI */
  47. /* Disable circular buffers */
  48. L0 = r6;
  49. L1 = r6;
  50. L2 = r6;
  51. L3 = r6;
  52. /* Disable hardware loops in case we were started by 'go' */
  53. LC0 = r6;
  54. LC1 = r6;
  55. /*
  56. * Clear ITEST_COMMAND and DTEST_COMMAND registers,
  57. * Leaving these as non-zero can confuse the emulator
  58. */
  59. [p5 + (DTEST_COMMAND - COREMMR_BASE)] = r6;
  60. [p5 + (ITEST_COMMAND - COREMMR_BASE)] = r6;
  61. CSYNC;
  62. trace_buffer_init(p0,r0);
  63. /* Turn off the icache */
  64. r1 = [p5 + (IMEM_CONTROL - COREMMR_BASE)];
  65. BITCLR (r1, ENICPLB_P);
  66. [p5 + (IMEM_CONTROL - COREMMR_BASE)] = r1;
  67. SSYNC;
  68. /* Turn off the dcache */
  69. r1 = [p5 + (DMEM_CONTROL - COREMMR_BASE)];
  70. BITCLR (r1, ENDCPLB_P);
  71. [p5 + (DMEM_CONTROL - COREMMR_BASE)] = r1;
  72. SSYNC;
  73. /* in case of double faults, save a few things */
  74. p1.l = _initial_pda;
  75. p1.h = _initial_pda;
  76. r4 = RETX;
  77. #ifdef CONFIG_DEBUG_DOUBLEFAULT
  78. /* Only save these if we are storing them,
  79. * This happens here, since L1 gets clobbered
  80. * below
  81. */
  82. GET_PDA(p0, r0);
  83. r0 = [p0 + PDA_DF_RETX];
  84. r1 = [p0 + PDA_DF_DCPLB];
  85. r2 = [p0 + PDA_DF_ICPLB];
  86. r3 = [p0 + PDA_DF_SEQSTAT];
  87. [p1 + PDA_INIT_DF_RETX] = r0;
  88. [p1 + PDA_INIT_DF_DCPLB] = r1;
  89. [p1 + PDA_INIT_DF_ICPLB] = r2;
  90. [p1 + PDA_INIT_DF_SEQSTAT] = r3;
  91. #endif
  92. [p1 + PDA_INIT_RETX] = r4;
  93. /* Initialize stack pointer */
  94. sp.l = _init_thread_union + THREAD_SIZE;
  95. sp.h = _init_thread_union + THREAD_SIZE;
  96. fp = sp;
  97. usp = sp;
  98. #ifdef CONFIG_EARLY_PRINTK
  99. call _init_early_exception_vectors;
  100. r0 = (EVT_IVHW | EVT_IRPTEN | EVT_EVX | EVT_NMI | EVT_RST | EVT_EMU);
  101. sti r0;
  102. #endif
  103. r0 = r6;
  104. /* Zero out all of the fun bss regions */
  105. #if L1_DATA_A_LENGTH > 0
  106. r1.l = __sbss_l1;
  107. r1.h = __sbss_l1;
  108. r2.l = __ebss_l1;
  109. r2.h = __ebss_l1;
  110. call __init_clear_bss
  111. #endif
  112. #if L1_DATA_B_LENGTH > 0
  113. r1.l = __sbss_b_l1;
  114. r1.h = __sbss_b_l1;
  115. r2.l = __ebss_b_l1;
  116. r2.h = __ebss_b_l1;
  117. call __init_clear_bss
  118. #endif
  119. #if L2_LENGTH > 0
  120. r1.l = __sbss_l2;
  121. r1.h = __sbss_l2;
  122. r2.l = __ebss_l2;
  123. r2.h = __ebss_l2;
  124. call __init_clear_bss
  125. #endif
  126. r1.l = ___bss_start;
  127. r1.h = ___bss_start;
  128. r2.l = ___bss_stop;
  129. r2.h = ___bss_stop;
  130. call __init_clear_bss
  131. /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
  132. call _bfin_relocate_l1_mem;
  133. #ifdef CONFIG_ROMKERNEL
  134. call _bfin_relocate_xip_data;
  135. #endif
  136. #ifdef CONFIG_BFIN_KERNEL_CLOCK
  137. /* Only use on-chip scratch space for stack when absolutely required
  138. * to avoid Anomaly 05000227 ... we know the init_clocks() func only
  139. * uses L1 text and stack space and no other memory region.
  140. */
  141. # define KERNEL_CLOCK_STACK (L1_SCRATCH_START + L1_SCRATCH_LENGTH - 12)
  142. sp.l = lo(KERNEL_CLOCK_STACK);
  143. sp.h = hi(KERNEL_CLOCK_STACK);
  144. call _init_clocks;
  145. sp = usp; /* usp hasn't been touched, so restore from there */
  146. #endif
  147. /* This section keeps the processor in supervisor mode
  148. * during kernel boot. Switches to user mode at end of boot.
  149. * See page 3-9 of Hardware Reference manual for documentation.
  150. */
  151. /* EVT15 = _real_start */
  152. p1.l = _real_start;
  153. p1.h = _real_start;
  154. [p5 + (EVT15 - COREMMR_BASE)] = p1;
  155. csync;
  156. #ifdef CONFIG_EARLY_PRINTK
  157. r0 = (EVT_IVG15 | EVT_IVHW | EVT_IRPTEN | EVT_EVX | EVT_NMI | EVT_RST | EVT_EMU) (z);
  158. #else
  159. r0 = EVT_IVG15 (z);
  160. #endif
  161. sti r0;
  162. raise 15;
  163. #ifdef CONFIG_EARLY_PRINTK
  164. p0.l = _early_trap;
  165. p0.h = _early_trap;
  166. #else
  167. p0.l = .LWAIT_HERE;
  168. p0.h = .LWAIT_HERE;
  169. #endif
  170. reti = p0;
  171. #if ANOMALY_05000281
  172. nop; nop; nop;
  173. #endif
  174. rti;
  175. .LWAIT_HERE:
  176. jump .LWAIT_HERE;
  177. ENDPROC(__start)
  178. /* A little BF561 glue ... */
  179. #ifndef WDOG_CTL
  180. # define WDOG_CTL WDOGA_CTL
  181. #endif
  182. ENTRY(_real_start)
  183. /* Enable nested interrupts */
  184. [--sp] = reti;
  185. /* watchdog off for now */
  186. p0.l = lo(WDOG_CTL);
  187. p0.h = hi(WDOG_CTL);
  188. r0 = 0xAD6(z);
  189. w[p0] = r0;
  190. ssync;
  191. /* Pass the u-boot arguments to the global value command line */
  192. R0 = R7;
  193. call _cmdline_init;
  194. sp += -12 + 4; /* +4 is for reti loading above */
  195. call _init_pda
  196. sp += 12;
  197. jump.l _start_kernel;
  198. ENDPROC(_real_start)
  199. __FINIT