1/* longjmp for Nios II.
2   Copyright (C) 2015-2021 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
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 License as
7   published by the Free Software Foundation; either version 2.1 of the
8   License, or (at your option) any later version.
9
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.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library.  If not, see
17   <https://www.gnu.org/licenses/>.  */
18
19#include <sysdep.h>
20#include <jmpbuf-offsets.h>
21
22/* __longjmp(jmpbuf, val) */
23
24ENTRY (__longjmp)
25	mov	r2, r5
26	bne	r5, zero, 1f
27	movi	r2, 1
281:
29#ifdef	PTR_DEMANGLE
30	PTR_MANGLE_GUARD (r3)
31	ldw	r5,  (JB_RA*4)(r4)
32	ldw	r6,  (JB_SP*4)(r4)
33	PTR_DEMANGLE (r5, r5, r3)
34	PTR_DEMANGLE (r6, r6, r3)
35#endif
36
37	cfi_def_cfa (r4, 0)
38	cfi_offset (r16, JB_R16*4)
39	cfi_offset (r17, JB_R17*4)
40	cfi_offset (r18, JB_R18*4)
41	cfi_offset (r19, JB_R19*4)
42	cfi_offset (r20, JB_R20*4)
43	cfi_offset (r21, JB_R21*4)
44	cfi_offset (r22, JB_R22*4)
45	cfi_offset (fp, JB_FP*4)
46#ifdef PTR_DEMANGLE
47	cfi_register (ra, r5)
48	cfi_register (sp, r7)
49#else
50	cfi_offset (ra, JB_RA*4)
51	cfi_offset (sp, JB_SP*4)
52#endif
53	ldw	r16, (JB_R16*4)(r4)
54	ldw	r17, (JB_R17*4)(r4)
55	ldw	r18, (JB_R18*4)(r4)
56	ldw	r19, (JB_R19*4)(r4)
57	ldw	r20, (JB_R20*4)(r4)
58	ldw	r21, (JB_R21*4)(r4)
59	ldw	r22, (JB_R22*4)(r4)
60	ldw	fp,  (JB_FP*4)(r4)
61#ifdef PTR_DEMANGLE
62	mov	ra, r5
63	mov	sp, r6
64#else
65	ldw	ra,  (JB_RA*4)(r4)
66	ldw	sp,  (JB_SP*4)(r4)
67#endif
68	cfi_same_value (r16)
69	cfi_same_value (r17)
70	cfi_same_value (r18)
71	cfi_same_value (r19)
72	cfi_same_value (r20)
73	cfi_same_value (r21)
74	cfi_same_value (r22)
75	cfi_same_value (fp)
76	cfi_same_value (ra)
77	cfi_same_value (sp)
78
79	ret
80END (__longjmp)
81