crtat91sam7se512_ram.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (C) 2005-2008 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. * NOTE: This is the corrected version for debugging in RAM.
  33. * The remapping, SRAM to 0x00000000, must be done by the
  34. * debugger script. Relocating of .data section is removed too.
  35. * (20.03.2011, Michael Fischer)
  36. */
  37. #include <cfg/clock.h>
  38. #include <cfg/memory.h>
  39. #include <arch/arm.h>
  40. #ifndef NUTMEM_FLASH_RWS
  41. /* By default use 1 wait state for flash read access. */
  42. #define NUTMEM_FLASH_RWS 1
  43. #endif
  44. #if NUTMEM_FLASH_RWS == 0
  45. #define MC_FWS_VAL MC_FWS_1R2W /* 1 cycle for read, 2 for write ops. */
  46. #elif NUTMEM_FLASH_RWS == 1
  47. #define MC_FWS_VAL MC_FWS_2R3W /* 2 cycles for read, 3 for write ops. */
  48. #elif NUTMEM_FLASH_RWS == 2
  49. #define MC_FWS_VAL MC_FWS_3R4W /* 3 cycles for read, 4 for write ops. */
  50. #else
  51. #define MC_FWS_VAL MC_FWS_4R4W /* 4 cycles for read and write ops. */
  52. #endif
  53. #ifndef IRQ_STACK_SIZE
  54. #define IRQ_STACK_SIZE 512
  55. #endif
  56. #ifndef FIQ_STACK_SIZE
  57. #define FIQ_STACK_SIZE 256
  58. #endif
  59. #ifndef ABT_STACK_SIZE
  60. #define ABT_STACK_SIZE 128
  61. #endif
  62. #ifndef UND_STACK_SIZE
  63. #define UND_STACK_SIZE 128
  64. #endif
  65. /*
  66. * Section 0: Vector table and reset entry.
  67. */
  68. .section .init0,"ax",%progbits
  69. .global __vectors
  70. __vectors:
  71. ldr pc, [pc, #24] /* Reset */
  72. ldr pc, [pc, #24] /* Undefined instruction */
  73. ldr pc, [pc, #24] /* Software interrupt */
  74. ldr pc, [pc, #24] /* Prefetch abort */
  75. ldr pc, [pc, #24] /* Data abort */
  76. ldr pc, [pc, #24] /* Reserved */
  77. /*
  78. * On IRQ the PC will be loaded from AIC_IVR, which
  79. * provides the address previously set in AIC_SVR.
  80. * The interrupt routine will be called in ARM_MODE_IRQ
  81. * with IRQ disabled and FIQ unchanged.
  82. */
  83. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  84. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  85. .word _start
  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. .global __xcpt_dummy
  99. __xcpt_dummy:
  100. b __xcpt_dummy
  101. .ltorg
  102. /*
  103. * Section 1: Hardware initialization.
  104. */
  105. .section .init1, "ax", %progbits
  106. .globl _start
  107. _start:
  108. /*
  109. * Set cycles for flash access.
  110. */
  111. ldr r1, =MC_BASE
  112. mov r0, #MC_FWS_VAL
  113. str r0, [r1, #MC_FMR_EFC0_OFF]
  114. str r0, [r1, #MC_FMR_EFC1_OFF]
  115. /*
  116. * Disable all interrupts. Useful for debugging w/o target reset.
  117. */
  118. ldr r1, =AIC_BASE
  119. mvn r0, #0
  120. str r0, [r1, #AIC_EOICR_OFF]
  121. str r0, [r1, #AIC_IDCR_OFF]
  122. /*
  123. * The watchdog is enabled after processor reset. Disable it.
  124. */
  125. ldr r1, =WDT_BASE
  126. ldr r0, =WDT_WDDIS
  127. str r0, [r1, #WDT_MR_OFF]
  128. /*
  129. * Enable external reset key.
  130. */
  131. ldr r0, =(RSTC_KEY | RSTC_URSTEN)
  132. ldr r1, =RSTC_MR
  133. str r0, [r1, #0]
  134. b __set_stacks
  135. .ltorg
  136. /*
  137. * Section 2: Set stack pointers.
  138. */
  139. .section .init2,"ax",%progbits
  140. .global __set_stacks
  141. __set_stacks:
  142. /*
  143. * Set exception stack pointers and enable interrupts.
  144. */
  145. ldr r0, =__exp_stack
  146. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  147. mov r13, r0
  148. sub r0, r0, #FIQ_STACK_SIZE
  149. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  150. mov r13, r0
  151. sub r0, r0, #IRQ_STACK_SIZE
  152. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  153. mov r13, r0
  154. sub r0, r0, #ABT_STACK_SIZE
  155. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  156. mov r13, r0
  157. sub r0, r0, #UND_STACK_SIZE
  158. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  159. mov r13, r0
  160. b __enter_mode
  161. .ltorg
  162. /*
  163. * Section 3: Enter system mode.
  164. */
  165. .section .init3,"ax",%progbits
  166. .global __enter_mode
  167. __enter_mode:
  168. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  169. b __clear_bss
  170. .ltorg
  171. /*
  172. * Section 4: Clear bss and copy data.
  173. */
  174. .section .init4,"ax",%progbits
  175. .global __clear_bss
  176. __clear_bss:
  177. ldr r1, =__bss_start
  178. ldr r2, =__bss_end
  179. ldr r3, =0
  180. _40:
  181. cmp r1, r2
  182. strne r3, [r1], #+4
  183. bne _40
  184. /*
  185. * Initialize user stack pointer.
  186. */
  187. ldr r13, =__stack
  188. b __call_rtos
  189. .ltorg
  190. /*
  191. * Section 5: Call RTOS
  192. */
  193. .section .init5,"ax",%progbits
  194. .global __call_rtos
  195. __call_rtos:
  196. /*
  197. * Jump to Nut/OS initialization.
  198. */
  199. ldr r0, =NutInit
  200. bx r0
  201. End:
  202. b End
  203. .ltorg