start.S 4.7 KB

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