crt0.S 7.1 KB

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