crtat91_httprom.S 9.8 KB

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