summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/bfin/crt1.S
blob: ead8dbfbea3f655591a57def8c02f69af392f585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.

This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB.  If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.  */


/* When we enter this piece of code, the user stack looks like this:
*      argc            argument counter (integer)
*      argv[0]         program name (pointer)
*      argv[1...N]     program args (pointers)
*      NULL
*      env[0...N]      environment variables (pointers)
*      NULL
	
*   When we are done here, we want
*	R0=argc
*	R1=*argv[0]
*	R2=*envp[0]  
*/

#include <features.h>

.text
.align 2
.global __start;
.type	__start,STT_FUNC;
.global ___uClibc_main;
.type	___uClibc_main,STT_FUNC;

/* Stick in a dummy reference to main(), so that if an application
 * is linking when the main() function is in a static library (.a)
 * we can be sure that main() actually gets linked in */

.type	_main,STT_FUNC;

__start:

#ifdef __BFIN_FDPIC__
	/* P0 contains a pointer to the program's load map.  */
	call	.Lcall;
.Lcall:
	R4 = RETS;
	SP += -12;
	R0.L = .Lcall;
	R0.H = .Lcall;
	R1.L = __ROFIXUP_LIST__;
	R1.H = __ROFIXUP_LIST__;
	R2.L = __ROFIXUP_END__;
	R2.H = __ROFIXUP_END__;
	R1 = R1 - R0;
	R1 = R1 + R4;
	R2 = R2 - R0;
	R2 = R2 + R4;
	R0 = P0;
	CALL	___self_reloc;
	SP += 12;
	P3 = R0;
#endif

/*	clear the frame pointer and the L registers.  */
	FP = 0;
	L0 = 0;
	L1 = 0;
	L2 = 0;
	L3 = 0;
	
/*	Load register R1 (argc) from the stack to its final resting place */
	P0 = SP;
	R1 = [P0++];

/*	Copy argv pointer into R2 -- which its final resting place */
	R2 = P0;

/*	Skip to the end of argv and put a pointer to the environment in
	[SP + 12] */
	R3 = R1;
	R3 <<= 2;
	R3 += 4;
	R3 = R2 + R3;

	SP += -24;
	[SP + 12] = R3;

/*	Ok, now run uClibc's main() -- shouldn't return */
#if defined L_crt1 && defined __UCLIBC_CTOR_DTOR__
#ifdef __BFIN_FDPIC__
	R3 = [P3 + __init@FUNCDESC_GOT17M4];
#else
	R3.H = __init;
	R3.L = __init;
#endif
	[SP+16] = R3;
#ifdef __BFIN_FDPIC__
	R3 = [P3 + __fini@FUNCDESC_GOT17M4];
#else
	R3.H = __fini;
	R3.L = __fini;
#endif
	[SP+20] = R3;
#else /* no ctor/dtor handling */
	R3 = 0;
	[SP + 16] = R3;
	[SP + 20] = R3;
#endif

#ifdef __BFIN_FDPIC__
	R0 = [P3 + _main@FUNCDESC_GOT17M4];
#else
	R0.H = _main;
	R0.L = _main;
#endif
	jump.l	___uClibc_main;