getcontext.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /*
  13. * int getcontext (ucontext_t *ucp)
  14. */
  15. ENTRY(__getcontext)
  16. /* Save callee saved registers ($r14, $r18 - $r31)
  17. * and some special registers */
  18. /* Save the entire occtuple, although we only need $sp and $r14 */
  19. so MCONTEXT_Q12[$r0] = $r12r13r14r15
  20. get $r4 = $lc
  21. ;;
  22. /* Don't need to save veneer registers $r16 and $r17 */
  23. sq (MCONTEXT_Q16 + 16)[$r0] = $r18r19
  24. get $r5 = $le
  25. ;;
  26. so MCONTEXT_Q20[$r0] = $r20r21r22r23
  27. get $r6 = $ls
  28. ;;
  29. so MCONTEXT_Q24[$r0] = $r24r25r26r27
  30. get $r7 = $ra
  31. ;;
  32. so MCONTEXT_Q28[$r0] = $r28r29r30r31
  33. get $r8 = $cs
  34. ;;
  35. so MCONTEXT_LC_LE_LS_RA[$r0] = $r4r5r6r7
  36. /* Save ucp and $ra in callee saved registers because below we need to
  37. * do a call to sigprocmask and afterwards we need to restore $ra. */
  38. copyd $r20 = $r0
  39. copyd $r21 = $r7
  40. ;;
  41. sd MCONTEXT_CS_SPC[$r0] = $r8
  42. /* Prepare call to sigprocmask */
  43. make $r0 = SIG_BLOCK
  44. make $r1 = 0
  45. ;;
  46. /* $r20 points to the ucontext */
  47. addd $r2 = $r20, UCONTEXT_SIGMASK
  48. /* Already set the return value for when this is called in the context
  49. * of swapcontext. Because when this context returns it should look
  50. * like as if swapcontext returned with 0. */
  51. sd MCONTEXT_Q0[$r20] = $r1
  52. ;;
  53. /* sigprocmask(SIG_BLOCK, NULL, &(ucontext->uc_sigmask)) */
  54. call sigprocmask
  55. ;;
  56. /* Restore $ra to point to the caller of this function. So,
  57. * __getcontext will return with -1 (set by __syscall_error) and an
  58. * appropriate errno */
  59. set $ra = $r21
  60. ;;
  61. /* Check return value of sigprocmask */
  62. cb.deqz $r0 ? 1f
  63. ;;
  64. goto __syscall_error
  65. ;;
  66. 1:
  67. /* Restore used callee saved registers */
  68. lq $r20r21 = MCONTEXT_Q20[$r20]
  69. ;;
  70. /* Set return value */
  71. make $r0 = 0
  72. ret
  73. ;;
  74. END(__getcontext)
  75. weak_alias(__getcontext, getcontext)