xref: /csrg-svn/lib/libc/tahoe/gen/setjmp.s (revision 34824)
1/*
2 * Copyright (c) 1988 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley.  The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * This code is derived from software contributed to Berkeley by
18 * Computer Consoles Inc.
19 */
20
21#if defined(LIBC_SCCS) && !defined(lint)
22	.asciz "@(#)setjmp.s	1.4 (Berkeley) 06/27/88"
23#endif /* LIBC_SCCS and not lint */
24
25/*
26 * C library -- setjmp, longjmp
27 *
28 *	longjmp(a,v)
29 * will generate a "return(v)" from
30 * the last call to
31 *	setjmp(a)
32 * by restoring registers from the stack,
33 * previous signal mask, and doing a return.
34 */
35
36#include "DEFS.h"
37
38ENTRY(setjmp, R6)
39	movl	4(fp),r6		# construct sigcontext
40	movab	-8(sp),sp		# space for current struct sigstack
41	pushal	(sp)			# get current values
42	pushl	$0			# no new values
43	callf	$16,_sigstack		# pop args plus signal stack value
44	movl	(sp)+,(r6)		# save onsigstack status of caller
45	pushl	$0
46	callf	$8,_sigblock		# get signal mask
47	movl	r0,4(r6)		# save signal mask of caller
48	addl3	$8,fp,8(r6)		# save stack pointer of caller
49	movl	(fp),12(r6)		# save frame pointer of caller
50	movl	-8(fp),20(r6)		# save pc of caller
51	movpsl	24(r6)			# save psl of caller
52	clrl	r0
53	ret
54
55ENTRY(longjmp, 0)
56	movl	8(fp),r0		# return(v)
57	movl	4(fp),r1		# fetch buffer
58	tstl	12(r1)
59	beql	botch
60loop:
61	cmpl	12(r1),(fp)
62	beql	done
63	blssu	botch
64	movl	$loop,-8(fp)
65	ret				# pop another frame
66
67done:
68	cmpb	*-8(fp),reiins		# returning to an "rei"?
69	bneq	1f
70	movab	3f,-8(fp)		# do return w/ psl-pc pop
71	brw	2f
721:
73	movab	4f,-8(fp)		# do standard return
742:
75	ret				# unwind stack before signals enabled
763:
77	addl2	$8,sp			# compensate for PSL-PC push
784:
79	pushl	r1			# pointer to sigcontext
80	callf	$4,_sigreturn		# restore previous context
81					# we should never return
82
83botch:
84	callf	$4,_longjmperror
85	halt
86
87	.data
88reiins:	rei
89