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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [arm/] [crt0.S] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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