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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [newlib/] [newlib/] [libc/] [sys/] [arm/] [crt0.S] - Blame information for rev 1782

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 56 joel
#error __USER_LABEL_PREFIX is not defined
11 39 lampret
#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 56 joel
        ldr     sl, .LC2        /*  stack limit is at end of data */
31 39 lampret
        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 56 joel
        adr     r1, .LC0        /*  point at ptr to 4 words to receive data */
38 39 lampret
        swi     AngelSWI_ARM    /*  We are always in ARM mode for startup */
39 56 joel
        ldr     r0, .LC0        /*  point at values read */
40 39 lampret
        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 56 joel
        ldr     r3, .LC0
47 39 lampret
        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 56 joel
        ldr     a1, .LC1                /* First arg: start of memory block */
63
        ldr     a3, .LC2
64 39 lampret
        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 56 joel
        .global __change_mode
74
        .thumb_func
75
__change_mode:
76 39 lampret
#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 56 joel
        adr     r1, .LC30       /*  Space for command line */
92 39 lampret
        swi     AngelSWI
93 56 joel
        ldr     r1, .LC30
94 39 lampret
#endif
95
        /*  Parse string at r1 */
96
        mov     r0, #0          /*  count of arguments so far */
97 56 joel
.LC10:
98 39 lampret
/*  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 56 joel
        beq     .LC12
107 39 lampret
        cmp     r3, #' '
108 56 joel
        beq     .LC10
109 39 lampret
 
110
/*  See whether we are scanning a string */
111
        cmp     r3, #'"'
112
#ifdef __thumb__
113 56 joel
        beq     .LC20
114 39 lampret
        cmp     r3, #'\''
115 56 joel
        bne     .LC21
116
.LC20:
117 39 lampret
        mov     r2, r3
118 56 joel
        b       .LC22
119 39 lampret
 
120 56 joel
.LC21:
121 39 lampret
        mov     r2, #' '        /*  terminator type */
122
        sub     r1, r1, #1      /*  adjust back to point at start char */
123 56 joel
.LC22:
124 39 lampret
#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 56 joel
.LC11:
139 39 lampret
#ifdef __thumb__
140
        ldrb    r3, [r1]
141
        add     r1, #1
142
#else
143
        ldrb    r3, [r1], #1
144
#endif
145
        cmp     r3, #0
146 56 joel
        beq     .LC12
147 39 lampret
        cmp     r2, r3          /*  reached terminator? */
148 56 joel
        bne     .LC11
149 39 lampret
        mov     r2, #0
150
        sub     r3, r1, #1
151
        strb    r2, [r3]        /*  terminate the arg string */
152 56 joel
        b       .LC10
153 39 lampret
 
154 56 joel
.LC12:
155 39 lampret
        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 56 joel
.LC15:  cmp     r2, r3
163
        bls     .LC14
164 39 lampret
        sub     r2, #4
165
        ldr     r4, [r2]
166
        ldr     r5, [r3]
167
        str     r5, [r2]
168
        str     r4, [r3]
169
        add     r3, #4
170 56 joel
        b       .LC15
171
.LC14:
172 39 lampret
#else
173
        add     r2, sp, r0, LSL #2      /* End of args */
174
        mov     r3, sp                  /* Start of args */
175 56 joel
.LC13:  cmp     r2, r3
176 39 lampret
        ldrhi   r4,[r2, #-4]            /* Reverse ends of list */
177
        ldrhi   r5, [r3]
178
        strhi   r5, [r2, #-4]!
179
        strhi   r4, [r3], #4
180 56 joel
        bhi     .LC13
181 39 lampret
#endif
182
 
183
#endif
184
        bl      FUNCTION (main)
185
 
186
        bl      FUNCTION (exit)         /* Should not return */
187
 
188
#ifdef __thumb__
189
        /* Come out of Thumb mode... This code should be redundant...   */
190
 
191
        mov     a4, pc
192
        bx      a4
193
 
194
        .code 32
195
        .global change_back
196
change_back:
197
        /* Halt the execution.  This code should never be executed.  */
198
        /*
199
        ** With no debug monitor, this probably aborts (eventually).
200
        ** With a Demon debug monitor, this halts cleanly.
201
        ** With an Angel debug monitor, this will report 'Unknown SWI'.
202
        */
203
        swi     SWI_Exit
204
#endif
205
 
206
        /* For Thumb, constants must be after the code since only
207
        positive offsets are supported for PC relative addresses. */
208
 
209
        .align 0
210 56 joel
.LC0:
211 39 lampret
#ifdef ARM_RDI_MONITOR
212
        .word   HeapBase
213
#else
214
#ifndef ARM_RDP_MONITOR
215
#ifdef __pe__
216
        .word   0x800000
217
#else
218
/*      .word   0x80000 */              /* Top of RAM on the PIE board */
219
#endif
220
#endif
221
#endif
222 56 joel
.LC1:
223 39 lampret
        .word   __bss_start__
224 56 joel
.LC2:
225 39 lampret
        .word   __bss_end__
226
 
227
#ifdef ARM_RDI_MONITOR
228 56 joel
.LC30:  .word   CommandLine
229 39 lampret
 
230
/*  Workspace for Angel calls. */
231
        .data
232
/*  Data returned by monitor SWI */
233
HeapBase:       .word   0
234
HeapLimit:      .word   0
235
StackBase:      .word   0
236
StackLimit:     .word   0
237
CommandLine:    .space  256,0   /*  Maximum length of 255 chars handled */
238
#endif
239
 
240
#ifdef __pe__
241
        .section .idata$3
242
        .long   0,0,0,0,0,0,0,0
243
#endif
244
 

powered by: WebSVN 2.1.0

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