crtat91sam9xe512_ram.S 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Copyright (C) 2012 by egnite GmbH.
  3. * Copyright (C) 2006-2007 by egnite Software GmbH.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. */
  35. /*
  36. * $Id: crtat91sam9xe512_ram.S 4053 2012-03-26 14:41:44Z haraldkipp $
  37. */
  38. .nolist
  39. #include <cfg/clock.h>
  40. #include <cfg/memory.h>
  41. #include <arch/arm.h>
  42. .psize 0
  43. .list
  44. /*
  45. * This file contains the runtime initialization for AT91SAM9XE512
  46. * based systems.
  47. *
  48. * The related linker file is at91sam9xe512_ram.ld.
  49. *
  50. * Code and data is located in external RAM and must be loaded by a boot
  51. * loader or debugger, which initializes the basic clocks. If this code
  52. * runs in SDRAM, it is assumed that it has been initialized as well.
  53. */
  54. /*
  55. * Stack sizes.
  56. *
  57. * Interrupt nesting is currently not supported. Therefore dedicated
  58. * stacks are used for all exceptions.
  59. */
  60. #ifndef INI_STACK_SIZE
  61. #define INI_STACK_SIZE (256 * 4)
  62. #endif
  63. #ifndef IRQ_STACK_SIZE
  64. #define IRQ_STACK_SIZE (128 * 4)
  65. #endif
  66. #ifndef FIQ_STACK_SIZE
  67. #define FIQ_STACK_SIZE (64 * 4)
  68. #endif
  69. #ifndef EXC_STACK_SIZE
  70. #define EXC_STACK_SIZE (32 * 4)
  71. #endif
  72. #define TOTAL_STACK_SIZE (INI_STACK_SIZE + IRQ_STACK_SIZE + FIQ_STACK_SIZE + EXC_STACK_SIZE)
  73. /* We start in ARM mode. */
  74. .arm
  75. /*
  76. * Vector Section: Must be moved to address 0.
  77. */
  78. .section .vectors,"ax",%progbits
  79. .global __vectors
  80. __vectors:
  81. /* Reset entry. */
  82. ldr pc, [pc, #___init_vect - . - 8]
  83. /* Undefined instruction entry. */
  84. ldr pc, [pc, #___undef_vect - . - 8]
  85. /* Software interrupt entry. */
  86. ldr pc, [pc, #___swi_vect - . - 8]
  87. /* Prefetch abort entry. */
  88. ldr pc, [pc, #___pref_vect - . - 8]
  89. /* Data abort entry. */
  90. ldr pc, [pc, #___data_vect - . - 8]
  91. /*
  92. * Reserved entry, used by some boot loaders to store the
  93. * size of the binary image.
  94. */
  95. .word 0
  96. /* Interrupt request entry, auto vectoring. */
  97. ldr pc, [pc, #__vectors + AIC_IVR - . - 8]
  98. /* Fast interrupt request entry, auto vectoring. */
  99. ldr pc, [pc, #__vectors + AIC_FVR - . - 8]
  100. ___init_vect:
  101. .weak __init1
  102. .set __init1, _start
  103. .word __init1
  104. /*
  105. * Exceptions are weakly linked to endless loops.
  106. *
  107. * This may look a bit confusing. The following words contain
  108. * the jump addresses that are loaded at each entry, see above.
  109. * They contain weakly defined addresses pointing to executable
  110. * code. Each of them may be overridden by the operating system
  111. * or the application, if a function with the same name exist.
  112. * By default they simply point to an endless loop.
  113. */
  114. ___undef_vect:
  115. .weak __undef
  116. .set __undef, __undef_stop
  117. .word __undef
  118. ___swi_vect:
  119. .weak __swi
  120. .set __swi, __undef_stop
  121. .word __swi
  122. ___pref_vect:
  123. .weak __prefetch_abort
  124. .set __prefetch_abort, __undef_stop
  125. .word __prefetch_abort
  126. ___data_vect:
  127. .weak __data_abort
  128. .set __data_abort, __undef_stop
  129. .word __data_abort
  130. /*
  131. * Init Section 0: Exception Dummies.
  132. *
  133. * All exceptions without a handler will end up in the same loop.
  134. * Alternatively, we may use a dedicated loop for each exception.
  135. * If an unhandled exception occurs, we can then use a simple
  136. * debugger (like OpenOCD) to retrieve the current program counter
  137. * and check the linker map to determine the type of the exception.
  138. */
  139. .section .init0, "ax", %progbits
  140. .global __undef_stop
  141. __undef_stop:
  142. b __undef_stop
  143. /*
  144. * Init section 1: Memory remapping.
  145. *
  146. * Additional code may be added here by defining a naked function
  147. * named __init1 and placing it in section .init1.user.
  148. */
  149. .section .init1, "ax", %progbits
  150. .global _start
  151. _start:
  152. /* Copy 8 vectors and 5 handler addresses to internal RAM. */
  153. ldr r0, =__vectors
  154. mov r1, #0x00300000
  155. ldmia r0!, {r2-r9}
  156. stmia r1!, {r2-r9}
  157. ldmia r0!, {r2-r6}
  158. stmia r1!, {r2-r6}
  159. /* Remap internal RAM to address 0. */
  160. mov r0, #(MATRIX_MRCR_RCB0 | MATRIX_MRCR_RCB1)
  161. ldr r1, =MATRIX_BASE
  162. str r0, [r1, #MATRIX_MRCR_OFF]
  163. .weak __init2
  164. .set __init2, __set_stacks
  165. ldr pc, =__init2
  166. /*
  167. * Init section 2: Set stack pointers.
  168. */
  169. .section .init2,"ax",%progbits
  170. .global __set_stacks
  171. __set_stacks:
  172. /*
  173. * Set stack pointers with disabled interrupts.
  174. */
  175. ldr r0, =__stack
  176. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  177. mov sp, r0
  178. sub r0, r0, #INI_STACK_SIZE
  179. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  180. mov sp, r0
  181. sub r0, r0, #FIQ_STACK_SIZE
  182. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  183. mov sp, r0
  184. sub r0, r0, #IRQ_STACK_SIZE
  185. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  186. mov sp, r0
  187. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  188. mov sp, r0
  189. /*
  190. * Nut/OS system and application are running in system mode.
  191. * Note, that we re-use the supervisory stack.
  192. */
  193. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  194. ldr r0, =__stack
  195. mov sp, r0
  196. #if 0
  197. /* Enable the instruction cache. */
  198. mrc p15, 0, r0, c1, c0, 0
  199. ldr r3, =0xC0001000
  200. orr r0, r0, r3
  201. mcr p15, 0, r0, c1, c0, 0
  202. #endif
  203. .weak __init3
  204. .set __init3, __clear_bss
  205. ldr pc, =__init3
  206. /*
  207. * Init section 3: Initialize C variables.
  208. */
  209. .section .init3, "ax", %progbits
  210. .global __clear_bss
  211. __clear_bss:
  212. ldr r1, =__bss_start
  213. ldr r2, =__bss_end
  214. mov r3, #0
  215. 1: cmp r1, r2
  216. strne r3, [r1], #4
  217. bne 1b
  218. .weak __init4
  219. .set __init4, __call_rtos
  220. ldr pc, =__init4
  221. /*
  222. * Init section 4: Start Nut/OS.
  223. */
  224. .section .init4, "ax", %progbits
  225. .global __call_rtos
  226. __call_rtos:
  227. /* Jump to Nut/OS initialization. */
  228. ldr r0, =NutInit
  229. .weak __exit0
  230. .set __exit0, __stop_rtos
  231. ldr lr, =__exit0
  232. bx r0
  233. /*
  234. * Exit Section 0: Endless loop.
  235. *
  236. * May be overridden by defining a naked function named __exit0.
  237. */
  238. .section .exit0, "ax", %progbits
  239. .global __stop_rtos
  240. __stop_rtos:
  241. b __stop_rtos
  242. /*
  243. * Stack Section.
  244. */
  245. .section .stack, "w", %nobits
  246. .space TOTAL_STACK_SIZE