start.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * armboot - Startup Code for XScale CPU-core
  3. *
  4. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  5. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  6. * Copyright (C) 2000 Wolfgang Denk <wd@denx.de>
  7. * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de>
  8. * Copyright (C) 2001 Marius Groger <mag@sysgo.de>
  9. * Copyright (C) 2002 Alex Zupke <azu@sysgo.de>
  10. * Copyright (C) 2002 Gary Jennejohn <garyj@denx.de>
  11. * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net>
  12. * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>
  13. * Copyright (C) 2003 Kshitij <kshitij@ti.com>
  14. * Copyright (C) 2003 Richard Woodruff <r-woodruff2@ti.com>
  15. * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>
  16. * Copyright (C) 2004 Texas Instruments <r-woodruff2@ti.com>
  17. * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
  18. *
  19. * SPDX-License-Identifier: GPL-2.0+
  20. */
  21. #include <asm-offsets.h>
  22. #include <config.h>
  23. /*
  24. *************************************************************************
  25. *
  26. * Startup Code (reset vector)
  27. *
  28. * do important init only if we don't start from memory!
  29. * setup Memory and board specific bits prior to relocation.
  30. * relocate armboot to ram
  31. * setup stack
  32. *
  33. *************************************************************************
  34. */
  35. .globl reset
  36. reset:
  37. /*
  38. * set the cpu to SVC32 mode
  39. */
  40. mrs r0,cpsr
  41. bic r0,r0,#0x1f
  42. orr r0,r0,#0xd3
  43. msr cpsr,r0
  44. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  45. bl cpu_init_crit
  46. #endif
  47. #ifdef CONFIG_CPU_PXA25X
  48. bl lock_cache_for_stack
  49. #endif
  50. bl _main
  51. /*------------------------------------------------------------------------------*/
  52. .globl c_runtime_cpu_setup
  53. c_runtime_cpu_setup:
  54. #ifdef CONFIG_CPU_PXA25X
  55. /*
  56. * Unlock (actually, disable) the cache now that board_init_f
  57. * is done. We could do this earlier but we would need to add
  58. * a new C runtime hook, whereas c_runtime_cpu_setup already
  59. * exists.
  60. * As this routine is just a call to cpu_init_crit, let us
  61. * tail-optimize and do a simple branch here.
  62. */
  63. b cpu_init_crit
  64. #else
  65. bx lr
  66. #endif
  67. /*
  68. *************************************************************************
  69. *
  70. * CPU_init_critical registers
  71. *
  72. * setup important registers
  73. * setup memory timing
  74. *
  75. *************************************************************************
  76. */
  77. #if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_CPU_PXA25X)
  78. cpu_init_crit:
  79. /*
  80. * flush v4 I/D caches
  81. */
  82. mov r0, #0
  83. mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */
  84. mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */
  85. /*
  86. * disable MMU stuff and caches
  87. */
  88. mrc p15, 0, r0, c1, c0, 0
  89. bic r0, r0, #0x00003300 @ clear bits 13:12, 9:8 (--VI --RS)
  90. bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
  91. orr r0, r0, #0x00000002 @ set bit 1 (A) Align
  92. mcr p15, 0, r0, c1, c0, 0
  93. mov pc, lr /* back to my caller */
  94. #endif /* !CONFIG_SKIP_LOWLEVEL_INIT || CONFIG_CPU_PXA25X */
  95. /*
  96. * Enable MMU to use DCache as DRAM.
  97. *
  98. * This is useful on PXA25x and PXA26x in early bootstages, where there is no
  99. * other possible memory available to hold stack.
  100. */
  101. #ifdef CONFIG_CPU_PXA25X
  102. .macro CPWAIT reg
  103. mrc p15, 0, \reg, c2, c0, 0
  104. mov \reg, \reg
  105. sub pc, pc, #4
  106. .endm
  107. lock_cache_for_stack:
  108. /* Domain access -- enable for all CPs */
  109. ldr r0, =0x0000ffff
  110. mcr p15, 0, r0, c3, c0, 0
  111. /* Point TTBR to MMU table */
  112. ldr r0, =mmutable
  113. mcr p15, 0, r0, c2, c0, 0
  114. /* Kick in MMU, ICache, DCache, BTB */
  115. mrc p15, 0, r0, c1, c0, 0
  116. bic r0, #0x1b00
  117. bic r0, #0x0087
  118. orr r0, #0x1800
  119. orr r0, #0x0005
  120. mcr p15, 0, r0, c1, c0, 0
  121. CPWAIT r0
  122. /* Unlock Icache, Dcache */
  123. mcr p15, 0, r0, c9, c1, 1
  124. mcr p15, 0, r0, c9, c2, 1
  125. /* Flush Icache, Dcache, BTB */
  126. mcr p15, 0, r0, c7, c7, 0
  127. /* Unlock I-TLB, D-TLB */
  128. mcr p15, 0, r0, c10, c4, 1
  129. mcr p15, 0, r0, c10, c8, 1
  130. /* Flush TLB */
  131. mcr p15, 0, r0, c8, c7, 0
  132. /* Allocate 4096 bytes of Dcache as RAM */
  133. /* Drain pending loads and stores */
  134. mcr p15, 0, r0, c7, c10, 4
  135. mov r4, #0x00
  136. mov r5, #0x00
  137. mov r2, #0x01
  138. mcr p15, 0, r0, c9, c2, 0
  139. CPWAIT r0
  140. /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */
  141. mov r0, #128
  142. ldr r1, =0xfffff000
  143. alloc:
  144. mcr p15, 0, r1, c7, c2, 5
  145. /* Drain pending loads and stores */
  146. mcr p15, 0, r0, c7, c10, 4
  147. strd r4, [r1], #8
  148. strd r4, [r1], #8
  149. strd r4, [r1], #8
  150. strd r4, [r1], #8
  151. subs r0, #0x01
  152. bne alloc
  153. /* Drain pending loads and stores */
  154. mcr p15, 0, r0, c7, c10, 4
  155. mov r2, #0x00
  156. mcr p15, 0, r2, c9, c2, 0
  157. CPWAIT r0
  158. mov pc, lr
  159. .section .mmutable, "a"
  160. mmutable:
  161. .align 14
  162. /* 0x00000000 - 0xffe00000 : 1:1, uncached mapping */
  163. .set __base, 0
  164. .rept 0xfff
  165. .word (__base << 20) | 0xc12
  166. .set __base, __base + 1
  167. .endr
  168. /* 0xfff00000 : 1:1, cached mapping */
  169. .word (0xfff << 20) | 0x1c1e
  170. #endif /* CONFIG_CPU_PXA25X */