source: trunk/libs/newlib/src/libgloss/epiphany/crt0.S @ 479

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

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

File size: 4.1 KB
RevLine 
[444]1# C Startup for EPIPHANY
2
3# Copyright (c) 2011, Adapteva, Inc.
4# All rights reserved.
5
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#  * Redistributions of source code must retain the above copyright notice,
9#    this list of conditions and the following disclaimer.
10#  * Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#  * Neither the name of Adapteva nor the names of its contributors may be
14#    used to endorse or promote products derived from this software without
15#    specific prior written permission.
16
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28
29
30.section IVT,"a",@progbits     ;
31        .global _start;
32        .type   _start, %function;
33_start:
34                .balign 4 ;
35         b .normal_start
36
37        .balign 4 ; 0x4
38         b .sw_exception_v
39
40                .balign 4 ; 0x8
41         b .page_miss_v;
42
43                .balign 4 ; 0xc
44         b .timer0_expired_v
45
46                .balign 4 ; 0x10
47         b .timer1_expired_v
48
49                .balign 4 ; 0x14
50                b .message_v
51
52                .balign 4 ; 0x18
53                 b .dma0_v
54
55                .balign 4 ; 0x1c
56                 b .dma1_v
57
58                .balign 4 ; 0x20
59                 b .wand_v
60
61                .balign 4 ; 0x24
62                 b .soft_v
63
64.size  _start, .-_start
65
66.section RESERVED_CRT0,"a",@progbits     ;
67
68.global .normal_start;
69.balign 4
70.type   .normal_start, %function
71.normal_start:
72        mov  r3,%low(_external_start)
73        movt r3,%high(_external_start)
74        jalr r3
75.size  .normal_start, .-.normal_start
76
77
78
79
80.section .text;
81        .org    0x0000                  ; Relative to start of text section
82        .global _external_start
83        .type   _external_start, %function
84_external_start:
85
86        .align  4
87
88        ;; Initialise the stack pointer and frame pointer. Hopefully __stack
89        ;; is somewhere meaningful.
90        mov     sp,%low(___stack)
91        movt    sp,%high(___stack)
92        mov     fp,sp
93
94        ;; Zero the data space
95        mov     r0,%low(___bss_start)
96        movt    r0,%high(___bss_start)
97        mov     r1,%low(_end)
98        movt    r1,%high(_end)
99        mov     r2,#0
100        mov     r3,#0
101.L0_init_:
102        strd    r2,[r0],+#1
103        sub     r5,r1,r0
104        bne     .L0_init_
105
106        ;;  Setup destructors to be called from exit if main never returns
107#if 0
108        mov     r0,%low(fini)
109        movt    r0,%high(fini)
110        mov r2,%low(_atexit)
111        movt r2,%high(_atexit)
112        jalr r2
113#else
114        ; calling atexit drags in malloc, so instead poke the function
115        ; address directly into the reent structure
116        mov     r2,%low(__impure_ptr)
117        movt    r2,%high(__impure_ptr)
118        ldr     r2,[r2]
119        mov     r1,%low(fini)
120        movt    r1,%high(fini)
121#ifdef __STRUCT_ALIGN_64__
122#error
123        add     r2,r2,need_to_find_out; &_GLOBAL_REENT->atexit0
124        str     r2, [r2,-1];??or -2?; _GLOBAL_REENT->atexit
125        mov     r0, 1
126        str     r0, [r2,1]      ; _GLOBAL_REENT->atexit0._ind
127        str     r1, [r2,2]      ; _GLOBAL_REENT->atexit0._fns[0]
128#else  /* !__STRUCT_ALIGN_64__ */
129        add     r0,r2,0x14c     ; &_GLOBAL_REENT->atexit0
130        str     r0, [r0,-1]     ; _GLOBAL_REENT->atexit
131        mov     r0, 1
132        strd    r0, [r2,0x2a]   ; _GLOBAL_REENT->atexit0._ind
133#endif /* !__STRUCT_ALIGN_64__ */
134#endif /* !0 */
135        ;; Call global and static constructors
136        mov r2,%low(init)
137        movt r2,%high(init)
138        jalr r2
139
140
141        ;;return from reset ISR
142        mov R0,%low(RDS)
143        movt R0,%high(RDS)
144        movts iret,r0
145        rti
146RDS:
147
148        ;;  Initialise argc, argv and envp to empty and call main
149        mov     r0,#0
150        mov     r1,#0
151        mov     r2,#0
152        mov r3,%low(_main)
153        movt r3,%high(_main)
154        jalr r3
155        ;;bl    _main
156
157        ;; Call exit
158        mov r3,%low(_exit)
159        movt r3,%high(_exit)
160        jalr r3
161        ;;bl    _exit
162
163        ;; Should never reach here
164        idle
165
166.size   _external_start, .-_external_start
Note: See TracBrowser for help on using the repository browser.