1/* Copyright (C) 2011-2018 Free Software Foundation, Inc.
2
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
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
13   You should have received a copy of the GNU Lesser General Public
14   License along with the GNU C Library.  If not, see
15   <http://www.gnu.org/licenses/>.  */
16
17#include <sysdep.h>
18#include <jmpbuf-offsets.h>
19#include <arch/spr_def.h>
20
21/* PL to return to via iret in longjmp */
22#define RETURN_PL 0
23
24	.text
25ENTRY (__longjmp)
26
27#define RESTORE(r) { ld r, r0 ; ADDI_PTR r0, r0, REGSIZE }
28	FOR_EACH_CALLEE_SAVED_REG(RESTORE)
29
30	/* Make longjmp(buf, 0) return "1" instead.
31	   At the same time, construct our iret context; we set ICS so
32	   we can validly load EX_CONTEXT for iret without being
33	   interrupted halfway through.  */
34	{
35	 ld r2, r0   /* retrieve ICS bit from jmp_buf */
36	 movei r3, 1
37	 cmpeqi r0, r1, 0
38	}
39	{
40	 mtspr INTERRUPT_CRITICAL_SECTION, r3
41	 shli r2, r2, SPR_EX_CONTEXT_0_1__ICS_SHIFT
42	}
43	{
44	 mtspr EX_CONTEXT_0_0, lr
45	 ori r2, r2, RETURN_PL
46	}
47	{
48	 or r0, r1, r0
49	 mtspr EX_CONTEXT_0_1, r2
50	}
51	iret
52	jrp lr   /* Keep the backtracer happy. */
53END (__longjmp)
54libc_hidden_def(__longjmp)
55