.386p

_TEXT_BIMO	SEGMENT	PARA USE16 PRIVATE 'CODE'
	ASSUME	cs:_TEXT_BIMO

	PUBLIC	autopassup_handler_
	org	0
autopassup_handler_:
	cli
	int	3
;	mov	cs:old_ss, ss
	db	2eh,8ch,16h,31h,00h
;	mov	cs:old_sp, sp
	db	2eh,89h,26h,33h,00h
	push	cs
	pop	ss
;	lea	sp, temp_stack
	db	0bch,00h,01h
	push	ds
	push	es
	push	fs
	push	gs
	pushad
	mov	ax, 0b7feh
	int	14h
	popad
	pop	gs
	pop	fs
	pop	es
	pop	ds
;	mov	ss, cs:old_ss
;	mov	sp, cs:old_sp
	db	2eh,8eh,16h,31h,00h
	db	2eh,8bh,26h,33h,00h
	iret
old_ss	dw	0
old_sp  dw	0
	org	256		; pad to 256 bytes
temp_stack:
_TEXT_BIMO	ENDS

_DATA	SEGMENT BYTE USE32 PUBLIC 'DATA'
	extrn   _old_ap_func:pword
_DATA	ENDS
	
	extrn   do_autopassup_:far
	
_TEXT	SEGMENT	BYTE USE32 PUBLIC 'CODE'
	ASSUME	cs:_TEXT

	PUBLIC	asm_do_autopassup_
asm_do_autopassup_:
	cmp	ax, 0b7feh
	je	short our_passup_message
	jmp	done
our_passup_message:
	pushfd
	cli
	call	do_autopassup_
	iretd
done:	
	push	cs
	push	eax
	push	ds
	push	ebp
	push	eax
	mov	ax, _DATA
	mov	ds, ax
	assume	ds:_DATA
	mov	ebp, esp
	mov	eax, dword ptr [_old_ap_func]
	mov	dword ptr ss:[ebp+12], eax
	mov	ax, word ptr [_old_ap_func+4]
	mov	word ptr ss:[ebp+16], ax
	pop	eax
	pop	ebp
	pop	ds
	retf
_TEXT	ENDS

END

