crtat91_boot.S 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. *
  32. */
  33. /*
  34. * $Log$
  35. * Revision 1.5 2009/01/16 19:45:42 haraldkipp
  36. * All ARM code is now running in system mode.
  37. *
  38. * Revision 1.4 2008/07/14 13:06:46 haraldkipp
  39. * Consistent chip selects and wait states.
  40. *
  41. * Revision 1.3 2008/03/17 10:14:44 haraldkipp
  42. * Reduced wait states for Flash access from 8 to 4.
  43. *
  44. * Revision 1.2 2006/10/05 17:12:35 haraldkipp
  45. * Bug #1497065 fixed. Stack sizes increased.
  46. *
  47. * Revision 1.1 2005/10/24 11:30:48 haraldkipp
  48. * Initial check in.
  49. *
  50. */
  51. #include <arch/arm.h>
  52. FLASH_BASE = 0x01000000
  53. FLASH_SIZE = 0x00200000
  54. RAM_BASE = 0x00000000
  55. RAM_LIMIT = 0x00000100
  56. RAM_SIZE = (256*1024)
  57. IRQ_STACK_SIZE = (128*4)
  58. FIQ_STACK_SIZE = (64*4)
  59. ABT_STACK_SIZE = (16*4)
  60. UND_STACK_SIZE = (16*4)
  61. /*
  62. * Section 0: Vector table and reset entry.
  63. */
  64. .section .init0,"ax",%progbits
  65. .global __vectors
  66. __vectors:
  67. ldr pc, [pc, #24] /* Reset */
  68. ldr pc, [pc, #24] /* Undefined instruction */
  69. ldr pc, [pc, #24] /* Software interrupt */
  70. ldr pc, [pc, #24] /* Prefetch abort */
  71. ldr pc, [pc, #24] /* Data abort */
  72. ldr pc, [pc, #24] /* Reserved */
  73. /*
  74. * On IRQ the PC will be loaded from AIC_IVR, which
  75. * provides the address previously set in AIC_SVR.
  76. * The interrupt routine will be called in ARM_MODE_IRQ
  77. * with IRQ disabled and FIQ unchanged.
  78. */
  79. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  80. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  81. .word _start
  82. .word __undef
  83. .word __swi
  84. .word __prefetch_abort
  85. .word __data_abort
  86. .weak __undef
  87. .set __undef, __xcpt_dummy
  88. .weak __swi
  89. .set __swi, __xcpt_dummy
  90. .weak __prefetch_abort
  91. .set __prefetch_abort, __xcpt_dummy
  92. .weak __data_abort
  93. .set __data_abort, __xcpt_dummy
  94. .global __xcpt_dummy
  95. __xcpt_dummy:
  96. b __xcpt_dummy
  97. _rom_start:
  98. .word 0x00000000
  99. _rom_end:
  100. .word 0x0003FFFC
  101. _ram_start:
  102. .word 0x00300000
  103. .ltorg
  104. .globl _start
  105. _start:
  106. /* Set supervisor mode. */
  107. mrs r0, cpsr
  108. bic r0, r0, #0x1f
  109. orr r0, r0, #0x13
  110. msr cpsr, r0
  111. /* Move code from ROM to RAM.
  112. * r0 = source address
  113. * r1 = target address
  114. * r2 = source end address
  115. */
  116. ldr r0, _rom_start
  117. ldr r1, _ram_start
  118. ldr r2, _rom_end
  119. _rom2ram:
  120. ldmia r0!, {r3-r10}
  121. stmia r1!, {r3-r10}
  122. cmp r0, r2
  123. ble _rom2ram
  124. /* Remapping memory. */
  125. adr r10, _rmap_tab
  126. /* Load the address where to jump */
  127. ldr r12, _rmap_endp
  128. ldmia r10!, {r0-r9,r11}
  129. stmia r11!, {r0-r9}
  130. /* Jump and break the pipeline */
  131. mov pc, r12
  132. _rmap_endp:
  133. .long remapmem_end
  134. _rmap_tab:
  135. /* Flash memory at 1000 0000. */
  136. .long 0x10000000 | EBI_CSEN | EBI_PAGES_16M | EBI_WSE | EBI_NWS_4 | EBI_DBW_16
  137. /* Ethernet controller at 2000 0000 */
  138. .long 0x20000000 | EBI_CSEN | EBI_BAT_BYTE_SELECT | EBI_PAGES_1M | EBI_WSE | EBI_NWS_3 | EBI_DBW_16
  139. /* CPLD registers at 2100 0000 */
  140. .long 0x21000000 | EBI_CSEN | EBI_PAGES_1M | EBI_WSE | EBI_NWS_2 | EBI_DBW_8
  141. .long 0x30000000 /* r3: unused */
  142. /* CPLD expansion port */
  143. .long 0x22000000 | EBI_CSEN | EBI_TDF_7 | EBI_WSE | EBI_NWS_8 | EBI_DBW_8
  144. .long 0x50000000 /* r5: unused */
  145. .long 0x60000000 /* r6: unused */
  146. .long 0x70000000 /* r7: unused */
  147. .long 0x00000001 /* r8: Remap command */
  148. .long EBI_ALE_4M /* r9: Memory control. */
  149. .long 0xFFE00000 /* r11: EBI base address */
  150. .ltorg
  151. remapmem_end:
  152. /*
  153. * Section 1: Hardware initialization.
  154. */
  155. .section .init1,"ax",%progbits
  156. /*
  157. * Enable all clocks.
  158. */
  159. mvn r0, #0
  160. ldr r1, =PS_BASE
  161. str r0, [r1, #0x04]
  162. /*
  163. * Initialize the interrupt controller.
  164. */
  165. add r0, pc,#-(8+.-__aic_table)
  166. ldmia r0, {r1-r4}
  167. str r4, [r1, #AIC_SPU]
  168. mov r0, #8
  169. L0:
  170. str r1, [r1, #AIC_EOICR]
  171. subs r0, r0, #1
  172. bhi L0
  173. str r2, [r1, #AIC_SVR(0)]
  174. add r1, r1, #AIC_SVR(0)
  175. mov r0, #31
  176. L1:
  177. str r3, [r1, r0, LSL #2]
  178. subs r0, r0, #1
  179. bhi L1
  180. b __set_stacks
  181. __aic_table:
  182. .word AIC_BASE
  183. .word __irq_dummy
  184. .word __irq_dummy
  185. .word __irq_dummy
  186. .ltorg
  187. /* Interrupt dummy. */
  188. .global __irq_dummy
  189. __irq_dummy:
  190. b __irq_dummy
  191. .global __set_stacks
  192. __set_stacks:
  193. /*
  194. * Section 2: Set stack pointers.
  195. */
  196. .section .init2,"ax",%progbits
  197. /*
  198. * Set exception stack pointers and enable interrupts.
  199. */
  200. ldr r0, =__xcp_stack
  201. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  202. mov r13, r0
  203. sub r0, r0, #FIQ_STACK_SIZE
  204. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  205. mov r13, r0
  206. sub r0, r0, #IRQ_STACK_SIZE
  207. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  208. mov r13, r0
  209. sub r0, r0, #ABT_STACK_SIZE
  210. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  211. mov r13, r0
  212. sub r0, r0, #UND_STACK_SIZE
  213. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  214. mov r13, r0
  215. b __enter_mode
  216. .rept 32
  217. .long 0
  218. .endr
  219. .global __xcp_stack
  220. __xcp_stack:
  221. .ltorg
  222. .global __enter_mode
  223. .align
  224. __enter_mode:
  225. /*
  226. * Section 3: Enter system mode.
  227. */
  228. .section .init3,"ax",%progbits
  229. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  230. b __clear_bss
  231. .ltorg
  232. .global __clear_bss
  233. __clear_bss:
  234. /*
  235. * Section 4: Clear bss.
  236. */
  237. .section .init4,"ax",%progbits
  238. ldr r1, =__bss_start
  239. ldr r2, =__bss_end
  240. ldr r3, =0
  241. _40:
  242. cmp r1, r2
  243. strne r3, [r1], #+4
  244. bne _40
  245. /*
  246. * Initialize user stack pointer.
  247. */
  248. ldr r13, =__stack
  249. b __call_rtos
  250. .ltorg
  251. .global __call_rtos
  252. __call_rtos:
  253. /*
  254. * Section 5: Call RTOS
  255. */
  256. .section .init5,"ax",%progbits
  257. /*
  258. * Jump to Nut/OS initialization.
  259. */
  260. ldr r0, =NutInit
  261. bx r0
  262. End:
  263. b End
  264. .ltorg