start.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * armboot - Startup Code for ARM720 CPU-core
  3. *
  4. * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
  5. * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <config.h>
  26. #include <version.h>
  27. #include <asm/hardware.h>
  28. /*
  29. *************************************************************************
  30. *
  31. * Jump vector table as in table 3.1 in [1]
  32. *
  33. *************************************************************************
  34. */
  35. .globl _start
  36. _start: b reset
  37. ldr pc, _undefined_instruction
  38. ldr pc, _software_interrupt
  39. ldr pc, _prefetch_abort
  40. ldr pc, _data_abort
  41. #ifdef CONFIG_LPC2292
  42. .word 0xB4405F76 /* 2's complement of the checksum of the vectors */
  43. #else
  44. ldr pc, _not_used
  45. #endif
  46. ldr pc, _irq
  47. ldr pc, _fiq
  48. _undefined_instruction: .word undefined_instruction
  49. _software_interrupt: .word software_interrupt
  50. _prefetch_abort: .word prefetch_abort
  51. _data_abort: .word data_abort
  52. _not_used: .word not_used
  53. _irq: .word irq
  54. _fiq: .word fiq
  55. .balignl 16,0xdeadbeef
  56. /*
  57. *************************************************************************
  58. *
  59. * Startup Code (reset vector)
  60. *
  61. * do important init only if we don't start from RAM!
  62. * relocate armboot to ram
  63. * setup stack
  64. * jump to second stage
  65. *
  66. *************************************************************************
  67. */
  68. .globl _TEXT_BASE
  69. _TEXT_BASE:
  70. .word CONFIG_SYS_TEXT_BASE
  71. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  72. .globl _armboot_start
  73. _armboot_start:
  74. .word _start
  75. #endif
  76. /*
  77. * These are defined in the board-specific linker script.
  78. */
  79. .globl _bss_start
  80. _bss_start:
  81. .word __bss_start
  82. .globl _bss_end
  83. _bss_end:
  84. .word _end
  85. #ifdef CONFIG_USE_IRQ
  86. /* IRQ stack memory (calculated at run-time) */
  87. .globl IRQ_STACK_START
  88. IRQ_STACK_START:
  89. .word 0x0badc0de
  90. /* IRQ stack memory (calculated at run-time) */
  91. .globl FIQ_STACK_START
  92. FIQ_STACK_START:
  93. .word 0x0badc0de
  94. #endif
  95. #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  96. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  97. .globl IRQ_STACK_START_IN
  98. IRQ_STACK_START_IN:
  99. .word 0x0badc0de
  100. .globl _datarel_start
  101. _datarel_start:
  102. .word __datarel_start
  103. .globl _datarelrolocal_start
  104. _datarelrolocal_start:
  105. .word __datarelrolocal_start
  106. .globl _datarellocal_start
  107. _datarellocal_start:
  108. .word __datarellocal_start
  109. .globl _datarelro_start
  110. _datarelro_start:
  111. .word __datarelro_start
  112. .globl _got_start
  113. _got_start:
  114. .word __got_start
  115. .globl _got_end
  116. _got_end:
  117. .word __got_end
  118. /*
  119. * the actual reset code
  120. */
  121. reset:
  122. /*
  123. * set the cpu to SVC32 mode
  124. */
  125. mrs r0,cpsr
  126. bic r0,r0,#0x1f
  127. orr r0,r0,#0xd3
  128. msr cpsr,r0
  129. /*
  130. * we do sys-critical inits only at reboot,
  131. * not when booting from ram!
  132. */
  133. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  134. bl cpu_init_crit
  135. #endif
  136. #ifdef CONFIG_LPC2292
  137. bl lowlevel_init
  138. #endif
  139. /* Set stackpointer in internal RAM to call board_init_f */
  140. call_board_init_f:
  141. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  142. ldr r0,=0x00000000
  143. bl board_init_f
  144. /*------------------------------------------------------------------------------*/
  145. /*
  146. * void relocate_code (addr_sp, gd, addr_moni)
  147. *
  148. * This "function" does not return, instead it continues in RAM
  149. * after relocating the monitor code.
  150. *
  151. */
  152. .globl relocate_code
  153. relocate_code:
  154. mov r4, r0 /* save addr_sp */
  155. mov r5, r1 /* save addr of gd */
  156. mov r6, r2 /* save addr of destination */
  157. mov r7, r2 /* save addr of destination */
  158. /* Set up the stack */
  159. stack_setup:
  160. mov sp, r4
  161. adr r0, _start
  162. ldr r2, _TEXT_BASE
  163. ldr r3, _bss_start
  164. sub r2, r3, r2 /* r2 <- size of armboot */
  165. add r2, r0, r2 /* r2 <- source end address */
  166. cmp r0, r6
  167. beq clear_bss
  168. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  169. copy_loop:
  170. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  171. stmia r6!, {r9-r10} /* copy to target address [r1] */
  172. cmp r0, r2 /* until source end address [r2] */
  173. blo copy_loop
  174. #ifndef CONFIG_PRELOADER
  175. /* fix got entries */
  176. ldr r1, _TEXT_BASE /* Text base */
  177. mov r0, r7 /* reloc addr */
  178. ldr r2, _got_start /* addr in Flash */
  179. ldr r3, _got_end /* addr in Flash */
  180. sub r3, r3, r1
  181. add r3, r3, r0
  182. sub r2, r2, r1
  183. add r2, r2, r0
  184. fixloop:
  185. ldr r4, [r2]
  186. sub r4, r4, r1
  187. add r4, r4, r0
  188. str r4, [r2]
  189. add r2, r2, #4
  190. cmp r2, r3
  191. bne fixloop
  192. #endif
  193. #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
  194. clear_bss:
  195. #ifndef CONFIG_PRELOADER
  196. ldr r0, _bss_start
  197. ldr r1, _bss_end
  198. ldr r3, _TEXT_BASE /* Text base */
  199. mov r4, r7 /* reloc addr */
  200. sub r0, r0, r3
  201. add r0, r0, r4
  202. sub r1, r1, r3
  203. add r1, r1, r4
  204. mov r2, #0x00000000 /* clear */
  205. clbss_l:str r2, [r0] /* clear loop... */
  206. add r0, r0, #4
  207. cmp r0, r1
  208. bne clbss_l
  209. bl coloured_LED_init
  210. bl red_LED_on
  211. #endif
  212. /*
  213. * We are done. Do not return, instead branch to second part of board
  214. * initialization, now running from RAM.
  215. */
  216. ldr r0, _TEXT_BASE
  217. ldr r2, _board_init_r
  218. sub r2, r2, r0
  219. add r2, r2, r7 /* position from board_init_r in RAM */
  220. /* setup parameters for board_init_r */
  221. mov r0, r5 /* gd_t */
  222. mov r1, r7 /* dest_addr */
  223. /* jump to it ... */
  224. mov lr, r2
  225. mov pc, lr
  226. _board_init_r: .word board_init_r
  227. #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  228. /*
  229. * the actual reset code
  230. */
  231. reset:
  232. /*
  233. * set the cpu to SVC32 mode
  234. */
  235. mrs r0,cpsr
  236. bic r0,r0,#0x1f
  237. orr r0,r0,#0x13
  238. msr cpsr,r0
  239. /*
  240. * we do sys-critical inits only at reboot,
  241. * not when booting from ram!
  242. */
  243. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  244. bl cpu_init_crit
  245. #endif
  246. #ifdef CONFIG_LPC2292
  247. bl lowlevel_init
  248. #endif
  249. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  250. relocate: /* relocate U-Boot to RAM */
  251. adr r0, _start /* r0 <- current position of code */
  252. ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
  253. cmp r0, r1 /* don't reloc during debug */
  254. beq stack_setup
  255. #if CONFIG_SYS_TEXT_BASE
  256. #ifndef CONFIG_LPC2292 /* already done in lowlevel_init */
  257. ldr r2, =0x0 /* Relocate the exception vectors */
  258. cmp r1, r2 /* and associated data to address */
  259. ldmneia r0!, {r3-r10} /* 0x0. Do nothing if CONFIG_SYS_TEXT_BASE is */
  260. stmneia r2!, {r3-r10} /* 0x0. Copy the first 15 words. */
  261. ldmneia r0, {r3-r9}
  262. stmneia r2, {r3-r9}
  263. adrne r0, _start /* restore r0 */
  264. #endif /* !CONFIG_LPC2292 */
  265. #endif
  266. ldr r2, _armboot_start
  267. ldr r3, _bss_start
  268. sub r2, r3, r2 /* r2 <- size of armboot */
  269. add r2, r0, r2 /* r2 <- source end address */
  270. copy_loop:
  271. ldmia r0!, {r3-r10} /* copy from source address [r0] */
  272. stmia r1!, {r3-r10} /* copy to target address [r1] */
  273. cmp r0, r2 /* until source end address [r2] */
  274. blo copy_loop
  275. #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
  276. /* Set up the stack */
  277. stack_setup:
  278. ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
  279. sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
  280. sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
  281. #ifdef CONFIG_USE_IRQ
  282. sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
  283. #endif
  284. sub sp, r0, #12 /* leave 3 words for abort-stack */
  285. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  286. clear_bss:
  287. ldr r0, _bss_start /* find start of bss segment */
  288. ldr r1, _bss_end /* stop here */
  289. mov r2, #0x00000000 /* clear */
  290. clbss_l:str r2, [r0] /* clear loop... */
  291. add r0, r0, #4
  292. cmp r0, r1
  293. blo clbss_l
  294. ldr pc, _start_armboot
  295. _start_armboot: .word start_armboot
  296. #endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  297. /*
  298. *************************************************************************
  299. *
  300. * CPU_init_critical registers
  301. *
  302. * setup important registers
  303. * setup memory timing
  304. *
  305. *************************************************************************
  306. */
  307. #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
  308. /* Interupt-Controller base addresses */
  309. INTMR1: .word 0x80000280 @ 32 bit size
  310. INTMR2: .word 0x80001280 @ 16 bit size
  311. INTMR3: .word 0x80002280 @ 8 bit size
  312. /* SYSCONs */
  313. SYSCON1: .word 0x80000100
  314. SYSCON2: .word 0x80001100
  315. SYSCON3: .word 0x80002200
  316. #define CLKCTL 0x6 /* mask */
  317. #define CLKCTL_18 0x0 /* 18.432 MHz */
  318. #define CLKCTL_36 0x2 /* 36.864 MHz */
  319. #define CLKCTL_49 0x4 /* 49.152 MHz */
  320. #define CLKCTL_73 0x6 /* 73.728 MHz */
  321. #elif defined(CONFIG_LPC2292)
  322. PLLCFG_ADR: .word PLLCFG
  323. PLLFEED_ADR: .word PLLFEED
  324. PLLCON_ADR: .word PLLCON
  325. PLLSTAT_ADR: .word PLLSTAT
  326. VPBDIV_ADR: .word VPBDIV
  327. MEMMAP_ADR: .word MEMMAP
  328. #endif
  329. cpu_init_crit:
  330. #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
  331. /*
  332. * mask all IRQs by clearing all bits in the INTMRs
  333. */
  334. mov r1, #0x00
  335. ldr r0, INTMR1
  336. str r1, [r0]
  337. ldr r0, INTMR2
  338. str r1, [r0]
  339. ldr r0, INTMR3
  340. str r1, [r0]
  341. /*
  342. * flush v4 I/D caches
  343. */
  344. mov r0, #0
  345. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  346. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  347. /*
  348. * disable MMU stuff and caches
  349. */
  350. mrc p15,0,r0,c1,c0
  351. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  352. bic r0, r0, #0x0000008f @ clear bits 7, 3:0 (B--- WCAM)
  353. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  354. mcr p15,0,r0,c1,c0
  355. #elif defined(CONFIG_NETARM)
  356. /*
  357. * prior to software reset : need to set pin PORTC4 to be *HRESET
  358. */
  359. ldr r0, =NETARM_GEN_MODULE_BASE
  360. ldr r1, =(NETARM_GEN_PORT_MODE(0x10) | \
  361. NETARM_GEN_PORT_DIR(0x10))
  362. str r1, [r0, #+NETARM_GEN_PORTC]
  363. /*
  364. * software reset : see HW Ref. Guide 8.2.4 : Software Service register
  365. * for an explanation of this process
  366. */
  367. ldr r0, =NETARM_GEN_MODULE_BASE
  368. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  369. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  370. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  371. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  372. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  373. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  374. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  375. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  376. /*
  377. * setup PLL and System Config
  378. */
  379. ldr r0, =NETARM_GEN_MODULE_BASE
  380. ldr r1, =( NETARM_GEN_SYS_CFG_LENDIAN | \
  381. NETARM_GEN_SYS_CFG_BUSFULL | \
  382. NETARM_GEN_SYS_CFG_USER_EN | \
  383. NETARM_GEN_SYS_CFG_ALIGN_ABORT | \
  384. NETARM_GEN_SYS_CFG_BUSARB_INT | \
  385. NETARM_GEN_SYS_CFG_BUSMON_EN )
  386. str r1, [r0, #+NETARM_GEN_SYSTEM_CONTROL]
  387. #ifndef CONFIG_NETARM_PLL_BYPASS
  388. ldr r1, =( NETARM_GEN_PLL_CTL_PLLCNT(NETARM_PLL_COUNT_VAL) | \
  389. NETARM_GEN_PLL_CTL_POLTST_DEF | \
  390. NETARM_GEN_PLL_CTL_INDIV(1) | \
  391. NETARM_GEN_PLL_CTL_ICP_DEF | \
  392. NETARM_GEN_PLL_CTL_OUTDIV(2) )
  393. str r1, [r0, #+NETARM_GEN_PLL_CONTROL]
  394. #endif
  395. /*
  396. * mask all IRQs by clearing all bits in the INTMRs
  397. */
  398. mov r1, #0
  399. ldr r0, =NETARM_GEN_MODULE_BASE
  400. str r1, [r0, #+NETARM_GEN_INTR_ENABLE]
  401. #elif defined(CONFIG_S3C4510B)
  402. /*
  403. * Mask off all IRQ sources
  404. */
  405. ldr r1, =REG_INTMASK
  406. ldr r0, =0x3FFFFF
  407. str r0, [r1]
  408. /*
  409. * Disable Cache
  410. */
  411. ldr r0, =REG_SYSCFG
  412. ldr r1, =0x83ffffa0 /* cache-disabled */
  413. str r1, [r0]
  414. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  415. /* No specific initialisation for IntegratorAP/CM720T as yet */
  416. #elif defined(CONFIG_LPC2292)
  417. /* Set-up PLL */
  418. mov r3, #0xAA
  419. mov r4, #0x55
  420. /* First disconnect and disable the PLL */
  421. ldr r0, PLLCON_ADR
  422. mov r1, #0x00
  423. str r1, [r0]
  424. ldr r0, PLLFEED_ADR /* start feed sequence */
  425. str r3, [r0]
  426. str r4, [r0] /* feed sequence done */
  427. /* Set new M and P values */
  428. ldr r0, PLLCFG_ADR
  429. mov r1, #0x23 /* M=4 and P=2 */
  430. str r1, [r0]
  431. ldr r0, PLLFEED_ADR /* start feed sequence */
  432. str r3, [r0]
  433. str r4, [r0] /* feed sequence done */
  434. /* Then enable the PLL */
  435. ldr r0, PLLCON_ADR
  436. mov r1, #0x01 /* PLL enable bit */
  437. str r1, [r0]
  438. ldr r0, PLLFEED_ADR /* start feed sequence */
  439. str r3, [r0]
  440. str r4, [r0] /* feed sequence done */
  441. /* Wait for the lock */
  442. ldr r0, PLLSTAT_ADR
  443. mov r1, #0x400 /* lock bit */
  444. lock_loop:
  445. ldr r2, [r0]
  446. and r2, r1, r2
  447. cmp r2, #0
  448. beq lock_loop
  449. /* And finally connect the PLL */
  450. ldr r0, PLLCON_ADR
  451. mov r1, #0x03 /* PLL enable bit and connect bit */
  452. str r1, [r0]
  453. ldr r0, PLLFEED_ADR /* start feed sequence */
  454. str r3, [r0]
  455. str r4, [r0] /* feed sequence done */
  456. /* Set-up VPBDIV register */
  457. ldr r0, VPBDIV_ADR
  458. mov r1, #0x01 /* VPB clock is same as process clock */
  459. str r1, [r0]
  460. #else
  461. #error No cpu_init_crit() defined for current CPU type
  462. #endif
  463. #ifdef CONFIG_ARM7_REVD
  464. /* set clock speed */
  465. /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */
  466. /* !!! not doing DRAM refresh properly! */
  467. ldr r0, SYSCON3
  468. ldr r1, [r0]
  469. bic r1, r1, #CLKCTL
  470. orr r1, r1, #CLKCTL_36
  471. str r1, [r0]
  472. #endif
  473. #ifndef CONFIG_LPC2292
  474. mov ip, lr
  475. /*
  476. * before relocating, we have to setup RAM timing
  477. * because memory timing is board-dependent, you will
  478. * find a lowlevel_init.S in your board directory.
  479. */
  480. bl lowlevel_init
  481. mov lr, ip
  482. #endif
  483. mov pc, lr
  484. /*
  485. *************************************************************************
  486. *
  487. * Interrupt handling
  488. *
  489. *************************************************************************
  490. */
  491. @
  492. @ IRQ stack frame.
  493. @
  494. #define S_FRAME_SIZE 72
  495. #define S_OLD_R0 68
  496. #define S_PSR 64
  497. #define S_PC 60
  498. #define S_LR 56
  499. #define S_SP 52
  500. #define S_IP 48
  501. #define S_FP 44
  502. #define S_R10 40
  503. #define S_R9 36
  504. #define S_R8 32
  505. #define S_R7 28
  506. #define S_R6 24
  507. #define S_R5 20
  508. #define S_R4 16
  509. #define S_R3 12
  510. #define S_R2 8
  511. #define S_R1 4
  512. #define S_R0 0
  513. #define MODE_SVC 0x13
  514. #define I_BIT 0x80
  515. /*
  516. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  517. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  518. */
  519. .macro bad_save_user_regs
  520. sub sp, sp, #S_FRAME_SIZE
  521. stmia sp, {r0 - r12} @ Calling r0-r12
  522. add r8, sp, #S_PC
  523. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  524. ldr r2, _armboot_start
  525. sub r2, r2, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
  526. sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
  527. #else
  528. ldr r2, IRQ_STACK_START_IN
  529. #endif
  530. ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
  531. add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
  532. add r5, sp, #S_SP
  533. mov r1, lr
  534. stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
  535. mov r0, sp
  536. .endm
  537. .macro irq_save_user_regs
  538. sub sp, sp, #S_FRAME_SIZE
  539. stmia sp, {r0 - r12} @ Calling r0-r12
  540. add r8, sp, #S_PC
  541. stmdb r8, {sp, lr}^ @ Calling SP, LR
  542. str lr, [r8, #0] @ Save calling PC
  543. mrs r6, spsr
  544. str r6, [r8, #4] @ Save CPSR
  545. str r0, [r8, #8] @ Save OLD_R0
  546. mov r0, sp
  547. .endm
  548. .macro irq_restore_user_regs
  549. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  550. mov r0, r0
  551. ldr lr, [sp, #S_PC] @ Get PC
  552. add sp, sp, #S_FRAME_SIZE
  553. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  554. .endm
  555. .macro get_bad_stack
  556. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  557. ldr r13, _armboot_start @ setup our mode stack
  558. sub r13, r13, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
  559. sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
  560. #else
  561. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  562. #endif
  563. str lr, [r13] @ save caller lr / spsr
  564. mrs lr, spsr
  565. str lr, [r13, #4]
  566. mov r13, #MODE_SVC @ prepare SVC-Mode
  567. msr spsr_c, r13
  568. mov lr, pc
  569. movs pc, lr
  570. .endm
  571. .macro get_irq_stack @ setup IRQ stack
  572. ldr sp, IRQ_STACK_START
  573. .endm
  574. .macro get_fiq_stack @ setup FIQ stack
  575. ldr sp, FIQ_STACK_START
  576. .endm
  577. /*
  578. * exception handlers
  579. */
  580. .align 5
  581. undefined_instruction:
  582. get_bad_stack
  583. bad_save_user_regs
  584. bl do_undefined_instruction
  585. .align 5
  586. software_interrupt:
  587. get_bad_stack
  588. bad_save_user_regs
  589. bl do_software_interrupt
  590. .align 5
  591. prefetch_abort:
  592. get_bad_stack
  593. bad_save_user_regs
  594. bl do_prefetch_abort
  595. .align 5
  596. data_abort:
  597. get_bad_stack
  598. bad_save_user_regs
  599. bl do_data_abort
  600. .align 5
  601. not_used:
  602. get_bad_stack
  603. bad_save_user_regs
  604. bl do_not_used
  605. #ifdef CONFIG_USE_IRQ
  606. .align 5
  607. irq:
  608. get_irq_stack
  609. irq_save_user_regs
  610. bl do_irq
  611. irq_restore_user_regs
  612. .align 5
  613. fiq:
  614. get_fiq_stack
  615. /* someone ought to write a more effiction fiq_save_user_regs */
  616. irq_save_user_regs
  617. bl do_fiq
  618. irq_restore_user_regs
  619. #else
  620. .align 5
  621. irq:
  622. get_bad_stack
  623. bad_save_user_regs
  624. bl do_irq
  625. .align 5
  626. fiq:
  627. get_bad_stack
  628. bad_save_user_regs
  629. bl do_fiq
  630. #endif
  631. #if defined(CONFIG_IMPA7) || defined(CONFIG_EP7312) || defined(CONFIG_ARMADILLO)
  632. .align 5
  633. .globl reset_cpu
  634. reset_cpu:
  635. mov ip, #0
  636. mcr p15, 0, ip, c7, c7, 0 @ invalidate cache
  637. mcr p15, 0, ip, c8, c7, 0 @ flush TLB (v4)
  638. mrc p15, 0, ip, c1, c0, 0 @ get ctrl register
  639. bic ip, ip, #0x000f @ ............wcam
  640. bic ip, ip, #0x2100 @ ..v....s........
  641. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  642. mov pc, r0
  643. #elif defined(CONFIG_NETARM)
  644. .align 5
  645. .globl reset_cpu
  646. reset_cpu:
  647. ldr r1, =NETARM_MEM_MODULE_BASE
  648. ldr r0, [r1, #+NETARM_MEM_CS0_BASE_ADDR]
  649. ldr r1, =0xFFFFF000
  650. and r0, r1, r0
  651. ldr r1, =(relocate-CONFIG_SYS_TEXT_BASE)
  652. add r0, r1, r0
  653. ldr r4, =NETARM_GEN_MODULE_BASE
  654. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  655. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  656. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  657. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  658. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  659. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  660. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  661. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  662. mov pc, r0
  663. #elif defined(CONFIG_S3C4510B)
  664. /* Nothing done here as reseting the CPU is board specific, depending
  665. * on external peripherals such as watchdog timers, etc. */
  666. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  667. /* No specific reset actions for IntegratorAP/CM720T as yet */
  668. #elif defined(CONFIG_LPC2292)
  669. .align 5
  670. .globl reset_cpu
  671. reset_cpu:
  672. mov pc, r0
  673. #else
  674. #error No reset_cpu() defined for current CPU type
  675. #endif