__longjmp.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* longjmp for Xtensa Processors.
  2. Copyright (C) 2001, 2007 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. /* This implementation relies heavily on the Xtensa register window
  17. mechanism. Setjmp flushes all the windows except its own to the
  18. stack and then copies registers from the save areas on the stack
  19. into the jmp_buf structure, along with the return address of the call
  20. to setjmp. Longjmp invalidates all the windows except its own, and
  21. then sets things up so that it will return to the right place,
  22. using a window underflow to automatically restore the registers.
  23. Note that it would probably be sufficient to only copy the
  24. registers from setjmp's caller into jmp_buf. However, we also copy
  25. the save area located at the stack pointer of setjmp's caller.
  26. This save area will typically remain intact until the longjmp call.
  27. The one exception is when there is an intervening alloca in
  28. setjmp's caller. This is certainly an unusual situation and is
  29. likely to cause problems in any case (the storage allocated on the
  30. stack cannot be safely accessed following the longjmp). As bad as
  31. it is, on most systems this situation would not necessarily lead to
  32. a catastrophic failure. If we did not preserve the extra save area
  33. on Xtensa, however, it would. When setjmp's caller returns after a
  34. longjmp, there will be a window underflow; an invalid return
  35. address or stack pointer in the save area will almost certainly
  36. lead to a crash. Keeping a copy of the extra save area in the
  37. jmp_buf avoids this with only a small additional cost. If setjmp
  38. and longjmp are ever time-critical, this could be removed. */
  39. #include "sysdep.h"
  40. ENTRY (__longjmp)
  41. /* Invalidate all but the current window. Reading and writing
  42. special registers WINDOWBASE and WINDOWSTART are
  43. privileged operations, so user processes must call the
  44. slower __window_spill() to do the job. */
  45. movi a4, __window_spill
  46. callx4 a4
  47. /* Return to the return address of the setjmp, using the
  48. window size bits from the setjmp call so that the caller
  49. will be able to find the return value that we put in a2. */
  50. l32i a0, a2, 64
  51. /* Copy the first 4 saved registers from jmp_buf into the save area
  52. at the current sp so that the values will be restored to registers
  53. when longjmp returns. */
  54. addi a7, a1, -16
  55. l32i a4, a2, 0
  56. l32i a5, a2, 4
  57. s32i a4, a7, 0
  58. s32i a5, a7, 4
  59. l32i a4, a2, 8
  60. l32i a5, a2, 12
  61. s32i a4, a7, 8
  62. s32i a5, a7, 12
  63. /* Copy the remaining 0-8 saved registers. */
  64. extui a7, a0, 30, 2
  65. blti a7, 2, .Lendlj
  66. l32i a8, a2, 52
  67. slli a4, a7, 4
  68. sub a6, a8, a4
  69. addi a5, a2, 16
  70. addi a8, a8, -16 /* a8 = end of register overflow area */
  71. .Lljloop:
  72. l32i a7, a5, 0
  73. l32i a4, a5, 4
  74. s32i a7, a6, 0
  75. s32i a4, a6, 4
  76. l32i a7, a5, 8
  77. l32i a4, a5, 12
  78. s32i a7, a6, 8
  79. s32i a4, a6, 12
  80. addi a5, a5, 16
  81. addi a6, a6, 16
  82. blt a6, a8, .Lljloop
  83. .Lendlj:
  84. /* The 4 words saved from the register save area at the target's
  85. sp are copied back to the target procedure's save area. The
  86. only point of this is to prevent a catastrophic failure in
  87. case the contents were moved by an alloca after calling
  88. setjmp. This is a bit paranoid but it doesn't cost much. */
  89. l32i a7, a2, 4 /* load the target stack pointer */
  90. addi a7, a7, -16 /* find the destination save area */
  91. l32i a4, a2, 48
  92. l32i a5, a2, 52
  93. s32i a4, a7, 0
  94. s32i a5, a7, 4
  95. l32i a4, a2, 56
  96. l32i a5, a2, 60
  97. s32i a4, a7, 8
  98. s32i a5, a7, 12
  99. /* Return v ? v : 1. */
  100. movi a2, 1
  101. movnez a2, a3, a3
  102. retw
  103. END (__longjmp)
  104. libc_hidden_def (__longjmp)