source: trunk/libs/newlib/src/libgloss/m32c/crt0.S @ 520

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

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

File size: 4.2 KB
RevLine 
[444]1/*
2
3Copyright (c) 2005,2008 Red Hat Incorporated.
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9    Redistributions of source code must retain the above copyright
10    notice, this list of conditions and the following disclaimer.
11
12    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    The name of Red Hat Incorporated may not be used to endorse
17    or promote products derived from this software without specific
18    prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31*/
32
33#if defined(__r8c_cpu__) || defined(__m16c_cpu__)
34#define A16
35#define A(n,w) n
36#define W w
37#define ALIGN 1
38#else
39#define A24
40#define A(n,w) w
41#define W l
42#define ALIGN 2
43#endif
44
45        .section ".resetvec","ax",@progbits
46        .long   _start
47
48        .text
49
50        .global _start
51_start:
52.LFB2:
53        fclr    U       /* One stack for user and interrupts */
54        ldc     #__stack,sp
55
56#ifdef A16
57        mov.b   #%hi8(__romdatastart),r1h
58        mov.w   #%lo16(__romdatastart),a0
59        mov.w   #__datastart,a1
60#else
61        mov.l   #__romdatastart,a0
62        mov.l   #__datastart,a1
63#endif
64        mov.w   #__romdatacopysize,r3
65        shl.w   #-1,r3
66        smovf.w
67
68#ifdef A16
69        mov.w   #__bssstart,a1
70#else
71        mov.l   #__bssstart,a1
72#endif
73        mov.w   #__bsssize,r3
74        shl.w   #-1,r3
75        mov.w   #0,r0
76        sstr.w
77
78#ifdef A16
79        ldc     #%lo16(__var_vects),intbl
80        ldc     #%hi16(__var_vects),intbh
81#else
82        ldc     #__var_vects,intb
83#endif
84
85        fset    I
86        jsr.a   __m32c_init
87
88        jsr.a   _main
89.LFE2:
90
91#ifdef A24
92        /* rv in r0, ok for arg0 */
93#else
94        mov.w   r0,r1
95#endif
96
97        jsr.a   _exit
98
99        .text
100
101        .global _m32c_run_preinit_array
102        .type   _m32c_run_preinit_array,@function
103_m32c_run_preinit_array:
104        mov.W   #__preinit_array_start,a0
105        mov.W   #__preinit_array_end,a1
106        jmp.w   _m32c_run_inilist
107
108        .global _m32c_run_init_array
109        .type   _m32c_run_init_array,@function
110_m32c_run_init_array:
111        mov.W   #__init_array_start,a0
112        mov.W   #__init_array_end,a1
113        jmp.w   _m32c_run_inilist
114
115        .global _m32c_run_fini_array
116        .type   _m32c_run_fini_array,@function
117_m32c_run_fini_array:
118        mov.W   #__fini_array_start,a0
119        mov.W   #__fini_array_end,a1
120        /* fall through */
121
122_m32c_run_inilist:
123next_inilist:
124        cmp.W   a0,a1
125        jeq     done_inilist
126        pushm   a0,a1
127        mov.W   [a0],a0
128#ifdef A16
129        mov.b:s #0,a1   /* zero extends */
130        jsri.a  a1a0
131#else
132        jsri.a  a0
133#endif
134        popm    a0,a1
135        add.W   A(#2,#4),a0
136        jmp.b   next_inilist
137done_inilist:
138        rts
139
140        .section        .init,"ax",@progbits
141
142        .global __m32c_init
143__m32c_init:
144        enter   #0
145
146        .section        .fini,"ax",@progbits
147
148        .global __m32c_fini
149__m32c_fini:
150        enter   #0
151        jsr.a   _m32c_run_fini_array
152
153
154;;; Provide Dwarf unwinding information that will help GDB stop
155;;; backtraces at the right place.  This is stolen from assembly
156;;; code generated by GCC with -dA.
157        .section        .debug_frame,"",@progbits
158.Lframe0:
159        .4byte  .LECIE0-.LSCIE0 ; Length of Common Information Entry
160.LSCIE0:
161        .4byte  0xffffffff      ; CIE Identifier Tag
162        .byte   0x1     ; CIE Version
163        .ascii "\0"     ; CIE Augmentation
164        .uleb128 0x1    ; CIE Code Alignment Factor
165        .sleb128 -1     ; CIE Data Alignment Factor
166        .byte   0xd     ; CIE RA Column
167        .byte   0xc     ; DW_CFA_def_cfa
168        .uleb128 0xc
169        .uleb128 0x3
170        .byte   0x8d    ; DW_CFA_offset, column 0xd
171        .uleb128 0x3
172        .p2align ALIGN
173.LECIE0:
174.LSFDE0:
175        .4byte  .LEFDE0-.LASFDE0        ; FDE Length
176.LASFDE0:
177        .4byte  .Lframe0        ; FDE CIE offset
178        .4byte  .LFB2           ; FDE initial location
179        .4byte  .LFE2-.LFB2     ; FDE address range
180        .byte   0xf             ; DW_CFA_def_cfa_expression
181        .uleb128 1              ; length of expression
182        .byte   0x30            ; DW_OP_lit0
183        .p2align ALIGN
184.LEFDE0:
185
186        .text
Note: See TracBrowser for help on using the repository browser.