OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [sys/] [arm/] [crt0.S] - Blame information for rev 520

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
#include "newlib.h"
2
#include "swi.h"
3
 
4
/* ANSI concatenation macros.  */
5
#define CONCAT(a, b) CONCAT2(a, b)
6
#define CONCAT2(a, b) a ## b
7
 
8
#ifdef __USER_LABEL_PREFIX__
9
#define FUNCTION( name ) CONCAT (__USER_LABEL_PREFIX__, name)
10
#else
11
#error __USER_LABEL_PREFIX is not defined
12
#endif
13
 
14
#ifdef HAVE_INITFINI_ARRAY
15
#define _init   __libc_init_array
16
#define _fini   __libc_fini_array
17
#endif
18
 
19
/* .text is used instead of .section .text so it works with arm-aout too.  */
20
        .text
21
#if defined(__thumb2__)
22
        .syntax unified
23
        .thumb
24
.macro FUNC_START name
25
        .global \name
26
        .thumb_func
27
\name:
28
.endm
29
#else
30
        .code 32
31
.macro FUNC_START name
32
        .global \name
33
\name:
34
.endm
35
#endif
36
        .align  0
37
 
38
        FUNC_START      _mainCRTStartup
39
        FUNC_START      _start
40
        FUNC_START      start
41
#if defined(__ELF__) && !defined(__USING_SJLJ_EXCEPTIONS__)
42
        /* Annotation for EABI unwinding tables.  */
43
        .fnstart
44
#endif
45
 
46
/* Start by setting up a stack */
47
#ifdef ARM_RDP_MONITOR
48
        /*  Issue Demon SWI to read stack info */
49
        swi     SWI_GetEnv      /*  Returns command line in r0 */
50
        mov     sp,r1           /*  and the highest memory address in r1 */
51
        ldr     sl, .LC2        /*  stack limit is at end of data */
52
        add     sl, sl, #256    /*  allow slop for stack overflow handling */
53
                                /*  and small frames */
54
#else
55
#ifdef ARM_RDI_MONITOR
56
        /*  Issue Angel SWI to read stack info */
57
        mov     r0, #AngelSWI_Reason_HeapInfo
58
        adr     r1, .LC0        /*  point at ptr to 4 words to receive data */
59
#if defined(__thumb2__)
60
        bkpt    AngelSWI
61
#else
62
        /*  We are always in ARM mode for startup */
63
        AngelSWIAsm     AngelSWI_ARM
64
#endif
65
        ldr     r0, .LC0        /*  point at values read */
