start.S 9.8 KB

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