start.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * armboot - Startup Code for XScale
  3. *
  4. * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
  5. * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
  6. * Copyright (C) 2000 Wolfgang Denk <wd@denx.de>
  7. * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de>
  8. * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net>
  9. * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>
  10. * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <config.h>
  31. #include <version.h>
  32. #include <asm/arch/pxa-regs.h>
  33. #include <asm/arch/macro.h>
  34. /* takes care the CP15 update has taken place */
  35. .macro CPWAIT reg
  36. mrc p15,0,\reg,c2,c0,0
  37. mov \reg,\reg
  38. sub pc,pc,#4
  39. .endm
  40. .globl _start
  41. _start: b reset
  42. #ifdef CONFIG_PRELOADER
  43. ldr pc, _hang
  44. ldr pc, _hang
  45. ldr pc, _hang
  46. ldr pc, _hang
  47. ldr pc, _hang
  48. ldr pc, _hang
  49. ldr pc, _hang
  50. _hang:
  51. .word do_hang
  52. .word 0x12345678
  53. .word 0x12345678
  54. .word 0x12345678
  55. .word 0x12345678
  56. .word 0x12345678
  57. .word 0x12345678
  58. .word 0x12345678 /* now 16*4=64 */
  59. #else
  60. ldr pc, _undefined_instruction
  61. ldr pc, _software_interrupt
  62. ldr pc, _prefetch_abort
  63. ldr pc, _data_abort
  64. ldr pc, _not_used
  65. ldr pc, _irq
  66. ldr pc, _fiq
  67. _undefined_instruction: .word undefined_instruction
  68. _software_interrupt: .word software_interrupt
  69. _prefetch_abort: .word prefetch_abort
  70. _data_abort: .word data_abort
  71. _not_used: .word not_used
  72. _irq: .word irq
  73. _fiq: .word fiq
  74. #endif /* CONFIG_PRELOADER */
  75. .balignl 16,0xdeadbeef
  76. /*
  77. * Startup Code (reset vector)
  78. *
  79. * do important init only if we don't start from RAM!
  80. * - relocate armboot to RAM
  81. * - setup stack
  82. * - jump to second stage
  83. */
  84. .globl _TEXT_BASE
  85. _TEXT_BASE:
  86. .word CONFIG_SYS_TEXT_BASE
  87. .globl _armboot_start
  88. _armboot_start:
  89. .word _start
  90. /*
  91. * These are defined in the board-specific linker script.
  92. */
  93. .globl _bss_start
  94. _bss_start:
  95. .word __bss_start
  96. .globl _bss_end
  97. _bss_end:
  98. .word _end
  99. #ifdef CONFIG_USE_IRQ
  100. /* IRQ stack memory (calculated at run-time) */
  101. .globl IRQ_STACK_START
  102. IRQ_STACK_START:
  103. .word 0x0badc0de
  104. /* IRQ stack memory (calculated at run-time) */
  105. .globl FIQ_STACK_START
  106. FIQ_STACK_START:
  107. .word 0x0badc0de
  108. #endif /* CONFIG_USE_IRQ */
  109. #ifndef CONFIG_PRELOADER
  110. /* IRQ stack memory (calculated at run-time) + 8 bytes */
  111. .globl IRQ_STACK_START_IN
  112. IRQ_STACK_START_IN:
  113. .word 0x0badc0de
  114. .globl _datarel_start
  115. _datarel_start:
  116. .word __datarel_start
  117. .globl _datarelrolocal_start
  118. _datarelrolocal_start:
  119. .word __datarelrolocal_start
  120. .globl _datarellocal_start
  121. _datarellocal_start:
  122. .word __datarellocal_start
  123. .globl _datarelro_start
  124. _datarelro_start:
  125. .word __datarelro_start
  126. .globl _got_start
  127. _got_start:
  128. .word __got_start
  129. .globl _got_end
  130. _got_end:
  131. .word __got_end
  132. /*
  133. * the actual reset code
  134. */
  135. reset:
  136. /*
  137. * set the cpu to SVC32 mode
  138. */
  139. mrs r0,cpsr
  140. bic r0,r0,#0x1f
  141. orr r0,r0,#0xd3
  142. msr cpsr,r0
  143. /*
  144. * Enable MMU to use DCache as DRAM
  145. */
  146. /* Domain access -- enable for all CPs */
  147. ldr r0, =0x0000ffff
  148. mcr p15, 0, r0, c3, c0, 0
  149. /* Point TTBR to MMU table */
  150. ldr r0, =mmu_table
  151. adr r2, _start
  152. orr r0, r2
  153. mcr p15, 0, r0, c2, c0, 0
  154. /* !!! Hereby, check if the code is running from SRAM !!! */
  155. /* If the code is running from SRAM, alias SRAM to 0x0 to simulate NOR. The code
  156. * is linked to 0x0 too, so this makes things easier. */
  157. cmp r2, #0x5c000000
  158. ldreq r1, [r0]
  159. orreq r1, r2
  160. streq r1, [r0]
  161. /* Kick in MMU, ICache, DCache, BTB */
  162. mrc p15, 0, r0, c1, c0, 0
  163. bic r0, #0x1b00
  164. bic r0, #0x0087
  165. orr r0, #0x1800
  166. orr r0, #0x0005
  167. mcr p15, 0, r0, c1, c0, 0
  168. CPWAIT r0
  169. /* Unlock Icache, Dcache */
  170. mcr p15, 0, r0, c9, c1, 1
  171. mcr p15, 0, r0, c9, c2, 1
  172. /* Flush Icache, Dcache, BTB */
  173. mcr p15, 0, r0, c7, c7, 0
  174. /* Unlock I-TLB, D-TLB */
  175. mcr p15, 0, r0, c10, c4, 1
  176. mcr p15, 0, r0, c10, c8, 1
  177. /* Flush TLB */
  178. mcr p15, 0, r0, c8, c7, 0
  179. /* Allocate 4096 bytes of Dcache as RAM */
  180. /* Drain pending loads and stores */
  181. mcr p15, 0, r0, c7, c10, 4
  182. mov r4, #0x00
  183. mov r5, #0x00
  184. mov r2, #0x01
  185. mcr p15, 0, r0, c9, c2, 0
  186. CPWAIT r0
  187. /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */
  188. mov r0, #128
  189. mov r1, #0xa0000000
  190. alloc:
  191. mcr p15, 0, r1, c7, c2, 5
  192. /* Drain pending loads and stores */
  193. mcr p15, 0, r0, c7, c10, 4
  194. strd r4, [r1], #8
  195. strd r4, [r1], #8
  196. strd r4, [r1], #8
  197. strd r4, [r1], #8
  198. subs r0, #0x01
  199. bne alloc
  200. /* Drain pending loads and stores */
  201. mcr p15, 0, r0, c7, c10, 4
  202. mov r2, #0x00
  203. mcr p15, 0, r2, c9, c2, 0
  204. CPWAIT r0
  205. /* Jump to 0x0 ( + offset) if running from SRAM */
  206. adr r0, zerojmp
  207. bic r0, #0x5c000000
  208. mov pc, r0
  209. zerojmp:
  210. /* Set stackpointer in internal RAM to call board_init_f */
  211. call_board_init_f:
  212. ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
  213. ldr r0,=0x00000000
  214. bl board_init_f
  215. /*------------------------------------------------------------------------------*/
  216. /*
  217. * void relocate_code (addr_sp, gd, addr_moni)
  218. *
  219. * This "function" does not return, instead it continues in RAM
  220. * after relocating the monitor code.
  221. *
  222. */
  223. .globl relocate_code
  224. relocate_code:
  225. mov r4, r0 /* save addr_sp */
  226. mov r5, r1 /* save addr of gd */
  227. mov r6, r2 /* save addr of destination */
  228. mov r7, r2 /* save addr of destination */
  229. /* Set up the stack */
  230. stack_setup:
  231. mov sp, r4
  232. adr r0, _start
  233. ldr r2, _TEXT_BASE
  234. ldr r3, _bss_start
  235. sub r2, r3, r2 /* r2 <- size of armboot */
  236. add r2, r0, r2 /* r2 <- source end address */
  237. cmp r0, r6
  238. beq clear_bss
  239. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  240. stmfd sp!, {r0-r12}
  241. copy_loop:
  242. ldmia r0!, {r3-r5, r7-r11} /* copy from source address [r0] */
  243. stmia r6!, {r3-r5, r7-r11} /* copy to target address [r1] */
  244. cmp r0, r2 /* until source end address [r2] */
  245. blo copy_loop
  246. ldmfd sp!, {r0-r12}
  247. #ifndef CONFIG_PRELOADER
  248. /* fix got entries */
  249. ldr r1, _TEXT_BASE /* Text base */
  250. mov r0, r7 /* reloc addr */
  251. ldr r2, _got_start /* addr in Flash */
  252. ldr r3, _got_end /* addr in Flash */
  253. sub r3, r3, r1
  254. add r3, r3, r0
  255. sub r2, r2, r1
  256. add r2, r2, r0
  257. fixloop:
  258. ldr r4, [r2]
  259. sub r4, r4, r1
  260. add r4, r4, r0
  261. str r4, [r2]
  262. add r2, r2, #4
  263. cmp r2, r3
  264. bne fixloop
  265. #endif
  266. #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
  267. clear_bss:
  268. #ifndef CONFIG_PRELOADER
  269. ldr r0, _bss_start
  270. ldr r1, _bss_end
  271. ldr r3, _TEXT_BASE /* Text base */
  272. mov r4, r7 /* reloc addr */
  273. sub r0, r0, r3
  274. add r0, r0, r4
  275. sub r1, r1, r3
  276. add r1, r1, r4
  277. mov r2, #0x00000000 /* clear */
  278. clbss_l:str r2, [r0] /* clear loop... */
  279. add r0, r0, #4
  280. cmp r0, r1
  281. bne clbss_l
  282. #endif
  283. /*
  284. * We are done. Do not return, instead branch to second part of board
  285. * initialization, now running from RAM.
  286. */
  287. #ifdef CONFIG_ONENAND_IPL
  288. ldr pc, _start_oneboot
  289. _start_oneboot: .word start_oneboot
  290. #else
  291. ldr r0, _TEXT_BASE
  292. ldr r2, _board_init_r
  293. sub r2, r2, r0
  294. add r2, r2, r7 /* position from board_init_r in RAM */
  295. /* setup parameters for board_init_r */
  296. mov r0, r5 /* gd_t */
  297. mov r1, r7 /* dest_addr */
  298. /* jump to it ... */
  299. mov lr, r2
  300. mov pc, lr
  301. _board_init_r: .word board_init_r
  302. #endif
  303. #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
  304. /****************************************************************************/
  305. /* */
  306. /* the actual reset code for OneNAND IPL */
  307. /* */
  308. /****************************************************************************/
  309. #ifndef CONFIG_PXA27X
  310. #error OneNAND IPL is not supported on PXA25x and 26x due to lack of SRAM
  311. #endif
  312. reset:
  313. /* Set CPU to SVC32 mode */
  314. mrs r0,cpsr
  315. bic r0,r0,#0x1f
  316. orr r0,r0,#0x13
  317. msr cpsr,r0
  318. /* Point stack at the end of SRAM and leave 32 words for abort-stack */
  319. ldr sp, =0x5c03ff80
  320. /* Start OneNAND IPL */
  321. ldr pc, =start_oneboot
  322. #endif /* #if !defined(CONFIG_ONENAND_IPL) */
  323. #ifndef CONFIG_PRELOADER
  324. /****************************************************************************/
  325. /* */
  326. /* Interrupt handling */
  327. /* */
  328. /****************************************************************************/
  329. /* IRQ stack frame */
  330. #define S_FRAME_SIZE 72
  331. #define S_OLD_R0 68
  332. #define S_PSR 64
  333. #define S_PC 60
  334. #define S_LR 56
  335. #define S_SP 52
  336. #define S_IP 48
  337. #define S_FP 44
  338. #define S_R10 40
  339. #define S_R9 36
  340. #define S_R8 32
  341. #define S_R7 28
  342. #define S_R6 24
  343. #define S_R5 20
  344. #define S_R4 16
  345. #define S_R3 12
  346. #define S_R2 8
  347. #define S_R1 4
  348. #define S_R0 0
  349. #define MODE_SVC 0x13
  350. /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
  351. .macro bad_save_user_regs
  352. sub sp, sp, #S_FRAME_SIZE
  353. stmia sp, {r0 - r12} /* Calling r0-r12 */
  354. add r8, sp, #S_PC
  355. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  356. ldr r2, _armboot_start
  357. sub r2, r2, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
  358. sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
  359. #else
  360. ldr r2, IRQ_STACK_START_IN
  361. #endif
  362. ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
  363. add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
  364. add r5, sp, #S_SP
  365. mov r1, lr
  366. stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
  367. mov r0, sp
  368. .endm
  369. /* use irq_save_user_regs / irq_restore_user_regs for */
  370. /* IRQ/FIQ handling */
  371. .macro irq_save_user_regs
  372. sub sp, sp, #S_FRAME_SIZE
  373. stmia sp, {r0 - r12} /* Calling r0-r12 */
  374. add r8, sp, #S_PC
  375. stmdb r8, {sp, lr}^ /* Calling SP, LR */
  376. str lr, [r8, #0] /* Save calling PC */
  377. mrs r6, spsr
  378. str r6, [r8, #4] /* Save CPSR */
  379. str r0, [r8, #8] /* Save OLD_R0 */
  380. mov r0, sp
  381. .endm
  382. .macro irq_restore_user_regs
  383. ldmia sp, {r0 - lr}^ @ Calling r0 - lr
  384. mov r0, r0
  385. ldr lr, [sp, #S_PC] @ Get PC
  386. add sp, sp, #S_FRAME_SIZE
  387. subs pc, lr, #4 @ return & move spsr_svc into cpsr
  388. .endm
  389. .macro get_bad_stack
  390. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  391. ldr r13, _armboot_start @ setup our mode stack
  392. sub r13, r13, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
  393. sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
  394. #else
  395. ldr r13, IRQ_STACK_START_IN @ setup our mode stack
  396. #endif
  397. str lr, [r13] @ save caller lr / spsr
  398. mrs lr, spsr
  399. str lr, [r13, #4]
  400. mov r13, #MODE_SVC @ prepare SVC-Mode
  401. msr spsr_c, r13
  402. mov lr, pc
  403. movs pc, lr
  404. .endm
  405. .macro get_irq_stack @ setup IRQ stack
  406. ldr sp, IRQ_STACK_START
  407. .endm
  408. .macro get_fiq_stack @ setup FIQ stack
  409. ldr sp, FIQ_STACK_START
  410. .endm
  411. #endif /* CONFIG_PRELOADER */
  412. /****************************************************************************/
  413. /* */
  414. /* exception handlers */
  415. /* */
  416. /****************************************************************************/
  417. #ifdef CONFIG_PRELOADER
  418. .align 5
  419. do_hang:
  420. ldr sp, _TEXT_BASE /* use 32 words abort stack */
  421. bl hang /* hang and never return */
  422. #else /* !CONFIG_PRELOADER */
  423. .align 5
  424. undefined_instruction:
  425. get_bad_stack
  426. bad_save_user_regs
  427. bl do_undefined_instruction
  428. .align 5
  429. software_interrupt:
  430. get_bad_stack
  431. bad_save_user_regs
  432. bl do_software_interrupt
  433. .align 5
  434. prefetch_abort:
  435. get_bad_stack
  436. bad_save_user_regs
  437. bl do_prefetch_abort
  438. .align 5
  439. data_abort:
  440. get_bad_stack
  441. bad_save_user_regs
  442. bl do_data_abort
  443. .align 5
  444. not_used:
  445. get_bad_stack
  446. bad_save_user_regs
  447. bl do_not_used
  448. #ifdef CONFIG_USE_IRQ
  449. .align 5
  450. irq:
  451. get_irq_stack
  452. irq_save_user_regs
  453. bl do_irq
  454. irq_restore_user_regs
  455. .align 5
  456. fiq:
  457. get_fiq_stack
  458. irq_save_user_regs /* someone ought to write a more */
  459. bl do_fiq /* effiction fiq_save_user_regs */
  460. irq_restore_user_regs
  461. #else /* !CONFIG_USE_IRQ */
  462. .align 5
  463. irq:
  464. get_bad_stack
  465. bad_save_user_regs
  466. bl do_irq
  467. .align 5
  468. fiq:
  469. get_bad_stack
  470. bad_save_user_regs
  471. bl do_fiq
  472. #endif /* CONFIG_PRELOADER */
  473. #endif /* CONFIG_USE_IRQ */
  474. /****************************************************************************/
  475. /* */
  476. /* Reset function: the PXA250 doesn't have a reset function, so we have to */
  477. /* perform a watchdog timeout for a soft reset. */
  478. /* */
  479. /****************************************************************************/
  480. /* Operating System Timer */
  481. OSTIMER_BASE: .word 0x40a00000
  482. #define OSMR3 0x0C
  483. #define OSCR 0x10
  484. #define OWER 0x18
  485. #define OIER 0x1C
  486. .align 5
  487. .globl reset_cpu
  488. /* FIXME: this code is PXA250 specific. How is this handled on */
  489. /* other XScale processors? */
  490. reset_cpu:
  491. /* We set OWE:WME (watchdog enable) and wait until timeout happens */
  492. ldr r0, OSTIMER_BASE
  493. ldr r1, [r0, #OWER]
  494. orr r1, r1, #0x0001 /* bit0: WME */
  495. str r1, [r0, #OWER]
  496. /* OS timer does only wrap every 1165 seconds, so we have to set */
  497. /* the match register as well. */
  498. ldr r1, [r0, #OSCR] /* read OS timer */
  499. add r1, r1, #0x800 /* let OSMR3 match after */
  500. add r1, r1, #0x800 /* 4096*(1/3.6864MHz)=1ms */
  501. str r1, [r0, #OSMR3]
  502. reset_endless:
  503. b reset_endless
  504. #ifndef CONFIG_PRELOADER
  505. .section .mmudata, "a"
  506. .align 14
  507. .globl mmu_table
  508. mmu_table:
  509. /* 0x00000000 - 0xa0000000 : 1:1, uncached mapping */
  510. .set __base, 0
  511. .rept 0xa00
  512. .word (__base << 20) | 0xc12
  513. .set __base, __base + 1
  514. .endr
  515. /* 0xa0000000 - 0xa0100000 : 1:1, cached mapping */
  516. .word (0xa00 << 20) | 0x1c1e
  517. .set __base, 0xa01
  518. .rept 0x1000 - 0xa01
  519. .word (__base << 20) | 0xc12
  520. .set __base, __base + 1
  521. .endr
  522. #endif