crtat91_bootcrom.S 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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.2 2009/01/16 19:45:42 haraldkipp
  36. * All ARM code is now running in system mode.
  37. *
  38. * Revision 1.1 2008/07/14 13:04:27 haraldkipp
  39. * New Ethernut 3 link option with code in RAM and constant data in ROM.
  40. *
  41. */
  42. #include <arch/arm.h>
  43. FLASH_BASE = 0x01000000
  44. FLASH_SIZE = 0x00200000
  45. RAM_BASE = 0x00000000
  46. RAM_LIMIT = 0x00000100
  47. RAM_SIZE = (256*1024)
  48. IRQ_STACK_SIZE = (128*4)
  49. FIQ_STACK_SIZE = (64*4)
  50. ABT_STACK_SIZE = (16*4)
  51. UND_STACK_SIZE = (16*4)
  52. /*
  53. * Section 0: Vector table and reset entry.
  54. */
  55. .section .init0,"ax",%progbits
  56. .global __vectors
  57. __vectors:
  58. ldr pc, [pc, #24] /* Reset */
  59. ldr pc, [pc, #24] /* Undefined instruction */
  60. ldr pc, [pc, #24] /* Software interrupt */
  61. ldr pc, [pc, #24] /* Prefetch abort */
  62. ldr pc, [pc, #24] /* Data abort */
  63. ldr pc, [pc, #24] /* Reserved */
  64. /*
  65. * On IRQ the PC will be loaded from AIC_IVR, which
  66. * provides the address previously set in AIC_SVR.
  67. * The interrupt routine will be called in ARM_MODE_IRQ
  68. * with IRQ disabled and FIQ unchanged.
  69. */
  70. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  71. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  72. .word _start
  73. .word __undef
  74. .word __swi
  75. .word __prefetch_abort
  76. .word __data_abort
  77. .weak __undef
  78. .set __undef, __xcpt_dummy
  79. .weak __swi
  80. .set __swi, __xcpt_dummy
  81. .weak __prefetch_abort
  82. .set __prefetch_abort, __xcpt_dummy
  83. .weak __data_abort
  84. .set __data_abort, __xcpt_dummy
  85. .global __xcpt_dummy
  86. __xcpt_dummy:
  87. b __xcpt_dummy
  88. _rom_start:
  89. .word 0x00000000
  90. _rom_end:
  91. .word 0x0003FFFC
  92. _ram_start:
  93. .word 0x00300000
  94. .ltorg
  95. .globl _start
  96. _start:
  97. /* Set supervisor mode. */
  98. mrs r0, cpsr
  99. bic r0, r0, #0x1f
  100. orr r0, r0, #0x13
  101. msr cpsr, r0
  102. /* Move code from ROM to RAM.
  103. * r0 = source address
  104. * r1 = target address
  105. * r2 = source end address
  106. */
  107. ldr r0, _rom_start
  108. ldr r1, _ram_start
  109. ldr r2, _rom_end
  110. _rom2ram:
  111. ldmia r0!, {r3-r10}
  112. stmia r1!, {r3-r10}
  113. cmp r0, r2
  114. ble _rom2ram
  115. /* Remapping memory. */
  116. adr r10, _rmap_tab
  117. /* Load the address where to jump */
  118. ldr r12, _rmap_endp
  119. ldmia r10!, {r0-r9,r11}
  120. stmia r11!, {r0-r9}
  121. /* Jump and break the pipeline */
  122. mov pc, r12
  123. _rmap_endp:
  124. .long remapmem_end
  125. _rmap_tab:
  126. /* Flash memory at 1000 0000. */
  127. .long 0x10000000 | EBI_CSEN | EBI_PAGES_16M | EBI_WSE | EBI_NWS_4 | EBI_DBW_16
  128. /* Ethernet controller at 2000 0000 */
  129. .long 0x20000000 | EBI_CSEN | EBI_BAT_BYTE_SELECT | EBI_PAGES_1M | EBI_WSE | EBI_NWS_3 | EBI_DBW_16
  130. /* CPLD registers at 2100 0000 */
  131. .long 0x21000000 | EBI_CSEN | EBI_PAGES_1M | EBI_WSE | EBI_NWS_2 | EBI_DBW_8
  132. .long 0x30000000 /* r3: unused */
  133. /* CPLD expansion port */
  134. .long 0x22000000 | EBI_CSEN | EBI_TDF_7 | EBI_WSE | EBI_NWS_8 | EBI_DBW_8
  135. .long 0x50000000 /* r5: unused */
  136. .long 0x60000000 /* r6: unused */
  137. .long 0x70000000 /* r7: unused */
  138. .long 0x00000001 /* r8: Remap command */
  139. .long EBI_ALE_4M /* r9: Memory control. */
  140. .long 0xFFE00000 /* r11: EBI base address */
  141. .ltorg
  142. remapmem_end:
  143. /*
  144. * Section 1: Hardware initialization.
  145. */
  146. .section .init1,"ax",%progbits
  147. /*
  148. * Enable all clocks.
  149. */
  150. mvn r0, #0
  151. ldr r1, =PS_BASE
  152. str r0, [r1, #0x04]
  153. /*
  154. * Initialize the interrupt controller.
  155. */
  156. add r0, pc,#-(8+.-__aic_table)
  157. ldmia r0, {r1-r4}
  158. str r4, [r1, #AIC_SPU]
  159. mov r0, #8
  160. L0:
  161. str r1, [r1, #AIC_EOICR]
  162. subs r0, r0, #1
  163. bhi L0
  164. str r2, [r1, #AIC_SVR(0)]
  165. add r1, r1, #AIC_SVR(0)
  166. mov r0, #31
  167. L1:
  168. str r3, [r1, r0, LSL #2]
  169. subs r0, r0, #1
  170. bhi L1
  171. b __set_stacks
  172. __aic_table:
  173. .word AIC_BASE
  174. .word __irq_dummy
  175. .word __irq_dummy
  176. .word __irq_dummy
  177. .ltorg
  178. /* Interrupt dummy. */
  179. .global __irq_dummy
  180. __irq_dummy:
  181. b __irq_dummy
  182. .global __set_stacks
  183. __set_stacks:
  184. /*
  185. * Section 2: Set stack pointers.
  186. */
  187. .section .init2,"ax",%progbits
  188. /*
  189. * Set exception stack pointers and enable interrupts.
  190. */
  191. ldr r0, =__xcp_stack
  192. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  193. mov r13, r0
  194. sub r0, r0, #FIQ_STACK_SIZE
  195. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  196. mov r13, r0
  197. sub r0, r0, #IRQ_STACK_SIZE
  198. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  199. mov r13, r0
  200. sub r0, r0, #ABT_STACK_SIZE
  201. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  202. mov r13, r0
  203. sub r0, r0, #UND_STACK_SIZE
  204. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  205. mov r13, r0
  206. b __enter_mode
  207. .rept 32
  208. .long 0
  209. .endr
  210. .global __xcp_stack
  211. __xcp_stack:
  212. .ltorg
  213. .global __enter_mode
  214. .align
  215. __enter_mode:
  216. /*
  217. * Section 3: Enter system mode.
  218. */
  219. .section .init3,"ax",%progbits
  220. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  221. b __clear_bss
  222. .ltorg
  223. .global __clear_bss
  224. __clear_bss:
  225. /*
  226. * Section 4: Clear bss.
  227. */
  228. .section .init4,"ax",%progbits
  229. ldr r1, =__bss_start
  230. ldr r2, =__bss_end
  231. ldr r3, =0
  232. _40:
  233. cmp r1, r2
  234. strne r3, [r1], #+4
  235. bne _40
  236. /*
  237. * Initialize user stack pointer.
  238. */
  239. ldr r13, =__stack
  240. b __call_rtos
  241. .ltorg
  242. .global __call_rtos
  243. __call_rtos:
  244. /*
  245. * Section 5: Call RTOS
  246. */
  247. .section .init5,"ax",%progbits
  248. /*
  249. * Jump to Nut/OS initialization.
  250. */
  251. ldr r0, =NutInit
  252. bx r0
  253. End:
  254. b End
  255. .ltorg