aboutsummaryrefslogtreecommitdiff
path: root/libgcc/config/csky/crti.S
blob: 1824596fb20ab3508b59c3f98268c4e84d070c2a (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Define _init and _fini entry points for C-SKY.
# Copyright (C) 2018-2024 Free Software Foundation, Inc.
# Contributed by C-SKY Microsystems and Mentor Graphics.
#
# 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 makes a stack frame for the contents of the .fini and
# .init sections.  Users may put any desired instructions in those
# sections.

	.file    "crti.S"

/* We use more complicated versions of this code with GLIBC.  */
#if defined(__gnu_linux__)

#ifndef PREINIT_FUNCTION
# define PREINIT_FUNCTION __gmon_start__
#endif

#ifndef PREINIT_FUNCTION_WEAK
# define PREINIT_FUNCTION_WEAK 1
#endif

#if PREINIT_FUNCTION_WEAK
	.global PREINIT_FUNCTION
	.weak PREINIT_FUNCTION
	.align 4
	.type call_weak_fn, %function
call_weak_fn:
	// push  lr
	subi    sp, 4
	stw     lr, (sp)
#ifdef  __PIC__
	lrw     a2, PREINIT_FUNCTION@GOT
	addu    a2, gb
	ldw     a2, (a2)
#else
	lrw     a2, PREINIT_FUNCTION
#endif
	cmpnei  a2, 0
	bf      1f
	jsr     a2
1:
	// pop lr
	ldw     lr, (sp)
	addi    sp, 4
	rts

	.align 4
#else
	.hidden PREINIT_FUNCTION
#endif /* PREINIT_FUNCTION_WEAK */

	.section .init,"ax",@progbits
	.align 4
	.globl _init
	.type _init, @function
_init:
	subi    sp, 8
	stw     lr, (sp, 0)
#ifdef __PIC__
	//  stw     gb, (sp, 4)
	bsr     .Lgetpc
.Lgetpc:
	lrw     gb, .Lgetpc@GOTPC
	add     gb, lr
#endif
#if PREINIT_FUNCTION_WEAK
#ifdef __PIC__
	lrw     a2, call_weak_fn@GOTOFF
	add     a2, gb
	jsr     a2
#else
	jsri    call_weak_fn
#endif
#else /* !PREINIT_FUNCTION_WEAK */
#ifdef  __PIC__
	lrw     a2, PREINIT_FUNCTION@PLT
	addu    a2, gb
	ldw     a2, (a2)
	jsr     a2
#else
	jsri    PREINIT_FUNCTION
#endif
#endif /* PREINIT_FUNCTION_WEAK */

	br      2f
	.literals
	.align  4
2:
	.section .fini,"ax",@progbits
	.align 4
	.globl _fini
	.type _fini, @function
_fini:
	subi    sp,8
	stw     lr, (sp, 0)
	br      2f
	.literals
	.align  4
2:

/* These are the non-GLIBC versions.  */
#else  /* !defined(__gnu_linux__) */
	.section  ".init"
	.global  _init
	.type  _init,@function
	.align  2
_init:
	subi  sp, 16
	st.w  lr, (sp, 12)
	mov     r0, r0

	.section  ".fini"
	.global  _fini
	.type  _fini,@function
	.align  2
_fini:
	subi  sp, 16
	st.w  lr, (sp, 12)
	mov     r0, r0
#endif /* defined(__gnu_linux__) */