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

Subversion Repositories or1k

[/] [or1k/] [branches/] [newlib/] [newlib/] [newlib/] [libc/] [sys/] [arm/] [crt0.S] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
#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
#define FUNCTION( name ) CONCAT ( _ , name)
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
change_mode:
75
#endif
76
 
77
        bl      FUNCTION (memset)
78
#if !defined (ARM_RDP_MONITOR) && !defined (ARM_RDI_MONITOR)
79
        mov     r0, #0          /*  no arguments  */
80
        mov     r1, #0          /*  no argv either */
81
#else
82
        /* Need to set up standard file handles */
83
        bl      FUNCTION (initialise_monitor_handles)
84
 
85
#ifdef ARM_RDP_MONITOR
86
        swi     SWI_GetEnv      /*  sets r0 to point to the command line */
87
        mov     r1, r0
88
#else
89
        mov     r0, #AngelSWI_Reason_GetCmdLine
90
        adr     r1, LC30        /*  Space for command line */
91
        swi     AngelSWI
92
        ldr     r1, LC30
93
#endif
94
        /*  Parse string at r1 */
95
        mov     r0, #0          /*  count of arguments so far */
96
LC10:
97
/*  Skip leading blanks */
98
#ifdef __thumb__
99
        ldrb    r3, [r1]
100
        add     r1, #1
101
#else
102
        ldrb    r3, [r1], #1
103
#endif
104
        cmp     r3, #0
105
        beq     LC12
106
        cmp     r3, #' '
107
        beq     LC10
108
 
109
/*  See whether we are scanning a string */
110
        cmp     r3, #'"'
111
#ifdef __thumb__
112
        beq     LC20
113
        cmp     r3, #'\''
114
        bne     LC21
115
LC20:
116
        mov     r2, r3
117
        b       LC22
118
 
119
LC21:
120
        mov     r2, #' '        /*  terminator type */
121
        sub     r1, r1, #1      /*  adjust back to point at start char */
122
LC22:
123
#else
124
        cmpne   r3, #'\''
125
        moveq   r2, r3
126
        movne   r2, #' '        /*  terminator type */
127
        subne   r1, r1, #1      /*  adjust back to point at start char */
128
#endif
129
 
130
/*  Stack a pointer to the current argument */
131
#ifdef __thumb__
132
        push    {r1}
133
#else
134
        stmfd   sp!, {r1}
135
#endif
136
        add     r0, r0, #1
137
LC11:
138
#ifdef __thumb__
139
        ldrb    r3, [r1]
140
        add     r1, #1
141
#else
142
        ldrb    r3, [r1], #1
143
#endif
144
        cmp     r3, #0
145
        beq     LC12
146
        cmp     r2, r3          /*  reached terminator? */
147
        bne     LC11
148
        mov     r2, #0
149
        sub     r3, r1, #1
150
        strb    r2, [r3]        /*  terminate the arg string */
151
        b       LC10
152
 
153
LC12:
154
        mov     r1, sp          /*  point at stacked arg pointers */
155
        /* We've now got the stacked args in order reverse the */
156
#ifdef __thumb__
157
        mov     r2, r0
158
        lsl     r2, #2
159
        add     r2, sp
160
        mov     r3, sp
161
LC15:   cmp     r2, r3
162
        bls     LC14
163
        sub     r2, #4
164
        ldr     r4, [r2]
165
        ldr     r5, [r3]
166
        str     r5, [r2]
167
        str     r4, [r3]
168
        add     r3, #4
169
        b       LC15
170
LC14:
171
#else
172
        add     r2, sp, r0, LSL #2      /* End of args */
173
        mov     r3, sp                  /* Start of args */
174
LC13:   cmp     r2, r3
175
        ldrhi   r4,[r2, #-4]            /* Reverse ends of list */
176
        ldrhi   r5, [r3]
177
        strhi   r5, [r2, #-4]!
178
        strhi   r4, [r3], #4
179
        bhi     LC13
180
#endif
181
 
182
#endif
183
        bl      FUNCTION (main)
184
 
185
        bl      FUNCTION (exit)         /* Should not return */
186
 
187
#ifdef __thumb__
188
        /* Come out of Thumb mode... This code should be redundant...   */
189
 
190
        mov     a4, pc
191
        bx      a4
192
 
193
        .code 32
194
        .global change_back
195
change_back:
196
        /* Halt the execution.  This code should never be executed.  */
197
        /*
198
        ** With no debug monitor, this probably aborts (eventually).
199
        ** With a Demon debug monitor, this halts cleanly.
200
        ** With an Angel debug monitor, this will report 'Unknown SWI'.
201
        */
202
        swi     SWI_Exit
203
#endif
204
 
205
        /* For Thumb, constants must be after the code since only
206
        positive offsets are supported for PC relative addresses. */
207
 
208
        .align 0
209
LC0:
210
#ifdef ARM_RDI_MONITOR
211
        .word   HeapBase
212
#else
213
#ifndef ARM_RDP_MONITOR
214
#ifdef __pe__
215
        .word   0x800000
216
#else
217
/*      .word   0x80000 */              /* Top of RAM on the PIE board */
218
#endif
219
#endif
220
#endif
221
LC1:
222
        .word   __bss_start__
223
LC2:
224
        .word   __bss_end__
225
 
226
#ifdef ARM_RDI_MONITOR
227
LC30:   .word   CommandLine
228
 
229
/*  Workspace for Angel calls. */
230
        .data
231
/*  Data returned by monitor SWI */
232
HeapBase:       .word   0
233
HeapLimit:      .word   0
234
StackBase:      .word   0
235
StackLimit:     .word   0
236
CommandLine:    .space  256,0   /*  Maximum length of 255 chars handled */
237
#endif
238
 
239
#ifdef __pe__
240
        .section .idata$3
241
        .long   0,0,0,0,0,0,0,0
242
#endif
243
 

powered by: WebSVN 2.1.0

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