start.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. * Note: _armboot_end_data and _armboot_end are defined
  92. * by the (board-dependent) linker script.
  93. * _armboot_end_data is the first usable FLASH address after armboot
  94. */
  95. .globl _armboot_end_data
  96. _armboot_end_data:
  97. .word armboot_end_data
  98. .globl _armboot_end
  99. _armboot_end:
  100. .word armboot_end
  101. /*
  102. * This is defined in the board specific linker script
  103. */
  104. .globl _bss_start
  105. _bss_start:
  106. .word bss_start
  107. .globl _bss_end
  108. _bss_end:
  109. .word bss_end
  110. /*
  111. * _armboot_real_end is the first usable RAM address behind armboot
  112. * and the various stacks
  113. */
  114. .globl _armboot_real_end
  115. _armboot_real_end:
  116. .word 0x0badc0de
  117. /*
  118. * We relocate uboot to this address (end of RAM - 128 KiB)
  119. */
  120. .globl _uboot_reloc
  121. _uboot_reloc:
  122. .word TEXT_BASE
  123. #ifdef CONFIG_USE_IRQ
  124. /* IRQ stack memory (calculated at run-time) */
  125. .globl IRQ_STACK_START
  126. IRQ_STACK_START:
  127. .word 0x0badc0de
  128. /* IRQ stack memory (calculated at run-time) */
  129. .globl FIQ_STACK_START
  130. FIQ_STACK_START:
  131. .word 0x0badc0de
  132. #endif
  133. /****************************************************************************/
  134. /* */
  135. /* the actual reset code */
  136. /* */
  137. /****************************************************************************/
  138. reset:
  139. /* disable mmu, set big-endian */
  140. mov r0, #0xf8
  141. mcr p15, 0, r0, c1, c0, 0
  142. CPWAIT r0
  143. /* invalidate I & D caches & BTB */
  144. mcr p15, 0, r0, c7, c7, 0
  145. CPWAIT r0
  146. /* invalidate I & Data TLB */
  147. mcr p15, 0, r0, c8, c7, 0
  148. CPWAIT r0
  149. /* drain write and fill buffers */
  150. mcr p15, 0, r0, c7, c10, 4
  151. CPWAIT r0
  152. /* disable write buffer coalescing */
  153. mrc p15, 0, r0, c1, c0, 1
  154. orr r0, r0, #1
  155. mcr p15, 0, r0, c1, c0, 1
  156. CPWAIT r0
  157. /* set EXP CS0 to the optimum timing */
  158. ldr r1, =CFG_EXP_CS0
  159. ldr r2, =IXP425_EXP_CS0
  160. str r1, [r2]
  161. /* make sure flash is visible at 0 */
  162. ldr r2, =IXP425_EXP_CFG0
  163. ldr r1, [r2]
  164. orr r1, r1, #0x80000000
  165. str r1, [r2]
  166. mov r1, #CFG_SDR_CONFIG
  167. ldr r2, =IXP425_SDR_CONFIG
  168. str r1, [r2]
  169. /* disable refresh cycles */
  170. mov r1, #0
  171. ldr r3, =IXP425_SDR_REFRESH
  172. str r1, [r3]
  173. /* send nop command */
  174. mov r1, #3
  175. ldr r4, =IXP425_SDR_IR
  176. str r1, [r4]
  177. DELAY_FOR 0x4000, r0
  178. /* set SDRAM internal refresh val */
  179. ldr r1, =CFG_SDRAM_REFRESH_CNT
  180. str r1, [r3]
  181. DELAY_FOR 0x4000, r0
  182. /* send precharge-all command to close all open banks */
  183. mov r1, #2
  184. str r1, [r4]
  185. DELAY_FOR 0x4000, r0
  186. /* provide 8 auto-refresh cycles */
  187. mov r1, #4
  188. mov r5, #8
  189. 111: str r1, [r4]
  190. DELAY_FOR 0x100, r0
  191. subs r5, r5, #1
  192. bne 111b
  193. /* set mode register in sdram */
  194. mov r1, #1
  195. str r1, [r4]
  196. DELAY_FOR 0x4000, r0
  197. /* send normal operation command */
  198. mov r1, #6
  199. str r1, [r4]
  200. DELAY_FOR 0x4000, r0
  201. /* copy */
  202. mov r0, #0
  203. mov r4, r0
  204. add r2, r0, #0x40000
  205. mov r1, #0x10000000
  206. mov r5, r1
  207. 30:
  208. ldr r3, [r0], #4
  209. str r3, [r1], #4
  210. cmp r0, r2
  211. bne 30b
  212. /* invalidate I & D caches & BTB */
  213. mcr p15, 0, r0, c7, c7, 0
  214. CPWAIT r0
  215. /* invalidate I & Data TLB */
  216. mcr p15, 0, r0, c8, c7, 0
  217. CPWAIT r0
  218. /* drain write and fill buffers */
  219. mcr p15, 0, r0, c7, c10, 4
  220. CPWAIT r0
  221. /* move flash to 0x50000000 */
  222. ldr r2, =IXP425_EXP_CFG0
  223. ldr r1, [r2]
  224. bic r1, r1, #0x80000000
  225. str r1, [r2]
  226. nop
  227. nop
  228. nop
  229. nop
  230. nop
  231. nop
  232. /* invalidate I & Data TLB */
  233. mcr p15, 0, r0, c8, c7, 0
  234. CPWAIT r0
  235. /* enable I cache */
  236. mrc p15, 0, r0, c1, c0, 0
  237. orr r0, r0, #MMU_Control_I
  238. mcr p15, 0, r0, c1, c0, 0
  239. CPWAIT r0
  240. mrs r0,cpsr /* set the cpu to SVC32 mode */
  241. bic r0,r0,#0x1f /* (superviser mode, M=10011) */
  242. orr r0,r0,#0x13
  243. msr cpsr,r0
  244. relocate: /* relocate U-Boot to RAM */
  245. adr r0, _start /* r0 <- current position of code */
  246. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  247. cmp r0, r1 /* don't reloc during debug */
  248. beq stack_setup
  249. ldr r2, _armboot_start
  250. ldr r3, _armboot_end
  251. sub r2, r3, r2 /* r2 <- size of armboot */
  252. add r2, r0, r2 /* r2 <- source end address */
  253. copy_loop:
  254. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  255. stmia r1!, {r3-r10} /* copy to target address [r1] */
  256. cmp r0, r2 /* until source end addreee [r2] */
  257. ble copy_loop
  258. /* Set up the stack */
  259. stack_setup:
  260. ldr r0, _uboot_reloc /* upper 128 KiB: relocated uboot */
  261. sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
  262. /* FIXME: bdinfo should be here */
  263. sub sp, r0, #12 /* leave 3 words for abort-stack */
  264. clear_bss:
  265. ldr r0, _bss_start /* find start of bss segment */
  266. add r0, r0, #4 /* start at first byte of bss */
  267. ldr r1, _bss_end /* stop here */
  268. mov r2, #0x00000000 /* clear */
  269. clbss_l:str r2, [r0] /* clear loop... */
  270. add r0, r0, #4
  271. cmp r0, r1
  272. bne clbss_l
  273. ldr pc, _start_armboot
  274. _start_armboot: .word start_armboot
  275. /****************************************************************************/
  276. /* */
  277. /* Interrupt handling */
  278. /* */
  279. /****************************************************************************/
  280. /* IRQ stack frame */
  281. #define S_FRAME_SIZE 72
  282. #define S_OLD_R0 68
  283. #define S_PSR 64
  284. #define S_PC 60
  285. #define S_LR 56
  286. #define S_SP 52
  287. #define S_IP 48
  288. #define S_FP 44
  289. #define S_R10 40
  290. #define S_R9 36
  291. #define S_R8 32
  292. #define S_R7 28
  293. #define S_R6 24
  294. #define S_R5 20
  295. #define S_R4 16
  296. #define S_R3 12
  297. #define S_R2 8
  298. #define S_R1 4
  299. #define S_R0 0
  300. #define MODE_SVC 0x13
  301. /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
  302. .macro bad_save_user_regs
  303. sub sp, sp, #S_FRAME_SIZE
  304. stmia sp, {r0 - r12} /* Calling r0-r12 */
  305. add r8, sp, #S_PC
  306. ldr r2, _armboot_end
  307. add r2, r2, #CONFIG_STACKSIZE
  308. sub r2, r2, #8
  309. ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
  310. add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
  311. add r5, sp, #S_SP
  312. mov r1, lr
  313. stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
  314. mov r0, sp
  315. .endm
  316. /* use irq_save_user_regs / irq_restore_user_regs for */
  317. /* IRQ/FIQ handling */
  318. .macro irq_save_user_regs
  319. sub sp, sp, #S_FRAME_SIZE
  320. stmia sp, {r0 - r12} /* Calling r0-r12 */
  321. add r8, sp, #S_PC
  322. stmdb r8, {sp, lr}^ /* Calling SP, LR */
  323. str lr, [r8, #0] /* Save calling PC */
  324. mrs r6, spsr
  325. str r6, [r8, #4] /* Save CPSR */
  326. str r0, [r8, #8] /* Save OLD_R0 */
  327. mov r0, sp
  328. .endm
  329. .macro irq_restore_user_regs
  330. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  331. mov r0, r0
  332. ldr lr, [sp, #S_PC] @ Get PC
  333. add sp, sp, #S_FRAME_SIZE
  334. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  335. .endm
  336. .macro get_bad_stack
  337. ldr r13, _armboot_end @ setup our mode stack
  338. add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack
  339. sub r13, r13, #8
  340. str lr, [r13] @ save caller lr / spsr
  341. mrs lr, spsr
  342. str lr, [r13, #4]
  343. mov r13, #MODE_SVC @ prepare SVC-Mode
  344. msr spsr_c, r13
  345. mov lr, pc
  346. movs pc, lr
  347. .endm
  348. .macro get_irq_stack @ setup IRQ stack
  349. ldr sp, IRQ_STACK_START
  350. .endm
  351. .macro get_fiq_stack @ setup FIQ stack
  352. ldr sp, FIQ_STACK_START
  353. .endm
  354. /****************************************************************************/
  355. /* */
  356. /* exception handlers */
  357. /* */
  358. /****************************************************************************/
  359. .align 5
  360. undefined_instruction:
  361. get_bad_stack
  362. bad_save_user_regs
  363. bl do_undefined_instruction
  364. .align 5
  365. software_interrupt:
  366. get_bad_stack
  367. bad_save_user_regs
  368. bl do_software_interrupt
  369. .align 5
  370. prefetch_abort:
  371. get_bad_stack
  372. bad_save_user_regs
  373. bl do_prefetch_abort
  374. .align 5
  375. data_abort:
  376. get_bad_stack
  377. bad_save_user_regs
  378. bl do_data_abort
  379. .align 5
  380. not_used:
  381. get_bad_stack
  382. bad_save_user_regs
  383. bl do_not_used
  384. #ifdef CONFIG_USE_IRQ
  385. .align 5
  386. irq:
  387. get_irq_stack
  388. irq_save_user_regs
  389. bl do_irq
  390. irq_restore_user_regs
  391. .align 5
  392. fiq:
  393. get_fiq_stack
  394. irq_save_user_regs /* someone ought to write a more */
  395. bl do_fiq /* effiction fiq_save_user_regs */
  396. irq_restore_user_regs
  397. #else
  398. .align 5
  399. irq:
  400. get_bad_stack
  401. bad_save_user_regs
  402. bl do_irq
  403. .align 5
  404. fiq:
  405. get_bad_stack
  406. bad_save_user_regs
  407. bl do_fiq
  408. #endif
  409. /****************************************************************************/
  410. /* */
  411. /* Reset function: Use Watchdog to reset */
  412. /* */
  413. /****************************************************************************/
  414. .align 5
  415. .globl reset_cpu
  416. reset_cpu:
  417. ldr r1, =0x482e
  418. ldr r2, =IXP425_OSWK
  419. str r1, [r2]
  420. ldr r1, =0x0fff
  421. ldr r2, =IXP425_OSWT
  422. str r1, [r2]
  423. ldr r1, =0x5
  424. ldr r2, =IXP425_OSWE
  425. str r1, [r2]
  426. b reset_endless
  427. reset_endless:
  428. b reset_endless