1 /* setjmp for Xtensa Processors.
2 Copyright (C) 2001, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18 Boston, MA 02110-1301, USA. */
20 /* This implementation relies heavily on the Xtensa register window
21 mechanism. Setjmp flushes all the windows except its own to the
22 stack and then copies registers from the save areas on the stack
23 into the jmp_buf structure, along with the return address of the call
24 to setjmp. Longjmp invalidates all the windows except its own, and
25 then sets things up so that it will return to the right place,
26 using a window underflow to automatically restore the registers.
28 Note that it would probably be sufficient to only copy the
29 registers from setjmp's caller into jmp_buf. However, we also copy
30 the save area located at the stack pointer of setjmp's caller.
31 This save area will typically remain intact until the longjmp call.
32 The one exception is when there is an intervening alloca in
33 setjmp's caller. This is certainly an unusual situation and is
34 likely to cause problems in any case (the storage allocated on the
35 stack cannot be safely accessed following the longjmp). As bad as
36 it is, on most systems this situation would not necessarily lead to
37 a catastrophic failure. If we did not preserve the extra save area
38 on Xtensa, however, it would. When setjmp's caller returns after a
39 longjmp, there will be a window underflow; an invalid return
40 address or stack pointer in the save area will almost certainly
41 lead to a crash. Keeping a copy of the extra save area in the
42 jmp_buf avoids this with only a small additional cost. If setjmp
43 and longjmp are ever time-critical, this could be removed. */
47 /* int setjmp (a2 = jmp_buf env) */
53 libc_hidden_def (_setjmp)
60 /* int __sigsetjmp (a2 = jmp_buf env,
65 /* Flush registers. */
66 movi a4, __window_spill
69 /* Preserve the second argument (savemask) in a15. The selection
70 of a15 is arbitrary, except it's otherwise unused. There is no
71 risk of triggering a window overflow since we just returned
72 from __window_spill(). */
75 /* Copy the register save area at (sp - 16). */
86 /* Copy 0-8 words from the register overflow area. */
93 addi a7, a7, -16 // a7 = end of register overflow area
108 /* Copy the register save area at sp. */
118 /* Save the return address, including the window size bits. */
121 /* a2 still addresses jmp_buf. a15 contains savemask. */
124 movi a3, __sigjmp_save