__start_context.S 2.7 KB

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