Add CFI statements to ARM's assembly code.
[glibc-ports.git] / sysdeps / arm / dl-trampoline.S
blobde8d891821a0549586dbddad4455bdf6d0ce359b
1 /* PLT trampolines.  ARM version.
2    Copyright (C) 2005, 2010 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <libc-symbols.h>
23 #if defined(__USE_BX__)
24 #define BX(x) bx        x
25 #else
26 #define BX(x) mov       pc, x
27 #endif
29         .text
30         .globl _dl_runtime_resolve
31         .type _dl_runtime_resolve, #function
32         .cfi_sections .debug_frame
33         cfi_startproc
34         .align 2
35 _dl_runtime_resolve:
36         cfi_adjust_cfa_offset (4)
37         cfi_rel_offset (lr, 0)
39         @ we get called with
40         @       stack[0] contains the return address from this call
41         @       ip contains &GOT[n+3] (pointer to function)
42         @       lr points to &GOT[2]
44         @ Save arguments.  We save r4 to realign the stack.
45         stmdb   sp!,{r0-r4}
46         cfi_adjust_cfa_offset (20)
47         cfi_rel_offset (r0, 0)
48         cfi_rel_offset (r1, 4)
49         cfi_rel_offset (r2, 8)
50         cfi_rel_offset (r3, 12)
52         @ get pointer to linker struct
53         ldr     r0, [lr, #-4]
55         @ prepare to call _dl_fixup()
56         @ change &GOT[n+3] into 8*n        NOTE: reloc are 8 bytes each
57         sub     r1, ip, lr
58         sub     r1, r1, #4
59         add     r1, r1, r1
61         @ call fixup routine
62         bl      _dl_fixup
64         @ save the return
65         mov     ip, r0
67         @ get arguments and return address back.  We restore r4
68         @ only to realign the stack.
69         ldmia   sp!, {r0-r4,lr}
70         cfi_adjust_cfa_offset (-24)
72         @ jump to the newly found address
73         BX(ip)
75         cfi_endproc
76         .size _dl_runtime_resolve, .-_dl_runtime_resolve
78 #ifndef PROF
79         .globl _dl_runtime_profile
80         .type _dl_runtime_profile, #function
81         .cfi_sections .debug_frame
82         cfi_startproc
83         .align 2
84 _dl_runtime_profile:
85         cfi_adjust_cfa_offset (4)
86         cfi_rel_offset (lr, 0)
88         @ we get called with
89         @       stack[0] contains the return address from this call
90         @       ip contains &GOT[n+3] (pointer to function)
91         @       lr points to &GOT[2]
93         @ Stack layout:
94         @ 212 - saved lr
95         @ 208 - framesize returned from pltenter
96         @ 16 - La_arm_regs
97         @ 8 - Saved two arguments to _dl_profile_fixup
98         @ 4 - Saved result of _dl_profile_fixup
99         @ 0 - outgoing argument to _dl_profile_fixup
100         @ For now, we only save the general purpose registers.
102         sub     sp, sp, #196
103         cfi_adjust_cfa_offset (196)
104         stmia   sp, {r0-r3}
105         cfi_rel_offset (r0, 0)
106         cfi_rel_offset (r1, 4)
107         cfi_rel_offset (r2, 8)
108         cfi_rel_offset (r3, 12)
110         sub     sp, sp, #16
111         cfi_adjust_cfa_offset (16)
113         @ Save sp and lr.
114         add     r0, sp, #216
115         str     r0, [sp, #32]
116         ldr     r2, [sp, #212]
117         str     r2, [sp, #36]
119         @ get pointer to linker struct
120         ldr     r0, [lr, #-4]
122         @ prepare to call _dl_profile_fixup()
123         @ change &GOT[n+3] into 8*n        NOTE: reloc are 8 bytes each
124         sub     r1, ip, lr
125         sub     r1, r1, #4
126         add     r1, r1, r1
128         @ Save these two arguments for pltexit.
129         add     r3, sp, #8
130         stmia   r3!, {r0,r1}
132         @ Set up extra args for _dl_profile_fixup.
133         @ r2 and r3 are already loaded.
134         add     ip, sp, #208
135         str     ip, [sp, #0]
137         @ call profiling fixup routine
138         bl      _dl_profile_fixup
140         @ The address to call is now in r0.
142         @ Check whether we're wrapping this function.
143         ldr     ip, [sp, #208]
144         cmp     ip, #0
145         bge     1f
146         cfi_remember_state
148         @ save the return
149         mov     ip, r0
151         @ get arguments and return address back
152         add     sp, sp, #16
153         cfi_adjust_cfa_offset (-16)
154         ldmia   sp, {r0-r3,sp,lr}
155         cfi_adjust_cfa_offset (-200)
157         @ jump to the newly found address
158         BX(ip)
160         cfi_restore_state
162         @ The new frame size is in ip.
164         @ New stack layout:
165         @ 268 - saved r7
166         @ 264 - saved result of _dl_profile_fixup
167         @ 72 - La_arm_regs
168         @ 64 - Saved two arguments to _dl_profile_fixup
169         @ 0 - La_arm_retval
170         @ For now, we only save the general purpose registers.
172         @ Build the new frame.
173         str     r7, [sp, #212]
174         cfi_rel_offset (r7, 212)
175         sub     r7, sp, #56
176         cfi_def_cfa_register (r7)
177         cfi_adjust_cfa_offset (56)
178         sub     sp, sp, ip
179         bic     sp, sp, #7
181         @ Save the _dl_profile_fixup result around the call to memcpy.
182         str     r0, [r7, #264]
184         @ Copy the stack arguments.
185         mov     r0, sp
186         add     r1, r7, #272
187         mov     r2, ip
188         bl      memcpy
190         @ Call the function.
191         add     ip, r7, #72
192         ldmia   ip, {r0-r3}
193         ldr     ip, [r7, #264]
194         mov     lr, pc
195         BX(ip)
196         stmia   r7, {r0-r3}
198         @ Call pltexit.
199         add     ip, r7, #64
200         ldmia   ip, {r0,r1}
201         add     r2, r7, #72
202         add     r3, r7, #0
203         bl      _dl_call_pltexit
205         @ Return to caller.
206         ldmia   r7, {r0-r3}
207         mov     sp, r7
208         cfi_def_cfa_register (sp)
209         ldr     r7, [sp, #268]
210         ldr     lr, [sp, #92]
211         add     sp, sp, #272
212         cfi_adjust_cfa_offset (-272)
213         BX(lr)
215         cfi_endproc
216         .size _dl_runtime_profile, .-_dl_runtime_profile
217 #endif
218         .previous