#################################################################
#								#
#	Copyright 2001, 2014 Fidelity Information Services, Inc	#
#								#
#	This source code contains the intellectual property	#
#	of its copyright holder(s), and is made available	#
#	under a license.  If you do not know the terms of	#
#	the license, please stop and do not read further.	#
#								#
#################################################################

	.sbttl	error.si
#	PAGE	+
#-----------------------------------------------
# Mumps error condition handler macros
#-----------------------------------------------
.ifdef cygwin
# will need another 8 to save sigmasks
chnd_size	=	228
.else
chnd_size	=	176
.endif
chnd_save_active =	0
chnd_ch_active	=	4
chnd_ch		=	12
chnd_jmp	=	16

.data
.extern	ctxt
.extern	active_ch

.text
.ifdef cygwin
#	on cygwin, sigsetjmp is a macro which calls sigprocmask then setjmp
.extern _setjmp
.else
#	setjmp is really __sigsetjmp(env,0)
.extern	__sigsetjmp
.extern gtm_asm_establish
.endif

	.sbttl	error.si    ESTABLISH
.macro ESTABLISH  x, label
        call	gtm_asm_establish		# Bulk of ESTABLISH macro
	movl	ctxt,%eax
	movl	$\x,chnd_ch(%eax)		# ctxt->ch = x
	addl	$chnd_jmp,%eax			# setjmp(ctxt->jmp)
.ifndef cygwin
	pushl	$0
.endif
	pushl 	%eax
.ifdef cygwin
	call _setjmp
	addl	$4,%esp
.else
	call 	__sigsetjmp
	addl  	$8,%esp
.endif
	incl  	%eax
	jne  	\label
	REVERT
	jmp  	return
\label:
.endm

	.sbttl	error.si    REVERT
.macro REVERT
	movl	ctxt,%eax			# active_ch = ctxt->save_active_c
	movl	chnd_save_active(%eax),%eax
	movl	%eax,active_ch
	subl  	$chnd_size,ctxt			# ctxt--
.endm
