1/* Copyright (C) 2012 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.  */
17
18#include <sysdep.h>
19
20#include "ucontext_i.h"
21
22	.syntax unified
23	.text
24
25/* int getcontext (ucontext_t *ucp) */
26
27ENTRY(__getcontext)
28	/* No need to save r0-r3, d0-d7, or d16-d31.  */
29	add	r1, r0, #MCONTEXT_ARM_R4
30	stmia   r1, {r4-r11}
31
32	/* Save R13 separately as Thumb can't STM it.  */
33	str     r13, [r0, #MCONTEXT_ARM_SP]
34	str     r14, [r0, #MCONTEXT_ARM_LR]
35	/* Return to LR */
36	str     r14, [r0, #MCONTEXT_ARM_PC]
37	/* Return zero */
38	mov     r2, #0
39	str     r2, [r0, #MCONTEXT_ARM_R0]
40
41	/* Save ucontext_t * across the next call.  */
42	mov	r4, r0
43
44	/* __sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */
45	mov     r0, #SIG_BLOCK
46	mov     r1, #0
47	add     r2, r4, #UCONTEXT_SIGMASK
48	bl      PLTJMP(sigprocmask)
49
50#if defined __UCLIBC_HAS_FLOATS__ && ! defined __UCLIBC_HAS_SOFT_FLOAT__
51# ifdef __VFP_FP__
52	/* Store the VFP registers.  */
53	/* Following instruction is fstmiax ip!, {d8-d15}.  */
54	stc     p11, cr8, [r0], #64
55	/* Store the floating-point status register.  */
56	/* Following instruction is fmrx r2, fpscr.  */
57	mrc     p10, 7, r1, cr1, cr0, 0
58	str     r1, [r0], #4
59# endif
60#endif
61#ifdef __IWMMXT__
62	/* Save the call-preserved iWMMXt registers.  */
63	/* Following instructions are wstrd wr10, [r0], #8 (etc.)  */
64	stcl    p1, cr10, [r0], #8
65	stcl    p1, cr11, [r0], #8
66	stcl    p1, cr12, [r0], #8
67	stcl    p1, cr13, [r0], #8
68	stcl    p1, cr14, [r0], #8
69	stcl    p1, cr15, [r0], #8
70#endif
71
72	/* Restore the clobbered R4 and LR.  */
73	ldr	r14, [r4, #MCONTEXT_ARM_LR]
74	ldr	r4, [r4, #MCONTEXT_ARM_R4]
75
76	mov	r0, #0
77	DO_RET(r14)
78
79END(__getcontext)
80weak_alias(__getcontext, getcontext)
81