start.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /* vi: set ts=8 sw=8 noet: */
  2. /*
  3. * u-boot - Startup Code for XScale IXP
  4. *
  5. * Copyright (C) 2003 Kyle Harris <kharris@nexus-tech.net>
  6. *
  7. * Based on startup code example contained in the
  8. * Intel IXP4xx Programmer's Guide and past u-boot Start.S
  9. * samples.
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <config.h>
  30. #include <version.h>
  31. #include <asm/arch/ixp425.h>
  32. #define MMU_Control_M 0x001 /* Enable MMU */
  33. #define MMU_Control_A 0x002 /* Enable address alignment faults */
  34. #define MMU_Control_C 0x004 /* Enable cache */
  35. #define MMU_Control_W 0x008 /* Enable write-buffer */
  36. #define MMU_Control_P 0x010 /* Compatability: 32 bit code */
  37. #define MMU_Control_D 0x020 /* Compatability: 32 bit data */
  38. #define MMU_Control_L 0x040 /* Compatability: */
  39. #define MMU_Control_B 0x080 /* Enable Big-Endian */
  40. #define MMU_Control_S 0x100 /* Enable system protection */
  41. #define MMU_Control_R 0x200 /* Enable ROM protection */
  42. #define MMU_Control_I 0x1000 /* Enable Instruction cache */
  43. #define MMU_Control_X 0x2000 /* Set interrupt vectors at 0xFFFF0000 */
  44. #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L)
  45. /*
  46. * Macro definitions
  47. */
  48. /* Delay a bit */
  49. .macro DELAY_FOR cycles, reg0
  50. ldr \reg0, =\cycles
  51. subs \reg0, \reg0, #1
  52. subne pc, pc, #0xc
  53. .endm
  54. /* wait for coprocessor write complete */
  55. .macro CPWAIT reg
  56. mrc p15,0,\reg,c2,c0,0
  57. mov \reg,\reg
  58. sub pc,pc,#4
  59. .endm
  60. .globl _start
  61. _start: b reset
  62. ldr pc, _undefined_instruction
  63. ldr pc, _software_interrupt
  64. ldr pc, _prefetch_abort
  65. ldr pc, _data_abort
  66. ldr pc, _not_used
  67. ldr pc, _irq
  68. ldr pc, _fiq
  69. _undefined_instruction: .word undefined_instruction
  70. _software_interrupt: .word software_interrupt
  71. _prefetch_abort: .word prefetch_abort
  72. _data_abort: .word data_abort
  73. _not_used: .word not_used
  74. _irq: .word irq
  75. _fiq: .word fiq
  76. .balignl 16,0xdeadbeef
  77. /*
  78. * Startup Code (reset vector)
  79. *
  80. * do important init only if we don't start from memory!
  81. * - relocate armboot to ram
  82. * - setup stack
  83. * - jump to second stage
  84. */
  85. _TEXT_BASE:
  86. .word TEXT_BASE
  87. .globl _armboot_start
  88. _armboot_start:
  89. .word _start
  90. /*
  91. * These are defined in the board-specific linker script.
  92. */
  93. .globl _bss_start
  94. _bss_start:
  95. .word __bss_start
  96. .globl _bss_end
  97. _bss_end:
  98. .word _end
  99. #ifdef CONFIG_USE_IRQ
  100. /* IRQ stack memory (calculated at run-time) */
  101. .globl IRQ_STACK_START
  102. IRQ_STACK_START:
  103. .word 0x0badc0de
  104. /* IRQ stack memory (calculated at run-time) */
  105. .globl FIQ_STACK_START
  106. FIQ_STACK_START:
  107. .word 0x0badc0de
  108. #endif
  109. /****************************************************************************/
  110. /* */
  111. /* the actual reset code */
  112. /* */
  113. /****************************************************************************/
  114. reset:
  115. /* disable mmu, set big-endian */
  116. mov r0, #0xf8
  117. mcr p15, 0, r0, c1, c0, 0
  118. CPWAIT r0
  119. /* invalidate I & D caches & BTB */
  120. mcr p15, 0, r0, c7, c7, 0
  121. CPWAIT r0
  122. /* invalidate I & Data TLB */
  123. mcr p15, 0, r0, c8, c7, 0
  124. CPWAIT r0
  125. /* drain write and fill buffers */
  126. mcr p15, 0, r0, c7, c10, 4
  127. CPWAIT r0
  128. /* disable write buffer coalescing */
  129. mrc p15, 0, r0, c1, c0, 1
  130. orr r0, r0, #1
  131. mcr p15, 0, r0, c1, c0, 1
  132. CPWAIT r0
  133. /* set EXP CS0 to the optimum timing */
  134. ldr r1, =CFG_EXP_CS0
  135. ldr r2, =IXP425_EXP_CS0
  136. str r1, [r2]
  137. /* make sure flash is visible at 0 */
  138. ldr r2, =IXP425_EXP_CFG0
  139. ldr r1, [r2]
  140. orr r1, r1, #0x80000000
  141. str r1, [r2]
  142. mov r1, #CFG_SDR_CONFIG
  143. ldr r2, =IXP425_SDR_CONFIG
  144. str r1, [r2]
  145. /* disable refresh cycles */
  146. mov r1, #0
  147. ldr r3, =IXP425_SDR_REFRESH
  148. str r1, [r3]
  149. /* send nop command */
  150. mov r1, #3
  151. ldr r4, =IXP425_SDR_IR
  152. str r1, [r4]
  153. DELAY_FOR 0x4000, r0
  154. /* set SDRAM internal refresh val */
  155. ldr r1, =CFG_SDRAM_REFRESH_CNT
  156. str r1, [r3]
  157. DELAY_FOR 0x4000, r0
  158. /* send precharge-all command to close all open banks */
  159. mov r1, #2
  160. str r1, [r4]
  161. DELAY_FOR 0x4000, r0
  162. /* provide 8 auto-refresh cycles */
  163. mov r1, #4
  164. mov r5, #8
  165. 111: str r1, [r4]
  166. DELAY_FOR 0x100, r0
  167. subs r5, r5, #1
  168. bne 111b
  169. /* set mode register in sdram */
  170. mov r1, #1
  171. str r1, [r4]
  172. DELAY_FOR 0x4000, r0
  173. /* send normal operation command */
  174. mov r1, #6
  175. str r1, [r4]
  176. DELAY_FOR 0x4000, r0
  177. /* copy */
  178. mov r0, #0
  179. mov r4, r0
  180. add r2, r0, #0x40000
  181. mov r1, #0x10000000
  182. mov r5, r1
  183. 30:
  184. ldr r3, [r0], #4
  185. str r3, [r1], #4
  186. cmp r0, r2
  187. bne 30b
  188. /* invalidate I & D caches & BTB */
  189. mcr p15, 0, r0, c7, c7, 0
  190. CPWAIT r0
  191. /* invalidate I & Data TLB */
  192. mcr p15, 0, r0, c8, c7, 0
  193. CPWAIT r0
  194. /* drain write and fill buffers */
  195. mcr p15, 0, r0, c7, c10, 4
  196. CPWAIT r0
  197. /* move flash to 0x50000000 */
  198. ldr r2, =IXP425_EXP_CFG0
  199. ldr r1, [r2]
  200. bic r1, r1, #0x80000000
  201. str r1, [r2]
  202. nop
  203. nop
  204. nop
  205. nop
  206. nop
  207. nop
  208. /* invalidate I & Data TLB */
  209. mcr p15, 0, r0, c8, c7, 0
  210. CPWAIT r0
  211. /* enable I cache */
  212. mrc p15, 0, r0, c1, c0, 0
  213. orr r0, r0, #MMU_Control_I
  214. mcr p15, 0, r0, c1, c0, 0
  215. CPWAIT r0
  216. mrs r0,cpsr /* set the cpu to SVC32 mode */
  217. bic r0,r0,#0x1f /* (superviser mode, M=10011) */
  218. orr r0,r0,#0x13
  219. msr cpsr,r0
  220. relocate: /* relocate U-Boot to RAM */
  221. adr r0, _start /* r0 <- current position of code */
  222. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  223. cmp r0, r1 /* don't reloc during debug */
  224. beq stack_setup
  225. ldr r2, _armboot_start
  226. ldr r3, _bss_start
  227. sub r2, r3, r2 /* r2 <- size of armboot */
  228. add r2, r0, r2 /* r2 <- source end address */
  229. copy_loop:
  230. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  231. stmia r1!, {r3-r10} /* copy to target address [r1] */
  232. cmp r0, r2 /* until source end addreee [r2] */
  233. ble copy_loop
  234. /* Set up the stack */
  235. stack_setup:
  236. ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
  237. sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
  238. sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
  239. #ifdef CONFIG_USE_IRQ
  240. sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
  241. #endif
  242. sub sp, r0, #12 /* leave 3 words for abort-stack */
  243. clear_bss:
  244. ldr r0, _bss_start /* find start of bss segment */
  245. ldr r1, _bss_end /* stop here */
  246. mov r2, #0x00000000 /* clear */
  247. clbss_l:str r2, [r0] /* clear loop... */
  248. add r0, r0, #4
  249. cmp r0, r1
  250. bne clbss_l
  251. ldr pc, _start_armboot
  252. _start_armboot: .word start_armboot
  253. /****************************************************************************/
  254. /* */
  255. /* Interrupt handling */
  256. /* */
  257. /****************************************************************************/
  258. /* IRQ stack frame */
  259. #define S_FRAME_SIZE 72
  260. #define S_OLD_R0 68
  261. #define S_PSR 64
  262. #define S_PC 60
  263. #define S_LR 56
  264. #define S_SP 52
  265. #define S_IP 48
  266. #define S_FP 44
  267. #define S_R10 40
  268. #define S_R9 36
  269. #define S_R8 32
  270. #define S_R7 28
  271. #define S_R6 24
  272. #define S_R5 20
  273. #define S_R4 16
  274. #define S_R3 12
  275. #define S_R2 8
  276. #define S_R1 4
  277. #define S_R0 0
  278. #define MODE_SVC 0x13
  279. /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
  280. .macro bad_save_user_regs
  281. sub sp, sp, #S_FRAME_SIZE
  282. stmia sp, {r0 - r12} /* Calling r0-r12 */
  283. add r8, sp, #S_PC
  284. ldr r2, _armboot_start
  285. sub r2, r2, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
  286. sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
  287. ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
  288. add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
  289. add r5, sp, #S_SP
  290. mov r1, lr
  291. stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
  292. mov r0, sp
  293. .endm
  294. /* use irq_save_user_regs / irq_restore_user_regs for */
  295. /* IRQ/FIQ handling */
  296. .macro irq_save_user_regs
  297. sub sp, sp, #S_FRAME_SIZE
  298. stmia sp, {r0 - r12} /* Calling r0-r12 */
  299. add r8, sp, #S_PC
  300. stmdb r8, {sp, lr}^ /* Calling SP, LR */
  301. str lr, [r8, #0] /* Save calling PC */
  302. mrs r6, spsr
  303. str r6, [r8, #4] /* Save CPSR */
  304. str r0, [r8, #8] /* Save OLD_R0 */
  305. mov r0, sp
  306. .endm
  307. .macro irq_restore_user_regs
  308. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  309. mov r0, r0
  310. ldr lr, [sp, #S_PC] @ Get PC
  311. add sp, sp, #S_FRAME_SIZE
  312. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  313. .endm
  314. .macro get_bad_stack
  315. ldr r13, _armboot_start @ setup our mode stack
  316. sub r13, r13, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
  317. sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
  318. str lr, [r13] @ save caller lr / spsr
  319. mrs lr, spsr
  320. str lr, [r13, #4]
  321. mov r13, #MODE_SVC @ prepare SVC-Mode
  322. msr spsr_c, r13
  323. mov lr, pc
  324. movs pc, lr
  325. .endm
  326. .macro get_irq_stack @ setup IRQ stack
  327. ldr sp, IRQ_STACK_START
  328. .endm
  329. .macro get_fiq_stack @ setup FIQ stack
  330. ldr sp, FIQ_STACK_START
  331. .endm
  332. /****************************************************************************/
  333. /* */
  334. /* exception handlers */
  335. /* */
  336. /****************************************************************************/
  337. .align 5
  338. undefined_instruction:
  339. get_bad_stack
  340. bad_save_user_regs
  341. bl do_undefined_instruction
  342. .align 5
  343. software_interrupt:
  344. get_bad_stack
  345. bad_save_user_regs
  346. bl do_software_interrupt
  347. .align 5
  348. prefetch_abort:
  349. get_bad_stack
  350. bad_save_user_regs
  351. bl do_prefetch_abort
  352. .align 5
  353. data_abort:
  354. get_bad_stack
  355. bad_save_user_regs
  356. bl do_data_abort
  357. .align 5
  358. not_used:
  359. get_bad_stack
  360. bad_save_user_regs
  361. bl do_not_used
  362. #ifdef CONFIG_USE_IRQ
  363. .align 5
  364. irq:
  365. get_irq_stack
  366. irq_save_user_regs
  367. bl do_irq
  368. irq_restore_user_regs
  369. .align 5
  370. fiq:
  371. get_fiq_stack
  372. irq_save_user_regs /* someone ought to write a more */
  373. bl do_fiq /* effiction fiq_save_user_regs */
  374. irq_restore_user_regs
  375. #else
  376. .align 5
  377. irq:
  378. get_bad_stack
  379. bad_save_user_regs
  380. bl do_irq
  381. .align 5
  382. fiq:
  383. get_bad_stack
  384. bad_save_user_regs
  385. bl do_fiq
  386. #endif
  387. /****************************************************************************/
  388. /* */
  389. /* Reset function: Use Watchdog to reset */
  390. /* */
  391. /****************************************************************************/
  392. .align 5
  393. .globl reset_cpu
  394. reset_cpu:
  395. ldr r1, =0x482e
  396. ldr r2, =IXP425_OSWK
  397. str r1, [r2]
  398. ldr r1, =0x0fff
  399. ldr r2, =IXP425_OSWT
  400. str r1, [r2]
  401. ldr r1, =0x5
  402. ldr r2, =IXP425_OSWE
  403. str r1, [r2]
  404. b reset_endless
  405. reset_endless:
  406. b reset_endless