cstartup.s 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file ARMCMx/compilers/IAR/cstartup.s
  15. * @brief Generic IAR Cortex-Mx startup file.
  16. *
  17. * @addtogroup ARMCMx_IAR_STARTUP
  18. * @{
  19. */
  20. #if !defined(__DOXYGEN__)
  21. #define SCB_VTOR 0xE000ED08
  22. /**
  23. * @brief VTOR special register initialization.
  24. * @details VTOR is initialized to point to the vectors table.
  25. * @note IAR assembler #if directive conditions do not work like C/C++ conditions.
  26. * @details Set to 0 to disable the function, 1 to enable
  27. */
  28. #ifndef CRT0_VTOR_INIT
  29. #define CRT0_VTOR_INIT 1
  30. #endif
  31. /**
  32. * @brief Stack segments initialization value.
  33. */
  34. #ifndef CRT0_STACKS_FILL_PATTERN
  35. #define CRT0_STACKS_FILL_PATTERN 0x55555555
  36. #endif
  37. /**
  38. * @brief Stack segments initialization switch.
  39. * @details Set to 0 to disable the function, 1 to enable
  40. */
  41. #ifndef CRT0_INIT_STACKS
  42. #define CRT0_INIT_STACKS 1
  43. #endif
  44. /**
  45. * @brief Heap segment initialization value.
  46. */
  47. #ifndef CRT0_HEAP_FILL_PATTERN
  48. #define CRT0_HEAP_FILL_PATTERN 0xCCCCCCCC
  49. #endif
  50. /**
  51. * @brief Heap segment initialization switch.
  52. * @details Set to 0 to disable the function, 1 to enable
  53. */
  54. #ifndef CRT0_INIT_HEAP
  55. #define CRT0_INIT_HEAP 1
  56. #endif
  57. MODULE ?cstartup
  58. CONTROL_MODE_PRIVILEGED SET 0
  59. CONTROL_MODE_UNPRIVILEGED SET 1
  60. CONTROL_USE_MSP SET 0
  61. CONTROL_USE_PSP SET 2
  62. AAPCS INTERWORK, VFP_COMPATIBLE, ROPI
  63. PRESERVE8
  64. SECTION HEAP:DATA:NOROOT(3)
  65. PUBLIC __heap_base__
  66. __heap_base__: /* Note: heap section defines sysheap base */
  67. SECTION SYSHEAP:DATA:NOROOT(3)
  68. PUBLIC __heap_end__
  69. __heap_end__: /* Note: sysheap section defines sysheap end */
  70. PUBLIC __iar_program_start
  71. EXTWEAK __iar_init_core
  72. EXTWEAK __iar_init_vfp
  73. EXTERN __cmain
  74. EXTERN __vector_table
  75. EXTERN __main_stack_base__
  76. EXTERN __main_stack_end__
  77. EXTERN __process_stack_base__
  78. EXTERN __process_stack_end__
  79. SECTION IRQSTACK:DATA:NOROOT(3)
  80. SECTION CSTACK:DATA:NOROOT(3)
  81. SECTION .text:CODE:REORDER(2)
  82. THUMB
  83. __iar_program_start:
  84. cpsid i
  85. ldr r0, =SFE(IRQSTACK)
  86. msr MSP, r0
  87. ldr r0, =SFE(CSTACK)
  88. msr PSP, r0
  89. movs r0, #CONTROL_MODE_PRIVILEGED | CONTROL_USE_PSP
  90. msr CONTROL, r0
  91. isb
  92. #if (CRT0_VTOR_INIT)
  93. ldr r0, =__vector_table
  94. movw r1, #SCB_VTOR & 0xFFFF
  95. movt r1, #SCB_VTOR >> 16
  96. str r0, [r1]
  97. #endif
  98. #if (CRT0_INIT_STACKS)
  99. ldr r0, =CRT0_STACKS_FILL_PATTERN
  100. /* Main Stack initialization. Note, it assumes that the stack size
  101. is a multiple of 4 so the linker file must ensure this.*/
  102. ldr r1, =__main_stack_base__
  103. ldr r2, =__main_stack_end__
  104. msloop:
  105. cmp r1, r2
  106. itt lo
  107. strlo r0, [r1], #4
  108. blo msloop
  109. /* Process Stack initialization. Note, it assumes that the stack size
  110. is a multiple of 4 so the linker file must ensure this.*/
  111. ldr r1, =__process_stack_base__
  112. ldr r2, =__process_stack_end__
  113. psloop:
  114. cmp r1, r2
  115. itt lo
  116. strlo r0, [r1], #4
  117. blo psloop
  118. #endif
  119. #if (CRT0_INIT_HEAP)
  120. ldr r0, =CRT0_HEAP_FILL_PATTERN
  121. /* Sys Heap initialization. Note, it assumes that the heap size
  122. is a multiple of 4 so the linker file must ensure this.*/
  123. ldr r1, =__heap_base__
  124. ldr r2, =__heap_end__
  125. hloop:
  126. cmp r1, r2
  127. itt lo
  128. strlo r0, [r1], #4
  129. blo hloop
  130. #endif
  131. bl __early_init
  132. bl __iar_init_core
  133. bl __iar_init_vfp
  134. b __cmain
  135. SECTION .text:CODE:NOROOT:REORDER(2)
  136. PUBWEAK __early_init
  137. __early_init:
  138. bx lr
  139. END
  140. #endif /* !defined(__DOXYGEN__) */
  141. /**< @} */