1 /* Support for cris*-axis-linux-gnu and src/sim/cris simulator.
2 Copyright (C) 2000-2005, 2017, 2023, 2024 Axis Communications.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
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.
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. */
29 #include "linunistd.h"
33 #ifdef _HAVE_INITFINI_ARRAY
34 #define _init __libc_init_array
35 #define _fini __libc_fini_array
38 extern void exit (int) __attribute ((__noreturn__
));
40 __asm__ (".syntax no_register_prefix");
43 /* This simulator magic for an earlier simulator was supposed to be
44 found two bytes before _start. Let's keep it for sake of
45 compatibility. Trying to emit them with an ordinary const char[]
46 and attribute section makes gcc barf; it doesn't like having the
47 same section attribute for both code and data.
48 The code is supposed to cause a crash if someone jumps to 0. */
51 " .section .startup,\"ax\",@progbits\n"
53 " move.d 0xbadacce5,r9\n"
64 #elif defined (__ELF__)
65 " .section .startup,\"ax\",@progbits\n"
69 /* SP must be set up by the simulator or the system. */
71 /* Find ARGC, ARGV and ENV. */
84 /* Terminate R9 and R6; we don't have a "console_print_etrax" or system
88 " move.d __start1,r13\n"
92 /* We rely on a.out not being in .data here. Quite fragile, but
93 covered by e.g. running the GCC test-suite for cris-unknown-aout. */
98 extern void _Libctors (void);
99 extern void _Libdtors (void);
101 extern void __init__start (void) __attribute ((weak
));
102 extern void __aout__ctors (void) __attribute ((weak
));
103 extern int main (int argc
, char **argv
, char **env
);
105 static void start1 (int, char **, char **) __asm__ ("__start1") __attribute ((__used__
));
107 start1 (int argc
, char **argv
, char **env
)
110 /* For ELF systems, we call _init and register _fini with atexit. */
112 extern void _init (void);
113 extern void _fini (void);
115 if (atexit (_fini
) != 0)
119 /* Constructors which may get here through the ELF .init section, when
120 linking ELF and producing a.out. */
127 /* Call constructors in shared libraries. */
130 if (atexit (_Libdtors
) != 0)
134 /* Call the user program. */
135 exit (main (argc
, argv
, env
));