summaryrefslogtreecommitdiff
path: root/libgcc/config/nios2/crti.S
blob: 43e77699e0638ab83ef6505129409db8dce4884d (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
/* Copyright (C) 2012-2018 Free Software Foundation, Inc.
   Contributed by Jonah Graham (jgraham@altera.com).
   Contributed by Mentor Graphics, Inc.

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

This file 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
General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
<http://www.gnu.org/licenses/>.  */


/* This file just make a stack frame for the contents of the .fini and
   .init sections.  Users may put any desired instructions in those
   sections.

   While technically any code can be put in the init and fini sections
   most stuff will not work other than stuff which obeys the call frame
   and ABI.  All the call-preserved registers are saved, the call clobbered
   registers should have been saved by the code calling init and fini.

   See crtstuff.c for an example of code that inserts itself in the init
   and fini sections. 

   See crt0.s for the code that calls init and fini.  */

	.section	".init"
	.align 2
	.global	_init
_init:
	addi	sp, sp, -48
	stw	ra, 44(sp)
	stw	r23, 40(sp)
	stw	r22, 36(sp)
	stw	r21, 32(sp)
	stw	r20, 28(sp)
	stw	r19, 24(sp)
	stw	r18, 20(sp)
	stw	r17, 16(sp)
	stw	r16, 12(sp)
	stw	fp, 8(sp)
	addi	fp, sp, 8
#ifdef linux
	nextpc	r22
1:	movhi	r2, %hiadj(_gp_got - 1b)
	addi	r2, r2, %lo(_gp_got - 1b)
	add	r22, r22, r2
#endif
	
	
	.section	".fini"
	.align	2
	.global	_fini
_fini:
	addi	sp, sp, -48
	stw	ra, 44(sp)
	stw	r23, 40(sp)
	stw	r22, 36(sp)
	stw	r21, 32(sp)
	stw	r20, 28(sp)
	stw	r19, 24(sp)
	stw	r18, 20(sp)
	stw	r17, 16(sp)
	stw	r16, 12(sp)
	stw	fp, 8(sp)
	addi	fp, sp, 8
#ifdef linux
	nextpc	r22
1:	movhi	r2, %hiadj(_gp_got - 1b)
	addi	r2, r2, %lo(_gp_got - 1b)
	add	r22, r22, r2
#endif