xref: /csrg-svn/lib/csu/mips/crt0.s (revision 58278)
152961Sralph/*
252961Sralph * Copyright (c) 1991 The Regents of the University of California.
352961Sralph * All rights reserved.
452961Sralph *
552961Sralph * This code is derived from software contributed to Berkeley by
652961Sralph * Ralph Campbell.
752961Sralph *
855741Sralph * %sccs.include.redist.c%
952961Sralph *
10*58278Sralph *	@(#)crt0.s	5.7 (Berkeley) 02/26/93
1152961Sralph */
1252887Sbostic
1352887Sbostic#include <machine/regdef.h>
1455741Sralph#include <machine/machAsmDefs.h>
1552887Sbostic
1652887Sbostic	.comm	environ, 4
1758101Sralph	.data
1858101Sralph	.align	2
1958101Sralph	.globl	__progname
2058101Sralph__progname:
2158101Sralph	.word	$L1
2258101Sralph$L1:
2358101Sralph	.word	0		# null string plus padding
2458101Sralph	.text
2552887Sbostic
26*58278SralphNON_LEAF(start, 24, ra)
2758101Sralph	.set	noreorder
2858101Sralph	lw	s0, 0(sp)	# get argc from stack
2958101Sralph	addu	s1, sp, 4	# get pointer to argv
3058101Sralph	addu	s2, s1, 4	# skip null pointer on stack
3158101Sralph	sll	v0, s0, 2	# add number of argv pointers
3258101Sralph	addu	s2, s2, v0	# final pointer to environment list
3358101Sralph	sw	s2, environ	# save environment pointer
3452887Sbostic	subu	sp, sp, 24	# allocate standard frame
3552887Sbostic	.mask	0x80000000, -4
3652887Sbostic	sw	zero, 20(sp)	# clear return address for debugging
3758101Sralph#ifdef MCRT0
3858101Sralpheprol:
3958101Sralph	la	a0, eprol
4058101Sralph	la	a1, etext
4158101Sralph	jal	monstartup	# monstartup(eprol, etext);
4258101Sralph	nop
43*58278Sralph	la	a0, _mcleanup
44*58278Sralph	jal	atexit		# atext(_mcleanup);
4558101Sralph	nop
4658101Sralph	sw	zero, errno
4758101Sralph#endif
4858101Sralph	lw	a0, 0(s1)	# a0 = argv[0];
4958101Sralph	nop
5058101Sralph	beq	a0, zero, 2f	# skip if a0 == NULL
5158101Sralph	move	s3, a0		# save argv[0]
5258101Sralph	jal	strrchr
5358101Sralph	li	a1, 0x2f	# a1 = '/'
5458101Sralph	bne	v0, zero, 1f	# if slash found
5558101Sralph	addu	v0, v0, 1
5658101Sralph	move	v0, s3		# v0 = argv[0];
5758101Sralph1:
5858101Sralph	sw	v0, __progname
5958101Sralph2:
6058101Sralph	move	a0, s0
6158101Sralph	move	a1, s1
6252887Sbostic	jal	main		# v0 = main(argc, argv, env);
6358101Sralph	move	a2, s2
6458101Sralph	jal	exit		# exit(v0);
6552887Sbostic	move	a0, v0
6652887Sbostic	break	0
6758101Sralph	.set	reorder
68*58278SralphEND(start)
6952887Sbostic
7057853SralphLEAF(__main)
7157853Sralph	j	ra
7257853SralphEND(__main)
7357853Sralph
7458101Sralph#ifndef MCRT0
7552887SbosticLEAF(moncontrol)
7652887Sbostic	j	ra
7752887SbosticEND(moncontrol)
7852887Sbostic
7952887SbosticLEAF(_mcount)
8058101Sralph	.set	noreorder
8158123Sralph	.set	noat
8258123Sralph	addu	sp, sp, 8	# undo push
8352887Sbostic	j	ra
8458123Sralph	move	ra, AT
8558123Sralph	.set	at
8658101Sralph	.set	reorder
8752887SbosticEND(_mcount)
8858101Sralph#endif
89