arm: Introduce and use PC_OFS
[glibc.git] / ports / sysdeps / unix / sysv / linux / arm / setcontext.S
blobedd17bcd40d85cd4df85bd816b18305c3fe988d4
1 /* Copyright (C) 2012-2013 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <rtld-global-offsets.h>
21 #include "ucontext_i.h"
23         .syntax unified
24         .text
26 /* int setcontext (const ucontext_t *ucp) */
28 ENTRY(__setcontext)
29         mov     r4, r0
30         add     r0, r0, #UCONTEXT_REGSPACE
32         /* Restore the VFP registers.  Copied from arm/__longjmp.S.  */
33 #ifdef PIC
34         ldr     r2, 1f
35         ldr     r1, .Lrtld_global_ro
36 0:      add     r2, pc, r2
37         ldr     r2, [r2, r1]
38         ldr     r2, [r2, #RTLD_GLOBAL_RO_DL_HWCAP_OFFSET]
39 #else
40         ldr     r2, .Lhwcap
41         ldr     r2, [r2, #0]
42 #endif
44 #ifdef __SOFTFP__
45         tst     r2, #HWCAP_ARM_VFP
46         beq     .Lno_vfp_sc
47 #endif
49         /* Following instruction is vldmia r0!, {d8-d15}.  */
50         ldc     p11, cr8, [r0], #64
51         /* Restore the floating-point status register.  */
52         ldr     r1, [r0], #4
53         /* Following instruction is fmxr fpscr, r1.  */
54         mcr     p10, 7, r1, cr1, cr0, 0
55 .Lno_vfp_sc:
56         tst     r2, #HWCAP_ARM_IWMMXT
57         beq     .Lno_iwmmxt_sc
59         /* Restore the call-preserved iWMMXt registers.  */
60         /* Following instructions are wldrd wr10, [r0], #8 (etc.)  */
61         ldcl    p1, cr10, [r0], #8
62         ldcl    p1, cr11, [r0], #8
63         ldcl    p1, cr12, [r0], #8
64         ldcl    p1, cr13, [r0], #8
65         ldcl    p1, cr14, [r0], #8
66         ldcl    p1, cr15, [r0], #8
67 .Lno_iwmmxt_sc:
69         /* Now bring back the signal status.  */
70         mov     r0, #SIG_SETMASK
71         add     r1, r4, #UCONTEXT_SIGMASK
72         mov     r2, #0
73         bl      PLTJMP(__sigprocmask)
75         /* Loading r0-r3 makes makecontext easier.  */
76         add     r14, r4, #MCONTEXT_ARM_R0
77         ldmia   r14, {r0-r12}
78         ldr     r13, [r14, #(MCONTEXT_ARM_SP - MCONTEXT_ARM_R0)]
79         add     r14, r14, #(MCONTEXT_ARM_LR - MCONTEXT_ARM_R0)
80         ldmia   r14, {r14, pc}
82 END(setcontext)
83 weak_alias(__setcontext, setcontext)
85         /* Called when a makecontext() context returns.  Start the
86            context in R4 or fall through to exit().  */
87 ENTRY(__startcontext)
88         movs    r0, r4
89         bne     PLTJMP(__setcontext)
91         @ New context was 0 - exit
92         b       PLTJMP(HIDDEN_JUMPTARGET(_exit))
93 END(__startcontext)
95 #ifdef PIC
96 1:      .long   _GLOBAL_OFFSET_TABLE_ - 0b - PC_OFS
97 .Lrtld_global_ro:
98         .long   C_SYMBOL_NAME(_rtld_global_ro)(GOT)
99 #else
100 .Lhwcap:
101         .long   C_SYMBOL_NAME(_dl_hwcap)
102 #endif