__start_context.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) 2018 - 2022 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. #if defined(__XTENSA_CALL0_ABI__)
  16. /*
  17. * There's no entry instruction, makecontext sets up ucontext_t as if
  18. * getcontext was called above and is about to return here.
  19. * Registers on entry to this function:
  20. * a12: func to call
  21. * a13: ucp->uc_link, next context to activate if func returns
  22. * a14: func argc
  23. */
  24. .literal_position
  25. ENTRY_PREFIX(__start_context)
  26. beqz a14, 1f
  27. /* load func arguments 0..1 from stack and free that space */
  28. l32i a2, a1, 8
  29. l32i a3, a1, 12
  30. addi a1, a1, 16
  31. bltui a14, 3, 1f
  32. /* load func arguments 2..5 from stack and free that space */
  33. l32i a4, a1, 0
  34. l32i a5, a1, 4
  35. l32i a6, a1, 8
  36. l32i a7, a1, 12
  37. addi a1, a1, 16
  38. /* func arguments 6..argc - 1 are now at the top of the stack */
  39. 1:
  40. callx0 a12
  41. beqz a13, 1f
  42. mov a2, a13
  43. movi a4, JUMPTARGET (setcontext)
  44. callx0 a4
  45. 1:
  46. movi a4, JUMPTARGET (_exit)
  47. movi a2, 0
  48. callx0 a4
  49. ill
  50. END(__start_context)
  51. #elif defined(__XTENSA_WINDOWED_ABI__)
  52. /*
  53. * There's no entry instruction, makecontext sets up ucontext_t as if
  54. * getcontext was called above and is about to return here.
  55. * Registers on entry to this function:
  56. * a2: func to call
  57. * a3: ucp->uc_link, next context to activate if func returns
  58. * a4: func argc
  59. * a5..a7: func arguments 0..2
  60. */
  61. .literal_position
  62. ENTRY_PREFIX(__start_context)
  63. mov a10, a5
  64. mov a11, a6
  65. mov a12, a7
  66. bltui a4, 4, 1f
  67. /* load func arguments 3..5 from stack and free that space */
  68. l32i a13, a1, 4
  69. l32i a14, a1, 8
  70. l32i a15, a1, 12
  71. addi a5, a1, 16
  72. movsp a1, a5
  73. /* func arguments 6..argc - 1 are now at the top of the stack */
  74. 1:
  75. callx8 a2
  76. beqz a3, 1f
  77. mov a6, a3
  78. movi a4, JUMPTARGET (setcontext)
  79. callx4 a4
  80. 1:
  81. movi a4, JUMPTARGET (_exit)
  82. movi a6, 0
  83. callx4 a4
  84. ill
  85. END(__start_context)
  86. #else
  87. #error Unsupported Xtensa ABI
  88. #endif