swapcontext.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive for
  4. * more details.
  5. *
  6. * Copyright (C) 2025 Kalray Inc.
  7. * Author(s): Julian Vetter <jvetter@kalrayinc.com>
  8. */
  9. #include <sysdep.h>
  10. #include "ucontext_i.h"
  11. .text
  12. /* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
  13. ENTRY(swapcontext)
  14. /* Make space on the stack to save all caller saved registers */
  15. get $r16 = $ra
  16. addd $r12 = $r12, -32
  17. ;;
  18. /* Save $ra on the stack */
  19. sd (24)[$r12] = $r16
  20. ;;
  21. /* Save the arguments of swapcontext on the stack */
  22. sq (8)[$r12] = $r0r1
  23. ;;
  24. call __getcontext
  25. ;;
  26. /* Save the return value of __getcontext in $r17 */
  27. copyd $r17 = $r0
  28. /* Restore $ra */
  29. ld $r16 = (24)[$r12]
  30. ;;
  31. /* Restore arguments */
  32. lq $r0r1 = (8)[$r12]
  33. /* Readjust the stack pointer */
  34. addd $r12 = $r12, 32
  35. /* Also restore $ra */
  36. set $ra = $r16
  37. ;;
  38. /* Exit if getcontext() failed */
  39. cb.deqz $r17 ? 1f
  40. ;;
  41. /* Set the return value set by __syscall_error in __getcontext */
  42. copyd $r0 = $r17
  43. ret
  44. ;;
  45. 1:
  46. /* Store the $sp and $ra in the context to be saved */
  47. sd (MCONTEXT_Q12)[$r0] = $r12
  48. ;;
  49. sd (MCONTEXT_LC_LE_LS_RA + 24)[$r0] = $r16
  50. copyd $r0 = $r1
  51. goto __setcontext
  52. ;;
  53. END(swapcontext)