start.S 4.8 KB

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