start.S 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * armboot - Startup Code for ARM1176 CPU-core
  3. *
  4. * Copyright (c) 2007 Samsung Electronics
  5. *
  6. * Copyright (C) 2008
  7. * Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. * 2007-09-21 - Restructured codes by jsgood (jsgood.yang@samsung.com)
  28. * 2007-09-21 - Added MoviNAND and OneNAND boot codes by
  29. * jsgood (jsgood.yang@samsung.com)
  30. * Base codes by scsuh (sc.suh)
  31. */
  32. #include <config.h>
  33. #include <version.h>
  34. #ifdef CONFIG_ENABLE_MMU
  35. #include <asm/proc/domain.h>
  36. #endif
  37. #if !defined(CONFIG_ENABLE_MMU) && !defined(CONFIG_SYS_PHY_UBOOT_BASE)
  38. #define CONFIG_SYS_PHY_UBOOT_BASE CONFIG_SYS_UBOOT_BASE
  39. #endif
  40. /*
  41. *************************************************************************
  42. *
  43. * Jump vector table as in table 3.1 in [1]
  44. *
  45. *************************************************************************
  46. */
  47. .globl _start
  48. _start: b reset
  49. #ifndef CONFIG_NAND_SPL
  50. ldr pc, _undefined_instruction
  51. ldr pc, _software_interrupt
  52. ldr pc, _prefetch_abort
  53. ldr pc, _data_abort
  54. ldr pc, _not_used
  55. ldr pc, _irq
  56. ldr pc, _fiq
  57. _undefined_instruction:
  58. .word undefined_instruction
  59. _software_interrupt:
  60. .word software_interrupt
  61. _prefetch_abort:
  62. .word prefetch_abort
  63. _data_abort:
  64. .word data_abort
  65. _not_used:
  66. .word not_used
  67. _irq:
  68. .word irq
  69. _fiq:
  70. .word fiq
  71. _pad:
  72. .word 0x12345678 /* now 16*4=64 */
  73. #else
  74. . = _start + 64
  75. #endif
  76. .global _end_vect
  77. _end_vect:
  78. .balignl 16,0xdeadbeef
  79. /*
  80. *************************************************************************
  81. *
  82. * Startup Code (reset vector)
  83. *
  84. * do important init only if we don't start from memory!
  85. * setup Memory and board specific bits prior to relocation.
  86. * relocate armboot to ram
  87. * setup stack
  88. *
  89. *************************************************************************
  90. */
  91. .globl _TEXT_BASE
  92. _TEXT_BASE:
  93. .word CONFIG_SYS_TEXT_BASE
  94. /*
  95. * Below variable is very important because we use MMU in U-Boot.
  96. * Without it, we cannot run code correctly before MMU is ON.
  97. * by scsuh.
  98. */
  99. _TEXT_PHY_BASE:
  100. .word CONFIG_SYS_PHY_UBOOT_BASE
  101. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  102. .globl _armboot_start
  103. _armboot_start:
  104. .word _start
  105. #endif
  106. /*
  107. * These are defined in the board-specific linker script.
  108. */
  109. .globl _bss_start
  110. _bss_start:
  111. .word __bss_start
  112. .globl _bss_end
  113. _bss_end:
  114. .word _end
  115. #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  116. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  117. .globl IRQ_STACK_START_IN
  118. IRQ_STACK_START_IN:
  119. .word 0x0badc0de
  120. .globl _datarel_start
  121. _datarel_start:
  122. .word __datarel_start
  123. .globl _datarelrolocal_start
  124. _datarelrolocal_start:
  125. .word __datarelrolocal_start
  126. .globl _datarellocal_start
  127. _datarellocal_start:
  128. .word __datarellocal_start
  129. .globl _datarelro_start
  130. _datarelro_start:
  131. .word __datarelro_start
  132. .globl _got_start
  133. _got_start:
  134. .word __got_start
  135. .globl _got_end
  136. _got_end:
  137. .word __got_end
  138. /*
  139. * the actual reset code
  140. */
  141. reset:
  142. /*
  143. * set the cpu to SVC32 mode
  144. */
  145. mrs r0, cpsr
  146. bic r0, r0, #0x3f
  147. orr r0, r0, #0xd3
  148. msr cpsr, r0
  149. /*
  150. *************************************************************************
  151. *
  152. * CPU_init_critical registers
  153. *
  154. * setup important registers
  155. * setup memory timing
  156. *
  157. *************************************************************************
  158. */
  159. /*
  160. * we do sys-critical inits only at reboot,
  161. * not when booting from ram!
  162. */
  163. cpu_init_crit:
  164. /*
  165. * When booting from NAND - it has definitely been a reset, so, no need
  166. * to flush caches and disable the MMU
  167. */
  168. #ifndef CONFIG_NAND_SPL
  169. /*
  170. * flush v4 I/D caches
  171. */
  172. mov r0, #0
  173. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  174. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  175. /*
  176. * disable MMU stuff and caches
  177. */
  178. mrc p15, 0, r0, c1, c0, 0
  179. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  180. bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
  181. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  182. orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
  183. /* Prepare to disable the MMU */
  184. adr r2, mmu_disable_phys
  185. sub r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - CONFIG_SYS_TEXT_BASE)
  186. b mmu_disable
  187. .align 5
  188. /* Run in a single cache-line */
  189. mmu_disable:
  190. mcr p15, 0, r0, c1, c0, 0
  191. nop
  192. nop
  193. mov pc, r2
  194. mmu_disable_phys:
  195. #ifdef CONFIG_DISABLE_TCM
  196. /*
  197. * Disable the TCMs
  198. */
  199. mrc p15, 0, r0, c0, c0, 2 /* Return TCM details */
  200. cmp r0, #0
  201. beq skip_tcmdisable
  202. mov r1, #0
  203. mov r2, #1
  204. tst r0, r2
  205. mcrne p15, 0, r1, c9, c1, 1 /* Disable Instruction TCM if present*/
  206. tst r0, r2, LSL #16
  207. mcrne p15, 0, r1, c9, c1, 0 /* Disable Data TCM if present*/
  208. skip_tcmdisable:
  209. #endif
  210. #endif
  211. #ifdef CONFIG_PERIPORT_REMAP
  212. /* Peri port setup */
  213. ldr r0, =CONFIG_PERIPORT_BASE
  214. orr r0, r0, #CONFIG_PERIPORT_SIZE
  215. mcr p15,0,r0,c15,c2,4
  216. #endif
  217. /*
  218. * Go setup Memory and board specific bits prior to relocation.
  219. */
  220. bl lowlevel_init /* go setup pll,mux,memory */
  221. /* Set stackpointer in internal RAM to call board_init_f */
  222. call_board_init_f:
  223. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  224. ldr r0,=0x00000000
  225. bl board_init_f
  226. /*------------------------------------------------------------------------------*/
  227. /*
  228. * void relocate_code (addr_sp, gd, addr_moni)
  229. *
  230. * This "function" does not return, instead it continues in RAM
  231. * after relocating the monitor code.
  232. *
  233. */
  234. .globl relocate_code
  235. relocate_code:
  236. mov r4, r0 /* save addr_sp */
  237. mov r5, r1 /* save addr of gd */
  238. mov r6, r2 /* save addr of destination */
  239. mov r7, r2 /* save addr of destination */
  240. /* Set up the stack */
  241. stack_setup:
  242. mov sp, r4
  243. adr r0, _start
  244. ldr r2, _TEXT_BASE
  245. ldr r3, _bss_start
  246. sub r2, r3, r2 /* r2 <- size of armboot */
  247. add r2, r0, r2 /* r2 <- source end address */
  248. cmp r0, r6
  249. beq clear_bss
  250. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  251. copy_loop:
  252. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  253. stmia r6!, {r9-r10} /* copy to target address [r1] */
  254. cmp r0, r2 /* until source end address [r2] */
  255. blo copy_loop
  256. #ifndef CONFIG_PRELOADER
  257. /* fix got entries */
  258. ldr r1, _TEXT_BASE /* Text base */
  259. mov r0, r7 /* reloc addr */
  260. ldr r2, _got_start /* addr in Flash */
  261. ldr r3, _got_end /* addr in Flash */
  262. sub r3, r3, r1
  263. add r3, r3, r0
  264. sub r2, r2, r1
  265. add r2, r2, r0
  266. fixloop:
  267. ldr r4, [r2]
  268. sub r4, r4, r1
  269. add r4, r4, r0
  270. str r4, [r2]
  271. add r2, r2, #4
  272. cmp r2, r3
  273. bne fixloop
  274. #endif
  275. #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
  276. #ifdef CONFIG_ENABLE_MMU
  277. enable_mmu:
  278. /* enable domain access */
  279. ldr r5, =0x0000ffff
  280. mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
  281. /* Set the TTB register */
  282. ldr r0, _mmu_table_base
  283. ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
  284. ldr r2, =0xfff00000
  285. bic r0, r0, r2
  286. orr r1, r0, r1
  287. mcr p15, 0, r1, c2, c0, 0
  288. /* Enable the MMU */
  289. mrc p15, 0, r0, c1, c0, 0
  290. orr r0, r0, #1 /* Set CR_M to enable MMU */
  291. /* Prepare to enable the MMU */
  292. adr r1, skip_hw_init
  293. and r1, r1, #0x3fc
  294. ldr r2, _TEXT_BASE
  295. ldr r3, =0xfff00000
  296. and r2, r2, r3
  297. orr r2, r2, r1
  298. b mmu_enable
  299. .align 5
  300. /* Run in a single cache-line */
  301. mmu_enable:
  302. mcr p15, 0, r0, c1, c0, 0
  303. nop
  304. nop
  305. mov pc, r2
  306. skip_hw_init:
  307. #endif
  308. clear_bss:
  309. #ifndef CONFIG_PRELOADER
  310. ldr r0, _bss_start
  311. ldr r1, _bss_end
  312. ldr r3, _TEXT_BASE /* Text base */
  313. mov r4, r7 /* reloc addr */
  314. sub r0, r0, r3
  315. add r0, r0, r4
  316. sub r1, r1, r3
  317. add r1, r1, r4
  318. mov r2, #0x00000000 /* clear */
  319. clbss_l:str r2, [r0] /* clear loop... */
  320. add r0, r0, #4
  321. cmp r0, r1
  322. bne clbss_l
  323. bl coloured_LED_init
  324. bl red_LED_on
  325. #endif
  326. /*
  327. * We are done. Do not return, instead branch to second part of board
  328. * initialization, now running from RAM.
  329. */
  330. #ifdef CONFIG_NAND_SPL
  331. ldr pc, _nand_boot
  332. _nand_boot: .word nand_boot
  333. #else
  334. ldr r0, _TEXT_BASE
  335. ldr r2, _board_init_r
  336. sub r2, r2, r0
  337. add r2, r2, r7 /* position from board_init_r in RAM */
  338. /* setup parameters for board_init_r */
  339. mov r0, r5 /* gd_t */
  340. mov r1, r7 /* dest_addr */
  341. /* jump to it ... */
  342. mov lr, r2
  343. mov pc, lr
  344. _board_init_r: .word board_init_r
  345. #endif
  346. #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  347. /*
  348. * the actual reset code
  349. */
  350. reset:
  351. /*
  352. * set the cpu to SVC32 mode
  353. */
  354. mrs r0, cpsr
  355. bic r0, r0, #0x3f
  356. orr r0, r0, #0xd3
  357. msr cpsr, r0
  358. /*
  359. *************************************************************************
  360. *
  361. * CPU_init_critical registers
  362. *
  363. * setup important registers
  364. * setup memory timing
  365. *
  366. *************************************************************************
  367. */
  368. /*
  369. * we do sys-critical inits only at reboot,
  370. * not when booting from ram!
  371. */
  372. cpu_init_crit:
  373. /*
  374. * When booting from NAND - it has definitely been a reset, so, no need
  375. * to flush caches and disable the MMU
  376. */
  377. #ifndef CONFIG_NAND_SPL
  378. /*
  379. * flush v4 I/D caches
  380. */
  381. mov r0, #0
  382. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  383. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  384. /*
  385. * disable MMU stuff and caches
  386. */
  387. mrc p15, 0, r0, c1, c0, 0
  388. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  389. bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
  390. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  391. orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
  392. /* Prepare to disable the MMU */
  393. adr r2, mmu_disable_phys
  394. sub r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - CONFIG_SYS_TEXT_BASE)
  395. b mmu_disable
  396. .align 5
  397. /* Run in a single cache-line */
  398. mmu_disable:
  399. mcr p15, 0, r0, c1, c0, 0
  400. nop
  401. nop
  402. mov pc, r2
  403. mmu_disable_phys:
  404. #ifdef CONFIG_DISABLE_TCM
  405. /*
  406. * Disable the TCMs
  407. */
  408. mrc p15, 0, r0, c0, c0, 2 /* Return TCM details */
  409. cmp r0, #0
  410. beq skip_tcmdisable
  411. mov r1, #0
  412. mov r2, #1
  413. tst r0, r2
  414. mcrne p15, 0, r1, c9, c1, 1 /* Disable Instruction TCM if present*/
  415. tst r0, r2, LSL #16
  416. mcrne p15, 0, r1, c9, c1, 0 /* Disable Data TCM if present*/
  417. skip_tcmdisable:
  418. #endif
  419. #endif
  420. #ifdef CONFIG_PERIPORT_REMAP
  421. /* Peri port setup */
  422. ldr r0, =CONFIG_PERIPORT_BASE
  423. orr r0, r0, #CONFIG_PERIPORT_SIZE
  424. mcr p15,0,r0,c15,c2,4
  425. #endif
  426. /*
  427. * Go setup Memory and board specific bits prior to relocation.
  428. */
  429. bl lowlevel_init /* go setup pll,mux,memory */
  430. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  431. relocate: /* relocate U-Boot to RAM */
  432. adr r0, _start /* r0 <- current position of code */
  433. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  434. cmp r0, r1 /* don't reloc during debug */
  435. beq stack_setup
  436. ldr r2, _armboot_start
  437. ldr r3, _bss_start
  438. sub r2, r3, r2 /* r2 <- size of armboot */
  439. add r2, r0, r2 /* r2 <- source end address */
  440. copy_loop:
  441. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  442. stmia r1!, {r3-r10} /* copy to target address [r1] */
  443. cmp r0, r2 /* until source end address [r2] */
  444. blo copy_loop
  445. #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
  446. #ifdef CONFIG_ENABLE_MMU
  447. enable_mmu:
  448. /* enable domain access */
  449. ldr r5, =0x0000ffff
  450. mcr p15, 0, r5, c3, c0, 0 /* load domain access register */
  451. /* Set the TTB register */
  452. ldr r0, _mmu_table_base
  453. ldr r1, =CONFIG_SYS_PHY_UBOOT_BASE
  454. ldr r2, =0xfff00000
  455. bic r0, r0, r2
  456. orr r1, r0, r1
  457. mcr p15, 0, r1, c2, c0, 0
  458. /* Enable the MMU */
  459. mrc p15, 0, r0, c1, c0, 0
  460. orr r0, r0, #1 /* Set CR_M to enable MMU */
  461. /* Prepare to enable the MMU */
  462. adr r1, skip_hw_init
  463. and r1, r1, #0x3fc
  464. ldr r2, _TEXT_BASE
  465. ldr r3, =0xfff00000
  466. and r2, r2, r3
  467. orr r2, r2, r1
  468. b mmu_enable
  469. .align 5
  470. /* Run in a single cache-line */
  471. mmu_enable:
  472. mcr p15, 0, r0, c1, c0, 0
  473. nop
  474. nop
  475. mov pc, r2
  476. skip_hw_init:
  477. #endif
  478. /* Set up the stack */
  479. stack_setup:
  480. ldr r0, =CONFIG_SYS_UBOOT_BASE /* base of copy in DRAM */
  481. sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
  482. sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
  483. sub sp, r0, #12 /* leave 3 words for abort-stack */
  484. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  485. clear_bss:
  486. ldr r0, _bss_start /* find start of bss segment */
  487. ldr r1, _bss_end /* stop here */
  488. mov r2, #0 /* clear */
  489. clbss_l:
  490. str r2, [r0] /* clear loop... */
  491. add r0, r0, #4
  492. cmp r0, r1
  493. blo clbss_l
  494. #ifndef CONFIG_NAND_SPL
  495. ldr pc, _start_armboot
  496. _start_armboot:
  497. .word start_armboot
  498. #else
  499. b nand_boot
  500. /* .word nand_boot*/
  501. #endif
  502. #endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  503. #ifdef CONFIG_ENABLE_MMU
  504. _mmu_table_base:
  505. .word mmu_table
  506. #endif
  507. #ifndef CONFIG_NAND_SPL
  508. /*
  509. * we assume that cache operation is done before. (eg. cleanup_before_linux())
  510. * actually, we don't need to do anything about cache if not use d-cache in
  511. * U-Boot. So, in this function we clean only MMU. by scsuh
  512. *
  513. * void theLastJump(void *kernel, int arch_num, uint boot_params);
  514. */
  515. #ifdef CONFIG_ENABLE_MMU
  516. .globl theLastJump
  517. theLastJump:
  518. mov r9, r0
  519. ldr r3, =0xfff00000
  520. ldr r4, _TEXT_PHY_BASE
  521. adr r5, phy_last_jump
  522. bic r5, r5, r3
  523. orr r5, r5, r4
  524. mov pc, r5
  525. phy_last_jump:
  526. /*
  527. * disable MMU stuff
  528. */
  529. mrc p15, 0, r0, c1, c0, 0
  530. bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
  531. bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
  532. orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
  533. orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
  534. mcr p15, 0, r0, c1, c0, 0
  535. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  536. mov r0, #0
  537. mov pc, r9
  538. #endif
  539. /*
  540. *************************************************************************
  541. *
  542. * Interrupt handling
  543. *
  544. *************************************************************************
  545. */
  546. @
  547. @ IRQ stack frame.
  548. @
  549. #define S_FRAME_SIZE 72
  550. #define S_OLD_R0 68
  551. #define S_PSR 64
  552. #define S_PC 60
  553. #define S_LR 56
  554. #define S_SP 52
  555. #define S_IP 48
  556. #define S_FP 44
  557. #define S_R10 40
  558. #define S_R9 36
  559. #define S_R8 32
  560. #define S_R7 28
  561. #define S_R6 24
  562. #define S_R5 20
  563. #define S_R4 16
  564. #define S_R3 12
  565. #define S_R2 8
  566. #define S_R1 4
  567. #define S_R0 0
  568. #define MODE_SVC 0x13
  569. #define I_BIT 0x80
  570. /*
  571. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  572. */
  573. .macro bad_save_user_regs
  574. /* carve out a frame on current user stack */
  575. sub sp, sp, #S_FRAME_SIZE
  576. /* Save user registers (now in svc mode) r0-r12 */
  577. stmia sp, {r0 - r12}
  578. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  579. ldr r2, _armboot_start
  580. sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
  581. /* set base 2 words into abort stack */
  582. sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)
  583. #else
  584. ldr r2, IRQ_STACK_START_IN
  585. #endif
  586. /* get values for "aborted" pc and cpsr (into parm regs) */
  587. ldmia r2, {r2 - r3}
  588. /* grab pointer to old stack */
  589. add r0, sp, #S_FRAME_SIZE
  590. add r5, sp, #S_SP
  591. mov r1, lr
  592. /* save sp_SVC, lr_SVC, pc, cpsr */
  593. stmia r5, {r0 - r3}
  594. /* save current stack into r0 (param register) */
  595. mov r0, sp
  596. .endm
  597. .macro get_bad_stack
  598. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  599. /* setup our mode stack (enter in banked mode) */
  600. ldr r13, _armboot_start
  601. /* move past malloc pool */
  602. sub r13, r13, #(CONFIG_SYS_MALLOC_LEN)
  603. /* move to reserved a couple spots for abort stack */
  604. sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  605. #else
  606. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  607. #endif
  608. /* save caller lr in position 0 of saved stack */
  609. str lr, [r13]
  610. /* get the spsr */
  611. mrs lr, spsr
  612. /* save spsr in position 1 of saved stack */
  613. str lr, [r13, #4]
  614. /* prepare SVC-Mode */
  615. mov r13, #MODE_SVC
  616. @ msr spsr_c, r13
  617. /* switch modes, make sure moves will execute */
  618. msr spsr, r13
  619. /* capture return pc */
  620. mov lr, pc
  621. /* jump to next instruction & switch modes. */
  622. movs pc, lr
  623. .endm
  624. .macro get_bad_stack_swi
  625. /* space on current stack for scratch reg. */
  626. sub r13, r13, #4
  627. /* save R0's value. */
  628. str r0, [r13]
  629. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  630. /* get data regions start */
  631. ldr r0, _armboot_start
  632. /* move past malloc pool */
  633. sub r0, r0, #(CONFIG_SYS_MALLOC_LEN)
  634. /* move past gbl and a couple spots for abort stack */
  635. sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE + 8)
  636. #else
  637. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  638. #endif
  639. /* save caller lr in position 0 of saved stack */
  640. str lr, [r0]
  641. /* get the spsr */
  642. mrs r0, spsr
  643. /* save spsr in position 1 of saved stack */
  644. str lr, [r0, #4]
  645. /* restore r0 */
  646. ldr r0, [r13]
  647. /* pop stack entry */
  648. add r13, r13, #4
  649. .endm
  650. /*
  651. * exception handlers
  652. */
  653. .align 5
  654. undefined_instruction:
  655. get_bad_stack
  656. bad_save_user_regs
  657. bl do_undefined_instruction
  658. .align 5
  659. software_interrupt:
  660. get_bad_stack_swi
  661. bad_save_user_regs
  662. bl do_software_interrupt
  663. .align 5
  664. prefetch_abort:
  665. get_bad_stack
  666. bad_save_user_regs
  667. bl do_prefetch_abort
  668. .align 5
  669. data_abort:
  670. get_bad_stack
  671. bad_save_user_regs
  672. bl do_data_abort
  673. .align 5
  674. not_used:
  675. get_bad_stack
  676. bad_save_user_regs
  677. bl do_not_used
  678. .align 5
  679. irq:
  680. get_bad_stack
  681. bad_save_user_regs
  682. bl do_irq
  683. .align 5
  684. fiq:
  685. get_bad_stack
  686. bad_save_user_regs
  687. bl do_fiq
  688. #endif /* CONFIG_NAND_SPL */