start.S 18 KB

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