start.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * armboot - Startup Code for OMP2420/ARM1136 CPU-core
  3. *
  4. * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
  5. *
  6. * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
  7. * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
  8. * Copyright (c) 2002 Gary Jennejohn <gj@denx.de>
  9. * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
  10. * Copyright (c) 2003 Kshitij <kshitij@ti.com>
  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. #if !defined(CONFIG_INTEGRATOR) && ! defined(CONFIG_ARCH_CINTEGRATOR)
  33. #include <asm/arch/omap2420.h>
  34. #endif
  35. .globl _start
  36. _start: b reset
  37. #ifdef CONFIG_ONENAND_IPL
  38. ldr pc, _hang
  39. ldr pc, _hang
  40. ldr pc, _hang
  41. ldr pc, _hang
  42. ldr pc, _hang
  43. ldr pc, _hang
  44. ldr pc, _hang
  45. _hang:
  46. .word do_hang
  47. .word 0x12345678
  48. .word 0x12345678
  49. .word 0x12345678
  50. .word 0x12345678
  51. .word 0x12345678
  52. .word 0x12345678
  53. .word 0x12345678 /* now 16*4=64 */
  54. #else
  55. ldr pc, _undefined_instruction
  56. ldr pc, _software_interrupt
  57. ldr pc, _prefetch_abort
  58. ldr pc, _data_abort
  59. ldr pc, _not_used
  60. ldr pc, _irq
  61. ldr pc, _fiq
  62. _undefined_instruction: .word undefined_instruction
  63. _software_interrupt: .word software_interrupt
  64. _prefetch_abort: .word prefetch_abort
  65. _data_abort: .word data_abort
  66. _not_used: .word not_used
  67. _irq: .word irq
  68. _fiq: .word fiq
  69. _pad: .word 0x12345678 /* now 16*4=64 */
  70. #endif /* CONFIG_ONENAND_IPL */
  71. .global _end_vect
  72. _end_vect:
  73. .balignl 16,0xdeadbeef
  74. /*
  75. *************************************************************************
  76. *
  77. * Startup Code (reset vector)
  78. *
  79. * do important init only if we don't start from memory!
  80. * setup Memory and board specific bits prior to relocation.
  81. * relocate armboot to ram
  82. * setup stack
  83. *
  84. *************************************************************************
  85. */
  86. _TEXT_BASE:
  87. .word TEXT_BASE
  88. .globl _armboot_start
  89. _armboot_start:
  90. .word _start
  91. /*
  92. * These are defined in the board-specific linker script.
  93. */
  94. .globl _bss_start
  95. _bss_start:
  96. .word __bss_start
  97. .globl _bss_end
  98. _bss_end:
  99. .word _end
  100. #ifdef CONFIG_USE_IRQ
  101. /* IRQ stack memory (calculated at run-time) */
  102. .globl IRQ_STACK_START
  103. IRQ_STACK_START:
  104. .word 0x0badc0de
  105. /* IRQ stack memory (calculated at run-time) */
  106. .globl FIQ_STACK_START
  107. FIQ_STACK_START:
  108. .word 0x0badc0de
  109. #endif
  110. /*
  111. * the actual reset code
  112. */
  113. reset:
  114. /*
  115. * set the cpu to SVC32 mode
  116. */
  117. mrs r0,cpsr
  118. bic r0,r0,#0x1f
  119. orr r0,r0,#0xd3
  120. msr cpsr,r0
  121. #ifdef CONFIG_OMAP2420H4
  122. /* Copy vectors to mask ROM indirect addr */
  123. adr r0, _start /* r0 <- current position of code */
  124. add r0, r0, #4 /* skip reset vector */
  125. mov r2, #64 /* r2 <- size to copy */
  126. add r2, r0, r2 /* r2 <- source end address */
  127. mov r1, #SRAM_OFFSET0 /* build vect addr */
  128. mov r3, #SRAM_OFFSET1
  129. add r1, r1, r3
  130. mov r3, #SRAM_OFFSET2
  131. add r1, r1, r3
  132. next:
  133. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  134. stmia r1!, {r3-r10} /* copy to target address [r1] */
  135. cmp r0, r2 /* until source end address [r2] */
  136. bne next /* loop until equal */
  137. bl cpy_clk_code /* put dpll adjust code behind vectors */
  138. #endif
  139. /* the mask ROM code should have PLL and others stable */
  140. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  141. bl cpu_init_crit
  142. #endif
  143. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  144. relocate: /* relocate U-Boot to RAM */
  145. adr r0, _start /* r0 <- current position of code */
  146. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  147. cmp r0, r1 /* don't reloc during debug */
  148. #ifndef CONFIG_ONENAND_IPL
  149. beq stack_setup
  150. #endif /* CONFIG_ONENAND_IPL */
  151. ldr r2, _armboot_start
  152. ldr r3, _bss_start
  153. sub r2, r3, r2 /* r2 <- size of armboot */
  154. add r2, r0, r2 /* r2 <- source end address */
  155. copy_loop:
  156. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  157. stmia r1!, {r3-r10} /* copy to target address [r1] */
  158. cmp r0, r2 /* until source end addreee [r2] */
  159. ble copy_loop
  160. #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
  161. /* Set up the stack */
  162. stack_setup:
  163. ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
  164. #ifdef CONFIG_ONENAND_IPL
  165. sub sp, r0, #128 /* leave 32 words for abort-stack */
  166. #else
  167. sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
  168. sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
  169. #ifdef CONFIG_USE_IRQ
  170. sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
  171. #endif
  172. sub sp, r0, #12 /* leave 3 words for abort-stack */
  173. #endif /* CONFIG_ONENAND_IPL */
  174. clear_bss:
  175. ldr r0, _bss_start /* find start of bss segment */
  176. ldr r1, _bss_end /* stop here */
  177. mov r2, #0x00000000 /* clear */
  178. #ifndef CONFIG_ONENAND_IPL
  179. clbss_l:str r2, [r0] /* clear loop... */
  180. add r0, r0, #4
  181. cmp r0, r1
  182. bne clbss_l
  183. #endif
  184. ldr pc, _start_armboot
  185. #ifdef CONFIG_ONENAND_IPL
  186. _start_armboot: .word start_oneboot
  187. #else
  188. _start_armboot: .word start_armboot
  189. #endif
  190. /*
  191. *************************************************************************
  192. *
  193. * CPU_init_critical registers
  194. *
  195. * setup important registers
  196. * setup memory timing
  197. *
  198. *************************************************************************
  199. */
  200. cpu_init_crit:
  201. /*
  202. * flush v4 I/D caches
  203. */
  204. mov r0, #0
  205. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  206. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  207. /*
  208. * disable MMU stuff and caches
  209. */
  210. mrc p15, 0, r0, c1, c0, 0
  211. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  212. bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
  213. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  214. orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
  215. mcr p15, 0, r0, c1, c0, 0
  216. /*
  217. * Jump to board specific initialization... The Mask ROM will have already initialized
  218. * basic memory. Go here to bump up clock rate and handle wake up conditions.
  219. */
  220. mov ip, lr /* persevere link reg across call */
  221. bl lowlevel_init /* go setup pll,mux,memory */
  222. mov lr, ip /* restore link */
  223. mov pc, lr /* back to my caller */
  224. #ifndef CONFIG_ONENAND_IPL
  225. /*
  226. *************************************************************************
  227. *
  228. * Interrupt handling
  229. *
  230. *************************************************************************
  231. */
  232. @
  233. @ IRQ stack frame.
  234. @
  235. #define S_FRAME_SIZE 72
  236. #define S_OLD_R0 68
  237. #define S_PSR 64
  238. #define S_PC 60
  239. #define S_LR 56
  240. #define S_SP 52
  241. #define S_IP 48
  242. #define S_FP 44
  243. #define S_R10 40
  244. #define S_R9 36
  245. #define S_R8 32
  246. #define S_R7 28
  247. #define S_R6 24
  248. #define S_R5 20
  249. #define S_R4 16
  250. #define S_R3 12
  251. #define S_R2 8
  252. #define S_R1 4
  253. #define S_R0 0
  254. #define MODE_SVC 0x13
  255. #define I_BIT 0x80
  256. /*
  257. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  258. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  259. */
  260. .macro bad_save_user_regs
  261. sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
  262. stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
  263. ldr r2, _armboot_start
  264. sub r2, r2, #(CFG_MALLOC_LEN)
  265. sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
  266. ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
  267. add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
  268. add r5, sp, #S_SP
  269. mov r1, lr
  270. stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
  271. mov r0, sp @ save current stack into r0 (param register)
  272. .endm
  273. .macro irq_save_user_regs
  274. sub sp, sp, #S_FRAME_SIZE
  275. stmia sp, {r0 - r12} @ Calling r0-r12
  276. add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
  277. stmdb r8, {sp, lr}^ @ Calling SP, LR
  278. str lr, [r8, #0] @ Save calling PC
  279. mrs r6, spsr
  280. str r6, [r8, #4] @ Save CPSR
  281. str r0, [r8, #8] @ Save OLD_R0
  282. mov r0, sp
  283. .endm
  284. .macro irq_restore_user_regs
  285. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  286. mov r0, r0
  287. ldr lr, [sp, #S_PC] @ Get PC
  288. add sp, sp, #S_FRAME_SIZE
  289. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  290. .endm
  291. .macro get_bad_stack
  292. ldr r13, _armboot_start @ setup our mode stack (enter in banked mode)
  293. sub r13, r13, #(CFG_MALLOC_LEN) @ move past malloc pool
  294. sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack
  295. str lr, [r13] @ save caller lr in position 0 of saved stack
  296. mrs lr, spsr @ get the spsr
  297. str lr, [r13, #4] @ save spsr in position 1 of saved stack
  298. mov r13, #MODE_SVC @ prepare SVC-Mode
  299. @ msr spsr_c, r13
  300. msr spsr, r13 @ switch modes, make sure moves will execute
  301. mov lr, pc @ capture return pc
  302. movs pc, lr @ jump to next instruction & switch modes.
  303. .endm
  304. .macro get_bad_stack_swi
  305. sub r13, r13, #4 @ space on current stack for scratch reg.
  306. str r0, [r13] @ save R0's value.
  307. ldr r0, _armboot_start @ get data regions start
  308. sub r0, r0, #(CFG_MALLOC_LEN) @ move past malloc pool
  309. sub r0, r0, #(CFG_GBL_DATA_SIZE+8) @ move past gbl and a couple spots for abort stack
  310. str lr, [r0] @ save caller lr in position 0 of saved stack
  311. mrs r0, spsr @ get the spsr
  312. str lr, [r0, #4] @ save spsr in position 1 of saved stack
  313. ldr r0, [r13] @ restore r0
  314. add r13, r13, #4 @ pop stack entry
  315. .endm
  316. .macro get_irq_stack @ setup IRQ stack
  317. ldr sp, IRQ_STACK_START
  318. .endm
  319. .macro get_fiq_stack @ setup FIQ stack
  320. ldr sp, FIQ_STACK_START
  321. .endm
  322. #endif /* CONFIG_ONENAND_IPL */
  323. /*
  324. * exception handlers
  325. */
  326. #ifdef CONFIG_ONENAND_IPL
  327. .align 5
  328. do_hang:
  329. ldr sp, _TEXT_BASE /* use 32 words about stack */
  330. bl hang /* hang and never return */
  331. #else /* !CONFIG_ONENAND IPL */
  332. .align 5
  333. undefined_instruction:
  334. get_bad_stack
  335. bad_save_user_regs
  336. bl do_undefined_instruction
  337. .align 5
  338. software_interrupt:
  339. get_bad_stack_swi
  340. bad_save_user_regs
  341. bl do_software_interrupt
  342. .align 5
  343. prefetch_abort:
  344. get_bad_stack
  345. bad_save_user_regs
  346. bl do_prefetch_abort
  347. .align 5
  348. data_abort:
  349. get_bad_stack
  350. bad_save_user_regs
  351. bl do_data_abort
  352. .align 5
  353. not_used:
  354. get_bad_stack
  355. bad_save_user_regs
  356. bl do_not_used
  357. #ifdef CONFIG_USE_IRQ
  358. .align 5
  359. irq:
  360. get_irq_stack
  361. irq_save_user_regs
  362. bl do_irq
  363. irq_restore_user_regs
  364. .align 5
  365. fiq:
  366. get_fiq_stack
  367. /* someone ought to write a more effiction fiq_save_user_regs */
  368. irq_save_user_regs
  369. bl do_fiq
  370. irq_restore_user_regs
  371. #else
  372. .align 5
  373. irq:
  374. get_bad_stack
  375. bad_save_user_regs
  376. bl do_irq
  377. .align 5
  378. fiq:
  379. get_bad_stack
  380. bad_save_user_regs
  381. bl do_fiq
  382. #endif
  383. .align 5
  384. .global arm1136_cache_flush
  385. arm1136_cache_flush:
  386. mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
  387. mov pc, lr @ back to caller
  388. #if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_CINTEGRATOR)
  389. /* Use the IntegratorCP function from board/integratorcp/platform.S */
  390. #else
  391. .align 5
  392. .globl reset_cpu
  393. reset_cpu:
  394. ldr r1, rstctl /* get addr for global reset reg */
  395. mov r3, #0x2 /* full reset pll+mpu */
  396. str r3, [r1] /* force reset */
  397. mov r0, r0
  398. _loop_forever:
  399. b _loop_forever
  400. rstctl:
  401. .word PM_RSTCTRL_WKUP
  402. #endif
  403. #endif /* CONFIG_ONENAND_IPL */