1! crt1.s for sparc & sparcv9 (SunOS 5)
2
3!   Copyright (C) 1992-2021 Free Software Foundation, Inc.
4!   Written By David Vinayak Henkel-Wallace, June 1992
5!
6! This file is free software; you can redistribute it and/or modify it
7! under the terms of the GNU General Public License as published by the
8! Free Software Foundation; either version 3, or (at your option) any
9! later version.
10!
11! This file is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14! General Public License for more details.
15!
16! Under Section 7 of GPL version 3, you are granted additional
17! permissions described in the GCC Runtime Library Exception, version
18! 3.1, as published by the Free Software Foundation.
19!
20! You should have received a copy of the GNU General Public License and
21! a copy of the GCC Runtime Library Exception along with this program;
22! see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23! <http://www.gnu.org/licenses/>.
24
25! This file takes control of the process from the kernel, as specified
26! in section 3 of the SVr4 ABI.
27! This file is the first thing linked into any executable.
28
29#ifdef __sparcv9
30#define	CPTRSIZE	8
31#define	CPTRSHIFT	3
32#define	STACK_BIAS	2047
33#define	ldn		ldx
34#define	stn		stx
35#define setn(s, scratch, dst)	setx s, scratch, dst
36#else
37#define	CPTRSIZE	4
38#define	CPTRSHIFT	2
39#define	STACK_BIAS	0
40#define	ldn		ld
41#define	stn		st
42#define setn(s, scratch, dst)	set s, dst
43#endif
44
45	.section	".text"
46	.proc	022
47	.global	_start
48
49_start:
50	mov	0, %fp		! Mark bottom frame pointer
51	ldn	[%sp + (16 * CPTRSIZE) + STACK_BIAS], %l0	! argc
52	add	%sp, (17 * CPTRSIZE) + STACK_BIAS, %l1		! argv
53
54	! Leave some room for a call.  Sun leaves 32 octets (to sit on
55	! a cache line?) so we do too.
56#ifdef __sparcv9
57	sub	%sp, 48, %sp
58#else
59	sub	%sp, 32, %sp
60#endif
61
62	! %g1 may contain a function to be registered w/atexit
63	orcc	%g0, %g1, %g0
64#ifdef __sparcv9
65	be	%xcc, .nope
66#else
67	be	.nope
68#endif
69	mov	%g1, %o0
70	call	atexit
71	nop
72.nope:
73	! Now make sure constructors and destructors are handled.
74	setn(_fini, %o1, %o0)
75	call	atexit, 1
76	nop
77	call	_init, 0
78	nop
79
80	! We ignore the auxiliary vector; there is no defined way to
81	! access those data anyway.  Instead, go straight to main:
82	mov	%l0, %o0	! argc
83	mov	%l1, %o1	! argv
84#ifdef GCRT1
85	setn(___Argv, %o4, %o3)
86	stn	%o1, [%o3]      ! *___Argv
87#endif
88	! Skip argc words past argv, to env:
89	sll	%l0, CPTRSHIFT, %o2
90	add	%o2, CPTRSIZE, %o2
91	add	%l1, %o2, %o2	! env
92	setn(_environ, %o4, %o3)
93	stn	%o2, [%o3]	! *_environ
94	call	main, 4
95	nop
96	call	exit, 0
97	nop
98	call	_exit, 0
99	nop
100	! We should never get here.
101
102	.type	_start,#function
103	.size	_start,.-_start
104