start.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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 <asm-offsets.h>
  30. #include <config.h>
  31. #include <version.h>
  32. #include <asm/arch/ixp425.h>
  33. #define MMU_Control_M 0x001 /* Enable MMU */
  34. #define MMU_Control_A 0x002 /* Enable address alignment faults */
  35. #define MMU_Control_C 0x004 /* Enable cache */
  36. #define MMU_Control_W 0x008 /* Enable write-buffer */
  37. #define MMU_Control_P 0x010 /* Compatability: 32 bit code */
  38. #define MMU_Control_D 0x020 /* Compatability: 32 bit data */
  39. #define MMU_Control_L 0x040 /* Compatability: */
  40. #define MMU_Control_B 0x080 /* Enable Big-Endian */
  41. #define MMU_Control_S 0x100 /* Enable system protection */
  42. #define MMU_Control_R 0x200 /* Enable ROM protection */
  43. #define MMU_Control_I 0x1000 /* Enable Instruction cache */
  44. #define MMU_Control_X 0x2000 /* Set interrupt vectors at 0xFFFF0000 */
  45. #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L)
  46. /*
  47. * Macro definitions
  48. */
  49. /* Delay a bit */
  50. .macro DELAY_FOR cycles, reg0
  51. ldr \reg0, =\cycles
  52. subs \reg0, \reg0, #1
  53. subne pc, pc, #0xc
  54. .endm
  55. /* wait for coprocessor write complete */
  56. .macro CPWAIT reg
  57. mrc p15,0,\reg,c2,c0,0
  58. mov \reg,\reg
  59. sub pc,pc,#4
  60. .endm
  61. .globl _start
  62. _start:
  63. ldr pc, _reset
  64. ldr pc, _undefined_instruction
  65. ldr pc, _software_interrupt
  66. ldr pc, _prefetch_abort
  67. ldr pc, _data_abort
  68. ldr pc, _not_used
  69. ldr pc, _irq
  70. ldr pc, _fiq
  71. _reset: .word reset
  72. _undefined_instruction: .word undefined_instruction
  73. _software_interrupt: .word software_interrupt
  74. _prefetch_abort: .word prefetch_abort
  75. _data_abort: .word data_abort
  76. _not_used: .word not_used
  77. _irq: .word irq
  78. _fiq: .word fiq
  79. .balignl 16,0xdeadbeef
  80. /*
  81. * Startup Code (reset vector)
  82. *
  83. * do important init only if we don't start from memory!
  84. * - relocate armboot to ram
  85. * - setup stack
  86. * - jump to second stage
  87. */
  88. .globl _TEXT_BASE
  89. _TEXT_BASE:
  90. #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
  91. .word CONFIG_SPL_TEXT_BASE
  92. #else
  93. .word CONFIG_SYS_TEXT_BASE
  94. #endif
  95. /*
  96. * These are defined in the board-specific linker script.
  97. * Subtracting _start from them lets the linker put their
  98. * relative position in the executable instead of leaving
  99. * them null.
  100. */
  101. .globl _bss_start_ofs
  102. _bss_start_ofs:
  103. .word __bss_start - _start
  104. .globl _bss_end_ofs
  105. _bss_end_ofs:
  106. .word __bss_end - _start
  107. .globl _end_ofs
  108. _end_ofs:
  109. .word _end - _start
  110. #ifdef CONFIG_USE_IRQ
  111. /* IRQ stack memory (calculated at run-time) */
  112. .globl IRQ_STACK_START
  113. IRQ_STACK_START:
  114. .word 0x0badc0de
  115. /* IRQ stack memory (calculated at run-time) */
  116. .globl FIQ_STACK_START
  117. FIQ_STACK_START:
  118. .word 0x0badc0de
  119. #endif
  120. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  121. .globl IRQ_STACK_START_IN
  122. IRQ_STACK_START_IN:
  123. .word 0x0badc0de
  124. /*
  125. * the actual reset code
  126. */
  127. reset:
  128. /* disable mmu, set big-endian */
  129. mov r0, #0xf8
  130. mcr p15, 0, r0, c1, c0, 0
  131. CPWAIT r0
  132. /* invalidate I & D caches & BTB */
  133. mcr p15, 0, r0, c7, c7, 0
  134. CPWAIT r0
  135. /* invalidate I & Data TLB */
  136. mcr p15, 0, r0, c8, c7, 0
  137. CPWAIT r0
  138. /* drain write and fill buffers */
  139. mcr p15, 0, r0, c7, c10, 4
  140. CPWAIT r0
  141. /* disable write buffer coalescing */
  142. mrc p15, 0, r0, c1, c0, 1
  143. orr r0, r0, #1
  144. mcr p15, 0, r0, c1, c0, 1
  145. CPWAIT r0
  146. /* set EXP CS0 to the optimum timing */
  147. ldr r1, =CONFIG_SYS_EXP_CS0
  148. ldr r2, =IXP425_EXP_CS0
  149. str r1, [r2]
  150. /* make sure flash is visible at 0 */
  151. mov r1, #CONFIG_SYS_SDR_CONFIG
  152. ldr r2, =IXP425_SDR_CONFIG
  153. str r1, [r2]
  154. /* disable refresh cycles */
  155. mov r1, #0
  156. ldr r3, =IXP425_SDR_REFRESH
  157. str r1, [r3]
  158. /* send nop command */
  159. mov r1, #3
  160. ldr r4, =IXP425_SDR_IR
  161. str r1, [r4]
  162. DELAY_FOR 0x4000, r0
  163. /* set SDRAM internal refresh val */
  164. ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT
  165. str r1, [r3]
  166. DELAY_FOR 0x4000, r0
  167. /* send precharge-all command to close all open banks */
  168. mov r1, #2
  169. str r1, [r4]
  170. DELAY_FOR 0x4000, r0
  171. /* provide 8 auto-refresh cycles */
  172. mov r1, #4
  173. mov r5, #8
  174. 111: str r1, [r4]
  175. DELAY_FOR 0x100, r0
  176. subs r5, r5, #1
  177. bne 111b
  178. /* set mode register in sdram */
  179. mov r1, #CONFIG_SYS_SDR_MODE_CONFIG
  180. str r1, [r4]
  181. DELAY_FOR 0x4000, r0
  182. /* send normal operation command */
  183. mov r1, #6
  184. str r1, [r4]
  185. DELAY_FOR 0x4000, r0
  186. /* invalidate I & D caches & BTB */
  187. mcr p15, 0, r0, c7, c7, 0
  188. CPWAIT r0
  189. /* invalidate I & Data TLB */
  190. mcr p15, 0, r0, c8, c7, 0
  191. CPWAIT r0
  192. /* drain write and fill buffers */
  193. mcr p15, 0, r0, c7, c10, 4
  194. CPWAIT r0
  195. /* remove flash mirror at 0x00000000 */
  196. ldr r2, =IXP425_EXP_CFG0
  197. ldr r1, [r2]
  198. bic r1, r1, #0x80000000
  199. str r1, [r2]
  200. /* invalidate I & Data TLB */
  201. mcr p15, 0, r0, c8, c7, 0
  202. CPWAIT r0
  203. /* enable I cache */
  204. mrc p15, 0, r0, c1, c0, 0
  205. orr r0, r0, #MMU_Control_I
  206. mcr p15, 0, r0, c1, c0, 0
  207. CPWAIT r0
  208. mrs r0,cpsr /* set the cpu to SVC32 mode */
  209. bic r0,r0,#0x1f /* (superviser mode, M=10011) */
  210. orr r0,r0,#0x13
  211. msr cpsr,r0
  212. bl _main
  213. /*------------------------------------------------------------------------------*/
  214. #ifndef CONFIG_SPL_BUILD
  215. /*
  216. * void relocate_code(addr_moni)
  217. *
  218. * This function relocates the monitor code.
  219. */
  220. .globl relocate_code
  221. relocate_code:
  222. mov r6, r0 /* save addr of destination */
  223. adr r0, _start
  224. subs r9, r6, r0 /* r9 <- relocation offset */
  225. beq relocate_done /* skip relocation */
  226. mov r1, r6 /* r1 <- scratch for copy_loop */
  227. ldr r3, _image_copy_end_ofs
  228. add r2, r0, r3 /* r2 <- source end address */
  229. copy_loop:
  230. ldmia r0!, {r10-r11} /* copy from source address [r0] */
  231. stmia r1!, {r10-r11} /* copy to target address [r1] */
  232. cmp r0, r2 /* until source end address [r2] */
  233. blo copy_loop
  234. /*
  235. * fix .rel.dyn relocations
  236. */
  237. ldr r0, _TEXT_BASE /* r0 <- Text base */
  238. ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
  239. add r10, r10, r0 /* r10 <- sym table in FLASH */
  240. ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
  241. add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
  242. ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
  243. add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
  244. fixloop:
  245. ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
  246. add r0, r0, r9 /* r0 <- location to fix up in RAM */
  247. ldr r1, [r2, #4]
  248. and r7, r1, #0xff
  249. cmp r7, #23 /* relative fixup? */
  250. beq fixrel
  251. cmp r7, #2 /* absolute fixup? */
  252. beq fixabs
  253. /* ignore unknown type of fixup */
  254. b fixnext
  255. fixabs:
  256. /* absolute fix: set location to (offset) symbol value */
  257. mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
  258. add r1, r10, r1 /* r1 <- address of symbol in table */
  259. ldr r1, [r1, #4] /* r1 <- symbol value */
  260. add r1, r1, r9 /* r1 <- relocated sym addr */
  261. b fixnext
  262. fixrel:
  263. /* relative fix: increase location by offset */
  264. ldr r1, [r0]
  265. add r1, r1, r9
  266. fixnext:
  267. str r1, [r0]
  268. add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
  269. cmp r2, r3
  270. blo fixloop
  271. relocate_done:
  272. bx lr
  273. _image_copy_end_ofs:
  274. .word __image_copy_end - _start
  275. _rel_dyn_start_ofs:
  276. .word __rel_dyn_start - _start
  277. _rel_dyn_end_ofs:
  278. .word __rel_dyn_end - _start
  279. _dynsym_start_ofs:
  280. .word __dynsym_start - _start
  281. #endif
  282. .globl c_runtime_cpu_setup
  283. c_runtime_cpu_setup:
  284. bx lr
  285. /****************************************************************************/
  286. /* */
  287. /* Interrupt handling */
  288. /* */
  289. /****************************************************************************/
  290. /* IRQ stack frame */
  291. #define S_FRAME_SIZE 72
  292. #define S_OLD_R0 68
  293. #define S_PSR 64
  294. #define S_PC 60
  295. #define S_LR 56
  296. #define S_SP 52
  297. #define S_IP 48
  298. #define S_FP 44
  299. #define S_R10 40
  300. #define S_R9 36
  301. #define S_R8 32
  302. #define S_R7 28
  303. #define S_R6 24
  304. #define S_R5 20
  305. #define S_R4 16
  306. #define S_R3 12
  307. #define S_R2 8
  308. #define S_R1 4
  309. #define S_R0 0
  310. #define MODE_SVC 0x13
  311. /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
  312. .macro bad_save_user_regs
  313. sub sp, sp, #S_FRAME_SIZE
  314. stmia sp, {r0 - r12} /* Calling r0-r12 */
  315. add r8, sp, #S_PC
  316. ldr r2, IRQ_STACK_START_IN
  317. ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
  318. add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
  319. add r5, sp, #S_SP
  320. mov r1, lr
  321. stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
  322. mov r0, sp
  323. .endm
  324. /* use irq_save_user_regs / irq_restore_user_regs for */
  325. /* IRQ/FIQ handling */
  326. .macro irq_save_user_regs
  327. sub sp, sp, #S_FRAME_SIZE
  328. stmia sp, {r0 - r12} /* Calling r0-r12 */
  329. add r8, sp, #S_PC
  330. stmdb r8, {sp, lr}^ /* Calling SP, LR */
  331. str lr, [r8, #0] /* Save calling PC */
  332. mrs r6, spsr
  333. str r6, [r8, #4] /* Save CPSR */
  334. str r0, [r8, #8] /* Save OLD_R0 */
  335. mov r0, sp
  336. .endm
  337. .macro irq_restore_user_regs
  338. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  339. mov r0, r0
  340. ldr lr, [sp, #S_PC] @ Get PC
  341. add sp, sp, #S_FRAME_SIZE
  342. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  343. .endm
  344. .macro get_bad_stack
  345. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  346. str lr, [r13] @ save caller lr / spsr
  347. mrs lr, spsr
  348. str lr, [r13, #4]
  349. mov r13, #MODE_SVC @ prepare SVC-Mode
  350. msr spsr_c, r13
  351. mov lr, pc
  352. movs pc, lr
  353. .endm
  354. .macro get_irq_stack @ setup IRQ stack
  355. ldr sp, IRQ_STACK_START
  356. .endm
  357. .macro get_fiq_stack @ setup FIQ stack
  358. ldr sp, FIQ_STACK_START
  359. .endm
  360. /****************************************************************************/
  361. /* */
  362. /* exception handlers */
  363. /* */
  364. /****************************************************************************/
  365. .align 5
  366. undefined_instruction:
  367. get_bad_stack
  368. bad_save_user_regs
  369. bl do_undefined_instruction
  370. .align 5
  371. software_interrupt:
  372. get_bad_stack
  373. bad_save_user_regs
  374. bl do_software_interrupt
  375. .align 5
  376. prefetch_abort:
  377. get_bad_stack
  378. bad_save_user_regs
  379. bl do_prefetch_abort
  380. .align 5
  381. data_abort:
  382. get_bad_stack
  383. bad_save_user_regs
  384. bl do_data_abort
  385. .align 5
  386. not_used:
  387. get_bad_stack
  388. bad_save_user_regs
  389. bl do_not_used
  390. #ifdef CONFIG_USE_IRQ
  391. .align 5
  392. irq:
  393. get_irq_stack
  394. irq_save_user_regs
  395. bl do_irq
  396. irq_restore_user_regs
  397. .align 5
  398. fiq:
  399. get_fiq_stack
  400. irq_save_user_regs /* someone ought to write a more */
  401. bl do_fiq /* effiction fiq_save_user_regs */
  402. irq_restore_user_regs
  403. #else
  404. .align 5
  405. irq:
  406. get_bad_stack
  407. bad_save_user_regs
  408. bl do_irq
  409. .align 5
  410. fiq:
  411. get_bad_stack
  412. bad_save_user_regs
  413. bl do_fiq
  414. #endif
  415. /****************************************************************************/
  416. /* */
  417. /* Reset function: Use Watchdog to reset */
  418. /* */
  419. /****************************************************************************/
  420. .align 5
  421. .globl reset_cpu
  422. reset_cpu:
  423. ldr r1, =0x482e
  424. ldr r2, =IXP425_OSWK
  425. str r1, [r2]
  426. ldr r1, =0x0fff
  427. ldr r2, =IXP425_OSWT
  428. str r1, [r2]
  429. ldr r1, =0x5
  430. ldr r2, =IXP425_OSWE
  431. str r1, [r2]
  432. b reset_endless
  433. reset_endless:
  434. b reset_endless