start.S 11 KB

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