start.S 17 KB

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