setjmp.S revision 71579
1/*	$NetBSD: setjmp.S,v 1.3 1997/12/05 02:06:27 thorpej Exp $	*/
2/* $FreeBSD: head/lib/libc/ia64/gen/setjmp.S 71579 2001-01-24 13:01:12Z deischen $ */
3
4/*
5 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
6 * All rights reserved.
7 *
8 * Author: Chris G. Demetriou
9 *
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
15 *
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23 *  School of Computer Science
24 *  Carnegie Mellon University
25 *  Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
29 *
30 * $FreeBSD: head/lib/libc/ia64/gen/setjmp.S 71579 2001-01-24 13:01:12Z deischen $
31 */
32
33#include "SYS.h"
34
35/*
36 * C library -- setjmp, longjmp
37 *
38 *	longjmp(a,v)
39 * will generate a "return(v)" from
40 * the last call to
41 *	setjmp(a)
42 * by restoring registers from the stack,
43 * and the previous signal state.
44 */
45
46ENTRY(setjmp, 1)
47	mov	ret0=r0
48	br.ret.sptk.few rp
49
50#if 0
51	LDGP(pv)
52	stq	ra, (2 * 8)(a0)			/* sc_pc = return address */
53	stq	s0, (( 9 + 4) * 8)(a0)		/* saved bits of sc_regs */
54	stq	s1, ((10 + 4) * 8)(a0)
55	stq	s2, ((11 + 4) * 8)(a0)
56	stq	s3, ((12 + 4) * 8)(a0)
57	stq	s4, ((13 + 4) * 8)(a0)
58	stq	s5, ((14 + 4) * 8)(a0)
59	stq	s6, ((15 + 4) * 8)(a0)
60	stq	ra, ((26 + 4) * 8)(a0)
61	stq	sp, ((30 + 4) * 8)(a0)
62
63	/*
64	 * get signal information
65	 */
66	mov	a0, s0				/* squirrel away ptr to sc */
67
68	/* see what's blocked */
69	lda	a2, (71 * 8)(a0)		/* oset: sc_reserved */
70	mov	zero, a1			/* set:	 NULL */
71	addq	a1, 1, a0			/* how:	 SIG_BLOCK */
72	CALL(_sigprocmask)			/* see what's blocked */
73
74	lda	sp, -24(sp)			/* sizeof struct sigaltstack */
75	mov	zero, a0
76	mov	sp, a1
77	CALL(_sigaltstack)
78	ldl	t0, 16(sp)			/* offset of ss_flags */
79	lda	sp, 24(sp)			/* sizeof struct sigaltstack */
80	ldq	ra, ((26 + 4) * 8)(s0)		/* restore return address */
81	blt	v0, botch			/* check for error */
82	and	t0, 0x1, t0			/* get SA_ONSTACK flag */
83	stq	t0, (0 * 8)(s0)			/* and save it in sc_onstack */
84	/*
85	 * Restore old s0 and a0, and continue saving registers
86	 */
87	mov	s0, a0
88	ldq	s0, (( 9 + 4) * 8)(a0)
89
90	ldiq	t0, 0xacedbade			/* sigcontext magic number */
91	stq	t0, ((31 + 4) * 8)(a0)		/* magic in sc_regs[31] */
92	/* Too bad we can't check if we actually used FP */
93	ldiq	t0, 1
94	stq	t0, (36 * 8)(a0)		/* say we've used FP.  */
95	stt	fs0, ((2 + 37) * 8)(a0)		/* saved bits of sc_fpregs */
96	stt	fs1, ((3 + 37) * 8)(a0)
97	stt	fs2, ((4 + 37) * 8)(a0)
98	stt	fs3, ((5 + 37) * 8)(a0)
99	stt	fs4, ((6 + 37) * 8)(a0)
100	stt	fs5, ((7 + 37) * 8)(a0)
101	stt	fs6, ((8 + 37) * 8)(a0)
102	stt	fs7, ((9 + 37) * 8)(a0)
103	mf_fpcr	ft0				/* get FP control reg */
104	stt	ft0, (69 * 8)(a0)		/* and store it in sc_fpcr */
105	stq	zero, (70 * 8)(a0)		/* FP software control XXX */
106	stq	zero, (71 * 8)(a0)		/* sc_reserved[0] */
107	stq	zero, (72 * 8)(a0)		/* sc_reserved[1] */
108	stq	zero, (73 * 8)(a0)		/* sc_xxx[0] */
109	stq	zero, (74 * 8)(a0)		/* sc_xxx[1] */
110	stq	zero, (75 * 8)(a0)		/* sc_xxx[2] */
111	stq	zero, (76 * 8)(a0)		/* sc_xxx[3] */
112	stq	zero, (77 * 8)(a0)		/* sc_xxx[4] */
113	stq	zero, (78 * 8)(a0)		/* sc_xxx[5] */
114	stq	zero, (79 * 8)(a0)		/* sc_xxx[6] */
115	stq	zero, (80 * 8)(a0)		/* sc_xxx[7] */
116
117	mov	zero, v0			/* return zero */
118	RET
119#endif
120END(setjmp)
121
122XENTRY(longjmp)
123ENTRY(__longjmp, 2)
124#if 0
125	LDGP(pv)
126	stq	a1, (( 0 + 4) * 8)(a0)		/* save return value */
127	PCALL(_sigreturn)			/* use sigreturn to return */
128
129botch:
130	CALL(longjmperror)
131	CALL(abort)
132	RET					/* "can't" get here... */
133END(__longjmp)
134