start.S 12 KB

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