OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [i386/] [crt0.S] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Copyright (C) 1991, 1992 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 Library General Public License as
6
published by the Free Software Foundation; either version 2 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
You should have received a copy of the GNU Library General Public
15
License along with the GNU C Library; see the file COPYING.LIB.  If
16
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17
Cambridge, MA 02139, USA.  */
18
 
19
 
20
/*  Based on the code from GNU libc, but hacked up by John Beppu and Erik Andersen */
21
/*  adapted by PaX Team for ET_DYN/PIE binaries */
22
 
23
/*
24
    When we enter this piece of code, the program stack looks like this:
25
        argc            argument counter (integer)
26
        argv[0]         program name (pointer)
27
        argv[1...N]     program args (pointers)
28
        argv[argc-1]    end of args (integer)
29
        NULL
30
        env[0...N]      environment variables (pointers)
31
        NULL
32
*/
33
 
34
#include 
35
 
36
.text
37
        .align 4
38
 
39
        .global _start
40
        .type   _start,%function
41
#if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__
42
        .type   __uClibc_main,%function
43
#else
44
        .weak   _init
45
        .weak   _fini
46
        .type   __uClibc_start_main,%function
47
#endif
48
/* Stick in a dummy reference to main(), so that if an application
49
 * is linking when the main() function is in a static library (.a)
50
 * we can be sure that main() actually gets linked in */
51
        .type   main,%function
52
 
53
_start:
54
        /* locate the start of the environment variables */
55
        popl %ecx       /* Store argc into %ecx */
56
        movl %esp,%ebx  /* Store argv into ebx */
57
        movl %esp,%eax  /* Store argv into eax as well*/
58
        movl %ecx,%edx  /* Stick argc into %edx so we can do some math in a sec */
59
        leal 4(%eax,%edx,4),%eax
60
 
61
        /*  [ register layout ]
62
 
63
            sizeof(char*) == 4
64
            %ecx = argc     ; 0(esp)
65
            %ebx = argv     ; 4(esp)
66
            %eax = env      ; argv + (argc * 4) + 4
67
        */
68
 
69
        /* Set up an invalid (NULL return address, NULL frame pointer)
70
           callers stack frame so anybody unrolling the stack knows where
71
           to stop */
72
        xorl %ebp,%ebp  /* NULL */
73
        pushl %ebp      /* callers %cs */
74
        pushl %ebp      /* callers %eip (return address) */
75
        pushl %ebp      /* callers %ebp (frame pointer) */
76
        movl %esp,%ebp  /* mark callers stack frame as invalid */
77
 
78
#if defined L_Scrt0 || defined L_Scrt1
79
        call .L0
80
.L0:
81
        pop %edx
82
        addl $_GLOBAL_OFFSET_TABLE_+[.-.L0],%edx
83
#endif
84
 
85
#if (defined L_crt1 || defined L_Scrt1 || defined L_gcrt1 ) && defined __UCLIBC_CTOR_DTOR__
86
        /* Push .init and .fini arguments to __uClibc_start_main() on the stack */
87
#ifdef L_Scrt1
88
        pushl _fini@GOT(%edx)
89
        pushl _init@GOT(%edx)
90
#else
91
        pushl $_fini
92
        pushl $_init
93
#endif
94
 
95
        /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */
96
        pushl %eax      /* Environment pointer */
97
        pushl %ebx      /* Argument pointer */
98
        pushl %ecx      /* And the argument count */
99
 
100
        /* Ok, now run uClibc's main() -- shouldn't return */
101
#ifdef L_Scrt1
102
        call *__uClibc_start_main@GOT(%edx)
103
#else
104
        call __uClibc_start_main
105
#endif
106
#else
107
        /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */
108
        pushl %eax      /* Environment pointer */
109
        pushl %ebx      /* Argument pointer */
110
        pushl %ecx      /* And the argument count */
111
 
112
#ifdef L_Scrt0
113
        call *__uClibc_main@GOT(%edx)
114
#else
115
        call __uClibc_main
116
#endif
117
#endif
118
 
119
        /* Crash if somehow `exit' returns anyways.  */
120
        hlt
121
.size _start,.-_start
122
 
123
 
124
#if defined L_gcrt1 && defined __UCLIBC_PROFILING__
125
# include "./gmon-start.S"
126
#endif
127
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.