]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/frv/crt0.S
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / frv / crt0.S
1 /* Copyright (C) 1991, 1992, 2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Library General Public License for more details.
13
14 In addition to the permissions in the GNU Lesser General Public
15 License, the Free Software Foundation gives you unlimited
16 permission to link the compiled version of this file with other
17 programs, and to distribute those programs without any restriction
18 coming from the use of this file.  (The GNU Lesser General Public
19 License restrictions do apply in other respects; for example, they
20 cover modification of the file, and distribution when not linked
21 into another program.)
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with the GNU C Library; see the file COPYING.LIB.  If
25 not, see <http://www.gnu.org/licenses/>.  */
26
27
28 /*  Based on ../i386/crt0.S and newlib's libgloss/frv/crt0.S  */
29
30 /*
31     When we enter this piece of code, the program stack looks like this:
32         argc            argument counter (integer)
33         argv[0]         program name (pointer)
34         argv[1...N]     program args (pointers)
35         argv[argc-1]    end of args (integer)
36         NULL
37         env[0...N]      environment variables (pointers)
38         NULL
39
40     Also, GR16 holds a pointer to a memory map.  */
41
42 #include <features.h>
43
44         .text
45         .global _start
46         .type   _start,%function
47 #if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__
48         .type __uClibc_main,%function
49 #else
50         .weak   _init
51         .weak   _fini
52         .type   __uClibc_start_main,%function
53 #endif
54 _start:
55         /* Make sure the stack pointer is properly aligned.  Save the
56            original value in gr21 such that we can get to arguments and
57            such from there.  */
58         mov.p   sp, gr21
59         andi    sp, #-8, sp
60         /* At program start-up, gr16 contains a pointer to a memory
61            map, that we use to relocate addresses.  */
62         call    .Lcall
63 .Lcall:
64         movsg   lr, gr4
65         sethi.p #gprelhi(.Lcall), gr5
66         setlo   #gprello(.Lcall), gr5
67         sub.p   gr4, gr5, gr4
68         /* gr4 now holds the _gp address.  */
69
70         mov     gr16, gr8
71         sethi.p #gprelhi(__ROFIXUP_LIST__), gr9
72         sethi   #gprelhi(__ROFIXUP_END__), gr10
73         setlo.p #gprello(__ROFIXUP_LIST__), gr9
74         setlo   #gprello(__ROFIXUP_END__), gr10
75         add.p   gr9, gr4, gr9
76         add     gr10, gr4, gr10
77         call    __self_reloc
78         mov.p   gr8, gr17
79         mov     gr8, gr15
80         /* gr17 now holds the self-relocated _GLOBAL_OFFSET_TABLE_
81         address, because the linker added its unrelocated address as
82         the last entry in the ROFIXUP list, and __self_reloc returns
83         the last entry, relocated.  */
84
85         /* Prepare arguments for uClibc main.  */
86         ld      @(gr21, gr0), gr8
87         slli    gr8, #2, gr10
88         add     gr21, gr10, gr10
89         addi.p  gr21, #4, gr9
90         addi    gr10, #8, gr10
91
92         /* Set up an invalid (NULL return address, NULL frame pointer)
93            callers stack frame so anybody unrolling the stack knows where
94            to stop */
95         mov     gr0, fp
96         movgs   gr0, lr
97
98 #if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__
99         /* Pass .init and .fini arguments to __uClibc_start_main().  */
100         sethi.p #gotfuncdeschi(_init), gr11
101         sethi   #gotfuncdeschi(_fini), gr12
102         setlo.p #gotfuncdesclo(_init), gr11
103         setlo   #gotfuncdesclo(_fini), gr12
104         ld.p    @(gr11, gr17), gr11
105         mov     gr17, gr15
106         ld.p    @(gr12, gr17), gr12
107         call    __uClibc_start_main
108 #else
109         mov.p   gr17, gr15
110         call    __uClibc_main
111 #endif
112
113         /* Crash if somehow `exit' returns anyways.  */
114         jmpl    @(gr0,gr0)
115 .size _start,.-_start
116
117 /* Define a symbol for the first piece of initialized data.  */
118         .data
119         .globl __data_start
120 __data_start:
121         .long 0
122         .weak data_start
123         data_start = __data_start
124