123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- /*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- /**
- * @file GCC/crt0.S
- * @brief Generic PowerPC startup file for GCC.
- *
- * @addtogroup PPC_GCC_CORE
- * @{
- */
- /*===========================================================================*/
- /* Module constants. */
- /*===========================================================================*/
- #if !defined(FALSE) || defined(__DOXYGEN__)
- #define FALSE 0
- #endif
- #if !defined(TRUE) || defined(__DOXYGEN__)
- #define TRUE 1
- #endif
- /*===========================================================================*/
- /* Module pre-compile time settings. */
- /*===========================================================================*/
- /**
- * @brief Stack segments initialization switch.
- */
- #if !defined(CRT0_STACKS_FILL_PATTERN) || defined(__DOXYGEN__)
- #define CRT0_STACKS_FILL_PATTERN 0x55555555
- #endif
- /**
- * @brief Stack segments initialization switch.
- */
- #if !defined(CRT0_INIT_STACKS) || defined(__DOXYGEN__)
- #define CRT0_INIT_STACKS TRUE
- #endif
- /**
- * @brief DATA segment initialization switch.
- */
- #if !defined(CRT0_INIT_DATA) || defined(__DOXYGEN__)
- #define CRT0_INIT_DATA TRUE
- #endif
- /**
- * @brief BSS segment initialization switch.
- */
- #if !defined(CRT0_INIT_BSS) || defined(__DOXYGEN__)
- #define CRT0_INIT_BSS TRUE
- #endif
- /**
- * @brief Constructors invocation switch.
- */
- #if !defined(CRT0_CALL_CONSTRUCTORS) || defined(__DOXYGEN__)
- #define CRT0_CALL_CONSTRUCTORS TRUE
- #endif
- /**
- * @brief Destructors invocation switch.
- */
- #if !defined(CRT0_CALL_DESTRUCTORS) || defined(__DOXYGEN__)
- #define CRT0_CALL_DESTRUCTORS TRUE
- #endif
- /*===========================================================================*/
- /* Code section. */
- /*===========================================================================*/
- #if !defined(__DOXYGEN__)
- .vle
- .section .crt0, "axv"
- .align 2
- .globl _boot_address
- .type _boot_address, @function
- _boot_address:
- /* Stack setup.*/
- e_lis r1, __process_stack_end__@h
- e_or2i r1, __process_stack_end__@l
- se_li r0, 0
- e_stwu r0, -8(r1)
- /* Small sections registers initialization.*/
- e_lis r2, __sdata2_start__@h
- e_or2i r2, __sdata2_start__@l
- e_lis r13, __sdata_start__@h
- e_or2i r13, __sdata_start__@l
- /* Early initialization.*/
- e_bl __early_init
- #if CRT0_INIT_STACKS == TRUE
- /* Stacks fill pattern.*/
- e_lis r7, CRT0_STACKS_FILL_PATTERN@h
- e_or2i r7, CRT0_STACKS_FILL_PATTERN@l
- /* IRQ Stack initialization. Note, the architecture does not use this
- stack, the size is usually zero. An OS can have special SW handling
- and require this. A 4 bytes alignment is assmend and required.*/
- e_lis r4, __irq_stack_base__@h
- e_or2i r4, __irq_stack_base__@l
- e_lis r5, __irq_stack_end__@h
- e_or2i r5, __irq_stack_end__@l
- .irqsloop:
- se_cmpl r4, r5
- se_bge .irqsend
- se_stw r7, 0(r4)
- se_addi r4, 4
- se_b .irqsloop
- .irqsend:
- /* Process Stack initialization. Note, does not overwrite the already
- written EABI frame. A 4 bytes alignment is assmend and required.*/
- e_lis r4, __process_stack_base__@h
- e_or2i r4, __process_stack_base__@l
- e_lis r5, (__process_stack_end__ - 8)@h
- e_or2i r5, (__process_stack_end__ - 8)@l
- .prcsloop:
- se_cmpl r4, r5
- se_bge .prcsend
- se_stw r7, 0(r4)
- se_addi r4, 4
- se_b .prcsloop
- .prcsend:
- #endif
- #if CRT0_INIT_BSS == TRUE
- /* BSS clearing.*/
- e_lis r4, __bss_start__@h
- e_or2i r4, __bss_start__@l
- e_lis r5, __bss_end__@h
- e_or2i r5, __bss_end__@l
- se_li r7, 0
- .bssloop:
- se_cmpl r4, r5
- se_bge .bssend
- se_stw r7, 0(r4)
- se_addi r4, 4
- se_b .bssloop
- .bssend:
- #endif
- #if CRT0_INIT_DATA == TRUE
- /* DATA initialization.*/
- e_lis r4, __romdata_start__@h
- e_or2i r4, __romdata_start__@l
- e_lis r5, __data_start__@h
- e_or2i r5, __data_start__@l
- e_lis r6, __data_end__@h
- e_or2i r6, __data_end__@l
- .dataloop:
- se_cmpl r5, r6
- se_bge .dataend
- se_lwz r7, 0(r4)
- se_addi r4, 4
- se_stw r7, 0(r5)
- se_addi r5, 4
- se_b .dataloop
- .dataend:
- #endif
- /* Late initialization.*/
- e_bl __late_init
- #if CRT0_CALL_CONSTRUCTORS == TRUE
- /* Constructors invocation.*/
- e_lis r4, __init_array_start@h
- e_or2i r4, __init_array_start@l
- e_lis r5, __init_array_end@h
- e_or2i r5, __init_array_end@l
- .iniloop:
- se_cmpl r4, r5
- se_bge .iniend
- se_lwz r6, 0(r4)
- mtctr r6
- se_addi r4, 4
- se_bctrl
- se_b .iniloop
- .iniend:
- #endif
- /* Main program invocation.*/
- e_bl main
- #if CRT0_CALL_DESTRUCTORS == TRUE
- /* Destructors invocation.*/
- e_lis r4, __fini_array_start@h
- e_or2i r4, __fini_array_start@l
- e_lis r5, __fini_array_end@h
- e_or2i r5, __fini_array_end@l
- .finiloop:
- se_cmpl r4, r5
- se_bge .finiend
- se_lwz r6, 0(r4)
- mtctr r6
- se_addi r4, 4
- se_bctrl
- se_b .finiloop
- .finiend:
- #endif
- /* Branching to the defined exit handler.*/
- e_b __default_exit
- /* Default main exit code, infinite loop.*/
- .weak __default_exit
- .type __default_exit, @function
- __default_exit:
- e_b __default_exit
- /* Default early initialization code, none.*/
- .weak __early_init
- .type __early_init, @function
- __early_init:
- se_blr
- /* Default late initialization code, none.*/
- .weak __late_init
- .type __late_init, @function
- __late_init:
- se_blr
- #endif /* !defined(__DOXYGEN__) */
- /** @} */
|