summaryrefslogtreecommitdiff
path: root/ports/sysdeps/m68k/dl-trampoline.S
blob: f4f457483c67effa0278cecc2aeab98235b06bc6 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* PLT trampolines.  m68k version.
   Copyright (C) 2005 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 Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 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
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include <sysdep.h>

	.text
	.globl _dl_runtime_resolve
	.type _dl_runtime_resolve, @function
_dl_runtime_resolve:
	| Save %a0 (struct return address) and %a1.
	move.l %a0, -(%sp)
	move.l %a1, -(%sp)
	| Call the real address resolver.
	jbsr _dl_fixup
	| Restore register %a0 and %a1.
	move.l (%sp)+, %a1
	move.l (%sp)+, %a0
	| Pop parameters
	addq.l #8, %sp
	| Call real function.
#ifdef __mcoldfire__
	move.l %d0,-(%sp)
	rts
#else
	jmp (%d0)
#endif
	.size _dl_runtime_resolve, . - _dl_runtime_resolve

	.text
	.globl _dl_runtime_profile
	.type _dl_runtime_profile, @function
_dl_runtime_profile:
	pea 8(%sp)
	move.l %a1, -(%sp)
	move.l %a0, -(%sp)
	pea -1.w
	| Push parameters for _dl_profile_fixup
	pea (%sp)
	pea 8(%sp)
	move.l 32(%sp), -(%sp)
	move.l 32(%sp), -(%sp)
	move.l 32(%sp), -(%sp)
	subq.l #8, %sp
	| Call the real address resolver.
	jbsr _dl_profile_fixup
	| Pop parameters
	lea 28(%sp), %sp
	move.l (%sp), %d1
	jpl 1f
	addq.l #4, %sp
	| Restore register %a0 and %a1.
	move.l (%sp)+, %a0
	move.l (%sp)+, %a1
	lea 12(%sp), %sp
	| Call real function.
#ifdef __mcoldfire__
	move.l %d0,-(%sp)
	rts
#else
	jmp (%d0)
#endif

	/*
	    +24     return address
	    +20     PLT1
	    +16     PLT2
	    +12     %sp
	    +8      %a1
	    +4      %a0
	   %sp      free
	*/
1:	move.l %a2, (%sp)
	move.l %sp, %a2
	move.l %sp, %a0
	lea 28(%sp), %a1
	| Round framesize up to longword alignment
	addq.l #3, %d1
	and.l #-3, %d1
	sub.l %d1, %a0
	move.l %a0, %sp
#ifdef __mcoldfire__
	tst.l %d1
	beq 2f
1:	move.l (%a0)+, (%a1)+
	subq.l #4,%d1
	bne 1b
2:
#else
	lsr.l #2,%d1
	jra 2f
1:	move.l (%a1)+, (%a0)+
2:	dbra %d1,1b
#endif
	/*
	   %a2+24  return address
	   %a2+20  PLT1
	   %a2+16  PLT2
	   %a2+12  %sp
	   %a2+8   %a1
	   %a2+4   %a0
	   %a2     %a2
	   %sp     copied stack frame
	*/

	move.l 4(%a2), %a0
	move.l 8(%a2), %a1
#ifdef __mcoldfire__
	pea 2f(%pc)
	move.l %d0,-(%sp)
	rts
2:
#else
	jsr (%d0)
#endif
	move.l %a2, %sp
	move.l (%sp)+, %a2
	/*
	    +20     return address
	    +16     PLT1
	    +12     PLT2
	    +8      %sp
	    +4      %a1
	   %sp      %a0
	*/
#if !defined (__mcoldfire__)
	fmove.x %fp0, -(%sp)
#elif defined (__mcffpu__)
	fmove.l %fp0, -(%sp)
#else
	clr.l -(%sp)
	clr.l -(%sp)
#endif
	move.l %a0, -(%sp)
	move.l %d1, -(%sp)
	move.l %d0, -(%sp)
	pea (%sp)
#ifdef __mcoldfire__
	pea 24(%sp)
	move.l 40(%sp), -(%sp)
	move.l 40(%sp), -(%sp)
#else
	pea 28(%sp)
	move.l 44(%sp), -(%sp)
	move.l 44(%sp), -(%sp)
#endif
	jbsr _dl_call_pltexit
	lea 16(%sp), %sp
	move.l (%sp)+, %d0
	move.l (%sp)+, %d1
	move.l (%sp)+, %a0
#if !defined (__mcoldfire__)
	fmove.x (%sp)+, %fp0
	lea 20(%sp), %sp
#elif defined (__mcffpu__)
	fmove.l (%sp)+, %fp0
	lea 20(%sp), %sp
#else
	lea 28(%sp), %sp
#endif
	rts
	.size _dl_runtime_profile, . - _dl_runtime_profile