OSDN Git Service

2008-05-15 Diego Novillo <dnovillo@google.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / arm / libunwind.S
1 /* Support functions for the unwinder.
2    Copyright (C) 2003, 2004, 2005, 2007, 2008  Free Software Foundation, Inc.
3    Contributed by Paul Brook
4
5    This file is free software; you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by the
7    Free Software Foundation; either version 2, or (at your option) any
8    later version.
9
10    In addition to the permissions in the GNU General Public License, the
11    Free Software Foundation gives you unlimited permission to link the
12    compiled version of this file into combinations with other programs,
13    and to distribute those combinations without any restriction coming
14    from the use of this file.  (The General Public License restrictions
15    do apply in other respects; for example, they cover modification of
16    the file, and distribution when not linked into a combine
17    executable.)
18
19    This file is distributed in the hope that it will be useful, but
20    WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    General Public License for more details.
23
24    You should have received a copy of the GNU General Public License
25    along with this program; see the file COPYING.  If not, write to
26    the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27    Boston, MA 02110-1301, USA.  */
28
29 /* An executable stack is *not* required for these functions.  */
30 #if defined(__ELF__) && defined(__linux__)
31 .section .note.GNU-stack,"",%progbits
32 .previous
33 #endif
34
35 #ifndef __symbian__
36
37 #include "lib1funcs.asm"
38
39 .macro UNPREFIX name
40         .global SYM (\name)
41         EQUIV SYM (\name), SYM (__\name)
42 .endm
43
44 #if (__ARM_ARCH__ == 4)
45 /* Some coprocessors require armv5.  We know this code will never be run on
46    other cpus.  Tell gas to allow armv5, but only mark the objects as armv4.
47  */
48 .arch armv5t
49 #ifdef __ARM_ARCH_4T__
50 .object_arch armv4t
51 #else
52 .object_arch armv4
53 #endif
54 #endif
55
56 #ifdef __ARM_ARCH_6M__
57
58 /* r0 points to a 16-word block.  Upload these values to the actual core
59    state.  */
60 FUNC_START restore_core_regs
61         mov r1, r0
62         add r1, r1, #52
63         ldmia r1!, {r3, r4, r5}
64         sub r3, r3, #4
65         mov ip, r3
66         str r5, [r3]
67         mov lr, r4
68         /* Restore r8-r11.  */
69         mov r1, r0
70         add r1, r1, #32
71         ldmia r1!, {r2, r3, r4, r5}
72         mov r8, r2
73         mov r9, r3
74         mov sl, r4
75         mov fp, r5
76         mov r1, r0
77         add r1, r1, #8
78         ldmia r1!, {r2, r3, r4, r5, r6, r7}
79         ldr r1, [r0, #4]
80         ldr r0, [r0]
81         mov sp, ip
82         pop {pc}
83         FUNC_END restore_core_regs
84         UNPREFIX restore_core_regs
85
86 /* ARMV6M does not have coprocessors, so these should never be used.  */
87 FUNC_START gnu_Unwind_Restore_VFP
88         RET
89
90 /* Store VFR regsters d0-d15 to the address in r0.  */
91 FUNC_START gnu_Unwind_Save_VFP
92         RET
93
94 /* Load VFP registers d0-d15 from the address in r0.
95    Use this to load from FSTMD format.  */
96 FUNC_START gnu_Unwind_Restore_VFP_D
97         RET
98
99 /* Store VFP registers d0-d15 to the address in r0.
100    Use this to store in FLDMD format.  */
101 FUNC_START gnu_Unwind_Save_VFP_D
102         RET
103
104 /* Load VFP registers d16-d31 from the address in r0.
105    Use this to load from FSTMD (=VSTM) format.  Needs VFPv3.  */
106 FUNC_START gnu_Unwind_Restore_VFP_D_16_to_31
107         RET
108
109 /* Store VFP registers d16-d31 to the address in r0.
110    Use this to store in FLDMD (=VLDM) format.  Needs VFPv3.  */
111 FUNC_START gnu_Unwind_Save_VFP_D_16_to_31
112         RET
113
114 FUNC_START gnu_Unwind_Restore_WMMXD
115         RET
116
117 FUNC_START gnu_Unwind_Save_WMMXD
118         RET
119
120 FUNC_START gnu_Unwind_Restore_WMMXC
121         RET
122
123 FUNC_START gnu_Unwind_Save_WMMXC
124         RET
125
126 .macro  UNWIND_WRAPPER name nargs
127         FUNC_START \name
128         /* Create a phase2_vrs structure.  */
129         /* Save r0 in the PC slot so we can use it as a scratch register.  */
130         push {r0}
131         add r0, sp, #4
132         push {r0, lr} /* Push original SP and LR.  */
133         /* Make space for r8-r12.  */
134         sub sp, sp, #20
135         /* Save low registers.  */
136         push {r0, r1, r2, r3, r4, r5, r6, r7}
137         /* Save high registers.  */
138         add r0, sp, #32
139         mov r1, r8
140         mov r2, r9
141         mov r3, sl
142         mov r4, fp
143         mov r5, ip
144         stmia r0!, {r1, r2, r3, r4, r5}
145         /* Restore original low register values.  */
146         add r0, sp, #4
147         ldmia r0!, {r1, r2, r3, r4, r5}
148         /* Restore orginial r0.  */
149         ldr r0, [sp, #60]
150         str r0, [sp]
151         /* Demand-save flags, plus an extra word for alignment.  */
152         mov r3, #0
153         push {r2, r3}
154         /* Point r1 at the block.  Pass r[0..nargs) unchanged.  */
155         add r\nargs, sp, #4
156
157         bl SYM (__gnu\name)
158
159         ldr r3, [sp, #64]
160         add sp, sp, #72
161         bx r3
162
163         FUNC_END \name
164         UNPREFIX \name
165 .endm
166
167 #else /* !__ARM_ARCH_6M__ */
168
169 /* r0 points to a 16-word block.  Upload these values to the actual core
170    state.  */
171 ARM_FUNC_START restore_core_regs
172         /* We must use sp as the base register when restoring sp.  Push the
173            last 3 registers onto the top of the current stack to achieve
174            this.  */
175         add r1, r0, #52
176         ldmia r1, {r3, r4, r5}  /* {sp, lr, pc}.  */
177 #if defined(__thumb2__)
178         /* Thumb-2 doesn't allow sp in a load-multiple instruction, so push
179            the target address onto the target stack.  This is safe as
180            we're always returning to somewhere further up the call stack.  */
181         mov ip, r3
182         mov lr, r4
183         str r5, [ip, #-4]!
184 #elif defined(__INTERWORKING__)
185         /* Restore pc into ip.  */
186         mov r2, r5
187         stmfd sp!, {r2, r3, r4}
188 #else
189         stmfd sp!, {r3, r4, r5}
190 #endif
191         /* Don't bother restoring ip.  */
192         ldmia r0, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp}
193 #if defined(__thumb2__)
194         /* Pop the return address off the target stack.  */
195         mov sp, ip
196         pop {pc}
197 #elif defined(__INTERWORKING__)
198         /* Pop the three registers we pushed earlier.  */
199         ldmfd sp, {ip, sp, lr}
200         bx ip
201 #else
202         ldmfd sp, {sp, lr, pc}
203 #endif
204         FUNC_END restore_core_regs
205         UNPREFIX restore_core_regs
206
207 /* Load VFP registers d0-d15 from the address in r0.
208    Use this to load from FSTMX format.  */
209 ARM_FUNC_START gnu_Unwind_Restore_VFP
210         /* Use the generic coprocessor form so that gas doesn't complain
211            on soft-float targets.  */
212         ldc   p11,cr0,[r0],{0x21} /* fldmiax r0, {d0-d15} */
213         RET
214
215 /* Store VFP registers d0-d15 to the address in r0.
216    Use this to store in FSTMX format.  */
217 ARM_FUNC_START gnu_Unwind_Save_VFP
218         /* Use the generic coprocessor form so that gas doesn't complain
219            on soft-float targets.  */
220         stc   p11,cr0,[r0],{0x21} /* fstmiax r0, {d0-d15} */
221         RET
222
223 /* Load VFP registers d0-d15 from the address in r0.
224    Use this to load from FSTMD format.  */
225 ARM_FUNC_START gnu_Unwind_Restore_VFP_D
226         ldc   p11,cr0,[r0],{0x20} /* fldmiad r0, {d0-d15} */
227         RET
228
229 /* Store VFP registers d0-d15 to the address in r0.
230    Use this to store in FLDMD format.  */
231 ARM_FUNC_START gnu_Unwind_Save_VFP_D
232         stc   p11,cr0,[r0],{0x20} /* fstmiad r0, {d0-d15} */
233         RET
234
235 /* Load VFP registers d16-d31 from the address in r0.
236    Use this to load from FSTMD (=VSTM) format.  Needs VFPv3.  */
237 ARM_FUNC_START gnu_Unwind_Restore_VFP_D_16_to_31
238         ldcl  p11,cr0,[r0],{0x20} /* vldm r0, {d16-d31} */
239         RET
240
241 /* Store VFP registers d16-d31 to the address in r0.
242    Use this to store in FLDMD (=VLDM) format.  Needs VFPv3.  */
243 ARM_FUNC_START gnu_Unwind_Save_VFP_D_16_to_31
244         stcl  p11,cr0,[r0],{0x20} /* vstm r0, {d16-d31} */
245         RET
246
247 ARM_FUNC_START gnu_Unwind_Restore_WMMXD
248         /* Use the generic coprocessor form so that gas doesn't complain
249            on non-iWMMXt targets.  */
250         ldcl  p1, cr0, [r0], #8 /* wldrd wr0, [r0], #8 */
251         ldcl  p1, cr1, [r0], #8 /* wldrd wr1, [r0], #8 */
252         ldcl  p1, cr2, [r0], #8 /* wldrd wr2, [r0], #8 */
253         ldcl  p1, cr3, [r0], #8 /* wldrd wr3, [r0], #8 */
254         ldcl  p1, cr4, [r0], #8 /* wldrd wr4, [r0], #8 */
255         ldcl  p1, cr5, [r0], #8 /* wldrd wr5, [r0], #8 */
256         ldcl  p1, cr6, [r0], #8 /* wldrd wr6, [r0], #8 */
257         ldcl  p1, cr7, [r0], #8 /* wldrd wr7, [r0], #8 */
258         ldcl  p1, cr8, [r0], #8 /* wldrd wr8, [r0], #8 */
259         ldcl  p1, cr9, [r0], #8 /* wldrd wr9, [r0], #8 */
260         ldcl  p1, cr10, [r0], #8 /* wldrd wr10, [r0], #8 */
261         ldcl  p1, cr11, [r0], #8 /* wldrd wr11, [r0], #8 */
262         ldcl  p1, cr12, [r0], #8 /* wldrd wr12, [r0], #8 */
263         ldcl  p1, cr13, [r0], #8 /* wldrd wr13, [r0], #8 */
264         ldcl  p1, cr14, [r0], #8 /* wldrd wr14, [r0], #8 */
265         ldcl  p1, cr15, [r0], #8 /* wldrd wr15, [r0], #8 */
266         RET
267
268 ARM_FUNC_START gnu_Unwind_Save_WMMXD
269         /* Use the generic coprocessor form so that gas doesn't complain
270            on non-iWMMXt targets.  */
271         stcl  p1, cr0, [r0], #8 /* wstrd wr0, [r0], #8 */
272         stcl  p1, cr1, [r0], #8 /* wstrd wr1, [r0], #8 */
273         stcl  p1, cr2, [r0], #8 /* wstrd wr2, [r0], #8 */
274         stcl  p1, cr3, [r0], #8 /* wstrd wr3, [r0], #8 */
275         stcl  p1, cr4, [r0], #8 /* wstrd wr4, [r0], #8 */
276         stcl  p1, cr5, [r0], #8 /* wstrd wr5, [r0], #8 */
277         stcl  p1, cr6, [r0], #8 /* wstrd wr6, [r0], #8 */
278         stcl  p1, cr7, [r0], #8 /* wstrd wr7, [r0], #8 */
279         stcl  p1, cr8, [r0], #8 /* wstrd wr8, [r0], #8 */
280         stcl  p1, cr9, [r0], #8 /* wstrd wr9, [r0], #8 */
281         stcl  p1, cr10, [r0], #8 /* wstrd wr10, [r0], #8 */
282         stcl  p1, cr11, [r0], #8 /* wstrd wr11, [r0], #8 */
283         stcl  p1, cr12, [r0], #8 /* wstrd wr12, [r0], #8 */
284         stcl  p1, cr13, [r0], #8 /* wstrd wr13, [r0], #8 */
285         stcl  p1, cr14, [r0], #8 /* wstrd wr14, [r0], #8 */
286         stcl  p1, cr15, [r0], #8 /* wstrd wr15, [r0], #8 */
287         RET
288
289 ARM_FUNC_START gnu_Unwind_Restore_WMMXC
290         /* Use the generic coprocessor form so that gas doesn't complain
291            on non-iWMMXt targets.  */
292         ldc2  p1, cr8, [r0], #4 /* wldrw wcgr0, [r0], #4 */
293         ldc2  p1, cr9, [r0], #4 /* wldrw wcgr1, [r0], #4 */
294         ldc2  p1, cr10, [r0], #4 /* wldrw wcgr2, [r0], #4 */
295         ldc2  p1, cr11, [r0], #4 /* wldrw wcgr3, [r0], #4 */
296         RET
297
298 ARM_FUNC_START gnu_Unwind_Save_WMMXC
299         /* Use the generic coprocessor form so that gas doesn't complain
300            on non-iWMMXt targets.  */
301         stc2  p1, cr8, [r0], #4 /* wstrw wcgr0, [r0], #4 */
302         stc2  p1, cr9, [r0], #4 /* wstrw wcgr1, [r0], #4 */
303         stc2  p1, cr10, [r0], #4 /* wstrw wcgr2, [r0], #4 */
304         stc2  p1, cr11, [r0], #4 /* wstrw wcgr3, [r0], #4 */
305         RET
306
307 /* Wrappers to save core registers, then call the real routine.   */
308
309 .macro  UNWIND_WRAPPER name nargs
310         ARM_FUNC_START \name
311         /* Create a phase2_vrs structure.  */
312         /* Split reg push in two to ensure the correct value for sp.  */
313 #if defined(__thumb2__)
314         mov ip, sp
315         push {lr} /* PC is ignored.  */
316         push {ip, lr} /* Push original SP and LR.  */
317 #else
318         stmfd sp!, {sp, lr, pc}
319 #endif
320         stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp, ip}
321         
322         /* Demand-save flags, plus an extra word for alignment.  */
323         mov r3, #0
324         stmfd sp!, {r2, r3}
325
326         /* Point r1 at the block.  Pass r[0..nargs) unchanged.  */
327         add r\nargs, sp, #4
328 #if defined(__thumb__) && !defined(__thumb2__)
329         /* Switch back to thumb mode to avoid interworking hassle.  */
330         adr ip, .L1_\name
331         orr ip, ip, #1
332         bx ip
333         .thumb
334 .L1_\name:
335         bl SYM (__gnu\name) __PLT__
336         ldr r3, [sp, #64]
337         add sp, #72
338         bx r3
339 #else
340         bl SYM (__gnu\name) __PLT__
341         ldr lr, [sp, #64]
342         add sp, sp, #72
343         RET
344 #endif
345         FUNC_END \name
346         UNPREFIX \name
347 .endm
348
349 #endif /* !__ARM_ARCH_6M__ */
350
351 UNWIND_WRAPPER _Unwind_RaiseException 1
352 UNWIND_WRAPPER _Unwind_Resume 1
353 UNWIND_WRAPPER _Unwind_Resume_or_Rethrow 1
354 UNWIND_WRAPPER _Unwind_ForcedUnwind 3
355 UNWIND_WRAPPER _Unwind_Backtrace 2
356
357 #endif  /* ndef __symbian__ */