start.S 11 KB

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