xref: /netbsd-src/lib/libc/compat/arch/alpha/gen/compat__setjmp.S (revision 2a8eed4fde034413bbd2c73fbcf4983cbfdeded7)
1*2a8eed4fSthorpej/* $NetBSD: compat__setjmp.S,v 1.5 2021/05/25 00:14:41 thorpej Exp $ */
2153a0d26Sdrochner
3153a0d26Sdrochner/*
4153a0d26Sdrochner * Copyright (c) 1994, 1995 Carnegie-Mellon University.
5153a0d26Sdrochner * All rights reserved.
6153a0d26Sdrochner *
7153a0d26Sdrochner * Author: Chris G. Demetriou
8153a0d26Sdrochner *
9153a0d26Sdrochner * Permission to use, copy, modify and distribute this software and
10153a0d26Sdrochner * its documentation is hereby granted, provided that both the copyright
11153a0d26Sdrochner * notice and this permission notice appear in all copies of the
12153a0d26Sdrochner * software, derivative works or modified versions, and any portions
13153a0d26Sdrochner * thereof, and that both notices appear in supporting documentation.
14153a0d26Sdrochner *
15153a0d26Sdrochner * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16153a0d26Sdrochner * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17153a0d26Sdrochner * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18153a0d26Sdrochner *
19153a0d26Sdrochner * Carnegie Mellon requests users of this software to return to
20153a0d26Sdrochner *
21153a0d26Sdrochner *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22153a0d26Sdrochner *  School of Computer Science
23153a0d26Sdrochner *  Carnegie Mellon University
24153a0d26Sdrochner *  Pittsburgh PA 15213-3890
25153a0d26Sdrochner *
26153a0d26Sdrochner * any improvements or extensions that they make and grant Carnegie the
27153a0d26Sdrochner * rights to redistribute these changes.
28153a0d26Sdrochner */
29153a0d26Sdrochner
30153a0d26Sdrochner#include <machine/asm.h>
31153a0d26Sdrochner
32153a0d26Sdrochner/*
33153a0d26Sdrochner * C library -- _setjmp, _longjmp
34153a0d26Sdrochner *
35153a0d26Sdrochner *	_longjmp(a,v)
36153a0d26Sdrochner * will generate a "return(v)" from
37153a0d26Sdrochner * the last call to
38153a0d26Sdrochner *	_setjmp(a)
39153a0d26Sdrochner * by restoring registers from the stack,
40153a0d26Sdrochner * The previous signal state is NOT restored.
41153a0d26Sdrochner */
42153a0d26Sdrochner
43153a0d26Sdrochner	.set	noreorder
44153a0d26Sdrochner
45153a0d26SdrochnerLEAF(_setjmp, 1)
46153a0d26Sdrochner	LDGP(pv)
47153a0d26Sdrochner	stq	ra, (2 * 8)(a0)			/* sc_pc = return address */
48153a0d26Sdrochner	stq	s0, (( 9 + 4) * 8)(a0)		/* saved bits of sc_regs */
49153a0d26Sdrochner	stq	s1, ((10 + 4) * 8)(a0)
50153a0d26Sdrochner	stq	s2, ((11 + 4) * 8)(a0)
51153a0d26Sdrochner	stq	s3, ((12 + 4) * 8)(a0)
52153a0d26Sdrochner	stq	s4, ((13 + 4) * 8)(a0)
53153a0d26Sdrochner	stq	s5, ((14 + 4) * 8)(a0)
54153a0d26Sdrochner	stq	s6, ((15 + 4) * 8)(a0)
55153a0d26Sdrochner	stq	ra, ((26 + 4) * 8)(a0)
56153a0d26Sdrochner	stq	sp, ((30 + 4) * 8)(a0)
57eb850bdaSchristos	ldq	t0, magic			/* sigcontext magic number */
58153a0d26Sdrochner	stq	t0, ((31 + 4) * 8)(a0)		/* magic in sc_regs[31] */
59153a0d26Sdrochner	/* Too bad we can't check if we actually used FP */
60153a0d26Sdrochner	ldiq	t0, 1
61153a0d26Sdrochner	stq	t0, (36 * 8)(a0)		/* say we've used FP.  */
62153a0d26Sdrochner	stt	fs0, ((2 + 37) * 8)(a0)		/* saved bits of sc_fpregs */
63153a0d26Sdrochner	stt	fs1, ((3 + 37) * 8)(a0)
64153a0d26Sdrochner	stt	fs2, ((4 + 37) * 8)(a0)
65153a0d26Sdrochner	stt	fs3, ((5 + 37) * 8)(a0)
66153a0d26Sdrochner	stt	fs4, ((6 + 37) * 8)(a0)
67153a0d26Sdrochner	stt	fs5, ((7 + 37) * 8)(a0)
68153a0d26Sdrochner	stt	fs6, ((8 + 37) * 8)(a0)
69153a0d26Sdrochner	stt	fs7, ((9 + 37) * 8)(a0)
70153a0d26Sdrochner	mf_fpcr ft0				/* get FP control reg */
71153a0d26Sdrochner	stt	ft0, (69 * 8)(a0)		/* and store it in sc_fpcr */
72153a0d26Sdrochner	stq	zero, (70 * 8)(a0)		/* FP software control XXX */
73153a0d26Sdrochner	stq	zero, (71 * 8)(a0)		/* sc_reserved[0] */
74153a0d26Sdrochner	stq	zero, (72 * 8)(a0)		/* sc_reserved[1] */
75153a0d26Sdrochner	stq	zero, (73 * 8)(a0)		/* sc_xxx[0] */
76153a0d26Sdrochner	stq	zero, (74 * 8)(a0)		/* sc_xxx[1] */
77153a0d26Sdrochner	stq	zero, (75 * 8)(a0)		/* sc_xxx[2] */
78153a0d26Sdrochner	stq	zero, (76 * 8)(a0)		/* sc_xxx[3] */
79153a0d26Sdrochner	stq	zero, (77 * 8)(a0)		/* sc_xxx[4] */
80153a0d26Sdrochner	stq	zero, (78 * 8)(a0)		/* sc_xxx[5] */
81153a0d26Sdrochner	stq	zero, (79 * 8)(a0)		/* sc_xxx[6] */
82153a0d26Sdrochner	stq	zero, (80 * 8)(a0)		/* sc_xxx[7] */
83153a0d26Sdrochner
84153a0d26Sdrochner	mov	zero, v0			/* return zero */
85153a0d26Sdrochner	RET
86eb850bdaSchristosmagic:
87eb850bdaSchristos	.quad 0xacedbadd
88153a0d26SdrochnerEND(_setjmp)
89153a0d26Sdrochner
90153a0d26SdrochnerLEAF(_longjmp, 2)
91153a0d26Sdrochner	LDGP(pv)
92153a0d26Sdrochner	ldq	t0, ((31 + 4) * 8)(a0)		/* magic in sc_regs[31] */
93b8d67b75Sskrll	ldq	t1, magic			/* sigcontext magic number */
94153a0d26Sdrochner	cmpeq	t0, t1, t0
95153a0d26Sdrochner	beq	t0, botch			/* If the magic was bad, punt */
96153a0d26Sdrochner
97153a0d26Sdrochner	ldq	ra, (2 * 8)(a0)			/* sc_pc = return address */
98153a0d26Sdrochner	ldq	s0, (( 9 + 4) * 8)(a0)		/* saved bits of sc_regs */
99153a0d26Sdrochner	ldq	s1, ((10 + 4) * 8)(a0)
100153a0d26Sdrochner	ldq	s2, ((11 + 4) * 8)(a0)
101153a0d26Sdrochner	ldq	s3, ((12 + 4) * 8)(a0)
102153a0d26Sdrochner	ldq	s4, ((13 + 4) * 8)(a0)
103153a0d26Sdrochner	ldq	s5, ((14 + 4) * 8)(a0)
104153a0d26Sdrochner	ldq	s6, ((15 + 4) * 8)(a0)
105153a0d26Sdrochner	/* ldq	ra, ((26 + 4) * 8)(a0)		set above */
106153a0d26Sdrochner	ldq	sp, ((30 + 4) * 8)(a0)
107153a0d26Sdrochner	ldt	fs0, ((2 + 37) * 8)(a0)		/* saved bits of sc_fpregs */
108153a0d26Sdrochner	ldt	fs1, ((3 + 37) * 8)(a0)
109153a0d26Sdrochner	ldt	fs2, ((4 + 37) * 8)(a0)
110153a0d26Sdrochner	ldt	fs3, ((5 + 37) * 8)(a0)
111153a0d26Sdrochner	ldt	fs4, ((6 + 37) * 8)(a0)
112153a0d26Sdrochner	ldt	fs5, ((7 + 37) * 8)(a0)
113153a0d26Sdrochner	ldt	fs6, ((8 + 37) * 8)(a0)
114153a0d26Sdrochner	ldt	fs7, ((9 + 37) * 8)(a0)
115153a0d26Sdrochner	ldt	ft0, (69 * 8)(a0)		/* get sc_fpcr */
116153a0d26Sdrochner	mt_fpcr	ft0				/* and restore it. */
117153a0d26Sdrochner
118*2a8eed4fSthorpej	bne	a1, 1f				/* val != 0, just go */
119*2a8eed4fSthorpej	ldiq	a1, 1				/* val = 1 otherwise */
120*2a8eed4fSthorpej1:	mov	a1, v0				/* return second arg */
121153a0d26Sdrochner	RET
122153a0d26Sdrochner
123153a0d26Sdrochnerbotch:
124153a0d26Sdrochner	CALL(longjmperror)
125153a0d26Sdrochner	CALL(abort)
126153a0d26Sdrochner	RET					/* "can't" get here... */
127153a0d26SdrochnerEND(_longjmp)
128