startprog.S revision 1.5
11.5Smatt/*	$NetBSD: startprog.S,v 1.5 2009/12/14 00:46:11 matt Exp $	*/
21.2Ssimonb
31.2Ssimonb/*-
41.2Ssimonb * Copyright (c) 1999 The NetBSD Foundation, Inc.
51.2Ssimonb * All rights reserved.
61.2Ssimonb *
71.2Ssimonb * This code is derived from software contributed to The NetBSD Foundation
81.2Ssimonb * by Jonathan Stone, Michael Hitch and Simon Burge.
91.2Ssimonb *
101.2Ssimonb * Redistribution and use in source and binary forms, with or without
111.2Ssimonb * modification, are permitted provided that the following conditions
121.2Ssimonb * are met:
131.2Ssimonb * 1. Redistributions of source code must retain the above copyright
141.2Ssimonb *    notice, this list of conditions and the following disclaimer.
151.2Ssimonb * 2. Redistributions in binary form must reproduce the above copyright
161.2Ssimonb *    notice, this list of conditions and the following disclaimer in the
171.2Ssimonb *    documentation and/or other materials provided with the distribution.
181.2Ssimonb *
191.2Ssimonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.2Ssimonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.2Ssimonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.2Ssimonb * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.2Ssimonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.2Ssimonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.2Ssimonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.2Ssimonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.2Ssimonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.2Ssimonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.2Ssimonb * POSSIBILITY OF SUCH DAMAGE.
301.2Ssimonb */
311.2Ssimonb
321.1Ssimonb/*
331.1Ssimonb * startprog(entry, stack, argc, argv, prom_magic, prom_ptr, bi_magic, bi_ptr);
341.1Ssimonb *
351.1Ssimonb * load new stack pointer, then call
361.1Ssimonb *  entry(argc, argv, prom_magic, prom_ptr, bi_magic, bi_ptr);
371.1Ssimonb */
381.1Ssimonb
391.1Ssimonb#include <mips/asm.h>
401.1Ssimonb
411.1SsimonbLEAF(startprog)
421.5Smatt        subu    sp,sp,CALLFRAME_SIZ
431.5Smatt	addu	t2,a1,-CALLFRAME_SIZ	# new stack value
441.5Smatt	move	t9,a0
451.1Ssimonb	move	a0,a2
461.1Ssimonb	move	a1,a3
471.1Ssimonb
481.5Smatt#ifdef __mips_o32
491.1Ssimonb	lw	a2,48(sp)		# load everything from old stack we need
501.1Ssimonb	lw	a3,52(sp)
511.5Smatt	lw	$8,56(sp)		# use a4/t0 in case N32/N64 kernel
521.5Smatt	lw	$9,60(sp)		# use a5/t1 in case N32/N64 kernel
531.5Smatt#else
541.5Smatt	move	a2,a4
551.5Smatt	move	a3,a5
561.5Smatt	move	a4,a6
571.5Smatt	move	a5,a7
581.5Smatt#endif
591.5Smatt
601.5Smatt	move	sp,t2			# new stack pointer
611.5Smatt	sw	ra,CALLFRAME_RA(sp)
621.5Smatt
631.5Smatt	sw	$8,16(sp)		# save on stack for O32
641.5Smatt	sw	$9,20(sp)		# save on stack for O32
651.5Smatt	jal	ra,t9
661.1Ssimonb	nop				# BDslot
671.1Ssimonb
681.5Smatt	lw	ra,CALLFRAME_RA(sp)	# should not get back here!
691.1Ssimonb	j	ra
701.5Smatt	addu	sp,sp,CALLFRAME_SIZ
711.1SsimonbEND(startprog)
72