sol2-c1.asm revision 52284
1281348Scy! crt1.s for sparc & sparcv9 (SunOS 5) 2281348Scy 3281348Scy! Copyright (C) 1992 Free Software Foundation, Inc. 4281348Scy! Written By David Vinayak Henkel-Wallace, June 1992 5281348Scy! 6281348Scy! This file is free software; you can redistribute it and/or modify it 7281348Scy! under the terms of the GNU General Public License as published by the 8281348Scy! Free Software Foundation; either version 2, or (at your option) any 9281348Scy! later version. 10281348Scy! 11281348Scy! In addition to the permissions in the GNU General Public License, the 12281348Scy! Free Software Foundation gives you unlimited permission to link the 13281348Scy! compiled version of this file with other programs, and to distribute 14281348Scy! those programs without any restriction coming from the use of this 15281348Scy! file. (The General Public License restrictions do apply in other 16281348Scy! respects; for example, they cover modification of the file, and 17281348Scy! distribution when not linked into another program.) 18281348Scy! 19281348Scy! This file is distributed in the hope that it will be useful, but 20281348Scy! WITHOUT ANY WARRANTY; without even the implied warranty of 21281348Scy! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22281348Scy! General Public License for more details. 23281348Scy! 24281348Scy! You should have received a copy of the GNU General Public License 25281348Scy! along with this program; see the file COPYING. If not, write to 26281348Scy! the Free Software Foundation, 59 Temple Place - Suite 330, 27281348Scy! Boston, MA 02111-1307, USA. 28281348Scy! 29281348Scy! As a special exception, if you link this library with files 30281348Scy! compiled with GCC to produce an executable, this does not cause 31281348Scy! the resulting executable to be covered by the GNU General Public License. 32281348Scy! This exception does not however invalidate any other reasons why 33330567Sgordon! the executable file might be covered by the GNU General Public License. 34281348Scy! 35281348Scy 36281348Scy! This file takes control of the process from the kernel, as specified 37281348Scy! in section 3 of the SVr4 ABI. 38281348Scy! This file is the first thing linked into any executable. 39281348Scy 40281348Scy#ifdef __sparcv9 41281348Scy#define CPTRSIZE 8 42281348Scy#define CPTRSHIFT 3 43281348Scy#define STACK_BIAS 2047 44281348Scy#define ldn ldx 45281348Scy#define stn stx 46281348Scy#define setn(s, scratch, dst) setx s, scratch, dst 47281348Scy#else 48281348Scy#define CPTRSIZE 4 49281348Scy#define CPTRSHIFT 2 50281348Scy#define STACK_BIAS 0 51281348Scy#define ldn ld 52281348Scy#define stn st 53281348Scy#define setn(s, scratch, dst) set s, dst 54281348Scy#endif 55281348Scy 56281348Scy .section ".text" 57281348Scy .proc 022 58281348Scy .global _start 59281348Scy 60281348Scy_start: 61281348Scy mov 0, %fp ! Mark bottom frame pointer 62281348Scy ldn [%sp + (16 * CPTRSIZE) + STACK_BIAS], %l0 ! argc 63281348Scy add %sp, (17 * CPTRSIZE) + STACK_BIAS, %l1 ! argv 64281348Scy 65281348Scy ! Leave some room for a call. Sun leaves 32 octets (to sit on 66281348Scy ! a cache line?) so we do too. 67281348Scy#ifdef __sparcv9 68281348Scy sub %sp, 48, %sp 69281348Scy#else 70281348Scy sub %sp, 32, %sp 71281348Scy#endif 72281348Scy 73281348Scy ! %g1 may contain a function to be registered w/atexit 74281348Scy orcc %g0, %g1, %g0 75281348Scy#ifdef __sparcv9 76281348Scy be %xcc, .nope 77281348Scy#else 78281348Scy be .nope 79281348Scy#endif 80281348Scy mov %g1, %o0 81281348Scy call atexit 82281348Scy nop 83281348Scy.nope: 84281348Scy ! Now make sure constructors and destructors are handled. 85281348Scy setn(_fini, %o1, %o0) 86281348Scy call atexit, 1 87281348Scy nop 88281348Scy call _init, 0 89281348Scy nop 90281348Scy 91281348Scy ! We ignore the auxiliary vector; there is no defined way to 92281348Scy ! access those data anyway. Instead, go straight to main: 93281348Scy mov %l0, %o0 ! argc 94281348Scy mov %l1, %o1 ! argv 95281348Scy ! Skip argc words past argv, to env: 96281348Scy sll %l0, CPTRSHIFT, %o2 97281348Scy add %o2, CPTRSIZE, %o2 98281348Scy add %l1, %o2, %o2 ! env 99281348Scy setn(_environ, %o4, %o3) 100281348Scy stn %o2, [%o3] ! *_environ 101281348Scy call main, 4 102281348Scy nop 103281348Scy call exit, 0 104281348Scy nop 105281348Scy call _exit, 0 106281348Scy nop 107281348Scy ! We should never get here. 108281348Scy 109281348Scy .type _start,#function 110281348Scy .size _start,.-_start 111281348Scy