source: trunk/libs/newlib/src/libgloss/cris/lcrt0.c @ 529

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

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

File size: 3.9 KB
Line 
1/* Support for cris*-axis-linux-gnu and src/sim/cris simulator.
2   Copyright (C) 2000-2005, 2017 Axis Communications.
3   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
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. Neither the name of Axis Communications nor the names of its
13      contributors may be used to endorse or promote products derived
14      from this software without specific prior written permission.
15
16   THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS
17   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS
20   COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26   IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27   POSSIBILITY OF SUCH DAMAGE.  */
28
29#include "linunistd.h"
30#include "newlib.h"
31
32#ifdef HAVE_INITFINI_ARRAY
33#define _init __libc_init_array
34#define _fini __libc_fini_array
35#endif
36
37extern void exit (int) __attribute ((__noreturn__));
38
39__asm__ (".syntax no_register_prefix");
40
41#ifdef __ELF__
42/* This simulator magic for an earlier simulator was supposed to be
43   found two bytes before _start.  Let's keep it for sake of
44   compatibility.  Trying to emit them with an ordinary const char[]
45   and attribute section makes gcc barf; it doesn't like having the
46   same section attribute for both code and data.
47   The code is supposed to cause a crash if someone jumps to 0.  */
48__asm__
49 (
50  " .section .startup,\"ax\",@progbits\n"
51  " .byte 55,55\n"
52  " move.d 0xbadacce5,r9\n"
53  " clear.d [r9]\n"
54  " setf\n"
55  " setf\n"
56  " .previous");
57#endif
58
59__asm__
60 (
61#ifdef __AOUT__
62  " .text\n\t"
63#elif defined (__ELF__)
64  " .section .startup,\"ax\",@progbits\n"
65#endif
66  " .global __start\n"
67  "__start:\n"
68  /* SP must be set up by the simulator or the system.  */
69
70  /* Find ARGC, ARGV and ENV.  */
71  /* ARGC.  */
72  " move.d [sp],r10\n"
73
74  /* ARGV.  */
75  " move.d sp,r11\n"
76  " addq 4,r11\n"
77
78  /* ENVP.  */
79  " move.d sp,r12\n"
80  " addi r10.d,r12\n"
81  " addq 8,r12\n"
82
83  /* Terminate R9 and R6; we don't have a "console_print_etrax" or system
84     call function.  */
85  " clear.d r9\n"
86  " clear.d r6\n"
87  " move.d __start1,r13\n"
88  " jump r13\n"
89  " setf\n"
90#ifndef __AOUT__
91  /* We rely on a.out not being in .data here.  Quite fragile, but
92     covered by e.g. running the GCC test-suite for cris-unknown-aout. */
93  " .previous"
94#endif
95  );
96
97extern void _Libctors (void);
98extern void _Libdtors (void);
99
100extern void __init__start (void) __attribute ((weak));
101extern void __aout__ctors (void) __attribute ((weak));
102
103static void start1 () __asm__ ("__start1") __attribute ((__used__));
104static void
105start1 (int argc, char **argv, char **env)
106{
107#ifdef __ELF__
108  /* For ELF systems, we call _init and register _fini with atexit.  */
109  {
110    extern void _init (void);
111    extern void _fini (void);
112    _init ();
113    if (atexit (_fini) != 0)
114      exit (-1);
115  }
116#else
117  /* Constructors which may get here through the ELF .init section, when
118     linking ELF and producing a.out.  */
119  if (__init__start)
120    __init__start ();
121
122  if (__aout__ctors)
123    __aout__ctors ();
124
125  /* Call constructors in shared libraries. */
126  _Libctors ();
127
128  if (atexit (_Libdtors) != 0)
129    exit (-1);
130#endif
131
132  /* Call the user program.  */
133  exit (main (argc, argv, env));
134}
Note: See TracBrowser for help on using the repository browser.