source: trunk/libs/newlib/src/libgloss/rs6000/xil-crt0.S @ 532

Last change on this file since 532 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 5.4 KB
Line 
1/*-----------------------------------------------------------------------------
2//
3// Copyright (c) 2004, 2009 Xilinx, Inc.  All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// 1.  Redistributions source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11//
12// 2.  Redistributions in binary form must reproduce the above copyright
13// notice, this list of conditions and the following disclaimer in the
14// documentation and/or other materials provided with the distribution.
15//
16// 3.  Neither the name of Xilinx nor the names of its contributors may be
17// used to endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//
32//---------------------------------------------------------------------------*/
33
34        .file   "xil-crt0.S"
35        .section ".got2","aw"
36        .align  2
37
38.LCTOC1 = . + 32768
39
40.Lsbss_start = .-.LCTOC1
41        .long   __sbss_start
42
43.Lsbss_end = .-.LCTOC1
44        .long   __sbss_end
45
46.Lbss_start = .-.LCTOC1
47        .long   __bss_start
48
49.Lbss_end = .-.LCTOC1
50        .long   __bss_end
51
52.Lstack = .-.LCTOC1
53        .long   __stack
54
55.Lsda = .-.LCTOC1
56    .long   _SDA_BASE_                      /* address of the first small data area */
57
58.Lsda2 = .-.LCTOC1
59    .long   _SDA2_BASE_                     /* address of the second small data area */
60
61   
62        .text
63        .globl  _start
64_start:
65        bl      __cpu_init              /* Initialize the CPU first (BSP provides this) */
66
67        lis     5,.LCTOC1@h
68        ori     5,5,.LCTOC1@l
69
70        lwz     13,.Lsda(5)             /* load r13 with _SDA_BASE_ address */
71        lwz     2,.Lsda2(5)             /* load r2 with _SDA2_BASE_ address */
72
73#ifndef SIMULATOR
74        /* clear sbss */
75        lwz     6,.Lsbss_start(5)       /* calculate beginning of the SBSS */
76        lwz     7,.Lsbss_end(5)         /* calculate end of the SBSS */
77
78        cmplw   1,6,7
79        bc      4,4,.Lenclsbss          /* If no SBSS, no clearing required */
80
81        li      0,0                     /* zero to clear memory */
82        subf    8,6,7                   /* number of bytes to zero */
83        srwi.   9,8,2                   /* number of words to zero */
84        beq     .Lstbyteloopsbss        /* Check if the number of bytes was less than 4 */
85        mtctr   9       
86        addi    6,6,-4                  /* adjust so we can use stwu */
87.Lloopsbss:
88        stwu    0,4(6)                  /* zero sbss */
89        bdnz    .Lloopsbss
90
91.Lstbyteloopsbss:
92        andi.   9,8,3                   /* Calculate how many trailing bytes we have */
93        beq     0,.Lenclsbss
94        mtctr   9
95        addi    6,6,-1                  /* adjust, so we can use stbu */
96
97.Lbyteloopsbss: 
98        stbu    0,1(6)
99        bdnz    .Lbyteloopsbss
100   
101.Lenclsbss: 
102.Lstclbss:
103   
104        /* clear bss */
105        lwz     6,.Lbss_start(5)        /* calculate beginning of the BSS */
106        lwz     7,.Lbss_end(5)          /* calculate end of the BSS */
107
108        cmplw   1,6,7
109        bc      4,4,.Lenclbss           /* If no BSS, no clearing required */
110
111        li      0,0                     /* zero to clear memory */
112        subf    8,6,7                   /* number of bytes to zero */
113        srwi.   9,8,2                   /* number of words to zero */
114        beq     .Lstbyteloopbss         /* Check if the number of bytes was less than 4 */
115        mtctr   9
116        addi    6,6,-4                  /* adjust so we can use stwu */
117.Lloopbss:
118        stwu    0,4(6)                  /* zero bss */
119        bdnz    .Lloopbss
120
121.Lstbyteloopbss:   
122        andi.   9,8,3                   /* Calculate how many trailing bytes we have */
123        beq     0,.Lenclbss             /* If zero, we are done */
124        mtctr   9
125        addi    6,6,-1                  /* adjust, so we can use stbu */
126
127.Lbyteloopbss: 
128        stbu    0,1(6)
129        bdnz    .Lbyteloopbss
130   
131.Lenclbss:
132#endif /* SIMULATOR */
133
134        /* set stack pointer */
135        lwz     1,.Lstack(5)            /* stack address */
136
137        /* set up initial stack frame */
138        addi    1,1,-8                  /* location of back chain */
139        lis     0,0
140        stw     0,0(1)                  /* set end of back chain */
141       
142        /* initialize base timer to zero */
143        mtspr   0x11c,0
144        mtspr   0x11d,0
145
146#ifdef HAVE_XFPU   
147        /* On the Xilinx PPC405 and PPC440, the MSR
148           must be explicitly set to mark the prescence
149           of an FPU */
150        mfpvr   0
151        rlwinm  0,0,0,12,15
152        cmpwi   7,0,8192
153        mfmsr   0
154        ori     0,0,8192
155        beq-    7,fpu_init_done
156do_405:
157        oris    0,0,512
158fpu_init_done:
159        mtmsr   0
160#endif   
161   
162#ifdef PROFILING
163        /* Setup profiling stuff */
164        bl      _profile_init
165#endif /* PROFILING */
166
167        /* Call __init */
168        bl      __init
169
170        /* Let her rip */
171        bl      main
172
173        /* Invoke the language cleanup functions */       
174        bl      __fini
175
176#ifdef PROFILING
177        /* Cleanup profiling stuff */
178        bl      _profile_clean
179#endif /* PROFILING */
180
181        /* Call __init */
182        /* All done */
183        bl      exit
184   
185/* Trap has been removed for both simulation and hardware */
186        .globl _exit
187_exit:
188        b _exit
189
190.Lstart:
191        .size   _start,.Lstart-_start
192
Note: See TracBrowser for help on using the repository browser.