aboutsummaryrefslogtreecommitdiffstats
path: root/os/common/startup/e200/compilers/GHS/crt0.s
blob: 5b2658c57a44f6bcdb1740cab4a218cd49fbd754 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
    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__) */

/** @} */