66
        ldr     sp, [r0, #8]
67
        ldr     sl, [r0, #12]
68
        add     sl, sl, #256    /*  allow slop for stack overflow handling */
69
                                /*  and small frames */
70
#else
71
        /*  Set up the stack pointer to a fixed value */
72
        ldr     r3, .LC0
73
        mov     sp, r3
74
        /* Setup a default stack-limit in-case the code has been
75
           compiled with "-mapcs-stack-check".  Hard-wiring this value
76
           is not ideal, since there is currently no support for
77
           checking that the heap and stack have not collided, or that
78
           this default 64k is enough for the program being executed.
79
           However, it ensures that this simple crt0 world will not
80
           immediately cause an overflow event:  */
81
        sub     sl, sp, #64 << 10       /* Still assumes 256bytes below sl */
82
#endif
83
#endif
84
        /* Zero the memory in the .bss section.  */
85
        mov     a2, #0                  /* Second arg: fill value */
86
        mov     fp, a2                  /* Null frame pointer */
87
        mov     r7, a2                  /* Null frame pointer for Thumb */
88
 
89
        ldr     a1, .LC1                /* First arg: start of memory block */
90
        ldr     a3, .LC2
91
        sub     a3, a3, a1              /* Third arg: length of block */
92
 
93
 
94
#if defined(__thumb__) && !defined(__thumb2__)
95
        /* Enter Thumb mode.... */
96
        add     a4, pc, #1      /* Get the address of the Thumb block */
97
        bx      a4              /* Go there and start Thumb decoding  */
98
 
99
        .code 16
100
        .global __change_mode
101
        .thumb_func
102
__change_mode:
103
#endif
104
 
105
        bl      FUNCTION (memset)
106
#if !defined (ARM_RDP_MONITOR) && !defined (ARM_RDI_MONITOR)
107
        mov     r0, #0          /*  no arguments  */
108
        mov     r1, #0          /*  no argv either */
109
#else
110
        /* Need to set up standard file handles */
111
        bl      FUNCTION (initialise_monitor_handles)
112
 
113
#ifdef ARM_RDP_MONITOR
114
        swi     SWI_GetEnv      /*  sets r0 to point to the command line */
115
        mov     r1, r0
116
#else
117
        mov     r0, #AngelSWI_Reason_GetCmdLine
118
        adr     r1, .LC30       /*  Space for command line */
119
        AngelSWIAsm     AngelSWI
120
        ldr     r1, .LC30
121
#endif
122
        /*  Parse string at r1 */
123
        mov     r0, #0          /*  count of arguments so far */
124
        /* Push a NULL argument onto the end of the list.  */
125
#ifdef __thumb__
126
        push    {r0}
127
#else
128
        stmfd   sp!, {r0}
129
#endif
130
.LC10:
131
/*  Skip leading blanks */
132
#ifdef __thumb__
133
        ldrb    r3, [r1]
134
        add     r1, #1
135
#else
136
        ldrb    r3, [r1], #1
137
#endif
138
        cmp     r3, #0
139
        beq     .LC12
140
        cmp     r3, #' '
141
        beq     .LC10
142
 
143
/*  See whether we are scanning a string */
144
        cmp     r3, #'"'
145
#ifdef __thumb__
146
        beq     .LC20
147
        cmp     r3, #'\''
148
        bne     .LC21
149
.LC20:
150
        mov     r2, r3
151
        b       .LC22
152
 
153
.LC21:
154
        mov     r2, #' '        /*  terminator type */
155
        sub     r1, r1, #1      /*  adjust back to point at start char */
156
.LC22:
157
#else
158
        cmpne   r3, #'\''
159
        moveq   r2, r3
160
        movne   r2, #' '        /*  terminator type */
161
        subne   r1, r1, #1      /*  adjust back to point at start char */
162
#endif
163
 
164
/*  Stack a pointer to the current argument */
165
#ifdef __thumb__
166
        push    {r1}
167
#else
168
        stmfd   sp!, {r1}
169
#endif
170
        add     r0, r0, #1
171
.LC11:
172
#ifdef __thumb__
173
        ldrb    r3, [r1]
174
        add     r1, #1
175
#else
176
        ldrb    r3, [r1], #1
177
#endif
178
        cmp     r3, #0
179
        beq     .LC12
180
        cmp     r2, r3          /*  reached terminator? */
181
        bne     .LC11
182
        mov     r2, #0
183
        sub     r3, r1, #1
184
        strb    r2, [r3]        /*  terminate the arg string */
185
        b       .LC10
186
 
187
.LC12:
188
        mov     r1, sp          /*  point at stacked arg pointers */
189
        /* We've now got the stacked args in order reverse the */
190
#ifdef __thumb__
191
        mov     r2, r0
192
        lsl     r2, #2
193
        add     r2, sp
194
        mov     r3, sp
195
.LC15:  cmp     r2, r3
196
        bls     .LC14
197
        sub     r2, #4
198
        ldr     r4, [r2]
199
        ldr     r5, [r3]
200
        str     r5, [r2]
201
        str     r4, [r3]
202
        add     r3, #4
203
        b       .LC15
204
.LC14:
205
        /* Ensure doubleword stack alignment.  */
206
        mov     r4, sp
207
        mov     r5, #7
208
        bic     r4, r5
209
        mov     sp, r4
210
#else
211
        add     r2, sp, r0, LSL #2      /* End of args */
212
        mov     r3, sp                  /* Start of args */
213
.LC13:  cmp     r2, r3
214
        ldrhi   r4,[r2, #-4]            /* Reverse ends of list */
215
        ldrhi   r5, [r3]
216
        strhi   r5, [r2, #-4]!
217
        strhi   r4, [r3], #4
218
        bhi     .LC13
219
        /* Ensure doubleword stack alignment.  */
220
        bic     sp, sp, #7
221
#endif
222
#endif
223
 
224
#ifdef __USES_INITFINI__
225
        /* Some arm/elf targets use the .init and .fini sections
226
           to create constructors and destructors, and for these
227
           targets we need to call the _init function and arrange
228
           for _fini to be called at program exit.  */
229
        mov     r4, r0
230
        mov     r5, r1
231
        ldr     r0, .Lfini
232
        bl      FUNCTION (atexit)
233
        bl      FUNCTION (_init)
234
        mov     r0, r4
235
        mov     r1, r5
236
#endif
237
        bl      FUNCTION (main)
238
 
239
        bl      FUNCTION (exit)         /* Should not return.  */
240
 
241
#if defined(__thumb__) && !defined(__thumb2__)
242
        /* Come out of Thumb mode.  This code should be redundant.  */
243
 
244
        mov     a4, pc
245
        bx      a4
246
 
247
        .code 32
248
        .global change_back
249
change_back:
250
        /* Halt the execution.  This code should never be executed.  */
251
        /* With no debug monitor, this probably aborts (eventually).
252
           With a Demon debug monitor, this halts cleanly.
253
           With an Angel debug monitor, this will report 'Unknown SWI'.  */
254
        swi     SWI_Exit
255
#endif
256
 
257
        /* For Thumb, constants must be after the code since only
258
           positive offsets are supported for PC relative addresses.  */
259
 
260
        .align 0
261
.LC0:
262
#ifdef ARM_RDI_MONITOR
263
        .word   HeapBase
264
#else
265
#ifndef ARM_RDP_MONITOR
266
#ifdef __pe__
267
        .word   0x800000
268
#else
269
/*      .word   0x80000 */              /* Top of RAM on the PIE board.  */
270
#endif
271
#endif
272
#endif
273
#if defined(__ELF__) && !defined(__USING_SJLJ_EXCEPTIONS__)
274
        /* Protect against unhandled exceptions.  */
275
        .cantunwind
276
        .fnend
277
#endif
278
.LC1:
279
        .word   __bss_start__
280
.LC2:
281
        .word   __bss_end__
282
#ifdef __USES_INITFINI__
283
.Lfini:
284
        .word   FUNCTION(_fini)
285
#endif
286
#ifdef ARM_RDI_MONITOR
287
.LC30:
288
        .word   CommandLine
289
        .word   255
290
 
291
/*  Workspace for Angel calls.  */
292
        .data
293
/*  Data returned by monitor SWI.  */
294
.global __stack_base__
295
HeapBase:       .word   0
296
HeapLimit:      .word   0
297
__stack_base__: .word   0
298
StackLimit:     .word   0
299
CommandLine:    .space  256,0   /*  Maximum length of 255 chars handled.  */
300
#endif
301
 
302
#ifdef __pe__
303
        .section .idata$3
304
        .long   0,0,0,0,0,0,0,0
305
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.