crt0.s 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 GCC/crt0.S
  15. * @brief Generic PowerPC startup file for GCC.
  16. *
  17. * @addtogroup PPC_GCC_CORE
  18. * @{
  19. */
  20. /*===========================================================================*/
  21. /* Module constants. */
  22. /*===========================================================================*/
  23. #if !defined(FALSE) || defined(__DOXYGEN__)
  24. #define FALSE 0
  25. #endif
  26. #if !defined(TRUE) || defined(__DOXYGEN__)
  27. #define TRUE 1
  28. #endif
  29. /*===========================================================================*/
  30. /* Module pre-compile time settings. */
  31. /*===========================================================================*/
  32. /**
  33. * @brief Stack segments initialization switch.
  34. */
  35. #if !defined(CRT0_STACKS_FILL_PATTERN) || defined(__DOXYGEN__)
  36. #define CRT0_STACKS_FILL_PATTERN 0x55555555
  37. #endif
  38. /**
  39. * @brief Stack segments initialization switch.
  40. */
  41. #if !defined(CRT0_INIT_STACKS) || defined(__DOXYGEN__)
  42. #define CRT0_INIT_STACKS TRUE
  43. #endif
  44. /**
  45. * @brief DATA segment initialization switch.
  46. */
  47. #if !defined(CRT0_INIT_DATA) || defined(__DOXYGEN__)
  48. #define CRT0_INIT_DATA TRUE
  49. #endif
  50. /**
  51. * @brief BSS segment initialization switch.
  52. */
  53. #if !defined(CRT0_INIT_BSS) || defined(__DOXYGEN__)
  54. #define CRT0_INIT_BSS TRUE
  55. #endif
  56. /**
  57. * @brief Constructors invocation switch.
  58. */
  59. #if !defined(CRT0_CALL_CONSTRUCTORS) || defined(__DOXYGEN__)
  60. #define CRT0_CALL_CONSTRUCTORS TRUE
  61. #endif
  62. /**
  63. * @brief Destructors invocation switch.
  64. */
  65. #if !defined(CRT0_CALL_DESTRUCTORS) || defined(__DOXYGEN__)
  66. #define CRT0_CALL_DESTRUCTORS TRUE
  67. #endif
  68. /*===========================================================================*/
  69. /* Code section. */
  70. /*===========================================================================*/
  71. #if !defined(__DOXYGEN__)
  72. .vle
  73. .section .crt0, "axv"
  74. .align 2
  75. .globl _boot_address
  76. .type _boot_address, @function
  77. _boot_address:
  78. /* Stack setup.*/
  79. e_lis r1, __process_stack_end__@h
  80. e_or2i r1, __process_stack_end__@l
  81. se_li r0, 0
  82. e_stwu r0, -8(r1)
  83. /* Small sections registers initialization.*/
  84. e_lis r2, __sdata2_start__@h
  85. e_or2i r2, __sdata2_start__@l
  86. e_lis r13, __sdata_start__@h
  87. e_or2i r13, __sdata_start__@l
  88. /* Early initialization.*/
  89. e_bl __early_init
  90. #if CRT0_INIT_STACKS == TRUE
  91. /* Stacks fill pattern.*/
  92. e_lis r7, CRT0_STACKS_FILL_PATTERN@h
  93. e_or2i r7, CRT0_STACKS_FILL_PATTERN@l
  94. /* IRQ Stack initialization. Note, the architecture does not use this
  95. stack, the size is usually zero. An OS can have special SW handling
  96. and require this. A 4 bytes alignment is assmend and required.*/
  97. e_lis r4, __irq_stack_base__@h
  98. e_or2i r4, __irq_stack_base__@l
  99. e_lis r5, __irq_stack_end__@h
  100. e_or2i r5, __irq_stack_end__@l
  101. .irqsloop:
  102. se_cmpl r4, r5
  103. se_bge .irqsend
  104. se_stw r7, 0(r4)
  105. se_addi r4, 4
  106. se_b .irqsloop
  107. .irqsend:
  108. /* Process Stack initialization. Note, does not overwrite the already
  109. written EABI frame. A 4 bytes alignment is assmend and required.*/
  110. e_lis r4, __process_stack_base__@h
  111. e_or2i r4, __process_stack_base__@l
  112. e_lis r5, (__process_stack_end__ - 8)@h
  113. e_or2i r5, (__process_stack_end__ - 8)@l
  114. .prcsloop:
  115. se_cmpl r4, r5
  116. se_bge .prcsend
  117. se_stw r7, 0(r4)
  118. se_addi r4, 4
  119. se_b .prcsloop
  120. .prcsend:
  121. #endif
  122. #if CRT0_INIT_BSS == TRUE
  123. /* BSS clearing.*/
  124. e_lis r4, __bss_start__@h
  125. e_or2i r4, __bss_start__@l
  126. e_lis r5, __bss_end__@h
  127. e_or2i r5, __bss_end__@l
  128. se_li r7, 0
  129. .bssloop:
  130. se_cmpl r4, r5
  131. se_bge .bssend
  132. se_stw r7, 0(r4)
  133. se_addi r4, 4
  134. se_b .bssloop
  135. .bssend:
  136. #endif
  137. #if CRT0_INIT_DATA == TRUE
  138. /* DATA initialization.*/
  139. e_lis r4, __romdata_start__@h
  140. e_or2i r4, __romdata_start__@l
  141. e_lis r5, __data_start__@h
  142. e_or2i r5, __data_start__@l
  143. e_lis r6, __data_end__@h
  144. e_or2i r6, __data_end__@l
  145. .dataloop:
  146. se_cmpl r5, r6
  147. se_bge .dataend
  148. se_lwz r7, 0(r4)
  149. se_addi r4, 4
  150. se_stw r7, 0(r5)
  151. se_addi r5, 4
  152. se_b .dataloop
  153. .dataend:
  154. #endif
  155. /* Late initialization.*/
  156. e_bl __late_init
  157. #if CRT0_CALL_CONSTRUCTORS == TRUE
  158. /* Constructors invocation.*/
  159. e_lis r4, __init_array_start@h
  160. e_or2i r4, __init_array_start@l
  161. e_lis r5, __init_array_end@h
  162. e_or2i r5, __init_array_end@l
  163. .iniloop:
  164. se_cmpl r4, r5
  165. se_bge .iniend
  166. se_lwz r6, 0(r4)
  167. mtctr r6
  168. se_addi r4, 4
  169. se_bctrl
  170. se_b .iniloop
  171. .iniend:
  172. #endif
  173. /* Main program invocation.*/
  174. e_bl main
  175. #if CRT0_CALL_DESTRUCTORS == TRUE
  176. /* Destructors invocation.*/
  177. e_lis r4, __fini_array_start@h
  178. e_or2i r4, __fini_array_start@l
  179. e_lis r5, __fini_array_end@h
  180. e_or2i r5, __fini_array_end@l
  181. .finiloop:
  182. se_cmpl r4, r5
  183. se_bge .finiend
  184. se_lwz r6, 0(r4)
  185. mtctr r6
  186. se_addi r4, 4
  187. se_bctrl
  188. se_b .finiloop
  189. .finiend:
  190. #endif
  191. /* Branching to the defined exit handler.*/
  192. e_b __default_exit
  193. /* Default main exit code, infinite loop.*/
  194. .weak __default_exit
  195. .type __default_exit, @function
  196. __default_exit:
  197. e_b __default_exit
  198. /* Default early initialization code, none.*/
  199. .weak __early_init
  200. .type __early_init, @function
  201. __early_init:
  202. se_blr
  203. /* Default late initialization code, none.*/
  204. .weak __late_init
  205. .type __late_init, @function
  206. __late_init:
  207. se_blr
  208. #endif /* !defined(__DOXYGEN__) */
  209. /** @} */