crtat91sam9260_ram.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * Copyright (C) 2006-2007 by egnite Software GmbH
  3. * Copyright (C) 2009-2010 by egnite 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. /*
  37. * $Id: crtat91sam9260_ram.S 3390 2011-04-27 11:06:20Z haraldkipp $
  38. */
  39. #include <cfg/clock.h>
  40. #include <cfg/memory.h>
  41. #include <arch/arm.h>
  42. #ifndef PLL_MUL_VAL
  43. #define PLL_MUL_VAL 96
  44. #endif
  45. #ifndef PLL_DIV_VAL
  46. #define PLL_DIV_VAL 9
  47. #endif
  48. #ifndef IRQ_STACK_SIZE
  49. #define IRQ_STACK_SIZE 512
  50. #endif
  51. #ifndef FIQ_STACK_SIZE
  52. #define FIQ_STACK_SIZE 256
  53. #endif
  54. #ifndef ABT_STACK_SIZE
  55. #define ABT_STACK_SIZE 128
  56. #endif
  57. #ifndef UND_STACK_SIZE
  58. #define UND_STACK_SIZE 128
  59. #endif
  60. /*
  61. * Section 0: Vector table and reset entry.
  62. */
  63. .section .init0,"ax",%progbits
  64. __vectors:
  65. ldr pc, [pc, #24] /* Reset */
  66. ldr pc, [pc, #24] /* Undefined instruction */
  67. ldr pc, [pc, #24] /* Software interrupt */
  68. ldr pc, [pc, #24] /* Prefetch abort */
  69. ldr pc, [pc, #24] /* Data abort */
  70. .word 0x00001000 /* Size of the boot image will go here */
  71. /*
  72. * On IRQ the PC will be loaded from AIC_IVR, which
  73. * provides the address previously set in AIC_SVR.
  74. * The interrupt routine will be called in ARM_MODE_IRQ
  75. * with IRQ disabled and FIQ unchanged.
  76. */
  77. ldr pc, [pc, #-0xF20] /* Interrupt request, auto vectoring. */
  78. ldr pc, [pc, #-0xF20] /* Fast interrupt request, auto vectoring. */
  79. .word _start
  80. .word __undef
  81. .word __swi
  82. .word __prefetch_abort
  83. .word __data_abort
  84. .weak __undef
  85. .set __undef, __undef_stop
  86. .weak __swi
  87. .set __swi, __swi_stop
  88. .weak __prefetch_abort
  89. .set __prefetch_abort, __prefetch_stop
  90. .weak __data_abort
  91. .set __data_abort, __data_stop
  92. __undef_stop:
  93. b __undef_stop
  94. __swi_stop:
  95. b __swi_stop
  96. __prefetch_stop:
  97. b __prefetch_stop
  98. __data_stop:
  99. b __data_stop
  100. .ltorg
  101. /*
  102. * Section 1: Hardware initialization.
  103. */
  104. .section .init1, "ax", %progbits
  105. .global _start
  106. _start:
  107. /*
  108. * Disable all interrupts and clear any pending ones.
  109. * Useful for debugging w/o target reset.
  110. */
  111. ldr r1, =AIC_BASE
  112. mvn r0, #0
  113. str r0, [r1, #AIC_IDCR_OFF]
  114. str r0, [r1, #AIC_ICCR_OFF]
  115. /*
  116. * Perform 8 "End Of Interrupt" commands to make sure that
  117. * the AIC will not lock out nIRQ.
  118. */
  119. str r0, [r1, #AIC_EOICR_OFF]
  120. str r0, [r1, #AIC_EOICR_OFF]
  121. str r0, [r1, #AIC_EOICR_OFF]
  122. str r0, [r1, #AIC_EOICR_OFF]
  123. str r0, [r1, #AIC_EOICR_OFF]
  124. str r0, [r1, #AIC_EOICR_OFF]
  125. str r0, [r1, #AIC_EOICR_OFF]
  126. str r0, [r1, #AIC_EOICR_OFF]
  127. /*
  128. * The watchdog is enabled after processor reset. Disable it.
  129. */
  130. ldr r1, =WDT_BASE
  131. ldr r0, =WDT_WDDIS
  132. str r0, [r1, #WDT_MR_OFF]
  133. /*
  134. * Enable the main oscillator. Set startup time of 64 * 8 slow
  135. * clock cycles and wait until oscillator is stabilized.
  136. */
  137. ldr r1, =PMC_BASE
  138. mov r0, #(64 << CKGR_OSCOUNT_LSB)
  139. orr r0, r0, #CKGR_MOSCEN
  140. str r0, [r1, #CKGR_MOR_OFF]
  141. wait_moscs:
  142. ldr r0, [r1, #CKGR_MCFR_OFF]
  143. tst r0, #CKGR_MAINRDY
  144. beq wait_moscs
  145. /*
  146. * Enable external reset key.
  147. */
  148. ldr r0, =(RSTC_KEY | RSTC_URSTEN)
  149. ldr r1, =RSTC_MR
  150. str r0, [r1, #0]
  151. /*
  152. * Remap internal RAM to address 0 and copy vectors to this loacation.
  153. */
  154. mov r0, #(MATRIX_MRCR_RCB0 | MATRIX_MRCR_RCB1)
  155. ldr r1, =MATRIX_BASE
  156. str r0, [r1, #MATRIX_MRCR_OFF]
  157. ldr r0, =__vectors
  158. mov r1, #0
  159. ldmia r0!, {r2-r9}
  160. stmia r1!, {r2-r9}
  161. ldmia r0!, {r2-r9}
  162. stmia r1!, {r2-r9}
  163. b __set_stacks
  164. .ltorg
  165. /*
  166. * Section 2: Set stack pointers.
  167. */
  168. .section .init2,"ax",%progbits
  169. __set_stacks:
  170. /*
  171. * Set exception stack pointers and enable interrupts.
  172. */
  173. ldr r0, =__exp_stack
  174. msr CPSR_c, #ARM_MODE_FIQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  175. mov r13, r0
  176. sub r0, r0, #FIQ_STACK_SIZE
  177. msr CPSR_c, #ARM_MODE_IRQ | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  178. mov r13, r0
  179. sub r0, r0, #IRQ_STACK_SIZE
  180. msr CPSR_c, #ARM_MODE_ABORT | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  181. mov r13, r0
  182. sub r0, r0, #ABT_STACK_SIZE
  183. msr CPSR_c, #ARM_MODE_UNDEF | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  184. mov r13, r0
  185. sub r0, r0, #UND_STACK_SIZE
  186. msr CPSR_c, #ARM_MODE_SVC | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  187. mov r13, r0
  188. b __enter_mode
  189. .ltorg
  190. /*
  191. * Section 3: Set ARM specific modes.
  192. */
  193. .section .init3,"ax",%progbits
  194. __enter_mode:
  195. /*
  196. * Enable the instruction cache.
  197. */
  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. msr CPSR_c, #ARM_MODE_SYS | ARM_CPSR_I_BIT | ARM_CPSR_F_BIT
  203. b __clear_bss
  204. .ltorg
  205. /*
  206. * Section 4: Clear bss and copy data.
  207. */
  208. .section .init4,"ax",%progbits
  209. __clear_bss:
  210. ldr r1, =__bss_start
  211. ldr r2, =__bss_end
  212. ldr r3, =0
  213. __next_bss:
  214. cmp r1, r2
  215. strne r3, [r1], #+4
  216. bne __next_bss
  217. /*
  218. * Initialize user stack pointer.
  219. */
  220. ldr r13, =__stack
  221. b __call_rtos
  222. .ltorg
  223. /*
  224. * Section 5: Call RTOS
  225. */
  226. .section .init5,"ax",%progbits
  227. __call_rtos:
  228. /*
  229. * Jump to Nut/OS initialization.
  230. */
  231. ldr r0, =NutInit
  232. mov lr, pc
  233. bx r0
  234. __exit_loop:
  235. b __exit_loop
  236. .ltorg