1 /* Support functions for the unwinder.
2 Copyright (C) 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
3 Contributed by Paul Brook
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
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
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.
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. */
29 /* An executable stack is *not* required for these functions. */
30 #if defined(__ELF__) && defined(__linux__)
31 .section .note.GNU-stack,"",%progbits
37 #include "lib1funcs.asm"
41 EQUIV SYM (\name), SYM (__\name)
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.
49 #ifdef __ARM_ARCH_4T__
56 #ifdef __ARM_ARCH_6M__
58 /* r0 points to a 16-word block. Upload these values to the actual core
60 FUNC_START restore_core_regs
63 ldmia r1!, {r3, r4, r5}
71 ldmia r1!, {r2, r3, r4, r5}
78 ldmia r1!, {r2, r3, r4, r5, r6, r7}
83 FUNC_END restore_core_regs
84 UNPREFIX restore_core_regs
86 /* ARMV6M does not have coprocessors, so these should never be used. */
87 FUNC_START gnu_Unwind_Restore_VFP
90 /* Store VFR regsters d0-d15 to the address in r0. */
91 FUNC_START gnu_Unwind_Save_VFP
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
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
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
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
114 FUNC_START gnu_Unwind_Restore_WMMXD
117 FUNC_START gnu_Unwind_Save_WMMXD
120 FUNC_START gnu_Unwind_Restore_WMMXC
123 FUNC_START gnu_Unwind_Save_WMMXC
126 .macro UNWIND_WRAPPER name nargs
128 /* Create a phase2_vrs structure. */
129 /* Save r0 in the PC slot so we can use it as a scratch register. */
132 push {r0, lr} /* Push original SP and LR. */
133 /* Make space for r8-r12. */
135 /* Save low registers. */
136 push {r0, r1, r2, r3, r4, r5, r6, r7}
137 /* Save high registers. */
144 stmia r0!, {r1, r2, r3, r4, r5}
145 /* Restore original low register values. */
147 ldmia r0!, {r1, r2, r3, r4, r5}
148 /* Restore orginial r0. */
151 /* Demand-save flags, plus an extra word for alignment. */
154 /* Point r1 at the block. Pass r[0..nargs) unchanged. */
167 #else /* !__ARM_ARCH_6M__ */
169 /* r0 points to a 16-word block. Upload these values to the actual core
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
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. */
184 #elif defined(__INTERWORKING__)
185 /* Restore pc into ip. */
187 stmfd sp!, {r2, r3, r4}
189 stmfd sp!, {r3, r4, r5}
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. */
197 #elif defined(__INTERWORKING__)
198 /* Pop the three registers we pushed earlier. */
199 ldmfd sp, {ip, sp, lr}
202 ldmfd sp, {sp, lr, pc}
204 FUNC_END restore_core_regs
205 UNPREFIX restore_core_regs
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} */
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} */
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} */
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} */
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} */
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} */
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 */
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 */
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 */
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 */
307 /* Wrappers to save core registers, then call the real routine. */
309 .macro UNWIND_WRAPPER name nargs
311 /* Create a phase2_vrs structure. */
312 /* Split reg push in two to ensure the correct value for sp. */
313 #if defined(__thumb2__)
315 push {lr} /* PC is ignored. */
316 push {ip, lr} /* Push original SP and LR. */
318 stmfd sp!, {sp, lr, pc}
320 stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp, ip}
322 /* Demand-save flags, plus an extra word for alignment. */
326 /* Point r1 at the block. Pass r[0..nargs) unchanged. */
328 #if defined(__thumb__) && !defined(__thumb2__)
329 /* Switch back to thumb mode to avoid interworking hassle. */
335 bl SYM (__gnu\name) __PLT__
340 bl SYM (__gnu\name) __PLT__
349 #endif /* !__ARM_ARCH_6M__ */
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
357 #endif /* ndef __symbian__ */