start.S 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. /* Operating System Timer */
  142. OSTIMER_BASE: .word 0x40a00000
  143. #define OSMR3 0x0C
  144. #define OSCR 0x10
  145. #define OWER 0x18
  146. #define OIER 0x1C
  147. /* Clock Manager Registers */
  148. CC_BASE: .word 0x41300000
  149. #define CCCR 0x00
  150. cpuspeed: .word CFG_CPUSPEED
  151. /* RS: ??? */
  152. .macro CPWAIT
  153. mrc p15,0,r0,c2,c0,0
  154. mov r0,r0
  155. sub pc,pc,#4
  156. .endm
  157. cpu_init_crit:
  158. /* mask all IRQs */
  159. ldr r0, IC_BASE
  160. mov r1, #0x00
  161. str r1, [r0, #ICMR]
  162. /* set clock speed */
  163. ldr r0, CC_BASE
  164. ldr r1, cpuspeed
  165. str r1, [r0, #CCCR]
  166. /*
  167. * before relocating, we have to setup RAM timing
  168. * because memory timing is board-dependend, you will
  169. * find a memsetup.S in your board directory.
  170. */
  171. mov ip, lr
  172. bl memsetup
  173. mov lr, ip
  174. /* Memory interfaces are working. Disable MMU and enable I-cache. */
  175. ldr r0, =0x2001 /* enable access to all coproc. */
  176. mcr p15, 0, r0, c15, c1, 0
  177. CPWAIT
  178. mcr p15, 0, r0, c7, c10, 4 /* drain the write & fill buffers */
  179. CPWAIT
  180. mcr p15, 0, r0, c7, c7, 0 /* flush Icache, Dcache and BTB */
  181. CPWAIT
  182. mcr p15, 0, r0, c8, c7, 0 /* flush instuction and data TLBs */
  183. CPWAIT
  184. /* Enable the Icache */
  185. /*
  186. mrc p15, 0, r0, c1, c0, 0
  187. orr r0, r0, #0x1800
  188. mcr p15, 0, r0, c1, c0, 0
  189. CPWAIT
  190. */
  191. mov pc, lr
  192. /****************************************************************************/
  193. /* */
  194. /* Interrupt handling */
  195. /* */
  196. /****************************************************************************/
  197. /* IRQ stack frame */
  198. #define S_FRAME_SIZE 72
  199. #define S_OLD_R0 68
  200. #define S_PSR 64
  201. #define S_PC 60
  202. #define S_LR 56
  203. #define S_SP 52
  204. #define S_IP 48
  205. #define S_FP 44
  206. #define S_R10 40
  207. #define S_R9 36
  208. #define S_R8 32
  209. #define S_R7 28
  210. #define S_R6 24
  211. #define S_R5 20
  212. #define S_R4 16
  213. #define S_R3 12
  214. #define S_R2 8
  215. #define S_R1 4
  216. #define S_R0 0
  217. #define MODE_SVC 0x13
  218. /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
  219. .macro bad_save_user_regs
  220. sub sp, sp, #S_FRAME_SIZE
  221. stmia sp, {r0 - r12} /* Calling r0-r12 */
  222. add r8, sp, #S_PC
  223. ldr r2, _armboot_end
  224. add r2, r2, #CONFIG_STACKSIZE
  225. sub r2, r2, #8
  226. ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
  227. add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
  228. add r5, sp, #S_SP
  229. mov r1, lr
  230. stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
  231. mov r0, sp
  232. .endm
  233. /* use irq_save_user_regs / irq_restore_user_regs for */
  234. /* IRQ/FIQ handling */
  235. .macro irq_save_user_regs
  236. sub sp, sp, #S_FRAME_SIZE
  237. stmia sp, {r0 - r12} /* Calling r0-r12 */
  238. add r8, sp, #S_PC
  239. stmdb r8, {sp, lr}^ /* Calling SP, LR */
  240. str lr, [r8, #0] /* Save calling PC */
  241. mrs r6, spsr
  242. str r6, [r8, #4] /* Save CPSR */
  243. str r0, [r8, #8] /* Save OLD_R0 */
  244. mov r0, sp
  245. .endm
  246. .macro irq_restore_user_regs
  247. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  248. mov r0, r0
  249. ldr lr, [sp, #S_PC] @ Get PC
  250. add sp, sp, #S_FRAME_SIZE
  251. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  252. .endm
  253. .macro get_bad_stack
  254. ldr r13, _armboot_end @ setup our mode stack
  255. add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack
  256. sub r13, r13, #8
  257. str lr, [r13] @ save caller lr / spsr
  258. mrs lr, spsr
  259. str lr, [r13, #4]
  260. mov r13, #MODE_SVC @ prepare SVC-Mode
  261. msr spsr_c, r13
  262. mov lr, pc
  263. movs pc, lr
  264. .endm
  265. .macro get_irq_stack @ setup IRQ stack
  266. ldr sp, IRQ_STACK_START
  267. .endm
  268. .macro get_fiq_stack @ setup FIQ stack
  269. ldr sp, FIQ_STACK_START
  270. .endm
  271. /****************************************************************************/
  272. /* */
  273. /* exception handlers */
  274. /* */
  275. /****************************************************************************/
  276. .align 5
  277. undefined_instruction:
  278. get_bad_stack
  279. bad_save_user_regs
  280. bl do_undefined_instruction
  281. .align 5
  282. software_interrupt:
  283. get_bad_stack
  284. bad_save_user_regs
  285. bl do_software_interrupt
  286. .align 5
  287. prefetch_abort:
  288. get_bad_stack
  289. bad_save_user_regs
  290. bl do_prefetch_abort
  291. .align 5
  292. data_abort:
  293. get_bad_stack
  294. bad_save_user_regs
  295. bl do_data_abort
  296. .align 5
  297. not_used:
  298. get_bad_stack
  299. bad_save_user_regs
  300. bl do_not_used
  301. #ifdef CONFIG_USE_IRQ
  302. .align 5
  303. irq:
  304. get_irq_stack
  305. irq_save_user_regs
  306. bl do_irq
  307. irq_restore_user_regs
  308. .align 5
  309. fiq:
  310. get_fiq_stack
  311. irq_save_user_regs /* someone ought to write a more */
  312. bl do_fiq /* effiction fiq_save_user_regs */
  313. irq_restore_user_regs
  314. #else
  315. .align 5
  316. irq:
  317. get_bad_stack
  318. bad_save_user_regs
  319. bl do_irq
  320. .align 5
  321. fiq:
  322. get_bad_stack
  323. bad_save_user_regs
  324. bl do_fiq
  325. #endif
  326. /************************************************************************/
  327. /* */
  328. /* Reset function: the PXA250 has no reset function, so we have to */
  329. /* perform a watchdog timeout to cause a reset. */
  330. /* */
  331. /************************************************************************/
  332. .align 5
  333. .globl reset_cpu
  334. reset_cpu:
  335. /* We set OWE:WME (watchdog enable) and wait until timeout happens */
  336. ldr r0, OSTIMER_BASE
  337. ldr r1, [r0, #OWER]
  338. orr r1, r1, #0x0001 /* bit0: WME */
  339. str r1, [r0, #OWER]
  340. /* OS timer does only wrap every 1165 seconds, so we have to set */
  341. /* the match register as well. */
  342. ldr r1, [r0, #OSCR] /* read OS timer */
  343. add r1, r1, #0x800 /* let OSMR3 match after */
  344. add r1, r1, #0x800 /* 4096*(1/3.6864MHz)=1ms */
  345. str r1, [r0, #OSMR3]
  346. reset_endless:
  347. b reset_endless