/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
/* $Header: exit.s,v 1.14.2.1 92/06/24 14:02:01 marker Exp $ */

#include <sys/regdef.h>
#ifndef	SYSTYPE_BSD43
#include <sys/asm.h>
#include <sys.s>
#else	/* SYSTYPE_BSD43 */
#include <mips/asm.h>
#endif	/* !SYSTYPE_BSD43 */
#include "sys/syscall.h"

#ifndef __DSO__
#define __DSO__
#endif

#ifdef	__DSO__
#include <rld_interface.h>

#define FRMSIZE 24
NESTED(_exit,FRMSIZE,zero)
	subu	sp,FRMSIZE
	sw	a0,FRMSIZE(sp)
 # _DYNAMIC_LINK is 
 #	0 for non_shared binaries
 # 	1 for call_shared binaries
 #	2 for shared objects
	la	v0,_DYNAMIC_LINK
	bne	v0,zero,1f
 # .fini handling for non_shared binaries
	jal	__fstart
	b	2f
1:
 # Rld will call all .fini sections in main binary & shared objects
	li	a0,_SHUT_DOWN
	jal	_rld_new_interface
2:
	lw	a0,FRMSIZE(sp)
	li	v0,SYS_exit
	syscall
#ifdef	SYSTYPE_BSD43
	jal	abort
#endif	/* SYSTYPE_BSD43 */
#else	/* !__DSO__ */

PSEUDO(_exit,exit)
#ifdef	SYSTYPE_BSD43
	jal	abort
#endif	/* SYSTYPE_BSD43 */

#endif	/* __DSO__ */
	.end _exit
