1/*******************************************************************************
2 *
3 * Copyright (c) 1993 Intel Corporation
4 *
5 * Intel hereby grants you permission to copy, modify, and distribute this
6 * software and its documentation.  Intel grants this permission provided
7 * that the above copyright notice appears in all copies and that both the
8 * copyright notice and this permission notice appear in supporting
9 * documentation.  In addition, Intel grants this permission provided that
10 * you prominently mark as "not part of the original" any modifications
11 * made to this software or documentation, and that the name of Intel
12 * Corporation not be used in advertising or publicity pertaining to
13 * distribution of the software or the documentation without specific,
14 * written prior permission.
15 *
16 * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
17 * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
18 * OR FITNESS FOR A PARTICULAR PURPOSE.  Intel makes no guarantee or
19 * representations regarding the use of, or the results of the use of,
20 * the software and documentation in terms of correctness, accuracy,
21 * reliability, currentness, or otherwise; and you rely on the software,
22 * documentation and results solely at your own risk.
23 *
24 * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
25 * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
26 * OF ANY KIND.  IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
27 * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
28 *
29 ******************************************************************************/
30
31/******************************************************************************/
32/*                                                                            */
33/*      setjmp(), longjmp()                                                   */
34/*                                                                            */
35/******************************************************************************/
36#include <picolibc.h>
37
38	.file "setjmp.as"
39	.text
40	/* .link_pix */
41
42	.align	4
43	.globl	_setjmp
44_setjmp:
45	flushreg
46	andnot	0xf,pfp,g1	/* get pfp, mask out return status bits */
47	st	g1, 0x58(g0)	/* save fp of caller*/
48   /* save globals not killed by the calling convention */
49	stq	g8, 0x40(g0)	/* save g8-g11*/
50	st	g12, 0x50(g0)	/* save g12*/
51	st	g14, 0x54(g0)	/* save g14*/
52   /* save previous frame local registers */
53	ldq	(g1), g4	/* get previous frame pfp, sp, rip, r3 */
54	stq	g4, (g0)	/* save pfp, sp, rip, r3 */
55	ldq	0x10(g1), g4	/* get previous frame r4-r7 */
56	stq	g4, 0x10(g0)	/* save r4-r7 */
57	ldq	0x20(g1), g4	/* get previous frame r8-r11 */
58	stq	g4, 0x20(g0)	/* save r8-r11 */
59	ldq	0x30(g1), g4	/* get previous frame r12-r15 */
60	stq	g4, 0x30(g0)	/* save r12-r15 */
61
62	mov	0, g0		/* return 0 */
63	ret
64
65   /*
66    * fake a return to the place that called the corresponding _setjmp
67   */
68	.align	4
69	.globl	_longjmp
70_longjmp:
71	call	0f		/* ensure there is at least one stack frame */
72
730:
74	flushreg		/* do this before swapping stack */
75	ld	0x58(g0), pfp	/* get fp of caller of setjmp */
76   /* restore local registers
77    * the following code modifies the frame of the function which originally
78    *  called setjmp.
79    */
80	ldq	(g0), g4	/* get pfp, sp, rip, r3 */
81	stq	g4, (pfp)	/* restore pfp, sp, rip, r3 */
82	ldq	0x10(g0), g4	/* get r4-r7 */
83	stq	g4, 0x10(pfp)	/* restore r4-r7 */
84	ldq	0x20(g0), g4	/* get r8-r11 */
85	stq	g4, 0x20(pfp)	/* restore r8-r11 */
86	ldq	0x30(g0), g4	/* get r12-r15 */
87	stq	g4, 0x30(pfp)	/* restore r12-r15 */
88   /* restore global registers */
89	ldq	0x40(g0), g8	/* get old g8-g11 values */
90	ld	0x50(g0), g12	/* get old g12 value */
91	ld	0x54(g0), g14	/* get old g14 value */
92
93	mov	g1, g0		/* get return value */
94	cmpo	g0, 0		/* make sure it is not zero */
95	bne	0f
96	mov	1, g0		/* return 1 by default */
970:
98	ret			/* return to caller of _setjmp */
99