start_rom.S 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * Copyright (C) 2005-2007 by egnite Software GmbH
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. */
  35. /*
  36. * $Id: start_rom.S 2935 2010-04-01 12:14:17Z haraldkipp $
  37. */
  38. PS_BASE = 0xFFFF4000 /* Power saving controller. */
  39. AIC_BASE = 0xFFFFF000 /* Advanced interrupt controller. */
  40. AIC_SVR = 0x080 /* Source Vector Register */
  41. AIC_EOICR = 0x130 /* of Interrupt Command Register */
  42. AIC_SPU = 0x134 /* Spurious Vector Register */
  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 = (3*8*4) @ 3 words per interrupt priority level
  49. FIQ_STACK_SIZE = (3*4) @ 3 words
  50. ABT_STACK_SIZE = (1*4) @ 1 word
  51. UND_STACK_SIZE = (1*4) @ 1 word
  52. ARM_MODE_USER = 0x10
  53. ARM_MODE_FIQ = 0x11
  54. ARM_MODE_IRQ = 0x12
  55. ARM_MODE_SVC = 0x13
  56. ARM_MODE_ABORT = 0x17
  57. ARM_MODE_UNDEF = 0x1B
  58. ARM_MODE_SYS = 0x1F
  59. EBI_DBW_8 = 0x0002
  60. EBI_DBW_16 = 0x0001
  61. EBI_NWS_1 = 0x0000
  62. EBI_NWS_2 = 0x0004
  63. EBI_NWS_3 = 0x0008
  64. EBI_NWS_4 = 0x000C
  65. EBI_NWS_5 = 0x0010
  66. EBI_NWS_6 = 0x0014
  67. EBI_NWS_7 = 0x0018
  68. EBI_NWS_8 = 0x001C
  69. EBI_WSE = 0x0020
  70. EBI_PAGES_1M = 0x0000
  71. EBI_PAGES_4M = 0x0080
  72. EBI_PAGES_16M = 0x0100
  73. EBI_PAGES_64M = 0x0180
  74. EBI_TDF_0 = 0x0000
  75. EBI_TDF_1 = 0x0200
  76. EBI_TDF_2 = 0x0400
  77. EBI_TDF_3 = 0x0600
  78. EBI_TDF_4 = 0x0800
  79. EBI_TDF_5 = 0x0A00
  80. EBI_TDF_6 = 0x0C00
  81. EBI_TDF_7 = 0x0E00
  82. EBI_BAT_BYTE_WRITE = 0x0000
  83. EBI_BAT_BYTE_SELECT = 0x1000
  84. EBI_CSEN = 0x2000
  85. EBI_ALE_16M = 0x00
  86. EBI_ALE_8M = 0x04
  87. EBI_ALE_4M = 0x05
  88. EBI_ALE_2M = 0x06
  89. EBI_ALE_1M = 0x07
  90. EBI_DRP_STANDARD = 0x00
  91. EBI_DRP_EARLY = 0x10
  92. /*
  93. * Section 0: Vector table and reset entry.
  94. */
  95. .arm
  96. .section .init0,"ax",%progbits
  97. .global __vectors
  98. __vectors:
  99. b _start /* Reset */
  100. b __undef /* Undefined instruction */
  101. b __swi /* Software interrupt */
  102. b __prefetch_abort /* Prefetch abort */
  103. b __data_abort /* Data abort */
  104. b __xcpt_dummy /* Reserved */
  105. /*
  106. * On IRQ the PC will be loaded from AIC_IVR, which
  107. * provides the address previously set in AIC_SVR.
  108. * The interrupt routine will be called in ARM_MODE_IRQ
  109. * with IRQ disabled and FIQ unchanged.
  110. */
  111. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  112. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  113. .word _start
  114. .word __undef
  115. .word __swi
  116. .word __prefetch_abort
  117. .word __data_abort
  118. .weak __undef
  119. .set __undef, __xcpt_dummy
  120. .weak __swi
  121. .set __swi, __xcpt_dummy
  122. .weak __prefetch_abort
  123. .set __prefetch_abort, __xcpt_dummy
  124. .weak __data_abort
  125. .set __data_abort, __xcpt_dummy
  126. .global __xcpt_dummy
  127. __xcpt_dummy:
  128. b __xcpt_dummy
  129. _rom_start:
  130. .word 0x00000000
  131. _rom_end:
  132. .word 0x0003FFFC
  133. _ram_start:
  134. .word 0x00300000
  135. .ltorg
  136. .globl _start
  137. _start:
  138. /* Set supervisor mode. */
  139. mrs r0, cpsr
  140. bic r0, r0, #0x1f
  141. orr r0, r0, #0x13
  142. msr cpsr, r0
  143. /* Remapping memory. */
  144. adr r10, _rmap_tab
  145. /* Load the address where to jump */
  146. ldr r12, _rmap_endp
  147. ldmia r10!, {r0-r9,r11}
  148. stmia r11!, {r0-r9}
  149. /* Jump and break the pipeline */
  150. mov pc, r12
  151. _rmap_endp:
  152. .long remapmem_end
  153. _rmap_tab:
  154. /* Flash memory at 1000 0000. */
  155. .long 0x10000000 | EBI_CSEN | EBI_PAGES_16M | EBI_WSE | EBI_NWS_4 | EBI_DBW_16
  156. /* Ethernet controller at 2000 0000 */
  157. .long 0x20000000 | EBI_CSEN | EBI_BAT_BYTE_SELECT | EBI_WSE | EBI_NWS_3 | EBI_DBW_16
  158. /* CPLD registers at 2100 0000 */
  159. .long 0x21000000 | EBI_CSEN | EBI_WSE | EBI_NWS_2 | EBI_DBW_8
  160. .long 0x30000000 /* r3: unused */
  161. /* CPLD expansion port */
  162. .long 0x22000000 | EBI_CSEN | EBI_TDF_7 | EBI_WSE | EBI_NWS_8 | EBI_DBW_8
  163. .long 0x50000000 /* r5: unused */
  164. .long 0x60000000 /* r6: unused */
  165. .long 0x70000000 /* r7: unused */
  166. .long 0x00000001 /* r8: Remap command */
  167. .long EBI_ALE_4M /* r9: Memory control. */
  168. .long 0xFFE00000 /* r11: EBI base address */
  169. .ltorg
  170. remapmem_end:
  171. /*
  172. * Section 1: Hardware initialization.
  173. */
  174. .section .init1,"ax",%progbits
  175. /*
  176. * Enable all clocks.
  177. */
  178. mvn r0, #0
  179. ldr r1, =PS_BASE
  180. str r0, [r1, #0x04]
  181. /*
  182. * Initialize the interrupt controller.
  183. */
  184. add r0, pc,#-(8+.-__aic_table)
  185. ldmia r0, {r1-r4}
  186. str r4, [r1, #AIC_SPU]
  187. mov r0, #8
  188. L0:
  189. str r1, [r1, #AIC_EOICR]
  190. subs r0, r0, #1
  191. bhi L0
  192. str r2, [r1, #AIC_SVR]
  193. add r1, r1, #AIC_SVR
  194. mov r0, #31
  195. L1:
  196. str r3, [r1, r0, LSL #2]
  197. subs r0, r0, #1
  198. bhi L1
  199. b __set_stacks
  200. __aic_table:
  201. .word AIC_BASE
  202. .word __irq_dummy
  203. .word __irq_dummy
  204. .word __irq_dummy
  205. .ltorg
  206. /* Interrupt dummy. */
  207. .global __irq_dummy
  208. __irq_dummy:
  209. b __irq_dummy
  210. .global __set_stacks
  211. __set_stacks:
  212. /*
  213. * Section 2: Set stack pointers.
  214. */
  215. .section .init2,"ax",%progbits
  216. /*
  217. * Set exception stack pointers and enable interrupts.
  218. */
  219. ldr r0, =__xcp_stack
  220. msr CPSR_c, #ARM_MODE_FIQ | 0xC0
  221. mov r13, r0
  222. sub r0, r0, #FIQ_STACK_SIZE
  223. msr CPSR_c, #ARM_MODE_IRQ | 0xC0
  224. mov r13, r0
  225. sub r0, r0, #IRQ_STACK_SIZE
  226. msr CPSR_c, #ARM_MODE_ABORT | 0xC0
  227. mov r13, r0
  228. sub r0, r0, #ABT_STACK_SIZE
  229. msr CPSR_c, #ARM_MODE_UNDEF | 0xC0
  230. mov r13, r0
  231. sub r0, r0, #UND_STACK_SIZE
  232. msr CPSR_c, #ARM_MODE_SVC | 0xC0
  233. mov r13, r0
  234. b __enter_user
  235. .rept 32
  236. .long 0
  237. .endr
  238. .global __xcp_stack
  239. __xcp_stack:
  240. .ltorg
  241. .global __enter_user
  242. .align
  243. __enter_user:
  244. /*
  245. * Section 3: Enter user mode.
  246. */
  247. .section .init3,"ax",%progbits
  248. @ msr CPSR_c, #ARM_MODE_USER
  249. b __clear_bss
  250. .ltorg
  251. .global __clear_bss
  252. __clear_bss:
  253. /*
  254. * Section 4: Clear bss.
  255. */
  256. .section .init4,"ax",%progbits
  257. ldr r1, =__bss_start
  258. ldr r2, =__bss_end
  259. ldr r3, =0
  260. _40:
  261. cmp r1, r2
  262. strne r3, [r1], #+4
  263. bne _40
  264. ldr r0, =_text_end
  265. ldr r1, =__data_start
  266. ldr r2, =__data_end
  267. subs r2, r2, r1
  268. beq _42
  269. _41:
  270. ldr r3, [r0], #4
  271. str r3, [r1], #4
  272. subs r2, r2, #4
  273. bne _41
  274. /*
  275. * Initialize user stack pointer.
  276. */
  277. _42:
  278. ldr r13, =__stack
  279. b __call_rtos
  280. .ltorg
  281. .global __call_rtos
  282. __call_rtos:
  283. /*
  284. * Section 5: Call RTOS
  285. */
  286. .section .init5,"ax",%progbits
  287. /*
  288. * Jump to Nut/OS initialization.
  289. */
  290. ldr r0, =main
  291. bx r0
  292. End:
  293. ldr r0, =0
  294. bx r0
  295. .ltorg