1 /* longjmp for Xtensa Processors.
3 Copyright (C) 2001, 2007 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
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. */
51 /* Invalidate all but the current window. Reading and writing
52 special registers WINDOWBASE and WINDOWSTART are
53 privileged operations, so user processes must call the
54 slower __window_spill() to do the job. */
56 movi a4, __window_spill
59 /* Return to the return address of the setjmp, using the
60 window size bits from the setjmp call so that the caller
61 will be able to find the return value that we put in a2. */
65 /* Copy the first 4 saved registers from jmp_buf into the save area
66 at the current sp so that the values will be restored to registers
67 when longjmp returns. */
79 /* Copy the remaining 0-8 saved registers. */
86 addi a8, a8, -16 /* a8 = end of register overflow area */
101 /* The 4 words saved from the register save area at the target's
102 sp are copied back to the target procedure's save area. The
103 only point of this is to prevent a catastrophic failure in
104 case the contents were moved by an alloca after calling
105 setjmp. This is a bit paranoid but it doesn't cost much. */
107 l32i a7, a2, 4 /* load the target stack pointer */
108 addi a7, a7, -16 /* find the destination save area */
118 /* Return v ? v : 1. */
125 libc_hidden_def (__longjmp)