start.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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 <asm-offsets.h>
  26. #include <config.h>
  27. #include <version.h>
  28. #include <asm/hardware.h>
  29. /*
  30. *************************************************************************
  31. *
  32. * Jump vector table as in table 3.1 in [1]
  33. *
  34. *************************************************************************
  35. */
  36. .globl _start
  37. _start: b reset
  38. ldr pc, _undefined_instruction
  39. ldr pc, _software_interrupt
  40. ldr pc, _prefetch_abort
  41. ldr pc, _data_abort
  42. #ifdef CONFIG_LPC2292
  43. .word 0xB4405F76 /* 2's complement of the checksum of the vectors */
  44. #else
  45. ldr pc, _not_used
  46. #endif
  47. ldr pc, _irq
  48. ldr pc, _fiq
  49. _undefined_instruction: .word undefined_instruction
  50. _software_interrupt: .word software_interrupt
  51. _prefetch_abort: .word prefetch_abort
  52. _data_abort: .word data_abort
  53. _not_used: .word not_used
  54. _irq: .word irq
  55. _fiq: .word fiq
  56. .balignl 16,0xdeadbeef
  57. /*
  58. *************************************************************************
  59. *
  60. * Startup Code (reset vector)
  61. *
  62. * do important init only if we don't start from RAM!
  63. * relocate armboot to ram
  64. * setup stack
  65. * jump to second stage
  66. *
  67. *************************************************************************
  68. */
  69. .globl _TEXT_BASE
  70. _TEXT_BASE:
  71. .word CONFIG_SYS_TEXT_BASE
  72. /*
  73. * These are defined in the board-specific linker script.
  74. * Subtracting _start from them lets the linker put their
  75. * relative position in the executable instead of leaving
  76. * them null.
  77. */
  78. .globl _bss_start_ofs
  79. _bss_start_ofs:
  80. .word __bss_start - _start
  81. .globl _bss_end_ofs
  82. _bss_end_ofs:
  83. .word __bss_end__ - _start
  84. .globl _end_ofs
  85. _end_ofs:
  86. .word _end - _start
  87. #ifdef CONFIG_USE_IRQ
  88. /* IRQ stack memory (calculated at run-time) */
  89. .globl IRQ_STACK_START
  90. IRQ_STACK_START:
  91. .word 0x0badc0de
  92. /* IRQ stack memory (calculated at run-time) */
  93. .globl FIQ_STACK_START
  94. FIQ_STACK_START:
  95. .word 0x0badc0de
  96. #endif
  97. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  98. .globl IRQ_STACK_START_IN
  99. IRQ_STACK_START_IN:
  100. .word 0x0badc0de
  101. /*
  102. * the actual reset code
  103. */
  104. reset:
  105. /*
  106. * set the cpu to SVC32 mode
  107. */
  108. mrs r0,cpsr
  109. bic r0,r0,#0x1f
  110. orr r0,r0,#0xd3
  111. msr cpsr,r0
  112. /*
  113. * we do sys-critical inits only at reboot,
  114. * not when booting from ram!
  115. */
  116. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  117. bl cpu_init_crit
  118. #endif
  119. #ifdef CONFIG_LPC2292
  120. bl lowlevel_init
  121. #endif
  122. /* Set stackpointer in internal RAM to call board_init_f */
  123. call_board_init_f:
  124. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  125. bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
  126. ldr r0,=0x00000000
  127. bl board_init_f
  128. /*------------------------------------------------------------------------------*/
  129. /*
  130. * void relocate_code (addr_sp, gd, addr_moni)
  131. *
  132. * This "function" does not return, instead it continues in RAM
  133. * after relocating the monitor code.
  134. *
  135. */
  136. .globl relocate_code
  137. relocate_code:
  138. mov r4, r0 /* save addr_sp */
  139. mov r5, r1 /* save addr of gd */
  140. mov r6, r2 /* save addr of destination */
  141. /* Set up the stack */
  142. stack_setup:
  143. mov sp, r4
  144. adr r0, _start
  145. cmp r0, r6
  146. beq clear_bss /* skip relocation */
  147. mov r1, r6 /* r1 <- scratch for copy_loop */
  148. ldr r3, _bss_start_ofs
  149. add r2, r0, r3 /* r2 <- source end address */
  150. copy_loop:
  151. ldmia r0!, {r9-r10} /* copy from source address [r0] */
  152. stmia r1!, {r9-r10} /* copy to target address [r1] */
  153. cmp r0, r2 /* until source end address [r2] */
  154. blo copy_loop
  155. #ifndef CONFIG_SPL_BUILD
  156. /*
  157. * fix .rel.dyn relocations
  158. */
  159. ldr r0, _TEXT_BASE /* r0 <- Text base */
  160. sub r9, r6, r0 /* r9 <- relocation offset */
  161. ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
  162. add r10, r10, r0 /* r10 <- sym table in FLASH */
  163. ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
  164. add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
  165. ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
  166. add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
  167. fixloop:
  168. ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
  169. add r0, r0, r9 /* r0 <- location to fix up in RAM */
  170. ldr r1, [r2, #4]
  171. and r7, r1, #0xff
  172. cmp r7, #23 /* relative fixup? */
  173. beq fixrel
  174. cmp r7, #2 /* absolute fixup? */
  175. beq fixabs
  176. /* ignore unknown type of fixup */
  177. b fixnext
  178. fixabs:
  179. /* absolute fix: set location to (offset) symbol value */
  180. mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
  181. add r1, r10, r1 /* r1 <- address of symbol in table */
  182. ldr r1, [r1, #4] /* r1 <- symbol value */
  183. add r1, r1, r9 /* r1 <- relocated sym addr */
  184. b fixnext
  185. fixrel:
  186. /* relative fix: increase location by offset */
  187. ldr r1, [r0]
  188. add r1, r1, r9
  189. fixnext:
  190. str r1, [r0]
  191. add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
  192. cmp r2, r3
  193. blo fixloop
  194. #endif
  195. clear_bss:
  196. #ifndef CONFIG_SPL_BUILD
  197. ldr r0, _bss_start_ofs
  198. ldr r1, _bss_end_ofs
  199. mov r4, r6 /* reloc addr */
  200. add r0, r0, r4
  201. add r1, r1, r4
  202. mov r2, #0x00000000 /* clear */
  203. clbss_l:str r2, [r0] /* clear loop... */
  204. add r0, r0, #4
  205. cmp r0, r1
  206. bne clbss_l
  207. bl coloured_LED_init
  208. bl red_led_on
  209. #endif
  210. /*
  211. * We are done. Do not return, instead branch to second part of board
  212. * initialization, now running from RAM.
  213. */
  214. ldr r0, _board_init_r_ofs
  215. adr r1, _start
  216. add lr, r0, r1
  217. add lr, lr, r9
  218. /* setup parameters for board_init_r */
  219. mov r0, r5 /* gd_t */
  220. mov r1, r6 /* dest_addr */
  221. /* jump to it ... */
  222. mov pc, lr
  223. _board_init_r_ofs:
  224. .word board_init_r - _start
  225. _rel_dyn_start_ofs:
  226. .word __rel_dyn_start - _start
  227. _rel_dyn_end_ofs:
  228. .word __rel_dyn_end - _start
  229. _dynsym_start_ofs:
  230. .word __dynsym_start - _start
  231. /*
  232. *************************************************************************
  233. *
  234. * CPU_init_critical registers
  235. *
  236. * setup important registers
  237. * setup memory timing
  238. *
  239. *************************************************************************
  240. */
  241. #if defined(CONFIG_LPC2292)
  242. PLLCFG_ADR: .word PLLCFG
  243. PLLFEED_ADR: .word PLLFEED
  244. PLLCON_ADR: .word PLLCON
  245. PLLSTAT_ADR: .word PLLSTAT
  246. VPBDIV_ADR: .word VPBDIV
  247. MEMMAP_ADR: .word MEMMAP
  248. #endif
  249. cpu_init_crit:
  250. #if defined(CONFIG_NETARM)
  251. /*
  252. * prior to software reset : need to set pin PORTC4 to be *HRESET
  253. */
  254. ldr r0, =NETARM_GEN_MODULE_BASE
  255. ldr r1, =(NETARM_GEN_PORT_MODE(0x10) | \
  256. NETARM_GEN_PORT_DIR(0x10))
  257. str r1, [r0, #+NETARM_GEN_PORTC]
  258. /*
  259. * software reset : see HW Ref. Guide 8.2.4 : Software Service register
  260. * for an explanation of this process
  261. */
  262. ldr r0, =NETARM_GEN_MODULE_BASE
  263. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  264. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  265. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  266. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  267. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  268. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  269. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  270. str r1, [r0, #+NETARM_GEN_SOFTWARE_SERVICE]
  271. /*
  272. * setup PLL and System Config
  273. */
  274. ldr r0, =NETARM_GEN_MODULE_BASE
  275. ldr r1, =( NETARM_GEN_SYS_CFG_LENDIAN | \
  276. NETARM_GEN_SYS_CFG_BUSFULL | \
  277. NETARM_GEN_SYS_CFG_USER_EN | \
  278. NETARM_GEN_SYS_CFG_ALIGN_ABORT | \
  279. NETARM_GEN_SYS_CFG_BUSARB_INT | \
  280. NETARM_GEN_SYS_CFG_BUSMON_EN )
  281. str r1, [r0, #+NETARM_GEN_SYSTEM_CONTROL]
  282. #ifndef CONFIG_NETARM_PLL_BYPASS
  283. ldr r1, =( NETARM_GEN_PLL_CTL_PLLCNT(NETARM_PLL_COUNT_VAL) | \
  284. NETARM_GEN_PLL_CTL_POLTST_DEF | \
  285. NETARM_GEN_PLL_CTL_INDIV(1) | \
  286. NETARM_GEN_PLL_CTL_ICP_DEF | \
  287. NETARM_GEN_PLL_CTL_OUTDIV(2) )
  288. str r1, [r0, #+NETARM_GEN_PLL_CONTROL]
  289. #endif
  290. /*
  291. * mask all IRQs by clearing all bits in the INTMRs
  292. */
  293. mov r1, #0
  294. ldr r0, =NETARM_GEN_MODULE_BASE
  295. str r1, [r0, #+NETARM_GEN_INTR_ENABLE]
  296. #elif defined(CONFIG_S3C4510B)
  297. /*
  298. * Mask off all IRQ sources
  299. */
  300. ldr r1, =REG_INTMASK
  301. ldr r0, =0x3FFFFF
  302. str r0, [r1]
  303. /*
  304. * Disable Cache
  305. */
  306. ldr r0, =REG_SYSCFG
  307. ldr r1, =0x83ffffa0 /* cache-disabled */
  308. str r1, [r0]
  309. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  310. /* No specific initialisation for IntegratorAP/CM720T as yet */
  311. #elif defined(CONFIG_LPC2292)
  312. /* Set-up PLL */
  313. mov r3, #0xAA
  314. mov r4, #0x55
  315. /* First disconnect and disable the PLL */
  316. ldr r0, PLLCON_ADR
  317. mov r1, #0x00
  318. str r1, [r0]
  319. ldr r0, PLLFEED_ADR /* start feed sequence */
  320. str r3, [r0]
  321. str r4, [r0] /* feed sequence done */
  322. /* Set new M and P values */
  323. ldr r0, PLLCFG_ADR
  324. mov r1, #0x23 /* M=4 and P=2 */
  325. str r1, [r0]
  326. ldr r0, PLLFEED_ADR /* start feed sequence */
  327. str r3, [r0]
  328. str r4, [r0] /* feed sequence done */
  329. /* Then enable the PLL */
  330. ldr r0, PLLCON_ADR
  331. mov r1, #0x01 /* PLL enable bit */
  332. str r1, [r0]
  333. ldr r0, PLLFEED_ADR /* start feed sequence */
  334. str r3, [r0]
  335. str r4, [r0] /* feed sequence done */
  336. /* Wait for the lock */
  337. ldr r0, PLLSTAT_ADR
  338. mov r1, #0x400 /* lock bit */
  339. lock_loop:
  340. ldr r2, [r0]
  341. and r2, r1, r2
  342. cmp r2, #0
  343. beq lock_loop
  344. /* And finally connect the PLL */
  345. ldr r0, PLLCON_ADR
  346. mov r1, #0x03 /* PLL enable bit and connect bit */
  347. str r1, [r0]
  348. ldr r0, PLLFEED_ADR /* start feed sequence */
  349. str r3, [r0]
  350. str r4, [r0] /* feed sequence done */
  351. /* Set-up VPBDIV register */
  352. ldr r0, VPBDIV_ADR
  353. mov r1, #0x01 /* VPB clock is same as process clock */
  354. str r1, [r0]
  355. #else
  356. #error No cpu_init_crit() defined for current CPU type
  357. #endif
  358. #ifdef CONFIG_ARM7_REVD
  359. /* set clock speed */
  360. /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */
  361. /* !!! not doing DRAM refresh properly! */
  362. ldr r0, SYSCON3
  363. ldr r1, [r0]
  364. bic r1, r1, #CLKCTL
  365. orr r1, r1, #CLKCTL_36
  366. str r1, [r0]
  367. #endif
  368. #ifndef CONFIG_LPC2292
  369. mov ip, lr
  370. /*
  371. * before relocating, we have to setup RAM timing
  372. * because memory timing is board-dependent, you will
  373. * find a lowlevel_init.S in your board directory.
  374. */
  375. bl lowlevel_init
  376. mov lr, ip
  377. #endif
  378. mov pc, lr
  379. /*
  380. *************************************************************************
  381. *
  382. * Interrupt handling
  383. *
  384. *************************************************************************
  385. */
  386. @
  387. @ IRQ stack frame.
  388. @
  389. #define S_FRAME_SIZE 72
  390. #define S_OLD_R0 68
  391. #define S_PSR 64
  392. #define S_PC 60
  393. #define S_LR 56
  394. #define S_SP 52
  395. #define S_IP 48
  396. #define S_FP 44
  397. #define S_R10 40
  398. #define S_R9 36
  399. #define S_R8 32
  400. #define S_R7 28
  401. #define S_R6 24
  402. #define S_R5 20
  403. #define S_R4 16
  404. #define S_R3 12
  405. #define S_R2 8
  406. #define S_R1 4
  407. #define S_R0 0
  408. #define MODE_SVC 0x13
  409. #define I_BIT 0x80
  410. /*
  411. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  412. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  413. */
  414. .macro bad_save_user_regs
  415. sub sp, sp, #S_FRAME_SIZE
  416. stmia sp, {r0 - r12} @ Calling r0-r12
  417. add r8, sp, #S_PC
  418. ldr r2, IRQ_STACK_START_IN
  419. ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
  420. add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
  421. add r5, sp, #S_SP
  422. mov r1, lr
  423. stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
  424. mov r0, sp
  425. .endm
  426. .macro irq_save_user_regs
  427. sub sp, sp, #S_FRAME_SIZE
  428. stmia sp, {r0 - r12} @ Calling r0-r12
  429. add r8, sp, #S_PC
  430. stmdb r8, {sp, lr}^ @ Calling SP, LR
  431. str lr, [r8, #0] @ Save calling PC
  432. mrs r6, spsr
  433. str r6, [r8, #4] @ Save CPSR
  434. str r0, [r8, #8] @ Save OLD_R0
  435. mov r0, sp
  436. .endm
  437. .macro irq_restore_user_regs
  438. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  439. mov r0, r0
  440. ldr lr, [sp, #S_PC] @ Get PC
  441. add sp, sp, #S_FRAME_SIZE
  442. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  443. .endm
  444. .macro get_bad_stack
  445. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  446. str lr, [r13] @ save caller lr / spsr
  447. mrs lr, spsr
  448. str lr, [r13, #4]
  449. mov r13, #MODE_SVC @ prepare SVC-Mode
  450. msr spsr_c, r13
  451. mov lr, pc
  452. movs pc, lr
  453. .endm
  454. .macro get_irq_stack @ setup IRQ stack
  455. ldr sp, IRQ_STACK_START
  456. .endm
  457. .macro get_fiq_stack @ setup FIQ stack
  458. ldr sp, FIQ_STACK_START
  459. .endm
  460. /*
  461. * exception handlers
  462. */
  463. .align 5
  464. undefined_instruction:
  465. get_bad_stack
  466. bad_save_user_regs
  467. bl do_undefined_instruction
  468. .align 5
  469. software_interrupt:
  470. get_bad_stack
  471. bad_save_user_regs
  472. bl do_software_interrupt
  473. .align 5
  474. prefetch_abort:
  475. get_bad_stack
  476. bad_save_user_regs
  477. bl do_prefetch_abort
  478. .align 5
  479. data_abort:
  480. get_bad_stack
  481. bad_save_user_regs
  482. bl do_data_abort
  483. .align 5
  484. not_used:
  485. get_bad_stack
  486. bad_save_user_regs
  487. bl do_not_used
  488. #ifdef CONFIG_USE_IRQ
  489. .align 5
  490. irq:
  491. get_irq_stack
  492. irq_save_user_regs
  493. bl do_irq
  494. irq_restore_user_regs
  495. .align 5
  496. fiq:
  497. get_fiq_stack
  498. /* someone ought to write a more effiction fiq_save_user_regs */
  499. irq_save_user_regs
  500. bl do_fiq
  501. irq_restore_user_regs
  502. #else
  503. .align 5
  504. irq:
  505. get_bad_stack
  506. bad_save_user_regs
  507. bl do_irq
  508. .align 5
  509. fiq:
  510. get_bad_stack
  511. bad_save_user_regs
  512. bl do_fiq
  513. #endif
  514. #if defined(CONFIG_NETARM)
  515. .align 5
  516. .globl reset_cpu
  517. reset_cpu:
  518. ldr r1, =NETARM_MEM_MODULE_BASE
  519. ldr r0, [r1, #+NETARM_MEM_CS0_BASE_ADDR]
  520. ldr r1, =0xFFFFF000
  521. and r0, r1, r0
  522. ldr r1, =(relocate-CONFIG_SYS_TEXT_BASE)
  523. add r0, r1, r0
  524. ldr r4, =NETARM_GEN_MODULE_BASE
  525. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  526. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  527. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  528. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  529. ldr r1, =NETARM_GEN_SW_SVC_RESETA
  530. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  531. ldr r1, =NETARM_GEN_SW_SVC_RESETB
  532. str r1, [r4, #+NETARM_GEN_SOFTWARE_SERVICE]
  533. mov pc, r0
  534. #elif defined(CONFIG_S3C4510B)
  535. /* Nothing done here as reseting the CPU is board specific, depending
  536. * on external peripherals such as watchdog timers, etc. */
  537. #elif defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_INTEGRATOR)
  538. /* No specific reset actions for IntegratorAP/CM720T as yet */
  539. #elif defined(CONFIG_LPC2292)
  540. .align 5
  541. .globl reset_cpu
  542. reset_cpu:
  543. mov pc, r0
  544. #else
  545. #error No reset_cpu() defined for current CPU type
  546. #endif