Update.
[glibc.git] / sysdeps / m68k / elf / start.S
blobcf286f1cedfa9820fb5aca620560d39bf0b6da0a
1 /* Startup code compliant to the ELF m68k ABI.
2    Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
20 /* This is the canonical entry point, usually the first thing in the text
21    segment.  The SVR4/m68k ABI says that when the entry point runs,
22    most registers' values are unspecified, except for:
24    %a1          Contains a function pointer to be registered with `atexit'.
25                 This is how the dynamic linker arranges to have DT_FINI
26                 functions called for shared libraries that have been loaded
27                 before this code runs.
29    %sp          The stack contains the arguments and environment:
30                 0(%sp)                  argc
31                 4(%sp)                  argv[0]
32                 ...
33                 (4*argc)(%sp)           NULL
34                 (4*(argc+1))(%sp)       envp[0]
35                 ...
36                                         NULL
39         .text
40         .globl _start
41         .type _start,@function
42 _start:
43         /* Clear the frame pointer.  The ABI suggests this be done, to mark
44            the outermost frame obviously.  */
45         sub.l %fp, %fp
47         /* Extract the arguments as encoded on the stack and set up the
48            arguments for `main': argc, argv.  envp will be determined
49            later in __libc_start_main.  */
50         move.l (%sp)+, %d0      /* Pop the argument count.  */
51         move.l %sp, %a0         /* The argument vector starts just at the
52                                    current stack top.  */
54         /* Provide the highest stack address to the user code (for stacks
55            which grow downward).  */
56         pea (%sp)
58         pea (%a1)               /* Push address of the shared library
59                                    termination function.  */
61         /* Push the address of our own entry points to `.fini' and
62            `.init'.  */
63         pea _fini
64         pea _init
66         pea (%a0)               /* Push second argument: argv.  */
67         move.l %d0, -(%sp)      /* Push first argument: argc.  */
69         pea main
71         /* Call the user's main function, and exit with its value.  But
72            let the libc call main.  */
73         jbsr __libc_start_main
75         illegal                 /* Crash if somehow `exit' does return.  */
77 /* Define a symbol for the first piece of initialized data.  */
78         .data
79         .globl __data_start
80 __data_start:
81         .long 0
82         .weak data_start
83         data_start = __data_start