crtat91_rom.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Copyright (C) 2005-2006 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/01/16 00:19:41 olereinhardt
  42. * Changed backslash to slash in include path names
  43. *
  44. * Revision 1.2 2006/10/05 17:12:36 haraldkipp
  45. * Bug #1497065 fixed. Stack sizes increased.
  46. *
  47. * Revision 1.1 2006/08/01 07:34:16 haraldkipp
  48. * New linker script and new startup file support applications running in
  49. * flash memory.
  50. *
  51. */
  52. #include <arch/arm.h>
  53. IRQ_STACK_SIZE = (128*4)
  54. FIQ_STACK_SIZE = (64*4)
  55. ABT_STACK_SIZE = (16*4)
  56. UND_STACK_SIZE = (16*4)
  57. /* We start in ARM mode. */
  58. .arm
  59. /*
  60. * Section 0: Vector table and remapping.
  61. */
  62. .section .init0,"ax",%progbits
  63. /*
  64. * After reset these vectors are located at the beginning of
  65. * flash memory, which starts at address 0x00000000. After
  66. * remap, flash will be relocated at 0x10000000 and these
  67. * vectors are copied to the RAM base address, which will
  68. * be remapped to address 0x00000000.
  69. */
  70. .global __vectors
  71. __vectors:
  72. b _start /* Reset */
  73. ldr pc, [pc, #20] /* Undefined instruction */
  74. ldr pc, [pc, #20] /* Software interrupt */
  75. ldr pc, [pc, #20] /* Prefetch abort */
  76. ldr pc, [pc, #20] /* Data abort */
  77. ldr pc, [pc, #20] /* Reserved */
  78. /*
  79. * On IRQ the PC will be loaded from AIC_IVR, which
  80. * provides the address previously set in AIC_SVR.
  81. * The interrupt routine will be called in ARM_MODE_IRQ
  82. * with IRQ disabled and FIQ unchanged.
  83. */
  84. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  85. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  86. .word __undef
  87. .word __swi
  88. .word __prefetch_abort
  89. .word __data_abort
  90. .weak __undef
  91. .set __undef, __xcpt_dummy
  92. .weak __swi
  93. .set __swi, __xcpt_dummy
  94. .weak __prefetch_abort
  95. .set __prefetch_abort, __xcpt_dummy
  96. .weak __data_abort
  97. .set __data_abort, __xcpt_dummy
  98. /*
  99. * Exceptions are weakly linked to this endless loop.
  100. */
  101. .global __xcpt_dummy
  102. __xcpt_dummy:
  103. b __xcpt_dummy
  104. .ltorg
  105. .global _start
  106. _start:
  107. /*
  108. * Set supervisor mode.
  109. */
  110. mrs r0, cpsr
  111. bic r0, r0, #ARM_MODE_MASK
  112. orr r0, r0, #ARM_MODE_SVC
  113. msr cpsr, r0
  114. /*
  115. * Remapping memory.
  116. */
  117. adr r10, _rmap_tab /* Load remap table address. */
  118. ldr r12, _rmap_endp /* Load jump target. */
  119. ldmia r10!, {r0-r9,r11} /* Load the complete remap table plus EBI address. */
  120. stmia r11!, {r0-r9}
  121. mov pc, r12 /* Jump to remapped flash and break the pipeline */
  122. _rmap_endp:
  123. .long remapmem_end
  124. _rmap_tab:
  125. /*
  126. * Chip select NCS0 enables 16-bit Flash memory at 0x10000000.
  127. * We need 4 wait states.
  128. */
  129. .long 0x10000000 | EBI_CSEN | EBI_PAGES_16M | EBI_WSE | EBI_NWS_4 | EBI_DBW_16
  130. /*
  131. * Chip select NCS1 enables 16-bit Ethernet controller at 0x20000000.
  132. * We need 3 wait states.
  133. */
  134. .long 0x20000000 | EBI_CSEN | EBI_BAT_BYTE_SELECT | EBI_PAGES_1M | EBI_WSE | EBI_NWS_3 | EBI_DBW_16
  135. /*
  136. * Chip select NCS2 selects 8-bit NPL registers at 0x21000000.
  137. * The CPLD is quite fast and may run at one or zero wait states.
  138. * This pin is shared with GPIO pin 26.
  139. */
  140. .long 0x21000000 | EBI_CSEN | EBI_PAGES_1M | EBI_WSE | EBI_NWS_2 | EBI_DBW_8
  141. /*
  142. * Chip select NCS3 is not used.
  143. * This pin os shared with GPIO pin 27 and available at the expansion port.
  144. */
  145. .long 0x30000000
  146. /*
  147. * Chip select CS4 selects the 8-bit NPL expansion bus at 0x22000000.
  148. * This pin is shared with GPIO pin 31 and address bit 23.
  149. */
  150. .long 0x22000000 | EBI_CSEN | EBI_TDF_7 | EBI_PAGES_1M | EBI_WSE | EBI_NWS_8 | EBI_DBW_8
  151. /*
  152. * Chip select CS5 is not used.
  153. * This pin is shared with GPIO pin 30 and address bit 22.
  154. */
  155. .long 0x50000000
  156. /*
  157. * Chip select CS6 is not available, but used as address bit 21.
  158. */
  159. .long 0x60000000
  160. /*
  161. * Chip select CS7 is not available, but used as address bit 20.
  162. */
  163. .long 0x70000000
  164. /*
  165. * EBI remap command.
  166. */
  167. .long EBI_RCB
  168. /*
  169. * Maximum address space of 4 MBytes per chip select.
  170. * This occupies A0 to A21.
  171. */
  172. .long EBI_ALE_4M
  173. /*
  174. * EBI base address.
  175. */
  176. .long EBI_BASE
  177. remapmem_end:
  178. /*
  179. * Move vectors from Flash to RAM.
  180. */
  181. ldr r0, =__vectors
  182. mov r1, #0
  183. ldmia r0!, {r2-r9}
  184. stmia r1!, {r2-r9}
  185. ldmia r0!, {r2-r9}
  186. stmia r1!, {r2-r9}
  187. /* Jump to next section. */
  188. b __hw_init
  189. /* Literal pool of section 0. */
  190. .ltorg
  191. /*
  192. * Section 1: Hardware initialization.
  193. */
  194. .section .init1,"ax",%progbits
  195. .global __hw_init
  196. __hw_init:
  197. /*
  198. * Enable all clocks.
  199. */
  200. mvn r0, #0
  201. ldr r1, =PS_BASE
  202. str r0, [r1, #0x04]
  203. /*
  204. * Initialize the interrupt controller.
  205. */
  206. add r0, pc,#-(8+.-__aic_table)
  207. ldmia r0, {r1-r4}
  208. str r4, [r1, #AIC_SPU]
  209. mov r0, #8
  210. L0:
  211. str r1, [r1, #AIC_EOICR]
  212. subs r0, r0, #1
  213. bhi L0
  214. str r2, [r1, #AIC_SVR(0)]
  215. add r1, r1, #AIC_SVR(0)
  216. mov r0, #31
  217. L1:
  218. str r3, [r1, r0, LSL #2]
  219. subs r0, r0, #1
  220. bhi L1
  221. b __set_stacks
  222. __aic_table:
  223. .word AIC_BASE
  224. .word __irq_dummy
  225. .word __irq_dummy
  226. .word __irq_dummy
  227. .ltorg
  228. /* Interrupt dummy. */
  229. .global __irq_dummy
  230. __irq_dummy:
  231. b __irq_dummy
  232. /*
  233. * Section 2: Set stack pointers.
  234. */
  235. .section .init2,"ax",%progbits
  236. .global __set_stacks
  237. __set_stacks:
  238. /*
  239. * Set exception stack pointers and enable interrupts.
  240. */
  241. ldr r0, =0x00030000
  242. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  243. mov r13, r0
  244. sub r0, r0, #FIQ_STACK_SIZE
  245. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  246. mov r13, r0
  247. sub r0, r0, #IRQ_STACK_SIZE
  248. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  249. mov r13, r0
  250. sub r0, r0, #ABT_STACK_SIZE
  251. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  252. mov r13, r0
  253. sub r0, r0, #UND_STACK_SIZE
  254. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  255. mov r13, r0
  256. b __enter_mode
  257. .ltorg
  258. /*
  259. * Section 3: Enter system mode.
  260. */
  261. .section .init3,"ax",%progbits
  262. .global __enter_mode
  263. .align
  264. __enter_mode:
  265. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  266. b __crt_init
  267. .ltorg
  268. /*
  269. * Section 4: C runtime initialization.
  270. */
  271. .section .init4,"ax",%progbits
  272. .global __crt_init
  273. __crt_init:
  274. /*
  275. * Clear bss.
  276. */
  277. ldr r1, =__bss_start
  278. ldr r2, =__bss_end
  279. ldr r3, =0
  280. _40:
  281. cmp r1, r2
  282. strne r3, [r1], #+4
  283. bne _40
  284. /*
  285. * Copy data and RAM functions from Flash to RAM.
  286. */
  287. ldr r0, =_text_end
  288. ldr r1, =__data_start
  289. ldr r2, =__data_end
  290. subs r2, r2, r1
  291. beq _42
  292. _41:
  293. ldr r3, [r0], #4
  294. str r3, [r1], #4
  295. subs r2, r2, #4
  296. bne _41
  297. /*
  298. * Initialize user stack pointer.
  299. */
  300. _42:
  301. ldr r13, =__stack
  302. b __call_rtos
  303. .ltorg
  304. /*
  305. * Section 5: Call RTOS
  306. */
  307. .section .init5,"ax",%progbits
  308. .global __call_rtos
  309. __call_rtos:
  310. /*
  311. * Jump to Nut/OS initialization.
  312. */
  313. ldr r0, =NutInit
  314. bx r0
  315. End:
  316. ldr r0, =_start
  317. bx r0
  318. /* Literal pool of section 5. */
  319. .ltorg