1/* Copyright (C) 2012-2021 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 <https://www.gnu.org/licenses/>. */ 17 18#include <sysdep.h> 19#include <rtld-global-offsets.h> 20 21#include "ucontext_i.h" 22 23 .syntax unified 24 .text 25 26/* int getcontext (ucontext_t *ucp) */ 27 28ENTRY(__getcontext) 29 /* No need to save r0-r3, d0-d7, or d16-d31. */ 30 add r1, r0, #MCONTEXT_ARM_R4 31 stmia r1, {r4-r11} 32 33 /* Save R13 separately as Thumb can't STM it. */ 34 str r13, [r0, #MCONTEXT_ARM_SP] 35 str r14, [r0, #MCONTEXT_ARM_LR] 36 /* Return to LR */ 37 str r14, [r0, #MCONTEXT_ARM_PC] 38 /* Return zero */ 39 mov r2, #0 40 str r2, [r0, #MCONTEXT_ARM_R0] 41 42 /* Save ucontext_t * across the next call. */ 43 mov r4, r0 44 45 /* __sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */ 46 mov r0, #SIG_BLOCK 47 mov r1, #0 48 add r2, r4, #UCONTEXT_SIGMASK 49 bl PLTJMP(__sigprocmask) 50 51 /* Store FP regs. Much of the FP code is copied from arm/setjmp.S. */ 52 53#ifdef SHARED 54 ldr r2, 1f 55 ldr r1, .Lrtld_global_ro 560: add r2, pc, r2 57 ldr r2, [r2, r1] 58 ldr r2, [r2, #RTLD_GLOBAL_RO_DL_HWCAP_OFFSET] 59#else 60 ldr r2, .Lhwcap 61 ldr r2, [r2, #0] 62#endif 63 64 add r0, r4, #UCONTEXT_REGSPACE 65 66#ifdef __SOFTFP__ 67 tst r2, #HWCAP_ARM_VFP 68 beq .Lno_vfp 69#endif 70 71 /* Store the VFP registers. 72 Don't use VFP instructions directly because this code 73 is used in non-VFP multilibs. */ 74 /* Following instruction is vstmia r0!, {d8-d15}. */ 75 stc p11, cr8, [r0], #64 76 /* Store the floating-point status register. */ 77 /* Following instruction is vmrs r1, fpscr. */ 78 mrc p10, 7, r1, cr1, cr0, 0 79 str r1, [r0], #4 80.Lno_vfp: 81 82 tst r2, #HWCAP_ARM_IWMMXT 83 beq .Lno_iwmmxt 84 85 /* Save the call-preserved iWMMXt registers. */ 86 /* Following instructions are wstrd wr10, [r0], #8 (etc.) */ 87 stcl p1, cr10, [r0], #8 88 stcl p1, cr11, [r0], #8 89 stcl p1, cr12, [r0], #8 90 stcl p1, cr13, [r0], #8 91 stcl p1, cr14, [r0], #8 92 stcl p1, cr15, [r0], #8 93.Lno_iwmmxt: 94 95 /* Restore the clobbered R4 and LR. */ 96 ldr r14, [r4, #MCONTEXT_ARM_LR] 97 ldr r4, [r4, #MCONTEXT_ARM_R4] 98 99 mov r0, #0 100 101 DO_RET(r14) 102 103END(__getcontext) 104 105#ifdef SHARED 1061: .long _GLOBAL_OFFSET_TABLE_ - 0b - PC_OFS 107.Lrtld_global_ro: 108 .long C_SYMBOL_NAME(_rtld_global_ro)(GOT) 109#else 110.Lhwcap: 111 .long C_SYMBOL_NAME(_dl_hwcap) 112#endif 113 114 115weak_alias(__getcontext, getcontext) 116