start.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. * armboot - Startup Code for XScale
  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 Züpke <azu@sysgo.de>
  8. * Copyright (c) 2002 Kyle Harris <kharris@nexus-tech.net>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <config.h>
  29. #include <version.h>
  30. .globl _start
  31. _start: b reset
  32. ldr pc, _undefined_instruction
  33. ldr pc, _software_interrupt
  34. ldr pc, _prefetch_abort
  35. ldr pc, _data_abort
  36. ldr pc, _not_used
  37. ldr pc, _irq
  38. ldr pc, _fiq
  39. _undefined_instruction: .word undefined_instruction
  40. _software_interrupt: .word software_interrupt
  41. _prefetch_abort: .word prefetch_abort
  42. _data_abort: .word data_abort
  43. _not_used: .word not_used
  44. _irq: .word irq
  45. _fiq: .word fiq
  46. .balignl 16,0xdeadbeef
  47. /*
  48. * Startup Code (reset vector)
  49. *
  50. * do important init only if we don't start from memory!
  51. * - relocate armboot to ram
  52. * - setup stack
  53. * - jump to second stage
  54. */
  55. /*
  56. * CFG_MEM_END is in the board dependent config-file (configs/config_BOARD.h)
  57. */
  58. _TEXT_BASE:
  59. .word TEXT_BASE
  60. .globl _armboot_start
  61. _armboot_start:
  62. .word _start
  63. /*
  64. * Note: _armboot_end_data and _armboot_end are defined
  65. * by the (board-dependent) linker script.
  66. * _armboot_end_data is the first usable FLASH address after armboot
  67. */
  68. .globl _armboot_end_data
  69. _armboot_end_data:
  70. .word armboot_end_data
  71. .globl _armboot_end
  72. _armboot_end:
  73. .word armboot_end
  74. /*
  75. * _armboot_real_end is the first usable RAM address behind armboot
  76. * and the various stacks
  77. */
  78. .globl _armboot_real_end
  79. _armboot_real_end:
  80. .word 0x0badc0de
  81. /*
  82. * We relocate uboot to this address (end of RAM - 128 KiB)
  83. */
  84. .globl _uboot_reloc
  85. _uboot_reloc:
  86. .word TEXT_BASE
  87. #ifdef CONFIG_USE_IRQ
  88. /* IRQ stack memory (calculated at run-time) */
  89. .globl IRQ_STACK_START
  90. IRQ_STACK_START:
  91. .word 0x0badc0de
  92. /* IRQ stack memory (calculated at run-time) */
  93. .globl FIQ_STACK_START
  94. FIQ_STACK_START:
  95. .word 0x0badc0de
  96. #endif
  97. /****************************************************************************/
  98. /* */
  99. /* the actual reset code */
  100. /* */
  101. /****************************************************************************/
  102. reset:
  103. mrs r0,cpsr /* set the cpu to SVC32 mode */
  104. bic r0,r0,#0x1f /* (superviser mode, M=10011) */
  105. orr r0,r0,#0x13
  106. msr cpsr,r0
  107. bl cpu_init_crit /* we do sys-critical inits */
  108. relocate: /* relocate U-Boot to RAM */
  109. adr r0, _start /* r0 <- current position of code */
  110. ldr r2, _armboot_start
  111. ldr r3, _armboot_end
  112. sub r2, r3, r2 /* r2 <- size of armboot */
  113. ldr r1, _TEXT_BASE
  114. add r2, r0, r2 /* r2 <- source end address */
  115. copy_loop:
  116. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  117. stmia r1!, {r3-r10} /* copy to target address [r1] */
  118. cmp r0, r2 /* until source end addreee [r2] */
  119. ble copy_loop
  120. /* Set up the stack */
  121. ldr r0, _uboot_reloc /* upper 128 KiB: relocated uboot */
  122. sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
  123. /* FIXME: bdinfo should be here */
  124. sub sp, r0, #12 /* leave 3 words for abort-stack */
  125. ldr pc, _start_armboot
  126. _start_armboot: .word start_armboot
  127. /****************************************************************************/
  128. /* */
  129. /* CPU_init_critical registers */
  130. /* */
  131. /* - setup important registers */
  132. /* - setup memory timing */
  133. /* */
  134. /****************************************************************************/
  135. /* Interrupt-Controller base address */
  136. IC_BASE: .word 0x40d00000
  137. #define ICMR 0x04
  138. /* Reset-Controller */
  139. RST_BASE: .word 0x40f00030
  140. #define RCSR 0x00
  141. /* Clock Manager Registers */
  142. CC_BASE: .word 0x41300000
  143. #define CCCR 0x00
  144. cpuspeed: .word CFG_CPUSPEED
  145. /* RS: ??? */
  146. .macro CPWAIT
  147. mrc p15,0,r0,c2,c0,0
  148. mov r0,r0
  149. sub pc,pc,#4
  150. .endm
  151. cpu_init_crit:
  152. /* mask all IRQs */
  153. ldr r0, IC_BASE
  154. mov r1, #0x00
  155. str r1, [r0, #ICMR]
  156. /* set clock speed */
  157. ldr r0, CC_BASE
  158. ldr r1, cpuspeed
  159. str r1, [r0, #CCCR]
  160. /*
  161. * before relocating, we have to setup RAM timing
  162. * because memory timing is board-dependend, you will
  163. * find a memsetup.S in your board directory.
  164. */
  165. mov ip, lr
  166. bl memsetup
  167. mov lr, ip
  168. /* Memory interfaces are working. Disable MMU and enable I-cache. */
  169. ldr r0, =0x2001 /* enable access to all coproc. */
  170. mcr p15, 0, r0, c15, c1, 0
  171. CPWAIT
  172. mcr p15, 0, r0, c7, c10, 4 /* drain the write & fill buffers */
  173. CPWAIT
  174. mcr p15, 0, r0, c7, c7, 0 /* flush Icache, Dcache and BTB */
  175. CPWAIT
  176. mcr p15, 0, r0, c8, c7, 0 /* flush instuction and data TLBs */
  177. CPWAIT
  178. /* Enable the Icache */
  179. /*
  180. mrc p15, 0, r0, c1, c0, 0
  181. orr r0, r0, #0x1800
  182. mcr p15, 0, r0, c1, c0, 0
  183. CPWAIT
  184. */
  185. mov pc, lr
  186. /****************************************************************************/
  187. /* */
  188. /* Interrupt handling */
  189. /* */
  190. /****************************************************************************/
  191. /* IRQ stack frame */
  192. #define S_FRAME_SIZE 72
  193. #define S_OLD_R0 68
  194. #define S_PSR 64
  195. #define S_PC 60
  196. #define S_LR 56
  197. #define S_SP 52
  198. #define S_IP 48
  199. #define S_FP 44
  200. #define S_R10 40
  201. #define S_R9 36
  202. #define S_R8 32
  203. #define S_R7 28
  204. #define S_R6 24
  205. #define S_R5 20
  206. #define S_R4 16
  207. #define S_R3 12
  208. #define S_R2 8
  209. #define S_R1 4
  210. #define S_R0 0
  211. #define MODE_SVC 0x13
  212. /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
  213. .macro bad_save_user_regs
  214. sub sp, sp, #S_FRAME_SIZE
  215. stmia sp, {r0 - r12} /* Calling r0-r12 */
  216. add r8, sp, #S_PC
  217. ldr r2, _armboot_end
  218. add r2, r2, #CONFIG_STACKSIZE
  219. sub r2, r2, #8
  220. ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
  221. add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
  222. add r5, sp, #S_SP
  223. mov r1, lr
  224. stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
  225. mov r0, sp
  226. .endm
  227. /* use irq_save_user_regs / irq_restore_user_regs for */
  228. /* IRQ/FIQ handling */
  229. .macro irq_save_user_regs
  230. sub sp, sp, #S_FRAME_SIZE
  231. stmia sp, {r0 - r12} /* Calling r0-r12 */
  232. add r8, sp, #S_PC
  233. stmdb r8, {sp, lr}^ /* Calling SP, LR */
  234. str lr, [r8, #0] /* Save calling PC */
  235. mrs r6, spsr
  236. str r6, [r8, #4] /* Save CPSR */
  237. str r0, [r8, #8] /* Save OLD_R0 */
  238. mov r0, sp
  239. .endm
  240. .macro irq_restore_user_regs
  241. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  242. mov r0, r0
  243. ldr lr, [sp, #S_PC] @ Get PC
  244. add sp, sp, #S_FRAME_SIZE
  245. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  246. .endm
  247. .macro get_bad_stack
  248. ldr r13, _armboot_end @ setup our mode stack
  249. add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack
  250. sub r13, r13, #8
  251. str lr, [r13] @ save caller lr / spsr
  252. mrs lr, spsr
  253. str lr, [r13, #4]
  254. mov r13, #MODE_SVC @ prepare SVC-Mode
  255. msr spsr_c, r13
  256. mov lr, pc
  257. movs pc, lr
  258. .endm
  259. .macro get_irq_stack @ setup IRQ stack
  260. ldr sp, IRQ_STACK_START
  261. .endm
  262. .macro get_fiq_stack @ setup FIQ stack
  263. ldr sp, FIQ_STACK_START
  264. .endm
  265. /****************************************************************************/
  266. /* */
  267. /* exception handlers */
  268. /* */
  269. /****************************************************************************/
  270. .align 5
  271. undefined_instruction:
  272. get_bad_stack
  273. bad_save_user_regs
  274. bl do_undefined_instruction
  275. .align 5
  276. software_interrupt:
  277. get_bad_stack
  278. bad_save_user_regs
  279. bl do_software_interrupt
  280. .align 5
  281. prefetch_abort:
  282. get_bad_stack
  283. bad_save_user_regs
  284. bl do_prefetch_abort
  285. .align 5
  286. data_abort:
  287. get_bad_stack
  288. bad_save_user_regs
  289. bl do_data_abort
  290. .align 5
  291. not_used:
  292. get_bad_stack
  293. bad_save_user_regs
  294. bl do_not_used
  295. #ifdef CONFIG_USE_IRQ
  296. .align 5
  297. irq:
  298. get_irq_stack
  299. irq_save_user_regs
  300. bl do_irq
  301. irq_restore_user_regs
  302. .align 5
  303. fiq:
  304. get_fiq_stack
  305. irq_save_user_regs /* someone ought to write a more */
  306. bl do_fiq /* effiction fiq_save_user_regs */
  307. irq_restore_user_regs
  308. #else
  309. .align 5
  310. irq:
  311. get_bad_stack
  312. bad_save_user_regs
  313. bl do_irq
  314. .align 5
  315. fiq:
  316. get_bad_stack
  317. bad_save_user_regs
  318. bl do_fiq
  319. #endif
  320. /*
  321. * FIXME How do we reset??? Watchdog timeout??
  322. */
  323. .align 5
  324. .globl reset_cpu
  325. reset_cpu:
  326. /*
  327. ldr r0, RST_BASE
  328. mov r1, #0x0 @ set bit 3-0 ...
  329. str r1, [r0, #RCSR] @ ... to clear in RCSR
  330. mov r1, #0x1
  331. str r1, [r0, #RCSR] @ and perform reset
  332. */
  333. b reset_cpu @ silly, but repeat endlessly