Imported Upstream version 1.3.1
[platform/upstream/libunwind.git] / src / arm / getcontext.S
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2008 CodeSourcery
3
4 This file is part of libunwind.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
24
25 #include "offsets.h"
26
27         .text
28         .arm
29
30         .global _Uarm_getcontext
31         .type   _Uarm_getcontext, %function
32         @ This is a stub version of getcontext() for ARM which only stores core
33         @ registers.  It must be called in a special way, not as a regular
34         @ function -- see also the libunwind-arm.h:unw_tdep_getcontext macro.
35 _Uarm_getcontext:
36         stmfd sp!, {r0, r1}
37         @ store r0
38 #if defined(__linux__)
39         str r0, [r0, #LINUX_UC_MCONTEXT_OFF + LINUX_SC_R0_OFF]
40         add r0, r0, #LINUX_UC_MCONTEXT_OFF + LINUX_SC_R0_OFF
41 #elif defined(__FreeBSD__)
42         str r0, [r0, #FREEBSD_UC_MCONTEXT_OFF + FREEBSD_MC_R0_OFF]
43         add r0, r0, #FREEBSD_UC_MCONTEXT_OFF + FREEBSD_MC_R0_OFF
44 #else
45 #error Fix me
46 #endif
47         @ store r1 to r12
48         stmib r0, {r1-r12}
49         @ reconstruct r13 at call site, then store
50         add r1, sp, #12
51         str r1, [r0, #13 * 4]
52         @ retrieve r14 from call site, then store
53         ldr r1, [sp, #8]
54         str r1, [r0, #14 * 4]
55         @ point lr to instruction after call site's stack adjustment
56         add r1, lr, #4
57         str r1, [r0, #15 * 4]
58         ldmfd sp!, {r0, r1}
59         bx lr
60 #if defined(__linux__) || defined(__FreeBSD__)
61  /* We do not need executable stack.  */
62  .section  .note.GNU-stack,"",%progbits
63 #endif