xref: /illumos-gate/usr/src/lib/libc/i386/gen/setjmp.S (revision 5d9d9091)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
59a70fc3bSMark J. Nelson * Common Development and Distribution License (the "License").
69a70fc3bSMark J. Nelson * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
213de0cfbbSRoger A. Faulkner
227c478bd9Sstevel@tonic-gate/*
233de0cfbbSRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
279a70fc3bSMark J. Nelson	.file	"setjmp.s"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate/	longjmp(env, val)
307c478bd9Sstevel@tonic-gate/ will generate a "return(val)" from
317c478bd9Sstevel@tonic-gate/ the last call to
327c478bd9Sstevel@tonic-gate/	setjmp(env)
337c478bd9Sstevel@tonic-gate/ by restoring registers ip, sp, bp, bx, si, and di from 'env'
347c478bd9Sstevel@tonic-gate/ and doing a return.
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate/ entry    reg	offset from (%si)
377c478bd9Sstevel@tonic-gate/ env[0] = %ebx	 0	/ register variables
387c478bd9Sstevel@tonic-gate/ env[1] = %esi	 4
397c478bd9Sstevel@tonic-gate/ env[2] = %edi	 8
407c478bd9Sstevel@tonic-gate/ env[3] = %ebp	 12	/ stack frame
417c478bd9Sstevel@tonic-gate/ env[4] = %esp	 16
427c478bd9Sstevel@tonic-gate/ env[5] = %eip	 20
433de0cfbbSRoger A. Faulkner/ env[6] = jmp flags 24
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
463de0cfbbSRoger A. Faulkner#include <../assym.h>
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(setjmp,function)
497c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(longjmp,function)
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate	ENTRY(setjmp)
527c478bd9Sstevel@tonic-gate	movl	4(%esp),%eax	/ jmpbuf address
537c478bd9Sstevel@tonic-gate	movl	%ebx,0(%eax)	/ save ebx
547c478bd9Sstevel@tonic-gate	movl	%esi,4(%eax)	/ save esi
557c478bd9Sstevel@tonic-gate	movl	%edi,8(%eax)	/ save edi
567c478bd9Sstevel@tonic-gate	movl	%ebp,12(%eax)	/ save caller's ebp
573de0cfbbSRoger A. Faulkner
583de0cfbbSRoger A. Faulkner	movl	%gs:UL_SIGLINK, %ecx
593de0cfbbSRoger A. Faulkner	xorl	%edx, %edx
603de0cfbbSRoger A. Faulkner	test	%ecx, %ecx	/ are we in a signal handler?
613de0cfbbSRoger A. Faulkner	jnz	1f
623de0cfbbSRoger A. Faulkner	inc	%edx		/ no, tell longjmp to clear ul_siglink
633de0cfbbSRoger A. Faulkner1:	movl	%edx, 24(%eax)	/ set flag word
643de0cfbbSRoger A. Faulkner
657c478bd9Sstevel@tonic-gate	popl	%edx		/ return address
667c478bd9Sstevel@tonic-gate	movl	%esp,16(%eax)	/ save caller's esp
673de0cfbbSRoger A. Faulkner	movl	%edx,20(%eax)	/ save caller's return address
683de0cfbbSRoger A. Faulkner	xorl	%eax, %eax	/ return 0
697c478bd9Sstevel@tonic-gate	pushl	%edx
707c478bd9Sstevel@tonic-gate	ret
717c478bd9Sstevel@tonic-gate	SET_SIZE(setjmp)
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate	ENTRY(longjmp)
747c478bd9Sstevel@tonic-gate	movl	4(%esp),%edx	/ first parameter after return addr
757c478bd9Sstevel@tonic-gate	movl	8(%esp),%eax	/ second parameter
767c478bd9Sstevel@tonic-gate	movl	0(%edx),%ebx	/ restore ebx
777c478bd9Sstevel@tonic-gate	movl	4(%edx),%esi	/ restore esi
787c478bd9Sstevel@tonic-gate	movl	8(%edx),%edi	/ restore edi
797c478bd9Sstevel@tonic-gate	movl	12(%edx),%ebp	/ restore caller's ebp
807c478bd9Sstevel@tonic-gate	movl	16(%edx),%esp	/ restore caller's esp
813de0cfbbSRoger A. Faulkner
823de0cfbbSRoger A. Faulkner	movl	24(%edx), %ecx
833de0cfbbSRoger A. Faulkner	test	%ecx, %ecx	/ test flag word
843de0cfbbSRoger A. Faulkner	jz	1f
853de0cfbbSRoger A. Faulkner	xorl	%ecx, %ecx	/ if set, clear ul_siglink
863de0cfbbSRoger A. Faulkner	movl	%ecx, %gs:UL_SIGLINK
873de0cfbbSRoger A. Faulkner1:
887c478bd9Sstevel@tonic-gate	test	%eax,%eax	/ if val != 0
893de0cfbbSRoger A. Faulkner	jnz	1f		/ 	return val
907c478bd9Sstevel@tonic-gate	incl	%eax		/ else return 1
913de0cfbbSRoger A. Faulkner1:
927c478bd9Sstevel@tonic-gate	jmp	*20(%edx)	/ return to caller
937c478bd9Sstevel@tonic-gate	SET_SIZE(longjmp)
94