crteb40a_ram.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (C) 2004 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.3 2009/01/16 19:45:42 haraldkipp
  36. * All ARM code is now running in system mode.
  37. *
  38. * Revision 1.2 2006/10/05 17:12:36 haraldkipp
  39. * Bug #1497065 fixed. Stack sizes increased.
  40. *
  41. * Revision 1.1 2004/09/19 12:37:42 haraldkipp
  42. * ARM7 initialization added
  43. *
  44. */
  45. #include <arch/arm.h>
  46. AIC_SVR = 0x080 /* Source Vector Register */
  47. FLASH_BASE = 0x01000000
  48. FLASH_SIZE = 0x00200000
  49. RAM_BASE = 0x00000000
  50. RAM_LIMIT = 0x00000100
  51. RAM_SIZE = (256*1024)
  52. IRQ_STACK_SIZE = (128*4)
  53. FIQ_STACK_SIZE = (64*4)
  54. ABT_STACK_SIZE = (16*4)
  55. UND_STACK_SIZE = (16*4)
  56. /*
  57. * Section 0: Vector table and reset entry.
  58. */
  59. .section .init0,"ax",%progbits
  60. .global __vectors
  61. __vectors:
  62. ldr pc, [pc, #24] /* Reset */
  63. ldr pc, [pc, #24] /* Undefined instruction */
  64. ldr pc, [pc, #24] /* Software interrupt */
  65. ldr pc, [pc, #24] /* Prefetch abort */
  66. ldr pc, [pc, #24] /* Data abort */
  67. ldr pc, [pc, #24] /* Reserved */
  68. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  69. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  70. .word _start
  71. .word __undef
  72. .word __swi
  73. .word __prefetch_abort
  74. .word __data_abort
  75. .weak __undef
  76. .set __undef, __xcpt_dummy
  77. .weak __swi
  78. .set __swi, __xcpt_dummy
  79. .weak __prefetch_abort
  80. .set __prefetch_abort, __xcpt_dummy
  81. .weak __data_abort
  82. .set __data_abort, __xcpt_dummy
  83. .global __xcpt_dummy
  84. __xcpt_dummy:
  85. b __xcpt_dummy
  86. .ltorg
  87. .globl _start
  88. _start:
  89. /*
  90. * Copy vectors to address zero.
  91. */
  92. mov r8, #0
  93. add r9, pc,#-(8+.-__vectors)
  94. ldmia r9!, {r0-r7}
  95. stmia r8!, {r0-r7}
  96. ldmia r9!, {r0-r4}
  97. stmia r8!, {r0-r4}
  98. /*
  99. * Section 1: Hardware initialization.
  100. */
  101. .section .init1,"ax",%progbits
  102. /*
  103. * Enable all clocks.
  104. */
  105. mvn r0, #0
  106. ldr r1, =PS_BASE
  107. str r0, [r1, #0x04]
  108. /*
  109. * Initialize the interrupt controller.
  110. */
  111. add r0, pc,#-(8+.-__aic_table)
  112. ldmia r0, {r1-r4}
  113. str r4, [r1, #AIC_SPU]
  114. mov r0, #8
  115. L0:
  116. str r1, [r1, #AIC_EOICR]
  117. subs r0, r0, #1
  118. bhi L0
  119. str r2, [r1, #AIC_SVR]
  120. add r1, r1, #AIC_SVR
  121. mov r0, #31
  122. L1:
  123. str r3, [r1, r0, LSL #2]
  124. subs r0, r0, #1
  125. bhi L1
  126. b __set_stacks
  127. __aic_table:
  128. .word AIC_BASE
  129. .word _start
  130. .word _start
  131. .word _start
  132. .ltorg
  133. .global __set_stacks
  134. __set_stacks:
  135. /*
  136. * Section 2: Set stack pointers.
  137. */
  138. .section .init2,"ax",%progbits
  139. /*
  140. * Set exception stack pointers and enable interrupts.
  141. */
  142. ldr r0, =__xcp_stack
  143. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  144. mov r13, r0
  145. sub r0, r0, #FIQ_STACK_SIZE
  146. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  147. mov r13, r0
  148. sub r0, r0, #IRQ_STACK_SIZE
  149. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  150. mov r13, r0
  151. sub r0, r0, #ABT_STACK_SIZE
  152. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  153. mov r13, r0
  154. sub r0, r0, #UND_STACK_SIZE
  155. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  156. mov r13, r0
  157. b __enter_mode
  158. .rept 32
  159. .long 0
  160. .endr
  161. .global __xcp_stack
  162. __xcp_stack:
  163. .ltorg
  164. .global __enter_mode
  165. .align
  166. __enter_mode:
  167. /*
  168. * Section 3: Enter system mode.
  169. */
  170. .section .init3,"ax",%progbits
  171. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  172. b __clear_bss
  173. .ltorg
  174. .global __clear_bss
  175. __clear_bss:
  176. /*
  177. * Section 4: Clear bss.
  178. */
  179. .section .init4,"ax",%progbits
  180. ldr r1, =__bss_start
  181. ldr r2, =__bss_end
  182. ldr r3, =0
  183. _40:
  184. cmp r1, r2
  185. strne r3, [r1], #+4
  186. bne _40
  187. /*
  188. * Initialize user stack pointer.
  189. */
  190. ldr r13, =__stack
  191. b __call_rtos
  192. .ltorg
  193. .global __call_rtos
  194. __call_rtos:
  195. /*
  196. * Section 5: Call RTOS
  197. */
  198. .section .init5,"ax",%progbits
  199. /*
  200. * Jump to Nut/OS initialization.
  201. */
  202. ldr r0, =NutInit
  203. bx r0
  204. End:
  205. b End
  206. .ltorg