start.S 12 KB

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