libunwind-arm.S revision 303634
1189251Ssam/* Support functions for the unwinder.
2189251Ssam   Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
3189251Ssam   Contributed by Paul Brook
4189251Ssam
5189251Ssam   This file is free software; you can redistribute it and/or modify it
6189251Ssam   under the terms of the GNU General Public License as published by the
7189251Ssam   Free Software Foundation; either version 2, or (at your option) any
8189251Ssam   later version.
9189251Ssam
10189251Ssam   In addition to the permissions in the GNU General Public License, the
11189251Ssam   Free Software Foundation gives you unlimited permission to link the
12189251Ssam   compiled version of this file into combinations with other programs,
13189251Ssam   and to distribute those combinations without any restriction coming
14189251Ssam   from the use of this file.  (The General Public License restrictions
15189251Ssam   do apply in other respects; for example, they cover modification of
16189251Ssam   the file, and distribution when not linked into a combine
17189251Ssam   executable.)
18189251Ssam
19189251Ssam   This file is distributed in the hope that it will be useful, but
20189251Ssam   WITHOUT ANY WARRANTY; without even the implied warranty of
21189251Ssam   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22189251Ssam   General Public License for more details.
23189251Ssam
24189251Ssam   You should have received a copy of the GNU General Public License
25189251Ssam   along with this program; see the file COPYING.  If not, write to
26189251Ssam   the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27189251Ssam   Boston, MA 02110-1301, USA.  */
28189251Ssam
29189251Ssam#include <machine/acle-compat.h>
30189251Ssam
31189251Ssam/* Allow the use of VFP instructions */
32214734Srpaulo#if __ARM_ARCH >= 7
33214734Srpaulo.fpu	vfp
34189251Ssam#endif
35189251Ssam
36189251Ssam#ifndef __symbian__
37189251Ssam
38252726Srpaulo#include "lib1funcs.asm"
39252726Srpaulo
40189251Ssam.macro UNPREFIX name
41189251Ssam	.global SYM (\name)
42189251Ssam	EQUIV SYM (\name), SYM (__\name)
43189251Ssam.endm
44189251Ssam
45189251Ssam/* r0 points to a 16-word block.  Upload these values to the actual core
46214734Srpaulo   state.  */
47189251SsamARM_FUNC_START restore_core_regs
48189251Ssam	/* We must use sp as the base register when restoring sp.  Push the
49	   last 3 registers onto the top of the current stack to achieve
50	   this.  */
51	add r1, r0, #52
52	ldmia r1, {r3, r4, r5}  /* {sp, lr, pc}.  */
53#ifdef __INTERWORKING__
54	/* Restore pc into ip.  */
55	mov r2, r5
56	stmfd sp!, {r2, r3, r4}
57#else
58	stmfd sp!, {r3, r4, r5}
59#endif
60	/* Don't bother restoring ip.  */
61	ldmia r0, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp}
62	/* Pop the three registers we pushed earlier.  */
63#ifdef __INTERWORKING__
64	ldmfd sp, {ip, sp, lr}
65	bx ip
66#else
67	ldmfd sp, {sp, lr, pc}
68#endif
69	FUNC_END restore_core_regs
70	UNPREFIX restore_core_regs
71
72/* Load VFP registers d0-d15 from the address in r0.  */
73ARM_FUNC_START gnu_Unwind_Restore_VFP
74	/* Use the generic coprocessor form so that gas doesn't complain
75	   on soft-float targets.  */
76#if __ARM_ARCH >= 7
77	fldmiax r0, {d0-d15}
78#else
79	ldc   p11,cr0,[r0],{0x21} /* fldmiax r0, {d0-d15} */
80#endif
81	RET
82
83/* Store VFR regsters d0-d15 to the address in r0.  */
84ARM_FUNC_START gnu_Unwind_Save_VFP
85	/* Use the generic coprocessor form so that gas doesn't complain
86	   on soft-float targets.  */
87#if __ARM_ARCH >= 7
88	fstmiax r0, {d0-d15}
89#else
90	stc   p11,cr0,[r0],{0x21} /* fstmiax r0, {d0-d15} */
91#endif
92	RET
93
94/* Wrappers to save core registers, then call the real routine.   */
95
96.macro  UNWIND_WRAPPER name nargs
97	ARM_FUNC_START \name
98	/* Create a phase2_vrs structure.  */
99	/* Split reg push in two to ensure the correct value for sp.  */
100	stmfd sp!, {sp, lr, pc}
101	stmfd sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, fp, ip}
102
103	/* Demand-save flags, plus an extra word for alignment.  */
104	mov r3, #0
105	stmfd sp!, {r2, r3}
106
107	/* Point r1 at the block.  Pass r[0..nargs) unchanged.  */
108	add r\nargs, sp, #4
109#if defined(__thumb__)
110	/* Switch back to thumb mode to avoid interworking hassle.  */
111	adr ip, .L1_\name
112	orr ip, ip, #1
113	bx ip
114	.thumb
115.L1_\name:
116	bl SYM (__gnu\name) __PLT__
117	ldr r3, [sp, #64]
118	add sp, #72
119	bx r3
120#else
121	bl SYM (__gnu\name) __PLT__
122	ldr lr, [sp, #64]
123	add sp, sp, #72
124	RET
125#endif
126	FUNC_END \name
127	UNPREFIX \name
128.endm
129
130UNWIND_WRAPPER _Unwind_RaiseException 1
131UNWIND_WRAPPER _Unwind_Resume 1
132UNWIND_WRAPPER _Unwind_Resume_or_Rethrow 1
133UNWIND_WRAPPER _Unwind_ForcedUnwind 3
134UNWIND_WRAPPER _Unwind_Backtrace 2
135
136#endif  /* ndef __symbian__ */
137