start.S 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. /*
  28. *************************************************************************
  29. *
  30. * Jump vector table as in table 3.1 in [1]
  31. *
  32. *************************************************************************
  33. */
  34. .globl _start
  35. _start: b reset
  36. ldr pc, _undefined_instruction
  37. ldr pc, _software_interrupt
  38. ldr pc, _prefetch_abort
  39. ldr pc, _data_abort
  40. ldr pc, _not_used
  41. ldr pc, _irq
  42. ldr pc, _fiq
  43. _undefined_instruction: .word undefined_instruction
  44. _software_interrupt: .word software_interrupt
  45. _prefetch_abort: .word prefetch_abort
  46. _data_abort: .word data_abort
  47. _not_used: .word not_used
  48. _irq: .word irq
  49. _fiq: .word fiq
  50. .balignl 16,0xdeadbeef
  51. /*
  52. *************************************************************************
  53. *
  54. * Startup Code (reset vector)
  55. *
  56. * do important init only if we don't start from memory!
  57. * relocate armboot to ram
  58. * setup stack
  59. * jump to second stage
  60. *
  61. *************************************************************************
  62. */
  63. _TEXT_BASE:
  64. .word TEXT_BASE
  65. .globl _armboot_start
  66. _armboot_start:
  67. .word _start
  68. /*
  69. * Note: _armboot_end_data and _armboot_end are defined
  70. * by the (board-dependent) linker script.
  71. * _armboot_end_data is the first usable FLASH address after armboot
  72. */
  73. .globl _armboot_end_data
  74. _armboot_end_data:
  75. .word armboot_end_data
  76. .globl _armboot_end
  77. _armboot_end:
  78. .word armboot_end
  79. /*
  80. * _armboot_real_end is the first usable RAM address behind armboot
  81. * and the various stacks
  82. */
  83. .globl _armboot_real_end
  84. _armboot_real_end:
  85. .word 0x0badc0de
  86. #ifdef CONFIG_USE_IRQ
  87. /* IRQ stack memory (calculated at run-time) */
  88. .globl IRQ_STACK_START
  89. IRQ_STACK_START:
  90. .word 0x0badc0de
  91. /* IRQ stack memory (calculated at run-time) */
  92. .globl FIQ_STACK_START
  93. FIQ_STACK_START:
  94. .word 0x0badc0de
  95. #endif
  96. /*
  97. * the actual reset code
  98. */
  99. reset:
  100. /*
  101. * set the cpu to SVC32 mode
  102. */
  103. mrs r0,cpsr
  104. bic r0,r0,#0x1f
  105. orr r0,r0,#0x13
  106. msr cpsr,r0
  107. /*
  108. * we do sys-critical inits only at reboot,
  109. * not when booting from ram!
  110. */
  111. #ifdef CONFIG_INIT_CRITICAL
  112. bl cpu_init_crit
  113. #endif
  114. relocate:
  115. /*
  116. * relocate armboot to RAM
  117. */
  118. adr r0, _start /* r0 <- current position of code */
  119. ldr r2, _armboot_start
  120. ldr r3, _armboot_end
  121. sub r2, r3, r2 /* r2 <- size of armboot */
  122. ldr r1, _TEXT_BASE /* r1 <- destination address */
  123. add r2, r0, r2 /* r2 <- source end address */
  124. /*
  125. * r0 = source address
  126. * r1 = target address
  127. * r2 = source end address
  128. */
  129. copy_loop:
  130. ldmia r0!, {r3-r10}
  131. stmia r1!, {r3-r10}
  132. cmp r0, r2
  133. ble copy_loop
  134. /* set up the stack */
  135. ldr r0, _armboot_end
  136. add r0, r0, #CONFIG_STACKSIZE
  137. sub sp, r0, #12 /* leave 3 words for abort-stack */
  138. ldr pc, _start_armboot
  139. _start_armboot: .word start_armboot
  140. /*
  141. *************************************************************************
  142. *
  143. * CPU_init_critical registers
  144. *
  145. * setup important registers
  146. * setup memory timing
  147. *
  148. *************************************************************************
  149. */
  150. /* Interupt-Controller base addresses */
  151. INTMR1: .word 0x80000280 @ 32 bit size
  152. INTMR2: .word 0x80001280 @ 16 bit size
  153. INTMR3: .word 0x80002280 @ 8 bit size
  154. /* SYSCONs */
  155. SYSCON1: .word 0x80000100
  156. SYSCON2: .word 0x80001100
  157. SYSCON3: .word 0x80002200
  158. #define CLKCTL 0x6 /* mask */
  159. #define CLKCTL_18 0x0 /* 18.432 MHz */
  160. #define CLKCTL_36 0x2 /* 36.864 MHz */
  161. #define CLKCTL_49 0x4 /* 49.152 MHz */
  162. #define CLKCTL_73 0x6 /* 73.728 MHz */
  163. cpu_init_crit:
  164. /*
  165. * mask all IRQs by clearing all bits in the INTMRs
  166. */
  167. mov r1, #0x00
  168. ldr r0, INTMR1
  169. str r1, [r0]
  170. ldr r0, INTMR2
  171. str r1, [r0]
  172. ldr r0, INTMR3
  173. str r1, [r0]
  174. /*
  175. * flush v4 I/D caches
  176. */
  177. mov r0, #0
  178. mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
  179. mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
  180. /*
  181. * disable MMU stuff and caches
  182. */
  183. mrc p15,0,r0,c1,c0
  184. bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
  185. bic r0, r0, #0x0000008f @ clear bits 7, 3:0 (B--- WCAM)
  186. orr r0, r0, #0x00000002 @ set bit 2 (A) Align
  187. mcr p15,0,r0,c1,c0
  188. #ifdef CONFIG_ARM7_REVD
  189. /* set clock speed */
  190. /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */
  191. /* !!! not doing DRAM refresh properly! */
  192. ldr r0, SYSCON3
  193. ldr r1, [r0]
  194. bic r1, r1, #CLKCTL
  195. orr r1, r1, #CLKCTL_36
  196. str r1, [r0]
  197. #endif
  198. /*
  199. * before relocating, we have to setup RAM timing
  200. * because memory timing is board-dependend, you will
  201. * find a memsetup.S in your board directory.
  202. */
  203. mov ip, lr
  204. bl memsetup
  205. mov lr, ip
  206. mov pc, lr
  207. /*
  208. *************************************************************************
  209. *
  210. * Interrupt handling
  211. *
  212. *************************************************************************
  213. */
  214. @
  215. @ IRQ stack frame.
  216. @
  217. #define S_FRAME_SIZE 72
  218. #define S_OLD_R0 68
  219. #define S_PSR 64
  220. #define S_PC 60
  221. #define S_LR 56
  222. #define S_SP 52
  223. #define S_IP 48
  224. #define S_FP 44
  225. #define S_R10 40
  226. #define S_R9 36
  227. #define S_R8 32
  228. #define S_R7 28
  229. #define S_R6 24
  230. #define S_R5 20
  231. #define S_R4 16
  232. #define S_R3 12
  233. #define S_R2 8
  234. #define S_R1 4
  235. #define S_R0 0
  236. #define MODE_SVC 0x13
  237. #define I_BIT 0x80
  238. /*
  239. * use bad_save_user_regs for abort/prefetch/undef/swi ...
  240. * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
  241. */
  242. .macro bad_save_user_regs
  243. sub sp, sp, #S_FRAME_SIZE
  244. stmia sp, {r0 - r12} @ Calling r0-r12
  245. add r8, sp, #S_PC
  246. ldr r2, _armboot_end
  247. add r2, r2, #CONFIG_STACKSIZE
  248. sub r2, r2, #8
  249. ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
  250. add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
  251. add r5, sp, #S_SP
  252. mov r1, lr
  253. stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
  254. mov r0, sp
  255. .endm
  256. .macro irq_save_user_regs
  257. sub sp, sp, #S_FRAME_SIZE
  258. stmia sp, {r0 - r12} @ Calling r0-r12
  259. add r8, sp, #S_PC
  260. stmdb r8, {sp, lr}^ @ Calling SP, LR
  261. str lr, [r8, #0] @ Save calling PC
  262. mrs r6, spsr
  263. str r6, [r8, #4] @ Save CPSR
  264. str r0, [r8, #8] @ Save OLD_R0
  265. mov r0, sp
  266. .endm
  267. .macro irq_restore_user_regs
  268. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  269. mov r0, r0
  270. ldr lr, [sp, #S_PC] @ Get PC
  271. add sp, sp, #S_FRAME_SIZE
  272. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  273. .endm
  274. .macro get_bad_stack
  275. ldr r13, _armboot_end @ setup our mode stack
  276. add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack
  277. sub r13, r13, #8
  278. str lr, [r13] @ save caller lr / spsr
  279. mrs lr, spsr
  280. str lr, [r13, #4]
  281. mov r13, #MODE_SVC @ prepare SVC-Mode
  282. msr spsr_c, r13
  283. mov lr, pc
  284. movs pc, lr
  285. .endm
  286. .macro get_irq_stack @ setup IRQ stack
  287. ldr sp, IRQ_STACK_START
  288. .endm
  289. .macro get_fiq_stack @ setup FIQ stack
  290. ldr sp, FIQ_STACK_START
  291. .endm
  292. /*
  293. * exception handlers
  294. */
  295. .align 5
  296. undefined_instruction:
  297. get_bad_stack
  298. bad_save_user_regs
  299. bl do_undefined_instruction
  300. .align 5
  301. software_interrupt:
  302. get_bad_stack
  303. bad_save_user_regs
  304. bl do_software_interrupt
  305. .align 5
  306. prefetch_abort:
  307. get_bad_stack
  308. bad_save_user_regs
  309. bl do_prefetch_abort
  310. .align 5
  311. data_abort:
  312. get_bad_stack
  313. bad_save_user_regs
  314. bl do_data_abort
  315. .align 5
  316. not_used:
  317. get_bad_stack
  318. bad_save_user_regs
  319. bl do_not_used
  320. #ifdef CONFIG_USE_IRQ
  321. .align 5
  322. irq:
  323. get_irq_stack
  324. irq_save_user_regs
  325. bl do_irq
  326. irq_restore_user_regs
  327. .align 5
  328. fiq:
  329. get_fiq_stack
  330. /* someone ought to write a more effiction fiq_save_user_regs */
  331. irq_save_user_regs
  332. bl do_fiq
  333. irq_restore_user_regs
  334. #else
  335. .align 5
  336. irq:
  337. get_bad_stack
  338. bad_save_user_regs
  339. bl do_irq
  340. .align 5
  341. fiq:
  342. get_bad_stack
  343. bad_save_user_regs
  344. bl do_fiq
  345. #endif
  346. .align 5
  347. .globl reset_cpu
  348. reset_cpu:
  349. mov ip, #0
  350. mcr p15, 0, ip, c7, c7, 0 @ invalidate cache
  351. mcr p15, 0, ip, c8, c7, 0 @ flush TLB (v4)
  352. mrc p15, 0, ip, c1, c0, 0 @ get ctrl register
  353. bic ip, ip, #0x000f @ ............wcam
  354. bic ip, ip, #0x2100 @ ..v....s........
  355. mcr p15, 0, ip, c1, c0, 0 @ ctrl register
  356. mov pc, r0