swapcontext.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2012 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include "ucontext_i.h"
  16. .syntax unified
  17. .text
  18. /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
  19. ENTRY(swapcontext)
  20. /* Have getcontext() do most of the work then fix up
  21. LR afterwards. Save R3 to keep the stack aligned. */
  22. push {r0,r1,r3,r14}
  23. cfi_adjust_cfa_offset (16)
  24. cfi_rel_offset (r0,0)
  25. cfi_rel_offset (r1,4)
  26. cfi_rel_offset (r3,8)
  27. cfi_rel_offset (r14,12)
  28. bl __getcontext
  29. mov r4, r0
  30. pop {r0,r1,r3,r14}
  31. cfi_adjust_cfa_offset (-16)
  32. cfi_restore (r0)
  33. cfi_restore (r1)
  34. cfi_restore (r3)
  35. cfi_restore (r14)
  36. /* Exit if getcontext() failed. */
  37. cmp r4, #0
  38. itt ne
  39. movne r0, r4
  40. RETINSTR(ne, r14)
  41. /* Fix up LR and the PC. */
  42. str r13,[r0, #MCONTEXT_ARM_SP]
  43. str r14,[r0, #MCONTEXT_ARM_LR]
  44. str r14,[r0, #MCONTEXT_ARM_PC]
  45. /* And swap using swapcontext(). */
  46. mov r0, r1
  47. b __setcontext
  48. END(swapcontext)