xref: /csrg-svn/lib/libc/sparc/gen/setjmp.s (revision 54389)
1*54389Storek/*
2*54389Storek * Copyright (c) 1992 The Regents of the University of California.
3*54389Storek * All rights reserved.
4*54389Storek *
5*54389Storek * This software was developed by the Computer Systems Engineering group
6*54389Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7*54389Storek * contributed to Berkeley.
8*54389Storek *
9*54389Storek * %sccs.include.redist.c%
10*54389Storek *
11*54389Storek * from: $Header: setjmp.s,v 1.2 92/06/25 03:18:43 torek Exp $
12*54389Storek */
13*54389Storek
14*54389Storek#if defined(LIBC_SCCS) && !defined(lint)
15*54389Storek	.asciz "@(#)setjmp.s	5.1 (Berkeley) 06/25/92"
16*54389Storek#endif /* LIBC_SCCS and not lint */
17*54389Storek
18*54389Storek/*
19*54389Storek * C library -- setjmp, longjmp
20*54389Storek *
21*54389Storek *	longjmp(a,v)
22*54389Storek * will generate a "return(v)" from
23*54389Storek * the last call to
24*54389Storek *	setjmp(a)
25*54389Storek * by restoring registers from the stack,
26*54389Storek * and a struct sigcontext, see <signal.h>
27*54389Storek */
28*54389Storek
29*54389Storek#include "SYS.h"
30*54389Storek
31*54389StorekENTRY(setjmp)
32*54389Storek	/*
33*54389Storek	 * We use the caller's `arg dump' area (%sp+0x44; there are 6 ints
34*54389Storek	 * reserved there for us) to avoid having to allocate stack space
35*54389Storek	 * here.
36*54389Storek	 */
37*54389Storek	mov	%o0, %o2	/* build sigcontext in [%o2] */
38*54389Storek	mov	1, %o0		/* SIG_BLOCK */
39*54389Storek	mov	SYS_sigprocmask, %g1
40*54389Storek	clr	%o1		/* sigprocmask(SIG_BLOCK, (sigset_t *)NULL) */
41*54389Storek	t	ST_SYSCALL
42*54389Storek	st	%o0, [%o2 + 4]	/* sc.sc_mask = current mask; */
43*54389Storek	mov	SYS_sigaltstack, %g1
44*54389Storek	clr	%o0		/* sigstack(NULL, &foo) */
45*54389Storek	add	%sp, 0x48, %o1	/* (foo being in arg dump area) */
46*54389Storek	t	ST_SYSCALL
47*54389Storek	ld	[%sp + 0x50], %o0	/* foo.ss_flags */
48*54389Storek	and	%o0, 1, %o1	/* onstack = foo.ss_flags & 1; */
49*54389Storek	st	%o0, [%o2 + 0]	/* sc.sc_onstack = current onstack; */
50*54389Storek	st	%sp, [%o2 + 8]	/* sc.sc_sp = sp (both ours and caller's) */
51*54389Storek	add	%o7, 8, %o0
52*54389Storek	st	%o0, [%o2 + 12]	/* sc.sc_pc = return_pc */
53*54389Storek	add	%o7, 12, %o0
54*54389Storek	st	%o0, [%o2 + 16]	/* sc.sc_npc = return_pc + 4 */
55*54389Storek	st	%g0, [%o2 + 20]	/* sc.sc_psr = (clean psr) */
56*54389Storek	st	%fp, [%o2 + 24]	/* sc.sc_g1 = %fp (misuse, but what the heck) */
57*54389Storek				/* sc.sc_o0 = random(), set in longjmp */
58*54389Storek	retl			/* return 0 */
59*54389Storek	 clr	%o0
60*54389Storek
61*54389Storek/*
62*54389Storek * All we need to do here is force sigreturn to load a new stack pointer,
63*54389Storek * new <pc,npc>, and appropriate %o0 return value from the sigcontext built
64*54389Storek * in setjmp.  The %i and %l registers will be reloaded from the place to
65*54389Storek * which %sp points, due to sigreturn() semantics (sigreturn does not modify
66*54389Storek * the window pointer in the psr, hence it must force all windows to reload).
67*54389Storek */
68*54389StorekENTRY(longjmp)
69*54389Storek	save	%sp, -96, %sp
70*54389Storek	ld	[%i0 + 8], %o2	/* make sure sc->sc_sp, sc->sc_fp nonzero */
71*54389Storek	ld	[%i0 + 24], %o3
72*54389Storek	orcc	%o2, %o3, %g0
73*54389Storek	bz	Lbotch
74*54389Storek	 tst	%i1		/* if (v == 0) v = 1; */
75*54389Storek	bz,a	1f
76*54389Storek	 mov	1, %i1
77*54389Storek1:
78*54389Storek	st	%i1, [%i0 + 28]	/* sc.sc_o0 = v; */
79*54389Storek	mov	SYS_sigreturn, %g1
80*54389Storek	mov	%i0, %o0
81*54389Storek	t	ST_SYSCALL	/* sigreturn(scp); */
82*54389Storek
83*54389StorekLbotch:
84*54389Storek	/* oops, caller botched it */
85*54389Storek	call	_longjmperror
86*54389Storek	 nop
87*54389Storek	unimp	0
88